From fa7cb77ec6784d41a8e6f1c0b9f76e036d04f456 Mon Sep 17 00:00:00 2001 From: Alexandre Date: Tue, 7 Dec 2021 20:51:14 +0100 Subject: [PATCH] new logic entrypoint --- joal/Dockerfile | 27 +++++++----- joal/rootfs/entrypoint.sh | 44 +++++++++++++++++++ .../scripts/00-aaa_dockerfile_backup.sh | 29 ++++++++++++ joal/rootfs/scripts/00-banner.sh | 39 ++++++++++++++++ joal/rootfs/{run.sh => scripts/99-run.sh} | 39 ---------------- 5 files changed, 127 insertions(+), 51 deletions(-) create mode 100644 joal/rootfs/entrypoint.sh create mode 100644 joal/rootfs/scripts/00-aaa_dockerfile_backup.sh create mode 100644 joal/rootfs/scripts/00-banner.sh rename joal/rootfs/{run.sh => scripts/99-run.sh} (75%) diff --git a/joal/Dockerfile b/joal/Dockerfile index 41ea395e2..0c87dc1d1 100644 --- a/joal/Dockerfile +++ b/joal/Dockerfile @@ -8,15 +8,16 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"] ARG BUILD_VERSION ARG BUILD_UPSTREAM="2.1.27" ENV BASHIO_VERSION=0.14.3 +ENV PACKAGES="wget \ + jq \ + nginx" RUN \ #Install bashio apt-get clean \ && apt-get update \ - && apt-get install -y --no-install-recommends \ - wget \ - jq \ - nginx \ + && apt-get install -y --no-install-recommends ${PACKAGES} \ + \ ################## # Install bashio # ################## @@ -28,10 +29,11 @@ RUN \ --strip 1 -C /tmp/bashio \ \ && mv /tmp/bashio/lib /usr/lib/bashio \ - && ln -s /usr/lib/bashio/bashio /usr/bin/bashio \ - \ + && ln -s /usr/lib/bashio/bashio /usr/bin/bashio || true + +RUN \ #Install Joal - && wget -O /tmp/joal.tar.gz "https://github.com/anthonyraymond/joal/releases/download/$BUILD_UPSTREAM/joal.tar.gz" \ + wget -O /tmp/joal.tar.gz "https://github.com/anthonyraymond/joal/releases/download/$BUILD_UPSTREAM/joal.tar.gz" \ && mkdir -p /data/joal \ && tar zxvf /tmp/joal.tar.gz -C /data/joal \ && rm /data/joal/jack-of* \ @@ -43,11 +45,12 @@ RUN \ VOLUME [ "/data" ] -# Copy root filesystem -COPY rootfs / -RUN chmod 777 /run.sh - -ENTRYPOINT [ "/run.sh" ] +# copy local files +COPY rootfs/ / +#WORKDIR / +RUN chmod 777 /entrypoint.sh +ENTRYPOINT [ "/usr/bin/env" ] +CMD [ "/entrypoint.sh" ] ### LABELS ARG BUILD_ARCH diff --git a/joal/rootfs/entrypoint.sh b/joal/rootfs/entrypoint.sh new file mode 100644 index 000000000..635dbc865 --- /dev/null +++ b/joal/rootfs/entrypoint.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +echo "Starting..." + +################################### +# Export all addon options as env # +################################### + +# For all keys in options.json +JSONSOURCE="/data/options.json" + +# Export keys as env variables +echo "All addon options were exported as variables" +mapfile -t arr < <(jq -r 'keys[]' ${JSONSOURCE}) +for KEYS in ${arr[@]}; do + # export key + VALUE=$(jq .$KEYS ${JSONSOURCE}) + export ${KEYS}=${VALUE//[\"\']/} &>/dev/null +done + +################ +# Set timezone # +################ +if [ ! -z "TZ" ] && [ -f /etc/localtime ]; then + if [ -f /usr/share/zoneinfo/$TZ ]; then + echo "Timezone set from $(cat /etc/timezone) to $TZ" + ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ >/etc/timezone + else + echo "WARNING : Timezone $TZ is invalid, it will be kept to default value of $(cat /etc/timezone)" + fi +fi + +#################### +# Starting scripts # +#################### + +for SCRIPTS in scripts/*; do + [ -e "$SCRIPTS" ] || continue + echo "$SCRIPTS: executing" + chown $(id -u):$(id -g) $SCRIPTS + chmod a+x $SCRIPTS + sed -i 's|/usr/bin/with-contenv bashio|/usr/bin/env bashio|g' $SCRIPTS || true + ./$SCRIPTS || echo "$SCRIPTS: exiting $?" +done diff --git a/joal/rootfs/scripts/00-aaa_dockerfile_backup.sh b/joal/rootfs/scripts/00-aaa_dockerfile_backup.sh new file mode 100644 index 000000000..612e26d7e --- /dev/null +++ b/joal/rootfs/scripts/00-aaa_dockerfile_backup.sh @@ -0,0 +1,29 @@ +#!/bin/bash +# If dockerfile failed install manually +if [ ! -f "/usr/bin/bashio" ]; then + echo "Bashio does not exist, executing script" + ( + ################ + # Install apps # + ################ + PACKAGES="${PACKAGES:="curl"}" + + apt-get clean \ + && apt-get update \ + && apt-get install -y --no-install-recommends ${PACKAGES} 2>/dev/null \ + || apk add --no-cache ${PACKAGES} + + ################### + # Install bashio # + ################## + + mkdir -p /tmp/bashio + curl -L -f -s "https://github.com/hassio-addons/bashio/archive/v${BASHIO_VERSION}.tar.gz" | + tar -xzf - --strip 1 -C /tmp/bashio + mv /tmp/bashio/lib /usr/lib/bashio + ln -s /usr/lib/bashio/bashio /usr/bin/bashio + rm -rf /tmp/bashio + + ) >/dev/null + +fi diff --git a/joal/rootfs/scripts/00-banner.sh b/joal/rootfs/scripts/00-banner.sh new file mode 100644 index 000000000..0ac294e9a --- /dev/null +++ b/joal/rootfs/scripts/00-banner.sh @@ -0,0 +1,39 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Displays a simple add-on banner on startup +# ============================================================================== + +if bashio::supervisor.ping; then + bashio::log.blue \ + '-----------------------------------------------------------' + bashio::log.blue " Add-on: $(bashio::addon.name)" + bashio::log.blue " $(bashio::addon.description)" + bashio::log.blue \ + '-----------------------------------------------------------' + + bashio::log.blue " Add-on version: $(bashio::addon.version)" + if bashio::var.true "$(bashio::addon.update_available)"; then + bashio::log.magenta ' There is an update available for this add-on!' + bashio::log.magenta \ + " Latest add-on version: $(bashio::addon.version_latest)" + bashio::log.magenta ' Please consider upgrading as soon as possible.' + else + bashio::log.green ' You are running the latest version of this add-on.' + fi + + bashio::log.blue " System: $(bashio::info.operating_system)" \ + " ($(bashio::info.arch) / $(bashio::info.machine))" + bashio::log.blue " Home Assistant Core: $(bashio::info.homeassistant)" + bashio::log.blue " Home Assistant Supervisor: $(bashio::info.supervisor)" + + bashio::log.blue \ + '-----------------------------------------------------------' + bashio::log.blue \ + ' Please, share the above information when looking for help' + bashio::log.blue \ + ' or support in, e.g., GitHub, forums' + bashio::log.green \ + ' https://github.com/alexbelgium/hassio-addons' + bashio::log.blue \ + '-----------------------------------------------------------' +fi diff --git a/joal/rootfs/run.sh b/joal/rootfs/scripts/99-run.sh similarity index 75% rename from joal/rootfs/run.sh rename to joal/rootfs/scripts/99-run.sh index 1c0510fb7..eec197a1f 100644 --- a/joal/rootfs/run.sh +++ b/joal/rootfs/scripts/99-run.sh @@ -1,44 +1,5 @@ #!/usr/bin/env bashio -########## -# BANNER # -########## - -if bashio::supervisor.ping; then - bashio::log.blue \ - '-----------------------------------------------------------' - bashio::log.blue " Add-on: $(bashio::addon.name)" - bashio::log.blue " $(bashio::addon.description)" - bashio::log.blue \ - '-----------------------------------------------------------' - - bashio::log.blue " Add-on version: $(bashio::addon.version)" - if bashio::var.true "$(bashio::addon.update_available)"; then - bashio::log.magenta ' There is an update available for this add-on!' - bashio::log.magenta \ - " Latest add-on version: $(bashio::addon.version_latest)" - bashio::log.magenta ' Please consider upgrading as soon as possible.' - else - bashio::log.green ' You are running the latest version of this add-on.' - fi - - bashio::log.blue " System: $(bashio::info.operating_system)" \ - " ($(bashio::info.arch) / $(bashio::info.machine))" - bashio::log.blue " Home Assistant Core: $(bashio::info.homeassistant)" - bashio::log.blue " Home Assistant Supervisor: $(bashio::info.supervisor)" - - bashio::log.blue \ - '-----------------------------------------------------------' - bashio::log.blue \ - ' Please, share the above information when looking for help' - bashio::log.blue \ - ' or support in, e.g., GitHub, forums or the Discord chat.' - bashio::log.green \ - ' https://github.com/alexbelgium/hassio-addons' - bashio::log.blue \ - '-----------------------------------------------------------' -fi - ################ # JOAL SETTING # ################