-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencrypt.sh
executable file
·69 lines (57 loc) · 2.03 KB
/
encrypt.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
readonly DECRYPT_SCRIPT_RAW="https://raw.githubusercontent.com/zakattack9/encrypt-2FA-codes/master/decrypt.sh"
ENCRYPTED_ZIP="backup_codes.zip"
RECOVERY_CODES_DIR="./recovery_codes"
SETUP_CODES_DIR="./setup_codes"
MISC_DIR="./misc"
# set encrypted zip to passed in filename
if [ ! -z "$1" ]; then
ENCRYPTED_ZIP="$1.zip"
fi
if [ ! -d "$RECOVERY_CODES_DIR" ]; then
# prompt for recovery codes directory
read -e -p "Enter recovery codes directory to encrypt (use * for current directory or hit [ENTER] to skip): " RECOVERY_CODES_DIR
echo ""
fi
if [ ! -d "$SETUP_CODES_DIR" ]; then
# prompt for setup codes directory
read -e -p "Enter setup codes directory to encrypt (use * for current directory or hit [ENTER] to skip): " SETUP_CODES_DIR
echo ""
fi
if [ ! -d "$MISC_DIR" ]; then
MISC_DIR=""
fi
PASSWORD="0"
PASSWORD_VERIFY="1"
while [[ ! $PASSWORD == $PASSWORD_VERIFY ]]; do
# prompt for password to AES256 encrypt archive with
read -s -p "Enter encrypt password: " PASSWORD
# verify the inputted password
echo ""; read -s -p "Verify encrypt password: " PASSWORD_VERIFY
if [[ ! $PASSWORD == $PASSWORD_VERIFY ]]; then
printf "\nPasswords do not match, try again.\n"
fi
echo ""
done
# use 7-zip to encrypt specified directory
7za a -tzip "-p$PASSWORD" -mem=AES256 $ENCRYPTED_ZIP $SETUP_CODES_DIR $RECOVERY_CODES_DIR $MISC_DIR
# check if zip command ran successfully before deleting the setup and recovery codes folders
if [ $? -eq 0 ]; then
# remove plaintext setup and recovery codes folders
rm -rf $SETUP_CODES_DIR $RECOVERY_CODES_DIR $MISC_DIR
printf "\nEncrypted $SETUP_CODES_DIR and $RECOVERY_CODES_DIR successfully!!!\n"
if [ ! -f "./decrypt.sh" ]; then
printf "\nGenerating decrypt script...\n"
curl $DECRYPT_SCRIPT_RAW -o decrypt.sh
chmod +x decrypt.sh
fi
printf "\nDelete encrypt script?\n"
printf "Enter (y)es or (n)o: "
read CLEANUP
if [[ $CLEANUP == "y" ]]; then
printf "\nCleaning up...\n"
rm -- "$0"
fi
else
printf "\nFailed to encrypt the specified directories :(\n"
fi