-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhotspot.sh
More file actions
executable file
·50 lines (40 loc) · 1.38 KB
/
Copy pathhotspot.sh
File metadata and controls
executable file
·50 lines (40 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
# Defaults
DEFAULT_SSID="Mustang's ap"
DEFAULT_PASS="mustangpassword"
# Detect Wi-Fi interface (ignore p2p devices)
IFACE=$(nmcli -t -f DEVICE,TYPE device | grep ":wifi" | cut -d: -f1 | grep -v "p2p")
if [ -z "$IFACE" ]; then
notify-send "Hotspot Error" "No Wi-Fi device found!"
exit 1
fi
# Check if hotspot is already active
if nmcli -t -f NAME,TYPE,DEVICE connection show --active | grep -q "Hotspot:"; then
nmcli connection down Hotspot
notify-send "Hotspot" "Turned OFF"
exit 0
fi
# Ask SSID
SSID=$(echo "" | dmenu -p "Enter SSID (default: $DEFAULT_SSID):")
if [ -z "$SSID" ]; then
SSID="$DEFAULT_SSID"
fi
# Ask Password
PASS=$(echo "" | dmenu -p "Enter password (default: $DEFAULT_PASS):")
if [ -z "$PASS" ]; then
PASS="$DEFAULT_PASS"
fi
# Ensure Wi-Fi is on
nmcli radio wifi on
# Delete old Hotspot connection if exists
nmcli connection delete Hotspot 2>/dev/null
# Create hotspot with better compatibility
nmcli device wifi hotspot ifname "$IFACE" con-name Hotspot ssid "$SSID" password "$PASS"
# Modify to ensure internet sharing
nmcli connection modify Hotspot ipv4.method shared
nmcli connection modify Hotspot 802-11-wireless.band bg
nmcli connection modify Hotspot 802-11-wireless.channel 6
# Restart the connection
nmcli connection down Hotspot 2>/dev/null
nmcli connection up Hotspot
notify-send "Hotspot" "Started SSID: $SSID with internet sharing"