#!/bin/bash
function createmenu
{
if [ -z "$tempdir" ];then
pathcomp=$(mktemp -u --suffix "$(date +%s)"|tr / "\\n")
export pathcomp
temppath=$(echo "$pathcomp"|tr / "\\n"|grep -nw tmp.|cut -f 1 -d :)
export temppath
tempdir=$(echo "$pathcomp"|head -n $((temppath-1))|tr "\\n" /)
export tempdir
fi
menudesc=$(stty -a|grep rows|cut -f 2-6 -d \;|cut -f 3,5,8 -d \ |tr \; \ |sed s/"  "/" "/|sed s/"  "/" "/)
export menudesc
cat "$1"|tail -n 1 >"$tempdir""/itemlist"
numitems=$(cat "$tempdir""/itemlist"|wc -l)
export numitems
linecounter=1
export linecounter
while true;do
cat "$tempdir"/itemlist|head -n $linecounter|tail -n 1 >>"$tempdir"/items
linecounter=$((linecounter+1))
export linecounter
if [ $linecounter -gt "$numitems" ];then
break
else
continue
fi
done
echo "whiptail --menu --nocancel ""$(cat "$1"|head -n 1)"" $(echo -n "$menudesc")"" $(cat "$1"|tail -n 1)">"$tempdir""/menu"
chmod 755 "$tempdir""/menu"
"$tempdir""/menu" 2>"$tempdir""/choice"
choice=$(cat "$tempdir""/choice"|cut -f 2 -d \;)
export choice
cat "$tempdir"/itemlist|sed s/"\"\ /\\n/g"|sed "s/\"//g" > "$tempdir"/items
testnum=$(cat "$tempdir""/items"|grep -nw "$choice"|cut -f 1 -d :|head -n 1)
export testnum
itemname=$(cat "$tempdir"/items|head -n $((testnum+1))|tail -n 1)
export itemname
rm "$tempdir"/choice "$tempdir"/menu "$tempdir"/itemlist "$tempdir"/items "$tempdir"/dynmenu > /dev/null 2>/dev/null
clear
}
function createdynamicmenu
{
if [ -z "$tempdir" ];then
pathcomp=$(mktemp -u --suffix "$(date +%s)"|tr / "\\n")
export pathcomp
temppath=$(echo "$pathcomp"|tr / "\\n"|grep -nw tmp.|cut -f 1 -d :)
export temppath
tempdir=$(echo "$pathcomp"|head -n $((temppath-1))|tr "\\n" /)
export tempdir
fi
"$@">"$tempdir"/itemlist
numitems=$(cat "$tempdir"/itemlist|wc -l)
export numitems
counter=1
export counter
if [ -f "$tempdir""/menutitle" ];then
title=$(cat "$tempdir""/menutitle"|head -n 1)
export title
else
title="$numitems items available"
export title
fi
echo \""$title"\" > "$tempdir"/dynmenu
while true;do
ltr=$(cat "$tempdir"/itemlist|head -n $counter|tail -n 1|cut -c 1)
export ltr
item=$(cat "$tempdir""/itemlist"|head -n $counter|tail -n 1)
export item
echo -n \" >> "$tempdir"/dynmenu
if [ "$ltr" = \" ];then
ltr="|"
export ltr
fi
echo -n "$ltr"\;$counter\"\  \" >> "$tempdir"/"dynmenu"
if echo "$item"|grep -q \";then
item="${item/\"/\|/}"
export item
fi
echo -n "$item" >> "$tempdir"/dynmenu
echo -n \"\  >>"$tempdir"/dynmenu
counter=$((counter+1))
export counter
if [ $counter -gt "$numitems" ];then
break
else
continue
fi
done
createmenu "$tempdir"/dynmenu
rm "$tempdir"/menutitle > /dev/null 2>/dev/null
}
cat<<EOF
This exhibit consists of the following:
VoiceNote MPower QT, running several versions of the Keysoft accessibility suite, You will be asked to select which software version on the next screen if you have not already. To swap versions, backup and move the persist folder, which contains your data.
The following keys can be used to control the device:
qwerty letter and number keys: type
Either Control: Control
Read key: Left Alt
Function: Right Alt
Help: F1
Repeat: F2
Menu: F3
Hold down F11 and tap r, then release both keys: Reset
To return to the menu, press Control slash, 0, Control C. Press Enter To start up.
EOF
read var
clear
if [ -e persist ];then
sleep .01
else
echo "select a version of Keysoft to boot." > /tmp/menutitle
createdynamicmenu sh -c "ls */FlashDisk|cut -f 1 -d /"
echo copying $itemname to work area
cp -rf $itemname persist
fi
./vbnote.`uname -m`.`uname -s` --sd-card persist/FlashDisk --cf-card persist/CFCard --serial-eeprom persist/EEPROM --keyboard --cpu-mhz 32 --flash-image persist/KeysoftSystemDisk > /dev/null 2>/dev/null&
sleep 5
ratpoison -c "select 0"
export bnwin=`ratpoison -c windows|grep -i vbnote|tail -n 1|cut -f 1 -d \  `
ratpoison -c "select $bnwin"
xdotool keydown F11
xdotool keydown g
xdotool keyup F11
xdotool keyup g
play -n -q synth square 440 trim 00:00:00 00:00:00.45
while true;do
trap 'ratpoison -c other;xdotool keydown F11;xdotool keydown q;xdotool keyup q;xdotool keyup F11;xdotool keydown y;xdotool keyup y;cd;catmenu' INT
sleep .25
done
