]> Git — Sourcephile - sourcephile-nix.git/blob - private/hosts/encrypt.sh
losurdo: syncoid: move to LoadCredentialEncrypted=
[sourcephile-nix.git] / private / hosts / encrypt.sh
1 #!/usr/bin/env sh
2 set -eux
3 set -o pipefail
4 dir=${0%/*}
5 key=$1
6 host=${key#*/}
7 host=${host%%/*}
8 hostkey=${key#*/*/}
9 mkdir -p "$dir/$host/credentials/${hostkey%/*}"
10 pass "$key" |
11 sudo unshare --mount sh -xc "
12 mount --bind $dir/$host/root/credential.secret /var/lib/systemd/credential.secret &&
13 mount --bind $dir/$host/root/machine-id /etc/machine-id &&
14 systemd-creds encrypt --with-key=host --name '${hostkey##*/}' - - |
15 install -m 400 -o $USER -g users /dev/stdin '$dir/$host/credentials/$hostkey.cred'
16 "