| 1 | #!/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 | usage() { |
| 13 | echo "Update the DRBL client's kernel from server..." |
| 14 | echo "Usage: $0 [-u|--update] [-v|--verbose]" |
| 15 | echo "-u, --update: Update only (do not overwrite newer files)" |
| 16 | echo "-v, --verbose: Prints out verbose information" |
| 17 | echo |
| 18 | echo "Ex:" |
| 19 | echo "$0 -u -v" |
| 20 | } |
| 21 | |
| 22 | # |
| 23 | check_if_root |
| 24 | |
| 25 | # default settings |
| 26 | RSYNC_OPT_EXTRA="" |
| 27 | depmod_stderr="/dev/null" |
| 28 | |
| 29 | while [ $# -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 | -*) echo "${0}: ${1}: invalid option" >&2 |
| 42 | usage >& 2 |
| 43 | exit 2 ;; |
| 44 | *) break ;; |
| 45 | esac |
| 46 | done |
| 47 | |
| 48 | # |
| 49 | if [ "$verbose" = "on" ]; then |
| 50 | # The default output for depmod is surpressed, now turn it on |
| 51 | depmod_stderr="/dev/stderr" |
| 52 | fi |
| 53 | |
| 54 | # copy the modules for clients, to $drbl_common_root/lib/modules |
| 55 | DRBL_KVER="$(cat $pxecfg_pd/kernel_version_in_initrd.txt 2>/dev/null)" |
| 56 | KARCH_CLIENT="$(cat $pxecfg_pd/client_kernel_arch.txt 2>/dev/null)" |
| 57 | if [ -n "$DRBL_KVER" ]; then |
| 58 | echo "The DRBL client uses $KARCH_CLIENT kernel with version $DRBL_KVER..." |
| 59 | else |
| 60 | echo "Warning! Unable to find the kernel version information for DRBL clients!" |
| 61 | echo "Are you sure you already run \"drblsrv -i\" ?" |
| 62 | echo "Press \"Enter\" to continue..." |
| 63 | read |
| 64 | fi |
| 65 | |
| 66 | [ -z "$KARCH_CLIENT" ] && echo "Unable to find the DRBL client's arch info!!! Did you run \"drblsrv -i\" ? Program terminated!!!" && exit 1 |
| 67 | |
| 68 | # |
| 69 | 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 [ ! -d $drbl_common_root/lib/modules/ ]; then |
| 73 | [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 74 | echo "Warning!!! Directory $drbl_common_root/lib/modules/ does NOT exists!!! Did you already install the necessary packages for DRBL ? Skip copying modules!" |
| 75 | [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 76 | exit 2 |
| 77 | fi |
| 78 | |
| 79 | # |
| 80 | if [ -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 [ "$FORCE_UPDATE" != "yes" ]; then |
| 84 | KARCH_SERVER="$(drbl-check-kernel-cpu-arch $DRBL_KVER)" |
| 85 | [ -z "$KARCH_SERVER" ] && 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 [ "$FORCE_UPDATE" = "yes" -o "$KARCH_CLIENT" = "best_optimization" -o "$KARCH_SERVER" = "$KARCH_CLIENT" ]; then |
| 90 | # TODO... if force, the KARCH_SERVER maybe "nothing". |
| 91 | 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 [ -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 | echo "Syncing /lib/modules/$DRBL_KVER to client's common root..." |
| 105 | rsync -a $RSYNC_OPT_EXTRA /lib/modules/$DRBL_KVER $drbl_common_root/lib/modules/ |
| 106 | fi |
| 107 | if ls /boot/*-$DRBL_KVER* >/dev/null 2>&1; then |
| 108 | # (b) for kernel, i.e. vmlinuz and initrd... |
| 109 | echo "Syncing /boot/*-$DRBL_KVER* to client's common root..." |
| 110 | rsync -a $RSYNC_OPT_EXTRA /boot/*-$DRBL_KVER* $drbl_common_root/boot |
| 111 | fi |
| 112 | # |
| 113 | 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 | [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 117 | 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 | [ "$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 | 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 | rsync -a $RSYNC_OPT_EXTRA /boot/*-2.[46].[0-9]* $drbl_common_root/boot |
| 127 | fi |
| 128 | |
| 129 | # Update firmwares |
| 130 | if [ -d "/lib/firmware" ]; then |
| 131 | echo "Syncing /lib/firmware/ to client's common root..." |
| 132 | rsync -a $RSYNC_OPT_EXTRA /lib/firmware $drbl_common_root/lib/ |
| 133 | fi |
| 134 | |
| 135 | exit 0 |