-
Notifications
You must be signed in to change notification settings - Fork 30
/
start.sh
executable file
·53 lines (42 loc) · 1.49 KB
/
start.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
#!/bin/sh
conf_path=/aria2/conf
conf_copy_path=/aria2/conf-copy
data_path=/aria2/data
ariang_js_path=/usr/local/www/ariang/js/aria-ng*.js
# If config does not exist - use default
if [ ! -f $conf_path/aria2.conf ]; then
cp $conf_copy_path/aria2.conf $conf_path/aria2.conf
fi
if [ -n "$RPC_SECRET" ]; then
sed -i '/^rpc-secret=/d' $conf_path/aria2.conf
printf 'rpc-secret=%s\n' "${RPC_SECRET}" >>$conf_path/aria2.conf
if [ -n "$EMBED_RPC_SECRET" ]; then
echo "Embedding RPC secret into ariang Web UI"
RPC_SECRET_BASE64=$(echo -n "${RPC_SECRET}" | base64 -w 0)
sed -i 's,secret:"[^"]*",secret:"'"${RPC_SECRET_BASE64}"'",g' $ariang_js_path
fi
fi
if [ -n "$BASIC_AUTH_USERNAME" ] && [ -n "$BASIC_AUTH_PASSWORD" ]; then
echo "Enabling caddy basic auth"
echo "
basicauth / {
$BASIC_AUTH_USERNAME $(caddy hash-password -plaintext "${BASIC_AUTH_PASSWORD}")
}
" >>/usr/local/caddy/Caddyfile
fi
touch $conf_path/aria2.session
if [[ -n "$ARIA2RPCPORT" ]]; then
echo "Changing rpc request port to $ARIA2RPCPORT"
sed -i "s/6800/${ARIA2RPCPORT}/g" $ariang_js_path
fi
userid="$(id -u)" # 65534 - nobody, 0 - root
groupid="$(id -g)"
if [[ -n "$PUID" && -n "$PGID" ]]; then
echo "Running as user $PUID:$PGID"
userid=$PUID
groupid=$PGID
fi
chown -R "$userid":"$groupid" $conf_path
chown -R "$userid":"$groupid" $data_path
caddy start -config /usr/local/caddy/Caddyfile -adapter=caddyfile
su-exec "$userid":"$groupid" aria2c "$@"