-
Notifications
You must be signed in to change notification settings - Fork 18
/
start_linux.sh
executable file
·191 lines (172 loc) · 5.64 KB
/
start_linux.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
#!/bin/bash
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$ID
elif type lsb_release &> /dev/null; then
OS=$(lsb_release -si | tr '[:upper:]' '[:lower:]')
elif [ "$(uname -o)" == "Android" ]; then
OS="android"
elif [ "$(uname)" == "Darwin" ]; then
OS="darwin"
elif [ -f /etc/debian_version ]; then
OS="debian"
elif [ -f /etc/fedora-release ]; then
OS="fedora"
elif [ -f /etc/centos-release ]; then
OS="centos"
else
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
fi
PACKAGE_MANAGER=""
if [ "$OS" == "ubuntu" ] || [ "$OS" == "debian" ]; then
PACKAGE_MANAGER="apt"
elif [ "$OS" == "fedora" ] || [ "$OS" == "centos" ]; then
PACKAGE_MANAGER="yum"
elif [ "$OS" == "darwin" ]; then
PACKAGE_MANAGER="brew"
elif [ "$OS" == "android" ]; then
PACKAGE_MANAGER="pkg"
fi
PACKAGE_MANAGER_UPDATE=""
if [ "$PACKAGE_MANAGER" == "apt" ]; then
PACKAGE_MANAGER_UPDATE="sudo apt update"
elif [ "$PACKAGE_MANAGER" == "yum" ]; then
PACKAGE_MANAGER_UPDATE="sudo yum update"
elif [ "$PACKAGE_MANAGER" == "brew" ]; then
PACKAGE_MANAGER_UPDATE="brew update"
elif [ "$PACKAGE_MANAGER" == "pkg" ]; then
PACKAGE_MANAGER_UPDATE="pkg update"
fi
PACKAGE_MANAGER_UPGRADE=""
if [ "$PACKAGE_MANAGER" == "apt" ]; then
PACKAGE_MANAGER_UPGRADE="sudo apt upgrade -y"
elif [ "$PACKAGE_MANAGER" == "yum" ]; then
PACKAGE_MANAGER_UPGRADE="sudo yum upgrade -y"
elif [ "$PACKAGE_MANAGER" == "brew" ]; then
PACKAGE_MANAGER_UPGRADE="brew upgrade"
elif [ "$PACKAGE_MANAGER" == "pkg" ]; then
PACKAGE_MANAGER_UPGRADE="pkg upgrade -y"
fi
PACKAGE_MANAGER_INSTALL=""
if [ "$PACKAGE_MANAGER" == "apt" ]; then
PACKAGE_MANAGER_INSTALL="sudo apt install -y"
elif [ "$PACKAGE_MANAGER" == "yum" ]; then
PACKAGE_MANAGER_INSTALL="sudo yum install -y"
elif [ "$PACKAGE_MANAGER" == "brew" ]; then
PACKAGE_MANAGER_INSTALL="brew install"
elif [ "$PACKAGE_MANAGER" == "pkg" ]; then
PACKAGE_MANAGER_INSTALL="pkg install -y"
fi
if ! command -v git &> /dev/null; then
echo "Git is not installed. Please install Git and try again."
if [ $PACKAGE_MANAGER == "" ]; then
exit 1
fi
echo "Do you want to install Git? (y/n)"
read -r INSTALL_GIT
if [ "$INSTALL_GIT" == "y" ]; then
echo "Running command: $PACKAGE_MANAGER_UPDATE"
$PACKAGE_MANAGER_UPDATE
echo "Running command: $PACKAGE_MANAGER_UPGRADE"
$PACKAGE_MANAGER_UPGRADE
echo "Running command: $PACKAGE_MANAGER_INSTALL git"
$PACKAGE_MANAGER_INSTALL git
else
exit 1
fi
fi
PIP=""
PYTHON=""
if command -v python3 &> /dev/null; then
PYTHON=python3
elif command -v python &> /dev/null; then
PYTHON=python
else
echo "Python is not installed. Please install Python and try again."
if [ $PACKAGE_MANAGER == "" ]; then
exit 1
fi
echo "Do you want to install Python? (y/n)"
read -r INSTALL_PYTHON
if [ "$INSTALL_PYTHON" == "y" ]; then
echo "Running command: $PACKAGE_MANAGER_UPDATE"
$PACKAGE_MANAGER_UPDATE
echo "Running command: $PACKAGE_MANAGER_UPGRADE"
$PACKAGE_MANAGER_UPGRADE
echo "Running command: $PACKAGE_MANAGER_INSTALL python3"
$PACKAGE_MANAGER_INSTALL python3
PYTHON=python3
else
exit 1
fi
fi
if command -v pip3 &> /dev/null; then
PIP=pip3
elif command -v pip &> /dev/null; then
PIP=pip
else
echo "Pip is not installed. Please install Pip and try again."
if [ $PACKAGE_MANAGER == "" ]; then
exit 1
fi
echo "Do you want to install Pip? (y/n)"
read -r INSTALL_PIP
if [ "$INSTALL_PIP" == "y" ]; then
echo "Running command: $PACKAGE_MANAGER_UPDATE"
$PACKAGE_MANAGER_UPDATE
echo "Running command: $PACKAGE_MANAGER_UPGRADE"
$PACKAGE_MANAGER_UPGRADE
if [ "$OS" == "arch" ]; then
echo "Running command: $PACKAGE_MANAGER_INSTALL python-pip"
$PACKAGE_MANAGER_INSTALL python-pip
else
echo "Running command: $PACKAGE_MANAGER_INSTALL python3-pip"
$PACKAGE_MANAGER_INSTALL python3-pip
fi
PIP=pip3
else
exit 1
fi
fi
echo "=========================================="
echo "Press CTRL+C to stop the bot"
echo "=========================================="
sleep 3
while true; do
# update the bot
echo "=========================================="
echo "Updating bot..."
echo "=========================================="
git config pull.rebase false
git pull origin main
echo "Project updated successfully"
sleep 2
echo "=========================================="
echo "Updating dependencies..."
echo "=========================================="
echo "Running command: $PIP install -U -r requirements.txt"
$PIP install -U -r requirements.txt > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Running command: $PIP install -U --break-system-packages -r requirements.txt"
$PIP install -U --break-system-packages -r requirements.txt > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Failed to update dependencies. Retrying in 5 seconds..."
sleep 3
continue
fi
fi
echo "Dependencies updated successfully"
sleep 2
echo "=========================================="
echo "Starting bot..."
echo "=========================================="
echo "Running command: $PYTHON main.py"
$PYTHON main.py
if [ $? -ne 0 ]; then
echo "Bot encountered an error. Restarting in 5 seconds..."
else
echo "Bot stopped. Restarting in 5 seconds..."
fi
sleep 5
done
trap 'echo "=========================================="; echo "CTRL+C pressed. Exiting..."; exit 0' SIGINT