1# When forge restore takes identity.db from litestream's replica (it2# changed after the backup's copy), the file is the git user's alone (600),3# however litestream wrote it. A stand-in litestream restores a copy of4# identity.db that is readable by anyone.5. "$(dirname "$0")/../lib.sh"6user dami7ok ssh_as dami token a8"$FORGE" backup --dry-run --force >/dev/null 2>&1 || fail "backup --dry-run"9mv "$FORGE_ROOT/.forge/backup/stage" "$T/stage"10# The replica, a token later.11export FORGE_NOW=$((T_NOW + 60))12ok ssh_as dami token b13FORGE_STATE=$FORGE_ROOT/.forge ok node "$T_HOME/lib/identity.ts" snapshot "$T/replica.db"14mkdir -p "$T/bin"15cat >"$T/bin/litestream" <<SH16#!/bin/sh17o=18while [ \$# -gt 0 ]; do case \$1 in -o) o=\$2; shift ;; esac; shift; done19cp "$T/replica.db" "\$o" && chmod 644 "\$o"20SH21chmod +x "$T/bin/litestream"22export PATH=$T/bin:$PATH FORGE_BACKUP_REPOSITORY=$T/restic FORGE_BACKUP_PASSWORD=test23r=$T/restored24ok restore_into "$r" --from "$T/stage"25has "$T_LOG" "identity.db is litestream's, which changed last"26eq "$(mode "$r/.forge/identity.db")" 600