|
|
@@ -19,29 +19,6 @@ sudo_prog='sudo --prompt=Sudo_Password:'
|
|
|
|
|
|
test "$ext" = 'luks' || ERR "File $file_path does not have extencion .luks." 1
|
|
|
|
|
|
-if test -e "$file_path"
|
|
|
-then
|
|
|
- test -f "$file_path" || ERR "${file_path} Is not a regular file" 1
|
|
|
-else
|
|
|
- echo -n "File ${file_path} does not exist. Want to create? (Y/n) "
|
|
|
- read choose
|
|
|
- case "$choose" in
|
|
|
- N|n) exit 1 ;;
|
|
|
- esac
|
|
|
-
|
|
|
- echo -n "What size? (10G) "
|
|
|
- read _size
|
|
|
- if test "$choose" = ''
|
|
|
- then
|
|
|
- _size='10G'
|
|
|
- fi
|
|
|
- truncate --size="$_size" "$file_path" || ERR "Failed to allocate file: ${file_path}" 1
|
|
|
-
|
|
|
- cryptsetup luksFormat -c aes-xts-plain64 -s 512 -y "$file_path" || ERR "Failed to format file: ${file_path}" 1
|
|
|
-
|
|
|
- echo "Successifuly create encrypted file: ${file_path}"
|
|
|
-fi
|
|
|
-
|
|
|
if test -e ./"$name"
|
|
|
then
|
|
|
test -d "./${name}" || ERR "File ${name} already exist in current directory. And is not a directory." 1
|
|
|
@@ -75,6 +52,61 @@ else
|
|
|
mkdir ./"$name"
|
|
|
fi
|
|
|
|
|
|
+if test -e "$file_path"
|
|
|
+then
|
|
|
+ test -f "$file_path" || ERR "${file_path} Is not a regular file" 1
|
|
|
+else
|
|
|
+ echo -n "File ${file_path} does not exist. Want to create? (Y/n) "
|
|
|
+ read choose
|
|
|
+ case "$choose" in
|
|
|
+ N|n) exit 1 ;;
|
|
|
+ esac
|
|
|
+
|
|
|
+ echo -n "What size? (10G) "
|
|
|
+ read _size
|
|
|
+ if test "$choose" = ''
|
|
|
+ then
|
|
|
+ _size='10G'
|
|
|
+ fi
|
|
|
+ truncate --size="$_size" "$file_path" || ERR "Failed to allocate file: ${file_path}" 1
|
|
|
+ echo "Succesfully Allocated file: ${file_path}"
|
|
|
+
|
|
|
+ echo "Encrypting file: ${file_path}"
|
|
|
+ cryptsetup luksFormat -c aes-xts-plain64 -s 512 -y "$file_path" || ERR "Failed to format file: ${file_path}" 1
|
|
|
+ echo "Succesfully Encrypted file: ${file_path}"
|
|
|
+
|
|
|
+ echo "Opening Encrypted file: ${file_path} as ${_name}"
|
|
|
+ $sudo_prog cryptsetup luksOpen "$file_path" "$_name" || ERR "Failed to open luks file: ${file_path}." 1
|
|
|
+ echo "Succesfully Opened Encrypted file: ${file_path} as ${_name}"
|
|
|
+
|
|
|
+ echo "Formating ${_name} as ext4"
|
|
|
+ $sudo_prog mkfs.ext4 -m0 "$block_dev" || ERR "Failed to format block dev: ${block_dev}" 1
|
|
|
+ echo "Succesfully Formated ${_name} as ext4"
|
|
|
+
|
|
|
+ echo "Mounting ${block_dev} into ./${name}"
|
|
|
+ $sudo_prog mount "$block_dev" ./"$name" || ERR "Failed to mound ${block_dev} on ./${name}." 1
|
|
|
+ echo "Succesfully Mounted ${block_dev} into ./${name}"
|
|
|
+
|
|
|
+ dir_perm="$(stat -c '%u:%g' "$file_path")"
|
|
|
+ cur_perm="${cur_uid}:${cur_gid}"
|
|
|
+ if ! test "$dir_perm" = "$cur_perm"
|
|
|
+ then
|
|
|
+ (
|
|
|
+ echo -n "Directory ./${name} not owned by current user. Want to change direcory owner? (Y/n) "
|
|
|
+ read choose
|
|
|
+ case "$choose" in
|
|
|
+ N|n) exit 0 ;;
|
|
|
+ esac
|
|
|
+ echo "Changing ownership of ./${name} from ${dir_perm} to ${cur_perm}."
|
|
|
+ $sudo_prog chown "$cur_perm" ./"$name" || ERR "Failed to change permission of directory ./${name} from ${dir_perm} to ${cur_perm}." 1
|
|
|
+ ) || exit 1
|
|
|
+ fi
|
|
|
+
|
|
|
+ echo "Succesfully Created and Opened file: ${file_path} into ./${name}"
|
|
|
+
|
|
|
+ exit 0
|
|
|
+fi
|
|
|
+
|
|
|
echo "Opening luks file: ${file_path} as ${_name}."
|
|
|
$sudo_prog cryptsetup luksOpen "$file_path" "$_name" || ERR "Failed to open luks file: ${file_path}." 1
|
|
|
|