| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | # Author: Steven Shiau <steven _at_ clonezilla org> |
| 3 | # license: GPL |
| 4 | # Description: update the kernel of DRBL clients from server's kernel |
| 5 | # RC: 0: succeed 1: fail 2:fail (can not find the common_root/lib/modules |
| 6 | |
| 7 | # Load DRBL setting and functions |
| 8 | DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}" |
| 9 | . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions |
| 10 | |
| 11 | # |
| 12 | usagescip-shell shell shell-project 0.0.0 usage().() { |
| 13 | echoscip-shell system . . echo. "Update the DRBL client's kernel from server..." |
| 14 | echoscip-shell system . . echo. "Usage: $0 [-u|--update] [-v|--verbose]" |
| 15 | echoscip-shell system . . echo. "-u, --update: Update only (do not overwrite newer files)" |
| 16 | echoscip-shell system . . echo. "-v, --verbose: Prints out verbose information" |
| 17 | echoscip-shell system . . echo. |
| 18 | echoscip-shell system . . echo. "Ex:" |
| 19 | echoscip-shell system . . echo. "$0 -u -v" |
| 20 | } |
| 21 | |
| 22 | # |
| 23 | check_if_root |
| 24 | |
| 25 | # default settings |
| 26 | RSYNC_OPT_EXTRA="" |
| 27 | depmod_stderr="/dev/nullscip-shell filesystem . . `/dev/null`." |
| 28 | |
| 29 | while [scip-shell system . . `[`. $# -gt 0 ]; do |
| 30 | case "$1" in |
| 31 | -f|--force) |
| 32 | shift; FORCE_UPDATE="yes" |
| 33 | ;; |
| 34 | -u|--update) |
| 35 | shift; RSYNC_OPT_EXTRA="$RSYNC_OPT_EXTRA -u" |
| 36 | ;; |
| 37 | -v|--verbose) |
| 38 | verbose="on" |
| 39 | RSYNC_OPT_EXTRA="$RSYNC_OPT_EXTRA -v" |
| 40 | shift ;; |
| 41 | -*) echoscip-shell system . . echo. "${0}: ${1}: invalid option" >&2 |
| 42 | usagescip-shell shell shell-project 0.0.0 usage(). >& 2 |
| 43 | exit 2 ;; |
| 44 | *) break ;; |
| 45 | esac |
| 46 | done |
| 47 | |
| 48 | # |
| 49 | if [scip-shell system . . `[`. "$verbose" = "on" ]; then |
| 50 | # The default output for depmod is surpressed, now turn it on |
| 51 | depmod_stderr="/dev/stderrscip-shell filesystem . . `/dev/stderr`." |
| 52 | fi |
| 53 | |
| 54 | # copy the modules for clients, to $drbl_common_root/lib/modules |
| 55 | DRBL_KVER="$(catscip-shell system . . cat. $pxecfg_pd/kernel_version_in_initrd.txt 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" |
| 56 | KARCH_CLIENT="$(catscip-shell system . . cat. $pxecfg_pd/client_kernel_arch.txt 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" |
| 57 | if [scip-shell system . . `[`. -n "$DRBL_KVER" ]; then |
| 58 | echoscip-shell system . . echo. "The DRBL client uses $KARCH_CLIENT kernel with version $DRBL_KVER..." |
| 59 | else |
| 60 | echoscip-shell system . . echo. "Warning! Unable to find the kernel version information for DRBL clients!" |
| 61 | echoscip-shell system . . echo. "Are you sure you already run \"drblsrv -i\" ?" |
| 62 | echoscip-shell system . . echo. "Press \"Enter\" to continue..." |
| 63 | read |
| 64 | fi |
| 65 | |
| 66 | [scip-shell system . . `[`. -z "$KARCH_CLIENT" ] && echoscip-shell system . . echo. "Unable to find the DRBL client's arch info!!! Did you run \"drblsrv -i\" ? Program terminated!!!" && exit 1 |
| 67 | |
| 68 | # |
| 69 | echoscip-shell system . . echo. "Trying to update the $drbl_common_root/lib/modules/$DRBL_KVER from server's /lib/modules/... This might take several minutes..." |
| 70 | |
| 71 | # check if $drbl_common_root/lib/modules/ exists |
| 72 | if [scip-shell system . . `[`. ! -d $drbl_common_root/lib/modules/ ]; then |
| 73 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 74 | echoscip-shell system . . echo. "Warning!!! Directory $drbl_common_root/lib/modules/ does NOT exists!!! Did you already install the necessary packages for DRBL ? Skip copying modules!" |
| 75 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 76 | exit 2 |
| 77 | fi |
| 78 | |
| 79 | # |
| 80 | if [scip-shell system . . `[`. -n "$DRBL_KVER" ]; then |
| 81 | # found the kernel version info of clients, process the specific version |
| 82 | # check the kernel arch of server and client, if matches, copy them. |
| 83 | if [scip-shell system . . `[`. "$FORCE_UPDATE" != "yes" ]; then |
| 84 | KARCH_SERVER="$(drbl-check-kernel-cpu-arch $DRBL_KVER)" |
| 85 | [scip-shell system . . `[`. -z "$KARCH_SERVER" ] && echoscip-shell system . . echo. "\"$KARCH_CLIENT\" $DRBL_KVER kernel in this DRBL server is not found, so skip this." && exit 1 |
| 86 | fi |
| 87 | |
| 88 | # do it... |
| 89 | if [scip-shell system . . `[`. "$FORCE_UPDATE" = "yes" -o "$KARCH_CLIENT" = "best_optimization" -o "$KARCH_SERVER" = "$KARCH_CLIENT" ]; then |
| 90 | # TODO... if force, the KARCH_SERVER maybe "nothing". |
| 91 | echoscip-shell system . . echo. "Found kernel modules in /lib/modules/$DRBL_KVER and its arch \"$KARCH_SERVER\" matches client's \"$KARCH_CLIENT\"..." |
| 92 | # no matter directory $drbl_kernel_mod_path/lib/modules/$DRBL_KVER |
| 93 | # exits or not, (note! Here we do NOT use rsync --delete! So this |
| 94 | # will supply more files at most, not delete some.) |
| 95 | # we copy it to DRBL clients' common root directory, i.e. we force to |
| 96 | # update the kernel modules when run mknic-nbi |
| 97 | # (a) for modules |
| 98 | |
| 99 | if [scip-shell system . . `[`. -d "/lib/modules/$DRBL_KVER" -a -f "/lib/modules/$DRBL_KVER/modules.dep" ] ; then |
| 100 | # check if -f "/lib/modules/\$DRBL_KVER/modules.dep is important. |
| 101 | # this will avoid copying an empty kernel modules tree. just a better check. |
| 102 | # this will happen if we compiled a module and install it, when we |
| 103 | # remove the kernel by rpm -e ..., the /lib/modules/kernel-xxx will still exist. |
| 104 | echoscip-shell system . . echo. "Syncing /lib/modules/$DRBL_KVER to client's common root..." |
| 105 | rsyncscip-shell system . . rsync. -a $RSYNC_OPT_EXTRA /lib/modules/$DRBL_KVER $drbl_common_root/lib/modules/ |
| 106 | fi |
| 107 | if lsscip-shell system . . ls. /boot/*-$DRBL_KVER* >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1; then |
| 108 | # (b) for kernel, i.e. vmlinuz and initrd... |
| 109 | echoscip-shell system . . echo. "Syncing /boot/*-$DRBL_KVER* to client's common root..." |
| 110 | rsyncscip-shell system . . rsync. -a $RSYNC_OPT_EXTRA /boot/*-$DRBL_KVER* $drbl_common_root/boot |
| 111 | fi |
| 112 | # |
| 113 | echoscip-shell system . . echo. "Generating the $drbl_common_root/lib/modules/$DRBL_KVER/modules.dep" |
| 114 | depmod -ae -b $drbl_common_root/ -F $drbl_common_root/boot/System.map-$DRBL_KVER $DRBL_KVER 2> $depmod_stderr |
| 115 | else |
| 116 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 117 | echoscip-shell system . . echo. "The kernel $DRBL_KVER installed in this DRBL server is for \"$KARCH_SERVER\", while the DRBL client wants kernel with \"$KARCH_CLIENT\"! Skip this!" |
| 118 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 119 | fi |
| 120 | else |
| 121 | # if we can not find the tag, copy them all, this only works in Redhat, |
| 122 | # might be NOT work in Mandrake |
| 123 | # (a) for modules |
| 124 | rsyncscip-shell system . . rsync. -a $RSYNC_OPT_EXTRA /lib/modules/2.[46].[0-9]* $drbl_common_root/lib/modules/ |
| 125 | # (b) for kernel, i.e. vmlinuz and initrd... |
| 126 | rsyncscip-shell system . . rsync. -a $RSYNC_OPT_EXTRA /boot/*-2.[46].[0-9]* $drbl_common_root/boot |
| 127 | fi |
| 128 | |
| 129 | # Update firmwares |
| 130 | if [scip-shell system . . `[`. -d "/lib/firmwarescip-shell filesystem . . `/lib/firmware`." ]; then |
| 131 | echoscip-shell system . . echo. "Syncing /lib/firmware/ to client's common root..." |
| 132 | rsyncscip-shell system . . rsync. -a $RSYNC_OPT_EXTRA /lib/firmwarescip-shell filesystem . . `/lib/firmware`. $drbl_common_root/lib/ |
| 133 | fi |
| 134 | |
| 135 | exit 0 |