From 4cb339b119fa66126842359d3bad998c5d58795b Mon Sep 17 00:00:00 2001 From: Gautham Varma K <43441192+GauthamVarmaK@users.noreply.github.com> Date: Wed, 8 Sep 2021 20:23:36 +0530 Subject: [PATCH 1/9] :hammer: Rewrite Add-on to make use of S6 --- tvheadend/Dockerfile | 19 +++- tvheadend/rootfs/etc/cont-init.d/tvheadend.sh | 60 ++++++++++++ tvheadend/rootfs/etc/cron.d/webgrabplus | 1 + tvheadend/rootfs/etc/services.d/cron/finish | 9 ++ tvheadend/rootfs/etc/services.d/cron/run | 6 ++ .../rootfs/etc/services.d/tvheadend/finish | 9 ++ tvheadend/rootfs/etc/services.d/tvheadend/run | 9 ++ tvheadend/rootfs/usr/bin/restart_addon | 9 ++ tvheadend/run.sh | 96 ------------------- 9 files changed, 117 insertions(+), 101 deletions(-) create mode 100644 tvheadend/rootfs/etc/cont-init.d/tvheadend.sh create mode 100644 tvheadend/rootfs/etc/cron.d/webgrabplus create mode 100644 tvheadend/rootfs/etc/services.d/cron/finish create mode 100644 tvheadend/rootfs/etc/services.d/cron/run create mode 100644 tvheadend/rootfs/etc/services.d/tvheadend/finish create mode 100644 tvheadend/rootfs/etc/services.d/tvheadend/run create mode 100644 tvheadend/rootfs/usr/bin/restart_addon delete mode 100644 tvheadend/run.sh diff --git a/tvheadend/Dockerfile b/tvheadend/Dockerfile index 9ea13047..705042cf 100644 --- a/tvheadend/Dockerfile +++ b/tvheadend/Dockerfile @@ -2,12 +2,21 @@ ARG BUILD_FROM # hadolint ignore=DL3006 FROM ${BUILD_FROM} -COPY run.sh /run.sh -RUN chmod +x /run.sh -RUN /run.sh +RUN \ + apk update \ + && apk add --no-cache \ + tvheadend=4.2.8-r3 \ + py3-pip \ + && apk add --no-cache --virtual .build-deps \ + musl-dev \ + gcc \ + && pip3 install --no-cache --upgrade \ + setuptools \ + streamlink \ + && apk del --no-cache --purge .build-deps -RUN echo "Starting TVHeadend" -ENTRYPOINT ["/usr/bin/tvheadend", "--firstrun", "-u", "root", "-g", "root", "-c", "/config/tvheadend"] +# Copy root filesystem +COPY rootfs / # Build arguments ARG BUILD_ARCH diff --git a/tvheadend/rootfs/etc/cont-init.d/tvheadend.sh b/tvheadend/rootfs/etc/cont-init.d/tvheadend.sh new file mode 100644 index 00000000..14e5bf2e --- /dev/null +++ b/tvheadend/rootfs/etc/cont-init.d/tvheadend.sh @@ -0,0 +1,60 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Home Assistant Community Add-on: TVHeadend +# Executes user customizations on startup +# ============================================================================== + +check_webgrabplus(){ + if [ -z "$(ls -A /config/tvheadend/wg++)" ]; then return 1; else return 0; fi +} + +webgrabplus_install(){ + if apk update; then + bashio::log.info '[Webgrab+] APK: Installing required packages.' + if apk add --no-cache --virtual .build-deps git mono --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing; then + bashio::log.info '[Webgrab+] Installing Webgrab+.' + cd /tmp \ + && wget http://webgrabplus.com/sites/default/files/download/SW/V3.2.0/WebGrabPlus_V3.2_install.tar.gz \ + && tar -zxvf WebGrabPlus_V3.2_install.tar.gz \ + && rm WebGrabPlus_V3.2_install.tar.gz \ + && mv .wg++/ /config/tvheadend/wg++ \ + && cd /config/tvheadend/wg++ \ + && ./install.sh \ + && rm -rf siteini.pack/ \ + && wget http://webgrabplus.com/sites/default/files/download/ini/SiteIniPack_current.zip \ + && unzip SiteIniPack_current.zip \ + && rm SiteIniPack_current.zip \ + && cp siteini.pack/India/* siteini.user/ \ + && wget -O /usr/bin/tv_grab_wg++ http://www.webgrabplus.com/sites/default/files/tv_grab_wg.txt \ + && sed -i 's|~/.wg++/guide.xml|/config/tvheadend/wg++/guide.xml|g' /usr/bin/tv_grab_wg++ \ + && chmod a+x /usr/bin/tv_grab_wg++ + else + bashio::log.info '[Webgrab+] APK: Critical error. Unable install required packages.' + exit 1 + fi + bashio::log.info '[Webgrab+] APK: Removing packages no longer required.' + apk del --no-cache --purge .build-deps + else + bashio::log.error '[Webgrab+] APK: Critical error. Unable to update pkg list. Check connectivity.' + exit 1 + fi + bashio::log.info '[Webgrab+] Finsihed all APK and PIP3 updates and installs.' +} + +# Ensure directory exists +if ! bashio::fs.directory_exists '/config/tvheadend/'; then + bashio::log.info "Creating default configuration directory at /config/tvheadend/" + mkdir -p /config/tvheadend/recordings + timeout 20s /usr/bin/tvheadend --firstrun -u root -g root -c /config/tvheadend +fi + +if check_webgrabplus; then + bashio::log.info "[Webgrab+] Webgrab+ already installed" +else + bashio::log.info "[Webgrab+] No webgrab+ installation found - Installing webgrab+" + webgrabplus_install + chmod +x /usr/bin/restart_addon + exec /usr/bin/restart_addon +fi + +bashio::log.info '[Webgrab+] Setup completed without errors!!' diff --git a/tvheadend/rootfs/etc/cron.d/webgrabplus b/tvheadend/rootfs/etc/cron.d/webgrabplus new file mode 100644 index 00000000..09746af2 --- /dev/null +++ b/tvheadend/rootfs/etc/cron.d/webgrabplus @@ -0,0 +1 @@ +0 0 * * * /config/tvheadend/wg++/run.sh diff --git a/tvheadend/rootfs/etc/services.d/cron/finish b/tvheadend/rootfs/etc/services.d/cron/finish new file mode 100644 index 00000000..2809cd78 --- /dev/null +++ b/tvheadend/rootfs/etc/services.d/cron/finish @@ -0,0 +1,9 @@ +#!/usr/bin/execlineb -S0 +# ============================================================================== +# Home Assistant Community Add-on: TVHeadend +# Take down the S6 supervision tree when crond fails +# ============================================================================== +if -n { s6-test $# -ne 0 } +if -n { s6-test ${1} -eq 256 } + +s6-svscanctl -t /var/run/s6/services diff --git a/tvheadend/rootfs/etc/services.d/cron/run b/tvheadend/rootfs/etc/services.d/cron/run new file mode 100644 index 00000000..b94b1274 --- /dev/null +++ b/tvheadend/rootfs/etc/services.d/cron/run @@ -0,0 +1,6 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Home Assistant Community Add-on: TVHeadend +# Runs the cron daemon +# ============================================================================== +exec fdmove -c 2 1 /usr/sbin/crond -f -L /var/log/cron -l 0 -c /etc/crontabs diff --git a/tvheadend/rootfs/etc/services.d/tvheadend/finish b/tvheadend/rootfs/etc/services.d/tvheadend/finish new file mode 100644 index 00000000..00c21cfb --- /dev/null +++ b/tvheadend/rootfs/etc/services.d/tvheadend/finish @@ -0,0 +1,9 @@ +#!/usr/bin/execlineb -S0 +# ============================================================================== +# Home Assistant Community Add-on: TVHeadend +# Take down the S6 supervision tree when TVHeadend fails +# ============================================================================== +if -n { s6-test $# -ne 0 } +if -n { s6-test ${1} -eq 256 } + +s6-svscanctl -t /var/run/s6/services diff --git a/tvheadend/rootfs/etc/services.d/tvheadend/run b/tvheadend/rootfs/etc/services.d/tvheadend/run new file mode 100644 index 00000000..fa1eb93e --- /dev/null +++ b/tvheadend/rootfs/etc/services.d/tvheadend/run @@ -0,0 +1,9 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Home Assistant Community Add-on: TVHeadend +# Starts TVHeadend +# ============================================================================== + +bashio::log.info "Starting TVHeadend..." + +exec /usr/bin/tvheadend -u root -g root -c /config/tvheadend diff --git a/tvheadend/rootfs/usr/bin/restart_addon b/tvheadend/rootfs/usr/bin/restart_addon new file mode 100644 index 00000000..5308b50b --- /dev/null +++ b/tvheadend/rootfs/usr/bin/restart_addon @@ -0,0 +1,9 @@ +#!/usr/bin/env bashio +# ============================================================================== +# Home Assistant Community Add-on: TVHeadend +# Restarts the add-on +# ============================================================================== + +echo "Restarting add-on" + +bashio::addon.restart diff --git a/tvheadend/run.sh b/tvheadend/run.sh deleted file mode 100644 index e3446304..00000000 --- a/tvheadend/run.sh +++ /dev/null @@ -1,96 +0,0 @@ -#!/usr/bin/env bashio - -bashio::log.info "[TVHeadend] Installing TVHeadend" -apk update && apk add --no-cache tvheadend=4.2.8-r3 - -mkdir -p /config/tvheadend/recordings - -bashio::log.info '[TVHeadend] Setup completed without errors!!' - -check_webgrabplus(){ - if [ -z "$(ls -A /config/tvheadend/wg++)" ]; then return 1; else return 0; fi -} - -webgrabplus_install(){ - if apk update; then - bashio::log.info '[Webgrab+] APK: Installing required packages.' - if apk add --no-cache --virtual .build-deps git mono --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing; then - bashio::log.info '[Webgrab+] Installing Webgrab+.' - mkdir -p ~/.wg++ - ln -sf /config/tvheadend/wg++/guide.xml ~/.wg++/guide.xml - cd /tmp && \ - wget http://webgrabplus.com/sites/default/files/download/SW/V3.2.0/WebGrabPlus_V3.2_install.tar.gz && \ - tar -xvf WebGrabPlus_V3.2_install.tar.gz && rm WebGrabPlus_V3.2_install.tar.gz && \ - mv .wg++/ /config/tvheadend/wg++ && cd /config/tvheadend/wg++ && ./install.sh - rm -rf siteini.pack/ && \ - wget http://webgrabplus.com/sites/default/files/download/ini/SiteIniPack_current.zip && \ - unzip SiteIniPack_current.zip && rm SiteIniPack_current.zip && \ - cp siteini.pack/India/* siteini.user/ - - wget -O /usr/bin/tv_grab_wg++ http://www.webgrabplus.com/sites/default/files/tv_grab_wg.txt && \ - chmod a+x /usr/bin/tv_grab_wg++ - - echo "0 0 * * * /config/tvheadend/wg++/run.sh" >> /var/spool/cron/root - crond - else - bashio::log.info '[Webgrab+] APK: Critical error. Unable install required packages.' - exit 1 - fi - bashio::log.info '[Webgrab+] APK: Removing packages no longer required.' - apk del .build-deps git mono - else - bashio::log.error '[Webgrab+] APK: Critical error. Unable to update pkg list. Check connectivity.' - exit 1 - fi - bashio::log.info '[Webgrab+] Finsihed all APK and PIP3 updates and installs.' -} - -if check_webgrabplus; then - bashio::log.info "[Webgrab+] Webgrab+ already installed" -else - bashio::log.info "[Webgrab+] No webgrab+ installation found - Installing webgrab+" - webgrabplus_install -fi - -bashio::log.info '[Webgrab+] Setup completed without errors!!' - -check_streamlink () { - if [ -z "$(command -v streamlink)" ]; then return 1; else return 0; fi -} - -streamlink_update () { - if pip3 install --no-cache --upgrade streamlink; then - bashio::log.info "[StreamLink] Streamlink version: $(streamlink --version)." - else - bashio::log.error '[StreamLink] Streamlink update failed!' - fi -} - -streamlink_install () { - bashio::log.info '[StreamLink] APK: Updating pkg list.' - if apk update; then - bashio::log.info '[StreamLink] APK: Installing required packages.' - if apk add --no-cache py3-pip && apk add --no-cache --virtual .build-deps musl-dev gcc; then - bashio::log.info '[StreamLink] PIP3: Updating and installing required packages.' - if ! pip3 install --no-cache --upgrade setuptools; then bashio::log.error '[StreamLink] PIP3: Error while upgrading setuptools.'; fi - if ! pip3 install --no-cache streamlink; then bashio::log.error '[StreamLink] PIP3: Error while installing Streamlink.'; fi - else - bashio::log.info '[StreamLink] APK: Critical error. Unable install required packages.' - exit 1 - fi - bashio::log.info '[StreamLink] APK: Removing packages no longer required.' - apk del .build-deps gcc musl-dev - else - bashio::log.error '[StreamLink] APK: Critical error. Unable to update pkg list. Check connectivity.' - exit 1 - fi - bashio::log.info '[StreamLink] Finsihed all APK and PIP3 updates and installs.' -} - -if check_streamlink; then - bashio::log.info '[StreamLink] Updating Streamlink...' ; streamlink_update -else - bashio::log.info '[StreamLink] Installing Streamlink...'; streamlink_install -fi - -bashio::log.info '[StreamLink] Setup completed without errors!!' From 2fb98c1fce1f9241ca72c4099bd7c8e185ed8cd8 Mon Sep 17 00:00:00 2001 From: Gautham Varma K <43441192+GauthamVarmaK@users.noreply.github.com> Date: Wed, 8 Sep 2021 20:40:07 +0530 Subject: [PATCH 2/9] :hammer: Use requirements.txt --- .github/dependabot.yaml | 5 +++++ tvheadend/Dockerfile | 12 ++++++++---- tvheadend/requirements.txt | 2 ++ 3 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 tvheadend/requirements.txt diff --git a/.github/dependabot.yaml b/.github/dependabot.yaml index 45dd97a4..c5c23888 100644 --- a/.github/dependabot.yaml +++ b/.github/dependabot.yaml @@ -6,3 +6,8 @@ updates: schedule: interval: daily time: "06:00" + - package-ecosystem: "pip" + directory: "/tvheadend/" + schedule: + interval: daily + time: "06:00" diff --git a/tvheadend/Dockerfile b/tvheadend/Dockerfile index 705042cf..5bde2272 100644 --- a/tvheadend/Dockerfile +++ b/tvheadend/Dockerfile @@ -2,17 +2,21 @@ ARG BUILD_FROM # hadolint ignore=DL3006 FROM ${BUILD_FROM} +COPY requirements.txt /tmp/ + RUN \ apk update \ && apk add --no-cache \ tvheadend=4.2.8-r3 \ - py3-pip \ + py3-pip=20.3.4-r1 \ && apk add --no-cache --virtual .build-deps \ musl-dev \ gcc \ - && pip3 install --no-cache --upgrade \ - setuptools \ - streamlink \ + && pip3 install \ + --upgrade \ + --no-cache-dir \ + --prefer-binary \ + -r /tmp/requirements.txt \ && apk del --no-cache --purge .build-deps # Copy root filesystem diff --git a/tvheadend/requirements.txt b/tvheadend/requirements.txt new file mode 100644 index 00000000..b6616671 --- /dev/null +++ b/tvheadend/requirements.txt @@ -0,0 +1,2 @@ +setuptools==58.0.3 +streamlink==2.4.0 From c12e08eeadbc6066ec87818055992fbff38a6962 Mon Sep 17 00:00:00 2001 From: Gautham Varma K <43441192+GauthamVarmaK@users.noreply.github.com> Date: Wed, 8 Sep 2021 20:42:28 +0530 Subject: [PATCH 3/9] :green_heart: Satisfy Hadolint --- tvheadend/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tvheadend/Dockerfile b/tvheadend/Dockerfile index 5bde2272..1f661d39 100644 --- a/tvheadend/Dockerfile +++ b/tvheadend/Dockerfile @@ -10,8 +10,8 @@ RUN \ tvheadend=4.2.8-r3 \ py3-pip=20.3.4-r1 \ && apk add --no-cache --virtual .build-deps \ - musl-dev \ - gcc \ + musl-dev=1.2.2-r3 \ + gcc=10.3.1_git20210424-r2 \ && pip3 install \ --upgrade \ --no-cache-dir \ From 8cf9819289463e0e8e4a97261a056e0338f25b32 Mon Sep 17 00:00:00 2001 From: Gautham Varma K <43441192+GauthamVarmaK@users.noreply.github.com> Date: Wed, 8 Sep 2021 20:48:00 +0530 Subject: [PATCH 4/9] :green_heart: Fix Streamlink Build Error --- tvheadend/Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tvheadend/Dockerfile b/tvheadend/Dockerfile index 1f661d39..50b34a14 100644 --- a/tvheadend/Dockerfile +++ b/tvheadend/Dockerfile @@ -12,6 +12,8 @@ RUN \ && apk add --no-cache --virtual .build-deps \ musl-dev=1.2.2-r3 \ gcc=10.3.1_git20210424-r2 \ + libxml2=2.9.12-r1 \ + libxslt=1.1.34-r1 \ && pip3 install \ --upgrade \ --no-cache-dir \ From af4e333eca2de478ac58bd044a1f87ab721d0e55 Mon Sep 17 00:00:00 2001 From: Gautham Varma K <43441192+GauthamVarmaK@users.noreply.github.com> Date: Wed, 8 Sep 2021 20:54:37 +0530 Subject: [PATCH 5/9] :grimacing: Attempt to fix build --- tvheadend/Dockerfile | 3 --- 1 file changed, 3 deletions(-) diff --git a/tvheadend/Dockerfile b/tvheadend/Dockerfile index 50b34a14..d81d7447 100644 --- a/tvheadend/Dockerfile +++ b/tvheadend/Dockerfile @@ -12,10 +12,7 @@ RUN \ && apk add --no-cache --virtual .build-deps \ musl-dev=1.2.2-r3 \ gcc=10.3.1_git20210424-r2 \ - libxml2=2.9.12-r1 \ - libxslt=1.1.34-r1 \ && pip3 install \ - --upgrade \ --no-cache-dir \ --prefer-binary \ -r /tmp/requirements.txt \ From d4913e49bb78c8d744162e5b9dd1aabcab108b21 Mon Sep 17 00:00:00 2001 From: Gautham Varma K <43441192+GauthamVarmaK@users.noreply.github.com> Date: Wed, 8 Sep 2021 21:01:26 +0530 Subject: [PATCH 6/9] :grimacing: Try fixing build by pinning python version --- tvheadend/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/tvheadend/Dockerfile b/tvheadend/Dockerfile index d81d7447..049f1c56 100644 --- a/tvheadend/Dockerfile +++ b/tvheadend/Dockerfile @@ -9,6 +9,7 @@ RUN \ && apk add --no-cache \ tvheadend=4.2.8-r3 \ py3-pip=20.3.4-r1 \ + python3=3.9.6-r0 && apk add --no-cache --virtual .build-deps \ musl-dev=1.2.2-r3 \ gcc=10.3.1_git20210424-r2 \ From 3b62e8540a8f9065c9a7e2937e641b616c45e54a Mon Sep 17 00:00:00 2001 From: Gautham Varma K <43441192+GauthamVarmaK@users.noreply.github.com> Date: Wed, 8 Sep 2021 21:03:44 +0530 Subject: [PATCH 7/9] =?UTF-8?q?=F0=9F=A4=A1=20Add=20a=20backslash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tvheadend/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tvheadend/Dockerfile b/tvheadend/Dockerfile index 049f1c56..b63d09b4 100644 --- a/tvheadend/Dockerfile +++ b/tvheadend/Dockerfile @@ -9,7 +9,7 @@ RUN \ && apk add --no-cache \ tvheadend=4.2.8-r3 \ py3-pip=20.3.4-r1 \ - python3=3.9.6-r0 + python3=3.9.6-r0 \ && apk add --no-cache --virtual .build-deps \ musl-dev=1.2.2-r3 \ gcc=10.3.1_git20210424-r2 \ From 267add9f4bde70a72cc30de1ff61a30e5b2e0816 Mon Sep 17 00:00:00 2001 From: Gautham Varma K <43441192+GauthamVarmaK@users.noreply.github.com> Date: Wed, 8 Sep 2021 21:28:57 +0530 Subject: [PATCH 8/9] :wrench: Fix lxml build --- tvheadend/Dockerfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tvheadend/Dockerfile b/tvheadend/Dockerfile index b63d09b4..70324514 100644 --- a/tvheadend/Dockerfile +++ b/tvheadend/Dockerfile @@ -9,10 +9,12 @@ RUN \ && apk add --no-cache \ tvheadend=4.2.8-r3 \ py3-pip=20.3.4-r1 \ - python3=3.9.6-r0 \ + libxslt=1.1.34-r1 \ && apk add --no-cache --virtual .build-deps \ musl-dev=1.2.2-r3 \ - gcc=10.3.1_git20210424-r2 \ + gcc=10.3.1_git20210424-r2 \ + libc-dev=0.7.2-r3 \ + libxslt-dev=1.1.34-r1 \ && pip3 install \ --no-cache-dir \ --prefer-binary \ From 8a9419a0d8a0d58deca2328ead0083059be37bf2 Mon Sep 17 00:00:00 2001 From: Gautham Varma K <43441192+GauthamVarmaK@users.noreply.github.com> Date: Thu, 9 Sep 2021 06:56:48 +0530 Subject: [PATCH 9/9] :wrench: Fix lxml build with updated deps --- tvheadend/Dockerfile | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tvheadend/Dockerfile b/tvheadend/Dockerfile index 70324514..11696c01 100644 --- a/tvheadend/Dockerfile +++ b/tvheadend/Dockerfile @@ -6,15 +6,17 @@ COPY requirements.txt /tmp/ RUN \ apk update \ - && apk add --no-cache \ - tvheadend=4.2.8-r3 \ - py3-pip=20.3.4-r1 \ - libxslt=1.1.34-r1 \ && apk add --no-cache --virtual .build-deps \ musl-dev=1.2.2-r3 \ gcc=10.3.1_git20210424-r2 \ - libc-dev=0.7.2-r3 \ + g++=10.3.1_git20210424-r2 \ + libxml2-dev=2.9.12-r1 \ libxslt-dev=1.1.34-r1 \ + python3-dev=3.9.5-r1 \ + && apk add --no-cache \ + tvheadend=4.2.8-r3 \ + py3-pip=20.3.4-r1 \ + libxslt=1.1.34-r1 \ && pip3 install \ --no-cache-dir \ --prefer-binary \