diff --git a/src/tomb-open b/src/tomb-open index e940a9f..6917f62 100755 --- a/src/tomb-open +++ b/src/tomb-open @@ -1,4 +1,4 @@ -#!/bin/zsh +#!/bin/zsh -x # # Tomb, the Crypto Undertaker # @@ -23,48 +23,63 @@ # startup wrapper to open tombs +echo "arg: $1" + try() { which ${1} > /dev/null if [ $? = 0 ]; then return 0; else return -1; fi } -# if no arguments are given, run in terminal -if [ -z $1 ]; then - try gnome-terminal; if [ $? = 0 ]; then gnome-terminal -e "tomb-open create"; exit 0; fi - try lxterm; if [ $? = 0 ]; then lxterm -bg black -fg white -e "tomb-open create"; exit 0; fi - try urxvt; if [ $? = 0 ]; then urxvt -bg black -fg white -e "tomb-open create"; exit 0; fi - try uxterm; if [ $? = 0 ]; then uxterm -bg black -fg white -e "tomb-open create"; exit 0; fi - try xterm; if [ $? = 0 ]; then xterm -bg black -fg white -e "tomb-open create"; exit 0; fi - exit 1 -fi -# got a directory as argument -if [ -d $1 ]; then + +# got an argument +if [ $1 ]; then +# is it a tomb? + arg="${1%%\.*}.tomb" + + if [ -f $arg ]; then + file $arg | grep LUKS + + if [ $? = 0 ]; then # tomb is a valid LUKS file + + tomb mount $arg + + if [ $? = 0 ]; then # mount was succesfull (with password and all) + # strip extension if there + tombname="${arg%%.*}" + tombmap=`mount -l | awk "/\[${tombname}\]$/"' { print $1 } '` + tombmount=`mount -l | awk "/\[${tombname}\]$/"' { print $3 } '` + tomb-status $tombmap $tombname $tombmount &! + exit 0 + else + tomb notify "Tomb cannot open." "Are you knocking the wrong door?" + exit 1 + fi + else + tomb notify "Not a real Tomb." "We found no real bones in there." + exit 1 + fi + + + elif [ -d $1 ]; then + # its a directory + # FIXME: somehow xdg-open loses mailcap mimes when executed by tomb-status # try xdg-open; if [ $? = 0 ]; then xdg-open ${1}; exit 0; fi - try gnome-open; if [ $? = 0 ]; then gnome-open ${1}; exit 0; fi - try thunar; if [ $? = 0 ]; then thunar ${1}; exit 0; fi - try rox; if [ $? = 0 ]; then rox ${1}; exit 0; fi - try fsviewer; if [ $? = 0 ]; then fsviewer ${1}; exit 0; fi - try xnc; if [ $? = 0 ]; then xnc ${1}; exit 0; fi - tomb notify "File manager not found." "Tomb cannot guess which filemanager you are using" - exit 1 -fi - -# got a tomb as argument? -if [ -f $1 ]; then - file $1 | grep LUKS - if [ $? = 0 ]; then - tomb mount $1 - exit $? - else - tomb notify "Not a real Tomb." "We found no real bones in there." + try gnome-open; if [ $? = 0 ]; then gnome-open ${1}; exit 0; fi + try thunar; if [ $? = 0 ]; then thunar ${1}; exit 0; fi + try pcmanfm; if [ $? = 0 ]; then pcmanfm ${1}; exit 0; fi + try rox; if [ $? = 0 ]; then rox ${1}; exit 0; fi + try fsviewer; if [ $? = 0 ]; then fsviewer ${1}; exit 0; fi +# try xnc; if [ $? = 0 ]; then xnc ${1}; exit 0; fi + tomb notify "File manager not found." "Tomb cannot guess which filemanager you are using" exit 1 fi fi + # no argument but on graphical display: creation dialog if [ -z $DISPLAY ]; then echo "[!] tomb-open is a wrapper for the command 'tomb'" @@ -72,11 +87,7 @@ if [ -z $DISPLAY ]; then exit 1 fi -if [ "$1" != "create" ]; then - exit 0 -fi - -# start guided tomb creation +# no arguments: start guided tomb creation tomb notify cat < 0; c++) + map[c] = buf; + close(pipefd[0]); + map[c] = 0; + execlp("tomb-open", "tomb-open", map, (char*)NULL); + _exit(1); } + close(pipefd[0]); // close unused read end + write(pipefd[1], mountpoint, strlen(mountpoint)); + close(pipefd[1]); // reader will see EOF + return TRUE; } + gboolean cb_close(GtkWidget *w, GdkEvent *e) { int pipefd[2]; pid_t cpid; @@ -189,7 +201,7 @@ gboolean cb_close(GtkWidget *w, GdkEvent *e) { for(c=0; read(pipefd[0], &buf, 1) > 0; c++) map[c] = buf; close(pipefd[0]); - map[c] = '\n'; + map[c] = 0; execlp("tomb", "tomb", "close", map, (char*)NULL); _exit(1); } @@ -257,3 +269,12 @@ gboolean cb_about(GtkWidget *w, GdkEvent *e) { } + // GtkWidget *dialog = + // gtk_message_dialog_new (NULL, + // GTK_DIALOG_DESTROY_WITH_PARENT, + // GTK_MESSAGE_INFO, + // GTK_BUTTONS_CLOSE, + // "Tomb '%s' open on '%s'\n" + // "device mapper: %s", filename, mountpoint, mapper); + // gtk_dialog_run (GTK_DIALOG (dialog)); + // gtk_widget_destroy (dialog);