-
Notifications
You must be signed in to change notification settings - Fork 11
/
cli.sh
executable file
·295 lines (247 loc) · 8.33 KB
/
cli.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
#!/bin/bash
set -e
# Check if docker is installed
if ! command -v docker >/dev/null 2>&1; then
echo "Error: Docker is not installed on this machine."
echo "https://www.docker.com/products/docker-desktop/"
exit 1
fi
if ! command -v curl >/dev/null 2>&1; then
apt-get update && apt-get install curl -y
fi
COMMAND="$1"
RAW_GITHUB_URL="https://raw.githubusercontent.com/arvida42/jackettio/master"
DIR=$(dirname "$0")
ENV_FILE="$DIR/.env.production"
JACKETT_PASSWORD=""
ACME_DOMAIN=""
ACME_EMAIL=""
INSTALL_TYPE=""
LOCALTUNNEL=""
JACKETT_URL="http://jackett:9117"
JACKETT_API_KEY=""
PORT=4000
COMPOSE_FILE=""
cd $DIR
importConfig() {
if [ ! -f "$ENV_FILE" ]; then
echo "Configuration file not found: $ENV_FILE"
echo "Are you in the corect folder to run this command ?"
exit 1
fi
source $ENV_FILE
}
runDockerCompose() {
docker compose -f docker-compose.yml -f $COMPOSE_FILE --env-file $ENV_FILE "$@"
}
downloadComposeFiles() {
echo "Downloading compose files ..."
curl -fsSL "${RAW_GITHUB_URL}/docker-compose.yml" -o docker-compose.yml
curl -fsSL "${RAW_GITHUB_URL}/${COMPOSE_FILE}" -o $COMPOSE_FILE
}
sedReplace(){
if [[ "$OSTYPE" == darwin* ]]; then
sed -i '' "$@"
else
sed -i "$@"
fi
}
createJackettPassword(){
FILE=$1
JACKETT_API_KEY=$(sed -n 's/.*"APIKey": "\(.*\)",/\1/p' $FILE)
if command -v openssl &> /dev/null; then
echo " - Generate password using openssl"
JACKETT_PASSWORD=$(openssl rand -base64 12)
else
echo " - Generate password using /dev/urandom "
JACKETT_PASSWORD=$(tr -dc A-Za-z0-9_ < /dev/urandom | head -c 12)
fi
echo " - Create password hash ..."
# https://github.com/Jackett/Jackett/blob/d560175c20a64c0d5379ceb7178810d00b71498d/src/Jackett.Server/Services/SecurityService.cs#L26
NODE_COMMAND="node -e \"const crypto = require('crypto');
const input = '${JACKETT_PASSWORD}${JACKETT_API_KEY}';
const hash = crypto.createHash('sha512');
hash.update(Buffer.from(input, 'utf16le'));
console.log(hash.digest().toString('hex'));\""
JACKETT_PASSWORD_HASH=$(docker run --rm node:20-slim sh -c "$NODE_COMMAND")
sedReplace 's/"AdminPassword": .*,/"AdminPassword": "'"$JACKETT_PASSWORD_HASH"'",/' $FILE
}
showHelp(){
cat <<-END
Usage: sh ./cli.sh [command]
Available commands:
start Start all containers
stop Stop all containers
down Stop and remove all containers
update Update all containers
install Install and configure all containers
jackett-password Reset jackett password
END
}
# Store information in an environment file
saveConfig() {
cat <<EOF > $ENV_FILE
ACME_DOMAIN=$ACME_DOMAIN
ACME_EMAIL=$ACME_EMAIL
INSTALL_TYPE=$INSTALL_TYPE
LOCALTUNNEL=$LOCALTUNNEL
JACKETT_URL=$JACKETT_URL
JACKETT_API_KEY=$JACKETT_API_KEY
PORT=$PORT
COMPOSE_FILE=$COMPOSE_FILE
EOF
}
case "$COMMAND" in
"--help"|"help")
showHelp
exit 0
;;
"start")
importConfig
runDockerCompose up -d
exit 0
;;
"stop" | "down")
importConfig
runDockerCompose $COMMAND
exit 0
;;
"update")
importConfig
runDockerCompose down
downloadComposeFiles
runDockerCompose pull
runDockerCompose up -d
exit 0
;;
"jackett-password")
importConfig
docker cp jackett:/config/Jackett/ServerConfig.json /tmp/ServerConfig.json > /dev/null
createJackettPassword /tmp/ServerConfig.json
docker cp /tmp/ServerConfig.json jackett:/config/Jackett/ServerConfig.json > /dev/null
rm -f /tmp/ServerConfig.json
echo "Restart jackett ..."
docker restart jackett
echo "Your new password is: $JACKETT_PASSWORD"
echo "Please change it for security in jackett dashboard"
exit 0
;;
"install")
echo "Install ..."
;;
*)
echo -e "\033[0;31mInvalid command: ${COMMAND}\033[0m"
showHelp
exit 1
;;
esac
if [ -f "$ENV_FILE" ]; then
echo -e "\033[0;31mAn installation appears to already exist and will be overwritten ! ($ENV_FILE)\033[0m"
read -p " Continue and overwrite ? (y/n): " continue
if [[ $continue != "yes" && $continue != "y" ]]; then
echo "Exiting..."
exit
fi
fi
cat <<-END
This script will install compose and environments file in the following folder
-----------------------
${PWD}
-----------------------
END
read -p "Are you sure you want to continue? (y/n): " continue
if [[ $continue != "yes" && $continue != "y" ]]; then
echo "Exiting..."
exit
fi
cat <<-END
Please select an installation type:
1) Using traefik
You must have a domain configured for this machine, ports 80 and 443 must be opened.
Your Addon will be available on the address: https://your_domain
2) Using localtunnel
This installation use "localtunnel" to expose the app on Internet.
There's no need to configure a domain; you can run it directly on your local machine.
However, you may encounter limitations imposed by LocalTunnel.
All requests from the addons will go through LocalTunnel.
Your Addon will be available on the address: https://random-id.localtunnel.me
3) Local
Install locally without domain. Stremio App must run in same machine to works.
Your Addon will be available on the address: http://localhost
END
read -p "Please chose 1,2 or 3): " INSTALL_TYPE
case "$INSTALL_TYPE" in
"1")
echo "traefik selected"
read -p "Please enter your domain name (example.com): " ACME_DOMAIN
read -p "Please enter your email ([email protected]): " ACME_EMAIL
COMPOSE_FILE=docker-compose-traefik.yml
echo "Your domain: ${ACME_DOMAIN}"
echo "Your email: ${ACME_EMAIL}"
;;
"2")
echo "localtunnel selected"
COMPOSE_FILE=docker-compose-tunnel.yml
LOCALTUNNEL="true"
;;
"3")
echo "local selected"
COMPOSE_FILE=docker-compose-local.yml
;;
*)
echo "Invalid installation type: ${INSTALL_TYPE}"
echo "Must be 1,2 or 3"
exit 1
;;
esac
saveConfig
echo "------------------"
cat $ENV_FILE
echo ""
echo "Please confirm the above information before proceeding."
read -p "Continue ? (y/n): " continue
if [[ $continue != "yes" && $continue != "y" ]]; then
echo "Exiting..."
exit
fi
downloadComposeFiles
echo "Configure jackett ..."
runDockerCompose up -d jackett
echo "Wait for jackett ..."
sleep 6
docker cp jackett:/config/Jackett/ServerConfig.json /tmp/ServerConfig.json > /dev/null
JACKETT_API_KEY=$(sed -n 's/.*"APIKey": "\(.*\)",/\1/p' /tmp/ServerConfig.json)
JACKETT_PASSWORD_HASH=$(sed -n 's/.*"AdminPassword": "\(.*\)",/\1/p' /tmp/ServerConfig.json)
if [ -z "$JACKETT_PASSWORD_HASH" ]; then
echo " - Configure jackett admin password ..."
createJackettPassword /tmp/ServerConfig.json
fi
echo " - Configure jackett flaresolverr url ..."
sedReplace 's/"FlareSolverrUrl": .*,/"FlareSolverrUrl": "http:\/\/flaresolverr:8191",/' /tmp/ServerConfig.json
docker cp /tmp/ServerConfig.json jackett:/config/Jackett/ServerConfig.json > /dev/null
rm -f /tmp/ServerConfig.json
runDockerCompose down
saveConfig
echo "Start all containers ..."
runDockerCompose up -d
echo "-----------------------"
echo -e "\n\033[0;32mInstallation complete! \033[0m\n"
case "$INSTALL_TYPE" in
"1")
echo " - Your addon is available on the following address: https://${ACME_DOMAIN}/configure"
;;
"2")
echo "Wait for Jackettio ..."
sleep 4
runDockerCompose logs -n 30 jackettio
;;
"3")
echo " - Your addon is available on the following address: http://localhost:4000/configure"
;;
esac
echo " - Your Jackett instance to configure your trackers is available on the following address: http://localhost:9117 or http://${ACME_DOMAIN:-your_public_ip}:9117"
echo " Be aware that having a lot of trackers may slow down search queries within the addon. We recommend utilizing trackers that do not have Cloudflare protection."
if [ ! -z "$JACKETT_PASSWORD" ]; then
echo -e "\n - \033[0;31mIMPORTANT:\033[0m The default password for Jackett is \"${JACKETT_PASSWORD}\", Please change it for security in jackett dashboard."
fi
echo "-----------------------"