added dynamic menu for configuration
This commit is contained in:
2024-03-26 22:14:34 +10:00
parent 6bf8badcac
commit b1282db7ae

View File

@@ -1,27 +1,31 @@
#!/usr/bin/env bash
scriptDIR=$(dirname $0)
hostname=$(hostname -f)
# Okay need to get the hostname and see if this exists in our list of items.
start () {
if [ $hostname == "nixos" ]
then
# no hostname defined. need to generate menu.
menuItems=(
"1. blade "
"2. W00072"
"3. W00149"
"Q. Exit "
)
menuActions=(
setupBlade
setupW00072
setupW00149
quitApp
)
menuIndex=1
menuItems=()
menuActions=()
for entry in "$scriptDIR"/*.nix
do
entry=${entry##*/}
entry=${entry%.nix}
menuItems+=("$menuIndex. $entry")
menuActions+=(build_$entry)
eval "build_${entry}() { hostname=${entry}; doBuild; }"
((menuIndex+=1))
done
menuItems+=("Q. Exit")
menuActions+=(quitApp)
menuTitle=" New nixos instance detected. Please select a build to deploy."
else
# Need to check if the nix file exists
if [[ ! -f "$hostname.nix" ]]
if [[ ! -f $scriptDIR/$hostname.nix ]]
then
menuItems=(
"Q. Exit"
@@ -52,24 +56,9 @@ start () {
menuLoop
}
setupBlade () {
hostname="blade"
doBuild
}
setupW00072 () {
hostname="w00072"
doBuild
}
setupW00149 () {
hostname="w00149"
doBuild
}
doBuild () {
logo
sudo nixos-rebuild switch -I nixos-config=./$hostname.nix
sudo nixos-rebuild switch -I nixos-config=$scriptDIR/$hostname.nix
return 0
}