#!/bin/bash # SPDX-License-Identifier: Apache-2.0 # Copyright (C) 2020 Fewtarius (https://github.com/fewtarius) . /etc/profile COMMAND="$1" ### ES won't save the configuration in time ### for it to be useable by the script, so ### we have to accept the ssid and key on the ### command line too. if [ ! -z "${2}" ] then SSID="${2}" else SSID="$(get_setting wifi.ssid)" 2>/dev/null fi if [ ! -z "${3}" ] then PSK="${3}" else PSK="$(get_setting wifi.key)" 2>/dev/null fi WIFICFG="/storage/.cache/connman/wifi.config" set_powersave() { ENABLED=$(get_setting wifi.powersave) if [ "${ENABLED}" = "1" ] then iw wlan0 set power_save on else iw wlan0 set power_save off fi } set_wifi() { case "${1}" in "enable") set_setting wifi.enabled 1 # Create the WIFI config. cat > "${WIFICFG}" </dev/null set_powersave 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 ;; "setpowersave") set_powersave 2>/dev/null ;; esac } if [ ! -d "" ] then mkdir -p "/storage/.cache/connman" fi set_wifi ${COMMAND}