Skip to content

Commit

Permalink
Read stdio buffer before asking for entry (#457)
Browse files Browse the repository at this point in the history
* Read stdio buffer before asking for entry

* Syntax cleanup

* Added true to avoid error code exit on discard 

disgrace line yields error code >0 stopping execute
  • Loading branch information
darkdrgn2k committed Dec 8, 2019
1 parent 556e084 commit f7ca4f9
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions scripts/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,26 @@ function askModule {

if [ "$(checkModule 'WITH_DIALOG')" ]; then
if [ -z "$res" ] || [ "$res" != "true" ] && [ "$res" != "false" ]; then
# Do not stop exec on non 0 return values
set +e
# shellcheck disable=SC2086
dialog $dialogGlobalParams $dialogParam --title "$2" --yesno "Install $2?" 6 55
response=$?
# Return to previous setting
set -e

case $response in
0) res="true";;
1) res="false";;
255) exit;;
# Do not stop exec on non 0 return values
set +e
# shellcheck disable=SC2086
dialog $dialogGlobalParams $dialogParam --title "$2" --yesno "Install $2?" 6 55
response=$?
# Return to previous setting
set -e

case $response in
0) res="true";;
1) res="false";;
255) exit;;
esac
fi
fi
else
if [ -z "$res" ] || [ "$res" != "true" ] && [ "$res" != "false" ]; then

# Clear buffer before asking
read -t 1 -n 10000 discard || true

read -p "Install $2 $askPrompt? " -n 1 -r
echo ""
if [[ $REPLY =~ ^[$nonDefaultMatch]$ ]]; then
Expand Down Expand Up @@ -85,6 +89,10 @@ function askSelection {
selection=$2
dialogREPLY=""
if [ "$(checkModule 'WITH_DIALOG')" ]; then

# Clear buffer before asking
read -t 1 -n 10000 discard || true

selection=$(echo -e "$selection" | while read -r selected; do
selectedItem="${selected:0:1}"
selectedText="${selected:2}"
Expand All @@ -93,7 +101,7 @@ function askSelection {
echo "$selection" > /tmp/selectionList
# shellcheck disable=SC2086
dialog $dialogGlobalParams --menu "$1" 15 55 8 --file /tmp/selectionList 2> /tmp/res
dialog $dialogGlobalParams --menu "$1" 15 55 8 --file /tmp/selectionList 2> /tmp/res
rm -f selectionList
response=$(cat /tmp/res)
rm -f /tmp/res
Expand All @@ -108,6 +116,10 @@ function askSelection {
else
isValid=""
while [[ "$isValid" == "" ]]; do
# Clear buffer before asking
read -t 1 -n 10000 discard || true
echo -e "$1"
echo -------------------
echo -e "$2"
Expand All @@ -117,6 +129,9 @@ function askSelection {
if [[ ! "$REPLY" == "" ]]; then
REPLY=$(echo "$REPLY" | awk '{print toupper($0)}')
# Clear buffer before asking
read -t 1 -n 10000 discard || true
isValid=$(echo -e "$selection" | while read -r selected; do
if [[ "${selected:0:1}" == "$REPLY" ]]; then
echo 1
Expand Down Expand Up @@ -154,18 +169,15 @@ function detectBoard {
BOARD_NAME=$(grep Hardware /proc/cpuinfo | awk '{print $3}' | head -n 1)
fi
fi
# Check for armbian identification
if [ -f "/etc/armbian-image-release" ]; then
BOARD_OS="Armbian"
BOARD_MODEL="$(grep "BOARD=" /etc/armbian-image-release | awk -F '=' '{print $2}' | tr -d \")"
BOARD_NAME="$(grep BOARD_NAME /etc/armbian-image-release | awk -F '=' '{print $2}' | tr -d \" )"
BOARD_NEON=true
fi
if [[ "$BOARD_NAME" == "Raspberry Pi"* ]]; then
BOARD_OS="Raspbian"
# Check for default password is still set for user pi
# If it is force password before reboot
# shellcheck disable=SC2016
Expand All @@ -185,11 +197,9 @@ function detectBoard {
BOARD_MODEL="raspberrypi1"
BOARD_NEON=false
fi
if [[ "$BOARD_NAME" == *"Zero"* ]]; then
BOARD_MODEL="raspberrypizero"
BOARD_NEON=false
fi
fi
}

0 comments on commit f7ca4f9

Please sign in to comment.