-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
create-image
executable file
·104 lines (85 loc) · 2.16 KB
/
create-image
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/expect --
set timeout -1
proc slurp {file} {
set fh [open $file r]
set ret [read $fh]
close $fh
return $ret
}
if { $argc == 1 } {
set imageName [lindex $argv 0]
set 64bit "false"
puts "32bit"
} elseif { $argc == 2 } {
set imageName [lindex $argv 1]
set 64bit "true"
puts "64bit"
}
if {[string trimleft $imageName] eq ""} {
puts "No Image file provided"
exit
}
set cwd [file normalize [file dirname $argv0]]
set imagePath [file join $cwd $imageName]
puts $imageName
puts $imagePath\n
if { $64bit == "true" } {
spawn docker run --name dockerpi -it --rm -v $imagePath:/sdcard/filesystem.img lukechilds/dockerpi:vm pi3
} else {
spawn docker run --name dockerpi -it --rm -v $imagePath:/sdcard/filesystem.img lukechilds/dockerpi:vm
}
expect "raspberrypi login: "
send "pi\n"
expect "Password: "
#send "raspberry\n"
send $env(PASSWORD)
send "\n"
expect "$ "
send "sudo apt-get update\n"
expect "$ "
send "sudo apt-get -y install dnsmasq\n"
expect "$ "
send "sudo apt-get clean\n"
expect "$ "
send "sudo su -\n"
set file [slurp "etc/dnsmasq.d/usb0"]
expect "# "
send "cat <<EOF >> /etc/dnsmasq.d/usb0\n"
send "$file\n"
send "EOF\n"
set file [slurp "etc/network/interfaces.d/usb0"]
expect "# "
send "cat <<EOF >> /etc/network/interfaces.d/usb0\n"
send "$file\n"
send "EOF\n"
set file [slurp "usr/local/sbin/usb-gadget.sh"]
expect "# "
send "cat <<EOF >> /usr/local/sbin/usb-gadget.sh\n"
send "$file\n"
send "EOF\n"
expect "# "
send "chmod +x /usr/local/sbin/usb-gadget.sh\n"
set file [slurp "lib/systemd/system/usbgadget.service"]
expect "# "
send "cat <<EOF >> /lib/systemd/system/usbgadget.service\n"
send "$file\n"
send "EOF\n"
expect "# "
send "systemctl enable usbgadget.service\n"
expect "# "
send "echo dtoverlay=dwc2 >> /boot/config.txt\n"
expect "# "
send "sed -i 's/$/ modules-load=dwc2/' /boot/cmdline.txt \n"
expect "# "
send "touch /boot/ssh\n"
expect "# "
send "echo libcomposite >> /etc/modules\n"
expect "# "
send "echo denyinterfaces usb0 usb1 br0 >> /etc/dhcpcd.conf\n"
expect "# "
send "sudo systemctl enable [email protected]\n"
expect "# "
send "poweroff\n"
expect "Reboot failed -- System halted"
exec docker stop dockerpi
exit