|
@@ -1,6 +1,7 @@
|
|
|
#!/bin/bash
|
|
|
#/##################################################################\
|
|
|
-#| Basic scrypt to automount Encrypted Dropbox with CryFS. |
|
|
|
+#| Basic scrypt to encrypt with CryFS file hosting services like |
|
|
|
+#| Dropbox, MEGA, Drive, etc. |
|
|
|
#| Guzmán Castanedo (guzman@castanedo.es) |
|
|
|
#| November 2016 |
|
|
|
#| Licence: GPL 3.0 -> https://www.gnu.org/licenses/gpl-3.0.en.html |
|
|
@@ -13,15 +14,19 @@
|
|
|
|
|
|
#Functions
|
|
|
function usage {
|
|
|
- printf "USAGE:\t"$(basename "$0")" [OPTIONS]\n"
|
|
|
+ printf "USAGE:\t"$(basename "$0")" [OPTIONS] name\n"
|
|
|
+ printf "NAME:\n"
|
|
|
+ printf "\tSet the automount name (without spaces).\n"
|
|
|
+ printf "\tIt's usefull if you wanty to encrypt more than one file hosting service.\n"
|
|
|
+ printf "\tThis parameter is OBLIGATORY.\n"
|
|
|
printf "OPTIONS:\n"
|
|
|
printf "\t-b, --basedir basedir\n"
|
|
|
printf "\t\tSet the encrypted folder that Dropbox client are going to\n"
|
|
|
printf "\t\tupload.\n"
|
|
|
- printf "\t\tDefault: /home/$USER/.DropboxEncrypted/Dropbox/ENCRYPTED\n"
|
|
|
+ printf "\t\tDefault: /home/$USER/.MegaEncrypted/ENCRYPTED\n"
|
|
|
printf "\t-m, --mountdir mountdir\n"
|
|
|
printf "\t\tSet the decrypted folder.\n"
|
|
|
- printf "\t\tDefault: /home/$USER/Dropbox\n"
|
|
|
+ printf "\t\tDefault: /home/$USER/MEGA\n"
|
|
|
printf "\t-v, --verbose\n"
|
|
|
printf "\t\tSet verbose mode.\n"
|
|
|
printf "\t\tDefault: false\n"
|
|
@@ -48,20 +53,29 @@ function usage {
|
|
|
}
|
|
|
|
|
|
function createautostart {
|
|
|
- #createautostart $basedir $mountdir $cryfsconfig $pass
|
|
|
- if [ ! $# -eq 4 ];then
|
|
|
+ #createautostart $basedir $mountdir $cryfsconfig $pass $name
|
|
|
+ if [ ! $# -eq 5 ];then
|
|
|
echo "ERROR: Internal error generating autostart file."
|
|
|
exit 1
|
|
|
fi
|
|
|
- startfile=/home/$USER/.config/autostart/cryfs-dropbox.desktop
|
|
|
+ startfile=/home/$USER/.config/autostart/cryfs-$5.desktop
|
|
|
if [ ! -d /home/$USER/.config/autostart ]; then
|
|
|
#Create directory (parents if needed)
|
|
|
mkdir -p /home/$USER/.config/autostart
|
|
|
fi
|
|
|
- #Not necessary to check existance because we're going to overwrite
|
|
|
+ #Need to check existance because we're going to overwrite
|
|
|
+ if [ -f $startfile ];then
|
|
|
+ grep "Exec=$(basename "$0") -b $1 -m $2 -c $3 -p $4 $5" $startfile > /dev/null
|
|
|
+ if [ $? -ne 0 ];then
|
|
|
+ printpaths $name $basedir $mountdir $cryfsconfig
|
|
|
+ printf "\nERROR:\tThere is another $(basename "$0") using that name (%s).\n" $5
|
|
|
+ printf "\tUse a diferent name.\n"
|
|
|
+ exit 1
|
|
|
+ fi
|
|
|
+ fi
|
|
|
echo "[Desktop Entry]" | tee $startfile > /dev/null
|
|
|
echo "Type=Application" | tee -a $startfile > /dev/null
|
|
|
- echo "Exec=cryfs-dropbox -b $1 -m $2 -c $3 -p $4" | tee -a $startfile > /dev/null
|
|
|
+ echo "Exec=$(basename "$0") -b $1 -m $2 -c $3 -p $4 $5" | tee -a $startfile > /dev/null
|
|
|
echo "X-GNOME-Autostart-enabled=true" | tee -a $startfile > /dev/null
|
|
|
echo "NoDisplay=false" | tee -a $startfile > /dev/null
|
|
|
echo "Hidden=false" | tee -a $startfile > /dev/null
|
|
@@ -71,17 +85,18 @@ function createautostart {
|
|
|
}
|
|
|
|
|
|
function printpaths {
|
|
|
- #printpaths $basedir $mountdir $cryfsconfig
|
|
|
- printf "Base Dir:\t%s\n" $1
|
|
|
- printf "Mount Dir:\t%s\n" $2
|
|
|
- printf "CryFS Dir:\t%s\n" $3
|
|
|
+ #printpaths $name $basedir $mountdir $cryfsconfig
|
|
|
+ printf "Name:\t\t%s\n" $1
|
|
|
+ printf "Base Dir:\t%s\n" $2
|
|
|
+ printf "Mount Dir:\t%s\n" $3
|
|
|
+ printf "CryFS Dir:\t%s\n" $4
|
|
|
echo
|
|
|
}
|
|
|
|
|
|
#Bash main
|
|
|
export CRYFS_FRONTEND=noninteractive
|
|
|
-basedir=/home/$USER/.DropboxEncrypted/Dropbox/ENCRYPTED
|
|
|
-mountdir=/home/$USER/Dropbox
|
|
|
+basedir=/home/$USER/.MegaEncrypted/ENCRYPTED
|
|
|
+mountdir=/home/$USER/MEGA
|
|
|
blocksize=524288
|
|
|
verbose=false
|
|
|
startlogin=true
|
|
@@ -118,7 +133,7 @@ while true; do
|
|
|
-h|--help)
|
|
|
#Help
|
|
|
usage
|
|
|
- exit
|
|
|
+ exit 0
|
|
|
;;
|
|
|
-c|--config)
|
|
|
#CryFS Config File
|
|
@@ -152,6 +167,12 @@ while true; do
|
|
|
esac
|
|
|
done
|
|
|
|
|
|
+if [ ! $# -eq 1 ]; then
|
|
|
+ echo "ERROR: You must set only one name for the installation"
|
|
|
+ exit 1
|
|
|
+fi
|
|
|
+name=$1
|
|
|
+
|
|
|
#Check if cryfs is installed
|
|
|
if [ ! -x /usr/local/bin/cryfs ]; then
|
|
|
echo "ERROR: CryFS is not installed."
|
|
@@ -159,13 +180,13 @@ if [ ! -x /usr/local/bin/cryfs ]; then
|
|
|
exit 1
|
|
|
fi
|
|
|
|
|
|
-#Check if cryfs-dropbox is installed
|
|
|
+#Check if cryfs-automount is installed
|
|
|
if [ ! -x /usr/local/bin/$(basename "$0") ]; then
|
|
|
echo "WARNING: "$(basename "$0")" is not installed."
|
|
|
echo "We'll use root access only for installation."
|
|
|
test=$(sudo whoami)
|
|
|
if [ $test = "root" ]; then
|
|
|
- sudo cp ./$(basename "$0") /usr/local/bin/
|
|
|
+ sudo cp ./$0 /usr/local/bin/
|
|
|
sudo chmod +x /usr/local/bin/$(basename "$0")
|
|
|
else
|
|
|
echo "ERROR: No root access!"
|
|
@@ -177,13 +198,13 @@ fi
|
|
|
|
|
|
#Check if directories exist
|
|
|
if [ ! -d $basedir ]; then
|
|
|
- printpaths $basedir $mountdir $cryfsconfig
|
|
|
+ printpaths $name $basedir $mountdir $cryfsconfig
|
|
|
echo "ERROR: $basedir is not a directory."
|
|
|
exit 1
|
|
|
fi
|
|
|
|
|
|
if [ ! -d $mountdir ]; then
|
|
|
- printpaths $basedir $mountdir $cryfsconfig
|
|
|
+ printpaths $name $basedir $mountdir $cryfsconfig
|
|
|
echo "ERROR: $mountdir is not a directory."
|
|
|
exit 1
|
|
|
fi
|
|
@@ -196,14 +217,14 @@ fi
|
|
|
if [ ! -f $cryfsconfig ]; then
|
|
|
#Config file doesn't exist
|
|
|
if [ $newvolume = false ]; then
|
|
|
- printpaths $basedir $mountdir $cryfsconfig
|
|
|
+ printpaths $name $basedir $mountdir $cryfsconfig
|
|
|
echo "ERROR: $cryfsconfig doesn't exist."
|
|
|
echo "If this is a new volume enter the tag: --new-volume"
|
|
|
exit 1
|
|
|
fi
|
|
|
else
|
|
|
if [ $newvolume = true ]; then
|
|
|
- printpaths $basedir $mountdir $cryfsconfig
|
|
|
+ printpaths $name $basedir $mountdir $cryfsconfig
|
|
|
echo "ERROR: Volume exists."
|
|
|
echo "If you want to load it, remove the tag: --new-volume"
|
|
|
exit 1
|
|
@@ -217,7 +238,7 @@ cryfsconfig=$(realpath $cryfsconfig)
|
|
|
|
|
|
#Verbose
|
|
|
if [ $verbose = true ];then
|
|
|
- printpaths $basedir $mountdir $cryfsconfig
|
|
|
+ printpaths $name $basedir $mountdir $cryfsconfig
|
|
|
fi
|
|
|
|
|
|
#Check if password is set
|
|
@@ -253,9 +274,10 @@ if [ $startlogin = true ]; then
|
|
|
if [ $verbose = true ];then
|
|
|
printf "Creating start at login.........\t"
|
|
|
fi
|
|
|
- createautostart $basedir $mountdir $cryfsconfig $pass
|
|
|
+ createautostart $basedir $mountdir $cryfsconfig $pass $name
|
|
|
if [ $verbose = true ];then
|
|
|
printf "Done!\n"
|
|
|
+ printf "File: %s\n" "/home/$USER/.config/autostart/cryfs-$name.desktop"
|
|
|
fi
|
|
|
fi
|
|
|
|