🔨 Persist secret and db

This commit is contained in:
Timmo 2019-09-14 23:15:31 +01:00
parent fd47050d0e
commit 44ff20cc1a

View file

@ -3,10 +3,18 @@
# Community Hass.io Add-ons: Home Panel
# This updates the internal auth secret for the API
# ==============================================================================
if [ "$(grep -i 'API_AUTH_SECRET' /opt/panel/config/default.json)" = 0 ]; then
bashio::log.info "Update auth secret.."
sed -i -e "s/API_AUTH_SECRET/$(openssl rand -base64 32)/g" /opt/panel/config/default.json
declare key
if ! bashio::fs.file_exists "/data/secret.txt"; then
bashio::log.info "Generating secret"
newkey=$(openssl rand -base64 32)
echo "${newkey}" > /data/secret.txt
fi
# Force database to use /data
key=$(cat /data/secret.txt)
# Set secret to persistent secret file
sed -i "s/API_AUTH_SECRET/${key}/g" /opt/panel/config/default.json
# Set database to /data
sed -i "s#../db#/data#g" /opt/panel/config/default.json