From 768ea4e4e1dc3f67dfdd1535af8bd612aef7f352 Mon Sep 17 00:00:00 2001 From: Hugo Villeneuve Date: Tue, 29 Oct 2024 15:26:55 -0400 Subject: [PATCH] hvk: add hvk-select.sh --- scripts/Makefile.am | 1 + scripts/hvk-select.sh | 63 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100755 scripts/hvk-select.sh diff --git a/scripts/Makefile.am b/scripts/Makefile.am index d04f78b..4eb6275 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -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 index 0000000..57ce291 --- /dev/null +++ b/scripts/hvk-select.sh @@ -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 -- 2.20.1