-
Notifications
You must be signed in to change notification settings - Fork 9
/
Auto_install.sh
executable file
·130 lines (110 loc) · 3.78 KB
/
Auto_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
#!/bin/bash
## Set default commands
pipCommand="pip"
pythonCommand="python"
useBale=0
## Display help for commands
showHelp() {
echo -e "Autoinstall usage: $0 [option..]\n
-b, --bale For install bale api instead of Telegram API \n
-h, --help This help message\n
-d, --debug Enable bash debug\n
-i, --interactive Install requirements for interactive commands\n
-u, --useful Install useful commands\n
-3, --python3 Use python3 instead of Python2\n
"
exit 0
}
## Use virtualenv
useVenv() {
## Create virtual environment
virtualenv -p $pythonCommand venv
## Activate virtual environment
source venv/bin/activate
}
useBaleAPI() {
## Change telegram API URL to Bale API URL
find ./ -name bot.py -exec sed -i 's/api\.telegram\.org/tapi.bale.ai/mg' {} \;
}
## to use interactive commands like htop we need these packages
installAha() {
[ -f "/etc/debian_version" ] && apt-get update && apt-get install -y aha && return 0
(git clone https://github.com/theZiz/aha.git && cd aha && make && make install return 0) || ( echo "cannot install aha, please use -d to debug \nPlease submit an issue here:\n https://github.com/MParvin/TSMB/issues/new" && exit 1)
}
## Install useful commands
installUsefulCMD() {
echo "Installing htop, please wait a moment..."
yum install -y htop &> /dev/null || apt install -y htop &> /dev/null
}
configureBot(){
echo -e "To configure your bot, you must have a Telegram or Bale token\n
How to create Telegram bot: https://core.telegram.org/bots#3-how-do-i-create-a-bot\n
How to create Bale bot: https://devbale.ir/quick-start\n"
read -p "Enter your bot token here:"
telegramToken=$REPLY
echo -e "Get chat_id and enter here:\n
To get chat_id do:
- In telegram:\n start a chat with @id_chatbot
- In Bale:\n start a chat with chatid_bot
"
chatId=$REPLY
}
while :
do
case "$1" in
-b | --bale)
which virtualenv &> /dev/null || (echo "Cannot use Bale without virtualenv, please run \"pip install virtualenv\" before run this script with -b option" && exit 1)
useBale = "True"
break
;;
-h | --help)
showHelp
exit 0
;;
-d | --debug)
set -x
break
;;
-i | --interactive)
installAha
break
;;
-u | --useful)
installUsefulCMD
break
;;
-3 | --python3)
pythonCommand="python3"
pipCommand="pip3"
break
;;
*)
break
;;
esac
done
## Check is python installed
which $pythonCommand &> /dev/null || (echo "Please install python, and run this script again" && exit 1)
## Check is pip installed
which $pipCommand &> /dev/null || (echo -e "Please install pip, and run this script again\n
In Debian base system for python2.* use apt-get install python-pip\n
for python3.* use apt-get install python3-pip" && exit 1)
## Install virtualenv if is not installed
(which virtualenv &> /dev/null && useVenv) || read -p "Do you want to install virtualenv(y/n)? " -n 1 -r
## User accepted
[[ ! $REPLY =~ ^[yY]$ ]] && $pipCommand install virtualenv --user && useVenv
## Install requirements
([ -f requirements.txt ] && $pipCommand install -r requirements.txt) || echo "Could not find requirements.txt, please clone complete this repository from here:\nhttps://github.com/MParvin/TSMB/, \nthen run Autoinstall.sh"
if [ "$useBale" -eq 1 ]
then
useBaleAPI
fi
read -p "Do you want to configure your bot now(y/n)?"
if [ $REPLY =~ ^[yY] ]
then
configureBot
else
echo -e "To use this bot, first change variables in \"config\" file\n
then executable bot script \"chmod +x bot.py \"
and run it: \"./bot.py \""
fi