diff --git a/deploy.conf b/deploy.conf index 5c796ef..0e16df7 100644 --- a/deploy.conf +++ b/deploy.conf @@ -1,3 +1,6 @@ +# SCRIPT SETTINGS +DEBUG="true" + #TARGET SETTINGS export TARGET_HOST="192.168.1.10" export REMOTE_PASS="example" diff --git a/deploy.sh b/deploy.sh index 9d87c45..234b620 100644 --- a/deploy.sh +++ b/deploy.sh @@ -384,22 +384,23 @@ services_generation() { } echo -e "\n ✅ Writing configuration files for the selected homelab services..." - cp -avu templates/nix-config/configuration.nix final-nix-config/etc/nixos/configuration.nix - cp -avu templates/nix-config/podman/traefik.nix final-nix-config/etc/nixos/podman/traefik.nix + cp -${FILES_COPY_FLAGS} templates/nix-config/configuration.nix final-nix-config/etc/nixos/configuration.nix + cp -${FILES_COPY_FLAGS} templates/nix-config/podman/traefik.nix final-nix-config/etc/nixos/podman/traefik.nix envsubst < templates/podman-config/traefik/traefik.yaml > final-nix-config/mnt/config/traefik/traefik.yaml j=1 for service in "${SELECTED_SERVICES[@]}"; do - [[ "${service}" != "virtualization" ]] && cp -avu templates/nix-config/podman/"${service}".nix final-nix-config/etc/nixos/podman/"${service}".nix + [[ "${service}" == "frigate" ]] && continue + [[ "${service}" != "virtualization" ]] && cp -${FILES_COPY_FLAGS} templates/nix-config/podman/"${service}".nix final-nix-config/etc/nixos/podman/"${service}".nix SERVICES_NETWORK_IDS+=("${j},$(( ${j} + 1 )):${service}") PODMAN_NETWORKS+=" sudo -u numbus-admin podman network exists \"${service}_frontend\" || sudo -u numbus-admin podman network create --driver=\"bridge\" --subnet=\"172.16.${j}.0/24\" --ip-range=\"172.16.${j}.0/24\" --gateway=\"172.16.${j}.254\" \"${service}_frontend\""$'\n' - ((j++)) - PODMAN_NETWORKS+=" sudo -u numbus-admin podman network exists \"${service}_backend\" || sudo -u numbus-admin podman network create --driver=\"bridge\" --subnet=\"172.16.${j}.0/24\" --ip-range=\"172.16.${j}.0/24\" --gateway=\"172.16.${j}.254\" \"${service}_backend\""$'\n' TRAEFIK_NETWORKS+=" ${service}_frontend:"$'\n' TRAEFIK_NETWORKS+=" ipv4_address: 172.16.${j}.253"$'\n' TRAEFIK_REF_NETWORKS+=" ${service}_frontend:"$'\n' TRAEFIK_REF_NETWORKS+=" external: true"$'\n' ((j++)) + PODMAN_NETWORKS+=" sudo -u numbus-admin podman network exists \"${service}_backend\" || sudo -u numbus-admin podman network create --driver=\"bridge\" --subnet=\"172.16.${j}.0/24\" --ip-range=\"172.16.${j}.0/24\" --gateway=\"172.16.${j}.254\" \"${service}_backend\""$'\n' + ((j++)) done for service in "${SELECTED_SERVICES[@]}"; do @@ -410,7 +411,7 @@ j=1 if [[ "${TARGET_PCIE_CORAL}" == "true" ]]; then FRIGATE_DEVICES_BLOCK+=" - /dev/apex_0:/dev/apex_0\n" sed -i "s|# ./pcie-coral/coral.nix| ./pcie-coral/coral.nix|" final-nix-config/etc/nixos/configuration.nix - cp -avu templates/nix-config/pcie-coral/* final-nix-config/etc/nixos/pcie-coral/ + cp -${FILES_COPY_FLAGS} templates/nix-config/pcie-coral/* final-nix-config/etc/nixos/pcie-coral/ fi if [[ -n "${FRIGATE_DEVICES_BLOCK}" ]]; then local REPLACEMENT="devices:\n${FRIGATE_DEVICES_BLOCK%\\n}" @@ -540,7 +541,7 @@ EOF fi done if [[ -n "${SPINDOWN_DISKS_ID[@]}" ]]; then - cp -avu templates/nix-config/disks/spindown.nix final-nix-config/etc/nixos/disks/ + cp -${FILES_COPY_FLAGS} templates/nix-config/disks/spindown.nix final-nix-config/etc/nixos/disks/ local FORMATTED_DISKS="" for disk in "${SPINDOWN_DISKS_ID[@]}"; do FORMATTED_DISKS+=" \"$disk\"\n" @@ -598,8 +599,8 @@ EOF nix_generation() { echo -e "\n ✅ Copying the configuration to the new machine..." - cp -avu templates/nix-config/flake.nix final-nix-config/etc/nixos/ - cp -avu templates/nix-config/misc/* final-nix-config/etc/nixos/misc/ + cp -${FILES_COPY_FLAGS} templates/nix-config/flake.nix final-nix-config/etc/nixos/ + cp -${FILES_COPY_FLAGS} templates/nix-config/misc/* final-nix-config/etc/nixos/misc/ echo "${SERVER_OWNER_NAME:-User}" > final-nix-config/etc/numbus-server/owner echo -e "\n ✅ Writing correct ips to configuration.nix..." @@ -617,7 +618,7 @@ nix_generation() { sed -i "s|# ./disks/pcr-check.nix| ./disks/pcr-check.nix|" final-nix-config/etc/nixos/configuration.nix sed -i "s|# boot.initrd.systemd.tpm2.enable = true;| boot.initrd.systemd.tpm2.enable = true;|" final-nix-config/etc/nixos/configuration.nix sed -i "s|# systemIdentity.enable = true;| systemIdentity.enable = true;|" /etc/nixos/configuration.nix - cp -avu templates/nix-config/disks/pcr-check.nix final-nix-config/etc/nixos/disks/ + cp -${FILES_COPY_FLAGS} templates/nix-config/disks/pcr-check.nix final-nix-config/etc/nixos/disks/ fi } @@ -779,7 +780,7 @@ export_configuration() { local CONFIG_EXPORT_DIR="final-nix-config/etc/numbus-server/" local CONFIG_EXPORT_FILE="${CONFIG_EXPORT_DIR}/numbus-server.conf" - cp -avu templates/post-install/numbus-server.sh "$CONFIG_EXPORT_DIR" + cp -${FILES_COPY_FLAGS} templates/post-install/numbus-server.sh "$CONFIG_EXPORT_DIR" echo "export TARGET_INTERFACE=\"${TARGET_INTERFACE}\"" >> $CONFIG_EXPORT_FILE echo -e "\n# SERVER SETTINGS" >> $CONFIG_EXPORT_FILE @@ -934,6 +935,14 @@ EOF sleep 1 +if [[ "${DEBUG:-false}" == "true" ]]; then + DIR_COPY_FLAGS="ravu" + FILES_COPY_FLAGS="avu" +else + DIR_COPY_FLAGS="rau" + FILES_COPY_FLAGS="au" +fi + # Choose the action ACTION_ANSWER=$(gum choose "[1] 🌐 Deploy NixOS on a remote machine" "[2] 💽 Deploy NixOS on a remote machine with a file configuration" "[3] 🛠️ Update a NixOS remote machine") diff --git a/templates/nix-config/misc/activation.nix b/templates/nix-config/misc/activation.nix index eb305c2..bfbd645 100644 --- a/templates/nix-config/misc/activation.nix +++ b/templates/nix-config/misc/activation.nix @@ -14,20 +14,26 @@ #!/usr/bin/env bash if [[ -e /home/numbus-admin/.numbus-server/activated.true ]]; then + echo "Already activated" exit 0 fi + echo "Creating directories with correct permissions..." mkdir -p /mnt/config/ /mnt/data/ /mnt/data/nextcloud/ mkdir -p /home/numbus-admin/.numbus-server/ chown -R numbus-admin:users /mnt/config/ chown -R numbus-admin:users /mnt/data/ chown -R 100032:users /mnt/data/nextcloud/ + echo "Creating podman networks..." + export PATH=$PATH:/run/wrappers/bin + PODMAN_NETWORKS mkdir -p /home/numbus-admin/.numbus-server/ touch /home/numbus-admin/.numbus-server/activated.true chown -R numbus-admin:users /home/numbus-admin/.numbus-server/ + echo "Activated successfully !" ''; }; @@ -52,16 +58,18 @@ PODMAN_NETWORKS set -euo pipefail if [[ -e /home/numbus-admin/.numbus-server/quirked.true ]]; then + echo "Quirks already applied" exit 0 fi DOMAIN_NAME="$(cat /run/secrets/domain_name)" + echo "Applying Pi-Hole quirks..." if [[ -e /etc/nixos/podman/pi-hole.nix ]]; then mkdir -p /mnt/config/pi-hole/ chown -R numbus-admin:users /mnt/config/pi-hole/ + echo "Waiting for Pi-hole to be ready..." until [[ -e /mnt/config/pi-hole/pihole-FTL.db ]]; do - echo "Waiting for Pi-hole to be ready..." sleep 15 done sleep 60 @@ -71,11 +79,12 @@ PODMAN_NETWORKS echo "Pi-Hole quirk applied and service ready !" fi + echo "Applying Home Assistant quirks..." if [[ -e /etc/nixos/podman/home-assistant.nix ]]; then mkdir -p /mnt/config/home-assistant/ chown -R numbus-admin:users /mnt/config/home-assistant/ + echo "Waiting for Home Assistant to be ready..." until [[ -e /mnt/config/home-assistant/configuration.yaml ]]; do - echo "Waiting for Home Assistant to be ready..." sleep 15 done sleep 180 @@ -92,11 +101,12 @@ EOF echo "Home Assistant quirk applied and service ready !" fi + echo "Applying Frigate quirks..." if [[ -e /etc/nixos/podman/frigate.nix ]]; then mkdir -p /mnt/config/frigate/ chown -R numbus-admin:users /mnt/config/frigate/ + echo "Waiting for Frigate to be ready..." until [[ -e /mnt/config/frigate/config.yaml ]]; do - echo "Waiting for Frigate to be ready..." sleep 15 done sleep 180 @@ -113,6 +123,7 @@ EOF mkdir -p /home/numbus-admin/.numbus-server/ touch /home/numbus-admin/.numbus-server/quirked.true chown -R numbus-admin:users /home/numbus-admin/.numbus-server/ + echo "Quirks applied successfully !" ''; }; } \ No newline at end of file