-
Notifications
You must be signed in to change notification settings - Fork 4
/
restore_debug.sh
160 lines (143 loc) · 5.86 KB
/
restore_debug.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env bash
######################################################################################
# Title: Cloudbox Restore Service: Restore Script #
# Author(s): l3uddz, desimaniac #
# URL: https://github.com/Cloudbox/Cloudbox #
# Description: Restores encrypted config files from Cloudbox Restore Service. #
# -- #
# Part of the Cloudbox project: https://cloudbox.works #
######################################################################################
# GNU General Public License v3.0 #
######################################################################################
# Usage: #
# ====== #
# Simple: #
# curl -s https://cloudbox.works/scripts/restore.sh | bash -s 'USER' 'PASS' #
# wget -qO- https://cloudbox.works/scripts/restore.sh | bash -s 'USER' 'PASS' #
# #
# Custom Cloudbox Path: #
# curl -s https://cloudbox.works/scripts/restore.sh | bash -s 'USER' 'PASS' 'PATH' #
# wget -qO- https://cloudbox.works/scripts/restore.sh | bash -s 'USER' 'PASS' 'PATH' #
######################################################################################
# vars
files=( "ansible.cfg" "accounts.yml" "settings.yml" "adv_settings.yml" "backup_config.yml" "rclone.conf" )
restore="restore.cloudbox.works"
folder="$HOME/.restore_service_tmp"
green="\e[1;32m"
red="\e[1;31m"
nc="\e[0m"
done="[ ${green}DONE${nc} ]"
fail="[ ${red}FAIL${nc} ]"
# Print banner
echo -e "
$green┌─────────────────────────────────────────────────────────────────────┐
$green│ Title: Cloudbox Restore Service: Restore Script │
$green│ Author(s): l3uddz, desimaniac │
$green│ URL: https://github.com/cloudbox/cloudbox │
$green│ Description: Restores encrypted config files from the │
$green│ Cloudbox Restore Service. │
$green├─────────────────────────────────────────────────────────────────────┤
$green│ Part of the Cloudbox project: https://cloudbox.works │
$green├─────────────────────────────────────────────────────────────────────┤
$green│ GNU General Public License v3.0 │
$green└─────────────────────────────────────────────────────────────────────┘
$nc"
# inputs
USER=$1
echo $USER
PASS=$2
echo $PASS
DIR=${3:-$HOME/cloudbox}
echo $DIR
# validate inputs
if [ -z "$USER" ] || [ -z "$PASS" ]
then
echo "You must provide the USER & PASS as arguments"
exit 1
fi
# validate folders exist
TMP_FOLDER_RESULT=$(mkdir -p $folder)
if [ ! -z "$TMP_FOLDER_RESULT" ]
then
echo "Failed to ensure $folder was created..."
exit 1
else
rm -rf $folder/*
fi
RESTORE_FOLDER_RESULT=$(mkdir -p $DIR)
if [ ! -z "$RESTORE_FOLDER_RESULT" ]
then
echo "Failed to ensure $DIR was created..."
exit 1
fi
# SHA1 username
USER_HASH=$(echo -n "$USER" | openssl dgst -sha1 | sed 's/^.*= //')
echo "User Hash: $USER_HASH"
echo ''
# Fetch files
echo "Fetching files from $restore..."
echo ''
for file in "${files[@]}"
do
:
# wget file
printf '%-20.20s' "$file"
echo wget -qO $folder/$file.enc http://$restore/load/$USER_HASH/$file
wget -qO $folder/$file.enc http://$restore/load/$USER_HASH/$file
echo head -c 10 $folder/$file.enc | tr -d '\0'
head -c 10 $folder/$file.enc | tr -d '\0'
file_header=$(head -c 10 $folder/$file.enc | tr -d '\0')
# is the file encrypted?
if [[ $file_header == Salted* ]]
then
echo -e $done
else
echo -e $fail
exit 1
fi
done
echo ''
# Decrypt files
echo 'Decrypting fetched files...'
echo ''
for file in "${files[@]}"
do
:
# wget file
printf '%-20.20s' "$file"
echo openssl enc -aes-256-cbc -d -salt -md md5 -in $folder/$file.enc -out $folder/$file -k "$PASS"
openssl enc -aes-256-cbc -d -salt -md md5 -in $folder/$file.enc -out $folder/$file -k "$PASS"
DECRYPT_RESULT=$?
# was the file decryption successful?
if [[ $DECRYPT_RESULT == 0 ]]
then
echo -e $done
else
echo -e $fail
exit 1
fi
done
echo ''
# Move decrypted files
echo 'Moving decrypted files...'
echo ''
for file in "${files[@]}"
do
:
# move file
printf '%-20.20s' "$file"
echo mv $folder/$file $DIR/$file
mv $folder/$file $DIR/$file
MOVE_RESULT=$?
# was the decrypted file moved successfully?
if [[ $MOVE_RESULT == 0 ]]
then
echo -e $done
else
echo -e $fail
exit 1
fi
done
echo ''
# finish
exit 0