tMerge: changed legacy code, added modelines - tomb - the crypto undertaker HTML git clone git://parazyd.org/tomb.git DIR Log DIR Files DIR Refs DIR README DIR LICENSE --- DIR commit 634720b40c0a9f643a2bf5fee560d9e9dd5f6e15 DIR parent d57994fcc3a0339060541069b0b3b2d88a5e2fdb HTML Author: boyska <piuttosto@logorroici.org> Date: Thu, 2 Feb 2012 23:44:43 +0100 Merge: changed legacy code, added modelines Diffstat: M src/tomb | 95 ++++++++++++++++--------------- 1 file changed, 49 insertions(+), 46 deletions(-) --- DIR diff --git a/src/tomb b/src/tomb t@@ -413,8 +413,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 t@@ -469,8 +469,8 @@ encode_key() { # }}} # {{{ - Decode Key decode_key() { - tombname=$CMD2 - imagefile=$CMD3 + tombname=$1 + imagefile=$2 res=1 file $imagefile | grep JPEG > /dev/null t@@ -604,18 +604,19 @@ 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 ! [ ${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 t@@ -779,11 +780,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 t@@ -795,12 +797,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%%\.*} t@@ -827,14 +829,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 t@@ -1118,13 +1120,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 t@@ -1221,17 +1224,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 t@@ -1258,7 +1262,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 }'` t@@ -1291,14 +1295,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`" t@@ -1356,8 +1360,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 }'` t@@ -1374,7 +1379,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 t@@ -1726,35 +1731,31 @@ main() { autoload colors; colors fi - CMD=$subcommand - 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 [ "$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 t@@ -1770,17 +1771,17 @@ main() { _warning "steghide not installed. Cannot exhume your key" return 1 fi - decode_key $PARAM[1] + 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 $PARAM[1] ;; + askpass) ask_password $PARAM[1] $PARAM[2] ;; + mktemp) safe_dir $PARAM[1] ;; translate) generate_translatable_strings ;; check) check_command $PARAM[1] ;; __default) t@@ -1799,7 +1800,7 @@ EOF usage ;; *) - _warning "command \"$CMD\" not recognized" + _warning "command \"$subcommand\" not recognized" _message "try -h for help" return 1 ;; t@@ -1817,3 +1818,5 @@ if [[ $ret != 0 ]]; then #this "if" seems useless, but avoid source tomb source fi # }}} +# -*- tab-width: 4; indent-tabs-mode:nil; -*- +# vim: set shiftwidth=4 expandtab: