-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.sh
More file actions
184 lines (157 loc) · 3.89 KB
/
Copy pathinstall.sh
File metadata and controls
184 lines (157 loc) · 3.89 KB
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
#!/usr/bin/env bash
set -euo pipefail
APP_NAME="Elys"
MODULE_NAME="elys"
REPO_URL="${ELYS_REPO_URL:-https://github.com/ZavozDevs/Elys.git}"
VENV_DIR="${ELYS_VENV_DIR:-.venv}"
LOG_FILE="elys-install.log"
if [ "${SUDO_USER:-}" != "" ] && command -v sudo >/dev/null 2>&1; then
RUN_AS_USER=(sudo -u "$SUDO_USER")
else
RUN_AS_USER=()
fi
info() {
printf "\033[0;34m%s\033[0m\n" "$1"
}
ok() {
printf "\033[0;32m%s\033[0m\n" "$1"
}
fail() {
printf "\033[1;31m%s\033[0m\n" "$1" >&2
[ -f "$LOG_FILE" ] && cat "$LOG_FILE" >&2
exit "${2:-1}"
}
run() {
"$@" >>"$LOG_FILE" 2>&1
}
sudo_run() {
if [ "$(id -u)" -eq 0 ]; then
run "$@"
elif command -v sudo >/dev/null 2>&1; then
run sudo "$@"
else
fail "Root privileges or sudo are required to install system packages." 2
fi
}
python_cmd() {
if command -v python3 >/dev/null 2>&1; then
printf "python3"
elif command -v python >/dev/null 2>&1; then
printf "python"
else
fail "Python is not installed." 2
fi
}
install_system_packages() {
info "Installing system packages..."
if echo "${OSTYPE:-}" | grep -qE "^linux-android"; then
run pkg update -y
run pkg install -y \
build-essential \
ffmpeg \
git \
libcairo \
libffi \
libjpeg-turbo \
libwebp \
ncurses-utils \
openssl \
python
elif command -v apt-get >/dev/null 2>&1; then
sudo_run apt-get update
sudo_run apt-get install -y \
build-essential \
ffmpeg \
git \
imagemagick \
libcairo2 \
libffi-dev \
libjpeg-dev \
libmagic1 \
libopenjp2-7 \
libtiff-dev \
libwebp-dev \
libz-dev \
python3 \
python3-dev \
python3-pip \
python3-venv
elif command -v pacman >/dev/null 2>&1; then
sudo_run pacman -Sy --needed --noconfirm \
base-devel \
ffmpeg \
file \
git \
imagemagick \
python \
python-pip
elif command -v dnf >/dev/null 2>&1; then
sudo_run dnf install -y \
ffmpeg \
file-libs \
gcc \
gcc-c++ \
git \
imagemagick \
python3 \
python3-devel \
python3-pip
elif command -v brew >/dev/null 2>&1; then
run brew install git jpeg webp
else
info "Unknown package manager, skipping system package installation."
fi
}
check_python() {
local py="$1"
"$py" - <<'PY'
import sys
if sys.version_info < (3, 10):
raise SystemExit("Python 3.10+ is required")
PY
}
prepare_repo() {
if [ -d "$MODULE_NAME" ] && [ -f "requirements.txt" ]; then
return
fi
if [ -d "$APP_NAME/$MODULE_NAME" ]; then
cd "$APP_NAME"
return
fi
info "Cloning repo..."
rm -rf "$APP_NAME"
"${RUN_AS_USER[@]}" git clone "$REPO_URL" "$APP_NAME" >>"$LOG_FILE" 2>&1 || fail "Clone failed." 3
cd "$APP_NAME"
}
create_venv() {
local py="$1"
info "Creating virtual environment..."
"${RUN_AS_USER[@]}" "$py" -m venv "$VENV_DIR" >>"$LOG_FILE" 2>&1 || fail "Virtual environment creation failed." 4
}
install_python_packages() {
local venv_python="$VENV_DIR/bin/python"
info "Installing Python dependencies..."
"${RUN_AS_USER[@]}" "$venv_python" -m pip install --upgrade pip setuptools wheel >>"$LOG_FILE" 2>&1 || fail "Pip upgrade failed." 4
"${RUN_AS_USER[@]}" "$venv_python" -m pip install --upgrade -r requirements.txt --disable-pip-version-check >>"$LOG_FILE" 2>&1 || fail "Requirements installation failed." 4
}
start_app() {
info "Starting..."
"${RUN_AS_USER[@]}" "$VENV_DIR/bin/python" -m "$MODULE_NAME" "$@"
}
clear || true
cat assets/download.txt
printf "\033[3;34;40m Installing %s...\033[0m\n\n" "$APP_NAME"
: >"$LOG_FILE"
if [ "${SUDO_USER:-}" != "" ]; then
chown "$SUDO_USER:" "$LOG_FILE" >/dev/null 2>&1 || true
fi
install_system_packages
PYTHON="$(python_cmd)"
prepare_repo
check_python "$PYTHON"
create_venv "$PYTHON"
install_python_packages
touch .setup_complete
rm -f "$LOG_FILE"
ok "Installation complete."
start_app "$@"