From 4e7933306e322a193b17acb7c8ce82ca252caa0a Mon Sep 17 00:00:00 2001 From: Timmo Date: Sat, 6 Oct 2018 17:40:59 +0100 Subject: [PATCH] :hammer: replace copy with symlink from /config --- .../rootfs/etc/cont-init.d/20-config.sh | 9 +++-- .../etc/cont-init.d/{40-api.sh => 30-api.sh} | 7 ++-- home-panel/rootfs/etc/cont-init.d/30-nginx.sh | 38 ------------------- .../rootfs/etc/services.d/config/finish | 9 ----- home-panel/rootfs/etc/services.d/config/run | 16 -------- home-panel/rootfs/etc/services.d/db/finish | 9 ----- home-panel/rootfs/etc/services.d/db/run | 14 ------- 7 files changed, 9 insertions(+), 93 deletions(-) rename home-panel/rootfs/etc/cont-init.d/{40-api.sh => 30-api.sh} (77%) delete mode 100644 home-panel/rootfs/etc/cont-init.d/30-nginx.sh delete mode 100644 home-panel/rootfs/etc/services.d/config/finish delete mode 100644 home-panel/rootfs/etc/services.d/config/run delete mode 100644 home-panel/rootfs/etc/services.d/db/finish delete mode 100644 home-panel/rootfs/etc/services.d/db/run diff --git a/home-panel/rootfs/etc/cont-init.d/20-config.sh b/home-panel/rootfs/etc/cont-init.d/20-config.sh index 072d851..94a82a5 100644 --- a/home-panel/rootfs/etc/cont-init.d/20-config.sh +++ b/home-panel/rootfs/etc/cont-init.d/20-config.sh @@ -14,7 +14,8 @@ if [ ! -f "$config_file" ]; then hass.log.info "Created. You should now edit this file at '$config_file'" fi -hass.log.info "Copy config to API.." - -mkdir -p /usr/src/api/files -cp "$config_file" /usr/src/api/files/config.json +if [ ! -f "/usr/src/api/files/config.json" ]; then + hass.log.info "Symlink config to API directory.." + mkdir -p /usr/src/api/files + ln -sf "$config_file" /usr/src/api/files/config.json +fi diff --git a/home-panel/rootfs/etc/cont-init.d/40-api.sh b/home-panel/rootfs/etc/cont-init.d/30-api.sh similarity index 77% rename from home-panel/rootfs/etc/cont-init.d/40-api.sh rename to home-panel/rootfs/etc/cont-init.d/30-api.sh index 5cb5886..51075f7 100644 --- a/home-panel/rootfs/etc/cont-init.d/40-api.sh +++ b/home-panel/rootfs/etc/cont-init.d/30-api.sh @@ -15,8 +15,9 @@ if hass.config.true 'ssl'; then cp "$keyfile" /usr/src/api/privkey.pem fi -if hass.file_exists "/config/home-panel.db"; then - hass.log.info "Copy DB to api.." +if [ ! -f "/config/home-panel.db" ]; then + hass.log.info "Symlink DB to API directory.." + touch /config/home-panel.db mkdir -p /usr/src/api/files - cp /config/home-panel.db /usr/src/api/files/home-panel.db + ln -sf "/config/home-panel.db" /usr/src/api/files/home-panel.db fi diff --git a/home-panel/rootfs/etc/cont-init.d/30-nginx.sh b/home-panel/rootfs/etc/cont-init.d/30-nginx.sh deleted file mode 100644 index 5932bdb..0000000 --- a/home-panel/rootfs/etc/cont-init.d/30-nginx.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/with-contenv bash -# ============================================================================== -# Timmo Hass.io Add-ons: Home Panel -# This copies the nginx configs to their respective locations -# ============================================================================== -# shellcheck disable=SC1091 -source /usr/lib/hassio-addons/base.sh - -certfile="/ssl/$(hass.config.get 'certfile')" -keyfile="/ssl/$(hass.config.get 'keyfile')" - -if hass.config.true 'ssl'; then - hass.log.info "Copy enabled SSL nginx config" - echo "server { - listen 8234 ssl http2 default_server; - listen [::]:8234 ssl http2 default_server; - root /usr/share/nginx/html; - index index.html; - server_name 172.0.0.1; - ssl_certificate ${certfile}; - ssl_certificate_key ${keyfile}; - location / { - try_files \$uri /index.html; - } - }" > /etc/nginx/conf.d/default.conf; -else - hass.log.info "Copy disabled SSL nginx config" - echo "server { - listen 8234 default_server; - listen [::]:8234 default_server; - root /usr/share/nginx/html; - index index.html; - server_name 172.0.0.1; - location / { - try_files \$uri /index.html; - } - }" > /etc/nginx/conf.d/default.conf; -fi diff --git a/home-panel/rootfs/etc/services.d/config/finish b/home-panel/rootfs/etc/services.d/config/finish deleted file mode 100644 index 8255b6e..0000000 --- a/home-panel/rootfs/etc/services.d/config/finish +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/execlineb -S0 -# ============================================================================== -# Timmo Hass.io Add-ons: Home Panel -# Take down the S6 supervision tree when Home Panel fails -# ============================================================================== -if -n { s6-test $# -ne 0 } -if -n { s6-test ${1} -eq 256 } - -s6-svscanctl -t /var/run/s6/services diff --git a/home-panel/rootfs/etc/services.d/config/run b/home-panel/rootfs/etc/services.d/config/run deleted file mode 100644 index cba2107..0000000 --- a/home-panel/rootfs/etc/services.d/config/run +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/with-contenv bash -# ============================================================================== -# Timmo Hass.io Add-ons: Home Panel -# Keeps the config file up to date -# ============================================================================== -# shellcheck disable=SC1091 -source /usr/lib/hassio-addons/base.sh - -config_file="/config/$(hass.config.get 'config_file')" - -# shellcheck disable=SC2162 -# shellcheck disable=SC2034 -inotifywait -e modify -m "$config_file" | while read file; do \ -hass.log.debug "Update Config.." \ -&& cp "$config_file" /usr/src/api/files/config.json; \ -done diff --git a/home-panel/rootfs/etc/services.d/db/finish b/home-panel/rootfs/etc/services.d/db/finish deleted file mode 100644 index 8255b6e..0000000 --- a/home-panel/rootfs/etc/services.d/db/finish +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/execlineb -S0 -# ============================================================================== -# Timmo Hass.io Add-ons: Home Panel -# Take down the S6 supervision tree when Home Panel fails -# ============================================================================== -if -n { s6-test $# -ne 0 } -if -n { s6-test ${1} -eq 256 } - -s6-svscanctl -t /var/run/s6/services diff --git a/home-panel/rootfs/etc/services.d/db/run b/home-panel/rootfs/etc/services.d/db/run deleted file mode 100644 index 3eed6de..0000000 --- a/home-panel/rootfs/etc/services.d/db/run +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/with-contenv bash -# ============================================================================== -# Timmo Hass.io Add-ons: Home Panel -# Copy back db to preserve data between restarts -# ============================================================================== -# shellcheck disable=SC1091 -source /usr/lib/hassio-addons/base.sh - -# shellcheck disable=SC2162 -# shellcheck disable=SC2034 -inotifywait -m "/usr/src/api/files/home-panel.db" | while read file; do \ -hass.log.debug "Backup db.." \ -&& cp /usr/src/api/files/home-panel.db /config/home-panel.db; \ -done