-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.sh
217 lines (175 loc) · 5.1 KB
/
build.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/bin/bash
NOCOLOR="\033[0m"
GREEN="\033[0;32m"
RED="\033[0;31m"
CONFIG_EXAMPLE_PATH="examples/config.ini"
CONFIG_PATH="data/config/config.ini"
JOIN_EXAMPLE_PATH="join.txt.example"
JOIN_PATH="join.txt"
REPORT_EXAMPLE_PATH="examples/report.txt"
REPORT_PATH="data/config/report.txt"
START_EXAMPLE_PATH="start.txt.example"
START_PATH="start.txt"
if [ "$(id -u)" -eq 0 ]; then
echo -e "\n${RED}Please DO NOT run the script as root user!${NOCOLOR}\n"
return || exit
fi
mkdir -p ~/scp-079
cd ~/scp-079 || exit
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" ] || [ ! -f "venv/bin/activate" ]; 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
}
project_config() {
echo ""
read -r -p "Project: " project
read -r -p "Name: " name
}
git_clone() {
echo -e "\n${GREEN}Cloning the project ${project^^}...${NOCOLOR}\n"
if [ ! -d "$name" ]; then
git clone https://github.com/scp-079/scp-079-"$project".git "$name"
cd "$name" || exit
else
cd "$name" || exit
git pull
fi
}
create_venv() {
if [ ! -d "venv" ] && [ "$project" != "noporn" ]; then
echo -e "\n${GREEN}Creating the virtual environment without system site packages...${NOCOLOR}"
python3 -m venv venv
elif [ ! -d "venv" ]; then
echo -e "\n${GREEN}Creating the virtual environment with system site packages...${NOCOLOR}"
python3 -m venv --system-site-packages venv
fi
echo -e "\n${GREEN}Installing the requirements...${NOCOLOR}\n"
source venv/bin/activate
pip install -U pip
pip install -U setuptools wheel
if [ "$project" == "tip" ]; then
pip install -U pybind11
fi
pip install -r requirements.txt
deactivate
}
bot_config() {
mkdir -p data/config
# TODO TEMP
if [ -f "examples/config.ini" ]; then
CONFIG_EXAMPLE_PATH="examples/config.ini"
CONFIG_PATH="data/config/config.ini"
else
CONFIG_EXAMPLE_PATH="config.ini.example"
CONFIG_PATH="config.ini"
fi
# TODO TEMP
if [ -f "examples/join.txt" ]; then
JOIN_EXAMPLE_PATH="examples/join.txt"
JOIN_PATH="data/config/join.txt"
else
JOIN_EXAMPLE_PATH="join.txt.example"
JOIN_PATH="join.txt"
fi
# TODO TEMP
if [ -f "examples/report.txt" ]; then
REPORT_EXAMPLE_PATH="examples/report.txt"
REPORT_PATH="data/config/report.txt"
else
REPORT_EXAMPLE_PATH="report.txt.example"
REPORT_PATH="report.txt"
fi
# TODO TEMP
if [ -f "examples/start.txt" ]; then
START_EXAMPLE_PATH="examples/start.txt"
START_PATH="data/config/start.txt"
else
START_EXAMPLE_PATH="start.txt.example"
START_PATH="start.txt"
fi
if [ ! -f "$CONFIG_PATH" ]; then
cp "$CONFIG_EXAMPLE_PATH" "$CONFIG_PATH"
fi
if [ ! -f ~/scp-079/scripts/config.ini ]; then
cp "$CONFIG_PATH" ~/scp-079/scripts/config.ini
fi
cd ~/scp-079/scripts || exit
source venv/bin/activate
python config.py "$name"
deactivate
cd ~/scp-079/"$name" || exit
bash ~/scp-079/scripts/config.sh "$name"
echo -e "\n${GREEN}Config updated!${NOCOLOR}\n"
if [ -f "$JOIN_EXAMPLE_PATH" ] && [ ! -f "$JOIN_PATH" ]; then
cp "$JOIN_EXAMPLE_PATH" "$JOIN_PATH"
fi
if [ -f "$JOIN_PATH" ]; then
vim "$JOIN_PATH"
echo -e "${GREEN}Join template updated!${NOCOLOR}\n"
fi
if [ -f "$REPORT_EXAMPLE_PATH" ] && [ ! -f "$REPORT_PATH" ]; then
cp "$REPORT_EXAMPLE_PATH" "$REPORT_PATH"
fi
if [ -f "$REPORT_PATH" ]; then
vim "$REPORT_PATH"
echo -e "${GREEN}Report template updated!${NOCOLOR}\n"
fi
if [ -f "$START_EXAMPLE_PATH" ] && [ ! -f "$START_PATH" ]; then
cp "$START_EXAMPLE_PATH" "$START_PATH"
fi
if [ -f "$START_PATH" ]; then
vim "$START_PATH"
echo -e "${GREEN}Start template updated!${NOCOLOR}\n"
fi
}
enable_service() {
mkdir -p ~/.config/systemd/user
echo "[Unit]
Description=SCP-079-${project^^} Telegram Bot ${name^^} Service
After=default.target
[Service]
WorkingDirectory=/home/$(whoami)/scp-079/$name
ExecStart=/home/$(whoami)/scp-079/$name/venv/bin/python -u main.py
Restart=always
RestartSec=15
[Install]
WantedBy=default.target" > ~/.config/systemd/user/"$name".service
echo -e "${GREEN}Enabling the systemd service...${NOCOLOR}\n"
systemctl --user daemon-reload
systemctl --user enable "$name"
}
build_begin() {
update_scripts
set_env
project_config
git_clone
create_venv
bot_config
enable_service
}
build_end() {
cd ~ || exit
echo "------------------------"
echo -e "\n${GREEN}Completed!${NOCOLOR}\n"
}
build_begin
build_end