Update menu-ap

This commit is contained in:
Esteban Mackay Q. 2024-05-29 09:55:36 -05:00
parent 065a3fe706
commit 04f0fb0d74
1 changed files with 56 additions and 57 deletions

View File

@ -1,66 +1,65 @@
#!/bin/bash #!/bin/bash
if [ "$(cat /proc/cpuinfo | grep 'Raspberry')" != "" ]; then
#menu-ap # Check if the script is running on a Raspberry Pi
if [ "$(grep 'Raspberry' /proc/cpuinfo)" != "" ]; then
# Create the menu-ap script
sudo cat > /bin/menu-ap <<- "EOF" sudo cat > /bin/menu-ap <<- "EOF"
#!/bin/bash #!/bin/bash
while : ; do while : ; do
choix=$(whiptail --title "WiFi auto AP option" --menu "Select enable or disable auto AP mode." 20 75 11 \ choix=$(whiptail --title "WiFi auto AP option" --menu "Select enable or disable auto AP mode." 20 75 11 \
1 "Disable auto AP mode" \ 1 "Disable auto AP mode" \
2 "Enable auto AP mode" \ 2 "Enable auto AP mode" \
3 "Menu Principal" 3>&1 1>&2 2>&3) 3 "Menu Principal" 3>&1 1>&2 2>&3)
exitstatus=$? exitstatus=$?
#on recupere ce choix
#exitstatus=$? # Check if the user selected an option
if [ $exitstatus = 0 ]; then if [ $exitstatus = 0 ]; then
echo "Your chosen option:" $choix echo "Your chosen option:" $choix
else else
echo "You chose cancel."; break; echo "You chose cancel."
break
fi fi
# case : action en fonction du choix
# Perform actions based on user choice
case $choix in case $choix in
1) 1)
#!/bin/bash # Disable auto AP mode
# Lista de servicios a reiniciar
servicios=("autoap.service") servicios=("autoap.service")
# Recorre la lista de servicios y verifica si están activos
for servicio in "${servicios[@]}"; do for servicio in "${servicios[@]}"; do
if systemctl status "$servicio" | grep "service; enabled;" >/dev/null 2>&1; then if systemctl is-enabled "$servicio" >/dev/null 2>&1; then
echo "stop $servicio" echo "Disabling $servicio"
sudo systemctl disable "$servicio" sudo systemctl disable "$servicio"
sudo systemctl stop "$servicio" sudo systemctl stop "$servicio"
fi fi
done done
;; ;;
2) 2)
#!/bin/bash # Enable auto AP mode
# Lista de servicios a reiniciar
servicios=("autoap.service") servicios=("autoap.service")
# Recorre la lista de servicios y verifica si están activos
for servicio in "${servicios[@]}"; do for servicio in "${servicios[@]}"; do
if systemctl status "$servicio" | grep "service; enabled;" >/dev/null 2>&1; then if systemctl is-enabled "$servicio" >/dev/null 2>&1; then
echo "restart $servicio" echo "Restarting $servicio"
sudo systemctl stop "$servicio" sudo systemctl restart "$servicio"
sudo systemctl start "$servicio"
else else
echo "start $servicio" echo "Starting and enabling $servicio"
sudo systemctl stop "$servicio"
sudo systemctl start "$servicio" sudo systemctl start "$servicio"
sudo systemctl enable "$servicio" sudo systemctl enable "$servicio"
fi fi
done done
;; ;;
3) 3)
break; # Exit the menu
break
;;
esac esac
done done
exit 0 exit 0
EOF EOF
#
# Make the script executable
chmod +x /bin/menu-ap chmod +x /bin/menu-ap
ln -sf /bin/menu-ap /bin/MENU-AP ln -sf /bin/menu-ap /bin/MENU-AP
chmod +x /bin/MENU* chmod +x /bin/MENU-AP
fi fi