2022-02-06 16:39:01 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
# Copyright (C) 2020 Fewtarius (https://github.com/fewtarius)
|
|
|
|
|
|
|
|
. /etc/profile
|
|
|
|
|
|
|
|
COMMAND="$1"
|
|
|
|
SSID="$(get_setting wifi.ssid)" 2>/dev/null
|
|
|
|
PSK="$(get_setting wifi.key)" 2>/dev/null
|
|
|
|
WIFICFG="/storage/.cache/connman/wifi.config"
|
|
|
|
|
|
|
|
set_wifi() {
|
|
|
|
case "${1}" in
|
|
|
|
"enable")
|
|
|
|
set_setting wifi.enabled 1
|
|
|
|
# Create the WIFI config.
|
|
|
|
cat > "${WIFICFG}" <<EOF
|
|
|
|
[global]
|
|
|
|
Name=${OS_NAME}
|
|
|
|
|
2022-02-06 17:02:58 +00:00
|
|
|
[service_${OS_NAME}_default]
|
2022-02-06 16:39:01 +00:00
|
|
|
Type=wifi
|
|
|
|
Name=${SSID}
|
2022-02-06 17:02:58 +00:00
|
|
|
Passphrase=${PSK}
|
2022-02-06 16:39:01 +00:00
|
|
|
EOF
|
|
|
|
|
|
|
|
connmanctl enable wifi 2>/dev/null
|
2022-04-09 00:08:14 +00:00
|
|
|
iw wlan0 set power_save off 2>/dev/null
|
2022-02-06 16:39:01 +00:00
|
|
|
connmanctl scan wifi 2>/dev/null
|
|
|
|
;;
|
|
|
|
"disable")
|
|
|
|
connmanctl disable wifi 2>/dev/null
|
|
|
|
rm -f "${WIFICFG}" 2>/dev/null
|
|
|
|
set_setting wifi.enabled 0
|
|
|
|
;;
|
|
|
|
"list")
|
2022-02-25 15:40:03 +00:00
|
|
|
connmanctl services | cut -b 5- | awk '/wifi/ {sub(/\s+wifi_.*$/,"",$0);print}' | sort | uniq
|
2022-02-06 16:39:01 +00:00
|
|
|
;;
|
2022-02-06 17:02:58 +00:00
|
|
|
"scan")
|
|
|
|
connmanctl scan 2>/dev/null
|
|
|
|
;;
|
|
|
|
"scanlist")
|
|
|
|
set_wifi scan 2>/dev/null
|
|
|
|
set_wifi list 2>/dev/null
|
|
|
|
;;
|
2022-02-06 16:39:01 +00:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ ! -d "" ]
|
|
|
|
then
|
|
|
|
mkdir -p "/storage/.cache/connman"
|
|
|
|
fi
|
|
|
|
|
|
|
|
set_wifi ${COMMAND}
|