hvk: add hvk-select.sh
authorHugo Villeneuve <hugo@hugovil.com>
Tue, 29 Oct 2024 19:26:55 +0000 (15:26 -0400)
committerHugo Villeneuve <hugo@hugovil.com>
Thu, 31 Oct 2024 04:44:16 +0000 (00:44 -0400)
scripts/Makefile.am
scripts/hvk-select.sh [new file with mode: 0755]

index d04f78b..4eb6275 100644 (file)
@@ -29,6 +29,7 @@ dist_bin_SCRIPTS = \
     hvk-init.sh \
     hvk-save-defconfig.sh \
     hvk-dt.sh \
+    hvk-select.sh \
     hvk-x86.sh \
     hv-hg-functions.sh \
     hg-format-patch hg-update-subrepos \
diff --git a/scripts/hvk-select.sh b/scripts/hvk-select.sh
new file mode 100755 (executable)
index 0000000..57ce291
--- /dev/null
@@ -0,0 +1,63 @@
+#!/bin/bash
+
+SCRIPT="`readlink -e $0`"
+SCRIPTPATH=$(dirname ${SCRIPT})
+source ${SCRIPTPATH}/hvk-common.sh
+
+hvk_src="${HOME}/.hvk"
+hvk_link=".hvk"
+dialog_outfile="$(mktemp -t hvk.XXXXXXXXXX)"
+
+if [ ! -d "${hvk_src}" ]; then
+    echo "Missing HVK source directory: ${hvk_src}"
+    exit 1
+fi
+
+file=()
+count=0
+list=""
+i=1
+
+# Loop over source folder and add files to array
+while IFS= read -r -d $'\0' file; do
+    f="$(basename ${file})"
+    file+=("${f}")
+
+    status="off"
+
+    set +e
+    hvk_current="$(readlink -e .hvk)"
+    set -e
+
+    if [ "${hvk_current}" != "" ]; then
+        hvk_current_base="$(basename ${hvk_current})"
+
+        if [ "${f}" = "${hvk_current_base}" ]; then
+            status="on"
+        fi
+    fi
+
+    list="${list} ${i} ${f} ${status}"
+    count=$((${count} + 1))
+    i=$((${i} + 1))
+done < <(find "${hvk_src}" -maxdepth 1 -type f ! -name '*~' -print0)
+
+if [ ${count} -eq 0 ]; then
+    echo "Error: no board files found"
+    exit 1
+fi
+
+rows=$((${count} + 7))
+width=40
+
+dialog --radiolist "HVK board selection" ${rows} ${width} ${count} ${list} 2> ${dialog_outfile}
+
+id=$(cat ${dialog_outfile})
+sel="${file[${id}]}"
+
+rm -f ${hvk_link}
+ln -s "${hvk_src}/${sel}" ${hvk_link}
+
+rm ${dialog_outfile}
+
+clear