1 | #!/bin/bash
|
---|
2 | #
|
---|
3 | # Copyright (c) 2016 Jiri Svoboda
|
---|
4 | # All rights reserved.
|
---|
5 | #
|
---|
6 | # Redistribution and use in source and binary forms, with or without
|
---|
7 | # modification, are permitted provided that the following conditions
|
---|
8 | # are met:
|
---|
9 | #
|
---|
10 | # - Redistributions of source code must retain the above copyright
|
---|
11 | # notice, this list of conditions and the following disclaimer.
|
---|
12 | # - Redistributions in binary form must reproduce the above copyright
|
---|
13 | # notice, this list of conditions and the following disclaimer in the
|
---|
14 | # documentation and/or other materials provided with the distribution.
|
---|
15 | # - The name of the author may not be used to endorse or promote products
|
---|
16 | # derived from this software without specific prior written permission.
|
---|
17 | #
|
---|
18 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
19 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
20 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
21 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
22 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
23 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
27 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
28 | #
|
---|
29 |
|
---|
30 | #
|
---|
31 | # Script to generate/update prebuilt Grub2 in HelenOS source tree
|
---|
32 | # Be sure you know what you are doing!
|
---|
33 | #
|
---|
34 |
|
---|
35 | origdir="$(pwd)"
|
---|
36 | helenosdir="$origdir/../.."
|
---|
37 | workdir="$(pwd)/grub-src"
|
---|
38 | builddir="$(pwd)/grub-build"
|
---|
39 | git_repo="git://git.savannah.gnu.org/grub.git"
|
---|
40 | grub_rev="bc220962e366b1b46769ed6f9fa5be603ba58ab5"
|
---|
41 |
|
---|
42 | function grub_build()
|
---|
43 | {
|
---|
44 | target="$1"
|
---|
45 | platform="$2"
|
---|
46 |
|
---|
47 | ./configure --prefix="$builddir/$target-$platform" --target="$target" --with-platform="$platform" || exit 1
|
---|
48 | make clean || exit 1
|
---|
49 | make install || exit 1
|
---|
50 | }
|
---|
51 |
|
---|
52 | function grub_files_update()
|
---|
53 | {
|
---|
54 | gdir="$1"
|
---|
55 | platform="$2"
|
---|
56 |
|
---|
57 | rm -rf "$helenosdir"/boot/"$gdir"/"$platform" || exit 1
|
---|
58 | cp -R "$builddir"/"$platform"/lib64/grub/"$platform" "$helenosdir"/boot/"$gdir" || exit 1
|
---|
59 | rm -f "$helenosdir"/boot/"$gdir"/"$platform"/*.image || exit 1
|
---|
60 | bzr add "$helenosdir"/boot/"$gdir"/"$platform" || exit 1
|
---|
61 | }
|
---|
62 |
|
---|
63 | # Prepare a clone of Grub2 repo
|
---|
64 | if [ ! -d "$workdir" ] ; then
|
---|
65 | rm -rf "$workdir" "$builddir" || exit 1
|
---|
66 | git clone "$git_repo" "$workdir" || exit 1
|
---|
67 | fi
|
---|
68 |
|
---|
69 | cd "$workdir" || exit 1
|
---|
70 | git pull || exit 1
|
---|
71 | git reset --hard "$grub_rev" || exit 1
|
---|
72 |
|
---|
73 | echo "$grub_rev" >"$helenosdir"/boot/grub.pc/REVISION || exit 1
|
---|
74 | echo "$grub_rev" > "$helenosdir"/boot/grub.efi/REVISION || exit 1
|
---|
75 |
|
---|
76 | # Build each platform to a different directory
|
---|
77 | ./autogen.sh || exit 1
|
---|
78 | grub_build i386 pc
|
---|
79 | grub_build i386 efi
|
---|
80 | grub_build x86_64 efi
|
---|
81 |
|
---|
82 | # Extract El Torrito boot image for i386-pc
|
---|
83 | cd "$helenosdir"/boot/grub.pc || exit 1
|
---|
84 | rm -f pc.img || exit 1
|
---|
85 | "$builddir"/i386-pc/bin/grub-mkrescue -o phony --xorriso="$origdir/getimage.sh" || exit 1
|
---|
86 |
|
---|
87 | # Extract El Torrito boot image for i386-efi
|
---|
88 | cd "$helenosdir"/boot/grub.efi || exit 1
|
---|
89 | rm -f efi.img.gz || exit 1
|
---|
90 | "$builddir"/i386-efi/bin/grub-mkrescue -o phony --xorriso="$origdir/getimage.sh" || exit 1
|
---|
91 | mv efi.img i386-efi.img
|
---|
92 |
|
---|
93 | # Extract El Torrito boot image for x86_64-efi
|
---|
94 | cd "$helenosdir"/boot/grub.efi || exit 1
|
---|
95 | rm -f efi.img.gz || exit 1
|
---|
96 | "$builddir"/x86_64-efi/bin/grub-mkrescue -o phony --xorriso="$origdir/getimage.sh" || exit 1
|
---|
97 |
|
---|
98 | # Combine El Torrito boot images for x86_64-efi and i386-efi
|
---|
99 | mkdir tmp || exit 1
|
---|
100 | mcopy -ns -i i386-efi.img ::efi tmp || exit 1
|
---|
101 | mcopy -s -i efi.img tmp/* :: || exit 1
|
---|
102 | gzip efi.img || exit 1
|
---|
103 | rm -rf tmp || exit 1
|
---|
104 | rm -f i386-efi.img || exit 1
|
---|
105 |
|
---|
106 | # Update Grub files for all platforms
|
---|
107 | grub_files_update grub.pc i386-pc
|
---|
108 | grub_files_update grub.efi i386-efi
|
---|
109 | grub_files_update grub.efi x86_64-efi
|
---|
110 |
|
---|
111 | # Clean up
|
---|
112 | rm -rf "$builddir" || exit 1
|
---|
113 |
|
---|
114 | echo "GRUB update successful."
|
---|