#! perl5 # # tgz.pl Daniel Brockman 20031219 makes or extracts a tarred, gzipped file # # Warning: tgz.pl will overwrite existing files, if any. ################################################ # The author grants permission to use for any # # purpose, including copying and modification, # # provided the user acknowledges the author by # # name. # # -- Daniel Brockman, author, 20031220 # ################################################ # # Usage: # # To compress... # # tgz.pl target [ zipname ] # # will store the compressed content of target, including subdirectories # in file zipname.tgz . If zipname is omitted from command, then # zipname defaults to target. # # To display a catalog of the contents of a compressed file... # # tgz.pl -t zipname # # To decompress... # # tgz.pl -d zipname # # Dependencies: tar gzip use strict "subs"; use strict "vars"; my ( $target, $zipname, $ziptgz, $cmd, ); if($#ARGV<0){ print "Usage: tgz.pl target \[zipname\]\n"; print " or: tgz.pl \[-t\|-d] zipname\]\n"; print "Advice: use -t before using -d."; }else{ if(($#ARGV>0) and (($ARGV[0] eq "-d") or ($ARGV[0] eq "-t"))) { $zipname=$ARGV[1]; $ziptgz=$zipname."\.tgz" ; if( -f $zipname & ! -f $ziptgz) { $ziptgz=$zipname ; } if(! -f $ziptgz){ die "File $ziptgz does not exist."; } if ($ARGV[0] eq "-d"){ $cmd="gzip -d < $ziptgz | tar xf -"; }else{ $cmd="gzip -d < $ziptgz | tar tf -"; } }else{ # at this point we know it's not catalog nor decompression, # so only compression remains # $target=$ARGV[0]; if($#ARGV>0){ $ziptgz=$ARGV[1]; }else{ $ziptgz=$target."\.tgz"; } if(! -x $target){ die "$target does not exist."; } $cmd="tar cf - $target | gzip -9fn > $ziptgz"; } print "executing $cmd \n"; system($cmd); # execute command } # end