-
Notifications
You must be signed in to change notification settings - Fork 1
/
mkdistrib
executable file
·275 lines (246 loc) · 9.9 KB
/
mkdistrib
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
#!/usr/bin/env bash
#
# Script to prepare source code and binary distribution files of rEFInd.
# Copyright Rod Smith, 2012-2024
# Licensed under the terms of the GNU GPL-3
#
# Updated 11/8/2012 to do more things automatically
# Updated 12/6/2012 to sign binaries with the rEFInd MOK
# Updated 12/3/2015 to independently compile .zip, RPM, and Debian packages
#
# Usage: ./mkdistrib [--nosign] [--norpm] [--nodebian] [--nozip] version
# where "version" is a version number.
#
# Build requirements:
# * Zip: x86-64 system with TianoCore configured for IA32, X64, and
# AARCH builds ("TARGET_ARCH = IA32 X64 AARCH64" in Conf/target.txt)
# * RPM: System with TianoCore or GNU-EFI of same CPU type as desired
# target architecture. (Tested only on X64/x86-64.)
# * Debian: System with GNU-EFI of same CPU type as desired target
# architecture.
# * MOK files: Used for zip and RPM builds; not used for building
# Debian packages. Must be mounted at /mnt/refind via /etc/fstab
# entry, unless --nosign is specified, in which case binaries are
# not signed. Only X64 binaries are signed.
SignIt=1
MakeRpm=1
MakeDebian=1
MakeZip=1
KeysDir=/mnt/refind
KeysInfo=$(df $KeysDir 2> /dev/null | grep $KeysDir)
StartDir=$(pwd)
SBSign=$(command -v sbsign 2> /dev/null)
ShowUsage() {
echo "Usage:"
echo "$0 [--nosign] [--norpm] [--nodebian] [--nozip] version"
exit
}
GetParams() {
while [[ $# -gt 0 ]]; do
echo "$1"
case "$1" in
--nosign) SignIt=0
;;
--norpm) MakeRpm=0
;;
--nodebian) MakeDebian=0
;;
--nozip) MakeZip=0
;;
--help) ShowUsage "$0"
;;
* ) Version=$1
esac
shift
done
if [[ -z "$Version" ]] ; then
ShowUsage "$0"
fi
} # GetParams()
# Copy rEFInd source files to refind-"$Version" inside "$TargetDir" directory
# and create a tarball from refind-"$Version". Both the tarball and the
# source directory are left in "$TargetDir" when this function finishes, and
# "$TargetDir" is the current directory at the end.
MakeTarball() {
# Prepare a place and copy files there....
mkdir -p "$TargetDir"/refind-"$Version"/icons/licenses "$TargetDir"/refind-"$Version"/icons/svg
cp --preserve=timestamps icons/*png icons/README "$TargetDir"/refind-"$Version"/icons/
cp --preserve=timestamps -r icons/licenses/* "$TargetDir"/refind-"$Version"/icons/licenses/
cp --preserve=timestamps -r icons/svg/* "$TargetDir"/refind-"$Version"/icons/svg/
cp -a debian docs images keys fonts banners include EfiLib libeg gzip mok net refind filesystems \
gptsync refind.spec refind-install refind-mkdefault mkrlconf \
mvrefind refind-sb-healthcheck mountesp CREDITS.txt \
NEWS.txt BUILDING.txt COPYING.txt LICENSE.txt README.txt refind.inf gptsync.inf \
Make.common Makefile refind.conf-sample RefindPkg.d?? refind-sbat.csv refind-sbat-local.csv \
"$TargetDir"/refind-"$Version"
# Go there and prepare a souce code tarball....
cd "$TargetDir"
rm -f refind-src-"$Version".tar.gz
tar cvf refind-src-"$Version".tar refind-"$Version"
gzip -9 refind-src-"$Version".tar
# Remove SVG files, since they aren't needed for binary packages....
rm -rf refind-"$Version"/icons/svg
} # MakeTarball()
# Create two .zip packages containing the full binary builds of rEFInd for three
# platforms -- IA32, X64, and AARCH64. One binary is the regular build and the
# second is the same as the first but substitutes refind_x64.efi build with
# GNU-EFI for the usual TianoCore build. (This is to provide an alternative for
# those rare cases when the TianoCore build fails.) The X64 binaries are signed
# with my key *IF* --nosign is not specified and if the key is available.
MakeZipBinary() {
cd "$TargetDir"/refind-"$Version"
# Build the ARM64 binaries
ARCH=aarch64 make -j1
ARCH=aarch64 make fs
mkdir -p refind-bin-"$Version"/refind/drivers_aa64
cp --preserve=timestamps drivers_aa64/*_aa64.efi refind-bin-"$Version"/refind/drivers_aa64/
cp --preserve=timestamps filesystems/LICENSE*txt refind-bin-"$Version"/refind/drivers_aa64/
cp refind/refind_aa64.efi refind-bin-"$Version"/refind/refind_aa64.efi
cp refind/refind_aa64.efi "$StartDir"/
mkdir -p refind-bin-"$Version"/refind/tools_aa64
# Don't copy gptsync_aa64.efi because it won't build in cross-compile environment
# and because it's likely to be useless on ARM64.
# Build the IA32 binaries
make clean
ARCH=ia32 make -j1
ARCH=ia32 make fs
mkdir -p refind-bin-"$Version"/refind/drivers_ia32
cp --preserve=timestamps drivers_ia32/*_ia32.efi refind-bin-"$Version"/refind/drivers_ia32/
cp --preserve=timestamps filesystems/LICENSE*txt refind-bin-"$Version"/refind/drivers_ia32/
cp refind/refind_ia32.efi refind-bin-"$Version"/refind/refind_ia32.efi
cp refind/refind_ia32.efi "$StartDir"/
mkdir -p refind-bin-"$Version"/refind/tools_ia32
cp --preserve=timestamps gptsync/gptsync_ia32.efi refind-bin-"$Version"/refind/tools_ia32/
# Build the X64 binaries
make clean
make -j1
make fs
mkdir -p refind-bin-"$Version"/refind/drivers_x64
cp -a icons refind-bin-"$Version"/refind/
if [[ $SignIt == 1 ]] ; then
for File in drivers_x64/*_x64.efi ; do
$SBSign --key "$KeysDir"/refind.key --cert "$KeysDir"/refind.crt \
--output refind-bin-"$Version"/refind/"$File" "$File"
done
else
cp --preserve=timestamps drivers_x64/*_x64.efi refind-bin-"$Version"/refind/drivers_x64/
fi
cp --preserve=timestamps filesystems/LICENSE*txt refind-bin-"$Version"/refind/drivers_x64/
cp --preserve=timestamps refind.conf-sample refind-bin-"$Version"/refind/
if [[ $SignIt == 1 ]] ; then
"$SBSign" --key "$KeysDir"/refind.key --cert "$KeysDir"/refind.crt \
--output refind-bin-"$Version"/refind/refind_x64.efi refind/refind_x64.efi
else
cp refind/refind_x64.efi refind-bin-"$Version"/refind/refind_x64.efi
fi
mkdir -p refind-bin-"$Version"/refind/tools_x64
if [[ $SignIt == 1 ]] ; then
$SBSign --key "$KeysDir"/refind.key --cert "$KeysDir"/refind.crt \
--output refind-bin-"$Version"/refind/tools_x64/gptsync_x64.efi gptsync/gptsync_x64.efi
else
cp --preserve=timestamps gptsync/gptsync_x64.efi refind-bin-"$Version"/refind/tools_x64/
fi
cp refind-bin-"$Version"/refind/refind_x64.efi "$StartDir"
cp -a docs keys banners fonts COPYING.txt LICENSE.txt README.txt CREDITS.txt NEWS.txt refind-install \
refind-mkdefault refind-sb-healthcheck mkrlconf mvrefind mountesp refind-bin-"$Version"
# Prepare the final .zip file
zip -9r ../refind-bin-"$Version".zip refind-bin-"$Version"
# Prepare a variant with the x86-64 version built with GNU-EFI....
make clean
make -j1 gnuefi
if [[ $SignIt == 1 ]] ; then
$SBSign --key "$KeysDir"/refind.key --cert "$KeysDir"/refind.crt \
--output refind-bin-"$Version"/refind/refind_x64.efi refind/refind_x64.efi
else
cp refind/refind_x64.efi refind-bin-"$Version"/refind/refind_x64.efi
fi
zip -9r ../refind-bin-gnuefi-"$Version".zip refind-bin-"$Version"
cd "$TargetDir"
rm -r refind-"$Version"
} # MakeZipBinary()
# Make Debian packages using native Debian calls. Note that the Debian
# rules currently do NOT use a signing key, so these binaries will be
# UNSIGNED!
MakeDebianPackage() {
cd "$TargetDir"
rm -rf debian-source
mkdir debian-source
cd debian-source
tar xvfz ../refind-src-"$Version".tar.gz
ln -sf ../refind-src-"$Version".tar.gz refind_"$Version".orig.tar.gz
cd refind-"$Version"
debuild -S -sa -rfakeroot -k'Rod Smith <rodsmith@rodsbooks.com>'
cd ..
rm -rf ../debian-binary
mkdir ../debian-binary
mv refind-"$Version" ../debian-binary
cd ../debian-binary
ln -sf ../refind-src-"$Version".tar.gz refind_"$Version".orig.tar.gz
cd refind-"$Version"
dpkg-buildpackage -us -uc
cd ..
rm -rf refind-"$Version"
cd ..
} # MakeDebianPackage
# Make RPMs and then build Debian package from the RPM. Note that
# these files will be signed with my key, assuming --nosign was not
# passed as an option. (The RPM .spec file checks for the presence
# of my key files.)
MakeRpmPackage() {
cd "$TargetDir"
cp refind-src-"$Version".tar.gz ~/rpmbuild/SOURCES/
rpmbuild -ba "$StartDir"/refind.spec
mv ~/rpmbuild/RPMS/*/refind-"$Version"* ./
mv ~/rpmbuild/SRPMS/refind-"$Version"* ./
sudo alien --to-deb -k -c refind-"$Version"*x86_64.rpm
sudo chown rodsmith: refind*deb
rm ~/rpmbuild/SOURCES/refind-src-"$Version".tar.gz
rm -rf ~/rpmbuild/BUILD/refind-"$Version"
rm -rf ~/rpmbuild/BUILDROOT/refind-"$Version"-*
} # MakeRpmPackage
###################################
#
# Main part of script begins here
#
###################################
GetParams "$@"
# From here on, if there's an error, abort immediately.
set -e
make clean
# Remove temporary files from the "debian" subdirectory
rm -rf debian/refind debian/*.log
# Convert man pages to HTML form
man2html docs/man/mkrlconf.8 > docs/refind/mkrlconf.html
man2html docs/man/mvrefind.8 > docs/refind/mvrefind.html
man2html docs/man/refind-mkdefault.8 > docs/refind/refind-mkdefault.html
man2html docs/man/refind-install.8 > docs/refind/refind-install.html
mkdir -p ../snapshots/"$Version"
TargetDir=$(cd -P ../snapshots/"$Version" && pwd)
echo "$TargetDir"
if [[ -z $SBSign && $SignIt == 1 ]] ; then
echo "Can't find sbsign binary! Aborting!"
exit 1
fi
if [[ -z $KeysInfo && $SignIt == 1 ]] ; then
if ! mount $KeysDir ; then
echo "Error mounting $KeysDir! Aborting!"
echo ""
exit 1
fi
fi
MakeTarball
if [[ $MakeZip == 1 ]] ; then
MakeZipBinary
fi
if [[ $MakeDebian == 1 ]] ; then
MakeDebianPackage
fi
if [[ $MakeRpm == 1 ]] ; then
MakeRpmPackage
fi
# Clean up....
if [[ $SignIt == 1 ]] ; then
umount "$KeysDir"
fi
# Finish
cd "$StartDir"