emq-TE1/menu/menu-ap

66 lines
1.9 KiB
Bash

#!/bin/bash
# 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"
#!/bin/bash
while : ; do
choix=$(whiptail --title "WiFi auto AP option" --menu "Select enable or disable auto AP mode." 20 75 11 \
1 "Disable auto AP mode" \
2 "Enable auto AP mode" \
3 "Menu Principal" 3>&1 1>&2 2>&3)
exitstatus=$?
# Check if the user selected an option
if [ $exitstatus = 0 ]; then
echo "Your chosen option:" $choix
else
echo "You chose cancel."
break
fi
# Perform actions based on user choice
case $choix in
1)
# Disable auto AP mode
servicios=("autoap.service")
for servicio in "${servicios[@]}"; do
if systemctl is-enabled "$servicio" >/dev/null 2>&1; then
echo "Disabling $servicio"
sudo systemctl disable "$servicio"
sudo systemctl stop "$servicio"
fi
done
;;
2)
# Enable auto AP mode
servicios=("autoap.service")
for servicio in "${servicios[@]}"; do
if systemctl is-enabled "$servicio" >/dev/null 2>&1; then
echo "Restarting $servicio"
sudo systemctl restart "$servicio"
else
echo "Starting and enabling $servicio"
sudo systemctl start "$servicio"
sudo systemctl enable "$servicio"
fi
done
;;
3)
# Exit the menu
break
;;
esac
done
exit 0
EOF
# Make the script executable
chmod +x /bin/menu-ap
ln -sf /bin/menu-ap /bin/MENU-AP
chmod +x /bin/MENU-AP
fi