Debian Codegraph @

sbin/drbl-usb-netinstall

raw symbols SCIP
1 #!/bin/bash
2 # Author: Steven Shiau <steven _at_ clonezilla org>
3 # License: GPL
4 # Description: Download the netinstall kernel & initrd and package them as a zip file for USB flash drive to boot and install GNU/Linux.
5 # This program only works for syslinux >= 6.0 because the EFI boot is supported from syslinux >= 6.0.
6
7 DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"
8
9 . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
10 [ -e /etc/drbl/drbl-ocs.conf ] && . /etc/drbl/drbl-ocs.conf
11 [ -e $DRBL_SCRIPT_PATH/sbin/ocs-functions ] && . $DRBL_SCRIPT_PATH/sbin/ocs-functions
12
13 #
14 supported_dists="$(LC_ALL=C set | grep -i "_netinstall_ver" | awk -F"_" '{print $1}' | sort | uniq)"
15 supported_dists="$(echo $supported_dists)" # To make it one line
16 supported_dists_with_comma="$(echo $supported_dists | sed -e "s/ /, /g")"
17
18 USAGE() {
19 echo "Download GNU/Linux netinstall kernel and initrd and package them as a zip file for USB flash drive to boot and install GNU/Linux."
20 echo "Usage: $0 [OPTION] [DIR]"
21 echo "OPTION:"
22 echo "-a, --file-name-prefix NAME Assign the output file name as NAME.zip. $0 will auto append '.zip' in the end of filename."
23 echo "-d, --dist DIST: Create GNU/Linux DIST netinstall zip. DIST is one of these: $supported_dists_with_comma. If this option is not assigned, all the supported GNU/Linux netinstall files will be included."
24 echo "-i, --assign-version-no NO Assign the version number as NO instead of date."
25 echo "-s, --syslinux-ver NO Assign the syslinux version number to be used as NO ."
26 }
27
28 #############
29 ### MAIN ###
30 #############
31 #
32 # Parse command-line options
33 while [ $# -gt 0 ]; do
34 case "$1" in
35 -a|--file-name-prefix)
36 shift
37 if [ -z "$(echo $1 |grep ^-.)" ]; then
38 # skip the -xx option, in case
39 target_zip_prefix="$1"
40 shift
41 fi
42 [ -z "$target_zip_prefix" ] && USAGE && exit 1
43 ;;
44 -d|--dist)
45 shift; mode="install"
46 if [ -z "$(echo $1 |grep ^-.)" ]; then
47 # skip the -xx option, in case
48 GL_INST="$1"
49 [ -z "$GL_INST" ] && USAGE && exit 1
50 shift
51 fi
52 ;;
53 -i|--assign-version-no)
54 shift
55 if [ -z "$(echo $1 |grep ^-.)" ]; then
56 # skip the -xx option, in case
57 version_no="$1"
58 shift
59 fi
60 [ -z "$version_no" ] && USAGE && exit 1
61 ;;
62 -s|--syslinux-ver)
63 shift
64 if [ -z "$(echo $1 |grep ^-.)" ]; then
65 # skip the -xx option, in case
66 syslinux_ver_no="$1"
67 shift
68 fi
69 [ -z "$syslinux_ver_no" ] && USAGE && exit 1
70 ;;
71 -*) echo "${0}: ${1}: invalid option" >&2
72 USAGE >& 2
73 exit 2 ;;
74 *) break ;;
75 esac
76 done
77 #
78 target_d="$1"
79
80 #
81 check_if_root
82
83 # if working dir is not assigned, create one
84 if [ -z "$target_d" ]; then
85 target_d="$(mktemp -d /tmp/netinstall.XXXXXX)"
86 echo "Working dir: $target_d"
87 fi
88 if [ -z "$GL_INST" ]; then
89 GL_INST="all"
90 else
91 # Check if it is in the supported distributions.
92 for i in $GL_INST; do
93 if [ -z "$(echo $supported_dists | grep -Ew $i)" ]; then
94 echo "\"$GL_INST\" is not a supported distribution."
95 echo "Supported ones are (case sensitive): $supported_dists."
96 exit 1
97 fi
98 done
99 fi
100
101 [ -z "$version_no" ] && version_no="$(date +%Y%m%d)"
102 zip_label_tag="${version_no}"
103 if [ -n "$target_zip_prefix" ]; then
104 output_filename="${target_zip_prefix}.zip"
105 else
106 output_filename="linux-netinstall-${zip_label_tag}.zip"
107 fi
108 echo "The output file name is: $output_filename."
109
110 WD="$(pwd)"
111 mkdir -p $target_d/syslinux/ $target_d/live/ $target_d/EFI/boot/ $target_d/boot/grub
112 cp -af $pxelinux_bg_img $target_d/syslinux/
113 cp -af $pxelinux_bg_img /usr/share/grub/unicode.pf2 $target_d/boot/grub/
114
115 echo "The following action will download a lot of network install packages, including these distributions: $GL_INST. This might take a long time..."
116 echo 'If you want to assign the url, check "netinstall image settings" in drbl.conf.'
117 drbl-netinstall -w --skip-rerun-gen -i "$GL_INST" -d $target_d/live/
118
119 echo "Generating default pxelinux config $target_d/syslinux/syslinux.cfg..."
120 echo "Adding menus..."
121 cat <<-PXE_END > $target_d/syslinux/syslinux.cfg
122 # Created by generate-pxe-menu! Do NOT edit unless you know what you are doing!
123 # Keep those comment "MENU DEFAULT" and "MENU HIDE"! Do NOT remove them.
124 # Note!!! If "serial" directive exists, it must be the first directive
125 default vesamenu.c32
126 timeout 70
127 prompt 0
128 noescape 1
129 MENU MARGIN 5
130 MENU BACKGROUND drblwp.png
131 # Set the color for unselected menu item and timout message
132 MENU COLOR UNSEL 7;32;41 #c0000090 #00000000
133 MENU COLOR TIMEOUT_MSG 7;32;41 #c0000090 #00000000
134 MENU COLOR TIMEOUT 7;32;41 #c0000090 #00000000
135 MENU COLOR HELP 7;32;41 #c0000090 #00000000
136
137 # MENU MASTER PASSWD
138
139 say **********************************************
140 say Welcome to DRBL.
141 say NCHC Free Software Labs, Taiwan.
142 say http://drbl.org; http://drbl.nchc.org.tw
143 say **********************************************
144
145 # Allow client to edit the parameters
146 ALLOWOPTIONS 1
147
148 # simple menu title
149 MENU TITLE DRBL (http://drbl.org)
150
151 PXE_END
152
153 # Creating the boot menu, 2 types: for BIOS and EFI
154 # 1. The boot menu for BIOS machine
155 # //NOTE// the / in the end of /live/ for -p option is important. Do not remove it.
156 # Because we use that in syslinux.cfg like:
157 # kernel $boot_file_dir$kernel
158 # append initrd=$boot_file_dir$img $ramdisk_size_opt $extra_append
159 output_netinstall_boot_menu -p /live/ $target_d/live/ $target_d/syslinux/syslinux.cfg
160
161 # Turn on all menus before copying to EFI dir
162 perl -pi -e "s/^(#|[[:space:]])*MENU HIDE.*/ # MENU HIDE/i" $target_d/syslinux/syslinux.cfg
163
164 # 2. The boot menu for EFI machine
165 # Check if required files exists on this machine
166 # grub-efi-amd64-signed: /usr/lib/grub/x86_64-efi-signed/gcdx64.efi.signed
167 # shim-signed: /usr/lib/shim/shimx64.efi.signed
168 uefi_boot_support="yes"
169 if [ -e /usr/lib/shim/shimx64.efi.signed ]; then
170 cp -a /usr/lib/shim/shimx64.efi.signed $target_d/EFI/boot/bootx64.efi
171 else
172 echo "File /usr/lib/shim/shimx64.efi.signed not found."
173 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
174 echo "uEFI booting not supported!"
175 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
176 echo "On Debian or Ubuntu Linux, you can install it by:"
177 echo "apt-get install shim-signed"
178 uefi_boot_support="no"
179 fi
180 if [ -e /usr/lib/grub/x86_64-efi-signed/gcdx64.efi.signed ]; then
181 cp -a /usr/lib/grub/x86_64-efi-signed/gcdx64.efi.signed $target_d/EFI/boot/grubx64.efi
182 else
183 echo "File /usr/lib/grub/x86_64-efi-signed/gcdx64.efi.signed not found."
184 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
185 echo "uEFI booting not supported!"
186 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
187 echo "On Debian or Ubuntu Linux, you can install it by:"
188 echo "apt-get install grub-efi-amd64-signed"
189 uefi_boot_support="no"
190 fi
191 if [ ! -d "/usr/lib/grub/i386-efi" ]; then
192 echo "File dir /usr/lib/grub/i386-efi not found."
193 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
194 echo "uEFI booting for i386 not supported!"
195 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
196 echo "On Debian or Ubuntu Linux, you can install it by:"
197 echo "apt-get install grub-efi-ia32-bin"
198 fi
199
200 #
201 if [ "$uefi_boot_support" = "yes" ]; then
202 # Create bootia32.efi. This is for i386 uEFI booting.
203 mkdir -p $target_d/tmp-efi
204 ocs-gen-grub2-efi-bldr $target_d/tmp-efi/
205 rsync -avP $target_d/tmp-efi/bootia32.efi $target_d/EFI/boot/
206 rm -rf $target_d/tmp-efi/
207 echo -n "Copying /usr/lib/grub/x86_64-efi and /usr/lib/grub/i386-efi to $target_d/boot/grub/..."
208 rsync -a /usr/lib/grub/x86_64-efi $target_d/boot/grub/
209 rsync -a /usr/lib/grub/i386-efi $target_d/boot/grub/
210 echo " done!"
211 output_netinstall_boot_menu --efi -u -p /live/ $target_d/live/ $target_d/boot/grub/grub.cfg
212 fi
213
214 echo "Preparing syslinux.exe, syslinux, makeboot.bat and makeboot.sh... "
215 put_syslinux_makeboot_for_usb_flash $target_d/ "$syslinux_ver_no"
216
217 cp -af /usr/share/doc/drbl/GPL $target_d/
218
219 (cd $target_d; zip -r $WD/$output_filename *)
220 echo "The netinstall file $output_filename was created."
221
222 echo "*******************************************************************"
223 if [ -n "$target_d" -a -d "$target_d" ]; then
224 echo "Do you want to remove the downloaded files in dir $target_d?"
225 echo -n "[y/N] "
226 read rm_files
227 case "$rm_files" in
228 y|Y|[yY][eE][sS])
229 # Some checkings to avoid to remove the /
230 if [ -n "$target_d" -a -d "$target_d/syslinux/" -a -f "$target_d/COPYING" ]; then
231 rm -rf $target_d
232 fi
233 ;;
234 esac
235 fi