distribution/packages/jelos/sources/scripts/wifictl
fewtarius 93a109ae93
* Fix get_setting to return the system setting if it exists but no game setting exists.
* Disable WIFI power save.
* Ensure the WIFI connection is refreshed on startup using wifictl.
2022-04-08 20:08:14 -04:00

54 lines
1.1 KiB
Bash
Executable file

#!/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}
[service_${OS_NAME}_default]
Type=wifi
Name=${SSID}
Passphrase=${PSK}
EOF
connmanctl enable wifi 2>/dev/null
iw wlan0 set power_save off 2>/dev/null
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")
connmanctl services | cut -b 5- | awk '/wifi/ {sub(/\s+wifi_.*$/,"",$0);print}' | sort | uniq
;;
"scan")
connmanctl scan 2>/dev/null
;;
"scanlist")
set_wifi scan 2>/dev/null
set_wifi list 2>/dev/null
;;
esac
}
if [ ! -d "" ]
then
mkdir -p "/storage/.cache/connman"
fi
set_wifi ${COMMAND}