BashScripts.org
http://bashscripts.org/forum/

a gpg script
http://bashscripts.org/forum/viewtopic.php?f=7&t=222
Page 1 of 1

Author:  coastie [ Mon Aug 07, 2006 9:39 pm ]
Post subject:  a gpg script

i'm formulating an idea for a script that will encrypt a dir after compressing the dir. the part i need help with is how to create a tar.gz from the command line :? i've been reading the man pages and think that somehow i am just missing something. any pointers would be appreciated.

Author:  BrionS [ Tue Aug 08, 2006 4:55 am ]
Post subject: 

If you have a dir called 'mydir' and it has sub directories 'sub1' and 'sub2', you should be able to create a tar.gz with the following command:
Code:
tar zcf mydir.tar.gz mydir

To verify that it worked, simply run the tar command again listing its contents:
Code:
tar zt mydir.tar.gz

This will print out the entire contents of the tarball (without extracting).

Author:  coastie [ Tue Aug 08, 2006 6:42 am ]
Post subject: 

Thanks BrionS, i'll look at it when i get home.

Author:  coastie [ Tue Aug 08, 2006 9:24 pm ]
Post subject: 

little update.

Code:
#!/bin/bash
#################################################################
#                                                               #
#                                                               #
#               This is going to be a GPG Script                #
#                                                               #
#################################################################

#Written by Trey Fox
#Uses: Compress files/dir. and encrypt
#http://usalug.org
#http://opensuse.us
#http://bashscripts.org
#http://ulteo.com

#########################
#       Functions       #
#########################

function gpg
{
gpg -c $FILENAME
}
#########################
#    end functions      #
#########################

#begin script

clear

echo "This program will compress and encrypt a directory of your choice."

read -p "Please enter the directory path to the parent directory of the dir. you would like to compress: " FILEPATH

cd $FILEPATH

ls

read -p "Please enter the name of the directory you would like to now compress: " DIRECTORY

tar -zcf $DIRECTORY.tar.gz $DIRECTORY

FILENAME="$DIRECTORY.tar.gz";

#this should run the function correctly right?
gpg



exit


Author:  BrionS [ Wed Aug 09, 2006 4:07 am ]
Post subject: 

What's the difference between $DIRECTORY and $DIR other than $DIR is not assigned anywhere?

It might also be easier and clearer to just ask to "ent er the full path of the directory you wish to compress and encrypt" and then use awk or sed to grab the directory name off the end of the string.

Author:  coastie [ Wed Aug 09, 2006 4:34 am ]
Post subject: 

typo :D

Author:  coastie [ Wed Aug 09, 2006 4:42 am ]
Post subject: 

Code:
#!/bin/bash
#################################################################
#                                                               #
#                                                               #
#               This is going to be a GPG Script                #
#                                                               #
#################################################################

#Written by Trey Fox
#Uses: Compress files/dir. and encrypt
#http://usalug.org
#http://opensuse.us
#http://bashscripts.org
#http://ulteo.com

#########################
#       Functions       #
#########################

function encrypt
{
gpg -c $FILENAME
}
#########################
#    end functions      #
#########################

#begin script

clear

echo "This program will compress and encrypt a directory of your choice."

read -p "Please enter the directory path to the parent directory of the dir. you would like to compress: " FILEPATH

cd $FILEPATH

ls

read -p "Please enter the name of the directory you would like to now compress: " DIRECTORY

tar -zcf $DIRECTORY.tar.gz $DIRECTORY

FILENAME="$DIRECTORY.tar.gz";

#this should run the function correctly right?

encrypt



exit

Author:  jbsnake [ Wed Aug 09, 2006 10:48 am ]
Post subject: 

in the function you should really do:
Code:
gpg -c "${1}"

and then call the function like:
Code:
encrypt "$FILENAME"

otherwise there really is no point in the function what so ever

Author:  coastie [ Wed Aug 09, 2006 4:56 pm ]
Post subject: 

ok thanks jbsnake :)

i think i would like to make the encryption an option. so something like

1 to encrypt it
and
2 to exit.

not everyone has gpg installed but a script to make a .tar.gz file would still be useful. at least i think so anyway.

i could use some ideas on how to set up the options :idea:

Author:  BrionS [ Thu Aug 10, 2006 4:25 am ]
Post subject: 

No offense coastie, but without the encryption portion of this, there's not much point in the script to tar/zip a directory as you can do that with one line like I stated earlier
Code:
tar zcf TARFILE DIRECTORY

And if that's too much typing, you can always alias it like
Code:
alias tb="tar zcf"
and use it like
Code:
tb TARFILE DIRECTORY


To do the options, you simply print out the options with echo, and then use read to read in the choice and evaluate the string like
Code:
echo "Press 1 to encrypt, or 2 to skip encryption: ";
read CHOICE;
case "$CHOICE" in
        1)
                echo "using encryption..."
                # do something
                ;;
        2)
                echo "skipping encryption..."
                # do something else
                ;;
        *)
                echo "$CHOICE is not an option"
                exit
                ;;
esac

Author:  coastie [ Thu Aug 10, 2006 4:43 am ]
Post subject: 

thanks BrionS, i'm just looking at different things, and ideas. i may add to something really cool to this....i just never know :lol: :roll: . i never really know what i might come up with.

Page 1 of 1 All times are UTC - 6 hours
© 2000, 2002, 2005, 2007 phpBB Group • http://www.phpbb.com