feat: nmcli shell

This commit is contained in:
hesam-init 2024-03-28 12:04:31 +03:30
parent b06c02940e
commit 3fee9a288c
2 changed files with 46 additions and 0 deletions

View file

@ -0,0 +1,26 @@
#!/bin/bash
source ~/.scripts/utils/main.sh
list_wifi_networks() {
echo "Available Wi-Fi Networks:"
nmcli dev wifi list
}
connect_to_wifi() {
echo "Enter the name (SSID) of the Wi-Fi network you want to connect to:"
read ssid
echo "Enter the password for the Wi-Fi network:"
read -s password
sudo nmcli dev wifi connect "$ssid" password "$password"
}
list_wifi_networks
if ask_prompt "Do you want to connect to a Wi-Fi network ?"; then
connect_to_wifi
else
echo "No network connection requested. Exiting."
fi

View file

@ -0,0 +1,20 @@
#!/bin/bash
check_sudo() {
if [ "$(id -u)" != 0 ]; then
echo "Please run the script with sudo."
exit 1
fi
}
ask_prompt() {
local question="$1"
while true; do
read -p "$question (Y/N): " choice
case "$choice" in
[Yy]) return 0 ;;
[Nn]) return 1 ;;
*) echo "Please enter Y or N." ;;
esac
done
}