From f340dab3a62949e3b348dbac833ae5483af172a1 Mon Sep 17 00:00:00 2001 From: Alexandre Date: Sun, 16 Jan 2022 08:07:28 +0100 Subject: [PATCH] clean --- fireflyiii/Dockerfile | 13 ++- .../rootfs/etc/cont-init.d/00-banner.sh | 39 ------- .../rootfs/etc/cont-init.d/00-global_var.sh | 35 ------ .../rootfs/etc/cont-init.d/92-config_yaml.sh | 103 ------------------ 4 files changed, 12 insertions(+), 178 deletions(-) delete mode 100644 fireflyiii/rootfs/etc/cont-init.d/00-banner.sh delete mode 100644 fireflyiii/rootfs/etc/cont-init.d/00-global_var.sh delete mode 100644 fireflyiii/rootfs/etc/cont-init.d/92-config_yaml.sh diff --git a/fireflyiii/Dockerfile b/fireflyiii/Dockerfile index 110e9e598..a2aa958ed 100644 --- a/fireflyiii/Dockerfile +++ b/fireflyiii/Dockerfile @@ -43,8 +43,19 @@ FROM ${BUILD_FROM} # Copy local files COPY rootfs/ / +# Modules +ARG MODULES="00-banner.sh 00-global_var.sh 90-config_yaml.sh" + +# Automatic modules download +RUN if ! command -v bash >/dev/null 2>/dev/null; then (apt-get update && apt-get install -yqq --no-install-recommends bash || apk add --no-cache bash); fi && \ + if ! command -v curl >/dev/null 2>/dev/null; then (apt-get update && apt-get install -yqq --no-install-recommends curl || apk add --no-cache curl); fi && \ + mkdir -p /tmpscripts /etc/cont-init.d && \ + for scripts in $MODULES; do curl -L -f -s "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/zzz_templates/$scripts" -o /tmpscripts/"$scripts"; done && \ + if [ -d /etc/cont-init.d ]; then /bin/cp -rf /tmpscripts/* /etc/cont-init.d/ && chmod -R 755 /etc/cont-init.d; fi && \ + rm -rf /tmpscripts || printf '%s\n' "${MODULES:-}" > /MODULESFILE + # Manual apps -ENV PACKAGES="cron sqlite3" +ENV PACKAGES="cron" # Automatic apps & bashio RUN if ! command -v bash >/dev/null 2>/dev/null; then (apt-get update && apt-get install -yqq --no-install-recommends bash || apk add --no-cache bash) >/dev/null; fi && \ diff --git a/fireflyiii/rootfs/etc/cont-init.d/00-banner.sh b/fireflyiii/rootfs/etc/cont-init.d/00-banner.sh deleted file mode 100644 index 0ac294e9a..000000000 --- a/fireflyiii/rootfs/etc/cont-init.d/00-banner.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/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/fireflyiii/rootfs/etc/cont-init.d/00-global_var.sh b/fireflyiii/rootfs/etc/cont-init.d/00-global_var.sh deleted file mode 100644 index dbfcba3b4..000000000 --- a/fireflyiii/rootfs/etc/cont-init.d/00-global_var.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/with-contenv bashio - -################################### -# 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}) - line="${KEYS}=${VALUE//[\"\']/}" - # Use locally - if ! bashio::config.false "verbose"; then bashio::log.blue "$line"; fi - export $line - # Export the variable to run scripts - line="${KEYS}=${VALUE//[\"\']/} &>/dev/null" - sed -i "1a export $line" /etc/services.d/*/*run* 2>/dev/null || true - sed -i "1a export $line" /etc/cont-init.d/*run* 2>/dev/null || true -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 - fi -fi - diff --git a/fireflyiii/rootfs/etc/cont-init.d/92-config_yaml.sh b/fireflyiii/rootfs/etc/cont-init.d/92-config_yaml.sh deleted file mode 100644 index 6d95fd4d4..000000000 --- a/fireflyiii/rootfs/etc/cont-init.d/92-config_yaml.sh +++ /dev/null @@ -1,103 +0,0 @@ -#!/usr/bin/with-contenv bashio - -################## -# INITIALIZATION # -################## - -# Where is the config -CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION") - -# Check if config file is there, or create one from template -if [ -f $CONFIGSOURCE ]; then - echo "Using config file found in $CONFIGSOURCE" -else - echo "No config file, creating one from template" - # Create folder - mkdir -p "$(dirname "${CONFIGSOURCE}")" - # Placing template in config - if [ -f /templates/config.yaml ]; then - # Use available template - cp /templates/config.yaml "$(dirname "${CONFIGSOURCE}")" - else - # Download template - TEMPLATESOURCE="https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/zzz_templates/config.template" - curl -L -f -s $TEMPLATESOURCE --output $CONFIGSOURCE - fi - # Need to restart - bashio::log.fatal "Config file not found, creating a new one. Please customize the file in $CONFIGSOURCE before restarting." - # bashio::exit.nok -fi - -# Check if yaml is valid -EXIT_CODE=0 -yamllint -d relaxed $CONFIGSOURCE &>ERROR || EXIT_CODE=$? -if [ $EXIT_CODE = 0 ]; then - echo "Config file is a valid yaml" -else - cat ERROR - bashio::log.fatal "Config file has an invalid yaml format. Please check the file in $CONFIGSOURCE. Errors list above." - # bashio::exit.nok -fi - -# Export all yaml entries as env variables -# Helper function -function parse_yaml { - local prefix=$2 || local prefix="" - local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @ | tr @ '\034') - sed -ne "s|^\($s\):|\1|" \ - -e "s| #.*$||g" \ - -e "s|#.*$||g" \ - -e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \ - -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 | - awk -F$fs '{ - indent = length($1)/2; - vname[indent] = $2; - for (i in vname) {if (i > indent) {delete vname[i]}} - if (length($3) > 0) { - vn=""; for (i=0; i/tmpfile -while IFS= read -r line; do - # Clean output - line=${line//[\"\']/} - # Check if secret - if [[ "${line}" == *'!secret '* ]]; then - echo "secret detected" - secret=${line#*secret } - # Check if single match - secretnum=$(sed -n "/$secret:/=" /config/secrets.yaml) - [[ $(echo $secretnum) == *' '* ]] && bashio::exit.nok "There are multiple matches for your password name. Please check your secrets.yaml file" - # Get text - secret=$(sed -n "/$secret:/p" /config/secrets.yaml) - secret=${secret#*: } - line="${line%%=*}=$secret" - fi - # Data validation - if [[ $line =~ ^.+[=].+$ ]]; then - export $line - # Export the variable - sed -i "1a export $line" /etc/services.d/*/*run* 2>/dev/null || true - sed -i "1a export $line" /scripts/*run* 2>/dev/null || true - sed -i "1a export $line" /etc/cont-init.d/*run* 2>/dev/null || true - # Show in log - if ! bashio::config.false "verbose"; then bashio::log.blue "$line"; fi - else - bashio::exit.nok "$line does not follow the correct structure. Please check your yaml file." - fi -done <"/tmpfile" - -# Test mode -TZ=$(bashio::config "TZ") -if [ $TZ = "test" ]; then - echo "secret mode found, launching script in /config/test.sh" - cd /config - chmod 777 test.sh - ./test.sh -fi