From 59649e8ba77262ad5a893244c8940319cf67485f Mon Sep 17 00:00:00 2001 From: spl Date: Wed, 25 May 2016 13:21:58 +0100 Subject: [PATCH] Tidied function to control remote GPIO access. --- raspi-config | 57 ++++++++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/raspi-config b/raspi-config index 2e89a08..d401eca 100755 --- a/raspi-config +++ b/raspi-config @@ -904,42 +904,37 @@ do_gpiosec() { whiptail --msgbox "This option can only be selected when using systemd" 20 60 2 return 1 fi - if [ "$INTERACTIVE" = True ]; then - RET=$(whiptail --menu "Choose GPIO Access Mode" 20 70 10 \ - "Public" "GPIO server can be accessed remotely" \ - "Private" "GPIO server can only be accessed locally" \ - 3>&1 1>&2 2>&3) - else - get_init_sys - RET=$1 - true + + DEFAULT=--defaultno + CURRENT=0 + if [ $(get_rgpio) -eq 0 ]; then + DEFAULT= + CURRENT=1 fi - if [ $? -eq 0 ]; then - case "$RET" in - Private) - rm -f /etc/systemd/system/pigpiod.service.d/public.conf - STATUS=disabled - ;; - Public) - mkdir -p /etc/systemd/system/pigpiod.service.d/ - cat > /etc/systemd/system/pigpiod.service.d/public.conf << EOF + if [ "$INTERACTIVE" = True ]; then + whiptail --yesno "Would you like the GPIO server to be accessible over the network?" $DEFAULT 20 60 2 + RET=$? + else + RET=$1 + fi + if [ $RET -eq 0 ]; then + mkdir -p /etc/systemd/system/pigpiod.service.d/ + cat > /etc/systemd/system/pigpiod.service.d/public.conf << EOF [Service] ExecStart= ExecStart=/usr/bin/pigpiod EOF - STATUS=enabled - ;; - *) - whiptail --msgbox "Programmer error, unrecognised option" 20 60 2 - return 1 - ;; - esac - systemctl daemon-reload - systemctl restart pigpiod - if [ "$INTERACTIVE" = True ]; then - whiptail --msgbox "Remote access to the GPIO server is $STATUS" 20 60 1 - fi - return 0 + STATUS=enabled + elif [ $RET -eq 1 ]; then + rm -f /etc/systemd/system/pigpiod.service.d/public.conf + STATUS=disabled + else + return $RET + fi + systemctl daemon-reload + systemctl restart pigpiod + if [ "$INTERACTIVE" = True ]; then + whiptail --msgbox "Remote access to the GPIO server is $STATUS" 20 60 1 fi }