diff --git a/addons_updater/Dockerfile b/addons_updater/Dockerfile index a72cedbc0..e75dce42c 100644 --- a/addons_updater/Dockerfile +++ b/addons_updater/Dockerfile @@ -10,10 +10,12 @@ RUN \ && pip install --upgrade pip \ && pip install lastversion -# Copy script -COPY run.sh / -RUN chmod a+x /run.sh -CMD [ "/run.sh"] +# copy local files +COPY rootfs/ / +#WORKDIR / +RUN chmod 777 /entrypoint.sh +ENTRYPOINT [ "/usr/bin/env" ] +CMD [ "/entrypoint.sh" ] # Set shell SHELL ["/bin/bash", "-o", "pipefail", "-c"] diff --git a/addons_updater/rootfs/entrypoint.sh b/addons_updater/rootfs/entrypoint.sh new file mode 100644 index 000000000..635dbc865 --- /dev/null +++ b/addons_updater/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/addons_updater/rootfs/scripts/00-aaa_dockerfile_backup.sh b/addons_updater/rootfs/scripts/00-aaa_dockerfile_backup.sh new file mode 100644 index 000000000..612e26d7e --- /dev/null +++ b/addons_updater/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/addons_updater/rootfs/scripts/00-banner.sh b/addons_updater/rootfs/scripts/00-banner.sh new file mode 100644 index 000000000..0ac294e9a --- /dev/null +++ b/addons_updater/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/addons_updater/run.sh b/addons_updater/rootfs/scripts/99-run.sh similarity index 100% rename from addons_updater/run.sh rename to addons_updater/rootfs/scripts/99-run.sh