Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- set -e
- set -o pipefail
- shopt -s lastpipe
- name="ap0"
- ssid="AP Test"
- psk="Hello world!"
- # security config
- proto='WPA2'
- key_mgmt='WPA-PSK'
- group='CCMP'
- pairwise='CCMP'
- # note: in north america use channel 1, 6, or 11
- # in most other countries use channel 1, 5, 9, or 13
- channel=1
- die() {
- echo "$*" >&2
- exit 1
- }
- dbus-do() {
- local interface="$1" path="$2" action="$3"; shift 3
- set -- busctl "$action" fi.w1.wpa_supplicant1 "$path" "$interface" "$@"
- #echo "DEBUG: $*" >/dev/tty
- "$@"
- }
- manager() {
- dbus-do fi.w1.wpa_supplicant1 /fi/w1/wpa_supplicant1 "$@"
- }
- interface() {
- dbus-do fi.w1.wpa_supplicant1.Interface "$@"
- }
- parse-obj() {
- read t x
- [[ "$t" == o && "$x" == \"/*\" ]] || die "Expecting object return value, received: $t $x"
- echo "${x:1:-1}"
- }
- config=(
- mode u 2
- ssid s "$ssid"
- psk s "$psk"
- proto s "$proto"
- key_mgmt s "$key_mgmt"
- group s "$group"
- pairwise s "$pairwise"
- frequency u $(( 2412 + ($channel - 1) * 5 ))
- )
- {
- manager call GetInterface 's' "$name" 2>/dev/null || \
- manager call CreateInterface 'a{sv}' 1 Ifname s "$name"
- } | parse-obj | read intf
- interface $intf call RemoveAllNetworks
- if [[ "$1" == '--disable' ]]; then
- echo "Access point disabled"
- exit 0
- fi
- # some sources include this but it gives a warning:
- #interface $intf set-property ApScan 'u' 2
- interface $intf call AddNetwork 'a{sv}' $(( ${#config[@]} / 3 )) "${config[@]}" | parse-obj | read net
- interface $intf call SelectNetwork 'o' $net
- echo "Access point enabled"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement