-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathstremio-web-service-run.sh
More file actions
56 lines (49 loc) · 2.26 KB
/
stremio-web-service-run.sh
File metadata and controls
56 lines (49 loc) · 2.26 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
#!/bin/sh -e
CONFIG_FOLDER="${APP_PATH:-${HOME}/.stremio-server/}"
AUTH_CONF_FILE="/etc/nginx/auth.conf"
HTPASSWD_FILE="/etc/nginx/.htpasswd"
sed -i 's/df -k/df -Pk/g' server.js
if [ -n "${SERVER_URL}" ]; then
if [ "${SERVER_URL: -1}" != "/" ]; then
SERVER_URL="$SERVER_URL/"
fi
cp localStorage.json build/localStorage.json
touch build/server_url.env
sed -i "s|http://127.0.0.1:11470/|"${SERVER_URL}"|g" build/localStorage.json
elif [ -n "${AUTO_SERVER_URL}" ] && [ "${AUTO_SERVER_URL}" -eq 1 ]; then
cp localStorage.json build/localStorage.json
fi
if [ -n "${USERNAME}" ] && [ -n "${PASSWORD}" ]; then
echo "Setting up HTTP basic authentication..."
htpasswd -bc "${HTPASSWD_FILE}" "${USERNAME}" "${PASSWORD}"
echo 'auth_basic "Restricted Content";' >"${AUTH_CONF_FILE}"
echo 'auth_basic_user_file '"${HTPASSWD_FILE}"';' >>"${AUTH_CONF_FILE}"
else
echo "No HTTP basic authentication will be used."
fi
start_http_server() {
if [ -n "${WEBUI_INTERNAL_PORT}" ] && [ "${WEBUI_INTERNAL_PORT}" -ge 1 ] && [ "${WEBUI_INTERNAL_PORT}" -le 65535 ]; then
sed -i "s/8080/"${WEBUI_INTERNAL_PORT}"/g" /etc/nginx/http.d/default.conf
fi
nginx -g "daemon off;"
}
if [ -n "${IPADDRESS}" ]; then
node certificate.js --action fetch
EXTRACT_STATUS="$?"
if [ "${EXTRACT_STATUS}" -eq 0 ] && [ -f "/srv/stremio-server/certificates.pem" ]; then
IP_DOMAIN=$(echo "${IPADDRESS}" | sed 's/\./-/g')
echo "${IPADDRESS} ${IP_DOMAIN}.519b6502d940.stremio.rocks" >> /etc/hosts
cp /etc/nginx/https.conf /etc/nginx/http.d/default.conf
node certificate.js --action load --pem-path "/srv/stremio-server/certificates.pem" --domain "${IP_DOMAIN}.519b6502d940.stremio.rocks" --json-path "${CONFIG_FOLDER}httpsCert.json"
else
echo "Failed to setup HTTPS. Falling back to HTTP."
fi
elif [ -n "${CERT_FILE}" ]; then
if [ -f "${CONFIG_FOLDER}${CERT_FILE}" ]; then
cp "${CONFIG_FOLDER}${CERT_FILE}" /srv/stremio-server/certificates.pem
cp /etc/nginx/https.conf /etc/nginx/http.d/default.conf
node certificate.js --action load --pem-path "/srv/stremio-server/certificates.pem" --domain "${DOMAIN}" --json-path "${CONFIG_FOLDER}httpsCert.json"
fi
fi
node server.js &
start_http_server