Migration to v5.0

https://github.com/alexbelgium/hassio-addons/issues/416
This commit is contained in:
Alexandre
2022-08-26 19:55:26 +02:00
parent 73159492ce
commit e4e7a6ee8d
24 changed files with 262 additions and 261 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -1,4 +1,3 @@
root /dev/null;
server_name $hostname;
add_header X-Content-Type-Options nosniff;

View File

@@ -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/;
}
}