Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- TEMPFILE=$(mktemp /tmp/wifi_config.XXXXXX)
- function connect_to_wifi() {
- wpa_passphrase "$SSID" "$PASSPHRASE" > /etc/wpa_supplicant/wpa_supplicant.conf
- wpa_supplicant -B -i "$INTERFACE" -c /etc/wpa_supplicant/wpa_supplicant.conf
- dhclient "$INTERFACE"
- }
- function display_form() {
- dialog --title "WiFi Connection" \
- --form "Enter WiFi SSID and passphrase" \
- 10 50 0 \
- "SSID:" 1 1 "$SSID" 1 20 30 0 \
- "Passphrase:" 2 1 "$PASSPHRASE" 2 20 30 0 \
- 2> "$TEMPFILE"
- SSID=$(sed -n 1p "$TEMPFILE")
- PASSPHRASE=$(sed -n 2p "$TEMPFILE")
- }
- # Entry Point..
- function main() {
- # Default values, Change to your values
- INTERFACE="<your_interface>"
- SSID=""
- PASSPHRASE=""
- # Display the form
- display_form
- # Check if the user pressed OK or Cancel
- case $? in
- 0) # OK button pressed
- connect_to_wifi
- dialog --title "Success" --msgbox "Connected to WiFi!" 8 30
- ;;
- 1) # Cancel button pressed
- dialog --title "Cancelled" --msgbox "Operation cancelled." 8 30
- ;;
- 255) # Escape key pressed or dialog closed
- dialog --title "Cancelled" --msgbox "Operation cancelled." 8 30
- ;;
- esac
- # Clean up temporary files
- rm -f "$TEMPFILE"
- }
- main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement