better dialogs, also for tomb-open

This commit is contained in:
Jaromil 2011-05-26 13:00:30 +02:00
parent 2c26903206
commit e9e584a9c2
2 changed files with 51 additions and 42 deletions

View File

@ -117,7 +117,7 @@ ask_password() {
GTK2_RC=/usr/share/themes/tomb/gtk-2.0-key/gtkrc GTK2_RC=/usr/share/themes/tomb/gtk-2.0-key/gtkrc
fi fi
cat <<EOF | GTK2_RC_FILES=${GTK2_RC} pinentry | awk '/^D/ { print $2 }' cat <<EOF | GTK2_RC_FILES=${GTK2_RC} pinentry 2>/dev/null | awk '/^D/ { print $2 }'
OPTION ttyname=$TTY OPTION ttyname=$TTY
OPTION lc-ctype=$LANG OPTION lc-ctype=$LANG
SETTITLE Insert tomb password SETTITLE Insert tomb password
@ -149,7 +149,7 @@ check_priv() {
sudok=false sudok=false
sudo -n ${TOMBEXEC} 2> /dev/null sudo -n ${TOMBEXEC} 2> /dev/null
if [ $? != 0 ]; then # if not then ask a password if [ $? != 0 ]; then # if not then ask a password
cat <<EOF | pinentry | awk '/^D/ { print $2 }' | sudo -S -v cat <<EOF | pinentry 2>/dev/null | awk '/^D/ { print $2 }' | sudo -S -v
OPTION ttyname=$TTY OPTION ttyname=$TTY
OPTION lc-ctype=$LANG OPTION lc-ctype=$LANG
SETTITLE Super user privileges required SETTITLE Super user privileges required
@ -1046,7 +1046,7 @@ main () {
act "version $VERSION ($DATE) by Jaromil @ dyne.org" act "version $VERSION ($DATE) by Jaromil @ dyne.org"
# print out the GPL license in this file # print out the GPL license in this file
act "" act ""
cat $0 | awk 'BEGIN { license=0 } /^# This source/ { license=1 } { if(license==1) print " " $0 } cat ${TOMBEXEC} | awk 'BEGIN { license=0 } /^# This source/ { license=1 } { if(license==1) print " " $0 }
/MA 02139, USA.$/ { license=0 }' /MA 02139, USA.$/ { license=0 }'
act "" act ""
exit 0 ;; exit 0 ;;

View File

@ -28,6 +28,9 @@ if [ "$0" = "./tomb-open" ]; then
TOMBEXEC="$PWD/tomb" TOMBEXEC="$PWD/tomb"
fi fi
# includes all shell functions in tomb
source $TOMBEXEC source
try() { try() {
which ${1} > /dev/null which ${1} > /dev/null
if [ $? = 0 ]; then if [ $? = 0 ]; then
@ -73,8 +76,8 @@ Let's start setting your Crypt?"
# so that they are configurable when calling tomb. # so that they are configurable when calling tomb.
ask_usbkey() { ask_usbkey() {
unset usbkey_mount unset usbkey_mount
echo "Waiting 1 minute for a usb key to connect" notice "Waiting 1 minute for a usb key to connect"
echo -n " . please insert your usb key " act -n "please insert your usb key "
tomb-notify "Insert your USB KEY" \ tomb-notify "Insert your USB KEY" \
"Tomb is waiting 30 seconds for you to insert an external key." "Tomb is waiting 30 seconds for you to insert an external key."
@ -89,13 +92,13 @@ ask_usbkey() {
c=`expr $c + 1` c=`expr $c + 1`
if [ $c -gt 60 ]; then if [ $c -gt 60 ]; then
echo echo
echo "[!] timeout." error "timeout."
return 1; return 1;
fi fi
done done
echo echo
echo -n " . usb key inserted, attaching " act -n "usb key inserted, attaching "
c=0 c=0
attached=false attached=false
@ -107,14 +110,14 @@ ask_usbkey() {
c=`expr $c + 1` c=`expr $c + 1`
if [ $c -gt 30 ]; then if [ $c -gt 30 ]; then
echo echo
echo "[!] timeout." error "[!] timeout."
export usbkey_mount=none export usbkey_mount=none
return 1; return 1;
fi fi
done done
echo echo
echo -n " . usb attached, opening " act -n "usb attached, opening "
# get the first partition # get the first partition
# usbpart=`dmesg |tail -n 12 | grep ' sd.:' |cut -d: -f2 |tr -d ' '` # usbpart=`dmesg |tail -n 12 | grep ' sd.:' |cut -d: -f2 |tr -d ' '`
@ -123,7 +126,7 @@ ask_usbkey() {
if [ -n "$usbpart" ]; then if [ -n "$usbpart" ]; then
break break
elif [ $i -eq 10 ]; then elif [ $i -eq 10 ]; then
echo "[!] timeout." error "timeout."
return 1 return 1
else else
echo -n . echo -n .
@ -136,12 +139,12 @@ ask_usbkey() {
if [ $? = 0 ]; then if [ $? = 0 ]; then
usbmount=$mtmp usbmount=$mtmp
else else
echo "[!] cannot mount usbkey partition $usbmount" error "cannot mount usbkey partition $usbmount"
return 1 return 1
fi fi
echo echo
echo " . usb key mounted on $usbmount" act "usb key mounted on $usbmount"
usbkey_mount=$usbmount usbkey_mount=$usbmount
return 0 return 0
} }
@ -151,17 +154,22 @@ launch_status() {
# applet; it takes the tomb name as an argument and should be # applet; it takes the tomb name as an argument and should be
# launched after a successful tomb mount. # launched after a successful tomb mount.
if ! [ $1 ]; then if ! [ $1 ]; then
echo "[!] cannot launch status tray applet: we don't even know the name of our tomb." error "cannot launch status tray applet: we don't even know the name of our tomb."
exit 1 exit 1
fi fi
tombname=${1} if [ $DISPLAY ]; then
tombmap=`mount -l | awk "/\[${tombname}\]$/"' { print $1 } '` tombname=${1}
tombmount=`mount -l | awk "/\[${tombname}\]$/"' { print $3 } '` tombmap=`mount -l | awk "/\[${tombname}\]$/"' { print $1 } '`
if [ -x ./tomb-status ]; then # launch from build dir tombmount=`mount -l | awk "/\[${tombname}\]$/"' { print $3 } '`
./tomb-status $tombmap $tombname $tombmount &! if [ -x ./tomb-status ]; then # launch from build dir
else ./tomb-status $tombmap $tombname $tombmount &!
tomb-status $tombmap $tombname $tombmount &! else
which tomb-status > /dev/null
if [ $? = 0 ]; then
tomb-status $tombmap $tombname $tombmount &!
fi
fi
fi fi
} }
@ -182,24 +190,24 @@ if [ $1 ]; then # is it a file?
else else
ask_usbkey ask_usbkey
if ! [ $usbkey_mount ]; then # no usb key was mounted if ! [ $usbkey_mount ]; then # no usb key was mounted
echo "key not provided for tomb: $tombname" error "key not provided for tomb: $tombname"
echo "operation aborted." # TODO: dialog with pinentry error "operation aborted." # TODO: dialog with pinentry
exit 1 exit 1
else # usb mounted, check key presence else # usb mounted, check key presence
if [ -r ${usbkey_mount}/.tomb/${tombname}.tomb.key ]; then if [ -r ${usbkey_mount}/.tomb/${tombname}.tomb.key ]; then
tombkey=${usbkey_mount}/.tomb/${tombname}.tomb.key tombkey=${usbkey_mount}/.tomb/${tombname}.tomb.key
elif [ -r ${usbkey_mount}/.tomb ]; then elif [ -r ${usbkey_mount}/.tomb ]; then
echo "we can't find the right key, have a look yourself:" error "we can't find the right key, have a look yourself:"
ls -lha ${usbkey_mount}/.tomb ls -lha ${usbkey_mount}/.tomb
exit 1 exit 1
else else
echo "there are no keys stored in your usb" error "there are no keys stored in your usb"
exit 1 exit 1
fi fi
fi fi
fi fi
if ! [ ${tombkey} ]; then # just to be sure if ! [ ${tombkey} ]; then # just to be sure
echo "key not found, operation aborted." error "key not found, operation aborted."
exit 1 exit 1
else else
@ -245,8 +253,8 @@ fi
# no argument but on graphical display: creation dialog # no argument but on graphical display: creation dialog
if [ "$1" != "wizard" ]; then if [ "$1" != "wizard" ]; then
if [ -z $DISPLAY ]; then if [ -z $DISPLAY ]; then
echo "[!] tomb-open is a wrapper for the command 'tomb'" error "tomb-open is a wrapper for the command 'tomb'"
echo "[!] type 'tomb-open wizard' if you want to be guided" error "[!] type 'tomb-open wizard' if you want to be guided"
"${TOMBEXEC}" -h "${TOMBEXEC}" -h
exit 1 exit 1
fi fi
@ -259,10 +267,11 @@ if [ -r $HOME/Desktop ]; then
cd $HOME/Desktop; cd $HOME/Desktop;
# or inside HOME # or inside HOME
else cd $HOME; fi else cd $HOME; fi
notice "Tomb - simple commandline tool for encrypted storage"
act "version $VERSION ($DATE) by Jaromil @ dyne.org"
echo
notice "Guided creation of a new Tomb"
cat <<EOF cat <<EOF
Create a new Tomb
=================
A Tomb is a special folder that keeps files safe using a password: A Tomb is a special folder that keeps files safe using a password:
it makes use of strong encryption and helps you keep the keys on a it makes use of strong encryption and helps you keep the keys on a
@ -282,24 +291,24 @@ EOF
echo -n "> " echo -n "> "
read -q read -q
if [ "$?" != 0 ]; then if [ "$?" != 0 ]; then
echo "Operation aborted." error "Operation aborted."
exit 1 exit 1
fi fi
# let's proceed # let's proceed
echo " Please type in the name for your new tomb file:" notice "Please type in the name for your new tomb file:"
echo -n "> " echo -n "> "
read -u 1 tombname read -u 1 tombname
echo " How big you want the Tomb to be?" notice "How big you want the Tomb to be?"
echo " Type a size number in Megabytes:" act "Type a size number in Megabytes:"
echo -n "> " echo -n "> "
read -u 1 tombsize read -u 1 tombsize
if [[ "$tombsize" != <-> ]]; then if [[ "$tombsize" != <-> ]]; then
echo "Only digit allowed! Operation aborted" error "Only digit allowed! Operation aborted"
exit 1 exit 1
fi fi
clear clear
echo " You have commanded the creation of this Tomb:" notice "You have commanded the creation of this Tomb:"
echo " $tombname ( $tombsize MBytes )"; act "$tombname ( $tombsize MBytes )";
echo echo
cat <<EOF cat <<EOF
Please confirm if you want to proceed now: Please confirm if you want to proceed now:
@ -316,11 +325,11 @@ cat <<EOF
Considering 1GB takes usually little less than an hour to be digged. Considering 1GB takes usually little less than an hour to be digged.
EOF EOF
echo " Digging will take quite some time! Should we start? (y/n)" notice " Digging will take quite some time! Should we start? (y/n)"
echo -n "> " echo -n "> "
read -q read -q
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "Operation aborted." error "Operation aborted."
exit 1 exit 1
fi fi
cat <<EOF cat <<EOF
@ -332,7 +341,7 @@ tombfile=${tombname}.tomb
"${TOMBEXEC}" -s $tombsize create ${tombfile} "${TOMBEXEC}" -s $tombsize create ${tombfile}
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "An error occurred creating tomb, operation aborted." error "An error occurred creating tomb, operation aborted."
exit 1 exit 1
fi fi
@ -356,8 +365,8 @@ if [ $? = 0 ]; then
sudo cp -v ${tombfile}.key ${usbkey_mount}/.tomb/ sudo cp -v ${tombfile}.key ${usbkey_mount}/.tomb/
sudo chmod -R go-rwx ${usbkey_mount}/.tomb sudo chmod -R go-rwx ${usbkey_mount}/.tomb
echo "${tombname}.key succesfully saved on your USB" notice "${tombname}.key succesfully saved on your USB"
echo "now we'll proceed opening your brand new tomb" act "now we'll proceed opening your brand new tomb"
"${TOMBEXEC}" -k ${tombfile}.key open ${tombfile} "${TOMBEXEC}" -k ${tombfile}.key open ${tombfile}
if [ $? = 0 ]; then if [ $? = 0 ]; then