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 # 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