#!/bin/bash # Required condition:ecryptfs is used. /home/USER_NAME/.Private is a symbolic link to /media/data/Encrypted. The encrypted files and directories in /media/data/Encrypted are decrypted in /media/data/Decrypted. Symbolic links are not copied to /media/data/Decrypted. curdir=$pwd langbackup=$LANG LANG=C dir1=/home/$USER/.Private dir2=/media/data/Encrypted dir3=/media/data/Decrypted if [ $USER != root ];then # User is ordinary user if [ -n "$(ls -l $dir1|grep ^l|grep $dir1' -> '$dir2)" ];then # $dir1 is a symbolic link to $dir2. if [ -z "$(mount|grep ^$dir1' on '$dir3' type ecryptfs')" ];then zenity --title="ecryptfs encrypt tool" --warning --text="$dir1 is not mounted on $dir3. I will mount." ecryptfs-mount-private if [ -z "$(mount|grep ^$dir1' on '$dir3' type ecryptfs')" ];then zenity --title="ecryptfs encrypt tool" --error --text="Mounting $dir1 on $dir3 failed. Aborted!" LANG=$langbackup exit 1 else zenity --title="ecryptfs encrypt tool" --info --text="$dir1 is successfully mounted on $dir3." fi fi zenity --title="ecryptfs encrypt tool" --info --text="Selcect files to be encrypted via ecryptfs in the next window" origin=$(zenity --title="ecryptfs encrypt tool" --file-selection --multiple --separator=" ") if [ $? = 1 ];then zenity --title="ecryptfs encrypt tool" --warning --text="This script is aborted because cancel is selected." LANG=$langbackup exit 1 fi for file in $origin;do if [ -z "$(echo "$file"|grep ^/)" ];then zenity --title="ecryptfs encrypt tool" --warning --text="There is no file named $file . I will skip this file." continue elif [ -f "$file" ];then file1="$file" elif [ -L "$file" ];then file1="$(readlink -eq $file)" zenity --title="ecryptfs encrypt tool" --warning --text="$file is a symbolic link. I will use $file1 instead." if [ -f "$file1" ];then : else zenity --title="ecryptfs encrypt tool" --warning --text="$file1 is not an ordinary file. I will skip this." continue fi else zenity --title="ecryptfs encrypt tool" --warning --text="$file is not an ordinary file. I will skip this." continue fi name1=$(basename $file1) operation1 () { cp -a $file1 $dir3/$1/$name1 || zenity --title="ecryptfs encrypt tool" --error --text="Copying $file1 to $dir3/$1/$name1 failed!" if [ -f $dir3/$1/$name1 ];then rm $file1 && (cd $(echo "$file1"|sed -e "s@[^/]*\$@@");ln -s $dir3/$1/$name1 $name1;zenity --title="ecryptfs encrypt tool" --info --text="$file1 = $file is encrypted and moved to $dir3/$1/$name1. Symbolic link $file1 is generated.") || zenity --title="ecryptfs encrypt tool" --error --text="Moving $file1 to $dir3/$1/$name1 failed! $file1 = $file is not encrypted!" cd $curdir else zenity --title="ecryptfs encrypt tool" --error --text="$file1 = $file is tried to be encrypted and copied to $dir3/$1/$name1. But, the generated $dir3/$1/$name1 is not an ordianary file." fi } dir4=1 while :;do if [ ! -e $dir3/$dir4/$name1 ];then operation1 $dir4 break else if [ $dir3/$dir4/$name1 = $file1 ];then zenity --title="ecryptfs encrypt tool" --info --text="$file is already encrypted as $dir3/$dir4/$name1." continue else dir4=$(expr 1 + $dir4) if [ ! -e $dir3/$dir4 ];then mkdir -p $dir3/$dir4 && zenity --title="ecryptfs encrypt tool" --info --text="$dir3/$dir4 is formed." fi if [ ! -d $dir3/$dir4 ];then zenity --title="ecryptfs encrypt tool" --error --text="$dir3/$dir4 is not a directory. $file = $file1 is not encrypted." break fi fi fi done done else # $dir1 is not a symbolic link to $dir2. zenity --title="ecryptfs encrypt tool" --error "$dir1 is not a symbolic link to $dir2. Aborted!" LANG=$langbackup exit 1 fi else # User is root. zenity --title="ecryptfs encrypt tool" --warning "Please execute me with a ordinary user account. Aborted!" LANG=$langbackup exit 1 fi LANG=$langbackup exit 0