From 40af028d8f11fb0c032ef62a4f45626f492c6dc9 Mon Sep 17 00:00:00 2001 From: boyska Date: Tue, 17 Jan 2012 16:49:03 +0100 Subject: [PATCH 1/3] Removed QUIET and DEBUG globals Addressed removal of $CMD2 and $CMD3, too. They were deprecated since a long time. You should use $PARAM[1], $PARAM[2],... instead --- src/tomb | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/src/tomb b/src/tomb index c210ebf..6e7a5d0 100755 --- a/src/tomb +++ b/src/tomb @@ -401,8 +401,8 @@ EOF # {{{ - HELPERS FOR KEYS # {{{ - Encode Key encode_key() { - tombkey=$CMD2 - imagefile=$CMD3 + tombkey=$1 + imagefile=$2 file $tombkey | grep PGP > /dev/null if [ $? != 0 ]; then @@ -457,8 +457,8 @@ encode_key() { # }}} # {{{ - Decode Key decode_key() { - tombname=$CMD2 - imagefile=$CMD3 + tombname=$1 + imagefile=$2 res=1 file $imagefile | grep JPEG > /dev/null @@ -597,13 +597,13 @@ create_tomb() { _message "Commanded to create tomb $CMD2" if ! option_is_set -f; then check_swap; fi - if ! [ ${CMD2} ]; then + if ! [ $1 ]; then _warning "no tomb name specified for creation" return 1 fi - tombfile=`basename ${CMD2}` - tombdir=`dirname ${CMD2}` + tombfile=`basename $1` + tombdir=`dirname $1` # make sure the file has a .tomb extension tombname=${tombfile%%\.*} tombfile=${tombname}.tomb @@ -767,11 +767,12 @@ create_tomb() { # }}} # {{{ - Open +# $1 = tombfile $2(optional) = mountpoint mount_tomb() { - _message "Commanded to open tomb $CMD2" + _message "Commanded to open tomb $1" if ! option_is_set -f; then check_swap; fi - if ! [ ${CMD2} ]; then + if ! [ ${1} ]; then _warning "no tomb name specified for creation" return 1 fi @@ -783,12 +784,12 @@ mount_tomb() { local tombfile local tombdir local tombname - tombfile=`basename ${CMD2}` - tombdir=`dirname ${CMD2}` + tombfile=`basename ${1}` + tombdir=`dirname ${1}` # check file type (if its a Luks fs) file ${tombdir}/${tombfile} | grep -i 'luks encrypted file' 2>&1 >/dev/null if [ $? != 0 ]; then - _warning "$CMD2 is not a valid tomb file, operation aborted" + _warning "$1 is not a valid tomb file, operation aborted" return 1 fi tombname=${tombfile%%\.*} @@ -815,14 +816,14 @@ mount_tomb() { return 1 fi - if ! [ $CMD3 ]; then + if ! [ $2 ]; then tombmount=/media/${tombfile} _message "mountpoint not specified, using default: $tombmount" - elif ! [ -x $CMD3 ]; then - _warning "mountpoint $CMD3 doesn't exist, operation aborted." + elif ! [ -x $2 ]; then + _warning "mountpoint $2 doesn't exist, operation aborted." return 1 else - tombmount=${CMD3} + tombmount=$2 fi # check if its already open @@ -1689,16 +1690,16 @@ main() { CMD2=$PARAM[1] CMD3=$PARAM[2] - xxx "Tomb command: $CMD $CMD2 $CMD3" + xxx "Tomb command: $subcommand ${PARAM}" case "$subcommand" in create) check_priv - create_tomb + create_tomb $PARAM[1] ;; mount|open) check_priv - mount_tomb + mount_tomb $PARAM[1] $PARAM[2] ;; umount|close|slam) check_priv @@ -1730,7 +1731,7 @@ main() { _warning "steghide not installed. Cannot exhume your key" return 1 fi - decode_key ${CMD2} + decode_key ${CMD2} ${CMD3} ;; resize) check_priv @@ -1758,7 +1759,7 @@ EOF usage ;; *) - _warning "command \"$CMD\" not recognized" + _warning "command \"$subcommand\" not recognized" _message "try -h for help" return 1 ;; From 2065090b841622786e9a0f8373ae58a3f11ad918 Mon Sep 17 00:00:00 2001 From: boyska Date: Fri, 20 Jan 2012 01:47:07 +0100 Subject: [PATCH 2/3] Cleaning: remove CMD{,2,3} (see #25) they were deprecated. If you really need, use $PARAM array instead. But you probably DON'T need to; it's better to make your function directly accept parameters (btw, mandatory options should probably be parameters, too) --- src/tomb | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/tomb b/src/tomb index 6e7a5d0..3fe9771 100755 --- a/src/tomb +++ b/src/tomb @@ -592,9 +592,10 @@ exec_safe_post_hooks() { # {{{ TOMB SUB-COMMANDS # {{{ - Create +# $1 is the tomb path create_tomb() { - _message "Commanded to create tomb $CMD2" + _message "Commanded to create tomb $1" if ! option_is_set -f; then check_swap; fi if ! [ $1 ]; then @@ -1092,13 +1093,14 @@ umount_tomb() { # }}} # }}} # {{{ - Change Password +# $1 is the tomb key path # change tomb key password change_passwd() { - _message "Commanded to change password for tomb key $CMD2" + _message "Commanded to change password for tomb key $1" if ! option_is_set -f; then check_swap; fi - local keyfile="$CMD2" + local keyfile="$1" # check the keyfile if ! [ -r $keyfile ]; then @@ -1195,17 +1197,18 @@ change_passwd() { # }}} # {{{ - Resize # resize tomb file size +# $1 is tomb path resize_tomb() { - _message "Commanded to resize tomb $CMD2 to $opts[-s] megabytes" - if ! [ ${CMD2} ]; then + _message "Commanded to resize tomb $1 to $opts[-s] megabytes" + if ! [ $1 ]; then _failure "No tomb name specified for resizing" - elif ! [ -r "${CMD2}" ]; then - _failure "Cannot find ${CMD2}" + elif ! [ -r "$1" ]; then + _failure "Cannot find $1" fi local c tombpass tombkey - local tombfile=`basename ${CMD2}` - local tombdir=`dirname ${CMD2}` + local tombfile=`basename $1` + local tombdir=`dirname $1` # make sure the file has a .tomb extension local tombname=${tombfile%%\.*} tombfile=${tombname}.tomb @@ -1232,7 +1235,7 @@ resize_tomb() { local tmp_resize=`safe_filename tmbrsz` local newtombsize=$opts[-s] - local oldtombsize=`stat -c %s "${CMD2}" 2>/dev/null` + local oldtombsize=`stat -c %s "$1" 2>/dev/null` local mounted_tomb=`mount -l | awk -vtomb="[$tombname]" '/^\/dev\/mapper\/tomb/ { if($7==tomb) print $1 }'` @@ -1265,14 +1268,14 @@ resize_tomb() { _failure "Error creating the extra resize $tmp_resize, operation aborted." fi - cat "${tmp_resize}" >> "${CMD2}" + cat "${tmp_resize}" >> "$1" ${=WIPE} "${tmp_resize}" local nstloop=`losetup -f` if [ $? = 255 ]; then _failure "too many tomb opened. Please close any of them to open another tomb" fi - losetup -f "${CMD2}" + losetup -f "$1" local mapdate=`date +%s` local mapper="tomb.${tombname}.${mapdate}.`basename $nstloop`" @@ -1330,8 +1333,9 @@ resize_tomb() { # }}} # {{{ - List # list all tombs mounted in a readable format +# $1 is optional, to specify a tomb list_tombs() { - if [ $CMD2 ]; then + if [ $1 ]; then # list a specific tomb mounted_tombs=`mount -l | awk -vtomb="[$1]" '/^\/dev\/mapper\/tomb/ { if($7==tomb) print $1 ";" $3 ";" $5 ";" $6 ";" $7 }'` @@ -1348,7 +1352,7 @@ list_tombs() { if ! [ $mounted_tombs ]; then if [ $1 ]; then - die "There seems to be no open tomb engraved as [$CMD2]" + die "There seems to be no open tomb engraved as [$1]" else die "I can't see any open tomb, may they all rest in peace." fi @@ -1686,10 +1690,6 @@ main() { autoload colors; colors fi - CMD=$subcommand - CMD2=$PARAM[1] - CMD3=$PARAM[2] - xxx "Tomb command: $subcommand ${PARAM}" case "$subcommand" in @@ -1704,17 +1704,17 @@ main() { umount|close|slam) check_priv [ "$subcommand" = "slam" ] && SLAM=1 - umount_tomb ${CMD2} + umount_tomb $PARAM[1] ;; passwd) check_priv - change_passwd ${CMD2} + change_passwd $PARAM[1] ;; list) - list_tombs ${CMD2} + list_tombs $PARAM[1] ;; status) - launch_status ${CMD2} + launch_status $PARAM[1] ;; help) usage @@ -1724,24 +1724,24 @@ main() { _warning "steghide not installed. Cannot bury your key" return 1 fi - encode_key ${CMD2} ${CMD3} + encode_key $PARAM[1] $PARAM[2] ;; exhume) if [ "$STEGHIDE" = 0 ]; then _warning "steghide not installed. Cannot exhume your key" return 1 fi - decode_key ${CMD2} ${CMD3} + decode_key $PARAM[1] $PARAM[2] ;; resize) check_priv - resize_tomb + resize_tomb $PARAM[1] ;; # internal commands useful to developers 'source') return 0 ;; install) check_priv ; install_tomb ;; - askpass) ask_password ${CMD2} ${CMD3} ;; - mktemp) safe_dir ${CMD2} ;; + askpass) ask_password $PARAM[1] $PARAM[2] ;; + mktemp) safe_dir $PARAM[1] ;; translate) generate_translatable_strings ;; __default) cat < Date: Fri, 20 Jan 2012 02:14:39 +0100 Subject: [PATCH 3/3] vim/emacs modeline: help keeping code tidy;see #25 --- src/tomb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tomb b/src/tomb index 3fe9771..e270405 100755 --- a/src/tomb +++ b/src/tomb @@ -1776,3 +1776,5 @@ if [[ $? != 0 ]]; then #this "if" seems useless, but avoid source tomb source fr fi # }}} +# -*- tab-width: 4; indent-tabs-mode:nil; -*- +# vim: set shiftwidth=4 expandtab: