Skip to content
This repository has been archived by the owner on Jan 6, 2024. It is now read-only.

Commit

Permalink
🔨 Persist secret and db
Browse files Browse the repository at this point in the history
  • Loading branch information
timmo001 committed Sep 14, 2019
1 parent fd47050 commit 44ff20c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions home-panel/rootfs/etc/cont-init.d/secrets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 44ff20c

Please sign in to comment.