-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathinstall.sh
executable file
·347 lines (306 loc) · 11.2 KB
/
install.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
#!/usr/bin/env bash
# Define color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
INPUT='\033[1;30m'
NC='\033[0m' # No Color
PACKAGE_MANAGER=""
# Ensure the script is run with root privileges
if [[ $UID != 0 ]]; then
printf "${YELLOW}This script requires root privileges.${NC}\n" # skipcq
printf "Please enter the root password to continue.\n"
exec sudo "$0" "$@"
else
printf "${YELLOW}Running with root privileges${NC}\n" # skipcq
fi
# Detect available package manager
if command -v apt &>/dev/null; then
PACKAGE_MANAGER="apt"
elif command -v apk &>/dev/null; then
PACKAGE_MANAGER="apk"
elif command -v yum &>/dev/null; then
PACKAGE_MANAGER="yum"
elif command -v pacman &>/dev/null; then
PACKAGE_MANAGER="pacman"
else
printf "${RED}Unsupported package manager. Please use a compatible distribution or update the installer script.${NC}\n" # skipcq
exit 1
fi
if command -v termux-setup-storage; then
printf "${RED}For termux, please use https://raw.githubusercontent.com/The-MoonTg-project/Moon-Userbot/main/termux-install.sh${NC}\n" # skipcq
exit 1
fi
# Install necessary packages based on detected package manager
case "$PACKAGE_MANAGER" in
apt)
apt update -y
apt install python3 python3-venv git wget -y || exit 2
;;
apk)
apk update
apk add python3 py3-virtualenv git wget || exit 2 # Packages here may be wrong, to verify
;;
yum)
yum update -y
yum install python3 python3-venv git wget -y || exit 2 # Packages here may be wrong, to verify
;;
pacman)
pacman -S --noconfirm python python-virtualenv git wget || exit 2
;;
esac
# Clone repository if not exists
if [[ -d "Moon-Userbot" && "$(basename "$PWD")" != "Moon-Userbot" ]]; then
cd Moon-Userbot || exit 2
elif [[ "$(basename "$PWD")" == "Moon-Userbot" && -f ".env.dist" && -f "main.py" && -d "modules" ]]; then
printf "${BLUE}Already inside the Moon-Userbot repo, proceeding...${NC}\n" # skipcq
else
git clone https://github.com/The-MoonTg-project/Moon-Userbot || exit 2
cd Moon-Userbot || exit 2
fi
if [[ -f ".env" ]] && [[ -f "my_account.session" ]]; then
printf "${GREEN}It seems that Moon-Userbot is already installed. Exiting...${NC}\n" # skipcq
exit
fi
# Prompt user if they want to proceed with creating a virtual environment
printf "${YELLOW}It's recommended to use a virtual environment for Python projects.${NC}\n" # skipcq
printf "Note: If your drive resources are very limited, you might consider not creating a virtual environment, but it shouldn't be rejected otherwise unless you know what you're doing.\n"
printf "If you're unsure, it's better to create a virtual environment.\n"
printf "${INPUT}Would you like to create a virtual environment? (Y/n)${NC} > " # skipcq
read -r create_venv
if [[ "$create_venv" != "n" ]] && [[ "$create_venv" != "N" ]]; then
# Create a virtual environment inside the cloned repository and activate it
python3 -m venv venv
. venv/bin/activate
# Upgrade pip and install wheel and pillow
pip install -U pip wheel pillow
fi
if [ -d ".venv" ]; then
. .venv/bin/activate
elif [ -d "venv" ]; then
. venv/bin/activate
fi
# Install Python requirements
pip install -U -r requirements.txt || exit 2
# Prompt for API_ID and API_HASH
printf "Enter API_ID and API_HASH\n"
printf "You can get it here -> https://my.telegram.org/\n"
printf "Leave empty to use defaults (please note that using default keys is a ${RED}very bad idea${NC} and significantly increases your ban chances)\n" # skipcq
read -r -p "API_ID > " api_id
# Default API_ID and API_HASH
if [[ $api_id = "" ]]; then
printf "${RED}You have chosen to use the default API_ID and API_HASH, which is strongly discouraged.${NC}\n" # skipcq
printf "${YELLOW}Please type${NC} '${BLUE}I agree${NC}'${YELLOW} to confirm that you understand the risks and still wish to proceed.${NC}\n" # skipcq
read -r -p "Confirmation > " confirmation
if [[ $confirmation = "I agree" ]]; then
api_id="2040"
api_hash="b18441a1ff607e10a989891a5462e627"
else
printf "${RED}Confirmation not provided. Exiting...${NC}\n" # skipcq
exit 1
fi
else
read -r -p "API_HASH > " api_hash
fi
# Prompt for PM PERMIT warn limit
# PM PERMIT warn limit is the number of messages a user can receive from others before giving them a warning, requires `antipm` plugin to be enabled
printf "SET PM PERMIT warn limit\n"
# Now below is more clear version:
printf "The number of messages others can send you before receiving a warning, and eventually a ban or leave empty for default (3), requires antipm plugin to be enabled\n"
read -r -p "PM_LIMIT warn limit > " pm_limit
if [[ $pm_limit = "" ]]; then
pm_limit="3"
printf "Limit not provided by user; set to default\n"
fi
# Prompt for musicbot usage
printf "Do you want to use musicbot? (y/N)"
read -r musicbot
if [[ $musicbot = "y" ]]; then
printf "Enter SECOND_SESSION_STRING to be used by musicbot\n"
read -r -p "SECOND_SESSION > " second_session
if [[ $second_session = "" ]]; then
printf "SECOND_SESSION not provided by user\n"
second_session=""
fi
fi
# Prompt for various API keys
printf "Enter APIFLASH_KEY for webshot plugin\n"
printf "You can get it here -> https://apiflash.com/dashboard/access_keys\n"
read -r -p "APIFLASH_KEY > " apiflash_key
if [[ $apiflash_key = "" ]]; then
printf "NOTE: API Not set; you'll get errors with webshot & ws module\n"
fi
printf "Enter RMBG_KEY for remove background module\n"
printf "You can get it here -> https://www.remove.bg/dashboard#api-key\n"
read -r -p "RMBG_KEY > " rmbg_key
if [[ $rmbg_key = "" ]]; then
printf "NOTE: API Not set; you'll not be able to use remove background modules\n"
fi
printf "Enter VT_KEY for VirusTotal\n"
printf "You can get it here -> https://www.virustotal.com/\n"
read -r -p "VT_KEY > " vt_key
if [[ $vt_key = "" ]]; then
printf "NOTE: API Not set; you'll not be able to use VirusTotal module\n"
fi
printf "Enter GEMINI_KEY if you want to use AI\n"
printf "You can get it here -> https://makersuite.google.com/app/apikey\n"
read -r -p "GEMINI_KEY > " gemini_key
if [[ $gemini_key = "" ]]; then
printf "NOTE: API Not set; you'll not be able to use Gemini AI modules\n"
fi
printf "Enter COHERE_KEY if you want to use AI"
printf "You can get it here -> https://dashboard.cohere.com/api-keys\n"
read -r -p "COHERE_KEY > " cohere_key
if [[ $cohere_key = "" ]]; then
printf "NOTE: API Not set; you'll not be able to use Coral AI modules\n"
fi
printf "Enter VCA_API_KEY for aiutils\n"
printf "Learn How to Get One --> https://github.com/VisionCraft-org/VisionCraft?tab=readme-ov-file#obtaining-an-api-key\n"
read -r -p "VCA_API_KEY > " vca_api_key
if [[ $vca_api_key = "" ]]; then
printf "NOTE: API Not set; you'll not be able to use aiutils module/plugins\n"
fi
while true; do
# Prompt for database type and database URL if MongoDB is selected
printf "${YELLOW}Choose database type:${NC}\n" # skipcq
printf "[1] MongoDB db_url\n"
printf "[2] MongoDB localhost\n"
printf "[3] Sqlite (default)\n"
read -r -p "> " db_type
case $db_type in
1)
printf "Please enter db_url\n"
printf "You can get it here -> https://mongodb.com/atlas\n"
read -r -p "> " db_url
db_name=Moon_Userbot
db_type=mongodb
break
;;
2)
if ! command -v apt &>/dev/null; then
printf "This option requires apt package manager, which is not available on your system.\n"
printf "Please choose a different database type.\n"
continue
fi
if systemctl status mongodb; then
wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | apt-key add -
source /etc/os-release
printf "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu %s/mongodb-org/5.0 multiverse\n" "${UBUNTU_CODENAME}" | tee /etc/apt/sources.list.d/mongodb-org-5.0.list
apt update
apt install mongodb -y
systemctl daemon-reload
systemctl enable mongodb
fi
systemctl start mongodb
db_url=mongodb://localhost:27017
db_name=Moon_Userbot
db_type=mongodb
break
;;
3)
db_name=db.sqlite3
db_type=sqlite3
break
;;
*)
printf "${RED}Invalid choice!${NC}\n" # skipcq
;;
esac
done
# Generate .env file with collected variables
cat >.env <<EOL
API_ID=${api_id}
API_HASH=${api_hash}
STRINGSESSION=
# sqlite/sqlite3 or mongo/mongodb
DATABASE_TYPE=${db_type}
# file name for sqlite3, database name for mongodb
DATABASE_NAME=${db_name}
# only for mongodb
DATABASE_URL=${db_url}
APIFLASH_KEY=${apiflash_key}
RMBG_KEY=${rmbg_key}
VT_KEY=${vt_key}
GEMINI_KEY=${gemini_key}
VCA_API_KEY=${vca_api_key}
COHERE_KEY=${cohere_key}
PM_LIMIT=${pm_limit}
SECOND_SESSION=${second_session}
EOL
# Adjust the ownership of the Moon-Userbot directory
chown -R $SUDO_USER:$SUDO_USER .
# Configure the bot based on selected installation type
while true; do
# Prompt for installation type and execute accordingly
printf "${YELLOW}Choose installation type:${NC}\n" # skipcq
printf "[1] PM2\n"
printf "[2] Systemd service\n"
printf "[3] Custom (default)\n"
read -r -p "> " install_type
case $install_type in
1)
if ! command -v apt &>/dev/null; then
printf "This option requires apt package manager, which is not available on your system.\n"
printf "Please choose a different installation type.\n"
continue
fi
if ! command -v pm2 &>/dev/null; then
curl -fsSL https://deb.nodesource.com/setup_17.x | bash
apt install nodejs -y
npm install pm2 -g
su -c "pm2 startup" $SUDO_USER
env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u $SUDO_USER --hp /home/$SUDO_USER
fi
su -c "pm2 start main.py --name Moon --interpreter python3" $SUDO_USER
su -c "pm2 save" $SUDO_USER
printf "${GREEN}============================\\n" # skipcq
printf "Great! Moon-Userbot installed successfully and running now!\n"
printf "Installation type: PM2\n"
printf "Start with: \"pm2 start Moon\"\n"
printf "Stop with: \"pm2 stop Moon\"\n"
printf "Process name: Moon\n"
printf "============================${NC}\n" # skipcq
break
;;
2)
cat >/etc/systemd/system/Moon.service <<EOL
[Unit]
Description=Service for Moon Userbot
[Service]
Type=simple
ExecStart=$(which python3) ${PWD}/main.py
WorkingDirectory=${PWD}
Restart=always
User=${SUDO_USER}
Group=${SUDO_USER}
[Install]
WantedBy=multi-user.target
EOL
systemctl daemon-reload
systemctl start Moon
systemctl enable Moon
printf "${GREEN}============================\\n" # skipcq
printf "Great! Moon-Userbot installed successfully and running now!\n"
printf "Installation type: Systemd service\n"
printf "Start with: \"sudo systemctl start Moon\"\n"
printf "Stop with: \"sudo systemctl stop Moon\"\n"
printf "============================${NC}\n" # skipcq
break
;;
3)
printf "${GREEN}============================\\n" # skipcq
printf "Great! Moon-Userbot installed successfully!\n"
printf "Installation type: Custom\n"
printf "Start with: \"python3 main.py\"\n"
printf "============================${NC}\n" # skipcq
break
;;
*)
printf "Invalid choice! Please enter 1, 2, or 3."
;;
esac
done
su -c "python3 install.py ${install_type}" $SUDO_USER || exit 3
# Adjust the ownership of the Moon-Userbot directory again as a final step
chown -R $SUDO_USER:$SUDO_USER .