From e4e7a6ee8da85784be9a4ca2268dd94b4b74f762 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Fri, 26 Aug 2022 19:55:26 +0200 Subject: [PATCH] Migration to v5.0 https://github.com/alexbelgium/hassio-addons/issues/416 --- scrutiny/CHANGELOG.md | 3 + scrutiny/Dockerfile | 27 +------ scrutiny/README.md | 9 +-- scrutiny/build.json | 5 +- scrutiny/config.json | 31 +++----- scrutiny/rootfs/etc/cont-init.d/01-run.sh | 58 +++++++++++++++ scrutiny/rootfs/etc/cont-init.d/31-run.sh | 50 ------------- .../etc/cont-init.d/32-nginx_ingress.sh | 2 + .../etc/nginx/includes/server_params.conf | 1 - .../rootfs/etc/nginx/servers/ingress.conf | 32 +++++++-- scrutiny/rootfs/run.sh | 13 ---- scrutiny/updater.json | 2 +- scrutiny_fa/CHANGELOG.md | 7 +- scrutiny_fa/Dockerfile | 26 +------ scrutiny_fa/README.md | 11 ++- scrutiny_fa/build.json | 5 +- scrutiny_fa/config.json | 71 +++++++++++++------ scrutiny_fa/rootfs/etc/cont-init.d/01-run.sh | 64 +++++++++++++++++ scrutiny_fa/rootfs/etc/cont-init.d/31-run.sh | 56 --------------- .../etc/cont-init.d/32-nginx_ingress.sh | 2 + .../etc/nginx/includes/server_params.conf | 1 - .../rootfs/etc/nginx/servers/ingress.conf | 32 +++++++-- scrutiny_fa/rootfs/run.sh | 13 ---- scrutiny_fa/updater.json | 2 +- 24 files changed, 262 insertions(+), 261 deletions(-) create mode 100644 scrutiny/rootfs/etc/cont-init.d/01-run.sh delete mode 100644 scrutiny/rootfs/etc/cont-init.d/31-run.sh delete mode 100644 scrutiny/rootfs/run.sh create mode 100644 scrutiny_fa/rootfs/etc/cont-init.d/01-run.sh delete mode 100644 scrutiny_fa/rootfs/etc/cont-init.d/31-run.sh delete mode 100644 scrutiny_fa/rootfs/run.sh diff --git a/scrutiny/CHANGELOG.md b/scrutiny/CHANGELOG.md index c4d81b082..a71485364 100644 --- a/scrutiny/CHANGELOG.md +++ b/scrutiny/CHANGELOG.md @@ -1,3 +1,6 @@ +- BACKUP BEFORE UPDATE : major version change +- PUID/PGID, ssl values deprecated + ## 2ab714f5-ls35 (11-05-2022) - Update to latest version from linuxserver/scrutiny diff --git a/scrutiny/Dockerfile b/scrutiny/Dockerfile index 6ecb4e8ce..e55cb533a 100644 --- a/scrutiny/Dockerfile +++ b/scrutiny/Dockerfile @@ -16,9 +16,7 @@ ARG BUILD_FROM ARG BUILD_VERSION -ARG BUILD_UPSTREAM="8e34ef8d-ls34" -#ARG BUILD_UPSTREAM="latest" -FROM ${BUILD_FROM}${BUILD_UPSTREAM} +FROM ${BUILD_FROM} ################## # 2 Modify Image # @@ -29,26 +27,6 @@ ENV S6_CMD_WAIT_FOR_SERVICES=1 \ S6_CMD_WAIT_FOR_SERVICES_MAXTIME=0 \ S6_SERVICES_GRACETIME=0 -# hadolint ignore=DL4006 -RUN \ - # Avoid custom-init.d duplications - if [ -f /etc/cont-init.d/02-tamper-check ]; then rm /etc/cont-init.d/02-tamper-check; fi \ - \ - # Prevent changing ownership of /config - && if [ -f /etc/cont-init.d/10-adduser ]; then sed -i "/chown abc:abc \/config$/d" /etc/cont-init.d/10-adduser; fi \ - \ - # Allow UID and GID setting - && sed -i 's/bash/bashio/g' /etc/cont-init.d/10-adduser \ - && sed -i 's/{PUID:-911}/(bashio::config "PUID")/g' /etc/cont-init.d/10-adduser \ - && sed -i 's/{PGID:-911}/(bashio::config "PGID")/g' /etc/cont-init.d/10-adduser \ - # use /data instead of /config for database - && sed -i 's| /config| /data|g' /defaults/scrutiny.yaml \ - && sed -i 's| /config| /data|g' /etc/cont-init.d/* \ - && sed -i 's| /config| /data|g' /etc/logrotate.d/scrutiny \ - && sed -i 's| /config| /data|g' /etc/crontabs/root \ - # correct url paths - && grep -rl '/web/' /app/scrutiny-web/ | xargs sed -i 's|/web/|./|g' - ################## # 3 Install apps # ################## @@ -90,8 +68,7 @@ RUN if ! command -v bash >/dev/null 2>/dev/null; then (apt-get update && apt-get # 4 Entrypoint # ################ -# Collector -RUN chmod 777 /run.sh + ############ # 5 Labels # diff --git a/scrutiny/README.md b/scrutiny/README.md index de44c46ac..52401c16d 100644 --- a/scrutiny/README.md +++ b/scrutiny/README.md @@ -30,7 +30,7 @@ Features : - SMART monitoring - Automatic addition of local drives - Hourly updates -- Ingress with/without ssl +- Ingress - Automatic upstream updates ## Configuration @@ -43,11 +43,8 @@ It automatically mounts all local drives. Enable full access only if you are encountering issues. SMART access should work without full access in all other scenarios. ```yaml -PGID: user -GPID: user -ssl: true/false (for Ingress) -certfile: fullchain.pem #ssl certificate -keyfile: privkey.pem #sslkeyfile +Updates : Hourly, Daily, Weekly +TZ : timezone ``` ## Installation diff --git a/scrutiny/build.json b/scrutiny/build.json index 826d94f2f..79f0bcfa5 100644 --- a/scrutiny/build.json +++ b/scrutiny/build.json @@ -1,8 +1,7 @@ { "build_from": { - "aarch64": "lscr.io/linuxserver/scrutiny:arm64v8-", - "amd64": "lscr.io/linuxserver/scrutiny:amd64-", - "armv7": "lscr.io/linuxserver/scrutiny:arm32v7-" + "aarch64": "ghcr.io/analogj/scrutiny:master-omnibus", + "amd64": "ghcr.io/analogj/scrutiny:master-omnibus" }, "codenotary": { "signer": "alexandrep.github@gmail.com" diff --git a/scrutiny/config.json b/scrutiny/config.json index 5362926b9..8972e6300 100644 --- a/scrutiny/config.json +++ b/scrutiny/config.json @@ -2,8 +2,7 @@ "apparmor": "true", "arch": [ "aarch64", - "amd64", - "armv7" + "amd64" ], "codenotary": "alexandrep.github@gmail.com", "description": "Scrutiny WebUI for smartd S.M.A.R.T monitoring", @@ -45,30 +44,25 @@ "/dev/nvme2" ], "environment": { - "SCRUTINY_API_ENDPOINT": "http://localhost:8080", - "SCRUTINY_COLLECTOR": "true", - "SCRUTINY_WEB": "true" + "COLLECTOR_API_ENDPOINT": "http://localhost:8080" }, "ingress": true, "init": false, "map": [ - "config:rw" + "share:rw" ], "name": "Scrutiny", "options": { - "PGID": 0, - "PUID": 0, - "Updates": "Hourly", - "certfile": "fullchain.pem", - "keyfile": "privkey.pem", - "ssl": false + "Updates": "Hourly" }, "panel_icon": "mdi:glasses", "ports": { - "8080/tcp": 8086 + "8080/tcp": 8086, + "8086/tcp": 8087 }, "ports_description": { - "8080/tcp": "Web UI port" + "8080/tcp": "Web UI port", + "8086/tcp": "InfluxDB admin" }, "privileged": [ "SYS_ADMIN", @@ -76,16 +70,11 @@ "DAC_READ_SEARCH" ], "schema": { - "PGID": "int", - "PUID": "int", "TZ": "str?", - "Updates": "list(|Hourly|Daily|Weekly)", - "certfile": "str", - "keyfile": "str", - "ssl": "bool" + "Updates": "list(|Hourly|Daily|Weekly)" }, "slug": "scrutiny", "udev": true, "url": "https://github.com/AnalogJ/scrutiny", - "version": "2ab714f5-ls35" + "version": "v0.5.0" } diff --git a/scrutiny/rootfs/etc/cont-init.d/01-run.sh b/scrutiny/rootfs/etc/cont-init.d/01-run.sh new file mode 100644 index 000000000..81f25457e --- /dev/null +++ b/scrutiny/rootfs/etc/cont-init.d/01-run.sh @@ -0,0 +1,58 @@ +#!/usr/bin/with-contenv bashio +# shellcheck shell=bash + +################# +# Create folder # +################# + +echo "Updating folders structure" +DATABASELOCATION="/data" +mkdir -p "$DATABASELOCATION"/config +mkdir -p "$DATABASELOCATION"/influxdb +if [ -d /opt/scrutiny/config ]; then rm -r /opt/scrutiny/config; fi +if [ -d /opt/scrutiny/influxdb ]; then rm -r /opt/scrutiny/influxdb; fi +ln -s "$DATABASELOCATION"/config /opt/scrutiny +ln -s "$DATABASELOCATION"/influxdb /opt/scrutiny + +############################### +# Migrating previous database # +############################### + +if [ -f /data/scrutiny.db ]; then +bashio::log.warning "Previous database detected, migration will start. Backup stored in /share/scrutiny.db.bak" +cp /data/scrutiny.db /share/scrutiny.db.bak +mv /data/scrutiny.db "$DATABASELOCATION"/config/ +fi + +###### +# TZ # +###### + +# Align timezone with options +if bashio::config.has_value "TZ"; then +TZ="$(bashio::config 'TZ')" +bashio::log.info "Timezone : $TZ" +sed -i "1a export TZ=$TZ" /etc/cont-init.d/10-timezone +fi + +################ +# CRON OPTIONS # +################ + +# Align update with options +FREQUENCY="$(bashio::config 'Updates')" +bashio::log.info "$FREQUENCY updates" + +case "$FREQUENCY" in + "Hourly") + sed -i "1a export COLLECTOR_CRON_SCHEDULE=\"0 * * * *\"" /etc/cont-init.d/50-cron-config + ;; + + "Daily") + sed -i "1a export COLLECTOR_CRON_SCHEDULE=\"0 0 * * *\"" /etc/cont-init.d/50-cron-config + ;; + + "Weekly") + sed -i "1a export COLLECTOR_CRON_SCHEDULE=\"0 0 * * 0\"" /etc/cont-init.d/50-cron-config + ;; +esac diff --git a/scrutiny/rootfs/etc/cont-init.d/31-run.sh b/scrutiny/rootfs/etc/cont-init.d/31-run.sh deleted file mode 100644 index 209a63bcd..000000000 --- a/scrutiny/rootfs/etc/cont-init.d/31-run.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/with-contenv bashio -# shellcheck shell=bash - -############## -# Data usage # -############## - -bashio::log.info "Setting permissions" -chown -R abc:abc /data - -####################### -# VIEWPORT CORRECTION # -####################### - -# correct viewport bug -# grep -rl '"lt-md":"(max-width: 959px)"' /app | xargs sed -i 's|"lt-md":"(max-width: 959px)"|"lt-md":"(max-width: 100px)"|g' || true - -###################### -# API URL CORRECTION # -###################### - -# allow true url for ingress -grep -rl '/api/' /app | xargs sed -i 's|/api/|api/|g' || true -grep -rl 'api/' /app | xargs sed -i 's|api/|./api/|g' || true - -################ -# CRON OPTIONS # -################ - -rm /config/crontabs/* || true -sed -i '$d' /etc/crontabs/root -sed -i -e '$a @reboot /run.sh' /etc/crontabs/root - -# Align update with options -FREQUENCY=$(bashio::config 'Updates') -bashio::log.info "$FREQUENCY updates" - -case $FREQUENCY in - "Hourly") - sed -i -e '$a 0 * * * * /run.sh' /etc/crontabs/root - ;; - - "Daily") - sed -i -e '$a 0 0 * * * /run.sh' /etc/crontabs/root - ;; - - "Weekly") - sed -i -e '$a 0 0 * * 0 /run.sh' /etc/crontabs/root - ;; -esac diff --git a/scrutiny/rootfs/etc/cont-init.d/32-nginx_ingress.sh b/scrutiny/rootfs/etc/cont-init.d/32-nginx_ingress.sh index 6ac38a5b6..fa6895cff 100644 --- a/scrutiny/rootfs/etc/cont-init.d/32-nginx_ingress.sh +++ b/scrutiny/rootfs/etc/cont-init.d/32-nginx_ingress.sh @@ -29,5 +29,7 @@ fi ingress_port=$(bashio::addon.ingress_port) ingress_interface=$(bashio::addon.ip_address) +ingress_entry=$(bashio::addon.ingress_entry) sed -i "s/%%port%%/${ingress_port}/g" /etc/nginx/servers/ingress.conf sed -i "s/%%interface%%/${ingress_interface}/g" /etc/nginx/servers/ingress.conf +sed -i "s|%%ingress_entry%%|${ingress_entry}|g" /etc/nginx/servers/ingress.conf diff --git a/scrutiny/rootfs/etc/nginx/includes/server_params.conf b/scrutiny/rootfs/etc/nginx/includes/server_params.conf index 09c06543e..a0ff6baa0 100644 --- a/scrutiny/rootfs/etc/nginx/includes/server_params.conf +++ b/scrutiny/rootfs/etc/nginx/includes/server_params.conf @@ -1,4 +1,3 @@ -root /dev/null; server_name $hostname; add_header X-Content-Type-Options nosniff; diff --git a/scrutiny/rootfs/etc/nginx/servers/ingress.conf b/scrutiny/rootfs/etc/nginx/servers/ingress.conf index 6c82c3dc5..03a6f4c0a 100644 --- a/scrutiny/rootfs/etc/nginx/servers/ingress.conf +++ b/scrutiny/rootfs/etc/nginx/servers/ingress.conf @@ -6,16 +6,34 @@ server { client_max_body_size 0; - location / { + root /opt/scrutiny/web; + + if ($http_referer ~* "^(http[s]?)://([^:]+):(\d*)(/.*)$") { + set $x_scheme $1; + set $x_host $2; + set $x_port $3; + } + + if ($http_referer ~* "^(http[s]?)://([^:]+)(/.*)$") { + set $x_scheme $1; + set $x_host $2; + set $x_port ""; + } + + location = / { + return 301 $x_scheme://$host:$x_port%%ingress_entry%%/web/dashboard; + } + + location /api { + add_header Access-Control-Allow-Origin *; + proxy_read_timeout 30; + proxy_pass http://backend/api; + } + + location /web/ { add_header Access-Control-Allow-Origin *; proxy_read_timeout 30; proxy_pass http://backend/web/; } - location /api/ { - add_header Access-Control-Allow-Origin *; - proxy_read_timeout 30; - proxy_pass http://backend/api/; - } - } diff --git a/scrutiny/rootfs/run.sh b/scrutiny/rootfs/run.sh deleted file mode 100644 index 30bc73d68..000000000 --- a/scrutiny/rootfs/run.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/with-contenv bashio -# shellcheck shell=bash - -# wait for scrutiny to load -bashio::net.wait_for 8080 - -##################### -# ADD LOCAL DEVICES # -##################### - -# search for local devices -# shellcheck disable=SC2015 -scrutiny-collector-metrics run >/dev/null && bashio::log.info "Local Devices Added" || bashio::log.error "Local Devices Not Added" diff --git a/scrutiny/updater.json b/scrutiny/updater.json index 0bc15f5f9..0635c1e00 100644 --- a/scrutiny/updater.json +++ b/scrutiny/updater.json @@ -1,7 +1,7 @@ { "github_fulltag": "true", "last_update": "11-05-2022", - "paused": true, + "paused": false, "repository": "alexbelgium/hassio-addons", "slug": "scrutiny", "source": "dockerhub", diff --git a/scrutiny_fa/CHANGELOG.md b/scrutiny_fa/CHANGELOG.md index f7017e50e..9cb1a60c1 100644 --- a/scrutiny_fa/CHANGELOG.md +++ b/scrutiny_fa/CHANGELOG.md @@ -1,3 +1,6 @@ +- BACKUP BEFORE UPDATE : major version change +- PUID/PGID, ssl values deprecated + ## 2ab714f5-ls35 (11-05-2022) - Update to latest version from linuxserver/scrutiny @@ -8,10 +11,10 @@ ## 8e34ef8d-ls35 (05-05-2022) -- Update to latest version from linuxserver/scrutiny -- Add codenotary sign - Require unprotected - Added full access. Use only if you can't connect without +- Update to latest version from linuxserver/scrutiny +- Add codenotary sign - New standardized logic for Dockerfile build and packages installation - Added : "/dev/nvme0" diff --git a/scrutiny_fa/Dockerfile b/scrutiny_fa/Dockerfile index aca96ee8a..e55cb533a 100644 --- a/scrutiny_fa/Dockerfile +++ b/scrutiny_fa/Dockerfile @@ -16,8 +16,7 @@ ARG BUILD_FROM ARG BUILD_VERSION -ARG BUILD_UPSTREAM="8e34ef8d-ls34" -FROM ${BUILD_FROM}${BUILD_UPSTREAM} +FROM ${BUILD_FROM} ################## # 2 Modify Image # @@ -28,26 +27,6 @@ ENV S6_CMD_WAIT_FOR_SERVICES=1 \ S6_CMD_WAIT_FOR_SERVICES_MAXTIME=0 \ S6_SERVICES_GRACETIME=0 -# hadolint ignore=DL4006 -RUN \ - # Avoid custom-init.d duplications - if [ -f /etc/cont-init.d/02-tamper-check ]; then rm /etc/cont-init.d/02-tamper-check; fi \ - \ - # Prevent changing ownership of /config - && if [ -f /etc/cont-init.d/10-adduser ]; then sed -i "/chown abc:abc \/config$/d" /etc/cont-init.d/10-adduser; fi \ - \ - # Allow UID and GID setting - && sed -i 's/bash/bashio/g' /etc/cont-init.d/10-adduser \ - && sed -i 's/{PUID:-911}/(bashio::config "PUID")/g' /etc/cont-init.d/10-adduser \ - && sed -i 's/{PGID:-911}/(bashio::config "PGID")/g' /etc/cont-init.d/10-adduser \ - # use /data instead of /config for database - && sed -i 's| /config| /data|g' /defaults/scrutiny.yaml \ - && sed -i 's| /config| /data|g' /etc/cont-init.d/* \ - && sed -i 's| /config| /data|g' /etc/logrotate.d/scrutiny \ - && sed -i 's| /config| /data|g' /etc/crontabs/root \ - # correct url paths - && grep -rl '/web/' /app/scrutiny-web/ | xargs sed -i 's|/web/|./|g' - ################## # 3 Install apps # ################## @@ -89,8 +68,7 @@ RUN if ! command -v bash >/dev/null 2>/dev/null; then (apt-get update && apt-get # 4 Entrypoint # ################ -# Collector -RUN chmod 777 /run.sh + ############ # 5 Labels # diff --git a/scrutiny_fa/README.md b/scrutiny_fa/README.md index fb0f5a6c3..52401c16d 100644 --- a/scrutiny_fa/README.md +++ b/scrutiny_fa/README.md @@ -1,3 +1,5 @@ +## ⚠ Open Request : [[Scrutiny] Help needed to migrate to the official Scrutiny Image? (opened 2022-08-05)](https://github.com/alexbelgium/hassio-addons/issues/416) by [@AnalogJ](https://github.com/AnalogJ) + # Home assistant add-on: Scrutiny [![Donate][donation-badge]](https://www.buymeacoffee.com/alexbelgium) @@ -28,7 +30,7 @@ Features : - SMART monitoring - Automatic addition of local drives - Hourly updates -- Ingress with/without ssl +- Ingress - Automatic upstream updates ## Configuration @@ -41,11 +43,8 @@ It automatically mounts all local drives. Enable full access only if you are encountering issues. SMART access should work without full access in all other scenarios. ```yaml -PGID: user -GPID: user -ssl: true/false (for Ingress) -certfile: fullchain.pem #ssl certificate -keyfile: privkey.pem #sslkeyfile +Updates : Hourly, Daily, Weekly +TZ : timezone ``` ## Installation diff --git a/scrutiny_fa/build.json b/scrutiny_fa/build.json index 826d94f2f..79f0bcfa5 100644 --- a/scrutiny_fa/build.json +++ b/scrutiny_fa/build.json @@ -1,8 +1,7 @@ { "build_from": { - "aarch64": "lscr.io/linuxserver/scrutiny:arm64v8-", - "amd64": "lscr.io/linuxserver/scrutiny:amd64-", - "armv7": "lscr.io/linuxserver/scrutiny:arm32v7-" + "aarch64": "ghcr.io/analogj/scrutiny:master-omnibus", + "amd64": "ghcr.io/analogj/scrutiny:master-omnibus" }, "codenotary": { "signer": "alexandrep.github@gmail.com" diff --git a/scrutiny_fa/config.json b/scrutiny_fa/config.json index 5be33ecc4..7b4af347c 100644 --- a/scrutiny_fa/config.json +++ b/scrutiny_fa/config.json @@ -2,35 +2,69 @@ "apparmor": "true", "arch": [ "aarch64", - "amd64", - "armv7" + "amd64" ], "codenotary": "alexandrep.github@gmail.com", "description": "Scrutiny WebUI for smartd S.M.A.R.T monitoring (Full Access)", + "devices": [ + "/dev/sda", + "/dev/sdb", + "/dev/sdc", + "/dev/sdd", + "/dev/sde", + "/dev/sdf", + "/dev/sdg", + "/dev/nvme", + "/dev/nvme0n1p1", + "/dev/nvme0n1p2", + "/dev/mmcblk", + "/dev/sda1", + "/dev/sdb1", + "/dev/sdc1", + "/dev/sdd1", + "/dev/sde1", + "/dev/sdf1", + "/dev/sdg1", + "/dev/sda2", + "/dev/sdb2", + "/dev/sdc2", + "/dev/sdd2", + "/dev/sde2", + "/dev/sdf2", + "/dev/sdg2", + "/dev/sda3", + "/dev/sdb3", + "/dev/sda4", + "/dev/sdb4", + "/dev/nvme0", + "/dev/nvme1", + "/dev/nvme2", + "/dev/nvme0", + "/dev/nvme1", + "/dev/nvme2" + ], "environment": { - "SCRUTINY_API_ENDPOINT": "http://localhost:8080", - "SCRUTINY_COLLECTOR": "true", - "SCRUTINY_WEB": "true" + "COLLECTOR_API_ENDPOINT": "http://localhost:8080" }, "full_access": true, "image": "ghcr.io/alexbelgium/scrutiny-fa-{arch}", "ingress": true, "init": false, + "map": [ + "share:rw" + ], "name": "Scrutiny (Full Access)", "options": { - "PGID": 0, - "PUID": 0, - "Updates": "Hourly", - "certfile": "fullchain.pem", - "keyfile": "privkey.pem", - "ssl": false + "Updates": "Hourly" }, "panel_icon": "mdi:glasses", "ports": { - "8080/tcp": 8086 + "8080/tcp": 8086, + "8086/tcp": 8087 }, "ports_description": { - "8080/tcp": "Web UI port" + "8080/tcp": "Web UI port", + "8086/tcp": "InfluxDB admin" }, "privileged": [ "SYS_ADMIN", @@ -38,16 +72,11 @@ "DAC_READ_SEARCH" ], "schema": { - "PGID": "int", - "PUID": "int", "TZ": "str?", - "Updates": "list(|Hourly|Daily|Weekly)", - "certfile": "str", - "keyfile": "str", - "ssl": "bool" + "Updates": "list(|Hourly|Daily|Weekly)" }, "slug": "scrutiny_fa", "udev": true, "url": "https://github.com/AnalogJ/scrutiny", - "version": "2ab714f5-ls35-2" -} + "version": "v0.5.0" +} \ No newline at end of file diff --git a/scrutiny_fa/rootfs/etc/cont-init.d/01-run.sh b/scrutiny_fa/rootfs/etc/cont-init.d/01-run.sh new file mode 100644 index 000000000..2394a5e15 --- /dev/null +++ b/scrutiny_fa/rootfs/etc/cont-init.d/01-run.sh @@ -0,0 +1,64 @@ +#!/usr/bin/with-contenv bashio +# shellcheck shell=bash + +####################### +# Require unprotected # +####################### + +bashio::require.unprotected + +################# +# Create folder # +################# + +echo "Updating folders structure" +DATABASELOCATION="/data" +mkdir -p "$DATABASELOCATION"/config +mkdir -p "$DATABASELOCATION"/influxdb +if [ -d /opt/scrutiny/config ]; then rm -r /opt/scrutiny/config; fi +if [ -d /opt/scrutiny/influxdb ]; then rm -r /opt/scrutiny/influxdb; fi +ln -s "$DATABASELOCATION"/config /opt/scrutiny +ln -s "$DATABASELOCATION"/influxdb /opt/scrutiny + +############################### +# Migrating previous database # +############################### + +if [ -f /data/scrutiny.db ]; then +bashio::log.warning "Previous database detected, migration will start. Backup stored in /share/scrutiny.db.bak" +cp /data/scrutiny.db /share/scrutiny.db.bak +mv /data/scrutiny.db "$DATABASELOCATION"/config/ +fi + +###### +# TZ # +###### + +# Align timezone with options +if bashio::config.has_value "TZ"; then +TZ="$(bashio::config 'TZ')" +bashio::log.info "Timezone : $TZ" +sed -i "1a export TZ=$TZ" /etc/cont-init.d/10-timezone +fi + +################ +# CRON OPTIONS # +################ + +# Align update with options +FREQUENCY="$(bashio::config 'Updates')" +bashio::log.info "$FREQUENCY updates" + +case "$FREQUENCY" in + "Hourly") + sed -i "1a export COLLECTOR_CRON_SCHEDULE=\"0 * * * *\"" /etc/cont-init.d/50-cron-config + ;; + + "Daily") + sed -i "1a export COLLECTOR_CRON_SCHEDULE=\"0 0 * * *\"" /etc/cont-init.d/50-cron-config + ;; + + "Weekly") + sed -i "1a export COLLECTOR_CRON_SCHEDULE=\"0 0 * * 0\"" /etc/cont-init.d/50-cron-config + ;; +esac diff --git a/scrutiny_fa/rootfs/etc/cont-init.d/31-run.sh b/scrutiny_fa/rootfs/etc/cont-init.d/31-run.sh deleted file mode 100644 index 24f0fcb7a..000000000 --- a/scrutiny_fa/rootfs/etc/cont-init.d/31-run.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/with-contenv bashio -# shellcheck shell=bash - -####################### -# Require unprotected # -####################### - -bashio::require.unprotected - -############## -# Data usage # -############## - -bashio::log.info "Setting permissions" -chown -R abc:abc /data - -####################### -# VIEWPORT CORRECTION # -####################### - -# correct viewport bug -# grep -rl '"lt-md":"(max-width: 959px)"' /app | xargs sed -i 's|"lt-md":"(max-width: 959px)"|"lt-md":"(max-width: 100px)"|g' || true - -###################### -# API URL CORRECTION # -###################### - -# allow true url for ingress -grep -rl '/api/' /app | xargs sed -i 's|/api/|api/|g' || true -grep -rl 'api/' /app | xargs sed -i 's|api/|./api/|g' || true - -################ -# CRON OPTIONS # -################ - -rm /config/crontabs/* || true -sed -i '$d' /etc/crontabs/root -sed -i -e '$a @reboot /run.sh' /etc/crontabs/root - -# Align update with options -FREQUENCY=$(bashio::config 'Updates') -bashio::log.info "$FREQUENCY updates" - -case $FREQUENCY in - "Hourly") - sed -i -e '$a 0 * * * * /run.sh' /etc/crontabs/root - ;; - - "Daily") - sed -i -e '$a 0 0 * * * /run.sh' /etc/crontabs/root - ;; - - "Weekly") - sed -i -e '$a 0 0 * * 0 /run.sh' /etc/crontabs/root - ;; -esac diff --git a/scrutiny_fa/rootfs/etc/cont-init.d/32-nginx_ingress.sh b/scrutiny_fa/rootfs/etc/cont-init.d/32-nginx_ingress.sh index 6ac38a5b6..fa6895cff 100644 --- a/scrutiny_fa/rootfs/etc/cont-init.d/32-nginx_ingress.sh +++ b/scrutiny_fa/rootfs/etc/cont-init.d/32-nginx_ingress.sh @@ -29,5 +29,7 @@ fi ingress_port=$(bashio::addon.ingress_port) ingress_interface=$(bashio::addon.ip_address) +ingress_entry=$(bashio::addon.ingress_entry) sed -i "s/%%port%%/${ingress_port}/g" /etc/nginx/servers/ingress.conf sed -i "s/%%interface%%/${ingress_interface}/g" /etc/nginx/servers/ingress.conf +sed -i "s|%%ingress_entry%%|${ingress_entry}|g" /etc/nginx/servers/ingress.conf diff --git a/scrutiny_fa/rootfs/etc/nginx/includes/server_params.conf b/scrutiny_fa/rootfs/etc/nginx/includes/server_params.conf index 09c06543e..a0ff6baa0 100644 --- a/scrutiny_fa/rootfs/etc/nginx/includes/server_params.conf +++ b/scrutiny_fa/rootfs/etc/nginx/includes/server_params.conf @@ -1,4 +1,3 @@ -root /dev/null; server_name $hostname; add_header X-Content-Type-Options nosniff; diff --git a/scrutiny_fa/rootfs/etc/nginx/servers/ingress.conf b/scrutiny_fa/rootfs/etc/nginx/servers/ingress.conf index 6c82c3dc5..03a6f4c0a 100644 --- a/scrutiny_fa/rootfs/etc/nginx/servers/ingress.conf +++ b/scrutiny_fa/rootfs/etc/nginx/servers/ingress.conf @@ -6,16 +6,34 @@ server { client_max_body_size 0; - location / { + root /opt/scrutiny/web; + + if ($http_referer ~* "^(http[s]?)://([^:]+):(\d*)(/.*)$") { + set $x_scheme $1; + set $x_host $2; + set $x_port $3; + } + + if ($http_referer ~* "^(http[s]?)://([^:]+)(/.*)$") { + set $x_scheme $1; + set $x_host $2; + set $x_port ""; + } + + location = / { + return 301 $x_scheme://$host:$x_port%%ingress_entry%%/web/dashboard; + } + + location /api { + add_header Access-Control-Allow-Origin *; + proxy_read_timeout 30; + proxy_pass http://backend/api; + } + + location /web/ { add_header Access-Control-Allow-Origin *; proxy_read_timeout 30; proxy_pass http://backend/web/; } - location /api/ { - add_header Access-Control-Allow-Origin *; - proxy_read_timeout 30; - proxy_pass http://backend/api/; - } - } diff --git a/scrutiny_fa/rootfs/run.sh b/scrutiny_fa/rootfs/run.sh deleted file mode 100644 index 30bc73d68..000000000 --- a/scrutiny_fa/rootfs/run.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/with-contenv bashio -# shellcheck shell=bash - -# wait for scrutiny to load -bashio::net.wait_for 8080 - -##################### -# ADD LOCAL DEVICES # -##################### - -# search for local devices -# shellcheck disable=SC2015 -scrutiny-collector-metrics run >/dev/null && bashio::log.info "Local Devices Added" || bashio::log.error "Local Devices Not Added" diff --git a/scrutiny_fa/updater.json b/scrutiny_fa/updater.json index 7f3e4678b..fa3586e18 100644 --- a/scrutiny_fa/updater.json +++ b/scrutiny_fa/updater.json @@ -1,7 +1,7 @@ { "github_fulltag": "true", "last_update": "11-05-2022", - "paused": true, + "paused": false, "repository": "alexbelgium/hassio-addons", "slug": "scrutiny_fa", "source": "dockerhub",