-
Notifications
You must be signed in to change notification settings - Fork 4
/
restore.sh
82 lines (64 loc) · 1.79 KB
/
restore.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
#!/bin/bash
NOCOLOR="\033[0m"
GREEN="\033[0;32m"
RED="\033[0;31m"
update_scripts() {
echo -e "\n${GREEN}Updating the scripts...${NOCOLOR}\n"
if [ ! -d "scripts" ]; then
git clone https://github.com/scp-079/scripts.git scripts
cd scripts || exit
else
cd scripts || exit
git pull
fi
if [ ! -d "venv" ]; then
python3 -m venv venv
fi
source venv/bin/activate
pip install -U pip
pip install -U setuptools wheel
pip install -r requirements.txt
deactivate
cd ../
}
set_env() {
# shellcheck source=./env.sh
source ~/scp-079/scripts/env.sh
}
# Restore specific bot
if [ $# -eq 1 ];then
bot=$1
if [ ! -f ~/scp-079-"$bot".tar.gz ]; then
echo -e "\n${RED}File ~/scp-079-$bot.tar.gz does not exist!${NOCOLOR}\n"
return || exit
fi
echo -e "\n${GREEN}Restoring the bot ${bot^^}'s backup...${NOCOLOR}"
mkdir -p ~/scp-079
cd ~/scp-079 || return || exit
tar xf ~/scp-079-"$bot".tar.gz
update_scripts
echo -e "$bot\n$bot" | bash ~/scp-079/scripts/rebuild.sh
set_env
echo -e "${GREEN}Bot ${bot^^}'s backup restored!${NOCOLOR}\n"
return || exit
fi
# Restore all bots
if [ ! -f ~/scp-079.tar.gz ]; then
echo -e "\n${RED}File ~/scp-079.tar.gz does not exist!${NOCOLOR}\n"
return || exit
fi
echo -e "\n${GREEN}Restoring all bots' backup...${NOCOLOR}"
cd ~ || return || exit
tar xf ~/scp-079.tar.gz
cd ~/scp-079 || return || exit
update_scripts
shopt -s nullglob
for bot in ~/scp-079/*; do
bot=$(basename "$bot")
if [ "$bot" != "scripts" ] && [ "$bot" != "venv" ] && ! [[ "$bot" =~ ^(conda)$ ]]; then
echo -e "$bot\n$bot" | bash ~/scp-079/scripts/rebuild.sh
fi
done
shopt -u nullglob
set_env
echo -e "${GREEN}All bots' backup restored!${NOCOLOR}\n"