Review shell scripts
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
@@ -9,24 +9,24 @@ if [[ "$#" -ne 2 ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
HOST="$1"
|
||||
host="$1"
|
||||
|
||||
mkdir -p "./hosts/${HOST}/secrets"
|
||||
mkdir -p "./hosts/$host/secrets"
|
||||
|
||||
ssh-keygen -t ed25519 -f "./hosts/${HOST}/secrets/ssh_host_ed25519_key" -N ""
|
||||
ssh-keygen -t ed25519 -f "./hosts/$host/secrets/ssh_host_ed25519_key" -N ""
|
||||
|
||||
AGE_KEY=$(nix shell nixpkgs#ssh-to-age --command bash -c "cat './hosts/${HOST}/secrets/ssh_host_ed25519_key.pub' | ssh-to-age")
|
||||
age_key=$(nix shell nixpkgs#ssh-to-age --command bash -c "cat './hosts/$host/secrets/ssh_host_ed25519_key.pub' | ssh-to-age")
|
||||
|
||||
find . -type f -name "sops.yaml" | while IFS= read -r SOPS_FILE; do
|
||||
sed -i "/- hosts:/a\ - &${HOST} ${AGE_KEY}" "${SOPS_FILE}"
|
||||
sed -i "/- age:/a\ - *${HOST}" "${SOPS_FILE}"
|
||||
find . -type f -name "sops.yaml" | while IFS= read -r sops_file; do
|
||||
sed -i "/- hosts:/a\ - &$host $age_key" "$sops_file"
|
||||
sed -i "/- age:/a\ - *$host" "$sops_file"
|
||||
done
|
||||
|
||||
sed -i "/knownHosts = {/a\ ${HOST}.publicKeyFile = ../../../../${HOST}/secrets/ssh_host_ed25519_key.pub;" ./hosts/common/configs/system/ssh/default.nix
|
||||
sed -i "/userKnownHostsFile = lib.strings.concatStringsSep \" \" \[/a\ ../../../../../${HOST}/secrets/ssh_host_ed25519_key.pub" ./hosts/common/configs/user/console/ssh/default.nix
|
||||
sed -i "/knownHosts = {/a\ $host.publicKeyFile = ../../../../$host/secrets/ssh_host_ed25519_key.pub;" ./hosts/common/configs/system/ssh/default.nix
|
||||
sed -i "/userKnownHostsFile = lib.strings.concatStringsSep \" \" \[/a\ ../../../../../$host/secrets/ssh_host_ed25519_key.pub" ./hosts/common/configs/user/console/ssh/default.nix
|
||||
|
||||
"$(dirname "$0")/update-keys.sh" "$2"
|
||||
|
||||
echo "Host ${HOST} has been successfully added."
|
||||
echo "Host $host has been successfully added."
|
||||
echo "You can generate SSH key pairs for any users that need to connect to user@host using the following command:"
|
||||
echo "ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_${HOST}_<user>"
|
||||
echo "ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_$host_<user>"
|
||||
|
Reference in New Issue
Block a user