Debian Codegraph @

sbin/drblsrv-offline

raw symbols SCIP
1 #!/bin/bash
2 # Author: Steven Shiau <steven _at_ clonezilla org>, Ceasar Sun <ceasar _at_ nchc ogr tw>
3 # License: GPL
4
5 # Load DRBL setting and functions
6 DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"
7 . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
8
9 #
10 USAGE() {
11 echo "Usage: $0 [OPTION]"
12 echo "OPTION"
13 language_help_prompt_by_idx_no
14 echo "-o, --console-output OPT: Set the console output parameters."
15 echo "-i, --pxe-serial-output OPT: Set the PXE menu to work with serial console output."
16 echo "-k, --client-kernel-pkg KERNEL_PKG: Specify the KERNEL_PKG (rpm or deb) which you want DRBL client to use."
17 echo "-e, --extra-client-kernel-pkg EXTRA_KERNEL_PKG: Specify the extra KERNEL_PKG (rpm or deb) which you want DRBL client to use. Usually this is specially for Ubuntu linux-restricted-modules and SuSE kernel-default-nongpl. Must use this with option -k|--client-kernel-pkg."
18 echo "-s, --client-kernel-ver-from-server KERNEL_VER: Use the kernel version KERNEL_VER from server, i.e. from /boot/vmlinuz-KERNEL_VER and /usr/lib/modules/KERNEL_VER..."
19 echo "-c, --no-required-pkgs-check: Force NOT to check the required packages, assume they are installed."
20 echo "-a, --no-prompt-different-arch-pkgs: Force NOT to show the messages about different architecture packages re-installation in the different CPU arch for server and client."
21 echo "-p, --skip-client-kernel-install: Force NOT to install the kernel for client. This option is used when a kernel for client already exists."
22 echo "-r, --only-show-required-pkgs: Do noting, just show the necessary packages."
23 echo "-d, --dev-for-client-is-ready: Dev files are already ready for clients, do not let $0 check it again."
24 echo "-v, --verbose: Prints verbose information"
25 } # end of USAGE
26
27 check_debian_dev_for_client() {
28 echo "$msg_delimiter_star_line"
29 # dev for client machines
30 # For Debian woody & B2D pureKDE20050603..It's necessary to make one before run
31 # this... (Just create the tarball from some Debian machine)
32 # It's ugly here...
33 # The solution: Make udev as the 1st priority
34 [ ! -d $drbl_pkgdir ] && mkdir -p $drbl_pkgdir
35
36 if ! chk_deb_installed udev; then
37 # udev is not available, use tarball
38 if [ -f $drbl_setup_path/files/$OS_Version/dev.$OS_Version.tgz ]; then
39 echo "Udev is not available, use pre-packaged device files."
40 cp -f $drbl_setup_path/files/$OS_Version/dev.$OS_Version.tgz $drbl_pkgdir/dev.tgz
41 else
42 [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
43 echo "No udev, and no pre-packaged device files!!! Program terminated!"
44 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
45 exit 1
46 fi
47 fi
48 } # end of check_debian_dev_for_client
49
50 check_required_pkgs() {
51 echo "$msg_delimiter_star_line"
52 eval PKG_FROM_OS=\$PKG_FROM_${OS_type}
53 echo "$msg_necessary_pkgs_from_dists"
54 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
55 echo "$PKG_FROM_OS $PKG_DEV"
56 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
57 echo "$msg_delimiter_star_line"
58 echo "$msg_necessary_pkgs_from_drbl"
59 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
60 echo "$PKG_FROM_DRBL"
61 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
62 echo "$msg_delimiter_star_line"
63 echo "$msg_recommended_pkgs_from_dists"
64 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
65 echo "$PKG_TO_QUERY"
66 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
67 # if it's only show required packages, we exit here.
68 [ "$only_show_required_pkgs" = "yes" ] && exit 0
69 echo "$msg_delimiter_star_line"
70 echo -n "$msg_press_ctrl_c_stop Or $msg_press_enter_to_continue "
71 read
72 echo "Check if they are installed... "
73 pkg_not_installed=""
74 ret=0
75 for ipkg in $PKG_FROM_OS $PKG_FROM_DRBL $PKG_DEV; do
76 echo -n "Checking $ipkg... "
77 if ! $query_pkglist_exist_cmd $ipkg &>/dev/null; then
78 pkg_not_installed="$pkg_not_installed $ipkg"
79 ret=$((ret + 1))
80 [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
81 echo "NOT installed!"
82 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
83 else
84 [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS
85 echo "installed."
86 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
87 fi
88 done
89 if [ "$ret" -gt 0 ]; then
90 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
91 echo "$msg_some_required_pkgs_not_installed: $pkg_not_installed."
92 echo "$msg_use_drblsrv_instead"
93 echo "$msg_continue_may_not_work"
94 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
95 echo "$msg_are_u_sure_u_want_to_continue"
96 echo -n "[y/N] "
97 read continue_run_ans
98 case "$continue_run_ans" in
99 y|Y|[yY][eE][sS])
100 echo "$msg_ok_let_do_it"
101 ;;
102 *)
103 echo "$msg_program_stop"
104 exit 1
105 ;;
106 esac
107 fi
108 } # end of check_required_pkgs
109 #
110 check_installed_pkgs_arch() {
111 echo "$msg_delimiter_star_line"
112 case "$OS_type" in
113 RH)
114 echo -n "Checking the installed packages of different arch..."
115 reinstall_pkg=""
116 for ipkg in $i686_pkg_check_list_RH_like; do
117 if rpm -q $ipkg &>/dev/null; then
118 echo -n "."
119 installed_pkg="$(rpm -qa | grep -E "^${ipkg}-[0-9]" | pkg-ver-latest)"
120 reinstall_pkg="$reinstall_pkg $installed_pkg.i386.rpm"
121 fi
122 done
123 echo " done!"
124 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
125 echo "$msg_install_glibc_etc_arch_by_yourself"
126 echo "rpm -Uvh --force $reinstall_pkg"
127 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
128 echo -n "$msg_press_ctrl_c_stop Or $msg_press_enter_to_continue"
129 read
130 ;;
131 SUSE)
132 echo -n "Checking the installed packages of different arch..."
133 reinstall_pkg=""
134 for ipkg in $i686_pkg_check_list_SUSE; do
135 if rpm -q $ipkg &>/dev/null; then
136 echo -n "."
137 installed_pkg=`rpm -qa | grep ^${ipkg}-[0-9]`
138 reinstall_pkg="$reinstall_pkg $installed_pkg.i586.rpm"
139 fi
140 done
141 echo " done!"
142 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
143 echo "$msg_install_glibc_etc_arch_by_yourself"
144 echo "rpm -Uvh --force $reinstall_pkg"
145 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
146 echo -n "$msg_press_ctrl_c_stop Or $msg_press_enter_to_continue"
147 read
148 ;;
149 MDK|MDV|DBN)
150 # Not necessary, since only single arch package in this distribution
151 true
152 ;;
153 esac
154 } # end of check_installed_pkgs_arch
155 #
156 install_kernel_for_client_func() {
157 echo "$msg_delimiter_star_line"
158 echo "$msg_install_kernel_for_clients ... "
159 case "$client_krn_mode" in
160 "from_pkg")
161 echo "The kernel for client is from specific package $client_kernel_pkg."
162 install-kernel-for-client $verbose_opt -l $lang -k $client_kernel_pkg
163 rc=$?
164 # We install the extra kernel package (linux-restricted-modules and linux-ubuntu-modules (from ubuntu 7.10) ) after the main kernel since if depmod is later, we will see some warning like:
165 # WARNING: /usr/lib/modules/2.6.17-10-386/madwifi/ath_rate_sample.ko needs unknown symbol ath_hal_computetxtime
166 # Ubuntu restricted kernel is mounted in /usr/lib/modules/$KVER/volatile/ when booting (/etc/init.d/linux-restricted-modules-common), and depmod will be run by /sbin/lrm-manager about the mounting.
167 # From ubuntu 7.10, another kernel module is linux-ubuntu-modules.
168 if [ -n "$extra_client_kernel_pkg" ]; then
169 for i in $extra_client_kernel_pkg; do
170 # FC 22 or later use kernel[-PAE]*-modules-*.rpm for extra modules
171 if [ -n "$(LC_ALL=C echo $i | grep -E 'linux-restricted-modules|kernel[-PAE]*-modules' )" ]; then
172 install_extra_opt="--just-cp-files"
173 else
174 install_extra_opt=""
175 fi
176 install-kernel-for-client $verbose_opt -l $lang $install_extra_opt -k $i
177 done
178 fi
179 ;;
180 "from_server")
181 echo "The kernel for client is copied from server."
182 install-kernel-for-client $verbose_opt -l $lang -s $client_kernel_ver_from_server
183 rc=$?
184 ;;
185 esac
186 # check if kernel installed successfully
187 if [ "$rc" -gt 0 ]; then
188 [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
189 echo "Failed to install the kernel for client!"
190 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
191 echo "$msg_program_stop"
192 exit 1
193 fi
194 } # end of install_kernel_for_client_func
195 #
196 check_input_kernel_param() {
197 if [ -n "$client_kernel_pkg" ]; then
198 # check if the kernel package exists
199 if [ ! -f "$client_kernel_pkg" ]; then
200 [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
201 echo "$client_kernel_pkg does NOT exist!!!"
202 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
203 echo "$msg_program_stop"
204 exit 1
205 fi
206 client_krn_mode="from_pkg"
207 echo "Kernel package $client_kernel_pkg is used for client..."
208 elif [ -n "$client_kernel_ver_from_server" -a \
209 -f /boot/vmlinuz-$client_kernel_ver_from_server -a \
210 -d /usr/lib/modules/$client_kernel_ver_from_server ]; then
211 client_krn_mode="from_server"
212 echo "Using kernel from this server for client..."
213 else
214 [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
215 echo "You must provide the kernel package (rpm or deb) or the kernel in the server"
216 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
217 USAGE
218 exit 1
219 fi
220 # 1. $PKG_FROM_* and $PKG_FROM_DRBL are loaded from conf/drbl.conf
221 # TODO: how about kernel 2.4 ? no udev ? how to prompt them ?
222 # If the kernel is version 2.6 for client, we must use udev.
223 # For package name, like: linux-image-2.6.15-26-686_2.6.15-26.46_i386.deb
224 # FC5: kernel-2.6.17-1.2174_FC5.i686.rpm
225 # RH9: kernel#2.4.20-46.9.legacy_2.4.20-46.9.legacy_i586.rpm
226 # For kernel version like: 2.6.15-26-386
227 if [ -n "$(echo $client_kernel_pkg | grep -iE "[_-][[:digit:]]+\.[[:digit:]]+")" -o \
228 -n "$(echo $client_kernel_ver_from_server | grep -iE "^[[:digit:]]+\.[[:digit:]]+")" ]; then
229 PKG_DEV="udev"
230 else
231 if [ "$dev_for_client_is_ready" = "no" ]; then
232 [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
233 echo "This script `basename $0` only works in kernel 2.6 or 3 or later with udev supported! The running kernel for client is not kernel 2.6 or 3 or later! Program terminated!"
234 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
235 exit 1
236 fi
237 fi
238 } # end of check_input_kernel_param
239
240
241 #################
242 #### Main ####
243 #################
244 # some default settings
245 required_pkgs_check="yes"
246 prompt_different_arch_pkgs="yes"
247 install_client_kernel="yes"
248 only_show_required_pkgs="no"
249 dev_for_client_is_ready="no"
250 extra_client_kernel_pkg=""
251
252 # Parse command-line options
253 while [ $# -gt 0 ]; do
254 case "$1" in
255 -l|--language)
256 shift
257 if [ -z "$(echo $1 |grep ^-.)" ]; then
258 # skip the -xx option, in case
259 specified_lang="$1"
260 shift
261 fi
262 [ -z "$specified_lang" ] && USAGE && exit 1
263 ;;
264 -k|--client-kernel-pkg)
265 shift
266 if [ -z "$(echo $1 |grep ^-.)" ]; then
267 # skip the -xx option, in case
268 client_kernel_pkg="$1"
269 shift
270 fi
271 [ -z "$client_kernel_pkg" ] && USAGE && exit 1
272 ;;
273 -e|--extra-client-kernel-pkg)
274 shift
275 if [ -z "$(echo $1 |grep ^-.)" ]; then
276 # skip the -xx option, in case
277 extra_client_kernel_pkg="$extra_client_kernel_pkg $1"
278 shift
279 fi
280 [ -z "$extra_client_kernel_pkg" ] && USAGE && exit 1
281 ;;
282 -s|--client-kernel-ver-from-server)
283 shift
284 if [ -z "$(echo $1 |grep ^-.)" ]; then
285 # skip the -xx option, in case
286 client_kernel_ver_from_server="$1"
287 shift
288 fi
289 [ -z "$client_kernel_ver_from_server" ] && USAGE && exit 1
290 ;;
291 -o|--console-output)
292 shift
293 if [ -z "$(echo $1 |grep ^-.)" ]; then
294 # skip the -xx option, in case
295 CONSOLE_OUTPUT="$1"
296 shift
297 fi
298 [ -z "$CONSOLE_OUTPUT" ] && USAGE && exit 1
299 ;;
300 -i|--pxe-serial-output)
301 shift
302 if [ -z "$(echo $1 |grep ^-.)" ]; then
303 # skip the -xx option, in case
304 PXE_SERIAL_OUTPUT="$1"
305 shift
306 fi
307 [ -z "$PXE_SERIAL_OUTPUT" ] && USAGE && exit 1
308 ;;
309 -c|--no-required-pkgs-check)
310 required_pkgs_check="no"
311 shift;;
312 -a|--no-prompt-different-arch-pkgs)
313 prompt_different_arch_pkgs="no"
314 shift;;
315 -p|--skip-client-kernel-install)
316 install_client_kernel="no"
317 shift;;
318 -r|--only-show-required-pkgs)
319 only_show_required_pkgs="yes"
320 shift;;
321 -d|--dev-for-client-is-ready)
322 dev_for_client_is_ready="yes"
323 shift;;
324 -v|--verbose)
325 verbose="on"
326 verbose_opt="-v"
327 shift ;;
328 -*) echo "${0}: ${1}: invalid option" >&2
329 USAGE >& 2
330 exit 2 ;;
331 *) break ;;
332 esac
333 done
334
335 #
336 check_if_root
337
338 #
339 ask_and_load_lang_set $specified_lang
340
341 #
342 if [ "$install_client_kernel" = "yes" -a \
343 "$only_show_required_pkgs" = "no" ]; then
344 check_input_kernel_param
345 fi
346
347 # get the distribution name and type: OS_Version and OS_type
348 check_distribution_name
349 echo "$msg_delimiter_star_line"
350 echo "$msg_OS_version: $FULL_OS_Version"
351
352
353 # 0.
354 if [ "$required_pkgs_check" = "yes" ]; then
355 check_required_pkgs
356 fi
357
358 # 1.
359 if [ "$prompt_different_arch_pkgs" = "yes" ]; then
360 check_installed_pkgs_arch
361 fi
362
363 # 2021/9/27. Comment this since all the packages are installed by users. If not, then drblsrv should have taken care of that. Hence there is no need to run drbl-deb-preconf actually.
364 # # 2. Prepare some config to avoid some delay when installing packages. If user already install them, we will overwrite those setting when running drblpush.
365 # if [ "$OS_type" = "DBN" ]; then
366 # # We need to preconfig some packages, such as dhcp3-server, tftpd-hpa, nis so
367 # # it will not ask user to config. We will configure later in drblpush.
368 # drbl-deb-preconf
369 # fi
370
371 # 3.
372 [ ! -d $pxecfg_pd ] && mkdir -p $pxecfg_pd
373 [ ! -d $drbl_common_root ] && mkdir -p $drbl_common_root
374 [ ! -d $drblroot ] && mkdir -p -m 700 $drblroot
375 [ ! -d $drbl_pkgdir ] && mkdir -p $drbl_pkgdir
376
377 # do some tunning.
378 if [ "$OS_type" = "DBN" ]; then
379 check_debian_dev_for_client
380 fi
381
382 # 4.
383 if [ "$install_client_kernel" = "yes" ]; then
384 install_kernel_for_client_func
385 else
386 # the kernel for clients existed
387 client_krn_mode="existed"
388 echo "[-p|--skip-client-kernel-install] is assigned, assume the kernel for client already existed! Skip installing kernel for client!"
389 fi
390
391 # 5.
392 # Before running this function, we first check if memtest86+ and pxelinux exist in the drbl package repository ($memtest86_dir and $pxelinux_file)
393 if [ -z "$(ls -l $memtest86_dir/mt86+x* 2>/dev/null)" ]; then
394 drbl-prepare-memtest
395 fi
396 # Here we check both pxelinux.0, gpxelinux.0 and lpxelinux.0. Since if older version of syslinux is installed (e.g. 3.7 in CentOS 5), no gpxelinux.0. However, if the user upgrade syslinux as 4.x after drblsrv-offline is run, drbl-prepare-pxelinux won't be run if not checking gpxelinux.0.
397 if [ ! -e "$pxelinux_file" -o ! -e "$gpxelinux_file" -o ! -e "$lpxelinux_file" ]; then
398 drbl-prepare-pxelinux
399 fi
400
401 # 6.
402 echo "$msg_delimiter_star_line"
403 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
404 echo "$msg_create_files_for_PXELINUX"
405 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
406 if [ -n "$CONSOLE_OUTPUT" ]; then
407 console_opt1="--console-output"
408 console_opt2="$CONSOLE_OUTPUT"
409 fi
410 if [ -n "$PXE_SERIAL_OUTPUT" ]; then
411 pxe_serial_opt1="--pxe-serial-output"
412 pxe_serial_opt2="$PXE_SERIAL_OUTPUT"
413 fi
414 prepare-files-for-PXE-client -l $lang $console_opt1 "$console_opt2" $pxe_serial_opt1 "$pxe_serial_opt2"
415
416 # 7.
417 # make the nbi/pxe files
418 echo "$msg_delimiter_star_line"
419 case "$client_krn_mode" in
420 "from_pkg")
421 if [ -n "$(file $client_kernel_pkg | grep -i RPM)" ]; then
422 client_kernel_ver="$(rpm -qpl $client_kernel_pkg | grep -E "^/boot/vmlinuz-" | sed -e "s|/boot/vmlinuz-||g")"
423 if [ -z "$client_kernel_ver" ]; then
424 # For OpenSuSE 11.1, kernel-default or kernel-pae, there is no vmlinuz-* file, try another method, i.e. use the path:
425 # /usr/lib/modules/2.6.27.7-9-default/...
426 client_kernel_ver="$(rpm -qpl $client_kernel_pkg | awk -F" " '{print $NF}' | awk -F"/" '/\/usr\/lib\/modules/ {print $4}' | sort | uniq)"
427 fi
428 elif [ -n "$(file $client_kernel_pkg | grep -i "Debian binary package")" ]; then
429 client_kernel_ver="$(dpkg --contents $client_kernel_pkg | awk -F" " '{print $NF}' | grep -E "./boot/vmlinuz-" | sed -e "s|\./boot/vmlinuz-||g")"
430 if [ -z "$client_kernel_ver" ]; then
431 # For deb linux-modules-*, there is no vmlinuz-* file, try another method, i.e. from dpkg-deb -f:
432 client_kernel_ver="$(dpkg-deb -f $client_kernel_pkg Package | sed 's/^linux-modules-//')"
433 fi
434 fi
435 drbl-gen-pxe-nbi -l $lang -k $client_kernel_ver
436 #
437 if [ -x /etc/init.d/linux-restricted-modules-common ]; then
438 # Create mount point $drbl_common_root/usr/lib/modules/$KERNEL_VER/volatile so that in Ubuntu with linux-restricted-modules, linux-restricted-modules-common service (which we will modify in drblpush so that it will use tmpfs otherwise it is Read-Only NFS filesystem) will need this.
439 mkdir -p $drbl_common_root/usr/lib/modules/$client_kernel_ver/volatile
440 fi
441 ;;
442 "from_server")
443 drbl-gen-pxe-nbi -l $lang -k $client_kernel_ver_from_server
444 ;;
445 "existed")
446 # not from server, not from pkg, kernel must already exists for client
447 drbl-gen-pxe-nbi -l $lang
448 ;;
449 esac
450
451 echo "$msg_delimiter_star_line"
452 echo "$msg_Done!"