-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
196 lines (169 loc) · 4.88 KB
/
run.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
#!/bin/bash
red='\033[0;31m'
bblue='\033[0;34m'
yellow='\033[0;33m'
green='\033[0;32m'
plain='\033[0m'
red(){ echo -e "\033[31m\033[01m$1\033[0m";}
green(){ echo -e "\033[32m\033[01m$1\033[0m";}
yellow(){ echo -e "\033[33m\033[01m$1\033[0m";}
blue(){ echo -e "\033[36m\033[01m$1\033[0m";}
white(){ echo -e "\033[37m\033[01m$1\033[0m";}
bblue(){ echo -e "\033[34m\033[01m$1\033[0m";}
rred(){ echo -e "\033[35m\033[01m$1\033[0m";}
readtp(){ read -t5 -n26 -p "$(yellow "$1")" $2;}
readp(){ read -p "$(yellow "$1")" $2;}
cd
# Get/update spotbot
if [ ! -d "spotbot" ]; then
git clone https://github.com/hrostami/spotbot.git
else
cd spotbot
git pull origin
cd
fi
set_bot_credentials() {
if [ -f "spotbot/spotbot_config.pkl" ]; then
readp "Config already exists, do you want to replace it? (y/n): " choice
if [[ $choice =~ ^[Yy] ]]; then
:
else
return
fi
fi
yellow "--------------Getting credntials--------------"
python3 spotbot/set_cred.py
yellow "----------------------------------------------"
echo
readp "Press Enter to continue..."
}
get_spotbot_add_service() {
echo
yellow "Going to update and run SpotBot in the background..."
echo
if [ ! -f "spotbot/spotbot_config.pkl" ]; then
echo
rred "spotbot_config.pkl not found. Please set credentials..."
echo
set_bot_credentials
fi
sudo apt install python3-venv -y
clear
cd spotbot
if [ ! -d "spotbot-venv" ]; then
python3 -m venv spotbot-venv
fi
source spotbot-venv/bin/activate
pip install --upgrade python-telegram-bot==13.5 spotdl
if ! command -v ffmpeg &> /dev/null; then
sudo apt-get install -y ffmpeg
fi
clear
# Check if the script is run with superuser privileges
if [ "$EUID" -ne 0 ]; then
rred "Please run as root"
exit
fi
cd
SERVICE_NAME="spotbot"
if systemctl list-units --type=service | grep -q "\<$SERVICE_NAME\>"; then
yellow "Service '$SERVICE_NAME' exists."
systemctl restart spotbot
else
rred "Service '$SERVICE_NAME' does not exist."
USERNAME=$(logname)
GROUP=$(id -gn $USERNAME)
SERVICE_FILE="/etc/systemd/system/spotbot.service"
cat <<EOL > $SERVICE_FILE
[Unit]
Description=Spotbot Python Script
[Service]
ExecStart=$(pwd)/spotbot/spotbot-venv/bin/python3 $(pwd)/spotbot/spotbot.py
Restart=always
RestartSec=3
User=$USERNAME
Group=$GROUP
WorkingDirectory=$(pwd)/spotbot
[Install]
WantedBy=multi-user.target
EOL
systemctl daemon-reload
systemctl enable spotbot
systemctl start spotbot
fi
yellow "Service created as spotbot. You can now start and manage it using 'systemctl'."
}
print_menu() {
bblue " _____ __ ____ __ ";
bblue " / ___/ ____ ____ / /_ / __ ) ____ / /_";
bblue " \__ \ / __ \ / __ \ / __// __ |/ __ \ / __/";
bblue " ___/ // /_/ // /_/ // /_ / /_/ // /_/ // /_ ";
bblue "/____// .___/ \____/ \__//_____/ \____/ \__/ ";
bblue " /_/ ";
white " Created by Hosy "
white "----------------------------------------------"
white " Github: https://github.com/hrostami"
white " Twitter: https://twitter.com/hosy000"
echo
yellow "-------------------Menu------------------"
green "1. Set Credntials"
echo
green "2. Start SpotBot and create service"
echo
green "3. Restart SpotBot"
echo
green "4. Show log in real time"
echo
green "5. Stop SpotBot"
echo
red "0. Exit"
yellow "-----------------------------------------"
}
while true; do
clear
print_menu
readp "Enter your choice (1-5): " choice
case "$choice" in
1)
yellow "Going to create required credntials for you"
set_bot_credentials
;;
2)
echo
rred "Installing and creating service..."
get_spotbot_add_service
readp "Press Enter to continue..."
;;
3)
echo
rred "Restarting service..."
systemctl restart spotbot
echo
readp "Press Enter to continue..."
;;
4)
echo
rred "Showing log in real time. Press Ctrl+C to exit."
echo
sudo journalctl -u spotbot -f
echo
readp "Press Enter to continue..."
;;
5)
echo
rred "Stoping service..."
systemctl stop spotbot
echo
rred "Done!"
echo
readp "Press Enter to continue..."
;;
0)
echo "Exiting."
exit 0
;;
*)
echo "Invalid choice. Please choose a valid option."
;;
esac
done