-
Notifications
You must be signed in to change notification settings - Fork 1
/
installer.sh
241 lines (230 loc) · 7.9 KB
/
installer.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
#!/usr/bin/env bash
REPO="https://github.com/itzNightmare17/Raven.git"
CURRENT_DIR="$(pwd)"
ENV_FILE_PATH=".env"
DIR="/root/itzNightmare17"
while [ $# -gt 0 ]; do
case "$1" in
--dir=*)
DIR="${1#*=}" || DIR="/root/itzNightmare17"
;;
--branch=*)
BRANCH="${1#*=}" || BRANCH="main"
;;
--env-file=*)
ENV_FILE_PATH="${1#*=}" || ENV_FILE_PATH=".env"
;;
--no-root)
NO_ROOT=true
;;
*)
echo "Unknown parameter passed: $1"
exit 1
;;
esac
shift
done
check_dependencies() {
# check if debian
echo "Checking dependencies..."
# read file with root access
if ! [[ $(ls -l "/etc/sudoers" | cut -d " " -f1) =~ "r" ]]; then
# check dependencies if installed
echo -e "Root access not found. Checking if dependencies are installed." >&2
if ! [ -x "$(command -v python3)" ] || ! [ -x "$(command -v python)" ]; then
echo -e "Python3 isn't installed. Please install python3.8 or higher to run this bot." >&2
exit 1
fi
if [ $(python3 -c "import sys; print(sys.version_info[1])") -lt 8 ] || [ $(python -c "import sys; print(sys.version_info[1])") -lt 8 ]; then
echo -e "Python 3.8 or higher is required to run this bot." >&2
exit 1
fi
# check if any of ffmpeg, mediainfo, neofetch, git is not installed
if ! command -v ffmpeg &>/dev/null || ! command -v mediainfo &>/dev/null || ! command -v neofetch &>/dev/null || ! command -v git &>/dev/null; then
echo -e "Some dependencies aren't installed. Please install ffmpeg, mediainfo, neofetch and git to run this bot." >&2
exit 1
fi
fi
if [ -x "$(command -v apt-get)" ]; then
echo -e "Installing dependencies..."
# check if any of ffmpeg, mediainfo, neofetch, git is not installed via dpkg
if dpkg -l | grep -q ffmpeg || dpkg -l | grep -q mediainfo || dpkg -l | grep -q neofetch || dpkg -l | grep -q git; then
sudo apt-get -qq -o=Dpkg::Use-Pty=0 update
sudo apt-get install -qq -o=Dpkg::Use-Pty=0 python3 python3-pip ffmpeg mediainfo neofetch git -y
fi
elif [ -x "$(command -v pacman)" ]; then
echo -e "Installing dependencies..."
if pacman -Q | grep -q ffmpeg || pacman -Q | grep -q mediainfo || pacman -Q | grep -q neofetch || pacman -Q | grep -q git; then
sudo pacman -Sy python python-pip git ffmpeg mediainfo neofetch --noconfirm
fi
else
echo -e "Unknown OS. Checking if dependecies are installed" >&2
if ! [ -x "$(command -v python3)" ] || ! [ -x "$(command -v python)" ]; then
echo -e "Python3 isn't installed. Please install python3.8 or higher to run this bot." >&2
exit 1
fi
if [ $(python3 -c "import sys; print(sys.version_info[1])") -lt 8 ] || [ $(python -c "import sys; print(sys.version_info[1])") -lt 8 ]; then
echo -e "Python 3.8 or higher is required to run this bot." >&2
exit 1
fi
if ! command -v ffmpeg &>/dev/null || ! command -v mediainfo &>/dev/null || ! command -v neofetch &>/dev/null || ! command -v git &>/dev/null; then
echo -e "Some dependencies aren't installed. Please install ffmpeg, mediainfo, neofetch and git to run this bot." >&2
exit 1
fi
fi
}
check_python() {
# check if python is installed
if ! command -v python3 &>/dev/null; then
echo -e "Python3 isn't installed. Please install python3.8 or higher to run this bot."
exit 1
elif ! command -v python &>/dev/null; then
echo -e "Python3 isn't installed. Please install python3.8 or higher to run this bot."
exit 1
fi
if [ $(python3 -c "import sys; print(sys.version_info[1])") -lt 8 ]; then
echo -e "Python 3.8 or higher is required to run this bot."
exit 1
elif [ $(python -c "import sys; print(sys.version_info[1])") -lt 3 ]; then
if [ $(python -c "import sys; print(sys.version_info[1])") -lt 8 ]; then
echo -e "Python 3.8 or higher is required to run this bot."
exit 1
fi
fi
}
clone_repo() {
# check if pyultroid, startup, plugins folders exist
cd $DIR
if [ -d $DIR ]; then
if [ -d $DIR/.git ]; then
echo -e "Updating Raven ${BRANCH}... "
cd $DIR
git pull
currentbranch="$(git rev-parse --abbrev-ref HEAD)"
if [ ! $BRANCH ]; then
export BRANCH=$currentbranch
fi
case $currentbranch in
$BRANCH)
# do nothing
;;
*)
echo -e "Switching to branch ${BRANCH}... "
echo -e $currentbranch
git checkout $BRANCH
;;
esac
else
rm -rf $DIR
exit 1
fi
if [ -d "addons" ]; then
cd addons
git pull
fi
return
else
if [ ! $BRANCH ]; then
export BRANCH="main"
fi
mkdir -p $DIR
echo -e "Cloning Raven ${BRANCH}... "
git clone -b $BRANCH $REPO $DIR
fi
}
install_requirements() {
pip3 install -q --upgrade pip
echo -e "\n\nInstalling requirements... "
pip3 install -q --no-cache-dir -r $DIR/requirements.txt
pip3 install -q -r $DIR/resources/startup/optional-requirements.txt
}
railways_dep() {
if [ $RAILWAY_STATIC_URL ]; then
echo -e "Installing YouTube dependency... "
pip3 install -q yt-dlp
fi
}
misc_install() {
if [ $SETUP_PLAYWRIGHT ]
then
echo -e "Installing playwright."
pip3 install playwright
playwright install
fi
if [ $OKTETO_TOKEN ]; then
echo -e "Installing Okteto-CLI... "
curl https://get.okteto.com -sSfL | sh
elif [ $VCBOT ]; then
if [ -d $DIR/vcbot ]; then
cd $DIR/vcbot
git pull
else
echo -e "Cloning VCBOT.."
git clone https://github.com/itzNightmare17/VcBot $DIR/vcbot
fi
pip3 install pytgcalls==3.0.0.dev23 && pip3 install av -q --no-binary av
fi
}
dep_install() {
echo -e "\n\nInstalling DB Requirement..."
if [ $MONGO_URI ]; then
echo -e " Installing MongoDB Requirements..."
pip3 install -q pymongo[srv]
elif [ $DATABASE_URL ]; then
echo -e " Installing PostgreSQL Requirements..."
pip3 install -q psycopg2-binary
elif [ $REDIS_URI ]; then
echo -e " Installing Redis Requirements..."
pip3 install -q redis hiredis
fi
}
main() {
echo -e "Starting Raven Setup..."
if [ -d "pyOreo" ] && [ -d "resources" ] && [ -d "plugins" ]; then
DIR=$CURRENT_DIR
fi
if [ -f $ENV_FILE_PATH ]
then
set -a
source <(cat $ENV_FILE_PATH | sed -e '/^#/d;/^\s*$/d' -e "s/'/'\\\''/g" -e "s/=\(.*\)/='\1'/g")
set +a
cp $ENV_FILE_PATH .env
fi
(check_dependencies)
(check_python)
(clone_repo)
(install_requirements)
(railways_dep)
(dep_install)
(misc_install)
echo -e "\n\nSetup Completed."
}
if [ $NO_ROOT ]; then
echo -e "Running with non root"
main
return 0
elif [ -t 0 ]; then
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) machine=Linux;;
Darwin*) machine=Mac;;
CYGWIN*) machine=Cygwin;;
MINGW*) machine=MinGw;;
*) machine="UNKNOWN:${unameOut}"
esac
if machine != "Linux"; then
echo -e "This script is only for Linux. Please use the Windows installer."
exit 1
fi
# check if sudo is installed
if ! command -v sudo &>/dev/null; then
echo -e "Sudo isn't installed. Please install sudo to run this bot."
exit 1
fi
sudo echo "Sudo permission granted."
main
else
echo "Not an interactive terminal, skipping sudo."
# run main function
main
fi