You are not logged in.

#1 2010-11-14 17:49:32

chrispoole
Member
Registered: 2008-12-30
Posts: 121

Simple shell script, decrypt with gpg, pass to tar not work?

I wrote a simple shell function,

decrypt () {
    for i in "$@"; do
        if [ -d "$i" ]; then
            gpg -d "$i" | tar xzf - 
#            srm "$i"
        elif [ -f "$i" ]; then
            gpg -o ${i%.gpg} -d "$i"
            srm "$i"
        else
            echo "$i" is not a valid file or directory.
        fi
    done
}

I can pass it a list of files that I have encrypted with an encrypt() function: regular files just get gpg'd, and folders get tarred first.

Decrypting files works fine, but decrypting a folder does not. Why?

Addendum:

I can run the following line in an interactive shell:

gpg -d test\ directory.tgz.gpg | tar xzf -

This works fine. I get a directory called "test directory".

However, running

decrypt test\ directory.tgz.gpg

(which is the file that my encrypt() function produces) doesn't work, I just get a file "test directory.tgz", as though tar was never invoked.

I can't figure out why, but I'm sure it's something simple.

Offline

#2 2010-11-14 18:37:23

ber_t
Member
From: Berlin, Germany
Registered: 2010-03-10
Posts: 214
Website

Re: Simple shell script, decrypt with gpg, pass to tar not work?

Does changing

gpg -o ${i%.gpg} -d "$i"

to

gpg -o "${i%.gpg}" -d "$i"

have any effect?

Offline

#3 2010-11-14 18:52:40

chrispoole
Member
Registered: 2008-12-30
Posts: 121

Re: Simple shell script, decrypt with gpg, pass to tar not work?

Aha! I'm an idiot.

I wrote an encryption folder to check for whether the input is a file or folder, and tar any folder first.

Of course, the decryption folder will only ever be acting on files, some of which just happen to be directories originally.

Offline

Board footer

Powered by FluxBB