#!/bin/sh set -eu cd "$(dirname "$0")" umask 077 mkdir -p state secrets control chmod 700 state secrets control if [ ! -f .env ]; then sed -e "s/^LOCAL_UID=.*/LOCAL_UID=$(id -u)/" \ -e "s/^LOCAL_GID=.*/LOCAL_GID=$(id -g)/" .env.example > .env fi read_secret() { target=$1 label=$2 minimum=${3:-1} if [ -s "$target" ]; then return; fi printf '%s: ' "$label" previous_tty=$(stty -g) trap 'stty "$previous_tty"' EXIT HUP INT TERM stty -echo IFS= read -r value stty "$previous_tty" trap - EXIT HUP INT TERM printf '\n' if [ "${#value}" -lt "$minimum" ]; then printf 'Password must contain at least %s characters. Run setup.sh again.\n' "$minimum" >&2 exit 1 fi printf '%s' "$value" > "$target" unset value } read_secret secrets/ui_password 'Homegate panel password (at least 12 characters)' 12 read_secret secrets/npm_password 'NPM password' printf 'Automatic DNS requires Pi-hole 6. Manual DNS works with any version.\n' printf 'Configure automatic Pi-hole DNS? [Y/n]: ' IFS= read -r automatic case "$automatic" in n|N|no|NO) if [ ! -f secrets/pihole_password ]; then : > secrets/pihole_password; fi printf 'Set dns_mode: manual in config/services.yaml.\n' ;; *) read_secret secrets/pihole_password 'Pi-hole password (app password requires app_sudo)' ;; esac chmod 600 .env secrets/* printf '\nEdit .env and config/services.yaml, then run:\n' printf ' docker compose build\n' printf ' docker compose run --rm homegate validate\n' printf ' docker compose up -d\n'