]> code.delx.au - refind/blob - mkdistrib
Fixed bug that caused mvrefind to fail to move bootmgfw.efi in some
[refind] / mkdistrib
1 #!/bin/bash
2 #
3 # Script to prepare source code and binary distribution files of rEFInd.
4 # By Rod Smith, 3/11/2012
5 # Updated 11/8/2012 to do more things automatically
6 # Updated 12/6/2012 to sign binaries with the rEFInd MOK
7 # Updated 12/3/2015 to independently compile .zip, RPM, and Debian packages
8 #
9 # Usage: ./mkdistrib [--nosign] [--norpm] [--nodebian] [--nozip] version
10 # where "version" is a version number.
11 #
12 # Build requirements:
13 # * Zip: x86-64 system with TianoCore configured for IA32, X64, and
14 # AARCH builds ("TARGET_ARCH = IA32 X64 AARCH64" in Conf/target.txt)
15 # * RPM: System with TianoCore or GNU-EFI of same CPU type as desired
16 # target architecture. (Tested only on X64/x86-64.)
17 # * Debian: System with GNU-EFI of same CPU type as desired target
18 # architecture.
19 # * MOK files: Used for zip and RPM builds; not used for building
20 # Debian packages. Must be mounted at /mnt/refind via /etc/fstab
21 # entry, unless --nosign is specified, in which case binaries are
22 # not signed. Only X64 binaries are signed.
23
24 SignIt=1
25 MakeRpm=1
26 MakeDebian=1
27 MakeZip=1
28 KeysDir=/mnt/refind
29 KeysInfo=`df $KeysDir 2> /dev/null | grep $KeysDir`
30 StartDir=`pwd`
31 SBSign=`which sbsign 2> /dev/null`
32
33 ShowUsage() {
34 echo "Usage:"
35 echo "$0 [--nosign] [--norpm] [--nodebian] [--nozip] version"
36 exit
37 }
38
39 GetParams() {
40 while [[ $# -gt 0 ]]; do
41 echo "$1"
42 case $1 in
43 --nosign) SignIt=0
44 ;;
45 --norpm) MakeRpm=0
46 ;;
47 --nodebian) MakeDebian=0
48 ;;
49 --nozip) MakeZip=0
50 ;;
51 --help) ShowUsage $0
52 ;;
53 * ) Version=$1
54 esac
55 shift
56 done
57 if [[ -z "$Version" ]] ; then
58 ShowUsage $0
59 fi
60 } # GetParams()
61
62 # Copy rEFInd source files to refind-$Version inside $TargetDir directory
63 # and create a tarball from refind-$Version. Both the tarball and the
64 # source directory are left in $TargetDir when this function finishes, and
65 # $TargetDir is the current directory at the end.
66 MakeTarball() {
67 # Prepare a place and copy files there....
68 mkdir -p $TargetDir/refind-$Version/icons/licenses $TargetDir/refind-$Version/icons/svg
69 cp --preserve=timestamps icons/*png icons/README $TargetDir/refind-$Version/icons/
70 cp --preserve=timestamps -r icons/licenses/* $TargetDir/refind-$Version/icons/licenses/
71 cp --preserve=timestamps -r icons/svg/* $TargetDir/refind-$Version/icons/svg/
72 cp -a debian docs images keys fonts banners include EfiLib libeg mok net refind filesystems \
73 gptsync refind.spec refind-install mkrlconf mvrefind mountesp CREDITS.txt NEWS.txt BUILDING.txt \
74 COPYING.txt LICENSE.txt README.txt refind.inf Make.common Makefile \
75 refind.conf-sample $TargetDir/refind-$Version
76
77 # Go there and prepare a souce code tarball....
78 cd $TargetDir
79 rm -f refind-src-$Version.tar.gz
80 tar cvf refind-src-$Version.tar refind-$Version
81 gzip -9 refind-src-$Version.tar
82
83 # Remove SVG files, since they aren't needed for binary packages....
84 rm -rf refind-$Version/icons/svg
85 } # MakeTarball()
86
87 # Create two .zip packages containing the full binary builds of rEFInd for three
88 # platforms -- IA32, X64, and AARCH64. One binary is the regular build and the
89 # second is the same as the first but substitutes refind_x64.efi build with
90 # GNU-EFI for the usual TianoCore build. (This is to provide an alternative for
91 # those rare cases when the TianoCore build fails.) The X64 binaries are signed
92 # with my key *IF* --nosign is not specified and if the key is available.
93 MakeZipBinary() {
94 cd $TargetDir/refind-$Version
95 # Build the ARM64 binaries
96 ARCH=aarch64 make -j1
97 ARCH=aarch64 make fs
98 mkdir -p refind-bin-$Version/refind/drivers_aa64
99 cp --preserve=timestamps drivers_aa64/*_aa64.efi refind-bin-$Version/refind/drivers_aa64/
100 cp --preserve=timestamps filesystems/LICENSE*txt refind-bin-$Version/refind/drivers_aa64/
101 cp refind/refind_aa64.efi refind-bin-$Version/refind/refind_aa64.efi
102 cp refind/refind_aa64.efi $StartDir/
103 mkdir -p refind-bin-$Version/refind/tools_aa64
104 # Don't copy gptsync_aa64.efi because it won't build in cross-compile environment
105 # and because it's likely to be useless on ARM64.
106
107 # Build the IA32 binaries
108 make clean
109 ARCH=ia32 make -j1
110 ARCH=ia32 make fs
111 mkdir -p refind-bin-$Version/refind/drivers_ia32
112 cp --preserve=timestamps drivers_ia32/*_ia32.efi refind-bin-$Version/refind/drivers_ia32/
113 cp --preserve=timestamps filesystems/LICENSE*txt refind-bin-$Version/refind/drivers_ia32/
114 cp refind/refind_ia32.efi refind-bin-$Version/refind/refind_ia32.efi
115 cp refind/refind_ia32.efi $StartDir/
116 mkdir -p refind-bin-$Version/refind/tools_ia32
117 cp --preserve=timestamps gptsync/gptsync_ia32.efi refind-bin-$Version/refind/tools_ia32/
118
119 # Build the X64 binaries
120 make clean
121 make -j1
122 make fs
123 mkdir -p refind-bin-$Version/refind/drivers_x64
124 cp -a icons refind-bin-$Version/refind/
125 if [[ $SignIt == 1 ]] ; then
126 for File in `ls drivers_x64/*_x64.efi` ; do
127 $SBSign --key $KeysDir/refind.key --cert $KeysDir/refind.crt --output refind-bin-$Version/refind/$File $File
128 done
129 else
130 cp --preserve=timestamps drivers_x64/*_x64.efi refind-bin-$Version/refind/drivers_x64/
131 fi
132 cp --preserve=timestamps filesystems/LICENSE*txt refind-bin-$Version/refind/drivers_x64/
133 cp --preserve=timestamps refind.conf-sample refind-bin-$Version/refind/
134 if [[ $SignIt == 1 ]] ; then
135 $SBSign --key $KeysDir/refind.key --cert $KeysDir/refind.crt --output refind-bin-$Version/refind/refind_x64.efi refind/refind_x64.efi
136 else
137 cp refind/refind_x64.efi refind-bin-$Version/refind/refind_x64.efi
138 fi
139 mkdir -p refind-bin-$Version/refind/tools_x64
140 if [[ $SignIt == 1 ]] ; then
141 $SBSign --key $KeysDir/refind.key --cert $KeysDir/refind.crt --output refind-bin-$Version/refind/tools_x64/gptsync_x64.efi gptsync/gptsync_x64.efi
142 else
143 cp --preserve=timestamps gptsync/gptsync_x64.efi refind-bin-$Version/refind/tools_x64/
144 fi
145 cp refind-bin-$Version/refind/refind_x64.efi $StartDir
146 cp -a docs keys banners fonts COPYING.txt LICENSE.txt README.txt CREDITS.txt NEWS.txt refind-install mkrlconf mvrefind mountesp refind-bin-$Version
147
148 # Prepare the final .zip file
149 zip -9r ../refind-bin-$Version.zip refind-bin-$Version
150
151 # Prepare a variant with the x86-64 version built with GNU-EFI....
152 make clean
153 make -j1 gnuefi
154 if [[ $SignIt == 1 ]] ; then
155 $SBSign --key $KeysDir/refind.key --cert $KeysDir/refind.crt --output refind-bin-$Version/refind/refind_x64.efi refind/refind_x64.efi
156 else
157 cp refind/refind_x64.efi refind-bin-$Version/refind/refind_x64.efi
158 fi
159 zip -9r ../refind-bin-gnuefi-$Version.zip refind-bin-$Version
160
161 cd $TargetDir
162 rm -r refind-$Version
163 } # MakeZipBinary()
164
165 # Make Debian packages using native Debian calls. Note that the Debian
166 # rules currently do NOT use a signing key, so these binaries will be
167 # UNSIGNED!
168 MakeDebianPackage() {
169 cd $TargetDir
170 rm -rf debian-source
171 mkdir debian-source
172 cd debian-source
173 tar xvfz ../refind-src-$Version.tar.gz
174 ln -sf ../refind-src-$Version.tar.gz refind_$Version.orig.tar.gz
175 cd refind-$Version
176 debuild -S -sa -rfakeroot -k'Rod Smith <rodsmith@rodsbooks.com>'
177 cd ..
178 rm -rf ../debian-binary
179 mkdir ../debian-binary
180 mv refind-$Version ../debian-binary
181 cd ../debian-binary
182 ln -sf ../refind-src-$Version.tar.gz refind_$Version.orig.tar.gz
183 cd refind-$Version
184 dpkg-buildpackage -us -uc
185 cd ..
186 rm -rf refind-$Version
187 cd ..
188 } # MakeDebianPackage
189
190 # Make RPMs and then build Debian package from the RPM. Note that
191 # these files will be signed with my key, assuming --nosign was not
192 # passed as an option. (The RPM .spec file checks for the presence
193 # of my key files.)
194 MakeRpmPackage() {
195 cd $TargetDir
196 cp refind-src-$Version.tar.gz ~/rpmbuild/SOURCES/
197 rpmbuild -ba $StartDir/refind.spec
198 mv ~/rpmbuild/RPMS/*/refind-$Version* ./
199 mv ~/rpmbuild/SRPMS/refind-$Version* ./
200 sudo alien --to-deb -k -c refind-$Version*x86_64.rpm
201 sudo chown rodsmith: refind*deb
202 rm ~/rpmbuild/SOURCES/refind-src-$Version.tar.gz
203 rm -rf ~/rpmbuild/BUILD/refind-$Version
204 rm -rf ~/rpmbuild/BUILDROOT/refind-$Version-*
205 } # MakeRpmPackage
206
207 ###################################
208 #
209 # Main part of script begins here
210 #
211 ###################################
212
213 GetParams "$@"
214
215 # From here on, if there's an error, abort immediately.
216 set -e
217
218 make clean
219
220 # Remove temporary files from the "debian" subdirectory
221 rm -rf debian/refind debian/*.log
222
223 # Convert man pages to HTML form
224 man2html docs/man/mkrlconf.8 > docs/refind/mkrlconf.html
225 man2html docs/man/mvrefind.8 > docs/refind/mvrefind.html
226 man2html docs/man/refind-install.8 > docs/refind/refind-install.html
227
228 mkdir -p ../snapshots/$Version
229 TargetDir=`cd -P ../snapshots/$Version && pwd`
230 echo $TargetDir
231
232 if [[ ! -n $SBSign && $SignIt == 1 ]] ; then
233 echo "Can't find sbsign binary! Aborting!"
234 exit 1
235 fi
236
237 if [[ ! -n $KeysInfo && $SignIt == 1 ]] ; then
238 mount $KeysDir
239 if [[ $? -ne 0 ]] ; then
240 echo "Error mounting $KeysDir! Aborting!"
241 echo ""
242 exit 1
243 fi
244 fi
245
246 MakeTarball
247
248 if [[ $MakeZip == 1 ]] ; then
249 MakeZipBinary
250 fi
251
252 if [[ $MakeDebian == 1 ]] ; then
253 MakeDebianPackage
254 fi
255
256 if [[ $MakeRpm == 1 ]] ; then
257 MakeRpmPackage
258 fi
259
260 # Clean up....
261 if [[ $SignIt == 1 ]] ; then
262 umount $KeysDir
263 fi
264
265 # Finish
266 cd $StartDir