Debian Codegraph @

scripts/sbin/prepare-files-for-PXE-client

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2 # Author: Steven Shiau <steven _at_ clonezilla org>
3 # License: GPL
4 # Description: DRBL utitilty to create files for PXELINUX clients.
5 # Load DRBL setting and functions
6 DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"
7
8 . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
9
10 # Settings
11 # By default we put all the files for clients.
12 # If put pxelinux-related files (*.0, *.c32, *.efi...) only, set as "true"
13 put_pxelinux_related_only="false"
14
15 USAGEscip-shell shell shell-project 0.0.0 USAGE().() {
16 echoscip-shell system . . echo. "Usage: $0 [OPTION]"
17 echoscip-shell system . . echo. "OPTION"
18 language_help_prompt_by_idx_no
19 echoscip-shell system . . echo. "-o, --console-output OPT: Set the console output parameters."
20 echoscip-shell system . . echo. "-i, --pxe-serial-output OPT: Set the PXE menu to work with serial console output."
21 echoscip-shell system . . echo. "-p, --only-pxelinux-related: Only put the PXELINUX related files. Skip the memtest, freedos, and not to create the PXELINUX boot menu file."
22 }
23 #
24 put_drbl_background_imgscip-shell shell shell-project 0.0.0 put_drbl_background_img().() {
25 # the background img in pxelinux
26 if [scip-shell system . . `[`. -f "$pxelinux_bg_img" ]; then
27 cpscip-shell system . . cp. -af $pxelinux_bg_img $pxecfg_pd
28 else
29 [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
30 echoscip-shell system . . echo. "$msg_Warning! $pxelinux_bg_img $msg_NOT_found!!! $msg_PXE_NOT_work"
31 echoscip-shell system . . echo. "$msg_press_enter_to_continue"
32 [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
33 read
34 fi
35 }
36 #
37 put_pxelinux_multi_arch_filesscip-shell shell shell-project 0.0.0 put_pxelinux_multi_arch_files().() {
38 # For those files will be copied to $pxecfg_pd/{bios,efi32,efi64}
39 for iarch in bios efi32 efi64; do
40 if [scip-shell system . . `[`. -d "$pxelinux_binsrc_dir/$iarch" ]; then
41 cpscip-shell system . . cp. -af $pxelinux_binsrc_dir/$iarch $pxecfg_pd/
42 fi
43 done
44 # Move the files to appropriate path.
45 # pxelinux.0, gpxelinux.0, and lpxelinux.0
46 mvscip-shell system . . mv. $pxecfg_pd/bios/*pxelinux.0 $pxecfg_pd/
47 if [scip-shell system . . `[`. -e "$pxecfg_pd/bios/ldlinux.c32" ]; then
48 mvscip-shell system . . mv. $pxecfg_pd/bios/ldlinux.c32 $pxecfg_pd/ldlinux.c32
49 fi
50 if [scip-shell system . . `[`. -e "$pxecfg_pd/efi32/ldlinux.e32" ]; then
51 mvscip-shell system . . mv. $pxecfg_pd/efi32/ldlinux.e32 $pxecfg_pd/ldlinux.e32
52 fi
53 if [scip-shell system . . `[`. -e "$pxecfg_pd/efi32/syslinux.efi" ]; then
54 mvscip-shell system . . mv. $pxecfg_pd/efi32/syslinux.efi $pxecfg_pd/bootia32.efi
55 echoscip-shell system . . echo. "File copied from syslinux efi32/syslinux.efi" > $pxecfg_pd/bootia32.efi.info
56 fi
57 if [scip-shell system . . `[`. -e "$pxecfg_pd/efi64/ldlinux.e64" ]; then
58 mvscip-shell system . . mv. $pxecfg_pd/efi64/ldlinux.e64 $pxecfg_pd/ldlinux.e64
59 fi
60 if [scip-shell system . . `[`. -e "$pxecfg_pd/efi64/syslinux.efi" ]; then
61 mvscip-shell system . . mv. $pxecfg_pd/efi64/syslinux.efi $pxecfg_pd/bootx64.efi
62 echoscip-shell system . . echo. "File copied from syslinux efi64/syslinux.efi" > $pxecfg_pd/bootx64.efi.info
63 fi
64 }
65 #
66 put_pxelinux_memdiskscip-shell shell shell-project 0.0.0 put_pxelinux_memdisk().() {
67 # memdisk, only for $pxecfg_pd/bios/
68 if [scip-shell system . . `[`. -f "$pxelinux_memdisk_file" ]; then
69 cpscip-shell system . . cp. -af $pxelinux_memdisk_file $pxecfg_pd/
70 else
71 [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
72 echoscip-shell system . . echo. "$msg_Warning! $pxelinux_memdisk_file $msg_NOT_found!!! $msg_PXE_NOT_work"
73 echoscip-shell system . . echo. "$msg_press_enter_to_continue"
74 [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
75 read
76 fi
77 }
78 #
79 link_pxelinux_bios_arch_filesscip-shell shell shell-project 0.0.0 link_pxelinux_bios_arch_files().() {
80 # If only $pxecfg_pd/bios/, no $pxecfg_pd/{efi32,efi64}, we'd better to link files from $pxecfg_pd/bios/ to $pxecfg_pd/, otherwise for CentOS 5 with syslinux 4.x, the "PATH" option is not supported.
81 if [scip-shell system . . `[`. -d $pxecfg_pd/bios -a \
82 ! -d $pxecfg_pd/efi32 -a \
83 ! -d $pxecfg_pd/efi64 ]; then
84 for i in $pxecfg_pd/bios/*; do
85 [scip-shell system . . `[`. ! -e "$i" ] && continue
86 fn="$(basenamescip-shell system . . basename. $i)"
87 (
88 lnscip-shell system . . ln. -t $pxecfg_pd -fs bios/$fn
89 )
90 done
91 fi
92 }
93 #
94 put_memtest86_imgscip-shell shell shell-project 0.0.0 put_memtest86_img().() {
95 # memtest86+
96 # make a version tag in $pxecfg_pd
97 # Only for x86
98 if [scip-shell system . . `[`. "$(unamescip-shell system . . uname. -m)" != "x86_64" ]; then
99 echoscip-shell system . . echo. "Not x86-64 system. Skip putting memtest86."
100 return 3
101 fi
102 echoscip-shell system . . echo. "Copying memtest86+ to $pxecfg_pd..."
103 if [scip-shell system . . `[`. -n "$(lsscip-shell system . . ls. -l $memtest86_dir/mt86+x* 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" ]; then
104 cpscip-shell system . . cp. -af $memtest86_dir/mt86+x* $pxecfg_pd
105 cpscip-shell system . . cp. -af $memtest86_dir/VERSION $pxecfg_pd/MEMTEST86+_VERSION
106 else
107 [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
108 echoscip-shell system . . echo. "$msg_Warning! $memtest86_dir/mt86+x* $msg_NOT_found!!!"
109 echoscip-shell system . . echo. "$msg_press_enter_to_continue"
110 [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
111 read
112 fi
113 }
114 #
115 put_etherboot_and_sis900_pxescip-shell shell shell-project 0.0.0 put_etherboot_and_sis900_pxe().() {
116 # This function is deprecated since we do not maintain drbl-etherboot package anymore.
117 # For etherboot PXE image (Especially necessary for sis900 NIC)
118 # clean the old ones
119 rmscip-shell system . . rm. -f $pxecfg_pd/eb-*-etherboot-pci.zpxe $pxecfg_pd/sis900.zpxe
120 # get the all-in-one etherboot zpxe and sis900 zpxe filename, we use sort and head to choose only one.
121 etherboot_pxe="$($query_pkglist_cmd drbl-etherboot 2>/dev/nullscip-shell filesystem . . `/dev/null`. | grepscip-shell system . . grep. -E "eb-.*-etherboot-pci.zpxe$")"
122 [scip-shell system . . `[`. -e "$etherboot_pxe" ] && cpscip-shell system . . cp. -af $etherboot_pxe $pxecfg_pd/
123
124 sis900_pxe="$($query_pkglist_cmd drbl-etherboot 2>/dev/nullscip-shell filesystem . . `/dev/null`. | grepscip-shell system . . grep. -E "sis900.zpxe$")"
125 [scip-shell system . . `[`. -e "$sis900_pxe" ] && cpscip-shell system . . cp. -af $sis900_pxe $pxecfg_pd/
126 }
127 #
128 put_free_dos_imgscip-shell shell shell-project 0.0.0 put_free_dos_img().() {
129 # create the freedos image, which a clean one.
130 # if user wants to insert files, use
131 # the script insert-file-fdos.sh
132 # [ -f kernel.sys ] && rm -f kernel.sys
133 if [scip-shell system . . `[`. -f "$fdos_img_src" ]; then
134 # 2005/4/4 since etherboot 5.4.0 is released, no more NBI.
135 # img_mt=`mktemp -d fdos_img.XXXXXX`
136 # mount -t vfat -o loop $fdos_img_src $img_mt
137 # cp -f $img_mt/kernel.sys .
138 # umount $img_mt
139 # mknbi-fdos --output=/tftpboot/nbi_img/$fdos_nbi_output kernel.sys $fdos_img_src
140 echoscip-shell system . . echo. "Copying FreeDOS files to $pxecfg_pd/... "
141 cpscip-shell system . . cp. -f $fdos_img_src $pxecfg_pd/$fdos_img_output
142 # [ -d "$img_mt" ] && rm -rf $img_mt
143 # clean the unnecessary file
144 # [ -f kernel.sys ] && rm -f kernel.sys
145 else
146 [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
147 echoscip-shell system . . echo. "$msg_Warning! $fdos_img_src $msg_NOT_found!!! $msg_FreeDOS_NOT_work"
148 echoscip-shell system . . echo. "$msg_press_enter_to_continue"
149 [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
150 fi
151 }
152 #
153 gen_pxe_boot_menuscip-shell shell shell-project 0.0.0 gen_pxe_boot_menu().() {
154 # create the pxelinux default
155 if [scip-shell system . . `[`. -n "$CONSOLE_OUTPUT" ]; then
156 console_opt1="--console"
157 console_opt2="$CONSOLE_OUTPUT"
158 fi
159 if [scip-shell system . . `[`. -n "$PXE_SERIAL_OUTPUT" ]; then
160 pxe_serial_opt1="--serial"
161 pxe_serial_opt2="$PXE_SERIAL_OUTPUT"
162 fi
163 generate-pxe-menu $console_opt1 "$console_opt2" $pxe_serial_opt1 "$pxe_serial_opt2"
164 }
165
166 # Parse command-line options
167 while [scip-shell system . . `[`. $# -gt 0 ]; do
168 case "$1" in
169 -l|--language)
170 shift
171 if [scip-shell system . . `[`. -z "$(echoscip-shell system . . echo. $1 |grepscip-shell system . . grep. ^-.)" ]; then
172 # skip the -xx option, in case
173 specified_lang="$1"
174 shift
175 fi
176 [scip-shell system . . `[`. -z "$specified_lang" ] && USAGEscip-shell shell shell-project 0.0.0 USAGE(). && exit 1
177 ;;
178 -o|--console-output)
179 shift
180 if [scip-shell system . . `[`. -z "$(echoscip-shell system . . echo. $1 |grepscip-shell system . . grep. ^-.)" ]; then
181 # skip the -xx option, in case
182 CONSOLE_OUTPUT="$1"
183 shift
184 fi
185 [scip-shell system . . `[`. -z "$CONSOLE_OUTPUT" ] && USAGEscip-shell shell shell-project 0.0.0 USAGE(). && exit 1
186 ;;
187 -i|--pxe-serial-output)
188 shift
189 if [scip-shell system . . `[`. -z "$(echoscip-shell system . . echo. $1 |grepscip-shell system . . grep. ^-.)" ]; then
190 # skip the -xx option, in case
191 PXE_SERIAL_OUTPUT="$1"
192 shift
193 fi
194 [scip-shell system . . `[`. -z "$PXE_SERIAL_OUTPUT" ] && USAGEscip-shell shell shell-project 0.0.0 USAGE(). && exit 1
195 ;;
196 -p|--only-pxelinux-related)
197 shift
198 put_pxelinux_related_only="true"
199 ;;
200 -*) echoscip-shell system . . echo. "${0}: ${1}: invalid option" >&2
201 USAGEscip-shell shell shell-project 0.0.0 USAGE(). >& 2
202 exit 2 ;;
203 *) break ;;
204 esac
205 done
206
207 #
208 check_if_root
209
210 #
211 ask_and_load_lang_set $specified_lang
212
213 echoscip-shell system . . echo. "Copying pxelinux.0, gpxelinux.0, menu.c32, vesamenu.c32, chain.c32, mboot.c32, sanboot.c32 and memdisk to $pxecfg_pd..."
214
215 [scip-shell system . . `[`. ! -d $pxecfg_pd/pxelinux.cfg ] && mkdirscip-shell system . . mkdir. -p $pxecfg_pd/pxelinux.cfg
216
217 # make a version tag in $pxecfg_pd
218 cpscip-shell system . . cp. -af $pxelinux_binsrc_dir/VERSION $pxecfg_pd/PXELINUX_VERSION
219
220 # These files (pxelinux.0, gpxelinux.0, menu.c32, vesamenu.c32, chain.c32, memdisk...) are very important.
221 # Hence we process here separately.
222
223 if [scip-shell system . . `[`. "$put_pxelinux_related_only" = "true" ]; then
224 put_pxelinux_multi_arch_filesscip-shell shell shell-project 0.0.0 put_pxelinux_multi_arch_files().
225 link_pxelinux_bios_arch_filesscip-shell shell shell-project 0.0.0 link_pxelinux_bios_arch_files().
226 put_pxelinux_memdiskscip-shell shell shell-project 0.0.0 put_pxelinux_memdisk().
227 else
228 put_drbl_background_imgscip-shell shell shell-project 0.0.0 put_drbl_background_img().
229 put_memtest86_imgscip-shell shell shell-project 0.0.0 put_memtest86_img().
230 put_etherboot_and_sis900_pxescip-shell shell shell-project 0.0.0 put_etherboot_and_sis900_pxe().
231 put_free_dos_imgscip-shell shell shell-project 0.0.0 put_free_dos_img().
232 #
233 put_pxelinux_multi_arch_filesscip-shell shell shell-project 0.0.0 put_pxelinux_multi_arch_files().
234 link_pxelinux_bios_arch_filesscip-shell shell shell-project 0.0.0 link_pxelinux_bios_arch_files().
235 put_pxelinux_memdiskscip-shell shell shell-project 0.0.0 put_pxelinux_memdisk().
236 #
237 gen_pxe_boot_menuscip-shell shell shell-project 0.0.0 gen_pxe_boot_menu().
238 fi
239
240 ### Deal with GRUB EFI NB ###
241 # //NOTE// This will overwrite the bootx64.efi and bootia32.efi
242 # from syslinux in the previous steps. i.e. now we force to use
243 # that from grub2 because it's more mature than syslinux 6.03.
244 drbl-gen-grub-efi-nb