From 3f0e8c9a531b51dd9b24cbe2e2d394d7da29f0ce Mon Sep 17 00:00:00 2001 From: Alvin Schiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Tue, 23 Apr 2024 08:53:45 +0200 Subject: [PATCH] fix: update default handling for yes/no questions --- components/audio/PirateAudioHAT/setup_pirateAudioHAT.sh | 7 +++---- .../buttons_usb_encoder/setup-buttons-usb-encoder.sh | 7 +++---- components/rfid-reader/PN532/setup_pn532.sh | 7 +++---- components/rfid-reader/RC522/setup_rc522.sh | 7 +++---- scripts/RegisterDevice.py.Multi | 6 +++--- 5 files changed, 15 insertions(+), 19 deletions(-) diff --git a/components/audio/PirateAudioHAT/setup_pirateAudioHAT.sh b/components/audio/PirateAudioHAT/setup_pirateAudioHAT.sh index 97c91194b..2fc977443 100755 --- a/components/audio/PirateAudioHAT/setup_pirateAudioHAT.sh +++ b/components/audio/PirateAudioHAT/setup_pirateAudioHAT.sh @@ -7,11 +7,10 @@ source "${JUKEBOX_HOME_DIR}"/scripts/helperscripts/inc.systemHelper.sh question() { local question=$1 - read -p "${question} (y/n)? " choice + read -p "${question} (Y/n)? " choice case "$choice" in - y|Y ) ;; - n|N ) exit 0;; - * ) echo "Error: invalid" ; question ${question};; + [nN][oO]|[nN]) exit 0;; + * ) ;; esac } diff --git a/components/controls/buttons_usb_encoder/setup-buttons-usb-encoder.sh b/components/controls/buttons_usb_encoder/setup-buttons-usb-encoder.sh index 95db0199c..0fa5fadc0 100755 --- a/components/controls/buttons_usb_encoder/setup-buttons-usb-encoder.sh +++ b/components/controls/buttons_usb_encoder/setup-buttons-usb-encoder.sh @@ -6,11 +6,10 @@ BUTTONS_USB_ENCODER_DIR="${JUKEBOX_HOME_DIR}/components/controls/buttons_usb_enc question() { local question=$1 - read -p "${question} (y/n)? " choice + read -p "${question} (Y/n)? " choice case "$choice" in - y|Y ) ;; - n|N ) exit 0;; - * ) echo "Error: invalid" ; question ${question};; + [nN][oO]|[nN]) exit 0;; + * ) ;; esac } diff --git a/components/rfid-reader/PN532/setup_pn532.sh b/components/rfid-reader/PN532/setup_pn532.sh index 3b9ab1252..8f2e97bbb 100755 --- a/components/rfid-reader/PN532/setup_pn532.sh +++ b/components/rfid-reader/PN532/setup_pn532.sh @@ -5,11 +5,10 @@ JUKEBOX_HOME_DIR="${HOME_DIR}/RPi-Jukebox-RFID" question() { local question=$1 - read -p "${question} (y/n)? " choice + read -p "${question} (Y/n)? " choice case "$choice" in - y|Y ) ;; - n|N ) exit 0;; - * ) echo "Error: invalid" ; question ${question};; + [nN][oO]|[nN]) exit 0;; + * ) ;; esac } diff --git a/components/rfid-reader/RC522/setup_rc522.sh b/components/rfid-reader/RC522/setup_rc522.sh index 43ab60fa6..b6333767b 100644 --- a/components/rfid-reader/RC522/setup_rc522.sh +++ b/components/rfid-reader/RC522/setup_rc522.sh @@ -5,11 +5,10 @@ JUKEBOX_HOME_DIR="${HOME_DIR}/RPi-Jukebox-RFID" question() { local question=$1 - read -p "${question} (y/n)? " choice + read -p "${question} (Y/n)? " choice case "$choice" in - y|Y ) ;; - n|N ) exit 0;; - * ) echo "Error: invalid" ; question ${question};; + [nN][oO]|[nN]) exit 0;; + * ) ;; esac } diff --git a/scripts/RegisterDevice.py.Multi b/scripts/RegisterDevice.py.Multi index 66dc16898..008121496 100644 --- a/scripts/RegisterDevice.py.Multi +++ b/scripts/RegisterDevice.py.Multi @@ -17,7 +17,7 @@ def runCmd(cmd, wait=True): def setupPN532(): answer = input('Please make sure that the PN532 reader is wired up correctly ' 'to the GPIO ports before continuing...\n Continue?: [Y/n]') - if not answer or answer[0] != 'Y': + if answer and answer[0].lower() == 'n': return False print("Activating I2C interface...\n") runCmd("sudo raspi-config nonint do_i2c 0") @@ -41,7 +41,7 @@ def setupPN532(): def setupMFRC522(): answer = input('Please make sure that the RC522 reader is wired up correctly ' 'to the GPIO ports before continuing...\n Continue?: [Y/n]') - if not answer or answer[0] != 'Y': + if answer and answer[0].lower() == 'n': return False print("Installing Python requirements for RC522...\n") runCmd("sudo python3 -m pip install --upgrade --force-reinstall " @@ -78,7 +78,7 @@ def configureDevices(): addDevice() while True: answer = input('Do you want to add another device: [Y/n]') - if not answer or answer[0] != 'Y': + if answer and answer[0].lower() == 'n': break addDevice()