From 4f5055dc4af88367e7163284500fd24d3b70e1c7 Mon Sep 17 00:00:00 2001 From: Paul Hendryx Date: Tue, 18 Oct 2016 08:41:49 -0400 Subject: [PATCH] blocklist w/ cron --- Dockerfile | 5 +++++ README.md | 10 ++++++++++ root/defaults/blocklist-update.sh | 12 ++++++++++++ root/etc/cont-init.d/20-config | 7 +++++++ root/etc/crontabs/root | 10 ++++++++++ root/etc/services.d/cron/run | 3 +++ 6 files changed, 47 insertions(+) create mode 100644 root/defaults/blocklist-update.sh create mode 100644 root/etc/crontabs/root create mode 100644 root/etc/services.d/cron/run diff --git a/Dockerfile b/Dockerfile index 662ab0f..32ae922 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,11 +10,16 @@ LABEL build_version="Linuxserver.io version:- ${VERSION} Build-date:- ${BUILD_DA RUN \ apk add --no-cache \ curl \ + jq \ + transmission-cli \ transmission-daemon # copy local files COPY root/ / +# add files +ADD cron/ /etc/cron.d/ + # ports and volumes EXPOSE 9091 51413 VOLUME /config /downloads /watch diff --git a/README.md b/README.md index 139c700..2e0de5c 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ docker create --name=transmission \ -v :/downloads \ -v :/watch \ -e PGID= -e PUID= \ +-e UIUSER= -e UIPASS= -e TZ= \ -p 9091:9091 -p 51413:51413 \ -p 51413:51413/udp \ @@ -48,6 +49,8 @@ http://192.168.x.x:8080 would show you what's running INSIDE the container on po * `-v /watch` - watch folder for torrent files * `-e PGID` for GroupID - see below for explanation * `-e PUID` for UserID - see below for explanation +* `-e UIUSER` for WebUI Username - see Updating Blocklists Automatically for explanation +* `-e UIPASS` for WebUI Password - see Updating Blocklists Automatically for explanation * `-e TZ` for timezone information, eg Europe/London It is based on alpine linux with s6 overlay, for shell access whilst the container is running do `docker exec -it transmission /bin/bash`. @@ -81,6 +84,13 @@ this requires 3 settings to be changed in the settings.json file. Transmission will convert it to a hash when you restart the container after making the above edits. +## Updating Blocklists Automatically + +This requires `"blocklist-enabled": true,` to be set. By setting this to true, it is assumed you have also populated `blocklist-url` with a valid block list. + +If you have webui security enabled, you will need to set the `UIUSER` and `UIPASS` environment variables in your docker configuration. + +The automatic update will run once a day at 3am local server time. ## Info diff --git a/root/defaults/blocklist-update.sh b/root/defaults/blocklist-update.sh new file mode 100644 index 0000000..ecd7946 --- /dev/null +++ b/root/defaults/blocklist-update.sh @@ -0,0 +1,12 @@ +#!/usr/bin/with-contenv bash + +RESULT=`jq '.["blocklist-enabled"]' settings.json` +REQUIRE_AUTH=`jq '.["rpc-authentication-required"]' settings.json` + +if [ $RESULT == true ]; then + if [ $REQUIRE_AUTH == true ]; then + transmission-remote -n $UIUSER:$UIPASS --blocklist-update + else + transmission-remote --blocklist-update + fi +fi \ No newline at end of file diff --git a/root/etc/cont-init.d/20-config b/root/etc/cont-init.d/20-config index 04486b2..1357a57 100644 --- a/root/etc/cont-init.d/20-config +++ b/root/etc/cont-init.d/20-config @@ -8,10 +8,17 @@ mkdir -p \ [[ ! -f /config/settings.json ]] && cp \ /defaults/settings.json /config/settings.json +# copy blocklist-update script +[[ ! -f /config/blocklist-update.sh ]] && cp \ + /defaults/blocklist-update.sh /config/blocklist-update.sh + # permissions chown abc:abc \ /config/settings.json \ + /config/blocklist-update.sh \ /downloads \ /downloads/complete \ /downloads/incomplete \ /watch + +chmod 755 /config/blocklist-update.sh diff --git a/root/etc/crontabs/root b/root/etc/crontabs/root new file mode 100644 index 0000000..0c91e82 --- /dev/null +++ b/root/etc/crontabs/root @@ -0,0 +1,10 @@ +# do daily/weekly/monthly maintenance +# min hour day month weekday command +*/15 * * * * run-parts /etc/periodic/15min +0 * * * * run-parts /etc/periodic/hourly +0 2 * * * run-parts /etc/periodic/daily +0 3 * * 6 run-parts /etc/periodic/weekly +0 5 1 * * run-parts /etc/periodic/monthly + +# run daily blocklist update +0 3 * * * /config/blocklist-update.sh 2>&1 diff --git a/root/etc/services.d/cron/run b/root/etc/services.d/cron/run new file mode 100644 index 0000000..a1b27f4 --- /dev/null +++ b/root/etc/services.d/cron/run @@ -0,0 +1,3 @@ +#!/usr/bin/with-contenv bash + +/usr/sbin/crond -f -S -l 0 -c /etc/crontabs