-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (40 loc) · 1.02 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"log"
"os"
)
func enable_ssh(base string) {
var ssh_file, err = os.Create(base + "ssh")
if err != nil {
log.Fatalf("Error: %v", err)
}
defer ssh_file.Close()
log.Println("SSH enabled")
}
func enable_wifi(base string, ssid string, password string) {
var wifi_file, err = os.Create(base + "wpa_supplicant.conf")
if err != nil {
log.Fatalf("Error: %v", err)
}
data := []byte(`update_config=1
ctrl_interface=/var/run/wpa_supplicant
network={
ssid="` + ssid + `"
psk="` + password + `"
}`)
_, err = wifi_file.Write(data)
defer wifi_file.Close()
log.Printf("Wifi enabled. The device will connect to %v\n", ssid)
}
func main() {
// Check if arguments are correctly passed
if len(os.Args) != 4 {
log.Fatalln("Please use three arguments in the correct order, see README.md")
}
baseDirectory := os.Args[1]
ssid := os.Args[2]
ssid_password := os.Args[3]
log.Printf("The boot directory to use is: %v\n", baseDirectory)
enable_ssh(baseDirectory)
enable_wifi(baseDirectory, ssid, ssid_password)
}