#!/bin/sh # Root-owned deploy for the server config repo. # Everything under etc/ and bin/ is deployed; only @@NAME@@ placeholders are # filled from /usr/local/etc/dango/secrets/values. The allow-list below is # deliberately NOT taken from the repository. PATH=/opt/wiiu/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin; export PATH BARE=/srv/git/Server/dangofactory-server.git W=/opt/wiiu T=$(mktemp -d /tmp/deploy.XXXXXX) || exit 1 trap 'rm -rf "$T"' EXIT git --git-dir=$BARE archive master | tar -x -C "$T" || exit 1 sh "$T/scripts/scan-secrets.sh" "$T" >/dev/null || { echo "deploy refused: secret scan failed"; exit 1; } map() { case "$1" in bin/deploy-server|bin/deploy-server-all|bin/dango-subst) return 1 ;; etc/*) echo "/usr/local/etc/${1#etc/}" ;; system/etc/*) echo "/etc/${1#system/etc/}" ;; system/boot/*) echo "/boot/${1#system/boot/}" ;; system/ssh/*) echo "/etc/ssh/${1#system/ssh/}" ;; system/cron.d/*) echo "/etc/cron.d/${1#system/cron.d/}" ;; bin/*|libexec/*) echo "$W/$1" ;; rc.d/laminard) echo /usr/local/etc/rc.d/laminard ;; rc.d/*) echo "/etc/rc.d/${1##*/}" ;; www/index.html) echo /srv/www/default/index.html ;; www/default/*) echo "/srv/www/default/${1#www/default/}" ;; www/os/*) echo "/srv/os/${1#www/os/}" ;; ci/laminar/jobs/*) echo "/var/db/laminar/cfg/jobs/${1##*/}" ;; *) return 1 ;; esac } changed="" cd "$T" || exit 1 for f in $(find . -type f | sed 's|^\./||'); do t=$(map "$f") || continue case "$t" in /srv/www/*|/srv/os/*|/usr/local/etc/*|/opt/wiiu/bin/*|/opt/wiiu/libexec/*|/etc/*|/usr/local/etc/*|/boot/*|/root/.ssh/*|/var/db/laminar/cfg/jobs/*) mkdir -p "$(dirname "$t")" ;; *) [ -e "$t" ] || continue ;; esac src="$T/$f" tmp="" if grep -qE '@@[A-Z0-9_]+@@' "$src"; then tmp="/tmp/deploy-subst.$$" if ! $W/bin/dango-subst "$src" "$tmp"; then echo "skipped (missing secret): $f" rm -f "$tmp" continue fi src="$tmp" fi if cmp -s "$src" "$t"; then [ -n "$tmp" ] && rm -f "$tmp" continue fi cp -p "$t" "/tmp/$(echo "$t" | tr / _).deploy-bak" 2>/dev/null || true cp "$src" "$t" || { echo "copy failed: $t"; rm -f "$tmp"; exit 1; } [ -n "$tmp" ] && rm -f "$tmp" changed="$changed $t" echo "deployed: $t" done restart_for() { case "$1" in *etc/lighttpd*) if $W/sbin/lighttpd -tf /usr/local/etc/lighttpd/lighttpd.conf >/dev/null 2>&1; then service lighttpd_wiiu restart >/dev/null 2>&1 && echo "lighttpd restarted" else echo "lighttpd config test failed (files left in place)" fi ;; *etc/dovecot*) service dovecot_wiiu restart >/dev/null 2>&1 && echo "dovecot restarted" ;; *etc/postfix/aliases*) /opt/wiiu/sbin/postalias /usr/local/etc/postfix/aliases >/dev/null 2>&1 && echo "postfix aliases rebuilt" ;; *etc/postfix*) $W/sbin/postfix -c /usr/local/etc/postfix reload >/dev/null 2>&1 && echo "postfix reloaded" ;; *etc/nsd*) service nsd_wiiu restart >/dev/null 2>&1 && echo "nsd restarted" ;; *etc/unbound*) service unbound_wiiu restart >/dev/null 2>&1 && echo "unbound restarted" ;; *etc/rspamd*) service rspamd_wiiu restart >/dev/null 2>&1 && echo "rspamd restarted" ;; *etc/vsftpd*) service vsftpd_wiiu restart >/dev/null 2>&1 && echo "vsftpd restarted" ;; *etc/openldap/*) chown root:ldap /usr/local/etc/openldap/slapd.conf 2>/dev/null || true; chmod 640 /usr/local/etc/openldap/slapd.conf 2>/dev/null || true; service slapd_wiiu restart >/dev/null 2>&1 && echo "slapd restarted" ;; *etc/nslcd.conf*) service nslcd_wiiu restart >/dev/null 2>&1 && echo "nslcd restarted" ;; *etc/cron.d/*) service cron reload >/dev/null 2>&1 && echo "cron reloaded" ;; *etc/sshguard*) service sshguard_wiiu restart >/dev/null 2>&1 && echo "sshguard restarted" ;; *etc/laminar/*|*rc.d/laminard*) daemon -f sh -c "sleep 5; service laminard restart" >/dev/null 2>&1; echo "laminard restart scheduled (detached, 5s)" ;; *etc/pf.conf*) pfctl -nf /etc/pf.conf >/dev/null 2>&1 && pfctl -f /etc/pf.conf >/dev/null 2>&1 && echo "pf reloaded" ;; *etc/ssh/sshd_config*) /usr/sbin/sshd -t >/dev/null 2>&1 && service sshd reload >/dev/null 2>&1 && echo "sshd reloaded" ;; *etc/sysctl.conf*) sysctl -f /etc/sysctl.conf >/dev/null 2>&1 && echo "sysctl applied" ;; *etc/ssh-ldap-keys.pw*) chown root:sshkey /usr/local/etc/ssh-ldap-keys.pw 2>/dev/null || true; chmod 640 /usr/local/etc/ssh-ldap-keys.pw 2>/dev/null || true ;; *git-hooks/post-receive*) $W/bin/deploy-git-hooks >/dev/null 2>&1 && echo "git hooks installed" ;; *etc/ntp.conf*) service ntpd restart >/dev/null 2>&1 && echo "ntpd restarted" ;; */etc/rc.d/bedrockconnect) if service bedrockconnect status >/dev/null 2>&1; then service bedrockconnect restart >/dev/null 2>&1 else service bedrockconnect start >/dev/null 2>&1 fi echo "bedrockconnect (re)started" ;; *etc/rc.conf*) echo "rc.conf deployed (services are not restarted automatically)" ;; *etc/cgitrc*|*etc/cgit-sections*) $W/bin/cgit-sections >/dev/null 2>&1 || true rm -f /var/cache/cgit/* >/dev/null 2>&1 || true echo "cgit sections/cache updated" ;; esac return 0 } for t in $changed; do restart_for "$t"; done [ -n "$changed" ] || echo "nothing to deploy" exit 0