Do different things for for rebuild and initialize commands.

component: tooling
This commit is contained in:
Adriano Caloiaro 2025-01-19 09:15:30 -07:00
parent f75443f087
commit a375a9f940
No known key found for this signature in database
GPG key ID: C2BC56DE73CE3F75

View file

@ -97,10 +97,13 @@
# Add our public key to the sfos user's authorized keys
nix-editor nixos/sfos-host-01/configuration.nix users.users.sfos.openssh.authorizedKeys.keys -i -v "[\"$TF_VAR_admin_ssh_public_key\"]"
tofu output -json | jq '.cluster_ips.value | join(",")' | tr -d '"' | while read host; do
echo "Rebuilding $host"
echo "Initializing $host"
ssh_public_key=$(ssh-keyscan $host | grep ssh-ed25519 | cut -d " " -f 2,3)
nix-editor ../secrets/secrets.nix gitea_postgres_password.age.publicKeys -i -v "\"$ssh_public_key\""
nixos-rebuild switch --flake .#sfos --target-host "root@$host" --build-host "root@$host"
client_trust_token=$(ssh sfos@$host incus config trust add sfos-client -q)
incus remote add $host --accept-certificate --token $client_trust_token
grep -qxF "export TF_VAR_incus_token=$client_trust_token" ../.env || echo "export TF_VAR_incus_token=$client_trust_token" >> ../.env
done
'';
};
@ -115,12 +118,9 @@
tofu output -json | jq '.cluster_ips.value | join(",")' | tr -d '"' | while read host; do
echo "Rebuilding $host"
nixos-rebuild switch --flake .#sfos --target-host "sfos@$host" --build-host "sfos@$host" --use-remote-sudo
client_trust_token=$(ssh sfos@$host incus config trust add sfos-client -q)
ssh_public_key=$(ssh-keyscan $host | grep ssh-ed25519 | cut -d " " -f 2,3)
incus remote generate-certificate 2&>/dev/null
incus remote add $host --accept-certificate --token $client_trust_token
grep -qxF "export TF_VAR_incus_cluster_ip=$host" ../.env || echo "export TF_VAR_incus_cluster_ip=$host" >> ../.env
grep -qxF "export TF_VAR_incus_token=$client_trust_token" ../.env || echo "export TF_VAR_incus_token=$client_trust_token" >> ../.env
grep -qxF "export TF_VAR_agenix_public_key=\"$ssh_public_key\"" ../.env || echo "export TF_VAR_agenix_public_key=\"$ssh_public_key\"" >> ../.env
done
'';