From 4f5055dc4af88367e7163284500fd24d3b70e1c7 Mon Sep 17 00:00:00 2001 From: Paul Hendryx Date: Tue, 18 Oct 2016 08:41:49 -0400 Subject: [PATCH 1/5] 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 From c3e2acd4c97e9c420864d2d9d36f8cc6f715d549 Mon Sep 17 00:00:00 2001 From: Paul Hendryx Date: Tue, 18 Oct 2016 08:43:09 -0400 Subject: [PATCH 2/5] readme version entry --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 2e0de5c..fdcd5a0 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,7 @@ The automatic update will run once a day at 3am local server time. ## Versions ++ **16.10.16:** Blocklist autoupdate with optional authentication. + **14.10.16:** Add version layer information. + **23.09.16:** Add information about securing the webui to README.. + **21.09.16:** Add curl package. From 8d7f56dcde2ff57298200bf9b922aff9b7a9b295 Mon Sep 17 00:00:00 2001 From: Paul Hendryx Date: Tue, 18 Oct 2016 08:45:09 -0400 Subject: [PATCH 3/5] dockerfile cleanup --- Dockerfile | 3 --- 1 file changed, 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 32ae922..3951887 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,9 +17,6 @@ RUN \ # copy local files COPY root/ / -# add files -ADD cron/ /etc/cron.d/ - # ports and volumes EXPOSE 9091 51413 VOLUME /config /downloads /watch From 401a469bb81bcb04bc76ba01f692e4053c5c81a7 Mon Sep 17 00:00:00 2001 From: Paul Hendryx Date: Tue, 18 Oct 2016 08:46:35 -0400 Subject: [PATCH 4/5] add newline --- root/defaults/blocklist-update.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/root/defaults/blocklist-update.sh b/root/defaults/blocklist-update.sh index ecd7946..af63791 100644 --- a/root/defaults/blocklist-update.sh +++ b/root/defaults/blocklist-update.sh @@ -9,4 +9,4 @@ if [ $RESULT == true ]; then else transmission-remote --blocklist-update fi -fi \ No newline at end of file +fi From 90510c1308256a433af79905e49ffac7c7a0a525 Mon Sep 17 00:00:00 2001 From: Paul Hendryx Date: Wed, 19 Oct 2016 09:34:04 -0400 Subject: [PATCH 5/5] change update script to download blocklist, decompress, restart service. no auth required. --- README.md | 5 +---- root/defaults/blocklist-update.sh | 16 +++++++--------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index fdcd5a0..bb951a5 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,6 @@ 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 \ @@ -49,8 +48,6 @@ 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`. @@ -88,7 +85,7 @@ Transmission will convert it to a hash when you restart the container after maki 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 is a shell script that downloads a blocklist from the url stored in the settings.json, gunzips it, and restarts the transmission daemon. The automatic update will run once a day at 3am local server time. diff --git a/root/defaults/blocklist-update.sh b/root/defaults/blocklist-update.sh index af63791..e3263df 100644 --- a/root/defaults/blocklist-update.sh +++ b/root/defaults/blocklist-update.sh @@ -1,12 +1,10 @@ #!/usr/bin/with-contenv bash -RESULT=`jq '.["blocklist-enabled"]' settings.json` -REQUIRE_AUTH=`jq '.["rpc-authentication-required"]' settings.json` +BLOCKLIST_URL=`jq -r '.["blocklist-url"]' 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 +rm /config/blocklists/* +cd /config/blocklists +wget -q $BLOCKLIST_URL +gunzip *.gz +chmod go+r * +s6-svc -h /var/run/s6/services/transmission