-
Notifications
You must be signed in to change notification settings - Fork 0
/
MakeISO.sh
286 lines (229 loc) · 10.7 KB
/
MakeISO.sh
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#!/bin/sh
### POSIX QEFS ###
### ###
##############################################################################
################## BUILDS A FULL RELEASE IMAGE FOR OPENBSD ###################
##############################################################################
### ###
### This script will build a fully patched ISO for -stable branch with ###
### patched sets. The iso can be burned to a CD and used for installing on ###
### other machines. All compiled code is signed using OPENBSD's signify. ###
### ###
### By Erik Adler aka Onryo. ###
### GPG/PGP key ID: 0x2B4B58FE ###
### ###
##############################################################################
# #
# BSD license #
# Copyright (c) 2017 ERIK ADLER [email protected] #
# aka Onryo #
# GPG/PGP key ID: 0x2B4B58FE #
# #
# Permission to use, copy, modify, and distribute this software for any #
# purpose with or without fee is hereby granted, provided that the above #
# copyright notice and this permission notice appear in all copies. #
# #
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES #
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF #
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR #
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES #
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN #
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF #
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #
# #
##############################################################################
# Supports the following architectures as of 2017: #
# alpha amd64 armv7 hppa i386 landisk IO-DATA loongson luna88k macppc octeon #
# sgi socppc sparc64 #
##############################################################################
# Full path to this script.
# Auto detection is a bad idea.
scriptpath=/home/erik/MakeISO.sh
# Your cvs server of choice.
# Your pkg server of choice.
pkgserver=https://ftp.eu.openbsd.org/pub/OpenBSD
# This is where build ends up
# You can use the path to your home dir
store=/home/erik
# Your name or nick used for the signing
# generated signify keys.
myname='erik adler'
# If you want to compile from ports change
# pkg to 'ports' here.
pkgsort='pkg'
# if a custom kernel should be used.
export NAME=GENERIC.MP
###################################
[ -f "$scriptpath" ] || { printf \
'Enter the correct name and path to this script\n'; exit 1; }
[ "$(id -u)" = 0 ] || { printf 'Must be root to run script\n'; exit 1; }
buildlog=/var/log
bsdver="OPENBSD_$(uname -r | tr . _)"
kernelcomp="$store/compileflag"
cores="$(sysctl hw.ncpufound)"
ver="$(uname -r | tr -d .)"
swapm="$(grep -i swap /etc/fstab)"; swapm="${swapm%% *}"
key="my-openbsd-$(uname -r)-base"
finger="$(ssh-keygen -E MD5 -l -F "${cvsserver#*@}" \
|grep MD5 || echo 'BEING ANALYZED')"
paths="/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin"
export PATH="$paths:/usr/local/bin:/usr/local/sbin"
export PKG_PATH # prevent conditionals, set -e and traps from working
mkdir -p "$store"
mkdir -p "$buildlog/buildlogs"
# Setting the below will enable mfs RAM. This will
# speed up the compile time by mitigating ufs slow IOs.
# Be warned that data can be lost in case of a crash or
# power outage.
if df | grep -q mfs; then
umount "$buildlog/buildlogs"
umount /usr/obj
umount /usr/xobj
fi
mount_mfs -s 300M "$swapm" "$buildlog/buildlogs"
mount_mfs -s 1500M "$swapm" /usr/obj
mount_mfs -s 1500M "$swapm" /usr/xobj
############# KERNEL ##############
if [ ! -f "$kernelcomp" ]; then
rm -f "$buildlog/buildlogs/*"
cd /usr || exit 1;
if [ ! -s src/CVS/Root ]; then
clear && printf '\nRepository in use:\n%s\n\n' "$finger"
printf '%s\n' 'Fingerprints listed: https://www.openbsd.org/anoncvs.html'
printf '%s\n\n' 'Populating local src code tree. Will take some time'
sleep 10
cvs -qd "$cvsserver:/cvs" checkout -r "$bsdver" -P src
else
clear && printf '\nRepository in use:\n%s\n\n' "$finger"
printf '%s\n' 'Fingerprints listed: https://www.openbsd.org/anoncvs.html'
printf '\n%s\n\n' 'Looking for src changes (cvs up). Will take some time'
{ cd src && cvs -d "$cvsserver:/cvs" -q up -r "$bsdver" -Pd; } || exit 1;
fi
cd "/usr/src/sys/arch/$(machine)/conf" || exit 1;
config "$NAME"
cd "/usr/src/sys/arch/$(machine)/compile/$NAME" || exit 1;
make clean
make "-j${cores#*=}" 2>&1 | tee "$buildlog/buildlogs/logfile_1_kernel"
make install
touch "$kernelcomp"
echo "$scriptpath" > /etc/rc.firsttime
mv "$buildlog/buildlogs/logfile_1_kernel" "$store/logfile_1_kernel"
shutdown -r now
exit
else
rm "$kernelcomp"
mv "$store/logfile_1_kernel" "$buildlog/buildlogs/logfile_1_kernel"
fi
grep -rqF '* Error ' "$buildlog/buildlogs/logfile_1_kernel" && exit 1;
############ USERLAND #############
mkdir -p /usr/obj
{ cd /usr/obj && mkdir -p .old; } || exit 1;
touch dot && mv -- * .old && rm -rf .old & ### mv and delete in the background
mkdir -p /usr/src
{ cd /usr/src && make obj; } || exit 1;
cd /usr/src/etc || exit 1;
env DESTDIR=/ make distrib-dirs
cd /usr/src || exit 1;
make "-j${cores#*=}" build 2>&1 | tee "$buildlog/buildlogs/logfile_2_system"
grep -rqF '* Error ' "$buildlog/buildlogs/logfile_2_system" && exit 1;
########## SYSTEM XORG ############
{ cd /usr/xobj && mkdir -p .old; } || exit 1;
touch dot && mv -- * .old && rm -rf .old & ### deletes .old in the background
cd /usr || exit 1;
if [ ! -s xenocara/CVS/Root ]; then
printf '\nRepository in use:\n%s\n\n' "$finger"
printf '%s\n' 'Fingerprints listed: https://www.openbsd.org/anoncvs.html'
printf '%s\n\n' 'Populating local xeno code tree. Will take some time'
cvs -d "$cvsserver:/cvs" checkout -r "$bsdver" -P xenocara
else
printf '\nRepository in use:\n%s\n\n' "$finger"
printf '%s\n' 'Fingerprints listed: https://www.openbsd.org/anoncvs.html'
printf '\n%s\n\n' 'Looking for xeno changes (cvs up). Will take some time'
{ cd xenocara && cvs -d "$cvsserver:/cvs" -q up -r "$bsdver" -Pd; } || exit 1;
fi
cd /usr/xenocara || exit 1;
make bootstrap
make obj
make "-j${cores#*=}" build 2>&1 | tee "$buildlog/buildlogs/logfile_3_xorg"
grep -rqF '* Error ' "$buildlog/buildlogs/logfile_3_xorg" && exit 1;
######## CREATE WORK DIR ##########
export DESTDIR="$store/dest"
export RELEASEDIR="$store/rel"
[ -d "$DESTDIR" ] && mv "$DESTDIR" "$DESTDIR-"
[ -d "$DESTDIR-" ] && rm -rf "$DESTDIR-" &
mkdir -p "$DESTDIR" "$RELEASEDIR"
########## SYSTEM SETS ############
cd /usr/src/etc || exit 1;
make release 2>&1 | tee "$buildlog/buildlogs/logfile_4_build_sys_sets"
grep -rqF '* Error ' "$buildlog/buildlogs/logfile_4_build_sys_sets" && exit 1;
######### XENOCARA SETS ###########
cd /usr/xenocara || exit 1;
make release 2>&1 | tee "$buildlog/buildlogs/logfile_5_build_xeno_sets"
grep -rqF '* Error ' "$buildlog/buildlogs/logfile_5_build_xeno_sets" && exit 1;
###### MAKE RELEASE STRUCTURE #####
cd "$store" || exit 1;
[ -d OpenBSD ] && mv OpenBSD OpenBSD-
[ -d OpenBSD- ] && rm -rf OpenBSD- & ### Delete old dir in background
mkdir "$store/OpenBSD"
mv "$RELEASEDIR" "$(machine)"
mkdir "$(uname -r)"
mv "$(machine)" "$(uname -r)/"
mv "$(uname -r)" OpenBSD/ || exit 1;
########## BUILDING ISO ###########
if [ "$pkgsort" = ports ]; then
cd /usr || exit 1;
if [ ! -s ports/CVS/Root ]; then
printf '\nRepository in use:\n%s\n\n' "$finger"
printf '%s\n' 'Fingerprints listed: https://www.openbsd.org/anoncvs.html'
printf '%s\n\n' 'Populating local port code tree. Will take some time'
cvs -d "$cvsserver:/cvs" checkout -r "$bsdver" -P ports
else
printf '\nRepository in use:\n%s\n\n' "$finger"
printf '%s\n' 'Fingerprints listed: https://www.openbsd.org/anoncvs.html'
printf '\n%s\n\n' 'Looking for ports changes (cvs up). Will take some time'
cd ports || exit 1;
cvs -d "$cvsserver:/cvs" -q up -r "$bsdver" -Pd
fi
cd /usr/ports/sysutils/cdrtools || exit 1;
if /usr/ports/infrastructure/bin/out-of-date | grep -q sysutils/cdrtools; then
make update
printf '\n%s\n\n' 'Found update for cdrtools'
else
make install
fi
else
PKG_PATH="$pkgserver/$(uname -r)/packages/$(machine)"
if ! pkg_info -Q crdtools | grep -q installed; then
pkg_add cdrtools
fi
fi
cd "$store" || exit 1;
mkisofs -r -no-emul-boot -b "$(uname -r)/$(machine)/cdbr" -c boot.catalog -o \
"$store/OpenBSD/$(uname -r)/$(machine)/install${ver}.iso" "$store/OpenBSD"
####### SIGNING CHECKSUMS #########
cd "$store/OpenBSD/$(uname -r)/$(machine)" || exit 1;
[ ! -f SHA256 ] || rm SHA256
sha256 -- * > SHA256
if [ ! -f "/etc/signify/$key.sec" ]; then
printf '\n%s\n\n' 'Generate a private key. Do not forget your password'
signify -G -c "$myname openbsd $(uname -r) base" -p "/etc/signify/$key.pub" \
-s "/etc/signify/$key.sec"
else
printf '\n%s\n\n' 'Using your old private key'
fi
signify -S -s "/etc/signify/$key.sec" -m SHA256 -e -x SHA256.sig
for f in *; do ### avoids using ls -l
[ -e "$f" ] || continue; echo "$f" >> index.txt
done
cp "/etc/signify/$key.pub" "$store/OpenBSD/"
####### CHECKING BUILD LOGS #######
printf '\n%s\n\n' 'CHECKING BUILD LOGS FOR ERRORS'
if grep -rF '* Error ' $buildlog/buildlogs/; then
printf '%s\n\n' 'Try deleting src xenocara src and ports. Run script again.'
printf '%s\n\n' 'CVS source code could be corrupt. Are paths set correctly?'
else
v=$(sysctl -n kern.version); v=${v#* }; v=${v%% *}
printf '%s\n\n' 'NO ERRORS FOUND IN BUILD LOGS'
printf 'YOU ARE TRACKING %s\n\n' "$v"
fi