forked from XUJINKAI/aria2-with-webui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit
20 lines (14 loc) · 911 Bytes
/
init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/sh
set -e
PUID=${PUID:-1000}
PGID=${PGID:-1000}
SECRET="${SECRET:-watching}"
WEB_HOME="${WEB_HOME:-/ariang}"
[ -f /conf/aria2.conf ] || cp /aria2.conf /conf/aria2.conf
grep '^rpc-secret=' /conf/aria2.conf &>/dev/null || echo "rpc-secret=${SECRET}" >> /conf/aria2.conf
touch /conf/aria2.session /conf/aria2.log /conf/darkhttpd.log /conf/dht.dat /conf/dht6.dat
chown $PUID:$PGID /conf/aria2.conf /conf/aria2.session /conf/aria2.log /conf/darkhttpd.log /conf/dht.dat /conf/dht6.dat
s6-setuidgid $PUID:$PGID darkhttpd ${WEB_HOME} --daemon --port 8080 --log /conf/darkhttpd.log
s6-setuidgid $PUID:$PGID inotifywait -m -e create -e moved_to --format '%w%f' '/watch' | \
s6-setuidgid $PUID:$PGID xargs -n 1 -I {} sh -c 'echo "{}" | grep "\.torrent$"; if [ $? -eq 0 ]; then echo aria2p -s ${SECRET} add "{}"; aria2p -s "'${SECRET}'" add "{}" && mv "{}" "{}.added"; fi' &
exec s6-setuidgid $PUID:$PGID "$@"