From fe0470281a8fa5a20e582cb2dbc420b5178e550d Mon Sep 17 00:00:00 2001 From: Zuma Date: Fri, 21 Nov 2025 16:05:19 +0100 Subject: [PATCH] Add deploy script for all cluster --- README.md | 7 +++++-- deploy_nix.sh | 56 +++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 50 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index e2b751c..09bebc9 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,12 @@ # Infra - La filouterie -Pour déployer une config, faites : +Pour déployer une config utilisez `deploy_nix.sh` : ``` -sudo ./deploy_nix +# Déploiement uniquement sur la node locale +./deploy_nix.sh local +# Déploiement sur le cluster +./deploy_nix.sh all ``` Merci à tous·tes diff --git a/deploy_nix.sh b/deploy_nix.sh index e32ad4a..e5a1ef2 100755 --- a/deploy_nix.sh +++ b/deploy_nix.sh @@ -1,13 +1,47 @@ -#! /usr/bin/env bash - -if [ -z "${NODE:-}" ] - then - echo "Erreur : Si c'est la première fois que vous déployez le serveur, merci de faire: sudo NODE='votre_node' ./deploy_nix.sh" - exit 1 +if [ -z "$1" ]; then + # If no mode is specified it is local by default + MODE="local" +else + if [ "$1" = "local" ] || [ "$1" = "all" ]; then + MODE="$1" + else + echo "Mode $1 not recognized. Use either \`local\` for deployement on this node or \`all\` for deployement on the cluster." + exit 1 + fi fi -cp configuration.nix /etc/nixos/configuration.nix -cp cluster/nodes/$NODE.nix /etc/nixos/node.nix -cp wgautomesh.nix /etc/nixos/wgautomesh.nix -cp cluster.nix /etc/nixos/cluster.nix -nixos-rebuild switch +# Get hostname for local deployement +HOSTNAME=$(hostname) + +if [ "$MODE" = "local" ]; then + echo "====== Started deployement for LOCAL NODE... ======" + echo "Copying files ..." + sudo cp ./configuration.nix /etc/nixos/ + sudo cp ./cluster.nix /etc/nixos/ + sudo cp ./wgautomesh.nix /etc/nixos/ + sudo cp ./cluster/nodes/$HOSTNAME.nix /etc/nixos/node.nix + echo "Rebuilding nixOs ..." + sudo nixos-rebuild switch +elif [ "$MODE" = "all" ]; then + echo "====== Started deployement for ALL CLUSTER... ======" + read -r -s -p "Enter remote sudo password: " ROOT_PASS + # Get list of files in ./cluster/nodes to get hostnames of nodes + NIXHOSTLIST=$(ls cluster/nodes | grep '\.nix$') + for NIXHOST in $NIXHOSTLIST; do + NIXHOST=${NIXHOST%.*} + echo "" + echo "====== doing $NIXHOST ======" + echo "Copying files ..." + # Creating files and folder in /tmp/nixcfg with user permissions + # Because we cannot scp to root folder + echo "mkdir -p /tmp/nixcfg && rm -R /tmp/nixcfg/*" | ssh -p 1972 $NIXHOST.node.chokbar.bzh sh - + scp -P 1972 ./configuration.nix $NIXHOST.node.chokbar.bzh:/tmp/nixcfg/ + scp -P 1972 ./cluster.nix $NIXHOST.node.chokbar.bzh:/tmp/nixcfg/ + scp -P 1972 ./wgautomesh.nix $NIXHOST.node.chokbar.bzh:/tmp/nixcfg/ + scp -P 1972 ./cluster/nodes/$NIXHOST.nix $NIXHOST.node.chokbar.bzh:/tmp/nixcfg/node.nix + echo "Moving them to /etc/nixos ..." + echo "sudo -S <<< $ROOT_PASS mv /tmp/nixcfg/* /etc/nixos/" | ssh -p 1972 $NIXHOST.node.chokbar.bzh sh - + echo "Rebuilding nixOs ..." + echo "sudo -S <<< $ROOT_PASS nixos-rebuild switch" | ssh -p 1972 $NIXHOST.node.chokbar.bzh sh - + done +fi