mirror of
				https://github.com/brain-hackers/brain-config.git
				synced 2025-11-04 06:28:39 +09:00 
			
		
		
		
	Tidied function to control remote GPIO access.
This commit is contained in:
		
							
								
								
									
										57
									
								
								raspi-config
									
									
									
									
									
								
							
							
						
						
									
										57
									
								
								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
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user