main
 1#!/sbin/openrc-run
 2description="Restore SSH host keys and WireGuard key from persist partition"
 3
 4depend() {
 5    after localmount
 6    before sshd secrets wg-quick.wg0
 7}
 8
 9start() {
10    if [ ! -d /persist ]; then
11        einfo "No persist partition — using generated keys"
12        return 0
13    fi
14
15    # SSH host key
16    if [ -f /persist/ssh/ssh_host_ed25519_key ]; then
17        ebegin "Restoring SSH host key from persist"
18        cp /persist/ssh/ssh_host_ed25519_key /etc/ssh/ssh_host_ed25519_key
19        [ -f /persist/ssh/ssh_host_ed25519_key.pub ] && \
20            cp /persist/ssh/ssh_host_ed25519_key.pub /etc/ssh/ssh_host_ed25519_key.pub
21        chmod 600 /etc/ssh/ssh_host_ed25519_key
22        chmod 644 /etc/ssh/ssh_host_ed25519_key.pub 2>/dev/null
23        eend 0
24    else
25        ewarn "No SSH host key on persist — using generated key"
26    fi
27}