pinebook-tests/connect-to-wifi/main.go

51 lines
1019 B
Go

package main
// import "os"
import "log"
import "time"
import "fmt"
import "os"
/*
import "reflect"
*/
import "git.wit.com/jcarr/shell"
func dhclient() {
shell.Run("systemctl stop NetworkManager.service")
shell.Run("systemctl disable NetworkManager.service")
shell.Run("systemctl stop wpa_supplicant.service")
go shell.Daemon("wpa_supplicant -D wext -i wlan0 -c /etc/wpa_supplicant.conf", 1000 * time.Millisecond)
log.Println("wait for wpa_supplicant, then run dhclient")
shell.Run("sleep 20")
shell.Run("dhclient wlan0")
for {
fmt.Println(" running")
time.Sleep(2000 * time.Millisecond)
filename := "/tmp/wit-install-done"
if _, err := os.Stat(filename); !os.IsNotExist(err) {
log.Println("filename", filename, "does exist")
return
}
}
}
func main() {
parseConfig()
go dhclient()
for {
time.Sleep(1000 * time.Millisecond)
ping := shell.Run("ping -c 1 git.wit.com")
log.Println("ping returned ", ping)
if (ping == 0) {
break
}
}
shell.Run("/root/go/bin/get-image")
}