dotfiles/.config/scripts/sync_vault.sh

23 lines
1.1 KiB
Bash
Raw Normal View History

2024-03-30 15:12:05 +01:00
#!/bin/bash
2024-04-01 01:25:46 +02:00
export XDG_CONFIG_HOME=/home/server/.config
2024-03-30 15:12:05 +01:00
source "$XDG_CONFIG_HOME"/zsh/secrets.sh
for _ in {1..2}; do
OUTPUT=$(echo "$ZFS_PASSPHRASE" | ssh 10.4.0.1 zfs load-key Vault/Thomas/Encrypted 2>&1);
if [ "$OUTPUT" == "Key load error: Key already loaded for 'Vault/Thomas/Encrypted'." ]; then
echo "Key successfully loaded, starting syncoid"
syncoid --no-privilege-elevation --no-sync-snap tank/Storage/Thomas/Workspace 10.4.0.1:Vault/Thomas/Encrypted/Storage/Workspace
syncoid --no-privilege-elevation --no-sync-snap tank/Storage/Thomas 10.4.0.1:Vault/Thomas/Encrypted/Storage/T
syncoid --no-privilege-elevation --no-sync-snap tank/Storage/Niels 10.4.0.1:Vault/Thomas/Encrypted/Storage/N
syncoid --no-privilege-elevation --no-sync-snap tank/Storage/Yolande 10.4.0.1:Vault/Thomas/Encrypted/Storage/Y
syncoid --no-privilege-elevation --no-sync-snap tank/Containers 10.4.0.1:Vault/Thomas/Encrypted/Containers
ssh 10.4.0.1 zfs unload-key Vault/Thomas/Encrypted
exit 0
fi
done
echo "Found output instead: $OUTPUT"
echo "Failed to load key: $OUTPUT" | sendmail
exit 1