#!/bin/ash
if ! [ -z $NGINX_LISTEN_SOCKET ]; then
sed -i 's#listen 80#listen unix:/var/run/nginx.sock#' /etc/nginx/conf.d/default.conf
rm -f /var/run/nginx.sock
fi
nginx
touch /data/torrents
chown $UID /data/torrents
su-exec $UID aria2c \
--show-console-readout false \
--summary-interval=0 \
--enable-rpc \
--bt-save-metadata \
--bt-load-saved-metadata \
--force-save \
--listen-port=${LISTEN_PORT:-6881-6889} \
--dht-listen-port=${DHT_LISTEN_PORT:-6881-6889} \
--seed-ratio=0 \
--dir /data/ \
--save-session /data/torrents \
--save-session-interval 900 \
-i /data/torrents