#!/bin/bash # # d-lok.sh Bash shell script, for use with d-lok encryption program - by Dave Lauderdale. # This script adds a few features to d-lok that isn't found in the actual program. # # 1) This script adds the usage of the -r switch. The -r switch will rename the # original file with a random number before passing to d-lok for processing. # The -r switch must be used after the -d switch: $d-lok foo bar -d -r # Key can be anything except these characters: `#$*()+|<> # 2) This script will move the encrypted file to another directory for storage if desired # User set variables # This is the name of the program (default is d-lok) # If you rename the program then change this. PROGNAME=d-lok # This is where you placed the program (default is $HOME/bin) PROGPATH=$HOME/bin # This is where you want the encrypted file to be placed (default is $HOME/.locked # If you don't want the encrypted file to be moved anywhere then put $PROGPATH # Example: LKDPATH=$PROGPATH LKDPATH=$HOME/.locked # If you don't want to clear the screen before reading # d-loks output then comment out the below command clear # check UID for root usage. If you want to run the script as root then comment out the below code if [ $UID -eq "0" ] ; then echo "NOTICE: Do not run this script as root!" ; echo ; exit 0 fi # NO EDITING NECESSARY BELOW THIS POINT # misc variables DELSWITCH=-d RANSWITCH=-r OFILE=$PROGPATH/$1 TEMPFILE=$PROGPATH/$2 EFILE=$LKDPATH/$2 NEWFILE=$RANDOM RPROC=0 # If user enters less than 3 args just dislpay $PROGNAME's usage [ $# -lt "3" ] && $PROGPATH/$PROGNAME # If user entered 3 or more args then continue if [ $# -ge "3" ] ; then # If user hasnt created $LKDPATH yet then do it now [ -d $LKDPATH ] || mkdir $LKDPATH # check for existence of $OFILE before doing anything. if [ -a $OFILE ] ; then # Make sure user did/didnt use -r switch before passing $OFILE's name to $PROGNAME. if [ $# -eq "5" ] ; then # If user entered -r switch then rename $OFILE with random number and pass $NEWFILE to $PROGNAME if [ $5 = $RANSWITCH ] ; then cd $PROGPATH ; mv $OFILE $NEWFILE ; ./$PROGNAME $NEWFILE $2 $3 $4 RPROC=1 fi # If user did NOT enter -r switch move to $PROGPATH directory and run $PROGNAME with user supplied args else cd $PROGPATH ; ./$PROGNAME $1 $2 $3 $4 fi # If $OFILE is not located in $PROGPATH then error else echo "ERROR: Script can not locate $OFILE." ; echo "NOTICE: Try putting $1 in same directory as $PROGNAME." ; echo ; exit 1 fi # If the encrypted file ($TEMPFILE) was created/found in $PROGPATH then move it to $LKDPATH if [ -a $TEMPFILE ] ; then mv $TEMPFILE $EFILE # If encrypted file wasn't found then error else echo "ERROR: Script could not locate (in order to move) $TEMPFILE." ; exit 1 fi # If $TEMPFILE was sucessfully moved to $LKDPATH chmod it and notify user if [ -a $EFILE ] ; then chmod 000 $EFILE ; echo "Process completed successfully. Your encrypted file is located at $EFILE" # If file was not found in (could not be moved to) $LKDPATH directory...error else echo "ERROR: Script couldn't locate $EFILE" ; exit 1 fi # If user enters 4th arg if [ $# -eq "4" ] ; then # compare user supplied arg with $DELSWITCH variable if [ $4 = $DELSWITCH ] ; then # if user entered -d switch check to see if $OFILE still exists if [ -a $OFILE ] ; then # $OFILE still exists so notify user echo "ERROR: Original data file still exists at: $OFILE." ; exit 1 # $OFILE not found so the overwrite/deletion process took place else echo "NOTICE: Original data file was overwritten and deleted." fi # If user enters void 4th arg else echo "NOTICE: The correct switch for overwrite of original data is \"-d\"." fi fi # If user successfully entered -r switch then notify user of results [ $RPROC -eq "1" ] && echo "NOTICE: Original data file was renamed with random numbers before it was overwritten and deleted." echo fi exit 0