Tomb/src/tomb-open

156 lines
4.4 KiB
Plaintext
Raw Normal View History

2011-02-10 11:22:11 +00:00
#!/bin/zsh
#
# Tomb, the Crypto Undertaker
#
# a tool to easily operate file encryption of private and secret data
#
# Copyleft (C) 2007-2011 Denis Roio <jaromil@dyne.org>
#
# This source code is free software; you can redistribute it and/or
# modify it under the terms of the GNU Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This source code is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# Please refer to the GNU Public License for more details.
#
# You should have received a copy of the GNU Public License along with
# this source code; if not, write to:
# Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# startup wrapper to open tombs
2011-02-09 19:35:11 +00:00
echo "arg: $1"
try() {
which ${1} > /dev/null
if [ $? = 0 ]; then return 0;
else return -1; fi
}
2011-02-09 19:35:11 +00:00
# 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
2011-02-09 19:35:11 +00:00
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
2011-02-09 19:35:11 +00:00
# no argument but on graphical display: creation dialog
if [ -z $DISPLAY ]; then
echo "[!] tomb-open is a wrapper for the command 'tomb'"
tomb -h
exit 1
fi
2011-02-09 19:35:11 +00:00
# no arguments: start guided tomb creation
tomb notify
cat <<EOF
Create a new Tomb
=================
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
separate USB storage for safer transports.
Inside a Tomb you can store private informations without fear that
other people possessing it will discover your secrets, unless they
have your USB key and your password.
If you choose to proceed now, we'll guide you through the creation
of a new Tomb. You will need the super-user (sudo) password for the
computer you are using, as well time available: depending how big
your tomb will be, make sure you are not running low on batteries,
considering 1GB takes little little less than an hour to be digged.
If you will, I'll be your Crypto Undertaker.
Do you want to proceed, Master? (y/n)
EOF
echo -n "> "
read -q
if [ $? != 0 ]; then
echo "Operation aborted."
exit 1
fi
# let's proceed
echo " Please type in the name for your new tomb file:"
echo -n "> "
read filename
echo " How big you want the Tomb to be?"
echo " Type a size number in Megabytes:"
echo -n "> "
read size
echo " You have commanded the creation of this Tomb:"
echo " $filename ( $size MBytes )";
echo
echo " Please confirm if you want to proceed now,"
echo " digging will take quite some time! (y/n)"
echo -n "> "
read -q
if [ $? != 0 ]; then
echo "Operation aborted."
exit 1
fi
cat <<EOF
Operation confirmed! we will now call the undertaker to do its
job, but in order to do so you will need to provide your sudo
password:
EOF
tomb create ${filename}.tomb $size
if [ $? != 0 ]; then
echo "An error occurred creating tomb, operation aborted."
exit 1
fi
2011-02-09 19:35:11 +00:00
# if ! [ -r /usr/share/applications/tomb.desktop ]; then
# echo " Well done!"
# echo " Now the last thing to do is to install Tomb on your desktop:"
# sudo tomb install
# fi