2
0
mirror of https://github.com/koreader/koreader synced 2024-11-13 19:11:25 +00:00
koreader/platform/cervantes/restore-wifi-async.sh

32 lines
937 B
Bash
Executable File

#!/bin/sh
RunWpaCli() {
./luajit <<EOF
require("setupkoenv")
local DataStorage = require("datastorage")
local LuaSettings = require("luasettings")
local settings = LuaSettings:open(DataStorage:getSettingsDir().."/network.lua")
local cli = io.popen("wpa_cli -g /var/run/wpa_supplicant/eth0 > /dev/null", "w")
local idx = 0
for ssid, network in pairs(settings.data) do
cli:write("add_network\n")
cli:write("set_network " .. tostring(idx) .. " ssid \"" .. ssid .. "\"\n")
cli:write("set_network " .. tostring(idx) .. " psk \"" .. network["password"] .. "\"\n")
cli:write("enable_network " .. tostring(idx) .. "\n")
idx = idx + 1
end
cli:close()
EOF
}
RestoreWifi() {
echo "[$(date)] restore-wifi-async.sh: Restarting WiFi"
./enable-wifi.sh
RunWpaCli
./obtain-ip.sh
echo "[$(date)] restore-wifi-async.sh: Restarted WiFi"
}
RestoreWifi &