Ver Fonte

Add _LUKS_OPEN function to encapsulate luksOpen logic

Vinicius Teshima há 10 meses atrás
pai
commit
81e1cb748a
1 ficheiros alterados com 8 adições e 5 exclusões
  1. 8 5
      luks.sh

+ 8 - 5
luks.sh

@@ -25,6 +25,12 @@ _MOUNT () {
 	echo "Succesfully Mounted ${1} into ${2}"
 }
 
+_LUKS_OPEN () {
+	echo "Opening Encrypted file: ${1} as ${2}"
+	TRY_AND_RETRY "${sudo_prog} cryptsetup luksOpen ${1} ${2}" "Failed to open luks file: ${1}."
+	echo "Succesfully Opened Encrypted file: ${1} as ${2}"
+}
+
 file_path="$1"
 test -n "$file_path" || { echo 'No file given'; exit 1; }
 file="$(basename "$file_path")"
@@ -94,9 +100,7 @@ else
 	TRY_AND_RETRY "cryptsetup luksFormat -c aes-xts-plain64 -s 512 -y ${file_path}" "Failed to format file: ${file_path}"
 	echo "Succesfully Encrypted file: ${file_path}"
 
-	echo "Opening Encrypted file: ${file_path} as ${_name}"
-	TRY_AND_RETRY "${sudo_prog} cryptsetup luksOpen ${file_path} ${_name}" "Failed to open luks file: ${file_path}."
-	echo "Succesfully Opened Encrypted file: ${file_path} as ${_name}"
+	_LUKS_OPEN "$file_path" "$_name"
 
 	echo "Formating ${_name} as ext4"
 	TRY_AND_RETRY "${sudo_prog} mkfs.ext4 -m0 ${block_dev}" "Failed to format block dev: ${block_dev}"
@@ -124,8 +128,7 @@ else
 	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
+_LUKS_OPEN "$file_path" "$_name"
 
 _MOUNT "$block_dev" "./${name}"