mirror of
https://github.com/Llewellynvdm/Tomb.git
synced 2025-02-02 11:58:28 +00:00
clean up mount code and list output ( fix #32 )
This commit is contained in:
parent
70e4a5d19f
commit
a3f0c7c86b
111
src/tomb
111
src/tomb
@ -201,53 +201,6 @@ EOF
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
get_arg_tomb() {
|
|
||||||
# set up variables to be used by caller:
|
|
||||||
# tombfile - filename without path
|
|
||||||
# tombdir - directory where the tomb is
|
|
||||||
# tombname - name of the tomb (filename without extension)
|
|
||||||
# the full path is made with $tombdir/$tombfile
|
|
||||||
if [ -z $1 ]; then
|
|
||||||
error "internal: get_arg_tomb called without argument"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
arg=${1}
|
|
||||||
if ! [ -r ${arg} ]; then
|
|
||||||
error "file not found: $arg"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
tombfile=`basename $arg`
|
|
||||||
tombdir=`dirname $arg`
|
|
||||||
|
|
||||||
file ${tombdir}/${tombfile} | grep -i 'luks encrypted file' 2>&1 >/dev/null
|
|
||||||
if [ $? != 0 ]; then
|
|
||||||
error "$arg is not a valid tomb file, operation aborted"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
tombname=${tombfile%%\.*}
|
|
||||||
func "tomb found: ${tombdir}/${tombfile}"
|
|
||||||
# now check if the key is kept beside or in args
|
|
||||||
# we use the extension .key
|
|
||||||
|
|
||||||
# the problem with .tomb.gpg is that decoding by hand using gpg it
|
|
||||||
# can override the tomb contents if the key is in the same
|
|
||||||
# directory than the tomb
|
|
||||||
if [ $KEY ]; then
|
|
||||||
tombkey=$KEY # commandline -k flag
|
|
||||||
act "tomb key specified manually: $tombkey"
|
|
||||||
elif [ -r ${tombdir}/${tombname}.tomb.key ]; then
|
|
||||||
tombkey=${tombdir}/${tombname}.tomb.key
|
|
||||||
act "key found for tomb '${tombname}': ${tombkey}"
|
|
||||||
else
|
|
||||||
error "key not found for tomb '${tombname}'"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
Tomb $VERSION - a strong and gentle undertaker for your secrets
|
Tomb $VERSION - a strong and gentle undertaker for your secrets
|
||||||
@ -269,7 +222,7 @@ EOF
|
|||||||
if [ "$STEGHIDE" = 1 ]; then
|
if [ "$STEGHIDE" = 1 ]; then
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
bury hide a tomb key FILE inside a jpeg PLACE
|
bury hide a tomb key FILE inside a jpeg PLACE
|
||||||
exhume extract a tomb key FILE from a jpeg PL
|
exhume extract a tomb key FILE from a jpeg PLACE
|
||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
@ -527,10 +480,23 @@ mount_tomb() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# TODO: eliminate this function
|
# set up variables to be used
|
||||||
get_arg_tomb $CMD2
|
# the full path is made with $tombdir/$tombfile
|
||||||
|
|
||||||
local tombkey
|
local tombkey
|
||||||
|
local tombfile
|
||||||
|
local tombdir
|
||||||
|
local tombname
|
||||||
|
tombfile=`basename ${CMD2}`
|
||||||
|
tombdir=`dirname ${CMD2}`
|
||||||
|
# check file type (if its a Luks fs)
|
||||||
|
file ${tombdir}/${tombfile} | grep -i 'luks encrypted file' 2>&1 >/dev/null
|
||||||
|
if [ $? != 0 ]; then
|
||||||
|
error "$CMD2 is not a valid tomb file, operation aborted"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
tombname=${tombfile%%\.*}
|
||||||
|
func "tomb found: ${tombdir}/${tombfile}"
|
||||||
|
|
||||||
if option_is_set -k ; then
|
if option_is_set -k ; then
|
||||||
if [[ "`option_value -k`" == "-" ]]; then
|
if [[ "`option_value -k`" == "-" ]]; then
|
||||||
# take key from stdin
|
# take key from stdin
|
||||||
@ -544,10 +510,10 @@ mount_tomb() {
|
|||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# guess key as lying besides the tomb
|
# guess key as lying besides the tomb
|
||||||
tombkey="${PARAM[1]}.key"
|
tombkey=${tombdir}/${tombfile}.key
|
||||||
fi
|
fi
|
||||||
echo the key used is $tombkey
|
if ! [ -r ${tombkey} ]; then
|
||||||
if [ $? != 0 ]; then
|
error "key file not found: ${tombkey}"
|
||||||
error "operation aborted."
|
error "operation aborted."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@ -557,33 +523,22 @@ mount_tomb() {
|
|||||||
act "mountpoint not specified, using default: $tombmount"
|
act "mountpoint not specified, using default: $tombmount"
|
||||||
elif ! [ -x $CMD3 ]; then
|
elif ! [ -x $CMD3 ]; then
|
||||||
error "mountpoint $CMD3 doesn't exist, operation aborted."
|
error "mountpoint $CMD3 doesn't exist, operation aborted."
|
||||||
if [ -n "$usbkey_mount" ]; then
|
|
||||||
umount $usbkey_mount
|
|
||||||
rmdir $usbkey_mount
|
|
||||||
unset usbkey_mount
|
|
||||||
fi
|
|
||||||
return 1
|
return 1
|
||||||
else
|
else
|
||||||
tombmount=$CMD3
|
tombmount=${CMD3}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check if its already open
|
# check if its already open
|
||||||
mount -l | grep "${tombname}.tomb.*\[$tombname\]$" 2>&1 > /dev/null
|
mount -l | grep "${tombfile}.*\[$tombname\]$" 2>&1 > /dev/null
|
||||||
if [ $? = 0 ]; then
|
if [ $? = 0 ]; then
|
||||||
error "$tombname is already mounted on $tombmount"
|
error "$tombname is already open on $tombmount"
|
||||||
act "tomb list - show all tombs currently open"
|
act "here below its status is reported:"
|
||||||
if [ -n "$usbkey_mount" ]; then
|
list_tombs ${tombname}
|
||||||
umount $usbkey_mount
|
|
||||||
rmdir $usbkey_mount
|
|
||||||
unset usbkey_mount
|
|
||||||
fi
|
|
||||||
error "operation aborted."
|
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
notice "mounting $tombfile on mountpoint $tombmount"
|
notice "mounting $tombfile on mountpoint $tombmount"
|
||||||
|
|
||||||
|
|
||||||
# we need root from here on
|
# we need root from here on
|
||||||
mkdir -p $tombmount
|
mkdir -p $tombmount
|
||||||
|
|
||||||
@ -641,7 +596,7 @@ mount_tomb() {
|
|||||||
|
|
||||||
act "encrypted storage filesystem check"
|
act "encrypted storage filesystem check"
|
||||||
fsck -p -C0 /dev/mapper/${mapper}
|
fsck -p -C0 /dev/mapper/${mapper}
|
||||||
act "tomb engraved as $tombname"
|
func "tomb engraved as $tombname"
|
||||||
tune2fs -L ${tombname} /dev/mapper/${mapper} > /dev/null
|
tune2fs -L ${tombname} /dev/mapper/${mapper} > /dev/null
|
||||||
|
|
||||||
mount -o $MOUNTOPTS /dev/mapper/${mapper} ${tombmount}
|
mount -o $MOUNTOPTS /dev/mapper/${mapper} ${tombmount}
|
||||||
@ -1077,30 +1032,32 @@ list_tombs() {
|
|||||||
print -n "$fg_no_bold[white] using "
|
print -n "$fg_no_bold[white] using "
|
||||||
print "$fg_bold[white]$tombfs $tombfsopts"
|
print "$fg_bold[white]$tombfs $tombfsopts"
|
||||||
|
|
||||||
|
print -n "$fg_no_bold[green]$tombname"
|
||||||
|
print -n "$fg_no_bold[white] open since "
|
||||||
|
print "$fg_bold[white]$tombsince$fg_no_bold[white]"
|
||||||
|
|
||||||
print -n "$fg_no_bold[green]$tombname"
|
print -n "$fg_no_bold[green]$tombname"
|
||||||
print -n "$fg[white] size "
|
print -n "$fg[white] size "
|
||||||
print -n "$fg_bold[white]$tombtot"
|
print -n "$fg_bold[white]$tombtot"
|
||||||
print -n "$fg_no_bold[white] of which "
|
print -n "$fg_no_bold[white] of which "
|
||||||
print -n "$fg_bold[white]$tombused"
|
print -n "$fg_bold[white]$tombused"
|
||||||
print -n "$fg_no_bold[white] used "
|
print -n "$fg_no_bold[white] used: "
|
||||||
print -n "$fg_bold[white]$tombavail"
|
print -n "$fg_bold[white]$tombavail"
|
||||||
print -n "$fg_no_bold[white] free ("
|
print -n "$fg_no_bold[white] free ("
|
||||||
print -n "$fg_bold[white]$tombpercent"
|
print -n "$fg_bold[white]$tombpercent"
|
||||||
print "$fg_no_bold[white] full)"
|
print "$fg_no_bold[white] full)"
|
||||||
|
|
||||||
if [[ ${tombp} -ge 90 ]]; then
|
if [[ ${tombp} -ge 90 ]]; then
|
||||||
error "Your tomb is almost full!"
|
print -n "$fg_no_bold[green]$tombname"
|
||||||
|
print "$fg_bold[red] Your tomb is almost full!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
print -n "$fg_no_bold[green]$tombname"
|
|
||||||
print -n "$fg_no_bold[white] open since "
|
|
||||||
print "$fg_bold[white]$tombsince$fg_no_bold[white]"
|
|
||||||
|
|
||||||
# now check hooks
|
# now check hooks
|
||||||
mtomb=`sed 's:\/:\\\/:g' <<< $tombmount`
|
mtomb=`sed 's:\/:\\\/:g' <<< $tombmount`
|
||||||
mounted_hooks=`mount | awk "/^$mtomb/"' {print $1 ";" $3}'`
|
mounted_hooks=`mount | awk "/^$mtomb/"' {print $1 ";" $3}'`
|
||||||
for h in ${(f)mounted_hooks}; do
|
for h in ${(f)mounted_hooks}; do
|
||||||
print -n "$fg[green]$tombname"
|
print -n "$fg_no_bold[green]$tombname"
|
||||||
print -n "$fg_no_bold[white] hooks "
|
print -n "$fg_no_bold[white] hooks "
|
||||||
print -n "$fg_bold[white]`basename ${h[(ws:;:)1]}`"
|
print -n "$fg_bold[white]`basename ${h[(ws:;:)1]}`"
|
||||||
print -n "$fg_no_bold[white] on "
|
print -n "$fg_no_bold[white] on "
|
||||||
|
Loading…
x
Reference in New Issue
Block a user