Fix utility script bugs

Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2024-12-20 10:00:01 +00:00
parent dbc913fcd8
commit 6c32412fa3
7 changed files with 35 additions and 20 deletions

View File

@@ -42,7 +42,7 @@ Any `options.nix` files create custom option definitions when present.
Below is a table of all hosts, with links to their respective README files, which may provide further details and/or post-installation checklists.
| Host | README |
|-------------|------------------------------------------------------|
|-------------|----------------------------------------------------------|
| `installer` | [hosts/installer/README.md](./hosts/installer/README.md) |
| `eirene` | [hosts/eirene/README.md](./hosts/eirene/README.md) |
| `elara` | [hosts/elara/README.md](./hosts/elara/README.md) |

View File

@@ -1 +1,13 @@
# installer
I have automated myself out of a job. How to use:
1. Boot into installer
2. Unlock luks partition
3. Run the following commands:
```
cd /etc/nixos
direnv allow
sudo ./lib/scripts/install.sh
```

View File

@@ -17,7 +17,7 @@ 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")
for SOPS_FILE in $(find . -type f -name "sops.yaml"); do
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

View File

@@ -59,7 +59,7 @@ setup_wifi() {
fi
echo "Waiting for a network connection..."
for i in {1..10}; do
for _ in {1..10}; do
if ping -c 1 google.com &>/dev/null; then
echo "Connected to the network successfully."
return
@@ -73,8 +73,9 @@ setup_wifi() {
select_host() {
echo "Available hosts:"
echo $(nix --experimental-features "nix-command flakes" flake show --json |
nix --experimental-features "nix-command flakes" shell nixpkgs#jq --command jq -r '.nixosConfigurations | keys[]')
hosts=$(nix --experimental-features "nix-command flakes" flake show --json \
| nix --experimental-features "nix-command flakes" shell nixpkgs#jq --command jq -r '.nixosConfigurations | keys[]')
echo "${hosts}"
echo "Enter host:"
read -r host
@@ -120,8 +121,8 @@ copy_config() {
read -r copy_config
if [[ "${copy_config}" =~ ^([yY][eE][sS]|[yY])$ ]]; then
rm -rf /mnt/etc/nixos
cp -r . /mnt/etc/nixos
rm -rf /mnt/persist/etc/nixos
cp -r . /mnt/persist/etc/nixos
echo "Configuration copied successfully."
fi
}

View File

@@ -13,7 +13,7 @@ HOST="$1"
AGE_KEY=$(nix shell nixpkgs#ssh-to-age --command bash -c "cat './hosts/${HOST}/secrets/ssh_host_ed25519_key.pub' | ssh-to-age")
for SOPS_FILE in $(find . -type f -name "sops.yaml"); do
find . -type f -name "sops.yaml" | while IFS= read -r SOPS_FILE; do
sed -i "/ - &${HOST} ${AGE_KEY}/d" "${SOPS_FILE}"
sed -i "/ - \*${HOST}/d" "${SOPS_FILE}"
done

View File

@@ -11,10 +11,12 @@ fi
export SOPS_AGE_KEY_FILE="$1"
for SOPS_FILE in $(find . -type f -name 'sops.yaml'); do
find . -type f -name 'sops.yaml' | while IFS= read -r SOPS_FILE; do
dir=$(dirname "${SOPS_FILE}")
echo "${dir}"
find "${dir}" -maxdepth 1 -type f -regextype posix-extended -regex '.+\.(yaml|yml|json|env|ini|bin)' | while read -r file; do
find "${dir}" -maxdepth 1 -type f -regextype posix-extended \
-regex '.+\.(yaml|yml|json|env|ini|bin)' \
! -name 'sops.yaml' | while IFS= read -r file; do
echo "${file}"
nix shell nixpkgs#sops --command sops --config "${SOPS_FILE}" updatekeys "${file}" -y
done