@@ -14,6 +14,9 @@ readonly SNAPSHOT=false
14
14
readonly ARCH=" ${ARCH:- amd64} "
15
15
readonly MIRROR=" ${MIRROR:- cdn.openbsd.org} "
16
16
17
+ readonly WORK=" $( mktemp -d) "
18
+ readonly SITE=" ${WORK} /site"
19
+
17
20
if [[ " ${ARCH} " != " amd64" && " ${ARCH} " != " i386" ]]; then
18
21
echo " ARCH must be amd64 or i386"
19
22
exit 1
@@ -31,45 +34,48 @@ if [[ ! -f "${ISO}" ]]; then
31
34
fi
32
35
33
36
function cleanup() {
34
- rm -f " ${ISO_PATCHED} "
35
- rm -f auto_install.conf
36
- rm -f boot.conf
37
- rm -f disk.raw
38
- rm -f disklabel.template
39
- rm -f etc/{installurl,rc.local,sysctl.conf}
40
- rm -f install.site
41
- rm -f random.seed
42
- rm -f site${RELNO} .tgz
43
- rmdir etc
37
+ rm -rf " ${WORK} "
44
38
}
45
39
46
40
trap cleanup EXIT INT
47
41
48
42
# Create custom siteXX.tgz set.
49
- PKG_ADD_OPTIONS=" "
43
+ PKG_ADD_OPTIONS=" -I "
50
44
if [[ " $SNAPSHOT " = true ]]; then
51
- PKG_ADD_OPTIONS=" -D snap"
45
+ PKG_ADD_OPTIONS=" -I - D snap"
52
46
fi
53
- mkdir -p etc
54
- cat > install.site << EOF
47
+ mkdir -p ${SITE} / etc
48
+ cat > ${SITE} / install.site << EOF
55
49
#!/bin/sh
56
50
touch /firstboot
57
51
echo 'set tty com0' > boot.conf
58
52
EOF
59
53
60
- cat > etc/installurl << EOF
54
+ cat > ${SITE} / etc/installurl << EOF
61
55
https://${MIRROR} /pub/OpenBSD
62
56
EOF
63
- cat > etc/rc.local << EOF
64
- if [[ -f /firstboot ]]; then
65
- syspatch
66
- # Run syspatch twice in case syspatch itself needs patching (this is the case with OpenBSD
67
- # 7.1: https://www.openbsd.org/errata71.html )
68
- syspatch
69
- pkg_add -iv ${PKG_ADD_OPTIONS} bash curl git
70
- rm -f /firstboot
71
- fi
57
+ cat > ${SITE} /etc/rc.firsttime << EOF
58
+ set -x
59
+ cat > /etc/login.conf.d/moreres <<'EOLOGIN'
60
+ moreres:\
61
+ :maxproc-max=1024: \
62
+ :maxproc-cur=1024: \
63
+ :openfiles-max=4096: \
64
+ :openfiles-cur=4096: \
65
+ :tc=default:
66
+ EOLOGIN
67
+ cap_mkdb
68
+ usermod -L moreres swarming
69
+ syspatch
70
+ # Run syspatch twice in case syspatch itself needs patching (this is the case with OpenBSD
71
+ # 7.1: https://www.openbsd.org/errata71.html )
72
+ syspatch
73
+ pkg_add -iv ${PKG_ADD_OPTIONS} bash curl git python3 sudo--gettext
74
+ chown root:wheel /etc/sudoers
75
+ halt -p
76
+ EOF
72
77
78
+ cat > ${SITE} /etc/rc.local << EOF
73
79
(
74
80
set -x
75
81
83
89
(
84
90
set -e
85
91
export PATH="\$ PATH:/usr/local/bin"
86
- /usr/local/bin/curl -o /buildlet \$ (/usr/local/bin/curl --fail -H "Metadata-Flavor: Google" http://metadata.google.internal/computeMetadata/v1/instance/attributes/buildlet-binary-url)
87
- chmod +x /buildlet
88
- exec /buildlet
92
+ project=\$ (curl -s -H "Metadata-Flavor: Google" http://metadata.google.internal/computeMetadata/v1/project/project-id)
93
+ case "\$ project" in
94
+ *luci*)
95
+ gcehost=\$ (curl -s -H "Metadata-Flavor: Google" http://metadata.google.internal/computeMetadata/v1/instance/hostname | cut -d . -f 1)
96
+ su -l swarming -c "/usr/local/bin/bootstrapswarm --hostname \$ gcehost"
97
+ ;;
98
+ *)
99
+ /usr/local/bin/curl -o /buildlet \$ (/usr/local/bin/curl --fail -H "Metadata-Flavor: Google" http://metadata.google.internal/computeMetadata/v1/instance/attributes/buildlet-binary-url)
100
+ chmod +x /buildlet
101
+ exec /buildlet
102
+ ;;
103
+ esac
89
104
)
90
105
echo "giving up"
91
106
(
92
- sleep 10
107
+ sleep 60
93
108
halt -p
94
109
)&
95
110
)
96
111
EOF
97
- cat > etc/sysctl.conf << EOF
112
+ cat > ${SITE} / etc/sysctl.conf << EOF
98
113
hw.smt=1
99
114
kern.timecounter.hardware=tsc
100
115
EOF
101
- chmod +x install.site
102
- tar -zcvf site${RELNO} .tgz install.site etc/{installurl,rc.local,sysctl.conf}
116
+ cat > ${SITE} /etc/sudoers << EOF
117
+ root ALL=(ALL:ALL) ALL
118
+ swarming ALL=NOPASSWD:/sbin/shutdown -r now
119
+ EOF
120
+ chmod +x ${SITE} /install.site
121
+ mkdir -p ${SITE} /usr/local/bin
122
+ CGO_ENABLED=0 GOOS=openbsd GOARCH=amd64 go1.21.0 build -o ${SITE} /usr/local/bin/bootstrapswarm golang.org/x/build/cmd/bootstrapswarm
123
+ tar -C ${SITE} -zcf ${WORK} /site${RELNO} .tgz .
103
124
104
125
# Autoinstall script.
105
- cat > auto_install.conf << EOF
106
- System hostname = buildlet
126
+ cat > ${WORK} / auto_install.conf << EOF
127
+ System hostname = openbsd-amd64
107
128
Which network interface = vio0
108
129
IPv4 address for vio0 = dhcp
109
130
IPv6 address for vio0 = none
110
131
Password for root account = root
111
132
Do you expect to run the X Window System = no
112
133
Change the default console to com0 = yes
113
134
Which speed should com0 use = 115200
114
- Setup a user = gopher
115
- Full name for user gopher = Gopher Gopherson
116
- Password for user gopher = gopher
135
+ Setup a user = swarming
136
+ Full name for user swarming = Swarming Gopher Gopherson
137
+ Password for user swarming = swarming
117
138
Allow root ssh login = no
118
139
What timezone = US/Pacific
119
140
Which disk = sd0
@@ -126,32 +147,32 @@ Directory does not contain SHA256.sig. Continue without verification = yes
126
147
EOF
127
148
128
149
# Disklabel template.
129
- cat > disklabel.template << EOF
150
+ cat > ${WORK} / disklabel.template << EOF
130
151
/ 5G-* 95%
131
152
swap 1G
132
153
EOF
133
154
134
155
# Hack install CD a bit.
135
- echo ' set tty com0' > boot.conf
136
- dd if=/dev/urandom of=random.seed bs=4096 count=1
156
+ echo ' set tty com0' > ${WORK} / boot.conf
157
+ dd if=/dev/urandom of=${WORK} / random.seed bs=4096 count=1
137
158
cp " ${ISO} " " ${ISO_PATCHED} "
138
159
growisofs -M " ${ISO_PATCHED} " -l -R -graft-points \
139
- /${VERSION} /${ARCH} /site${RELNO} .tgz=site${RELNO} .tgz \
140
- /auto_install.conf=auto_install.conf \
141
- /disklabel.template=disklabel.template \
142
- /etc/boot.conf=boot.conf \
143
- /etc/random.seed=random.seed
160
+ /${VERSION} /${ARCH} /site${RELNO} .tgz=${WORK} / site${RELNO} .tgz \
161
+ /auto_install.conf=${WORK} / auto_install.conf \
162
+ /disklabel.template=${WORK} / disklabel.template \
163
+ /etc/boot.conf=${WORK} / boot.conf \
164
+ /etc/random.seed=${WORK} / random.seed
144
165
145
166
# Initialize disk image.
146
- rm -f disk.raw
147
- qemu-img create -f raw disk.raw 10G
167
+ rm -f ${WORK} / disk.raw
168
+ qemu-img create -f raw ${WORK} / disk.raw 30G
148
169
149
170
# Run the installer to create the disk image.
150
171
expect << EOF
151
172
set timeout 1800
152
173
153
174
spawn qemu-system-x86_64 -nographic -smp 2 \
154
- -drive if=virtio,file=disk.raw,format=raw -cdrom "${ISO_PATCHED} " \
175
+ -drive if=virtio,file=${WORK} / disk.raw,format=raw -cdrom "${ISO_PATCHED} " \
155
176
-net nic,model=virtio -net user -boot once=d
156
177
157
178
expect timeout { exit 1 } "boot>"
174
195
175
196
# Create Compute Engine disk image.
176
197
echo " Archiving disk.raw... (this may take a while)"
177
- tar -Szcf " openbsd-${VERSION} -${ARCH} -gce.tar.gz" disk.raw
198
+ tar -C ${WORK} - Szcf " openbsd-${VERSION} -${ARCH} -gce.tar.gz" disk.raw
178
199
179
200
echo " Done. GCE image is openbsd-${VERSION} -${ARCH} -gce.tar.gz."
0 commit comments