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