Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔨 Rewrite Add-on to make use of S6 #36

Merged
merged 9 commits into from
Sep 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ updates:
schedule:
interval: daily
time: "06:00"
- package-ecosystem: "pip"
directory: "/tvheadend/"
schedule:
interval: daily
time: "06:00"
27 changes: 22 additions & 5 deletions tvheadend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,29 @@ ARG BUILD_FROM
# hadolint ignore=DL3006
FROM ${BUILD_FROM}

COPY run.sh /run.sh
RUN chmod +x /run.sh
RUN /run.sh
COPY requirements.txt /tmp/

RUN echo "Starting TVHeadend"
ENTRYPOINT ["/usr/bin/tvheadend", "--firstrun", "-u", "root", "-g", "root", "-c", "/config/tvheadend"]
RUN \
apk update \
&& apk add --no-cache --virtual .build-deps \
musl-dev=1.2.2-r3 \
gcc=10.3.1_git20210424-r2 \
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 \
-r /tmp/requirements.txt \
&& apk del --no-cache --purge .build-deps

# Copy root filesystem
COPY rootfs /

# Build arguments
ARG BUILD_ARCH
Expand Down
2 changes: 2 additions & 0 deletions tvheadend/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
setuptools==58.0.3
streamlink==2.4.0
60 changes: 60 additions & 0 deletions tvheadend/rootfs/etc/cont-init.d/tvheadend.sh
Original file line number Diff line number Diff line change
@@ -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!!'
1 change: 1 addition & 0 deletions tvheadend/rootfs/etc/cron.d/webgrabplus
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 0 * * * /config/tvheadend/wg++/run.sh
9 changes: 9 additions & 0 deletions tvheadend/rootfs/etc/services.d/cron/finish
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions tvheadend/rootfs/etc/services.d/cron/run
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions tvheadend/rootfs/etc/services.d/tvheadend/finish
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions tvheadend/rootfs/etc/services.d/tvheadend/run
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions tvheadend/rootfs/usr/bin/restart_addon
Original file line number Diff line number Diff line change
@@ -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
96 changes: 0 additions & 96 deletions tvheadend/run.sh

This file was deleted.