Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tabs/system-setup/5-samba-ssh-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ install_package() {
;;
esac
else
echo "$PACKAGE is already installed."
printf "%b\n" "${RED}$PACKAGE is already installed.${RC}"
fi
}

Expand Down
68 changes: 34 additions & 34 deletions tabs/utils/encrypt_decrypt_tool.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,39 @@ if ! command_exists openssl; then
*)
printf "%b\n" "${RED}Your Linux distribution is not supported by this script.${RC}"
printf "%b\n" "${YELLOW}You can try installing OpenSSL manually:${RC}"
echo "1. Refer to your distribution's documentation."
printf "1. Refer to your distribution's documentation.\n"
;;
esac
fi

show_menu() {
echo "========================================================"
echo " File/Directory Encryption/Decryption"
echo "========================================================"
echo "How to use:-"
echo "if you encrypt or decrypt a file include new file name for successful operation"
echo "if you encrypt or decrypt a folder include new directory name for successful operation"
echo "========================================================"
echo "1. Encrypt a file or directory"
echo "2. Decrypt a file or directory"
echo "3. Exit"
echo "========================================================"
printf "========================================================\n"
printf " File/Directory Encryption/Decryption\n"
printf "========================================================\n"
printf "How to use:-\n"
printf "if you encrypt or decrypt a file include new file name for successful operation\n"
printf "if you encrypt or decrypt a folder include new directory name for successful operation\n"
printf "========================================================\n"
printf "1. Encrypt a file or directory\n"
printf "2. Decrypt a file or directory\n"
printf "3. Exit\n"
printf "========================================================\n"
}

# Function to encrypt a file
encrypt_file() {
echo "Enter the path to the file or directory to encrypt:"
printf "Enter the path to the file or directory to encrypt:\n"
read -r INPUT_PATH

if [ ! -e "$INPUT_PATH" ]; then
echo "Path does not exist!"
printf "Path does not exist!\n"
return
fi

echo "Enter the path for the encrypted file or directory:"
printf "Enter the path for the encrypted file or directory:\n"
read -r OUTPUT_PATH

echo "Enter the encryption password:"
printf "Enter the encryption password:\n"
read -s -r PASSWORD

if [ -d "$INPUT_PATH" ]; then
Expand All @@ -65,41 +65,41 @@ encrypt_file() {
mkdir -p "$(dirname "$OUTPUT_FILE")"
openssl enc -aes-256-cbc -salt -pbkdf2 -in "$FILE" -out "$OUTPUT_FILE" -k "$PASSWORD"
if [ $? -eq 0 ]; then
echo "Encrypted: $OUTPUT_FILE"
printf "Encrypted: %s\n" "$OUTPUT_FILE"
else
echo "Failed to encrypt: $FILE"
printf "Failed to encrypt: %s\n" "$FILE"
fi
done
else
# Encrypt a single file
if [ -d "$OUTPUT_PATH" ]; then
echo "Output path must be a file for single file encryption."
printf "Output path must be a file for single file encryption.\n"
return
fi
mkdir -p "$(dirname "$OUTPUT_PATH")"
openssl enc -aes-256-cbc -salt -pbkdf2 -in "$INPUT_PATH" -out "$OUTPUT_PATH" -k "$PASSWORD"
if [ $? -eq 0 ]; then
echo "Encrypted: $OUTPUT_PATH"
printf "Encrypted: %s\n" "$OUTPUT_PATH"
else
echo "Failed to encrypt: $INPUT_PATH"
printf "Failed to encrypt: %s\n" "$INPUT_PATH"
fi
fi
}

# Function to decrypt a file
decrypt_file() {
echo "Enter the path to the file or directory to decrypt:"
printf "Enter the path to the file or directory to decrypt:\n"
read -r INPUT_PATH

if [ ! -e "$INPUT_PATH" ]; then
echo "Path does not exist!"
printf "Path does not exist!\n"
return
fi

echo "Enter the path for the decrypted file or directory:"
printf "Enter the path for the decrypted file or directory:\n"
read -r OUTPUT_PATH

echo "Enter the decryption password:"
printf "Enter the decryption password:\n"
read -s -r PASSWORD

if [ -d "$INPUT_PATH" ]; then
Expand All @@ -110,23 +110,23 @@ decrypt_file() {
mkdir -p "$(dirname "$OUTPUT_FILE")"
openssl enc -aes-256-cbc -d -pbkdf2 -in "$FILE" -out "$OUTPUT_FILE" -k "$PASSWORD"
if [ $? -eq 0 ]; then
echo "Decrypted: $OUTPUT_FILE"
printf "Decrypted: %s\n" "$OUTPUT_FILE"
else
echo "Failed to decrypt: $FILE"
printf "Failed to decrypt: %s\n" "$FILE"
fi
done
else
# Decrypt a single file
if [ -d "$OUTPUT_PATH" ]; then
echo "Output path must be a file for single file decryption."
printf "Output path must be a file for single file decryption.\n"
return
fi
mkdir -p "$(dirname "$OUTPUT_PATH")"
openssl enc -aes-256-cbc -d -pbkdf2 -in "$INPUT_PATH" -out "$OUTPUT_PATH" -k "$PASSWORD"
if [ $? -eq 0 ]; then
echo "Decrypted: $OUTPUT_PATH"
printf "Decrypted: %s\n" "$OUTPUT_PATH"
else
echo "Failed to decrypt: $INPUT_PATH"
printf "Failed to decrypt: %s\n" "$INPUT_PATH"
fi
fi
}
Expand All @@ -135,17 +135,17 @@ main(){
clear
while true; do
show_menu
echo "Enter your choice:"
printf "Enter your choice:\n"
read -r CHOICE

case $CHOICE in
1) encrypt_file ;;
2) decrypt_file ;;
3) echo "Exiting..."; exit 0 ;;
*) echo "Invalid choice. Please try again." ;;
3) printf "Exiting...\n"; exit 0 ;;
*) printf "Invalid choice. Please try again.\n" ;;
esac

echo "Press [Enter] to continue..."
printf "Press [Enter] to continue...\n"
read -r
done
}
Expand Down