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