diff --git a/home-panel/rootfs/etc/cont-init.d/secrets.sh b/home-panel/rootfs/etc/cont-init.d/secrets.sh index 25714a3..c52d1b7 100644 --- a/home-panel/rootfs/etc/cont-init.d/secrets.sh +++ b/home-panel/rootfs/etc/cont-init.d/secrets.sh @@ -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