Register
It is currently Sat Nov 01, 2014 5:09 am

a gpg script


All times are UTC - 6 hours


Post new topic Reply to topic  [ 11 posts ] 
Author Message
 PostPosted: Mon Aug 07, 2006 9:39 pm   
User avatar

Joined: Tue May 17, 2005 12:55 am
Posts: 86
Location: Big Easy, Louisiana
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.


Top
 Profile YIM  
 PostPosted: Tue Aug 08, 2006 4:55 am   
User avatar

Joined: Mon Jul 03, 2006 8:58 pm
Posts: 52
Location: Rochester, NY
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).


Top
 Profile WWW  
 PostPosted: Tue Aug 08, 2006 6:42 am   
User avatar

Joined: Tue May 17, 2005 12:55 am
Posts: 86
Location: Big Easy, Louisiana
Thanks BrionS, i'll look at it when i get home.


Top
 Profile YIM  
 PostPosted: Tue Aug 08, 2006 9:24 pm   
User avatar

Joined: Tue May 17, 2005 12:55 am
Posts: 86
Location: Big Easy, Louisiana
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



Last edited by coastie on Wed Aug 09, 2006 4:34 am, edited 1 time in total.

Top
 Profile YIM  
 PostPosted: Wed Aug 09, 2006 4:07 am   
User avatar

Joined: Mon Jul 03, 2006 8:58 pm
Posts: 52
Location: Rochester, NY
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.


Top
 Profile WWW  
 PostPosted: Wed Aug 09, 2006 4:34 am   
User avatar

Joined: Tue May 17, 2005 12:55 am
Posts: 86
Location: Big Easy, Louisiana
typo :D


Top
 Profile YIM  
 PostPosted: Wed Aug 09, 2006 4:42 am   
User avatar

Joined: Tue May 17, 2005 12:55 am
Posts: 86
Location: Big Easy, Louisiana
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


Top
 Profile YIM  
 PostPosted: Wed Aug 09, 2006 10:48 am   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
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


Top
 Profile  
 PostPosted: Wed Aug 09, 2006 4:56 pm   
User avatar

Joined: Tue May 17, 2005 12:55 am
Posts: 86
Location: Big Easy, Louisiana
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:


Top
 Profile YIM  
 PostPosted: Thu Aug 10, 2006 4:25 am   
User avatar

Joined: Mon Jul 03, 2006 8:58 pm
Posts: 52
Location: Rochester, NY
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


Top
 Profile WWW  
 PostPosted: Thu Aug 10, 2006 4:43 am   
User avatar

Joined: Tue May 17, 2005 12:55 am
Posts: 86
Location: Big Easy, Louisiana
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.


Top
 Profile YIM  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP