| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | # -*-Shell-script-*- |
| 3 | # Steven Shiau <steven _at_ clonezilla org> |
| 4 | # Ceasar Sun <ceasar dot sun _at_ gmail com> |
| 5 | # License: GPL |
| 6 | # |
| 7 | # Functions: This file contains functions to be used by most or all shell scripts in the DRBL environment |
| 8 | # |
| 9 | # //NOTE// Do NOT set the locale by "export LC_ALL=C". It will make dialog distortation. |
| 10 | |
| 11 | # Source DRBL setting |
| 12 | DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}" |
| 13 | . /etc/drbl/drbl.confscip-shell source . . `/etc/drbl/drbl.conf`. |
| 14 | |
| 15 | # Append a default search path. |
| 16 | # To make it like: |
| 17 | # PATH="$PATH:$DRBL_SCRIPT_PATH/sbin:$DRBL_SCRIPT_PATH/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin" |
| 18 | path_to_add="$DRBL_SCRIPT_PATH/sbin $DRBL_SCRIPT_PATH/bin /usr/sbin /usr/bin /sbin" |
| 19 | for i in $path_to_add; do |
| 20 | if [scip-shell system . . `[`. -z "$(echoscip-shell system . . echo. $PATH | grepscip-shell system . . grep. -Fw $i)" ]; then |
| 21 | PATH="$PATH:$i" |
| 22 | fi |
| 23 | done |
| 24 | export PATH |
| 25 | |
| 26 | # setup some parameters for color output. The variables should be already |
| 27 | # defined in the /etc/init.d/functions in RH-like distribution |
| 28 | |
| 29 | # Check if terminal supports colors output |
| 30 | colors_no="$(LC_ALL=C tputscip-shell system . . tput. colors 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" |
| 31 | |
| 32 | BOOTUP="" |
| 33 | if [scip-shell system . . `[`. -n "$colors_no" ]; then |
| 34 | if [scip-shell system . . `[`. "$colors_no" -ge 8 ]; then |
| 35 | [scip-shell system . . `[`. -z "$SETCOLOR_SUCCESS" ] && SETCOLOR_SUCCESS="echo -en \\033[1;32m" |
| 36 | [scip-shell system . . `[`. -z "$SETCOLOR_FAILURE" ] && SETCOLOR_FAILURE="echo -en \\033[1;31m" |
| 37 | [scip-shell system . . `[`. -z "$SETCOLOR_WARNING" ] && SETCOLOR_WARNING="echo -en \\033[1;33m" |
| 38 | [scip-shell system . . `[`. -z "$SETCOLOR_NORMAL" ] && SETCOLOR_NORMAL="echo -en \\033[0;39m" |
| 39 | BOOTUP="color" |
| 40 | fi |
| 41 | fi |
| 42 | |
| 43 | # some functions |
| 44 | # get OS type |
| 45 | get_os_typescip-shell shell shell-project 0.0.0 get_os_type().() { |
| 46 | case "$OS_Version" in |
| 47 | RH*|FC*|CO*) |
| 48 | OS_type="RH" |
| 49 | ;; |
| 50 | MD[KV]*) |
| 51 | OS_type="MDK" |
| 52 | ;; |
| 53 | DBN*) |
| 54 | OS_type="DBN" |
| 55 | ;; |
| 56 | SUSE*) |
| 57 | OS_type="SUSE" |
| 58 | ;; |
| 59 | *) |
| 60 | echoscip-shell system . . echo. "This version in this distribution is NOT supported by DRBL, maybe you can try to use the drbl in testing or unstable repository. Program terminated!" |
| 61 | exit 1 |
| 62 | esac |
| 63 | } # end of get OS type |
| 64 | |
| 65 | # |
| 66 | check_distribution_namescip-shell shell shell-project 0.0.0 check_distribution_name().() { |
| 67 | local VER |
| 68 | local DIST |
| 69 | local FULL_DIST |
| 70 | # Reset these values |
| 71 | OS_Version= |
| 72 | FULL_OS_Version= |
| 73 | # FULL_OS_Version is only used in the label |
| 74 | # like the files /tftpboot/nbi_img/pxelinux.cfg/* (default or 0A....). |
| 75 | # OS_Version is used in drblsrv and drblpush to judge the dist and version. |
| 76 | if [scip-shell system . . `[`. -f /etc/fedora-releasescip-shell filesystem . . `/etc/fedora-release`. ]; then |
| 77 | VER=$(rpm -qf /etc/fedora-releasescip-shell filesystem . . `/etc/fedora-release`. --qf "%{VERSION}" | sedscip-shell system . . sed. "s/[^0-9\.]//g") |
| 78 | DIST=FC |
| 79 | FULL_DIST=Fedora |
| 80 | elif [scip-shell system . . `[`. -f /etc/mandriva-releasescip-shell filesystem . . `/etc/mandriva-release`. ]; then |
| 81 | VER=$(rpm -qf /etc/mandriva-releasescip-shell filesystem . . `/etc/mandriva-release`. --qf "%{VERSION}" | sedscip-shell system . . sed. "s/[^0-9\.]//g") |
| 82 | DIST=MDV |
| 83 | FULL_DIST=Mandriva |
| 84 | elif [scip-shell system . . `[`. -f /etc/mandrake-releasescip-shell filesystem . . `/etc/mandrake-release`. ]; then |
| 85 | # /etc/mandrake-release must be after the /etc/mandriva-release, since the |
| 86 | # new Mandriva distributions has /etc/mandrake-release, too. |
| 87 | VER=$(rpm -qf /etc/mandrake-releasescip-shell filesystem . . `/etc/mandrake-release`. --qf "%{VERSION}" | sedscip-shell system . . sed. "s/[^0-9\.]//g") |
| 88 | if [scip-shell system . . `[`. "$VER" = "10.2" ]; then |
| 89 | # Exception: |
| 90 | # "Mandrakelinux release 10.2.*" /etc/mandrakelinux-release |
| 91 | # OS_Version="MDV2005" |
| 92 | DIST=MDV |
| 93 | FULL_DIST=Mandriva |
| 94 | VER=2005 |
| 95 | else |
| 96 | DIST=MDK |
| 97 | FULL_DIST=Mandrake |
| 98 | fi |
| 99 | elif [scip-shell system . . `[`. -e /etc/SuSE-releasescip-shell filesystem . . `/etc/SuSE-release`. ]; then |
| 100 | VER=$(rpm -qf /etc/SuSE-releasescip-shell filesystem . . `/etc/SuSE-release`. --qf "%{VERSION}" | sedscip-shell system . . sed. "s/[^0-9\.]//g") |
| 101 | DIST=SUSE |
| 102 | FULL_DIST=SuSE |
| 103 | elif [scip-shell system . . `[`. -f /etc/redhat-releasescip-shell filesystem . . `/etc/redhat-release`. ]; then |
| 104 | # /etc/redhat-release must be the last "elif" for RH-like dist, since there |
| 105 | # are so many distributions are based on RH, and do exist /etc/redhat-release |
| 106 | if grepscip-shell system . . grep. -q -i "CentOS" /etc/redhat-releasescip-shell filesystem . . `/etc/redhat-release`.; then |
| 107 | # The release of CentOS is a little difference, we can not use |
| 108 | # rpm -qf /etc/redhat-release --qf "%{VERSION}" to get the version, since |
| 109 | # we will get "4", but actually it's "4.2" or "4.1" |
| 110 | VER=$(catscip-shell system . . cat. /etc/redhat-releasescip-shell filesystem . . `/etc/redhat-release`. | sedscip-shell system . . sed. "s/[^0-9\.]//g") |
| 111 | DIST=CO |
| 112 | FULL_DIST=CentOS |
| 113 | elif grepscip-shell system . . grep. -q -i "Scientific Linux" /etc/redhat-releasescip-shell filesystem . . `/etc/redhat-release`.; then |
| 114 | # Scientific Linux |
| 115 | # To simplify that, we only support drblsrv-offline for Scientific Linux |
| 116 | # The DIST is set as CO for compatibility. |
| 117 | VER=$(catscip-shell system . . cat. /etc/redhat-releasescip-shell filesystem . . `/etc/redhat-release`. | sedscip-shell system . . sed. "s/[^0-9\.]//g") |
| 118 | DIST=CO |
| 119 | FULL_DIST=SL |
| 120 | elif grepscip-shell system . . grep. -q -i "OSSII" /etc/redhat-releasescip-shell filesystem . . `/etc/redhat-release`.; then |
| 121 | # The release of OSSII M6 Linux is like: |
| 122 | # OSSII M6 Linux |
| 123 | # To simplify that, we only support drblsrv-offline for OSSII |
| 124 | # The DIST is set as CO for compatibility, basically it's useless here. |
| 125 | VER=$(grepscip-shell system . . grep. -Eo "M[[:digit:]]" /etc/redhat-releasescip-shell filesystem . . `/etc/redhat-release`.) |
| 126 | DIST=CO |
| 127 | FULL_DIST=OSSII |
| 128 | else |
| 129 | # The last one... RedHat |
| 130 | # In some case, no idea why, when run this as root in RH9, it will crash |
| 131 | # [root]# rpm -qf --qf '%{VERSION}' /etc/redhat-release |
| 132 | # Segmentation fault |
| 133 | # So we do not use this: |
| 134 | #VER=$(rpm -qf /etc/redhat-release --qf "%{VERSION}" | sed "s/[^0-9\.]//g") |
| 135 | # We use this: |
| 136 | VER=$(catscip-shell system . . cat. /etc/redhat-releasescip-shell filesystem . . `/etc/redhat-release`. | sedscip-shell system . . sed. "s/[^0-9\.]//g") |
| 137 | DIST=RH |
| 138 | FULL_DIST=RedHat |
| 139 | fi |
| 140 | elif [scip-shell system . . `[`. -f /etc/debian_versionscip-shell filesystem . . `/etc/debian_version`. ]; then |
| 141 | DIST=DBN |
| 142 | FULL_DIST=Debian |
| 143 | # get the version |
| 144 | if grepscip-shell system . . grep. -qE "(testing/unstable|sid)" /etc/debian_versionscip-shell filesystem . . `/etc/debian_version`.; then |
| 145 | VER="-TU" |
| 146 | # Here we assign a better tag for FULL_OS_Version |
| 147 | FULL_OS_Version="Debian Testing-Unstable" |
| 148 | else |
| 149 | VER="$(catscip-shell system . . cat. /etc/debian_versionscip-shell filesystem . . `/etc/debian_version`.)" |
| 150 | fi |
| 151 | # Overwrite the FULL_OS_Version if others are found. Especially for Ubuntu |
| 152 | if [scip-shell system . . `[`. -e /etc/lsb-releasescip-shell filesystem . . `/etc/lsb-release`. ]; then |
| 153 | . /etc/lsb-releasescip-shell source . . `/etc/lsb-release`. |
| 154 | FULL_OS_Version="$DISTRIB_ID $DISTRIB_RELEASE" |
| 155 | fi |
| 156 | fi |
| 157 | |
| 158 | if [scip-shell system . . `[`. -z "$DIST" -o -z "$VER" ]; then |
| 159 | echoscip-shell system . . echo. "The distribution or version is unknown! Program terminated!" |
| 160 | exit 1 |
| 161 | fi |
| 162 | # If not assigned, assign it |
| 163 | [scip-shell system . . `[`. -z "$OS_Version" ] && OS_Version="${DIST}${VER}" |
| 164 | [scip-shell system . . `[`. -z "$OS_DIST" ] && OS_DIST="${DIST}" |
| 165 | [scip-shell system . . `[`. -z "$FULL_OS_Version" ] && FULL_OS_Version="${FULL_DIST} ${VER}" |
| 166 | |
| 167 | # get the OS_type variable |
| 168 | get_os_typescip-shell shell shell-project 0.0.0 get_os_type(). |
| 169 | # |
| 170 | # echo $OS_Version |
| 171 | } # end of check_distribution_name |
| 172 | |
| 173 | # create the shared library program runtime env. |
| 174 | # ldd might give these 3 type results: |
| 175 | # 1. newer version (FC3): |
| 176 | # ldd /sbin/depmod |
| 177 | # libc.so.6 => /lib/libc.so.6 (0x00a08000) |
| 178 | # /lib/ld-linux.so.2 (0x009f1000) |
| 179 | # 2. older version (RH8/9,FC1/2): |
| 180 | # ldd /sbin/depmod |
| 181 | # libc.so.6 => /lib/libc.so.6 (0x40025000) |
| 182 | # /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000) |
| 183 | # 3. MDK10 |
| 184 | # linux-gate.so.1 => (0xffffe000) |
| 185 | # libc.so.6 => /lib/tls/libc.so.6 (0x40028000) |
| 186 | # /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000) |
| 187 | #RH9: |
| 188 | #libc.so.6 => /lib/libc.so.6 (0x40025000) |
| 189 | #/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000) |
| 190 | #FC1: |
| 191 | #libc.so.6 => /lib/libc.so.6 (0x00a35000) |
| 192 | #/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x00a20000) |
| 193 | #FC2: |
| 194 | #libc.so.6 => /lib/libc.so.6 (0x00b76000) |
| 195 | #linux.so.2 => /lib/ld-linux.so.2 (0x00b61000) |
| 196 | #FC3: |
| 197 | #libc.so.6 => /lib/tls/i686/libc.so.6 (0x007b3000) |
| 198 | #linux.so.2 (0x0079c000) |
| 199 | #mdk10: |
| 200 | #linux-gate.so.1 => (0xffffe000) |
| 201 | #libc.so.6 => /lib/tls/libc.so.6 (0x40028000) |
| 202 | #/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000) |
| 203 | |
| 204 | create_depmod_envscip-shell shell shell-project 0.0.0 create_depmod_env().() { |
| 205 | # This function is useless from drbl 1.7.6-23 or later, since we use |
| 206 | # depmod -b baseroot/ instead of chroot. |
| 207 | # However, we still keep this for ref. |
| 208 | local newroot="$1" |
| 209 | [scip-shell system . . `[`. -z "$newroot" ] && exit 1 |
| 210 | # some distribution, like Mandriva, use link in /sbin/depmod, so we clean it |
| 211 | # to avoid some error. |
| 212 | [scip-shell system . . `[`. -e "$newroot/sbin/depmod" ] && rmscip-shell system . . rm. -f $newroot/sbin/depmod |
| 213 | # -L: always follow symbolic links |
| 214 | cpscip-shell system . . cp. -L --parents /sbin/depmod* $newroot |
| 215 | export DESTDIR="$newroot" |
| 216 | if lddscip-shell system . . ldd. /sbin/depmodscip-shell filesystem . . `/sbin/depmod`. &>/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 217 | depmod_lib_need=$(LC_ALL=C lddscip-shell system . . ldd. /sbin/depmodscip-shell filesystem . . `/sbin/depmod`. | sedscip-shell system . . sed. -e "s/.*=> //g" -e "s/(0x.*)//g" | awkscip-shell system . . awk. '{print $1}') |
| 218 | for imod in $depmod_lib_need; do |
| 219 | # Skip linux-vdso.so.1 and linux-gate.so.1, the virtual DSO, a shared object exposed by the kernel. They do not exist on the file system. Ref: http://ilivetoseek.wordpress.com/2011/10/24/linux-gate-so-1-or-linux-vdso-so-1/ |
| 220 | [scip-shell system . . `[`. "$imod" = "linux-vdso.so.1" ] && continue |
| 221 | [scip-shell system . . `[`. "$imod" = "linux-gate.so.1" ] && continue |
| 222 | #cp --parents -d $imod $newroot |
| 223 | copy_exec_drblscip-shell shell shell-project 0.0.0 copy_exec_drbl(). $imod "$(LC_ALL=C dirnamescip-shell system . . dirname. $imod)" |
| 224 | done |
| 225 | fi |
| 226 | } |
| 227 | clean_depmod_envscip-shell shell shell-project 0.0.0 clean_depmod_env().() { |
| 228 | # This function is useless from drbl 1.7.6-23 or later, since we use |
| 229 | # depmod -b baseroot/ instead of chroot. |
| 230 | # However, we still keep this for ref. |
| 231 | local newroot="$1" |
| 232 | [scip-shell system . . `[`. -z "$newroot" ] && exit 1 |
| 233 | [scip-shell system . . `[`. -f $newroot/sbin/depmod ] && rmscip-shell system . . rm. -f $newroot/sbin/depmod |
| 234 | # for MDK 9.2, there is another depmod.old... |
| 235 | [scip-shell system . . `[`. -f $newroot/sbin/depmod.old ] && rmscip-shell system . . rm. -f $newroot/sbin/depmod.old |
| 236 | if lddscip-shell system . . ldd. /sbin/depmodscip-shell filesystem . . `/sbin/depmod`. &>/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 237 | depmod_lib_need=$(LC_ALL=C lddscip-shell system . . ldd. /sbin/depmodscip-shell filesystem . . `/sbin/depmod`. | sedscip-shell system . . sed. -e "s/.*=> //g" -e "s/(0x.*)//g" | awkscip-shell system . . awk. '{print $1}') |
| 238 | for f2rm in $depmod_lib_need; do |
| 239 | [scip-shell system . . `[`. -f "$newroot/$f2rm" ] && rmscip-shell system . . rm. -f $newroot/$f2rm |
| 240 | done |
| 241 | fi |
| 242 | } |
| 243 | |
| 244 | # function to create chkconfig environment |
| 245 | create_chkconfig_envscip-shell shell shell-project 0.0.0 create_chkconfig_env().() { |
| 246 | local newroot="$1" |
| 247 | [scip-shell system . . `[`. -z "$newroot" ] && exit 1 |
| 248 | cpscip-shell system . . cp. --parents /sbin/chkconfigscip-shell filesystem . . `/sbin/chkconfig`. $newroot |
| 249 | export DESTDIR="$newroot" |
| 250 | if lddscip-shell system . . ldd. /sbin/chkconfigscip-shell filesystem . . `/sbin/chkconfig`. &>/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 251 | chkconfig_lib_need=$(LC_ALL=C lddscip-shell system . . ldd. /sbin/chkconfigscip-shell filesystem . . `/sbin/chkconfig`. | sedscip-shell system . . sed. -e "s/.*=> //g" -e "s/(0x.*)//g" | awkscip-shell system . . awk. '{print $1}') |
| 252 | for imod in $chkconfig_lib_need; do |
| 253 | # Skip linux-vdso.so.1 and linux-gate.so.1, the virtual DSO, a shared object exposed by the kernel. They do not exist on the file system. Ref: http://ilivetoseek.wordpress.com/2011/10/24/linux-gate-so-1-or-linux-vdso-so-1/ |
| 254 | [scip-shell system . . `[`. "$imod" = "linux-vdso.so.1" ] && continue |
| 255 | [scip-shell system . . `[`. "$imod" = "linux-gate.so.1" ] && continue |
| 256 | #cp --parents -d $imod $newroot |
| 257 | copy_exec_drblscip-shell shell shell-project 0.0.0 copy_exec_drbl(). $imod "$(LC_ALL=C dirnamescip-shell system . . dirname. $imod)" |
| 258 | done |
| 259 | fi |
| 260 | } |
| 261 | |
| 262 | # function to clean chkconfig environment |
| 263 | clean_chkconfig_envscip-shell shell shell-project 0.0.0 clean_chkconfig_env().() { |
| 264 | local newroot="$1" |
| 265 | [scip-shell system . . `[`. -z "$newroot" ] && exit 1 |
| 266 | chkconfig_lib_need=$(LC_ALL=C lddscip-shell system . . ldd. /sbin/chkconfigscip-shell filesystem . . `/sbin/chkconfig`. | sedscip-shell system . . sed. -e "s/.*=> //g" -e "s/(0x.*)//g" | awkscip-shell system . . awk. '{print $1}') |
| 267 | [scip-shell system . . `[`. -f $newroot/sbin/chkconfig ] && rmscip-shell system . . rm. -f $newroot/sbin/chkconfig |
| 268 | for f2rm in $chkconfig_lib_need; do |
| 269 | [scip-shell system . . `[`. -f $newroot/$f2rm ] && rmscip-shell system . . rm. -f $newroot/$f2rm |
| 270 | done |
| 271 | } |
| 272 | |
| 273 | # function to create insserv environment |
| 274 | create_insserv_envscip-shell shell shell-project 0.0.0 create_insserv_env().() { |
| 275 | local newroot="$1" |
| 276 | [scip-shell system . . `[`. -z "$newroot" ] && exit 1 |
| 277 | cpscip-shell system . . cp. --parents -d /sbin/insservscip-shell filesystem . . `/sbin/insserv`. $newroot |
| 278 | export DESTDIR="$newroot" |
| 279 | if lddscip-shell system . . ldd. /sbin/insservscip-shell filesystem . . `/sbin/insserv`. &>/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 280 | insserv_lib_need=$(LC_ALL=C lddscip-shell system . . ldd. /sbin/insservscip-shell filesystem . . `/sbin/insserv`. | sedscip-shell system . . sed. -e "s/.*=> //g" -e "s/(0x.*)//g" | awkscip-shell system . . awk. '{print $1}') |
| 281 | for imod in $insserv_lib_need; do |
| 282 | # Skip linux-vdso.so.1 and linux-gate.so.1, the virtual DSO, a shared object exposed by the kernel. They do not exist on the file system. Ref: http://ilivetoseek.wordpress.com/2011/10/24/linux-gate-so-1-or-linux-vdso-so-1/ |
| 283 | [scip-shell system . . `[`. "$imod" = "linux-vdso.so.1" ] && continue |
| 284 | [scip-shell system . . `[`. "$imod" = "linux-gate.so.1" ] && continue |
| 285 | #cp --parents -d $imod $newroot |
| 286 | copy_exec_drblscip-shell shell shell-project 0.0.0 copy_exec_drbl(). $imod "$(LC_ALL=C dirnamescip-shell system . . dirname. $imod)" |
| 287 | done |
| 288 | fi |
| 289 | } |
| 290 | # Check if root or not |
| 291 | check_if_rootscip-shell shell shell-project 0.0.0 check_if_root().() { |
| 292 | if [scip-shell system . . `[`. ! "$UID" = "0" ]; then |
| 293 | echoscip-shell system . . echo. |
| 294 | echoscip-shell system . . echo. "[$LOGNAME] You need to run this script \"`basenamescip-shell system . . basename. $0`\" as root." |
| 295 | echoscip-shell system . . echo. |
| 296 | exit 1 |
| 297 | fi |
| 298 | } |
| 299 | |
| 300 | # function to get the autologin_account |
| 301 | # input is the host dir, like /tftpboot/nodes/192.168.1.1, then |
| 302 | # return the auto_login ID |
| 303 | get_autologin_accountscip-shell shell shell-project 0.0.0 get_autologin_account().() { |
| 304 | local ihost="$1" |
| 305 | local ip HOSTNAME |
| 306 | # $auto_login_id and $echo_no_digit_0_1 are global variables |
| 307 | # auto login username is set as hostname, i.e. use client's hostname as the auto-login ID. |
| 308 | # Reset variable auto_login_id |
| 309 | auto_login_id="" |
| 310 | if [scip-shell system . . `[`. -e /etc/debian_versionscip-shell filesystem . . `/etc/debian_version`. ]; then |
| 311 | # Debian |
| 312 | auto_login_id="$(catscip-shell system . . cat. $ihost/etc/hostname 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" |
| 313 | elif [scip-shell system . . `[`. -e /etc/SuSE-releasescip-shell filesystem . . `/etc/SuSE-release`. ]; then |
| 314 | # SuSE |
| 315 | auto_login_id="$(catscip-shell system . . cat. $ihost/etc/HOSTNAME 2>/dev/nullscip-shell filesystem . . `/dev/null`. | sedscip-shell system . . sed. -e "s/\..*//g")" |
| 316 | else |
| 317 | # RH-like |
| 318 | if [scip-shell system . . `[`. -e $ihost/$SYSCONF_PATH/network ]; then |
| 319 | HOSTNAME="" |
| 320 | . $ihost/$SYSCONF_PATH/network |
| 321 | auto_login_id="$HOSTNAME" |
| 322 | fi |
| 323 | fi |
| 324 | # if no hostname, such as in DRBL SSI mode, try to map the hostname from $IP_HOST_TABLE |
| 325 | if [scip-shell system . . `[`. -z "$auto_login_id" ]; then |
| 326 | ip="$(basenamescip-shell system . . basename. $ihost)" |
| 327 | auto_login_id="$(awkscip-shell system . . awk. -F" " "/^$ip[[:space:]]+/ {print \$2}" $IP_HOST_TABLE)" |
| 328 | fi |
| 329 | |
| 330 | # Added by Ceasar: |
| 331 | # auto-login account can be defined via: /etc/drbl/auto_login_host_id_passwd.txt |
| 332 | # Read /etc/drbl/auto_login_host_id_passwd.example as sample |
| 333 | auto_login_host_id_passwd_file="/etc/drbl/auto_login_host_id_passwd.txtscip-shell filesystem . . `/etc/drbl/auto_login_host_id_passwd.txt`." |
| 334 | _tmp_auto_login_id="$(LC_ALL=C awkscip-shell system . . awk. -v auto_login_id="$auto_login_id" '{if ($1 == auto_login_id ) {print $2}}' $auto_login_host_id_passwd_file 2>/dev/nullscip-shell filesystem . . `/dev/null`. )" |
| 335 | _tmp_auto_login_passwd="$(LC_ALL=C awkscip-shell system . . awk. -v auto_login_id="$auto_login_id" '{if ($1 == auto_login_id ) {print $3}}' $auto_login_host_id_passwd_file 2>/dev/nullscip-shell filesystem . . `/dev/null`. )" |
| 336 | |
| 337 | if [scip-shell system . . `[`. -n "$_tmp_auto_login_id" ] ; then |
| 338 | auto_login_id="$_tmp_auto_login_id" |
| 339 | password_opt="$_tmp_auto_login_passwd" |
| 340 | fi |
| 341 | } |
| 342 | # only show existing autologin account |
| 343 | get_existing_autologin_accountscip-shell shell shell-project 0.0.0 get_existing_autologin_account().() { |
| 344 | local ihost="$1" |
| 345 | get_autologin_accountscip-shell shell shell-project 0.0.0 get_autologin_account(). $ihost |
| 346 | if grepscip-shell system . . grep. -q $auto_login_id /etc/passwdscip-shell filesystem . . `/etc/passwd`. ; then |
| 347 | # account $auto_login_id exists, show it |
| 348 | echoscip-shell system . . echo. "$auto_login_id" |
| 349 | fi |
| 350 | } |
| 351 | |
| 352 | # check switch if it is input correct as on or off |
| 353 | check_switch_on_offscip-shell shell shell-project 0.0.0 check_switch_on_off().() { |
| 354 | local switch="$1" |
| 355 | case "$switch" in |
| 356 | on|ON|[oO]|[nN]|off|OFF|[oO][fF][fF]) |
| 357 | truescip-shell system . . true.;; |
| 358 | "") |
| 359 | usage && exit 1 |
| 360 | ;; |
| 361 | *) |
| 362 | echoscip-shell system . . echo. "You must specify \"on\" or \"off\" !!! Program stop!!!" |
| 363 | exit 1 |
| 364 | ;; |
| 365 | esac |
| 366 | } |
| 367 | |
| 368 | # |
| 369 | create_authconfig_envscip-shell shell shell-project 0.0.0 create_authconfig_env().() { |
| 370 | local newroot="$1" |
| 371 | [scip-shell system . . `[`. -z "$newroot" ] && exit 1 |
| 372 | file_need="/usr/sbin/authconfig /usr/sbin/pwconv /usr/sbin/grpconvscip-shell filesystem . . `/usr/sbin/authconfig /usr/sbin/pwconv /usr/sbin/grpconv`." |
| 373 | cpscip-shell system . . cp. --parents $file_need $newroot |
| 374 | |
| 375 | if lddscip-shell system . . ldd. /usr/sbin/authconfigscip-shell filesystem . . `/usr/sbin/authconfig`. &>/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 376 | authconfig_lib_need=$(LC_ALL=C lddscip-shell system . . ldd. /usr/sbin/authconfigscip-shell filesystem . . `/usr/sbin/authconfig`. | sedscip-shell system . . sed. -e "s/.*=> //g" -e "s/(0x.*)//g" | awkscip-shell system . . awk. '{print $1}') |
| 377 | for imod in $authconfig_lib_need; do |
| 378 | # Skip linux-vdso.so.1 and linux-gate.so.1, the virtual DSO, a shared object exposed by the kernel. They do not exist on the file system. Ref: http://ilivetoseek.wordpress.com/2011/10/24/linux-gate-so-1-or-linux-vdso-so-1/ |
| 379 | [scip-shell system . . `[`. "$imod" = "linux-vdso.so.1" ] && continue |
| 380 | [scip-shell system . . `[`. "$imod" = "linux-gate.so.1" ] && continue |
| 381 | cpscip-shell system . . cp. --parents -d $imod $newroot |
| 382 | done |
| 383 | fi |
| 384 | if lddscip-shell system . . ldd. /usr/sbin/pwconfscip-shell filesystem . . `/usr/sbin/pwconf`. &>/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 385 | pwconf_lib_need=$(LC_ALL=C lddscip-shell system . . ldd. /usr/sbin/pwconfscip-shell filesystem . . `/usr/sbin/pwconf`. | sedscip-shell system . . sed. -e "s/.*=> //g" -e "s/(0x.*)//g" | awkscip-shell system . . awk. '{print $1}') |
| 386 | for imod in $pwconf_lib_need; do |
| 387 | # Skip linux-vdso.so.1 and linux-gate.so.1, the virtual DSO, a shared object exposed by the kernel. They do not exist on the file system. Ref: http://ilivetoseek.wordpress.com/2011/10/24/linux-gate-so-1-or-linux-vdso-so-1/ |
| 388 | [scip-shell system . . `[`. "$imod" = "linux-vdso.so.1" ] && continue |
| 389 | [scip-shell system . . `[`. "$imod" = "linux-gate.so.1" ] && continue |
| 390 | cpscip-shell system . . cp. --parents -d $imod $newroot |
| 391 | done |
| 392 | fi |
| 393 | if lddscip-shell system . . ldd. /usr/sbin/grpconvscip-shell filesystem . . `/usr/sbin/grpconv`. &>/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 394 | grpconv_lib_need=$(LC_ALL=C lddscip-shell system . . ldd. /usr/sbin/grpconvscip-shell filesystem . . `/usr/sbin/grpconv`. | sedscip-shell system . . sed. -e "s/.*=> //g" -e "s/(0x.*)//g" | awkscip-shell system . . awk. '{print $1}') |
| 395 | for imod in $grpconv_lib_need; do |
| 396 | # Skip linux-vdso.so.1 and linux-gate.so.1, the virtual DSO, a shared object exposed by the kernel. They do not exist on the file system. Ref: http://ilivetoseek.wordpress.com/2011/10/24/linux-gate-so-1-or-linux-vdso-so-1/ |
| 397 | [scip-shell system . . `[`. "$imod" = "linux-vdso.so.1" ] && continue |
| 398 | [scip-shell system . . `[`. "$imod" = "linux-gate.so.1" ] && continue |
| 399 | cpscip-shell system . . cp. --parents -d $imod $newroot |
| 400 | done |
| 401 | fi |
| 402 | } |
| 403 | |
| 404 | # |
| 405 | create_chpasswd_envscip-shell shell shell-project 0.0.0 create_chpasswd_env().() { |
| 406 | local newroot="$1" |
| 407 | [scip-shell system . . `[`. -z "$newroot" ] && exit 1 |
| 408 | # These *.so were found by using strace |
| 409 | # If something goes wrong in newer GNU/Linux distribution, we can find more by: |
| 410 | # (1) uncomment this line in this function: |
| 411 | # # cp --parents /usr/bin/strace $newroot |
| 412 | # (2) in drbl-client-root-passwd, make it run |
| 413 | # echo "root:$new_passwd" | /usr/bin/strace /usr/sbin/chpasswd |
| 414 | # instead of "echo "root:$new_passwd" | /usr/sbin/chpasswd" |
| 415 | # Then by running drbl-client-root-passwd we can see which lib*.so* is missing. |
| 416 | # //NOTE// /lib* includes /lib and /lib64 |
| 417 | PAM_need_files="/lib*/security/ /usr/lib*/libcrack*.so* /usr/lib*/cracklib_dict.* /lib*/libnss_files*.so* /lib/*/libnss_files*.so* /usr/lib/*/libnss_files*.so* /lib*/libnsl*.so* /lib/*/libnss_nis*.so* /usr/lib/*/libnss_nis*.so* /usr/lib/pwdutils/*.so* /lib*/libcrypt*.so* /usr/lib*/libcrypto*.so* /lib/xcrypt/libxcrypt*.so* /lib/*/security/*pam*.so* /lib/security/*pam*.so* /lib/*/libnsl*.so* /lib/*/tls/i686/sse2/cmov/libnsl*.so* /lib/*/tls/cmov/libnsl*.so* /usr/lib/*/tls/i686/sse2/cmov/libnsl*.so* /usr/lib/*/tls/cmov/libnsl*.so* /lib/tls/*/libnsl*.so* /lib/tls/sse2/cmov/libnsl*.so* /lib/tls/cmov/libnsl*.so* /lib/*/libdbus*.so* /lib/*/tls/libdbus*.so* /usr/lib/*/i686/libnsl*.so* /usr/lib*/libdbus*.so* /usr/lib/cmov/libdbus*.so* /lib/*/libcap*.so* /lib/libcap*.so* /usr/lib/libcap*.so* /lib/libck-connector*.so* /lib/*/libck-connector*.so* /usr/lib/libck-connector*.so* /lib/*/librt*.so* /usr/lib/*/librt*.so* /lib/*/libcgmanager*.so* /lib/*/libnih*.so* /lib/*/*pam*.so* /lib/*/libpthread*.so*" |
| 418 | chpasswd_lib_need="$(LC_ALL=C lddscip-shell system . . ldd. /usr/sbin/chpasswdscip-shell filesystem . . `/usr/sbin/chpasswd`. | sedscip-shell system . . sed. -e "s/.*=> //g" -e "s/(0x.*)//g" | awkscip-shell system . . awk. '{print $1}')" |
| 419 | echo_lib_need="$(LC_ALL=C lddscip-shell system . . ldd. /bin/echoscip-shell filesystem . . `/bin/echo`. | sedscip-shell system . . sed. -e "s/.*=> //g" -e "s/(0x.*)//g" | awkscip-shell system . . awk. '{print $1}')" |
| 420 | export DESTDIR="$newroot" |
| 421 | for imod in $chpasswd_lib_need $echo_lib_need; do |
| 422 | # Skip linux-vdso.so.1 and linux-gate.so.1, the virtual DSO, a shared object exposed by the kernel. They do not exist on the file system. Ref: http://ilivetoseek.wordpress.com/2011/10/24/linux-gate-so-1-or-linux-vdso-so-1/ |
| 423 | [scip-shell system . . `[`. "$imod" = "linux-vdso.so.1" ] && continue |
| 424 | [scip-shell system . . `[`. "$imod" = "linux-gate.so.1" ] && continue |
| 425 | #cp --parents -d $imod $newroot |
| 426 | copy_exec_drblscip-shell shell shell-project 0.0.0 copy_exec_drbl(). $imod "$(LC_ALL=C dirnamescip-shell system . . dirname. $imod)" |
| 427 | done |
| 428 | # /bin/echo is necessary for chpasswd |
| 429 | cpscip-shell system . . cp. --parents -d /bin/echoscip-shell filesystem . . `/bin/echo`. $newroot |
| 430 | cpscip-shell system . . cp. --parents -d /usr/sbin/chpasswdscip-shell filesystem . . `/usr/sbin/chpasswd`. $newroot |
| 431 | # cp --parents /usr/bin/strace $newroot |
| 432 | |
| 433 | #cp --parents -r $PAM_need_files $newroot |
| 434 | for ipam in $PAM_need_files; do |
| 435 | [scip-shell system . . `[`. -n "$(lsscip-shell system . . ls. $ipam 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" ] && cpscip-shell system . . cp. --parents -r $ipam $newroot |
| 436 | done |
| 437 | # we need sh to run the script, borrow it from mkpxeinitrd-net's busybox |
| 438 | cpscip-shell system . . cp. /usr/lib/mkpxeinitrd-net/initrd-skel/bin/shscip-shell filesystem . . `/usr/lib/mkpxeinitrd-net/initrd-skel/bin/sh`. $newroot/bin |
| 439 | } # end of create_chpasswd_env |
| 440 | |
| 441 | # |
| 442 | #create_passwd_env() { |
| 443 | # local newroot="$1" |
| 444 | # [ -z $newroot ] && exit 1 |
| 445 | # # /lib* includes /lib and /lib64 |
| 446 | # PAM_need_files="/lib*/security/ /usr/lib*/libcrack*.so* /usr/lib*/cracklib_dict.* /lib*/libnss_files*.so* /lib*/libnsl*.so* /usr/lib/pwdutils/*.so*" |
| 447 | # passwd_lib_need=$(ldd /usr/bin/passwd | sed -e "s/.*=> //g" -e "s/(0x.*)//g" | awk '{print $1}') |
| 448 | # for imod in $passwd_lib_need; do |
| 449 | # cp --parents $imod $newroot |
| 450 | # done |
| 451 | # cp --parents /usr/bin/passwd $newroot |
| 452 | # |
| 453 | # # /bin/echo is necessary for passwd --stdin |
| 454 | # cp --parents /bin/echo $newroot |
| 455 | # |
| 456 | # cp --parents -r $PAM_need_files $newroot |
| 457 | # # we need sh to run the script, borrow it from mkpxeinitrd-net's busybox |
| 458 | # cp /usr/lib/mkpxeinitrd-net/initrd-skel/bin/sh $newroot/bin |
| 459 | #} |
| 460 | |
| 461 | clean_passwd_envscip-shell shell shell-project 0.0.0 clean_passwd_env().() { |
| 462 | local newroot="$1" |
| 463 | [scip-shell system . . `[`. -z "$newroot" ] && exit 1 |
| 464 | # passwd_lib_need=$(ldd /usr/bin/passwd | cut -d" " -f3) |
| 465 | # [ -f "$newroot/usr/bin/passwd" ] && rm -f $newroot/usr/bin/passwd |
| 466 | # [ -f "$newroot/bin/echo" ] && rm -f $newroot/bin/echo |
| 467 | # for f2rm in $passwd_lib_need; do |
| 468 | # [ -f $newroot/$f2rm ] && rm -f $newroot/$f2rm |
| 469 | # done |
| 470 | # for f2rm in $PAM_need_files; do |
| 471 | # [ -f $newroot/$f2rm ] && rm -f $newroot/$f2rm |
| 472 | # done |
| 473 | # [ -f "$newroot/bin/sh" ] && rm -f $newroot/bin/sh |
| 474 | for d2rm in bin lib usr; do |
| 475 | if [scip-shell system . . `[`. -d "$newroot/$d2rm" ]; then |
| 476 | [scip-shell system . . `[`. -n "$verbose" ] && echoscip-shell system . . echo. "Cleaning the unnecessary directory $newroot/$d2rm ..." |
| 477 | rmscip-shell system . . rm. -rf $newroot/$d2rm |
| 478 | fi |
| 479 | done |
| 480 | } # end of clean_passwd_env |
| 481 | # |
| 482 | clean_chpasswd_envscip-shell shell shell-project 0.0.0 clean_chpasswd_env().() { |
| 483 | local newroot="$1" |
| 484 | [scip-shell system . . `[`. -z "$newroot" ] && exit 1 |
| 485 | for d2rm in bin lib usr; do |
| 486 | if [scip-shell system . . `[`. -d "$newroot/$d2rm" ]; then |
| 487 | [scip-shell system . . `[`. -n "$verbose" ] && echoscip-shell system . . echo. "Cleaning the unnecessary directory $newroot/$d2rm ..." |
| 488 | rmscip-shell system . . rm. -rf $newroot/$d2rm |
| 489 | fi |
| 490 | done |
| 491 | } # end of clean_chpasswd_env |
| 492 | |
| 493 | # check if the user input /dev/hda, /dev/hdb... |
| 494 | check_input_hdscip-shell shell shell-project 0.0.0 check_input_hd().() { |
| 495 | local target_hd="$1" |
| 496 | case "$target_hd" in |
| 497 | [hsv]d[a-z]) |
| 498 | continue |
| 499 | ;; |
| 500 | *) |
| 501 | echoscip-shell system . . echo. "Unknown HD device! Program stop!" |
| 502 | Usage |
| 503 | exit 1 |
| 504 | esac |
| 505 | } |
| 506 | |
| 507 | ## description: |
| 508 | ## convert devfs names into normal short ones, written by Tom Rini. |
| 509 | fixdevfsscip-shell shell shell-project 0.0.0 fixdevfs().() { |
| 510 | ## get partition number, if any |
| 511 | local PARTNUM="${1##*[a-z]}" |
| 512 | ## Find the bus type. |
| 513 | local TYPE="$(v=${1#/dev/} ; echoscip-shell system . . echo. ${v%/host*})" |
| 514 | ## Find the host number. |
| 515 | local HOST="$(v=${1#/dev/*/host} ; echoscip-shell system . . echo. ${v%/bus*})" |
| 516 | ## Find the bus number. |
| 517 | local BUS="$(v=${1#/dev/*/bus} ; echoscip-shell system . . echo. ${v%/tar*})" |
| 518 | ## Find the target. |
| 519 | local TARGET="$(v=${1#/dev/*/target} ; echoscip-shell system . . echo. ${v%/lun*})" |
| 520 | |
| 521 | case "$TYPE" in |
| 522 | ide) |
| 523 | case "$HOST" in |
| 524 | 0) |
| 525 | case "$TARGET" in |
| 526 | 0) |
| 527 | local DEV=hda |
| 528 | ;; |
| 529 | 1) |
| 530 | local DEV=hdb |
| 531 | ;; |
| 532 | esac |
| 533 | ;; |
| 534 | 1) |
| 535 | case "$TARGET" in |
| 536 | 0) |
| 537 | local DEV=hdc |
| 538 | ;; |
| 539 | 1) |
| 540 | local DEV=hdd |
| 541 | ;; |
| 542 | esac |
| 543 | ;; |
| 544 | 2) |
| 545 | case "$TARGET" in |
| 546 | 0) |
| 547 | local DEV=hde |
| 548 | ;; |
| 549 | 1) |
| 550 | local DEV=hdf |
| 551 | ;; |
| 552 | esac |
| 553 | ;; |
| 554 | 3) |
| 555 | case "$TARGET" in |
| 556 | 0) |
| 557 | local DEV=hdg |
| 558 | ;; |
| 559 | 1) |
| 560 | local DEV=hdh |
| 561 | ;; |
| 562 | esac |
| 563 | ;; |
| 564 | *) |
| 565 | echoscip-shell system . . echo. "${1#/dev/}" |
| 566 | #echo "Unable to translate this device, try again without devfs." |
| 567 | return 1 |
| 568 | esac |
| 569 | local DEV="${DEV}${PARTNUM}" |
| 570 | echoscip-shell system . . echo. "$DEV" |
| 571 | return 0 |
| 572 | ;; |
| 573 | scsi) |
| 574 | local LUN="$(v=${1#/dev/*/lun} ; echoscip-shell system . . echo. ${v%/*})" |
| 575 | |
| 576 | ## In this case, we need to figure out what number our device is |
| 577 | local DEVCOUNT=0 |
| 578 | |
| 579 | ## copy scsi file into a variable removing "Attached Devices" |
| 580 | ## which is the first line. this avoids a lot of |
| 581 | ## [incmopatible] crap later, and improves readability. |
| 582 | |
| 583 | ## find number of lines once and recycle that number, to save |
| 584 | ## some time (linecount is a bit slow). subtract one line |
| 585 | ## to scrap Attached Devices: |
| 586 | |
| 587 | local SCSILINES="$(($(wcscip-shell system . . wc. -l /proc/scsi/scsiscip-shell filesystem . . `/proc/scsi/scsi`. | cutscip-shell system . . cut. -d' ' -f1) - 1))" |
| 588 | local PROCSCSI="$(catscip-shell system . . cat. /proc/scsi/scsiscip-shell filesystem . . `/proc/scsi/scsi`. | tailscip-shell system . . tail. -n $SCSILINES)" |
| 589 | |
| 590 | for i in $(seqscip-shell system . . seq. $(($SCSILINES / 3))) ; do |
| 591 | |
| 592 | ## put every scsi device into one single line |
| 593 | local DEVINFO="$(echoscip-shell system . . echo. "$PROCSCSI" | headscip-shell system . . head. -n $(($i * 3)) | tailscip-shell system . . tail. -n 3)" |
| 594 | [scip-shell system . . `[`. "$DEBUG" = 1 ] && echoscip-shell system . . echo. 1>&2 "$PRG: DEBUG: fixdevfs: DEVINFO=$DEVINFO" |
| 595 | |
| 596 | ## cut the type field, expect "Direct-Access" later. |
| 597 | local DEVTYPE="$(v=$(echoscip-shell system . . echo. ${DEVINFO##*Type: }) ; echoscip-shell system . . echo. ${v%% *})" |
| 598 | [scip-shell system . . `[`. "$DEBUG" = 1 ] && echoscip-shell system . . echo. 1>&2 "$PRG: DEBUG: fixdevfs: DEVTYPE=$DEVTYPE" |
| 599 | |
| 600 | if [scip-shell system . . `[`. "$DEVTYPE" = "Direct-Access" ] ; then |
| 601 | ## Lets find out some more information |
| 602 | ## get the device id. |
| 603 | local DEVID="$(v=$(echoscip-shell system . . echo. ${DEVINFO##*Id: }) ; n=$(echoscip-shell system . . echo. ${v%% *}) ; echoscip-shell system . . echo. ${n#*0})" |
| 604 | [scip-shell system . . `[`. "$DEBUG" = 1 ] && echoscip-shell system . . echo. 1>&2 "$PRG: DEBUG: fixdevfs: DEVID=$DEVID" |
| 605 | |
| 606 | ## get the device lun. |
| 607 | local DEVLUN="$(v=$(echoscip-shell system . . echo. ${DEVINFO##*Lun: }) ; n=$(echoscip-shell system . . echo. ${v%% *}) ; echoscip-shell system . . echo. ${n#*0})" |
| 608 | [scip-shell system . . `[`. "$DEBUG" = 1 ] && echoscip-shell system . . echo. 1>&2 "$PRG: DEBUG: fixdevfs: DEVLUN=$DEVLUN" |
| 609 | |
| 610 | ## get the device channel. |
| 611 | local DEVCHAN="$(v=$(echoscip-shell system . . echo. ${DEVINFO##*Channel: }) ; n=$(echoscip-shell system . . echo. ${v%% *}) ; echoscip-shell system . . echo. ${n#*0})" |
| 612 | [scip-shell system . . `[`. "$DEBUG" = 1 ] && echoscip-shell system . . echo. 1>&2 "$PRG: DEBUG: fixdevfs: DEVCHAN=$DEVCHAN" |
| 613 | |
| 614 | ## get the scsi host id. |
| 615 | local DEVHOST="$(v=$(echoscip-shell system . . echo. ${DEVINFO##*Host: scsi}) ; echoscip-shell system . . echo. ${v%% *})" |
| 616 | [scip-shell system . . `[`. "$DEBUG" = 1 ] && echoscip-shell system . . echo. 1>&2 "$PRG: DEBUG: fixdevfs: DEVHOST=$DEVHOST" |
| 617 | |
| 618 | local DEVCOUNT="$(($DEVCOUNT + 1))" |
| 619 | [scip-shell system . . `[`. "$DEBUG" = 1 ] && echoscip-shell system . . echo. 1>&2 "$PRG: DEBUG: fixdevfs: DEVCOUNT=$DEVCOUNT" |
| 620 | if [scip-shell system . . `[`. "$DEVHOST" = "$HOST" -a "$DEVCHAN" = "$BUS" -a \ |
| 621 | "$DEVID" = "$TARGET" -a "$DEVLUN" = "$LUN" ] ; then |
| 622 | local DEV="sd$(smalltr $DEVCOUNT)${PARTNUM}" |
| 623 | echoscip-shell system . . echo. "$DEV" |
| 624 | return 0 |
| 625 | fi |
| 626 | fi |
| 627 | done |
| 628 | echoscip-shell system . . echo. "${1#/dev/}" |
| 629 | #echo "Unable to translate this device, try again without devfs." |
| 630 | return 1 |
| 631 | ;; |
| 632 | *) |
| 633 | echoscip-shell system . . echo. "${1#/dev/}" |
| 634 | #echo "Unknown bus" |
| 635 | return 1 |
| 636 | ;; |
| 637 | esac |
| 638 | ## we should never get here |
| 639 | return 1 |
| 640 | } |
| 641 | |
| 642 | # get dhcpd interface |
| 643 | get_dhcpd_interfacescip-shell shell shell-project 0.0.0 get_dhcpd_interface().() { |
| 644 | local INTERFACES INTERFACESv4 INTERFACES_TMP |
| 645 | if [scip-shell system . . `[`. -e /etc/debian_versionscip-shell filesystem . . `/etc/debian_version`. ]; then |
| 646 | # Debian |
| 647 | . $SYSCONF_PATH/$DHCP_SRV_NAME |
| 648 | elif [scip-shell system . . `[`. -e /etc/SuSE-releasescip-shell filesystem . . `/etc/SuSE-release`. ]; then |
| 649 | # SuSE |
| 650 | . $SYSCONF_PATH/$DHCP_SRV_NAME |
| 651 | INTERFACES="$DHCPD_INTERFACE" |
| 652 | else |
| 653 | # RH-like |
| 654 | # The content of /etc/sysconfig/dhcpd file: |
| 655 | # E.g. DHCPDARGS="-p 67 eth0 eth1"; |
| 656 | # //NOTE// Although /etc/sysconfig/dhcpd is not used anymore by CentOS/Fedora which uses systemd, we still can use it as the config file for dhcpd, because it's easier for us to parse compared with dhcpd.conf. |
| 657 | # Det the setting of dhcp server |
| 658 | . $SYSCONF_PATH/$DHCP_SRV_NAME |
| 659 | # collect those interface, filter out other options, such as -p 60 |
| 660 | INTERFACES="" |
| 661 | for ieth in $DHCPDARGS; do |
| 662 | # For CentOS >= 7, NIC device name is changed as "Predictable Network Interface Names". |
| 663 | # Ref: http://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/ |
| 664 | # Names incorporating Firmware/BIOS provided index numbers for on-board devices (example: eno1) |
| 665 | # Names incorporating Firmware/BIOS provided PCI Express hotplug slot index numbers (example: ens1) |
| 666 | # Names incorporating physical/geographical location of the connector of the hardware (example: enp2s0) |
| 667 | # Names incorporating the interfaces's MAC address (example: enx78e7d1ea46da) |
| 668 | # Classic, unpredictable kernel-native ethX naming (example: eth0) |
| 669 | INTERFACES_TMP="$(echoscip-shell system . . echo. $ieth | grepscip-shell system . . grep. -Eo '(eth[[:digit:]]+|en[[:print:]]+|p[[:digit:]]+p[[:digit:]]+)')" |
| 670 | INTERFACES="$INTERFACES $INTERFACES_TMP" |
| 671 | done |
| 672 | fi |
| 673 | # The variable might be INTERFACES or INTERFACESv4 (newer isc-dhcp-server) |
| 674 | echoscip-shell system . . echo. $INTERFACES $INTERFACESv4 |
| 675 | } # end of get_dhcpd_interface |
| 676 | |
| 677 | # HD dma status |
| 678 | check_hd_dmascip-shell shell shell-project 0.0.0 check_hd_dma().() { |
| 679 | # input example: /dev/hda |
| 680 | # return 0/1, 0: DMA off, 1: DMA on |
| 681 | local hd_dev=$1 |
| 682 | DMA_status=$(hdparm -d $hd_dev 2>/dev/nullscip-shell filesystem . . `/dev/null`. | grepscip-shell system . . grep. using_dma | awkscip-shell system . . awk. '{print $3}') |
| 683 | echoscip-shell system . . echo. "$DMA_status" |
| 684 | } |
| 685 | |
| 686 | # turn on hd dma |
| 687 | turn_on_hd_dmascip-shell shell shell-project 0.0.0 turn_on_hd_dma().() { |
| 688 | local hd_dev="$1" |
| 689 | if [scip-shell system . . `[`. -z "$hd_dev" ]; then |
| 690 | echoscip-shell system . . echo. "To turn on HD dma, you have to specify the HD dev!" |
| 691 | exit 1 |
| 692 | fi |
| 693 | # Only IDE (/dev/hda) need to be turned on DMA. |
| 694 | [scip-shell system . . `[`. -z "$(echoscip-shell system . . echo. $hd_dev | grepscip-shell system . . grep. -F "/dev/hdscip-shell filesystem . . `/dev/hd`.")" ] && return 3 |
| 695 | # |
| 696 | echoscip-shell system . . echo. "*******************************************" |
| 697 | echoscip-shell system . . echo. "Try to turn on the harddisk \"$hd_dev\" DMA..." |
| 698 | if [scip-shell system . . `[`. "$(check_hd_dmascip-shell shell shell-project 0.0.0 check_hd_dma(). $hd_dev)" = "0" ]; then |
| 699 | # turn on DMA if it's off (0) |
| 700 | hdparm -d1m1c1 $hd_dev |
| 701 | fi |
| 702 | # check the result |
| 703 | DMA="$(check_hd_dmascip-shell shell shell-project 0.0.0 check_hd_dma(). $hd_dev)" |
| 704 | if [scip-shell system . . `[`. -n "$DMA" ]; then |
| 705 | # This is IDE device, we can get DMA status |
| 706 | [scip-shell system . . `[`. "$DMA" -eq 0 ] && echoscip-shell system . . echo. "Warning!!! Failed to turn on harddisk \"$hd_dev\" DMA... The clone performance might be NOT good..." && sleepscip-shell system . . sleep. 5 |
| 707 | else |
| 708 | # This is SCSI device, we can not get DMA status |
| 709 | echoscip-shell system . . echo. "No HD DMA information, maybe this not a IDE device!" |
| 710 | fi |
| 711 | echoscip-shell system . . echo. "*******************************************" |
| 712 | } # end of turn_on_hd_dma |
| 713 | |
| 714 | # do not let screen be blank |
| 715 | # |
| 716 | screen_not_blankscip-shell shell shell-project 0.0.0 screen_not_blank().() { |
| 717 | if [scip-shell system . . `[`. "$ocs_screen_blank" != "no" ]; then |
| 718 | settermscip-shell system . . setterm. --blank 0 --powersave off 2>/dev/nullscip-shell filesystem . . `/dev/null`. |
| 719 | fi |
| 720 | } |
| 721 | |
| 722 | # set passwd login for single user mode |
| 723 | set_clients_rc1_passwdscip-shell shell shell-project 0.0.0 set_clients_rc1_passwd().() { |
| 724 | local rc1_sulogin="~~:S:wait:/sbin/sulogin" |
| 725 | IP_LIST=$* |
| 726 | # make a flag "LIST_HOST" |
| 727 | [scip-shell system . . `[`. -n "$IP_LIST" ] && LIST_HOST="on" |
| 728 | |
| 729 | for ihost in $drblroot/*; do |
| 730 | # skip those IP not listed in the $IP_LIST |
| 731 | if [scip-shell system . . `[`. "$LIST_HOST" = "on" ]; then |
| 732 | [scip-shell system . . `[`. -z "$(echoscip-shell system . . echo. $IP_LIST | grepscip-shell system . . grep. ${ihost##/*/})" ] && continue |
| 733 | fi |
| 734 | |
| 735 | if ! grepscip-shell system . . grep. -qE ^$rc1_sulogin $ihost/etc/inittab 2>/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 736 | echoscip-shell system . . echo. "Set the single user password for client ${ihost##/*/}, this will be safer..." |
| 737 | catscip-shell system . . cat. <<-EOF >> $ihost/etc/inittab |
| 738 | |
| 739 | # Single User Mode Password, added by DRBL |
| 740 | $rc1_sulogin |
| 741 | EOF |
| 742 | fi |
| 743 | done |
| 744 | } |
| 745 | # |
| 746 | get_lang_indexscip-shell shell shell-project 0.0.0 get_lang_index().() { |
| 747 | local lang=$1 |
| 748 | local language |
| 749 | case "$lang" in |
| 750 | "2") |
| 751 | language="zh_TW.UTF-8" |
| 752 | ;; |
| 753 | *) |
| 754 | language="en_US.UTF-8" |
| 755 | ;; |
| 756 | esac |
| 757 | echoscip-shell system . . echo. $language |
| 758 | } |
| 759 | |
| 760 | check_kernel_nfsd_tcp_configscip-shell shell shell-project 0.0.0 check_kernel_nfsd_tcp_config().() { |
| 761 | # note the kernel should be the one is using in the drbl server |
| 762 | kernel_ver=$(unamescip-shell system . . uname. -r) |
| 763 | # check if /boot/config-$kernel_ver exists |
| 764 | # kernel config is either in /boot/ |
| 765 | kernel_config="/boot/config-$kernel_ver" |
| 766 | echoscip-shell system . . echo. "Checking server kernel config \"$kernel_config...\"" |
| 767 | if [scip-shell system . . `[`. ! -f $kernel_config ]; then |
| 768 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 769 | echoscip-shell system . . echo. "$kernel_config does NOT exist!" |
| 770 | echoscip-shell system . . echo. "I can not judge whether NFS over TCP is supported in the kernel you are using!!!" |
| 771 | echoscip-shell system . . echo. "We will assume that the NFS server use UDP protocol!" |
| 772 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 773 | protocol="udp" |
| 774 | else |
| 775 | # we assume the the priority is higher for EXT2, i.e. EXT2 option will overwrite the CRAMFS. |
| 776 | if [scip-shell system . . `[`. -n "$(grepscip-shell system . . grep. "^CONFIG_NFSD_TCP=y" $kernel_config)" ]; then |
| 777 | protocol="tcp" |
| 778 | else |
| 779 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE |
| 780 | echoscip-shell system . . echo. "$kernel_config is found but NFS over TCP is not supported in the kernel you are using for the DRBL clients!!!" |
| 781 | echoscip-shell system . . echo. "We will use NFS over UDP !" |
| 782 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 783 | protocol="udp" |
| 784 | fi |
| 785 | fi |
| 786 | case "$protocol" in |
| 787 | [tT][cC][pP]) |
| 788 | rc=0 |
| 789 | ;; |
| 790 | [uU][dD][pP]) |
| 791 | rc=1 |
| 792 | ;; |
| 793 | esac |
| 794 | return $rc |
| 795 | } |
| 796 | |
| 797 | switch_clients_initscip-shell shell shell-project 0.0.0 switch_clients_init().() { |
| 798 | # input: client_init IP_LIST |
| 799 | # if IP_LIST is none, this function will process all the clients. |
| 800 | local CLIENT_INIT |
| 801 | local IP_LIST |
| 802 | CLIENT_INIT=$1 |
| 803 | shift |
| 804 | IP_LIST=$* |
| 805 | # make a flag "LIST_HOST" |
| 806 | [scip-shell system . . `[`. -n "$IP_LIST" ] && LIST_HOST="on" |
| 807 | [scip-shell system . . `[`. -z "$CLIENT_INIT" ] && echoscip-shell system . . echo. "No specified mode for client inittab!!! Program stop!!!" && exit 1 |
| 808 | for host in $drblroot/*; do |
| 809 | # skip those IP not listed in the $IP_LIST |
| 810 | if [scip-shell system . . `[`. "$LIST_HOST" = "on" ]; then |
| 811 | [scip-shell system . . `[`. -z "$(echoscip-shell system . . echo. $IP_LIST | grepscip-shell system . . grep. ${host##/*/})" ] && continue |
| 812 | fi |
| 813 | |
| 814 | echoscip-shell system . . echo. "Setting the graphic mode for node IP = $(basenamescip-shell system . . basename. $host)..." |
| 815 | # set the init to 5, i.e. default is X |
| 816 | /usr/bin/perlscip-shell filesystem . . `/usr/bin/perl`. -p -i -e "s/^id:[1-5]:initdefault:/id:$CLIENT_INIT:initdefault:/g" $host/etc/inittab |
| 817 | done |
| 818 | } |
| 819 | |
| 820 | # This "GREP_NEWER" program is borrowed from http://staff.washington.edu/corey/new-patches.cgi |
| 821 | # The original author: |
| 822 | # Corey Satten, corey @ cac.washington.edu, 06/26/03, release 1.8 |
| 823 | # For the latest version visit: http://staff.washington.edu/corey/tools.html |
| 824 | # |
| 825 | # Modified by Blake Huang and Steven Shiau to use in DRBL |
| 826 | GREP_NEWER=' |
| 827 | # Function newer: |
| 828 | # Return 1 if second arg is "newer" than the first arg, else return 0. |
| 829 | # |
| 830 | # Because extra dotted fields before a hyphen are more significant |
| 831 | # than those after a hyphen, first split on hyphens, then loop over |
| 832 | # dotted fields passing the hard alphanumerics to function "compare" |
| 833 | # for further splitting and comparing. |
| 834 | # |
| 835 | # eg. older bind-utils-8.2.2_P5-9 and older gzip-1.2.4-14 |
| 836 | # newer bind-utils-8.2.2_P7-0.6.2 and newer gzip-1.2.4a-2 |
| 837 | # |
| 838 | # older apmd-3.0beta9-3 and older rmt-0.4b4-11 |
| 839 | # newer apmd-3.0final-2 and newer rmt-0.4b19-5.6x |
| 840 | |
| 841 | function newer(a, b, na1, nb1, na, nb, minn, i, j) { |
| 842 | #printf("newer called with %s %s\n", a, b) |
| 843 | if ('"${EFLAG-0}"') return a!=b |
| 844 | if (O) {na=a; a=b; b=na} |
| 845 | na1 = split(a, A1, /-/) |
| 846 | nb1 = split(b, B1, /-/) |
| 847 | if (na1 != nb1) { |
| 848 | #printf "unsure about %s and %s\n", a, b > "/dev/stderr" |
| 849 | return 1 } |
| 850 | for (j=1; j<=na1; ++j) { |
| 851 | na = split(A1[j], A, /\./) |
| 852 | nb = split(B1[j], B, /\./) |
| 853 | minn = na < nb ? na : nb |
| 854 | for (i=1; i<=minn; ++i) { |
| 855 | if ('"${DEBUG-0}"') \ |
| 856 | printf(" newer%d comparing %s %s\n", i, A[i], B[i])>"/dev/stderr" |
| 857 | if ((A[i] B[i]) ~ /^[0-9]+$/) { |
| 858 | if (A[i]+0 < B[i]+0) return 1 |
| 859 | if (A[i]+0 > B[i]+0) return 0 } |
| 860 | else if (A[i] "" != B[i] "") return compare(A[i], B[i]) |
| 861 | } |
| 862 | if (nb > na) return 1 |
| 863 | if (nb < na) return 0 |
| 864 | } |
| 865 | return 0 |
| 866 | } |
| 867 | |
| 868 | # Function compare (called only by function newer): |
| 869 | # Return 1 if second arg is "newer" than the first arg, else return 0. |
| 870 | # |
| 871 | # This is harder than it looks: consider "v9" vs "v10a", etc. |
| 872 | # split out and compare alternating fields of numeric and non-numeric |
| 873 | |
| 874 | function compare (a, b, xa, xb) { |
| 875 | #printf(" compare called with %s %s\n", a, b) |
| 876 | while (length(a) && length(b)) { |
| 877 | if (a ~ /^[0-9]/) { |
| 878 | match(a, /^[0-9]+/) |
| 879 | xa = substr(a, 1, RLENGTH); a = substr(a, RLENGTH+1) } |
| 880 | else { |
| 881 | match(a, /^[^0-9]+/) |
| 882 | xa = substr(a, 1, RLENGTH); a = substr(a, RLENGTH+1) } |
| 883 | if (b ~ /^[0-9]/) { |
| 884 | match(b, /^[0-9]+/) |
| 885 | xb = substr(b, 1, RLENGTH); b = substr(b, RLENGTH+1) } |
| 886 | else { |
| 887 | match(b, /^[^0-9]+/) |
| 888 | xb = substr(b, 1, RLENGTH); b = substr(b, RLENGTH+1) } |
| 889 | #printf(" compare2 %s %s <%s> <%s>\n", xa, xb, a, b) |
| 890 | if ( (xa xb) ~ /^[0-9]+$/) { |
| 891 | if (xa+0 < xb+0) return 1 |
| 892 | if (xa+0 > xb+0) return 0 } |
| 893 | else { |
| 894 | if (xa "" < xb "") return 1 |
| 895 | if (xa "" > xb "") return 0 } |
| 896 | } |
| 897 | if (length(b)) return 1 |
| 898 | else return 0 |
| 899 | } |
| 900 | ' |
| 901 | # |
| 902 | set_specific_host_pxe_confscip-shell shell shell-project 0.0.0 set_specific_host_pxe_conf().() { |
| 903 | local HOSTS="$*" |
| 904 | local pxecfg pxecfg_MAC pxecfg_MIP OCS_TMP IP |
| 905 | # prepare the HOSTNAME-IP-MAC table |
| 906 | OCS_TMP=`mktempscip-shell system . . mktemp. /tmp/ocs_clean_tmp.XXXXXXscip-shell filesystem . . `/tmp/ocs_clean_tmp.XXXXXX`.` |
| 907 | trap "[ -f "$OCS_TMP" ] && rm -f $OCS_TMP" HUP INT QUIT TERM EXIT |
| 908 | parse_dhcpd_conf $OCS_TMP |
| 909 | |
| 910 | for ih in $HOSTS; do |
| 911 | case "$ih" in |
| 912 | *.*.*.*) |
| 913 | # list by IP |
| 914 | # the pxecfg will like "C0A80001" |
| 915 | pxecfg="$(drbl-gethostip $ih)" |
| 916 | # These files look like: 01-MAC address (with ":" -> "-"), |
| 917 | # We'd better to clean the 01-MAC file if it exists since maybe it's created by ocsmgrd when received the results from client in the previous save/restoration. Since 01-MAC has higher priority than "C0A80001" style file in pxelinux, this is a must if we can find it, we have to remove it. |
| 918 | # TODO: What if no MAC address setting in dhcpd.conf ? Then $OCS_TMP will be empty, then... ? |
| 919 | pxecfg_MAC="01-$(grepscip-shell system . . grep. ${ih} $OCS_TMP | awkscip-shell system . . awk. -F" " '{print $3}' | trscip-shell system . . tr. ":" "-")" |
| 920 | [scip-shell system . . `[`. -f "$PXELINUX_DIR/$pxecfg_MAC" ] && rmscip-shell system . . rm. -f $PXELINUX_DIR/$pxecfg_MAC |
| 921 | ;; |
| 922 | *:*:*:*:*:*) |
| 923 | # list by MAC |
| 924 | # for an Ethernet (ARP type 1) with address 88:99:AA:BB:CC:DD it would search for the filename 01-88-99-aa-bb-cc-dd (lowercase) |
| 925 | pxecfg="$(echoscip-shell system . . echo. $ih | trscip-shell system . . tr. "[A-Z]" "[a-z]" | trscip-shell system . . tr. ":" "-")" |
| 926 | # append "01-" in the beginning |
| 927 | pxecfg="01-$pxecfg" |
| 928 | # We'd better to clean the IP-based setting file if it exists since maybe it's created by ocsmgrd when received the results from client in the previous save/restoration. Although 01-MAC has higher priority than "C0A80001" style file in pxelinux, this NOT a must if we can find it, but we remove it to avoid confusion. |
| 929 | IP="$(grepscip-shell system . . grep. -E ${ih} $OCS_TMP | awkscip-shell system . . awk. -F" " '{print $2}')" |
| 930 | pxecfg_MIP="$(drbl-gethostip $IP)" |
| 931 | [scip-shell system . . `[`. -f "$PXELINUX_DIR/$pxecfg_MIP" ] && rmscip-shell system . . rm. -f $PXELINUX_DIR/$pxecfg_MIP |
| 932 | ;; |
| 933 | esac |
| 934 | echoscip-shell system . . echo. -n "Generate the PXE config file for host $ih ... " |
| 935 | cpscip-shell system . . cp. -f $PXELINUX_DIR/default_skeleton $PXELINUX_DIR/$pxecfg |
| 936 | echoscip-shell system . . echo. "done!" |
| 937 | done |
| 938 | [scip-shell system . . `[`. -f "$OCS_TMP" ] && rmscip-shell system . . rm. -f $OCS_TMP |
| 939 | } # end of set_specific_host_pxe_conf |
| 940 | |
| 941 | # function to get the pxecfg image block line number |
| 942 | get_pxecfg_image_blockscip-shell shell shell-project 0.0.0 get_pxecfg_image_block().() { |
| 943 | local IMG_NAME="$1" |
| 944 | local PXE_CONF_TMP="$2" |
| 945 | [scip-shell system . . `[`. -z "$IMG_NAME" ] && exit 1 |
| 946 | # By using |
| 947 | # grep -Ei -n '^[[:space:]]*label[[:space:]]+.*([[:space:]]|$)+' /tftpboot/nbi_img/pxelinux.cfg/default | grep -A1 -E "label[[:space:]]+drbl([[:space:]]|$)+" |
| 948 | # 10:label drbl |
| 949 | # 17:label local |
| 950 | # so we know we can replace the one between line no. 10 and 17 |
| 951 | between_lines="$(LC_ALL=C grepscip-shell system . . grep. -Ei -n "^[[:space:]]*label[[:space:]]+.*([[:space:]]|$)+" $PXE_CONF_TMP | grepscip-shell system . . grep. -Ei -A1 "label[[:space:]]+$IMG_NAME([[:space:]]|$)+" | cutscip-shell system . . cut. -d":" -f1)" |
| 952 | begin_line="$(LC_ALL=C echoscip-shell system . . echo. $between_lines | awkscip-shell system . . awk. -F" " '{print $1}')" |
| 953 | end_line="$(LC_ALL=C echoscip-shell system . . echo. $between_lines | awkscip-shell system . . awk. -F" " '{print $2}')" |
| 954 | # if end_line is nothing, it must be the last block, i.e. we can not find the next [.*] |
| 955 | if [scip-shell system . . `[`. -z "$end_line" ]; then |
| 956 | end_line="$(LC_ALL=C wcscip-shell system . . wc. -l $PXE_CONF_TMP | awkscip-shell system . . awk. -F" " '{print $1}')" |
| 957 | else |
| 958 | # if not nothing, backword one line |
| 959 | end_line="$(($end_line - 1))" |
| 960 | fi |
| 961 | echoscip-shell system . . echo. "$begin_line $end_line" |
| 962 | } # end of get_pxecfg_image_block |
| 963 | check_img_in_pxe_cfgscip-shell shell shell-project 0.0.0 check_img_in_pxe_cfg().() { |
| 964 | local IMG="$1" |
| 965 | local PXE_CONF_TMP="$2" |
| 966 | if [scip-shell system . . `[`. -z "$IMG" ]; then |
| 967 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE |
| 968 | echoscip-shell system . . echo. "You must specify the image name! Program terminated!!!" |
| 969 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 970 | exit 1 |
| 971 | fi |
| 972 | if ! grepscip-shell system . . grep. -Eiq "^[[:space:]]*label[[:space:]]+$IMG" $PXE_CONF_TMP; then |
| 973 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE |
| 974 | echoscip-shell system . . echo. "Unable to find the image ($IMG) label! Make sure the $IMG is labeled in $PXE_CONF_TMP! Program terminated!!!" |
| 975 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 976 | exit 1 |
| 977 | fi |
| 978 | } # end of check_img_in_pxe_cfg |
| 979 | sub_default_pxe_imgscip-shell shell shell-project 0.0.0 sub_default_pxe_img().() { |
| 980 | local IMG="$1" |
| 981 | local PXE_CONF_TMP="$2" |
| 982 | local MENU_LABEL="$3" |
| 983 | check_img_in_pxe_cfgscip-shell shell shell-project 0.0.0 check_img_in_pxe_cfg(). $IMG $PXE_CONF_TMP |
| 984 | # turn off all MENU DEFAULT |
| 985 | echoscip-shell system . . echo. "Turn off all MENU DEFAULT in $PXE_CONF_TMP... " |
| 986 | perlscip-shell system . . perl. -pi -e "s/^(#|[[:space:]])*MENU DEFAULT.*/ # MENU DEFAULT/i" $PXE_CONF_TMP |
| 987 | all_label="$(awkscip-shell system . . awk. '/^[[:space:]]*label[[:space:]]+.*([[:space:]]|$)+/ {print $2}scip-shell filesystem . . `/^[[:space:]]*label[[:space:]]+.*([[:space:]]|$)+/ {print $2}`.' $PXE_CONF_TMP)" |
| 988 | # 2006/09/10 Steven commented this, we'd better keep the way pxelinux config is. |
| 989 | #for i in $all_label; do |
| 990 | # if [ -z "$(echo $IMG_SHOW_IN_MENU | grep -i $i)" ]; then |
| 991 | # [ -n "$VERBOSE" ] && echo "Hide image $i" |
| 992 | # hide_reveal_pxe_img $i hide $PXE_CONF_TMP |
| 993 | # fi |
| 994 | #done |
| 995 | |
| 996 | # turn on MENU DEFAULT & turn off MENU HIDE for the specified image |
| 997 | lines="$(get_pxecfg_image_blockscip-shell shell shell-project 0.0.0 get_pxecfg_image_block(). $IMG $PXE_CONF_TMP)" |
| 998 | begin_line="$(echoscip-shell system . . echo. $lines | awkscip-shell system . . awk. -F" " '{print $1}')" |
| 999 | end_line="$(echoscip-shell system . . echo. $lines | awkscip-shell system . . awk. -F" " '{print $2}')" |
| 1000 | echoscip-shell system . . echo. "Make \"$IMG\" as default label in $PXE_CONF_TMP." |
| 1001 | sub_def_cmd="if ($begin_line..$end_line) {s/^(#|[[:space:]])*MENU DEFAULT.*/ MENU DEFAULT/i}" |
| 1002 | sub_hide_cmd="if ($begin_line..$end_line) {s/^(#|[[:space:]])*MENU HIDE.*/ # MENU HIDE/i}" |
| 1003 | perlscip-shell system . . perl. -pi -e "$sub_def_cmd" $PXE_CONF_TMP |
| 1004 | perlscip-shell system . . perl. -pi -e "$sub_hide_cmd" $PXE_CONF_TMP |
| 1005 | |
| 1006 | if [scip-shell system . . `[`. -n "$MENU_LABEL" ]; then |
| 1007 | echoscip-shell system . . echo. The MENU LABEL is \"$MENU_LABEL\" |
| 1008 | sub_menu_label_cmd="if ($begin_line..$end_line) {s|^[[:space:]]*MENU LABEL.*| MENU LABEL $MENU_LABEL|i}" |
| 1009 | perlscip-shell system . . perl. -pi -e "$sub_menu_label_cmd" $PXE_CONF_TMP |
| 1010 | fi |
| 1011 | } # end of sub_default_pxe_img |
| 1012 | # use script hide_reveal_pxe_img instead of fnction. |
| 1013 | #hide_reveal_pxe_img() { |
| 1014 | # local IMG="$1" |
| 1015 | # local ACT="$2" |
| 1016 | # local PXE_CONF_TMP="$3" |
| 1017 | # check_img_in_pxe_cfg $IMG $PXE_CONF_TMP |
| 1018 | # # turn off MENU DEFAULT & turn on MENU HIDE for the specified image |
| 1019 | # lines=$(get_pxecfg_image_block $IMG $PXE_CONF_TMP) |
| 1020 | # begin_line=$(echo $lines | awk -F" " '{print $1}') |
| 1021 | # end_line=$(echo $lines | awk -F" " '{print $2}') |
| 1022 | # case "$ACT" in |
| 1023 | # "hide") |
| 1024 | # [ -n "$VERBOSE" ] && echo "Hide $IMG in $PXE_CONF_TMP... " |
| 1025 | # sub_act_cmd="if ($begin_line..$end_line) {s/^(#|[[:space:]])*MENU HIDE.*/ MENU HIDE/i}" |
| 1026 | # ;; |
| 1027 | # "reveal") |
| 1028 | # [ -n "$VERBOSE" ] && echo "Reveal $IMG in $PXE_CONF_TMP... " |
| 1029 | # sub_act_cmd="if ($begin_line..$end_line) {s/^(#|[[:space:]])*MENU HIDE.*/ # MENU HIDE/i}" |
| 1030 | # ;; |
| 1031 | # esac |
| 1032 | # perl -pi -e "$sub_act_cmd" $PXE_CONF_TMP |
| 1033 | #} |
| 1034 | # |
| 1035 | delete_label_block_pxe_imgscip-shell shell shell-project 0.0.0 delete_label_block_pxe_img().() { |
| 1036 | local LABEL="$1" |
| 1037 | local PXE_CONF_TMP="$2" |
| 1038 | local lines begin_line end_line rc |
| 1039 | [scip-shell system . . `[`. -z "$LABEL" -o -z "$PXE_CONF_TMP" ] && return 1 |
| 1040 | lines=$(get_pxecfg_image_blockscip-shell shell shell-project 0.0.0 get_pxecfg_image_block(). $LABEL $PXE_CONF_TMP) |
| 1041 | begin_line=$(echoscip-shell system . . echo. $lines | awkscip-shell system . . awk. -F" " '{print $1}') |
| 1042 | end_line=$(echoscip-shell system . . echo. $lines | awkscip-shell system . . awk. -F" " '{print $2}') |
| 1043 | # delete lines between $begin_line and $end_line |
| 1044 | perlscip-shell system . . perl. -i -ne "print unless $begin_line..$end_line" $PXE_CONF_TMP |
| 1045 | rc=$? |
| 1046 | return $rc |
| 1047 | } # end of delete_label_block_pxe_img |
| 1048 | # |
| 1049 | delete_menuentry_block_grub_imgscip-shell shell shell-project 0.0.0 delete_menuentry_block_grub_img().() { |
| 1050 | local ENTRY_ID="$1" |
| 1051 | local GRUB_CONF_TMP="$2" |
| 1052 | local lines begin_line end_line rc |
| 1053 | [scip-shell system . . `[`. -z "$ENTRY_ID" -o -z "$GRUB_CONF_TMP" ] && return 1 |
| 1054 | if [scip-shell system . . `[`. -n "$GRUB_CONF_TMP" -a ! -e "$GRUB_CONF_TMP" ]; then |
| 1055 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 1056 | echoscip-shell system . . echo. "File $GRUB_CONF_TMP not found. No support for uEFI network boot." |
| 1057 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 1058 | return 2 |
| 1059 | fi |
| 1060 | lines="$(get_grub_efi_image_block "--id $ENTRY_ID" $GRUB_CONF_TMP)" |
| 1061 | begin_line=$(echoscip-shell system . . echo. $lines | awkscip-shell system . . awk. -F" " '{print $1}') |
| 1062 | end_line=$(echoscip-shell system . . echo. $lines | awkscip-shell system . . awk. -F" " '{print $2}') |
| 1063 | # delete lines between $begin_line and $end_line |
| 1064 | perlscip-shell system . . perl. -i -ne "print unless $begin_line..$end_line" $GRUB_CONF_TMP |
| 1065 | rc=$? |
| 1066 | return $rc |
| 1067 | } # end of delete_label_block_pxe_img |
| 1068 | # |
| 1069 | ask_lang_setscip-shell shell shell-project 0.0.0 ask_lang_set().() { |
| 1070 | local language_opt="$1" |
| 1071 | local chosen_lang_var |
| 1072 | # lang will be the global variable |
| 1073 | # get the language |
| 1074 | if [scip-shell system . . `[`. -z "$language_opt" ]; then |
| 1075 | # Try the Environment variable "LC_ALL", then "LANG" |
| 1076 | if [scip-shell system . . `[`. -n "$LC_ALL" ]; then |
| 1077 | chosen_lang_var="$LC_ALL" |
| 1078 | elif [scip-shell system . . `[`. -n "$LANG" ]; then |
| 1079 | chosen_lang_var="$LANG" |
| 1080 | fi |
| 1081 | # Normally we use the locale format like: en_US.UTF-8, however, it's possible it is en_US.utf8. Therefore here we format it to be *.UTF-8. |
| 1082 | chosen_lang_var="$(LC_ALL=C echoscip-shell system . . echo. $chosen_lang_var | sedscip-shell system . . sed. -e "s/\.utf8/.UTF-8/g")" |
| 1083 | if [scip-shell system . . `[`. -n "$chosen_lang_var" -a -e "$DRBL_SCRIPT_PATH/lang/bash/$chosen_lang_var" ] ; then |
| 1084 | lang_answer="$chosen_lang_var" |
| 1085 | else |
| 1086 | lang_answer="en_US.UTF-8" |
| 1087 | fi |
| 1088 | elif [scip-shell system . . `[`. "$language_opt" = "ask" -o "$language_opt" = "a" ]; then |
| 1089 | # Language |
| 1090 | echoscip-shell system . . echo. "Language?". |
| 1091 | echoscip-shell system . . echo. "[0]: English" |
| 1092 | echoscip-shell system . . echo. "[2]: Traditional Chinese (UTF-8, Unicode) - Taiwan" |
| 1093 | echoscip-shell system . . echo. -n "[0] " |
| 1094 | read lang_answer |
| 1095 | [scip-shell system . . `[`. -z "$lang_answer" ] && lang_answer="en_US.UTF-8" |
| 1096 | else |
| 1097 | lang_answer="$language_opt" |
| 1098 | fi |
| 1099 | } # end of ask_lang_set |
| 1100 | |
| 1101 | load_lang_setscip-shell shell shell-project 0.0.0 load_lang_set().() { |
| 1102 | lang_answer=$1 |
| 1103 | # The language files are en, tw.UTF-8, we have to format the input parameter. |
| 1104 | case "$lang_answer" in |
| 1105 | 2|zh_TW.UTF-8|zh_TW.utf8|tw.UTF-8|tw.utf8) |
| 1106 | lang="zh_TW.UTF-8" |
| 1107 | ;; |
| 1108 | C) |
| 1109 | lang="en_US.UTF-8" |
| 1110 | ;; |
| 1111 | *) |
| 1112 | if [scip-shell system . . `[`. -n "$lang_answer" -a -e "$DRBL_SCRIPT_PATH/lang/bash/$lang_answer" ] ; then |
| 1113 | lang="$lang_answer" |
| 1114 | else |
| 1115 | lang="en_US.UTF-8" |
| 1116 | fi |
| 1117 | esac |
| 1118 | |
| 1119 | # get the l10n message |
| 1120 | if [scip-shell system . . `[`. -n "$lang" -a -e "$DRBL_SCRIPT_PATH/lang/bash/$lang" ] ; then |
| 1121 | . $DRBL_SCRIPT_PATH/lang/bash/$lang |
| 1122 | elif [scip-shell system . . `[`. -n "$lang" -a -e "$DRBL_SCRIPT_PATH/lang/bash/${lang%.UTF-8}" ] ; then |
| 1123 | . $DRBL_SCRIPT_PATH/lang/bash/${lang%.UTF-8} |
| 1124 | else |
| 1125 | echoscip-shell system . . echo. "No such language option '$lang'!!!" |
| 1126 | exit 1 |
| 1127 | fi |
| 1128 | } # end of load_lang_set |
| 1129 | # |
| 1130 | ask_and_load_lang_setscip-shell shell shell-project 0.0.0 ask_and_load_lang_set().() { |
| 1131 | local language_opt="$1" |
| 1132 | ask_lang_setscip-shell shell shell-project 0.0.0 ask_lang_set(). $language_opt |
| 1133 | load_lang_setscip-shell shell shell-project 0.0.0 load_lang_set(). $lang_answer |
| 1134 | } # end of ask_and_load_lang_set |
| 1135 | |
| 1136 | # |
| 1137 | language_help_prompt_by_idx_noscip-shell shell shell-project 0.0.0 language_help_prompt_by_idx_no().() { |
| 1138 | echoscip-shell system . . echo. " -l, --language INDEX Set the language to be shown by index number:" |
| 1139 | echoscip-shell system . . echo. " [0|en_US.UTF-8]: English," |
| 1140 | echoscip-shell system . . echo. " [2|zh_TW.UTF-8]: Traditional Chinese (UTF-8, Unicode) - Taiwan" |
| 1141 | echoscip-shell system . . echo. " [a|ask]: Prompt to ask the language index" |
| 1142 | echoscip-shell system . . echo. " This option is for backward compatibility. It's recommended to use locales to assign that." |
| 1143 | } |
| 1144 | # |
| 1145 | language_help_prompt_by_idx_namescip-shell shell shell-project 0.0.0 language_help_prompt_by_idx_name().() { |
| 1146 | echoscip-shell system . . echo. "-ln NAME Set the language to be shown by index name, not number, such as en_US.UTF-8, zh_TW.UTF-8" |
| 1147 | } |
| 1148 | |
| 1149 | # For update-rc.d in Debian |
| 1150 | prepare_update_rc_d_envscip-shell shell shell-project 0.0.0 prepare_update_rc_d_env().() { |
| 1151 | local newroot="$1" |
| 1152 | local perl_lib_need insserv_lib_need |
| 1153 | [scip-shell system . . `[`. -z "$newroot" ] && exit 1 |
| 1154 | # for update-rc.d |
| 1155 | cpscip-shell system . . cp. -f --parents /usr/sbin/update-rc.dscip-shell filesystem . . `/usr/sbin/update-rc.d`. $newroot |
| 1156 | cpscip-shell system . . cp. -f --parents /usr/bin/perlscip-shell filesystem . . `/usr/bin/perl`. $newroot |
| 1157 | perl_lib_need="$(LC_ALL=C lddscip-shell system . . ldd. /usr/bin/perlscip-shell filesystem . . `/usr/bin/perl`. | sedscip-shell system . . sed. -e "s/.*=> //g" -e "s/(0x.*)//g" | awkscip-shell system . . awk. '{print $1}')" |
| 1158 | export DESTDIR="$newroot" |
| 1159 | for imod in $perl_lib_need; do |
| 1160 | # Skip linux-vdso.so.1 and linux-gate.so.1, the virtual DSO, a shared object exposed by the kernel. They do not exist on the file system. Ref: http://ilivetoseek.wordpress.com/2011/10/24/linux-gate-so-1-or-linux-vdso-so-1/ |
| 1161 | [scip-shell system . . `[`. "$imod" = "linux-vdso.so.1" ] && continue |
| 1162 | [scip-shell system . . `[`. "$imod" = "linux-gate.so.1" ] && continue |
| 1163 | #cp --parents -d $imod $newroot |
| 1164 | copy_exec_drblscip-shell shell shell-project 0.0.0 copy_exec_drbl(). $imod "$(LC_ALL=C dirnamescip-shell system . . dirname. $imod)" |
| 1165 | done |
| 1166 | # Ugly! we need some perl pm... |
| 1167 | mkdirscip-shell system . . mkdir. -p $newroot/usr/{share,lib} |
| 1168 | # For perl >=5.20 in Debian, multi-arch is enabled |
| 1169 | # e.g. /usr/lib/i386-linux-gnu/perl, /usr/lib/x86_64-linux-gnu/perl/ |
| 1170 | rsyncscip-shell system . . rsync. -a /usr/share/perlscip-shell filesystem . . `/usr/share/perl`. $newroot/usr/share/ |
| 1171 | if [scip-shell system . . `[`. -n "$(lsscip-shell system . . ls. /usr/lib/*perl* 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" ]; then |
| 1172 | rsyncscip-shell system . . rsync. -a /usr/lib/*perl* $newroot/usr/lib/ |
| 1173 | fi |
| 1174 | if [scip-shell system . . `[`. -d "/usr/lib/i386-linux-gnu/perlscip-shell filesystem . . `/usr/lib/i386-linux-gnu/perl`." ]; then |
| 1175 | mkdirscip-shell system . . mkdir. -p $newroot/usr/lib/i386-linux-gnu/ |
| 1176 | rsyncscip-shell system . . rsync. -a /usr/lib/i386-linux-gnu/perlscip-shell filesystem . . `/usr/lib/i386-linux-gnu/perl`. $newroot/usr/lib/i386-linux-gnu/ |
| 1177 | fi |
| 1178 | if [scip-shell system . . `[`. -d "/usr/lib/x86_64-linux-gnu/perlscip-shell filesystem . . `/usr/lib/x86_64-linux-gnu/perl`." ]; then |
| 1179 | mkdirscip-shell system . . mkdir. -p $newroot/usr/lib/x86_64-linux-gnu/ |
| 1180 | rsyncscip-shell system . . rsync. -a /usr/lib/x86_64-linux-gnu/perlscip-shell filesystem . . `/usr/lib/x86_64-linux-gnu/perl`. $newroot/usr/lib/x86_64-linux-gnu/ |
| 1181 | fi |
| 1182 | |
| 1183 | # for insserv |
| 1184 | if type insserv &>/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 1185 | cpscip-shell system . . cp. -f --parents /sbin/insservscip-shell filesystem . . `/sbin/insserv`. $newroot |
| 1186 | insserv_lib_need="$(LC_ALL=C lddscip-shell system . . ldd. /sbin/insservscip-shell filesystem . . `/sbin/insserv`. | sedscip-shell system . . sed. -e "s/.*=> //g" -e "s/(0x.*)//g" | awkscip-shell system . . awk. '{print $1}')" |
| 1187 | for imod in $insserv_lib_need; do |
| 1188 | [scip-shell system . . `[`. "$imod" = "linux-vdso.so.1" ] && continue |
| 1189 | [scip-shell system . . `[`. "$imod" = "linux-gate.so.1" ] && continue |
| 1190 | cpscip-shell system . . cp. --parents -d $imod $newroot |
| 1191 | done |
| 1192 | fi |
| 1193 | } # end of prepare_update_rc_d_env |
| 1194 | |
| 1195 | # |
| 1196 | clean_update_rc_d_envscip-shell shell shell-project 0.0.0 clean_update_rc_d_env().() { |
| 1197 | local newroot="$1" |
| 1198 | [scip-shell system . . `[`. -z "$newroot" ] && exit 1 |
| 1199 | # we can clean files in /usr/bin and /usr/sbin in common_root because they are mount ponts. |
| 1200 | [scip-shell system . . `[`. -f $newroot/usr/bin/perl ] && rmscip-shell system . . rm. -f $newroot/usr/bin/perl |
| 1201 | [scip-shell system . . `[`. -f $newroot/usr/sbin/update-rc.d ] && rmscip-shell system . . rm. -f $newroot/usr/sbin/update-rc.d |
| 1202 | perl_lib_need=$(LC_ALL=C lddscip-shell system . . ldd. /usr/bin/perlscip-shell filesystem . . `/usr/bin/perl`. | sedscip-shell system . . sed. -e "s/.*=> //g" -e "s/(0x.*)//g" | awkscip-shell system . . awk. '{print $1}') |
| 1203 | for f2rm in $perl_lib_need; do |
| 1204 | [scip-shell system . . `[`. -f $newroot/$f2rm ] && rmscip-shell system . . rm. -f $newroot/$f2rm |
| 1205 | done |
| 1206 | } |
| 1207 | |
| 1208 | # |
| 1209 | chk_deb_installedscip-shell shell shell-project 0.0.0 chk_deb_installed(). () { |
| 1210 | local pkg_name=$1 |
| 1211 | local RC |
| 1212 | [scip-shell system . . `[`. -z "$pkg_name" ] && exit 1 |
| 1213 | # dpkg version 1.17.13 has a bug which fails to update /var/lib/dpkg/available in bootstrap environment. |
| 1214 | # Therefore the option --print-avail fails. We switched to use "dpkg -L". |
| 1215 | #dpkg-query --print-avail $pkg_name &>/dev/null |
| 1216 | dpkgscip-shell system . . dpkg. -L $pkg_name &>/dev/nullscip-shell filesystem . . `/dev/null`. |
| 1217 | RC=$? |
| 1218 | return $RC |
| 1219 | } |
| 1220 | # |
| 1221 | copy_rc1d_for_drbl_ssiscip-shell shell shell-project 0.0.0 copy_rc1d_for_drbl_ssi().() { |
| 1222 | # Note! use absolute path for template_cli |
| 1223 | local template_cli="$1" |
| 1224 | echoscip-shell system . . echo. -n "Copying files to $drbl_common_root/drbl_ssi for DRBL SSI... " |
| 1225 | mkdirscip-shell system . . mkdir. -p "$drbl_common_root/drbl_ssi/rc1.d" |
| 1226 | if [scip-shell system . . `[`. -z "$template_cli" ]; then |
| 1227 | for ih in $drblroot/*; do |
| 1228 | # use the 1st one drbl client we found as template |
| 1229 | if [scip-shell system . . `[`. -d "$ih" ]; then |
| 1230 | template_cli="$ih" |
| 1231 | break |
| 1232 | fi |
| 1233 | done |
| 1234 | fi |
| 1235 | cpscip-shell system . . cp. -af $template_cli/$RCX_ROOTDIR/rc1.d/* $drbl_common_root/drbl_ssi/rc1.d/ |
| 1236 | echoscip-shell system . . echo. "done!" |
| 1237 | } # end of copy_rc1d_for_drbl_ssi |
| 1238 | # |
| 1239 | remove_rc1d_for_drbl_ssiscip-shell shell shell-project 0.0.0 remove_rc1d_for_drbl_ssi().() { |
| 1240 | # Note! use absolute path for template_cli |
| 1241 | local template_cli="$1" |
| 1242 | echoscip-shell system . . echo. -n "Resetting files of $drbl_common_root/drbl_ssi for DRBL SSI... " |
| 1243 | # we just clean the unnecessary files, keep the directory |
| 1244 | if [scip-shell system . . `[`. -d "$drbl_common_root/drbl_ssi/rc1.d" ]; then |
| 1245 | rmscip-shell system . . rm. -rf $drbl_common_root/drbl_ssi/rc1.d |
| 1246 | fi |
| 1247 | echoscip-shell system . . echo. "done!" |
| 1248 | } # end of remove_rc1d_for_drbl_ssi |
| 1249 | # |
| 1250 | prepare_gdm_custom_confscip-shell shell shell-project 0.0.0 prepare_gdm_custom_conf().(){ |
| 1251 | # For ubuntu 9.10, the gdm 2.28.1-0ubuntu does not put /etc/gdm/custom.conf in the deb. It will be added when user creates it. |
| 1252 | if [scip-shell system . . `[`. -n "$($query_pkglist_cmd gdm 2>/dev/nullscip-shell filesystem . . `/dev/null`. | grepscip-shell system . . grep. -F "/usr/share/doc/gdm/examples/custom.confscip-shell filesystem . . `/usr/share/doc/gdm/examples/custom.conf`.")" ]; then |
| 1253 | # It must be /etc/gdm/custom.conf. We prepare one if not exits. |
| 1254 | # (1) For server, since drbl-powerful-thin-client might need that: |
| 1255 | if [scip-shell system . . `[`. ! -e "/etc/gdm/custom.confscip-shell filesystem . . `/etc/gdm/custom.conf`." ]; then |
| 1256 | cpscip-shell system . . cp. -a /usr/share/doc/gdm/examples/custom.confscip-shell filesystem . . `/usr/share/doc/gdm/examples/custom.conf`. /etc/gdm/custom.confscip-shell filesystem . . `/etc/gdm/custom.conf`. |
| 1257 | fi |
| 1258 | # (2) For client. We always use the one from /usr/share/doc/gdm/examples/custom.conf in case /etc/gdm/custom.conf is modified. |
| 1259 | cpscip-shell system . . cp. -af /usr/share/doc/gdm/examples/custom.confscip-shell filesystem . . `/usr/share/doc/gdm/examples/custom.conf`. $drbl_common_root/etc/gdm/custom.conf |
| 1260 | if [scip-shell system . . `[`. -z "$(grepscip-shell system . . grep. -E "^\[daemon\]" $drbl_common_root/etc/gdm/custom.conf 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" ]; then |
| 1261 | echoscip-shell system . . echo. "" >> $drbl_common_root/etc/gdm/custom.conf |
| 1262 | echoscip-shell system . . echo. "[daemon]" >> $drbl_common_root/etc/gdm/custom.conf |
| 1263 | fi |
| 1264 | GDM_CFG="/etc/gdm/custom.confscip-shell filesystem . . `/etc/gdm/custom.conf`." |
| 1265 | fi |
| 1266 | } # end of prepare_gdm_custom_conf |
| 1267 | # |
| 1268 | get_gdm_kdm_conf_filenamescip-shell shell shell-project 0.0.0 get_gdm_kdm_conf_filename().() { |
| 1269 | # Get the gdm, kdm, mdm config: |
| 1270 | # Ex: this is the setting for gdm 2.13 before and kdm 2.x/3.x |
| 1271 | # GDM_CFG="/etc/X11/gdm/gdm.conf" |
| 1272 | # FAC_GDM_CFG="/etc/X11/gdm/factory-gdm.conf" |
| 1273 | # KDM_CFG="/etc/kde3/kdm/kdmrc" |
| 1274 | # MDM_CFG="/etc/mdm/mdm.conf" |
| 1275 | # For gdm 2.13 or later, different filenames, such as custom.conf, gdm.conf-custom and kdmrc, no more factory-gdm.conf |
| 1276 | # For Ubuntu 9.10, since upstart use /etc/init/gdm.conf, we have to exclude that. |
| 1277 | GDM_CFG="" |
| 1278 | # The order "gdm.conf-custom custom.conf gdm.conf" is important, we put gdm.conf as the last one, since we wan to get only one $GDM_CFG, gdm.conf is always the last one to choose, if we can get gdm.conf-custom or custom.conf, we use that first |
| 1279 | # Note: Even in SuSE, gdm.conf/custom.conf is in /etc/opt/gnome/gdm/gdm.conf, we can get it by rpm -ql gdm, unlike kdm. It's not necessary to put /etc/ in the beginning. |
| 1280 | # For OpenSuSE 11.1, /etc/gdm/custom.conf is from package gdm-branding-openSUSE, and there is another same file name /etc/dbus-1/system.d/gdm.conf from package gdm, and /etc/dbus-1/system.d/gdm.conf is NOT what we want. |
| 1281 | for ipkg in gdm3 gdm gdm-branding-openSUSE; do |
| 1282 | for ig in daemon.conf gdm.conf-custom custom.conf gdm.conf; do |
| 1283 | GDM_CFG="$($query_pkglist_cmd $ipkg 2>/dev/nullscip-shell filesystem . . `/dev/null`. | grepscip-shell system . . grep. -E "\/$ig$" | grepscip-shell system . . grep. -Ev "dbus" | grepscip-shell system . . grep. -Evi "examples" | grepscip-shell system . . grep. -Evi "\/etc\/init\/")" |
| 1284 | [scip-shell system . . `[`. -n "$GDM_CFG" ] && break |
| 1285 | done |
| 1286 | [scip-shell system . . `[`. -n "$GDM_CFG" ] && break |
| 1287 | done |
| 1288 | FAC_GDM_CFG="$($query_pkglist_cmd gdm 2>/dev/nullscip-shell filesystem . . `/dev/null`. | grepscip-shell system . . grep. -E "\/factory-gdm.conf$")" |
| 1289 | if [scip-shell system . . `[`. -z "$GDM_CFG" ]; then |
| 1290 | prepare_gdm_custom_confscip-shell shell shell-project 0.0.0 prepare_gdm_custom_conf(). |
| 1291 | fi |
| 1292 | |
| 1293 | # kdmrc maybe in package kdm (Debian-based), kdebase (FC), kdebase-kdm-config-file (Mandrake) or kdebase3-kdm (OpenSuSE) |
| 1294 | # In FC, there are 2 kdmrc: |
| 1295 | # /etc/X11/xdm/kdmrc |
| 1296 | # /etc/kde/kdm/kdmrc |
| 1297 | # But /etc/X11/xdm/kdmrc is actually linked to /etc/kde/kdm/kdmrc, so use either one will be ok. |
| 1298 | for ipkg in kde4-kdm kdm kdebase kdebase-kdm-config-file kdebase3-kdm; do |
| 1299 | KDM_CFG="$($query_pkglist_cmd $ipkg 2>/dev/nullscip-shell filesystem . . `/dev/null`. | grepscip-shell system . . grep. -E "(\/kdmrc$)" | headscip-shell system . . head. -n 1)" |
| 1300 | if [scip-shell system . . `[`. -n "$(echoscip-shell system . . echo. $KDM_CFG | grepscip-shell system . . grep. -E "^\/opt\/kde")" ]; then |
| 1301 | # For SuSE 10.1 or earlier, actually the config file is in /etc/opt/kde3/share/config/kdm/kdmrc, therefore put /etc/ in the beginning. |
| 1302 | # For SuSE 10.2, no more /etc/opt/kde3/share/config/kdm/kdmrc, only /opt/kde3/share/config/kdm/kdmrc |
| 1303 | # Ref: http://lists.opensuse.org/opensuse-factory/2006-09/msg00021.html |
| 1304 | [scip-shell system . . `[`. -e "/etc/$KDM_CFG" ] && KDM_CFG=/etc/$KDM_CFG |
| 1305 | fi |
| 1306 | [scip-shell system . . `[`. -n "$KDM_CFG" ] && break |
| 1307 | done |
| 1308 | # For lightdm |
| 1309 | if [scip-shell system . . `[`. -e "/etc/lightdm/lightdm.confscip-shell filesystem . . `/etc/lightdm/lightdm.conf`." ]; then |
| 1310 | LIGHTDM_CFG=/etc/lightdm/lightdm.confscip-shell filesystem . . `/etc/lightdm/lightdm.conf`. |
| 1311 | elif [scip-shell system . . `[`. -d "/etc/lightdm/lightdm.conf.dscip-shell filesystem . . `/etc/lightdm/lightdm.conf.d`." ]; then |
| 1312 | # For Ubuntu 13.10, lightdm 1.8.4 has different initial configration file. |
| 1313 | # "/etc/lightdm/lightdm.conf" does not exist in the initial installation. |
| 1314 | # While it will exist when a user configures that in the GUI. |
| 1315 | LIGHTDM_CFG=/etc/lightdm/lightdm.confscip-shell filesystem . . `/etc/lightdm/lightdm.conf`. |
| 1316 | elif [scip-shell system . . `[`. -d "/usr/share/lightdm/lightdm.conf.dscip-shell filesystem . . `/usr/share/lightdm/lightdm.conf.d`." -a \ |
| 1317 | -e "/usr/share/doc/lightdm/lightdm.conf.gzscip-shell filesystem . . `/usr/share/doc/lightdm/lightdm.conf.gz`." ]; then |
| 1318 | # For Ubuntu 14.04, lightdm 1.10 has different way. The /etc/lightdm/lightdm.conf.d has been moved to /usr/share/lightdm/lightdm.conf.d, and /etc/lightdm/lightdm.conf does not exist in the beginning. Only a sample file exists in "/usr/share/doc/lightdm/lightdm.conf.gz". |
| 1319 | if [scip-shell system . . `[`. ! -f "$drbl_common_root/etc/lightdm/lightdm.conf" ]; then |
| 1320 | zcatscip-shell system . . zcat. "/usr/share/doc/lightdm/lightdm.conf.gzscip-shell filesystem . . `/usr/share/doc/lightdm/lightdm.conf.gz`." > "$drbl_common_root/etc/lightdm/lightdm.conf" |
| 1321 | fi |
| 1322 | LIGHTDM_CFG=/etc/lightdm/lightdm.confscip-shell filesystem . . `/etc/lightdm/lightdm.conf`. |
| 1323 | fi |
| 1324 | |
| 1325 | # For mdm : by Ceasar for Linuxmint |
| 1326 | if [scip-shell system . . `[`. -e "/etc/mdm/mdm.confscip-shell filesystem . . `/etc/mdm/mdm.conf`." ]; then |
| 1327 | # for mdm v2.0 |
| 1328 | MDM_CFG=/etc/mdm/mdm.confscip-shell filesystem . . `/etc/mdm/mdm.conf`. |
| 1329 | fi |
| 1330 | |
| 1331 | } # end of get_gdm_kdm_conf_filename |
| 1332 | # |
| 1333 | get_block_line_in_gdm_kdmscip-shell shell shell-project 0.0.0 get_block_line_in_gdm_kdm().() { |
| 1334 | local session="$1" |
| 1335 | local CFG_FILE="$2" |
| 1336 | [scip-shell system . . `[`. -e "$CFG_FILE" ] || exit 1 |
| 1337 | # Take xdmcp as an example: |
| 1338 | # Turn on the Enable=true in [xdmcp] |
| 1339 | # Enable=true |
| 1340 | # By using |
| 1341 | # grep -n "^\[.*\]" gdm.conf |grep -A1 "\[xdmcp\]" |
| 1342 | # We can get the results like: |
| 1343 | # 175:[xdmcp] |
| 1344 | # 210:[gui] |
| 1345 | # so we know we can replace the one between line no. 175 and 210 |
| 1346 | between_lines="$(LC_ALL=C grepscip-shell system . . grep. -n "^\[.*\]" $CFG_FILE |grepscip-shell system . . grep. -i -A1 "\[$session\]" | cutscip-shell system . . cut. -d":" -f1)" |
| 1347 | begin_line="$(echoscip-shell system . . echo. $between_lines | awkscip-shell system . . awk. -F" " '{print $1}')" |
| 1348 | end_line="$(echoscip-shell system . . echo. $between_lines | awkscip-shell system . . awk. -F" " '{print $2}')" |
| 1349 | if [scip-shell system . . `[`. -z "$begin_line" -a -z "$end_line" ]; then |
| 1350 | # no this session in file. Use the last line to append. |
| 1351 | begin_line="$(LC_ALL=C wcscip-shell system . . wc. -l $CFG_FILE | awkscip-shell system . . awk. -F" " '{print $1}')" |
| 1352 | end_line="$(LC_ALL=C wcscip-shell system . . wc. -l $CFG_FILE | awkscip-shell system . . awk. -F" " '{print $1}')" |
| 1353 | elif [scip-shell system . . `[`. -z "$end_line" ]; then |
| 1354 | # if end_line is nothing, it must be the last block, i.e. we can not find the next [.*] |
| 1355 | end_line="$(LC_ALL=C wcscip-shell system . . wc. -l $CFG_FILE | awkscip-shell system . . awk. -F" " '{print $1}')" |
| 1356 | else |
| 1357 | # if not nothing, backword one line |
| 1358 | end_line="$(($end_line - 1))" |
| 1359 | fi |
| 1360 | echoscip-shell system . . echo. "$begin_line $end_line" |
| 1361 | } # end of get_block_line_in_gdm_kdm |
| 1362 | |
| 1363 | # |
| 1364 | get_dhcpdlease_dirscip-shell shell shell-project 0.0.0 get_dhcpdlease_dir().() { |
| 1365 | if [scip-shell system . . `[`. -e /etc/debian_versionscip-shell filesystem . . `/etc/debian_version`. ]; then |
| 1366 | # Debian |
| 1367 | if [scip-shell system . . `[`. -d "/var/lib/dhcpscip-shell filesystem . . `/var/lib/dhcp`." ]; then |
| 1368 | DHCPDLEASE_DIR="/var/lib/dhcpscip-shell filesystem . . `/var/lib/dhcp`." |
| 1369 | elif [scip-shell system . . `[`. -d "/var/lib/dhcp3scip-shell filesystem . . `/var/lib/dhcp3`." ]; then |
| 1370 | DHCPDLEASE_DIR="/var/lib/dhcp3scip-shell filesystem . . `/var/lib/dhcp3`." |
| 1371 | fi |
| 1372 | elif [scip-shell system . . `[`. -e /etc/SuSE-releasescip-shell filesystem . . `/etc/SuSE-release`. ]; then |
| 1373 | # SuSE |
| 1374 | DHCPDLEASE_DIR="/var/lib/dhcp/dbscip-shell filesystem . . `/var/lib/dhcp/db`." |
| 1375 | else |
| 1376 | # RH-like |
| 1377 | # FC5: /var/lib/dhcpd/dhcpd.leases |
| 1378 | # RH 8.0/9, FC1-4: /var/lib/dhcp/dhcpd.leases |
| 1379 | # So this method is better: |
| 1380 | DHCPDLEASE_DIR="$(dirnamescip-shell system . . dirname. `rpm -ql dhcp | grepscip-shell system . . grep. -E "dhcpd.leases$"`)" |
| 1381 | fi |
| 1382 | } |
| 1383 | # |
| 1384 | countdownscip-shell shell shell-project 0.0.0 countdown(). () { |
| 1385 | local time_limit="$1" |
| 1386 | local i |
| 1387 | ( i="$time_limit" |
| 1388 | while [scip-shell system . . `[`. "$i" -ne 0 ]; do |
| 1389 | echoscip-shell system . . echo. -n "$i " |
| 1390 | sleepscip-shell system . . sleep. 1 |
| 1391 | i=$((i-1)) |
| 1392 | done |
| 1393 | ) |
| 1394 | } |
| 1395 | # |
| 1396 | is_drbl_clientscip-shell shell shell-project 0.0.0 is_drbl_client().() { |
| 1397 | root_src="$(LC_ALL=C mountscip-shell system . . mount. | grepscip-shell system . . grep. -Ew "on /" | awkscip-shell system . . awk. -F" " '{print $1}')" |
| 1398 | # Example for $root_src: 192.168.50.254:/tftpboot/node_root |
| 1399 | if [scip-shell system . . `[`. -n "$(echoscip-shell system . . echo. $root_src | grepscip-shell system . . grep. -E "^[[:space:]]*([[:digit:]]+\.){3}[[:digit:]]+:/.*")" ] ; then |
| 1400 | rc=0 |
| 1401 | else |
| 1402 | rc=1 |
| 1403 | fi |
| 1404 | return $rc |
| 1405 | } |
| 1406 | # |
| 1407 | add_param_in_pxelinux_cfg_drbl_related_blockscip-shell shell shell-project 0.0.0 add_param_in_pxelinux_cfg_drbl_related_block().() { |
| 1408 | local PXE_CONF="$1" |
| 1409 | local param_tmp="$2" |
| 1410 | [scip-shell system . . `[`. -z "$param_tmp" ] && echoscip-shell system . . echo. "You have to assign param_tmp in function add_param_in_pxelinux_cfg_drbl_related_block!" && return 1 |
| 1411 | for iblock in drbl drbl-terminal; do |
| 1412 | lines="$(get_pxecfg_image_blockscip-shell shell shell-project 0.0.0 get_pxecfg_image_block(). $iblock $PXE_CONF)" |
| 1413 | begin_line="$(LC_ALL=C echoscip-shell system . . echo. $lines | awkscip-shell system . . awk. -F" " '{print $1}')" |
| 1414 | end_line="$(LC_ALL=C echoscip-shell system . . echo. $lines | awkscip-shell system . . awk. -F" " '{print $2}')" |
| 1415 | tag_found="$(LC_ALL=C headscip-shell system . . head. -n $end_line $PXE_CONF | tailscip-shell system . . tail. -n $(($end_line-$begin_line)) | grepscip-shell system . . grep. -Ei "^[[:space:]]*append[[:space:]]*.*[[:space:]]+$param_tmp([[:space:]]+|$)")" |
| 1416 | if [scip-shell system . . `[`. -z "$tag_found" ]; then |
| 1417 | sub_menu_label_cmd="if ($begin_line..$end_line) {s|(^[[:space:]]*append[[:space:]]+.*)|\$1 $param_tmp|i}" |
| 1418 | perlscip-shell system . . perl. -pi -e "$sub_menu_label_cmd" $PXE_CONF |
| 1419 | fi |
| 1420 | done |
| 1421 | } # end of add_param_in_pxelinux_cfg_drbl_related_block |
| 1422 | # |
| 1423 | del_param_in_pxelinux_cfg_drbl_related_blockscip-shell shell shell-project 0.0.0 del_param_in_pxelinux_cfg_drbl_related_block().() { |
| 1424 | local PXE_CONF="$1" |
| 1425 | local param_tmp="$2" |
| 1426 | [scip-shell system . . `[`. -z "$param_tmp" ] && echoscip-shell system . . echo. "You have to assign param_tmp in function del_param_in_pxelinux_cfg_drbl_related_block!" && return 1 |
| 1427 | for iblock in drbl drbl-terminal; do |
| 1428 | lines="$(get_pxecfg_image_blockscip-shell shell shell-project 0.0.0 get_pxecfg_image_block(). $iblock $PXE_CONF)" |
| 1429 | begin_line="$(LC_ALL=C echoscip-shell system . . echo. $lines | awkscip-shell system . . awk. -F" " '{print $1}')" |
| 1430 | end_line="$(LC_ALL=C echoscip-shell system . . echo. $lines | awkscip-shell system . . awk. -F" " '{print $2}')" |
| 1431 | tag_found="$(LC_ALL=C headscip-shell system . . head. -n $end_line $PXE_CONF | tailscip-shell system . . tail. -n $(($end_line-$begin_line)) | grepscip-shell system . . grep. -Ei "^[[:space:]]*append[[:space:]]*.*[[:space:]]+$param_tmp([[:space:]]+|$)")" |
| 1432 | if [scip-shell system . . `[`. -n "$tag_found" ]; then |
| 1433 | sub_menu_label_cmd="if ($begin_line..$end_line) {s|$param_tmp||i}" |
| 1434 | perlscip-shell system . . perl. -pi -e "$sub_menu_label_cmd" $PXE_CONF |
| 1435 | fi |
| 1436 | done |
| 1437 | } # end of del_param_in_pxelinux_cfg_drbl_related_block |
| 1438 | # |
| 1439 | ocs_advanced_param_post_mode_after_clonescip-shell shell shell-project 0.0.0 ocs_advanced_param_post_mode_after_clone().() { |
| 1440 | local ocs_parm # The file to output the result //NOTE// This is to be append, not overwritten. |
| 1441 | local default_postaction="reboot " # //NOTE// Extra space is required |
| 1442 | # For Clonezilla SE mode, we always ask this (reboot, poweroff...) no matter it's advanced or beginner mode. |
| 1443 | while [scip-shell system . . `[`. $# -gt 0 ]; do |
| 1444 | case "$1" in |
| 1445 | -d|--default-menu) |
| 1446 | shift; |
| 1447 | if [scip-shell system . . `[`. -z "$(echoscip-shell system . . echo. $1 |grepscip-shell system . . grep. ^-.)" ]; then |
| 1448 | # skip the -xx option, in case |
| 1449 | default_postaction="$1" |
| 1450 | shift; |
| 1451 | fi |
| 1452 | [scip-shell system . . `[`. -z "$default_postaction" ] && USAGE && exit 1 |
| 1453 | ;; |
| 1454 | *) break ;; |
| 1455 | esac |
| 1456 | done |
| 1457 | ocs_parm="$1" |
| 1458 | if [scip-shell system . . `[`. -z "$ocs_postmode" ]; then |
| 1459 | # //NOTE// Extra space is required in the --default-item. |
| 1460 | $DIA --backtitle "$msg_nchc_free_software_labs" --title \ |
| 1461 | "$msg_clonezilla_advanced_extra_param | $msg_mode: $ocs_mode_prompt" \ |
| 1462 | --default-item "-p $default_postaction " \ |
| 1463 | --menu "$msg_choose_post_mode_after_clone:" \ |
| 1464 | 0 0 0 $DIA_ESC \ |
| 1465 | "-p reboot " "$msg_ocs_param_p_reboot" \ |
| 1466 | "-p poweroff " "$msg_ocs_param_p_poweroff" \ |
| 1467 | "-p choose " "$msg_ocs_param_p_choose" \ |
| 1468 | "-p true " "$msg_ocs_param_p_true" \ |
| 1469 | 2>> $ocs_parm |
| 1470 | else |
| 1471 | echoscip-shell system . . echo. "-p $ocs_postmode " >> $ocs_parm |
| 1472 | fi |
| 1473 | } # end of ocs_advanced_param_post_mode_after_clone |
| 1474 | # |
| 1475 | ocs_sr_param_postaction_after_clonescip-shell shell shell-project 0.0.0 ocs_sr_param_postaction_after_clone().() { |
| 1476 | local ocs_parm="$1" # The file to output the result //NOTE// This is to be append, not overwritten. |
| 1477 | $DIA --backtitle "$msg_nchc_free_software_labs" --title \ |
| 1478 | "$msg_mode: $ocs_mode_prompt" --menu "$msg_choose_post_mode_after_clone_1:" \ |
| 1479 | 0 0 0 $DIA_ESC \ |
| 1480 | "-p choose " "$msg_ocs_param_p_choose_1" \ |
| 1481 | "-p true" "$msg_enter_cml" \ |
| 1482 | "-p reboot " "$msg_ocs_param_p_reboot_1" \ |
| 1483 | "-p poweroff " "$msg_ocs_param_p_poweroff_1" \ |
| 1484 | 2>> $ocs_parm |
| 1485 | } # end of ocs_sr_param_postaction_after_clone |
| 1486 | # |
| 1487 | ocs_onthefly_param_postaction_after_clonescip-shell shell shell-project 0.0.0 ocs_onthefly_param_postaction_after_clone().() { |
| 1488 | local ocs_parm="$1" # The file to output the result //NOTE// This is to be append, not overwritten. |
| 1489 | $DIA --backtitle "$msg_nchc_free_software_labs" --title \ |
| 1490 | "$msg_mode: $ocs_mode_prompt" --menu "$msg_choose_post_mode_after_clone_1:" \ |
| 1491 | 0 0 0 $DIA_ESC \ |
| 1492 | "-p choose " "$msg_ocs_param_p_choose_1" \ |
| 1493 | "-p true" "$msg_enter_cml" \ |
| 1494 | "-p reboot " "$msg_ocs_param_p_reboot_1" \ |
| 1495 | "-p poweroff " "$msg_ocs_param_p_poweroff_1" \ |
| 1496 | 2>> $ocs_parm |
| 1497 | } # end of ocs_onthefly_param_postaction_after_clone |
| 1498 | # |
| 1499 | show_z4_or_above_menu_or_notscip-shell shell shell-project 0.0.0 show_z4_or_above_menu_or_not().() { |
| 1500 | # function to show -z4, -z5/z5p, -z6/z6p options |
| 1501 | if type lzma &>/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 1502 | # "-z4" "$msg_ocs_param_z4" \ |
| 1503 | ocs_z4_option_1="-z4" |
| 1504 | ocs_z4_option_2="$(rep_whspc_w_udrsc "$msg_ocs_param_z4")" |
| 1505 | fi |
| 1506 | if type xz &>/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 1507 | # "-z5" "$msg_ocs_param_z5" \ |
| 1508 | ocs_z5_option_1="-z5" |
| 1509 | ocs_z5_option_2="$(rep_whspc_w_udrsc "$msg_ocs_param_z5")" |
| 1510 | |
| 1511 | # "-z5p" "$msg_ocs_param_z5p" \ |
| 1512 | ocs_z5p_option_1="-z5p" |
| 1513 | ocs_z5p_option_2="$(rep_whspc_w_udrsc "$msg_ocs_param_z5p")" |
| 1514 | fi |
| 1515 | if type lzip &>/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 1516 | # "-z6" "$msg_ocs_param_z6" \ |
| 1517 | ocs_z6_option_1="-z6" |
| 1518 | ocs_z6_option_2="$(rep_whspc_w_udrsc "$msg_ocs_param_z6")" |
| 1519 | fi |
| 1520 | if type plzip &>/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 1521 | # "-z6p" "$msg_ocs_param_z6p" \ |
| 1522 | ocs_z6p_option_1="-z6p" |
| 1523 | ocs_z6p_option_2="$(rep_whspc_w_udrsc "$msg_ocs_param_z6p")" |
| 1524 | fi |
| 1525 | if type lrzip &>/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 1526 | # "-z7" "$msg_ocs_param_z7" \ |
| 1527 | ocs_z7_option_1="-z7" |
| 1528 | ocs_z7_option_2="$(rep_whspc_w_udrsc "$msg_ocs_param_z7")" |
| 1529 | fi |
| 1530 | if type lz4 &>/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 1531 | # "-z8" "$msg_ocs_param_z8" \ |
| 1532 | ocs_z8_option_1="-z8" |
| 1533 | ocs_z8_option_2="$(rep_whspc_w_udrsc "$msg_ocs_param_z8")" |
| 1534 | # "-z8p" "$msg_ocs_param_z8p" \ |
| 1535 | ocs_z8p_option_1="-z8p" |
| 1536 | ocs_z8p_option_2="$(rep_whspc_w_udrsc "$msg_ocs_param_z8p")" |
| 1537 | fi |
| 1538 | if type zstd &>/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 1539 | # "-z9" "$msg_ocs_param_z9" \ |
| 1540 | ocs_z9_option_1="-z9" |
| 1541 | ocs_z9_option_2="$(rep_whspc_w_udrsc "$msg_ocs_param_z9")" |
| 1542 | fi |
| 1543 | if type zstdmt &>/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 1544 | # "-z9p" "$msg_ocs_param_z9p" \ |
| 1545 | ocs_z9p_option_1="-z9p" |
| 1546 | ocs_z9p_option_2="$(rep_whspc_w_udrsc "$msg_ocs_param_z9p")" |
| 1547 | fi |
| 1548 | } # end show_z4_or_above_menu_or_not |
| 1549 | # |
| 1550 | set_drbl_ocs_extra_paramscip-shell shell shell-project 0.0.0 set_drbl_ocs_extra_param().() { |
| 1551 | local mode |
| 1552 | # OCS_PARAM_TMP is a global variable |
| 1553 | local dev_ |
| 1554 | local vol_size_tmp |
| 1555 | local ASK_VOL_SIZE=1 |
| 1556 | local inst_grub_opt |
| 1557 | local set_y_opt="yes" # Option to set option y* (y0/y1/y2) |
| 1558 | local default_postaction postaction_opt j2_switch_msg_1 j2_switch_msg_2 j2_switch_msg_3 |
| 1559 | |
| 1560 | while [scip-shell system . . `[`. $# -gt 0 ]; do |
| 1561 | case "$1" in |
| 1562 | -s|--skip-y) set_y_opt="no"; shift;; |
| 1563 | -p|--default-postaction) |
| 1564 | shift; |
| 1565 | if [scip-shell system . . `[`. -z "$(echoscip-shell system . . echo. $1 |grepscip-shell system . . grep. ^-.)" ]; then |
| 1566 | # skip the -xx option, in case |
| 1567 | default_postaction="$1" |
| 1568 | shift; |
| 1569 | fi |
| 1570 | [scip-shell system . . `[`. -z "$default_postaction" ] && USAGE && exit 1 |
| 1571 | ;; |
| 1572 | *) break ;; |
| 1573 | esac |
| 1574 | done |
| 1575 | |
| 1576 | mode="$1" |
| 1577 | dev_="$2" |
| 1578 | vol_size_tmp="$(mktempscip-shell system . . mktemp. /tmp/vol_size_tmp.XXXXXXscip-shell filesystem . . `/tmp/vol_size_tmp.XXXXXX`.)" |
| 1579 | |
| 1580 | if [scip-shell system . . `[`. -z "$OCS_PARAM_TMP" ]; then |
| 1581 | echoscip-shell system . . echo. "\"$OCS_PARAM_TMP\" was not assigned in function set_drbl_ocs_extra_param." |
| 1582 | echoscip-shell system . . echo. "$msg_program_stop!" |
| 1583 | exit 1 |
| 1584 | fi |
| 1585 | |
| 1586 | # If the mode is only for parts, we won't turn on "-g auto" option by default |
| 1587 | case "$dev_" in |
| 1588 | parts) inst_grub_opt="off" |
| 1589 | # For restoreparts, forget about clean mbr |
| 1590 | skip_clean_mbr_opt="on" |
| 1591 | ;; |
| 1592 | *) inst_grub_opt="on" |
| 1593 | # For restoredisk, do mbr cleaning |
| 1594 | skip_clean_mbr_opt="off" |
| 1595 | ;; |
| 1596 | esac |
| 1597 | |
| 1598 | if [scip-shell system . . `[`. "$mode" = "restore" ]; then |
| 1599 | if [scip-shell system . . `[`. "$ocs_user_mode" = "expert" ]; then |
| 1600 | # The option "-j2" (clone_hidden_data) should be only enabled by default when it's restoredisk |
| 1601 | # Ref: https://sourceforge.net/p/clonezilla/bugs/361/ |
| 1602 | case "$dev_" in |
| 1603 | parts) # For restoreparts |
| 1604 | j2_switch_msg_1="" |
| 1605 | j2_switch_msg_2="" |
| 1606 | j2_switch_msg_3="" |
| 1607 | ;; |
| 1608 | disk) # For restoredisk |
| 1609 | j2_switch_msg_1="-j2" |
| 1610 | j2_switch_msg_2="$(rep_whspc_w_udrsc "$msg_ocs_param_j2")" |
| 1611 | j2_switch_msg_3="on" |
| 1612 | ;; |
| 1613 | esac |
| 1614 | $DIA --separate-output --backtitle "$msg_nchc_free_software_labs" --title \ |
| 1615 | "$msg_clonezilla_advanced_extra_param | $msg_mode: $ocs_mode_prompt" --checklist "$msg_choose_param_to_set_multiple_choices ($msg_press_space_to_mark_selection)" \ |
| 1616 | 0 0 0 $DIA_ESC \ |
| 1617 | "-g auto" "$msg_ocs_param_g_auto" $inst_grub_opt \ |
| 1618 | "-e1 auto" "$msg_ocs_param_e1_auto" on \ |
| 1619 | "-e2" "$msg_ocs_param_e2" on \ |
| 1620 | "-x" "$msg_ocs_param_x" on \ |
| 1621 | "-nogui" "$msg_ocs_param_nogui" off \ |
| 1622 | "-hn0 $WIN_HOSTNAME_PREFIX" "$msg_ocs_param_hn0" off \ |
| 1623 | "-hn1 $WIN_HOSTNAME_PREFIX" "$msg_ocs_param_hn1" off \ |
| 1624 | "-v" "$msg_ocs_param_v" off \ |
| 1625 | "-c" "$msg_ocs_param_c" off \ |
| 1626 | "-u" "$msg_ocs_param_u" off \ |
| 1627 | "-t" "$msg_ocs_param_t" $skip_clean_mbr_opt \ |
| 1628 | "-t1" "$msg_ocs_param_t1" off \ |
| 1629 | "-t2" "$msg_ocs_param_t2" off \ |
| 1630 | "-r" "$msg_ocs_param_r" off \ |
| 1631 | "-ns" "$msg_ocs_param_ns" off \ |
| 1632 | "-e" "$msg_ocs_param_e" off \ |
| 1633 | "-icrc" "$msg_ocs_param_icrc" off \ |
| 1634 | "-irhr" "$msg_ocs_param_irhr" off \ |
| 1635 | "-irvd" "$msg_ocs_param_irvd" off \ |
| 1636 | "-ius" "$msg_ocs_param_ius" off \ |
| 1637 | "-iui" "$msg_ocs_param_iui" off \ |
| 1638 | "-icds" "$msg_ocs_param_icds" off \ |
| 1639 | "-iefi" "$msg_ocs_param_iefi" off \ |
| 1640 | "-j1" "$msg_ocs_param_j1" off \ |
| 1641 | $j2_switch_msg_1 $j2_switch_msg_2 $j2_switch_msg_3 \ |
| 1642 | "-cm" "$msg_ocs_param_cm" off \ |
| 1643 | "-cs" "$msg_ocs_param_cs" off \ |
| 1644 | "-cb2" "$msg_ocs_param_cb2" off \ |
| 1645 | "-cb3" "$msg_ocs_param_cb3" off \ |
| 1646 | "-cmf" "$msg_ocs_param_cmf" off \ |
| 1647 | "-f" "$msg_ocs_param_f" off \ |
| 1648 | "-rescue " "$msg_ocs_param_rescue" off \ |
| 1649 | "-s" "$msg_ocs_param_s" off \ |
| 1650 | "-a" "$msg_ocs_param_a" off \ |
| 1651 | "-o0" "$msg_ocs_param_o0" off \ |
| 1652 | "-o1" "$msg_ocs_param_o1" off \ |
| 1653 | "-srel" "$msg_ocs_param_srel" off \ |
| 1654 | "-ssnf" "$msg_ocs_param_ssnf" off \ |
| 1655 | "-ps" "$msg_ocs_param_ps" off \ |
| 1656 | "-edio" "$msg_ocs_param_edio" on \ |
| 1657 | "-rmtd" "$msg_ocs_param_rmtd" off \ |
| 1658 | "-rmmcb" "$msg_ocs_param_rmmcb" off \ |
| 1659 | "-reluks" "$msg_ocs_param_reluks" off \ |
| 1660 | 2>> $OCS_PARAM_TMP |
| 1661 | else |
| 1662 | # Beginner mode. Use default settings |
| 1663 | if [scip-shell system . . `[`. "$inst_grub_opt" = "on" ]; then |
| 1664 | # restoredisk mode. |
| 1665 | # "$inst_grub_opt" = "on" (-g auto) means skip_clean_mbr_opt="off" (no -t) |
| 1666 | echoscip-shell system . . echo. "-g auto" "-e1 auto" "-e2" "-r" "-x" "-j2" "-edio" >> $OCS_PARAM_TMP |
| 1667 | else |
| 1668 | # restoreparts mode. |
| 1669 | # "$inst_grub_opt" = "off" (no "-g auto") means skip_clean_mbr_opt="on" (-t) |
| 1670 | # Do not enable -j2 by default since for restoreparts, it should not be done by default. |
| 1671 | # Ref: https://sourceforge.net/p/clonezilla/bugs/361/ |
| 1672 | echoscip-shell system . . echo. "-e1 auto" "-e2" "-t" "-r" "-x" "-edio" >> $OCS_PARAM_TMP |
| 1673 | fi |
| 1674 | fi |
| 1675 | |
| 1676 | # About partition table |
| 1677 | case "$dev_" in |
| 1678 | parts) |
| 1679 | # Partition restore only. default NOT to create partition table |
| 1680 | if [scip-shell system . . `[`. "$ocs_user_mode" = "expert" ]; then |
| 1681 | $DIA --backtitle "$msg_nchc_free_software_labs" --title \ |
| 1682 | "$msg_clonezilla_advanced_extra_param | $msg_mode: $ocs_mode_prompt" --menu "$msg_hint_for_fdisk \n$msg_choose_param_to_set_single_choice" \ |
| 1683 | 0 0 0 $DIA_ESC \ |
| 1684 | "-k " "$msg_ocs_param_k" \ |
| 1685 | "-k1 " "$msg_ocs_param_k1" \ |
| 1686 | "-k2 " "$msg_ocs_param_k2" \ |
| 1687 | "-j0 " "$msg_ocs_param_j0" \ |
| 1688 | "-k0 " "$msg_use_the_part_table_from_image" \ |
| 1689 | "exit " "$msg_exit" \ |
| 1690 | 2>> $OCS_PARAM_TMP |
| 1691 | else |
| 1692 | echoscip-shell system . . echo. "-k " >> $OCS_PARAM_TMP |
| 1693 | fi |
| 1694 | ;; |
| 1695 | *) |
| 1696 | # Disk restore, default to create partition table |
| 1697 | if [scip-shell system . . `[`. "$ocs_user_mode" = "expert" ]; then |
| 1698 | $DIA --backtitle "$msg_nchc_free_software_labs" --title \ |
| 1699 | "$msg_clonezilla_advanced_extra_param | $msg_mode: $ocs_mode_prompt" --menu "$msg_hint_for_fdisk \n$msg_choose_param_to_set_single_choice" \ |
| 1700 | 0 0 0 $DIA_ESC \ |
| 1701 | "-k0 " "$msg_use_the_part_table_from_image" \ |
| 1702 | "-k " "$msg_ocs_param_k" \ |
| 1703 | "-k1 " "$msg_ocs_param_k1" \ |
| 1704 | "-k2 " "$msg_ocs_param_k2" \ |
| 1705 | "-j0 " "$msg_ocs_param_j0" \ |
| 1706 | "exit " "$msg_exit" \ |
| 1707 | 2>> $OCS_PARAM_TMP |
| 1708 | else |
| 1709 | # Beginner mode. |
| 1710 | $DIA --backtitle "$msg_nchc_free_software_labs" --title \ |
| 1711 | "$msg_mode: $ocs_mode_prompt" --menu "$msg_hint_for_fdisk_beginner \n$msg_choose_default_param_if_no_idea" \ |
| 1712 | 0 0 0 $DIA_ESC \ |
| 1713 | "-k0 " "$msg_use_the_part_table_from_image" \ |
| 1714 | "-k1 " "$msg_ocs_param_k1" \ |
| 1715 | "exit " "$msg_exit" \ |
| 1716 | 2>> $OCS_PARAM_TMP |
| 1717 | fi |
| 1718 | ;; |
| 1719 | esac |
| 1720 | if grepscip-shell system . . grep. -Ew "exit" $OCS_PARAM_TMP &>/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 1721 | echoscip-shell system . . echo. "$msg_program_stop" |
| 1722 | exit 1 |
| 1723 | fi |
| 1724 | # Question about checking the image is restorable or not. By default, no matter it's beginner or advanced mode, |
| 1725 | # we will ask. |
| 1726 | if [scip-shell system . . `[`. -z "$chk_img_restoreable_on_srv" ]; then |
| 1727 | $DIA --backtitle "$msg_nchc_free_software_labs" --title \ |
| 1728 | "$msg_clonezilla_advanced_extra_param | $msg_mode: $ocs_mode_prompt" --menu "$msg_choose_if_checking_image_restorable_before_restoring_on_this_server" \ |
| 1729 | 0 0 0 $DIA_ESC \ |
| 1730 | " " "$msg_ocs_param_check_img_restorable_before_restoring" \ |
| 1731 | "-sc0 " "$msg_ocs_param_skip_checking_img_restorable_before_restoring" \ |
| 1732 | 2>> $OCS_PARAM_TMP |
| 1733 | else |
| 1734 | echoscip-shell system . . echo. " " >> $OCS_PARAM_TMP |
| 1735 | fi |
| 1736 | if LC_ALL=C grepscip-shell system . . grep. -Ew -- "(-k1|-k2)" $OCS_PARAM_TMP &>/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 1737 | # Option -k1 or -k2 is for different partition size, turn on -r and -icds by default |
| 1738 | if [scip-shell system . . `[`. -z "$(LC_ALL=C grepscip-shell system . . grep. -Ew -- "-r" $OCS_PARAM_TMP)" ]; then |
| 1739 | echoscip-shell system . . echo. "Since the mode you choose might resize partition size, we turn on file system resize funtion automatically (-r)..." |
| 1740 | echoscip-shell system . . echo. "-r " >> $OCS_PARAM_TMP |
| 1741 | fi |
| 1742 | if [scip-shell system . . `[`. -z "$(LC_ALL=C grepscip-shell system . . grep. -Ew -- "-icds" $OCS_PARAM_TMP)" ]; then |
| 1743 | echoscip-shell system . . echo. "Since the mode you choose might resize partition size, we now enable option \"-icds\" to ignore the partition size checking in Partclone..." |
| 1744 | echoscip-shell system . . echo. "-icds ">> $OCS_PARAM_TMP |
| 1745 | fi |
| 1746 | fi |
| 1747 | |
| 1748 | # about y[0-2] |
| 1749 | if [scip-shell system . . `[`. "$set_y_opt" = "yes" ]; then |
| 1750 | if [scip-shell system . . `[`. "$ocs_user_mode" = "expert" ]; then |
| 1751 | $DIA --backtitle "$msg_nchc_free_software_labs" --title \ |
| 1752 | "$msg_clonezilla_advanced_extra_param | $msg_mode: $ocs_mode_prompt" --menu "$msg_if_always_provide_clonezilla_srv" \ |
| 1753 | 0 0 0 $DIA_ESC \ |
| 1754 | " " "$msg_ocs_param_skip" \ |
| 1755 | "-y0 " "$msg_ocs_param_y0" \ |
| 1756 | "-y1 " "$msg_ocs_param_y1" \ |
| 1757 | "-y2 " "$msg_ocs_param_y2" \ |
| 1758 | 2>> $OCS_PARAM_TMP |
| 1759 | else |
| 1760 | echoscip-shell system . . echo. " " >> $OCS_PARAM_TMP |
| 1761 | fi |
| 1762 | fi |
| 1763 | else |
| 1764 | # Save mode. |
| 1765 | # about -q, -q1, -q2 |
| 1766 | if [scip-shell system . . `[`. "$ocs_user_mode" = "expert" ]; then |
| 1767 | $DIA --backtitle "$msg_nchc_free_software_labs" --title \ |
| 1768 | "$msg_clonezilla_advanced_extra_param | $msg_mode: $ocs_mode_prompt" --menu "$msg_choose_param_for_clone_prog" \ |
| 1769 | 0 0 0 $DIA_ESC \ |
| 1770 | "-q2 " "$msg_ocs_param_q2" \ |
| 1771 | "-q1 " "$msg_ocs_param_q1" \ |
| 1772 | "-q " "$msg_ocs_param_q" \ |
| 1773 | " " "$msg_ocs_param_none_ie_partimage" \ |
| 1774 | 2>> $OCS_PARAM_TMP |
| 1775 | else |
| 1776 | echoscip-shell system . . echo. "-q2 " >> $OCS_PARAM_TMP |
| 1777 | fi |
| 1778 | |
| 1779 | get_smtd_smmcb_switchscip-shell shell shell-project 0.0.0 get_smtd_smmcb_switch(). # Obtain smtd_smmcb_switch |
| 1780 | if [scip-shell system . . `[`. "$ocs_user_mode" = "expert" ]; then |
| 1781 | $DIA --separate-output --backtitle "$msg_nchc_free_software_labs" --title \ |
| 1782 | "$msg_clonezilla_advanced_extra_param | $msg_mode: $ocs_mode_prompt" --checklist "$msg_choose_param_to_set_multiple_choices ($msg_press_space_to_mark_selection):" \ |
| 1783 | 0 0 0 $DIA_ESC \ |
| 1784 | "-c " "$msg_ocs_param_c" off \ |
| 1785 | "-j2 " "$msg_ocs_param_j2" on \ |
| 1786 | "-nogui " "$msg_ocs_param_nogui" off \ |
| 1787 | "-a " "$msg_ocs_param_a" off \ |
| 1788 | "-batch " "$msg_ocs_param_b" off \ |
| 1789 | "-f " "$msg_ocs_param_f" off \ |
| 1790 | "-s " "$msg_ocs_param_s" off \ |
| 1791 | "-rm-win-swap-hib " "$msg_ocs_param_rm_win_swap_hib" off \ |
| 1792 | "-ntfs-ok " "$msg_ocs_param_ntfs_ok" off \ |
| 1793 | "-rescue " "$msg_ocs_param_rescue" off \ |
| 1794 | "-gm " "$msg_ocs_param_gm" off \ |
| 1795 | "-gs " "$msg_ocs_param_gs" off \ |
| 1796 | "-gb2 " "$msg_ocs_param_gb2" off \ |
| 1797 | "-gb3 " "$msg_ocs_param_gb3" off \ |
| 1798 | "-gmf " "$msg_ocs_param_gmf" off \ |
| 1799 | "-noabo " "$msg_ocs_param_noabo" off \ |
| 1800 | "-o0 " "$msg_ocs_param_o0" off \ |
| 1801 | "-o1 " "$msg_ocs_param_o1" off \ |
| 1802 | "-ps " "$msg_ocs_param_ps" off \ |
| 1803 | "-scpt " "$msg_ocs_param_scpt" off \ |
| 1804 | "-sfs " "$msg_ocs_param_sfs" off \ |
| 1805 | "-edio " "$msg_ocs_param_edio" on \ |
| 1806 | "-smtd " "$msg_ocs_param_smtd" $smtd_smmcb_switch \ |
| 1807 | "-smmcb " "$msg_ocs_param_smmcb" $smtd_smmcb_switch \ |
| 1808 | 2>> $OCS_PARAM_TMP |
| 1809 | else |
| 1810 | case "$smtd_smmcb_switch" in |
| 1811 | on) echoscip-shell system . . echo. "-j2 " "-edio " "-smtd " "-smmcb " >> $OCS_PARAM_TMP;; |
| 1812 | off) echoscip-shell system . . echo. "-j2 " "-edio " >> $OCS_PARAM_TMP;; |
| 1813 | esac |
| 1814 | fi |
| 1815 | # Question about fsck the source partition. By default, no matter it's beginner or advanced mode, we will ask. |
| 1816 | if [scip-shell system . . `[`. -z "$fsck_src_part_intr" -a -z "$fsck_src_part_auto" ]; then |
| 1817 | $DIA --backtitle "$msg_nchc_free_software_labs" --title \ |
| 1818 | "$msg_clonezilla_advanced_extra_param | $msg_mode: $ocs_mode_prompt" --menu "$msg_choose_if_fsck_the_source_part" \ |
| 1819 | 0 0 0 $DIA_ESC \ |
| 1820 | " " "$msg_skip_check_source_fs" \ |
| 1821 | "-fsck " "$msg_ocs_param_fsck_src_part" \ |
| 1822 | "-fsck-y " "$msg_ocs_param_fsck_src_part_yes" \ |
| 1823 | 2>> $OCS_PARAM_TMP |
| 1824 | else |
| 1825 | case "$fsck_src_part_intr" in |
| 1826 | yes) echoscip-shell system . . echo. "-fsck " >> $OCS_PARAM_TMP;; |
| 1827 | *) echoscip-shell system . . echo. " " >> $OCS_PARAM_TMP;; |
| 1828 | esac |
| 1829 | case "$fsck_src_part_auto" in |
| 1830 | yes) echoscip-shell system . . echo. "-fsck-y " >> $OCS_PARAM_TMP;; |
| 1831 | *) echoscip-shell system . . echo. " " >> $OCS_PARAM_TMP;; |
| 1832 | esac |
| 1833 | fi |
| 1834 | |
| 1835 | # Question about checking the image is restorable or not. By default, no matter it's beginner or advanced mode, |
| 1836 | # we will ask. |
| 1837 | if [scip-shell system . . `[`. -z "$chk_img_restoreable_mod_save" ]; then |
| 1838 | $DIA --backtitle "$msg_nchc_free_software_labs" --title \ |
| 1839 | "$msg_clonezilla_advanced_extra_param | $msg_mode: $ocs_mode_prompt" --menu "$msg_choose_if_checking_image_restorable" \ |
| 1840 | 0 0 0 $DIA_ESC \ |
| 1841 | " " "$msg_ocs_param_check_img_restorable" \ |
| 1842 | "-scs " "$msg_ocs_param_skip_checking_img_restorable" \ |
| 1843 | 2>> $OCS_PARAM_TMP |
| 1844 | else |
| 1845 | case "$chk_img_restoreable_mod_save" in |
| 1846 | yes) echoscip-shell system . . echo. " " >> $OCS_PARAM_TMP;; |
| 1847 | no) echoscip-shell system . . echo. "-scs " >> $OCS_PARAM_TMP;; |
| 1848 | esac |
| 1849 | fi |
| 1850 | fi |
| 1851 | |
| 1852 | if [scip-shell system . . `[`. -n "$default_postaction" ]; then |
| 1853 | postaction_opt="-d $default_postaction" |
| 1854 | fi |
| 1855 | ocs_advanced_param_post_mode_after_clonescip-shell shell shell-project 0.0.0 ocs_advanced_param_post_mode_after_clone(). $postaction_opt $OCS_PARAM_TMP |
| 1856 | |
| 1857 | # if -hn0|-hn1 is chosen, |
| 1858 | # (1). prompt the warning about ntfs-3g/nfsmount for ntfs is necessary |
| 1859 | # (2). ask if the hostname prefix want to change |
| 1860 | if grepscip-shell system . . grep. -qE "\-hn[01]" $OCS_PARAM_TMP; then |
| 1861 | # part 1. |
| 1862 | $DIA --title "$msg_change_hostname_of_MS_WIN_on_the_fly" --clear \ |
| 1863 | --msgbox "$msg_write_MS_WIN_is_necessary" 15 70 |
| 1864 | |
| 1865 | # part 2. |
| 1866 | HNTMP="$(mktempscip-shell system . . mktemp. /tmp/winhn.XXXXXXscip-shell filesystem . . `/tmp/winhn.XXXXXX`.)" |
| 1867 | $DIA --backtitle "$msg_nchc_free_software_labs" --title "$msg_nchc_clonezilla" \ |
| 1868 | --inputbox "$msg_What_the_win_hostname_prefix ?" 0 0 "$WIN_HOSTNAME_PREFIX" 2> $HNTMP |
| 1869 | HN_PREFIX="$(catscip-shell system . . cat. $HNTMP)" |
| 1870 | if [scip-shell system . . `[`. -z "$HN_PREFIX" ]; then |
| 1871 | echoscip-shell system . . echo. "You did not specify the hostname prefix for MS windows! We use the default value in drbl-ocs.conf" |
| 1872 | else |
| 1873 | perlscip-shell system . . perl. -pi -e "s|(-hn.*) $WIN_HOSTNAME_PREFIX|\$1 $HN_PREFIX|g" $OCS_PARAM_TMP |
| 1874 | fi |
| 1875 | [scip-shell system . . `[`. -f "$HNTMP" ] && rmscip-shell system . . rm. -f $HNTMP |
| 1876 | fi |
| 1877 | |
| 1878 | if [scip-shell system . . `[`. "$mode" = "save" ]; then |
| 1879 | # Save mode. |
| 1880 | show_z4_or_above_menu_or_notscip-shell shell shell-project 0.0.0 show_z4_or_above_menu_or_not(). |
| 1881 | # We can not detect # of the CPU cores in the clients from server, hence let user choose. |
| 1882 | if [scip-shell system . . `[`. "$ocs_user_mode" = "expert" ]; then |
| 1883 | $DIA --backtitle "$msg_nchc_free_software_labs" --title \ |
| 1884 | "$msg_clonezilla_advanced_extra_param | $msg_mode: $ocs_mode_prompt" --menu "$msg_choose_one_compression_param_to_save" \ |
| 1885 | --default-item "$ocs_z9p_option_1" \ |
| 1886 | 0 0 0 $DIA_ESC \ |
| 1887 | "-z1p" "$msg_ocs_param_z1p" \ |
| 1888 | "-z1" "$msg_ocs_param_z1" \ |
| 1889 | "-z2p" "$msg_ocs_param_z2p" \ |
| 1890 | "-z2" "$msg_ocs_param_z2" \ |
| 1891 | "-z3" "$msg_ocs_param_z3" \ |
| 1892 | $ocs_z4_option_1 $ocs_z4_option_2 \ |
| 1893 | $ocs_z5p_option_1 $ocs_z5p_option_2 \ |
| 1894 | $ocs_z5_option_1 $ocs_z5_option_2 \ |
| 1895 | $ocs_z6p_option_1 $ocs_z6p_option_2 \ |
| 1896 | $ocs_z6_option_1 $ocs_z6_option_2 \ |
| 1897 | $ocs_z7_option_1 $ocs_z7_option_2 \ |
| 1898 | $ocs_z8_option_1 $ocs_z8_option_2 \ |
| 1899 | $ocs_z8p_option_1 $ocs_z8p_option_2 \ |
| 1900 | $ocs_z9_option_1 $ocs_z9_option_2 \ |
| 1901 | $ocs_z9p_option_1 $ocs_z9p_option_2 \ |
| 1902 | "-z0" "$msg_ocs_param_z0" \ |
| 1903 | 2>> $OCS_PARAM_TMP |
| 1904 | # We need to append a space after this parameter so it won't be connected to next parameter. |
| 1905 | echoscip-shell system . . echo. -n " " >> $OCS_PARAM_TMP |
| 1906 | else |
| 1907 | # Beginner mode. Question about -z1p and -z9p. |
| 1908 | # We can not detect # of the CPU cores in the clients from server, hence let user choose. |
| 1909 | # Here to make it simple, just use z*p since it works for both single and multiple cores. |
| 1910 | if [scip-shell system . . `[`. -n "$ocs_z9p_option_1" -a -n "$ocs_z9p_option_2" ]; then |
| 1911 | $DIA --backtitle "$msg_nchc_free_software_labs" --title \ |
| 1912 | "$msg_nchc_clonezilla | $msg_mode: $ocs_mode_prompt" --menu "$msg_choose_one_compression_param_to_save" \ |
| 1913 | --default-item "$ocs_z9p_option_1" \ |
| 1914 | 0 0 0 $DIA_ESC \ |
| 1915 | "-z1p" "$msg_ocs_param_z1p" \ |
| 1916 | $ocs_z9p_option_1 $ocs_z9p_option_2 \ |
| 1917 | 2>> $OCS_PARAM_TMP |
| 1918 | # We need to append a space after this parameter so it won't be connected to next parameter. |
| 1919 | echoscip-shell system . . echo. -n " " >> $OCS_PARAM_TMP |
| 1920 | else |
| 1921 | echoscip-shell system . . echo. "-z1p " >> $OCS_PARAM_TMP |
| 1922 | fi |
| 1923 | fi |
| 1924 | # About image volume size |
| 1925 | if [scip-shell system . . `[`. -z "$dcs_img_vol_limit" ]; then |
| 1926 | trap "[ -f "$vol_size_tmp" ] && rm -f $vol_size_tmp" HUP INT QUIT TERM EXIT |
| 1927 | while [scip-shell system . . `[`. "$ASK_VOL_SIZE" -ne 0 ]; do |
| 1928 | $DIA --backtitle "$msg_nchc_free_software_labs" --title \ |
| 1929 | "$msg_nchc_clonezilla | $msg_mode: $ocs_mode_prompt" --inputbox "$msg_set_image_volume_size" \ |
| 1930 | 0 0 $VOL_LIMIT_DEFAULT \ |
| 1931 | 2> $vol_size_tmp |
| 1932 | if [scip-shell system . . `[`. -n "$(catscip-shell system . . cat. $vol_size_tmp | grepscip-shell system . . grep. -iE "[^[:digit:]]")" ]; then |
| 1933 | ASK_VOL_SIZE=1 |
| 1934 | $DIA --backtitle "$msg_nchc_free_software_labs" --title "$msg_nchc_clonezilla | $msg_mode: $ocs_mode_prompt" \ |
| 1935 | --msgbox "$msg_enter_digits_only\n$msg_please_do_it_again!!!" 0 0 |
| 1936 | else |
| 1937 | ASK_VOL_SIZE=0 |
| 1938 | fi |
| 1939 | done |
| 1940 | echoscip-shell system . . echo. "-i $(catscip-shell system . . cat. $vol_size_tmp)" >> $OCS_PARAM_TMP |
| 1941 | else |
| 1942 | echoscip-shell system . . echo. "-i $dcs_img_vol_limit" >> $OCS_PARAM_TMP |
| 1943 | fi |
| 1944 | fi |
| 1945 | # Force to strip the unnecessary quotation ', this is specially for dialog (from cdialog) in Mandriva and same reason to strip the unnecessary double quotation ", this is sepcially for dialog in OpenSuSE 11.1. Otherwise it will cause -p reboot become (containing space) '-p reboot', which is wrong option in dcs. |
| 1946 | LC_ALL=C perlscip-shell system . . perl. -pi -e "s/\'//g" $OCS_PARAM_TMP |
| 1947 | LC_ALL=C perlscip-shell system . . perl. -pi -e "s/\"//g" $OCS_PARAM_TMP |
| 1948 | # |
| 1949 | [scip-shell system . . `[`. -e "$vol_size_tmp" ] && rmscip-shell system . . rm. -f $vol_size_tmp |
| 1950 | } # end of set_drbl_ocs_extra_param |
| 1951 | |
| 1952 | # |
| 1953 | set_ocs_sr_extra_paramscip-shell shell shell-project 0.0.0 set_ocs_sr_extra_param().() { |
| 1954 | # This function is used to be called inside ocs-sr, not from other program. |
| 1955 | local mode="$1" |
| 1956 | # OCS_PARAM_TMP is a global variable |
| 1957 | local mode2_="$2" |
| 1958 | local cpu_no |
| 1959 | local vol_size_tmp |
| 1960 | local ASK_VOL_SIZE=1 |
| 1961 | local inst_grub_opt opt_confirm_ j2_switch_msg_1 j2_switch_msg_2 j2_switch_msg_3 |
| 1962 | vol_size_tmp="$(mktempscip-shell system . . mktemp. /tmp/vol_size_tmp.XXXXXXscip-shell filesystem . . `/tmp/vol_size_tmp.XXXXXX`.)" |
| 1963 | |
| 1964 | if [scip-shell system . . `[`. -z "$OCS_PARAM_TMP" ]; then |
| 1965 | echoscip-shell system . . echo. "\"$OCS_PARAM_TMP\" was not assigned in function set_ocs_sr_extra_param" |
| 1966 | echoscip-shell system . . echo. "$msg_program_stop!" |
| 1967 | exit 1 |
| 1968 | fi |
| 1969 | |
| 1970 | if [scip-shell system . . `[`. "$mode2_" = "recovery-iso-zip" ]; then |
| 1971 | # E.g., set_ocs_sr_extra_param restore /tmp/ocs_recovery_tmp.8YNkii recovery-iso-zip |
| 1972 | # When mode2_ is recovery-iso-zip, we have to convert it to restoreparts or restoredisk |
| 1973 | # by testing the image |
| 1974 | if [scip-shell system . . `[`. -e "$ocsroot/$target_dir/disk" ]; then |
| 1975 | mode2_="restoredisk" |
| 1976 | else |
| 1977 | mode2_="restoreparts" |
| 1978 | fi |
| 1979 | fi |
| 1980 | |
| 1981 | # If the mode is only for parts, we won't turn on "-g auto" option by default |
| 1982 | case "$mode2_" in |
| 1983 | *parts) inst_grub_opt="off" |
| 1984 | # For restoreparts, forget about clean mbr |
| 1985 | skip_clean_mbr_opt="on" |
| 1986 | ;; |
| 1987 | *) inst_grub_opt="on" |
| 1988 | # For restoredisk, do mbr cleaning |
| 1989 | skip_clean_mbr_opt="off" |
| 1990 | ;; |
| 1991 | esac |
| 1992 | |
| 1993 | if [scip-shell system . . `[`. "$mode" = "restore" ]; then |
| 1994 | # Although -u/-y0/-y1 is shown in ocs-sr, but actually they are used to |
| 1995 | # pass the varialbe, and in this function, when chooing parameters, we |
| 1996 | # remove them on purpose. Since the necessay parameters will be assigned by |
| 1997 | # drbl-ocs (Ex: we use "-y1 -p choose" in drbl-ocs) |
| 1998 | if [scip-shell system . . `[`. "$ocs_user_mode" = "expert" ]; then |
| 1999 | # The option "-j2" (clone_hidden_data) should be only shown when it's in restoredisk mode |
| 2000 | # Ref: https://sourceforge.net/p/clonezilla/bugs/361/ |
| 2001 | case "$mode2_" in |
| 2002 | restoreparts) |
| 2003 | j2_switch_msg_1="-j2" |
| 2004 | j2_switch_msg_2="$(rep_whspc_w_udrsc "$msg_ocs_param_j2")" |
| 2005 | j2_switch_msg_3="off" |
| 2006 | ;; |
| 2007 | restoredisk) |
| 2008 | j2_switch_msg_1="-j2" |
| 2009 | j2_switch_msg_2="$(rep_whspc_w_udrsc "$msg_ocs_param_j2")" |
| 2010 | j2_switch_msg_3="on" |
| 2011 | ;; |
| 2012 | esac |
| 2013 | $DIA --separate-output --backtitle "$msg_nchc_free_software_labs" --title \ |
| 2014 | "$msg_clonezilla_advanced_extra_param | $msg_mode: $ocs_mode_prompt" --checklist "$msg_choose_param_to_set_multiple_choices ($msg_press_space_to_mark_selection)" \ |
| 2015 | 0 0 0 $DIA_ESC \ |
| 2016 | "-g auto" "$msg_ocs_param_g_auto" $inst_grub_opt \ |
| 2017 | "-e1 auto" "$msg_ocs_param_e1_auto" on \ |
| 2018 | "-e2" "$msg_ocs_param_e2" on \ |
| 2019 | "-nogui" "$msg_ocs_param_nogui" off \ |
| 2020 | "-hn0 $WIN_HOSTNAME_PREFIX" "$msg_ocs_param_hn0" off \ |
| 2021 | "-hn1 $WIN_HOSTNAME_PREFIX" "$msg_ocs_param_hn1" off \ |
| 2022 | "-v" "$msg_ocs_param_v" off \ |
| 2023 | "-batch" "$msg_ocs_param_b" off \ |
| 2024 | "-c" "$msg_ocs_param_c" on \ |
| 2025 | "-t" "$msg_ocs_param_t" $skip_clean_mbr_opt \ |
| 2026 | "-t1" "$msg_ocs_param_t1" off \ |
| 2027 | "-t2" "$msg_ocs_param_t2" off \ |
| 2028 | "-r" "$msg_ocs_param_r" off \ |
| 2029 | "-rescue " "$msg_ocs_param_rescue" off \ |
| 2030 | "-e" "$msg_ocs_param_e" off \ |
| 2031 | "-icrc" "$msg_ocs_param_icrc" off \ |
| 2032 | "-irhr" "$msg_ocs_param_irhr" off \ |
| 2033 | "-irvd" "$msg_ocs_param_irvd" off \ |
| 2034 | "-ius" "$msg_ocs_param_ius" off \ |
| 2035 | "-iui" "$msg_ocs_param_iui" off \ |
| 2036 | "-icds" "$msg_ocs_param_icds" off \ |
| 2037 | "-iefi" "$msg_ocs_param_iefi" off \ |
| 2038 | "-j1" "$msg_ocs_param_j1" off \ |
| 2039 | $j2_switch_msg_1 $j2_switch_msg_2 $j2_switch_msg_3 \ |
| 2040 | "-cm" "$msg_ocs_param_cm" off \ |
| 2041 | "-cs" "$msg_ocs_param_cs" off \ |
| 2042 | "-cb2" "$msg_ocs_param_cb2" off \ |
| 2043 | "-cb3" "$msg_ocs_param_cb3" off \ |
| 2044 | "-cmf" "$msg_ocs_param_cmf" off \ |
| 2045 | "-a" "$msg_ocs_param_a" off \ |
| 2046 | "-o0" "$msg_ocs_param_o0" off \ |
| 2047 | "-o1" "$msg_ocs_param_o1" off \ |
| 2048 | "-srel" "$msg_ocs_param_srel" off \ |
| 2049 | "-ps" "$msg_ocs_param_ps" off \ |
| 2050 | "-edio" "$msg_ocs_param_edio" on \ |
| 2051 | "-rmtd" "$msg_ocs_param_rmtd" off \ |
| 2052 | "-rmmcb" "$msg_ocs_param_rmmcb" off \ |
| 2053 | "-reluks" "$msg_ocs_param_reluks" off \ |
| 2054 | 2>> $OCS_PARAM_TMP |
| 2055 | else |
| 2056 | if [scip-shell system . . `[`. "$ocs_batch_mode" != "on" ]; then |
| 2057 | # Interactive mode. We need to add "-c" |
| 2058 | opt_confirm_="-c" |
| 2059 | else |
| 2060 | # Batch mode. We do not add "-c" |
| 2061 | opt_confirm_="" |
| 2062 | fi |
| 2063 | # Beginner mode. Use default settings |
| 2064 | if [scip-shell system . . `[`. "$inst_grub_opt" = "on" ]; then |
| 2065 | # restoredisk mode. |
| 2066 | # "$inst_grub_opt" = "on" (-g auto) means skip_clean_mbr_opt="off" (no -t) |
| 2067 | echoscip-shell system . . echo. "-g auto" "-e1 auto" "-e2" "-r" "-j2" "-edio" "$opt_confirm_" >> $OCS_PARAM_TMP |
| 2068 | else |
| 2069 | # restoreparts mode. |
| 2070 | # "$inst_grub_opt" = "off" (no "-g auto") means skip_clean_mbr_opt="on" (-t) |
| 2071 | # Do not enable -j2 by default since for restoreparts, it should not be done by default. |
| 2072 | # Ref: https://sourceforge.net/p/clonezilla/bugs/361/ |
| 2073 | echoscip-shell system . . echo. "-e1 auto" "-e2" "-t" "-r" "-edio" "$opt_confirm_" >> $OCS_PARAM_TMP |
| 2074 | fi |
| 2075 | fi |
| 2076 | |
| 2077 | # About partition table |
| 2078 | case "$mode2_" in |
| 2079 | "restoreparts") |
| 2080 | # Partition restore only. default NOT to create partition table |
| 2081 | if [scip-shell system . . `[`. "$ocs_user_mode" = "expert" ]; then |
| 2082 | $DIA --backtitle "$msg_nchc_free_software_labs" --title \ |
| 2083 | "$msg_clonezilla_advanced_extra_param | $msg_mode: $ocs_mode_prompt" --menu "$msg_hint_for_fdisk \n$msg_choose_param_to_set_single_choice" \ |
| 2084 | 0 0 0 $DIA_ESC \ |
| 2085 | "-k " "$msg_ocs_param_k" \ |
| 2086 | "-k1 " "$msg_ocs_param_k1" \ |
| 2087 | "-k2 " "$msg_ocs_param_k2" \ |
| 2088 | "-j0 " "$msg_ocs_param_j0" \ |
| 2089 | "-k0 " "$msg_use_the_part_table_from_image" \ |
| 2090 | "exit " "$msg_exit" \ |
| 2091 | 2>> $OCS_PARAM_TMP |
| 2092 | else |
| 2093 | echoscip-shell system . . echo. "-k " >> $OCS_PARAM_TMP |
| 2094 | fi |
| 2095 | ;; |
| 2096 | *) |
| 2097 | # Disk restore, default to create partition table |
| 2098 | if [scip-shell system . . `[`. "$ocs_user_mode" = "expert" ]; then |
| 2099 | $DIA --backtitle "$msg_nchc_free_software_labs" --title \ |
| 2100 | "$msg_clonezilla_advanced_extra_param | $msg_mode: $ocs_mode_prompt" --menu "$msg_hint_for_fdisk \n$msg_choose_param_to_set_single_choice" \ |
| 2101 | 0 0 0 $DIA_ESC \ |
| 2102 | "-k0 " "$msg_use_the_part_table_from_image" \ |
| 2103 | "-k " "$msg_ocs_param_k" \ |
| 2104 | "-k1 " "$msg_ocs_param_k1" \ |
| 2105 | "-k2 " "$msg_ocs_param_k2" \ |
| 2106 | "-j0 " "$msg_ocs_param_j0" \ |
| 2107 | "exit " "$msg_exit" \ |
| 2108 | 2>> $OCS_PARAM_TMP |
| 2109 | else |
| 2110 | $DIA --backtitle "$msg_nchc_free_software_labs" --title \ |
| 2111 | "$msg_nchc_clonezilla | $msg_mode: $ocs_mode_prompt" --menu "$msg_hint_for_fdisk_beginner \n$msg_choose_default_param_if_no_idea" \ |
| 2112 | 0 0 0 $DIA_ESC \ |
| 2113 | "-k0 " "$msg_use_the_part_table_from_image" \ |
| 2114 | "-k1 " "$msg_ocs_param_k1" \ |
| 2115 | "exit " "$msg_exit" \ |
| 2116 | 2>> $OCS_PARAM_TMP |
| 2117 | fi |
| 2118 | ;; |
| 2119 | esac |
| 2120 | if grepscip-shell system . . grep. -Ew "exit" $OCS_PARAM_TMP &>/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 2121 | echoscip-shell system . . echo. "$msg_program_stop" |
| 2122 | exit 1 |
| 2123 | fi |
| 2124 | # Question about checking the image is restorable or not. By default, no matter it's beginner or advanced mode, |
| 2125 | # we will ask. |
| 2126 | if [scip-shell system . . `[`. -z "$chk_img_restoreable_mod_restore" ]; then |
| 2127 | $DIA --backtitle "$msg_nchc_free_software_labs" --title \ |
| 2128 | "$msg_clonezilla_advanced_extra_param | $msg_mode: $ocs_mode_prompt" --menu "$msg_choose_if_checking_image_restorable_before_restoring" \ |
| 2129 | 0 0 0 $DIA_ESC \ |
| 2130 | " " "$msg_ocs_param_check_img_restorable_before_restoring" \ |
| 2131 | "-scr " "$msg_ocs_param_skip_checking_img_restorable_before_restoring" \ |
| 2132 | 2>> $OCS_PARAM_TMP |
| 2133 | else |
| 2134 | case "$chk_img_restoreable_mod_restore" in |
| 2135 | yes) echoscip-shell system . . echo. " " >> $OCS_PARAM_TMP;; |
| 2136 | no) echoscip-shell system . . echo. "-scr " >> $OCS_PARAM_TMP;; |
| 2137 | esac |
| 2138 | fi |
| 2139 | if LC_ALL=C grepscip-shell system . . grep. -Ew -- "(-k1|-k2)" $OCS_PARAM_TMP &>/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 2140 | # Option -k1 or -k2 is for different partition size, turn on -r and -icds by default |
| 2141 | if [scip-shell system . . `[`. -z "$(LC_ALL=C grepscip-shell system . . grep. -Ew -- "-r" $OCS_PARAM_TMP)" ]; then |
| 2142 | echoscip-shell system . . echo. "Since the mode you choose might resize partition size, we turn on file system resize funtion automatically (-r)..." |
| 2143 | echoscip-shell system . . echo. "-r " >> $OCS_PARAM_TMP |
| 2144 | fi |
| 2145 | if [scip-shell system . . `[`. -z "$(LC_ALL=C grepscip-shell system . . grep. -Ew -- "-icds" $OCS_PARAM_TMP)" ]; then |
| 2146 | echoscip-shell system . . echo. "Since the mode you choose might resize partition size, we now enable option \"-icds\" to ignore the partition size checking in Partclone..." |
| 2147 | echoscip-shell system . . echo. "-icds " >> $OCS_PARAM_TMP |
| 2148 | fi |
| 2149 | fi |
| 2150 | else |
| 2151 | # Save mode. |
| 2152 | # about -q, -q1, -q2 |
| 2153 | if [scip-shell system . . `[`. "$ocs_user_mode" = "expert" ]; then |
| 2154 | $DIA --backtitle "$msg_nchc_free_software_labs" --title \ |
| 2155 | "$msg_clonezilla_advanced_extra_param | $msg_mode: $ocs_mode_prompt" --menu "$msg_choose_param_for_clone_prog" \ |
| 2156 | 0 0 0 $DIA_ESC \ |
| 2157 | "-q2 " "$msg_ocs_param_q2" \ |
| 2158 | "-q1 " "$msg_ocs_param_q1" \ |
| 2159 | "-q " "$msg_ocs_param_q" \ |
| 2160 | " " "$msg_ocs_param_none_ie_partimage" \ |
| 2161 | 2>> $OCS_PARAM_TMP |
| 2162 | else |
| 2163 | echoscip-shell system . . echo. "-q2 " >> $OCS_PARAM_TMP |
| 2164 | fi |
| 2165 | |
| 2166 | get_smtd_smmcb_switchscip-shell shell shell-project 0.0.0 get_smtd_smmcb_switch(). # Obtain smtd_smmcb_switch |
| 2167 | if [scip-shell system . . `[`. "$ocs_user_mode" = "expert" ]; then |
| 2168 | $DIA --separate-output --backtitle "$msg_nchc_free_software_labs" --title \ |
| 2169 | "$msg_clonezilla_advanced_extra_param | $msg_mode: $ocs_mode_prompt" --checklist "$msg_choose_param_to_set_multiple_choices ($msg_press_space_to_mark_selection):" \ |
| 2170 | 0 0 0 $DIA_ESC \ |
| 2171 | "-c " "$msg_ocs_param_c" on \ |
| 2172 | "-j2 " "$msg_ocs_param_j2" on \ |
| 2173 | "-nogui " "$msg_ocs_param_nogui" off \ |
| 2174 | "-a " "$msg_ocs_param_a" off \ |
| 2175 | "-batch " "$msg_ocs_param_b" off \ |
| 2176 | "-rm-win-swap-hib " "$msg_ocs_param_rm_win_swap_hib" off \ |
| 2177 | "-ntfs-ok " "$msg_ocs_param_ntfs_ok" off \ |
| 2178 | "-rescue " "$msg_ocs_param_rescue" off \ |
| 2179 | "-gm " "$msg_ocs_param_gm" off \ |
| 2180 | "-gs " "$msg_ocs_param_gs" off \ |
| 2181 | "-gb2 " "$msg_ocs_param_gb2" off \ |
| 2182 | "-gb3 " "$msg_ocs_param_gb3" off \ |
| 2183 | "-gmf " "$msg_ocs_param_gmf" off \ |
| 2184 | "-noabo " "$msg_ocs_param_noabo" off \ |
| 2185 | "-ps " "$msg_ocs_param_ps" off \ |
| 2186 | "-scpt " "$msg_ocs_param_scpt" off \ |
| 2187 | "-sfs " "$msg_ocs_param_sfs" off \ |
| 2188 | "-edio " "$msg_ocs_param_edio" on \ |
| 2189 | "-smtd " "$msg_ocs_param_smtd" $smtd_smmcb_switch \ |
| 2190 | "-smmcb " "$msg_ocs_param_smmcb" $smtd_smmcb_switch \ |
| 2191 | 2>> $OCS_PARAM_TMP |
| 2192 | else |
| 2193 | case "$smtd_smmcb_switch" in |
| 2194 | on) echoscip-shell system . . echo. "-c " "-j2 " "-edio " "-smtd " "-smmcb " >> $OCS_PARAM_TMP;; |
| 2195 | off) echoscip-shell system . . echo. "-c " "-j2 " "-edio " >> $OCS_PARAM_TMP;; |
| 2196 | esac |
| 2197 | fi |
| 2198 | fi |
| 2199 | |
| 2200 | # if -hn0|-hn1 is chosen, |
| 2201 | # (1). prompt the warning about ntfs-3g/nfsmount for ntfs is necessary |
| 2202 | # (2). ask if the hostname prefix want to change |
| 2203 | if grepscip-shell system . . grep. -qE "\-hn[01]" $OCS_PARAM_TMP; then |
| 2204 | # part 1. |
| 2205 | $DIA --title "$msg_change_hostname_of_MS_WIN_on_the_fly" --clear \ |
| 2206 | --msgbox "$msg_write_MS_WIN_is_necessary" 15 70 |
| 2207 | |
| 2208 | # part 2. |
| 2209 | HNTMP="$(mktempscip-shell system . . mktemp. /tmp/winhn.XXXXXXscip-shell filesystem . . `/tmp/winhn.XXXXXX`.)" |
| 2210 | $DIA --backtitle "$msg_nchc_free_software_labs" --title "$msg_nchc_clonezilla" \ |
| 2211 | --inputbox "$msg_What_the_win_hostname_prefix ?" 0 0 "$WIN_HOSTNAME_PREFIX" 2> $HNTMP |
| 2212 | HN_PREFIX="$(catscip-shell system . . cat. $HNTMP)" |
| 2213 | if [scip-shell system . . `[`. -z "$HN_PREFIX" ]; then |
| 2214 | echoscip-shell system . . echo. "You did not specify the hostname prefix for MS windows! We use the default value in drbl-ocs.conf" |
| 2215 | else |
| 2216 | perlscip-shell system . . perl. -pi -e "s|(-hn.*) $WIN_HOSTNAME_PREFIX|\$1 $HN_PREFIX|g" $OCS_PARAM_TMP |
| 2217 | fi |
| 2218 | [scip-shell system . . `[`. -f "$HNTMP" ] && rmscip-shell system . . rm. -f $HNTMP |
| 2219 | fi |
| 2220 | |
| 2221 | if [scip-shell system . . `[`. "$mode" = "save" ]; then |
| 2222 | cpu_no="$(LC_ALL=C grepscip-shell system . . grep. -iE "^processor" /proc/cpuinfoscip-shell filesystem . . `/proc/cpuinfo`. | wcscip-shell system . . wc. -l)" |
| 2223 | # Due to the extra space required after -z1p, we can NOT use variable like this: |
| 2224 | # if [ "$cpu_no" -gt 1 ]; then |
| 2225 | # z1p_option_1="-z1p " |
| 2226 | # z1p_option_2="$msg_ocs_param_z1p" |
| 2227 | # else |
| 2228 | # z1p_option_1="" |
| 2229 | # z1p_option_2="" |
| 2230 | # fi |
| 2231 | # $DIA --backtitle "$msg_nchc_free_software_labs" --title \ |
| 2232 | # "$msg_clonezilla_advanced_extra_param" --menu "$msg_choose_one_compression_param_to_save" \ |
| 2233 | # 0 0 0 $DIA_ESC \ |
| 2234 | # "-z1 " "$msg_ocs_param_z1" \ |
| 2235 | # $z1p_option_1 $z1p_option_2 \ |
| 2236 | # "-z2 " "$msg_ocs_param_z2" \ |
| 2237 | # "-z3 " "$msg_ocs_param_z3" \ |
| 2238 | # "-z0 " "$msg_ocs_param_z0" \ |
| 2239 | # 2>> $OCS_PARAM_TMP |
| 2240 | show_z4_or_above_menu_or_notscip-shell shell shell-project 0.0.0 show_z4_or_above_menu_or_not(). |
| 2241 | if [scip-shell system . . `[`. "$cpu_no" -gt 1 ]; then |
| 2242 | # Show -z1p |
| 2243 | if [scip-shell system . . `[`. "$ocs_user_mode" = "expert" ]; then |
| 2244 | $DIA --backtitle "$msg_nchc_free_software_labs" --title \ |
| 2245 | "$msg_clonezilla_advanced_extra_param | $msg_mode: $ocs_mode_prompt" --menu "$msg_choose_one_compression_param_to_save" \ |
| 2246 | --default-item "$ocs_z9p_option_1" \ |
| 2247 | 0 0 0 $DIA_ESC \ |
| 2248 | "-z1p" "$msg_ocs_param_z1p" \ |
| 2249 | "-z1" "$msg_ocs_param_z1" \ |
| 2250 | "-z2p" "$msg_ocs_param_z2p" \ |
| 2251 | "-z2" "$msg_ocs_param_z2" \ |
| 2252 | "-z3" "$msg_ocs_param_z3" \ |
| 2253 | $ocs_z4_option_1 $ocs_z4_option_2 \ |
| 2254 | $ocs_z5p_option_1 $ocs_z5p_option_2 \ |
| 2255 | $ocs_z5_option_1 $ocs_z5_option_2 \ |
| 2256 | $ocs_z6p_option_1 $ocs_z6p_option_2 \ |
| 2257 | $ocs_z6_option_1 $ocs_z6_option_2 \ |
| 2258 | $ocs_z7_option_1 $ocs_z7_option_2 \ |
| 2259 | $ocs_z8_option_1 $ocs_z8_option_2 \ |
| 2260 | $ocs_z8p_option_1 $ocs_z8p_option_2 \ |
| 2261 | $ocs_z9_option_1 $ocs_z9_option_2 \ |
| 2262 | $ocs_z9p_option_1 $ocs_z9p_option_2 \ |
| 2263 | "-z0" "$msg_ocs_param_z0" \ |
| 2264 | 2>> $OCS_PARAM_TMP |
| 2265 | # We need to append a space after this parameter so it won't be connected to next parameter. |
| 2266 | echoscip-shell system . . echo. -n " " >> $OCS_PARAM_TMP |
| 2267 | else |
| 2268 | # Beginner mode. |
| 2269 | # Question about -z1p and -z9p. |
| 2270 | if [scip-shell system . . `[`. -n "$ocs_z9p_option_1" -a -n "$ocs_z9p_option_2" ]; then |
| 2271 | $DIA --backtitle "$msg_nchc_free_software_labs" --title \ |
| 2272 | "$msg_nchc_clonezilla | $msg_mode: $ocs_mode_prompt" --menu "$msg_choose_one_compression_param_to_save" \ |
| 2273 | --default-item "$ocs_z9p_option_1" \ |
| 2274 | 0 0 0 $DIA_ESC \ |
| 2275 | "-z1p" "$msg_ocs_param_z1p" \ |
| 2276 | $ocs_z9p_option_1 $ocs_z9p_option_2 \ |
| 2277 | 2>> $OCS_PARAM_TMP |
| 2278 | # We need to append a space after this parameter so it won't be connected to next parameter. |
| 2279 | echoscip-shell system . . echo. -n " " >> $OCS_PARAM_TMP |
| 2280 | else |
| 2281 | echoscip-shell system . . echo. "-z1p " >> $OCS_PARAM_TMP |
| 2282 | fi |
| 2283 | fi |
| 2284 | else |
| 2285 | # Single processor, so we hide -z1p, z2p... |
| 2286 | if [scip-shell system . . `[`. "$ocs_user_mode" = "expert" ]; then |
| 2287 | $DIA --backtitle "$msg_nchc_free_software_labs" --title \ |
| 2288 | "$msg_clonezilla_advanced_extra_param | $msg_mode: $ocs_mode_prompt" --menu "$msg_choose_one_compression_param_to_save" \ |
| 2289 | 0 0 0 $DIA_ESC \ |
| 2290 | "-z1" "$msg_ocs_param_z1" \ |
| 2291 | "-z2" "$msg_ocs_param_z2" \ |
| 2292 | "-z3" "$msg_ocs_param_z3" \ |
| 2293 | $ocs_z4_option_1 $ocs_z4_option_2 \ |
| 2294 | $ocs_z5_option_1 $ocs_z5_option_2 \ |
| 2295 | $ocs_z6_option_1 $ocs_z6_option_2 \ |
| 2296 | $ocs_z7_option_1 $ocs_z7_option_2 \ |
| 2297 | $ocs_z8_option_1 $ocs_z8_option_2 \ |
| 2298 | $ocs_z9_option_1 $ocs_z9_option_2 \ |
| 2299 | "-z0" "$msg_ocs_param_z0" \ |
| 2300 | 2>> $OCS_PARAM_TMP |
| 2301 | # We need to append a space after this parameter so it won't be connected to next parameter. |
| 2302 | echoscip-shell system . . echo. -n " " >> $OCS_PARAM_TMP |
| 2303 | else |
| 2304 | # Beginner mode. |
| 2305 | # Question about -z1 and -z9. |
| 2306 | if [scip-shell system . . `[`. -n "$ocs_z9_option_1" -a -n "$ocs_z9_option_2" ]; then |
| 2307 | $DIA --backtitle "$msg_nchc_free_software_labs" --title \ |
| 2308 | "$msg_nchc_clonezilla | $msg_mode: $ocs_mode_prompt" --menu "$msg_choose_one_compression_param_to_save" \ |
| 2309 | --default-item "$ocs_z9_option_1" \ |
| 2310 | 0 0 0 $DIA_ESC \ |
| 2311 | "-z1" "$msg_ocs_param_z1" \ |
| 2312 | $ocs_z9_option_1 $ocs_z9_option_2 \ |
| 2313 | 2>> $OCS_PARAM_TMP |
| 2314 | # We need to append a space after this parameter so it won't be connected to next parameter. |
| 2315 | echoscip-shell system . . echo. -n " " >> $OCS_PARAM_TMP |
| 2316 | else |
| 2317 | echoscip-shell system . . echo. "-z1 " >> $OCS_PARAM_TMP |
| 2318 | fi |
| 2319 | fi |
| 2320 | fi |
| 2321 | |
| 2322 | # About image volume size |
| 2323 | if [scip-shell system . . `[`. "$ocs_user_mode" = "expert" ]; then |
| 2324 | trap "[ -f "$vol_size_tmp" ] && rm -f $vol_size_tmp" HUP INT QUIT TERM EXIT |
| 2325 | while [scip-shell system . . `[`. "$ASK_VOL_SIZE" -ne 0 ]; do |
| 2326 | $DIA --backtitle "$msg_nchc_free_software_labs" --title \ |
| 2327 | "$msg_clonezilla_advanced_extra_param | $msg_mode: $ocs_mode_prompt" --inputbox "$msg_set_image_volume_size" \ |
| 2328 | 0 0 $VOL_LIMIT_IN_INTERACTIVE\ |
| 2329 | 2> $vol_size_tmp |
| 2330 | if [scip-shell system . . `[`. -n "$(catscip-shell system . . cat. $vol_size_tmp | grepscip-shell system . . grep. -iE "[^[:digit:]]")" ]; then |
| 2331 | ASK_VOL_SIZE=1 |
| 2332 | $DIA --backtitle "$msg_nchc_free_software_labs" --title "$msg_nchc_clonezilla | $msg_mode: $ocs_mode_prompt" \ |
| 2333 | --msgbox "$msg_enter_digits_only\n$msg_please_do_it_again!!!" 0 0 |
| 2334 | else |
| 2335 | ASK_VOL_SIZE=0 |
| 2336 | fi |
| 2337 | done |
| 2338 | echoscip-shell system . . echo. "-i $(catscip-shell system . . cat. $vol_size_tmp)" >> $OCS_PARAM_TMP |
| 2339 | else |
| 2340 | echoscip-shell system . . echo. "-i $VOL_LIMIT_IN_INTERACTIVE" >> $OCS_PARAM_TMP |
| 2341 | fi |
| 2342 | # Question about fsck the source partition. By default, no matter it's beginner or advanced mode, we will ask. |
| 2343 | if [scip-shell system . . `[`. -z "$fsck_src_part_intr" -a -z "$fsck_src_part_auto" ]; then |
| 2344 | $DIA --backtitle "$msg_nchc_free_software_labs" --title \ |
| 2345 | "$msg_nchc_clonezilla | $msg_mode: $ocs_mode_prompt" --menu "$msg_choose_if_fsck_the_source_part" \ |
| 2346 | 0 0 0 $DIA_ESC \ |
| 2347 | "-sfsck " "$msg_skip_check_source_fs" \ |
| 2348 | "-fsck " "$msg_ocs_param_fsck_src_part" \ |
| 2349 | "-fsck-y " "$msg_ocs_param_fsck_src_part_yes" \ |
| 2350 | 2>> $OCS_PARAM_TMP |
| 2351 | else |
| 2352 | case "$fsck_src_part_intr" in |
| 2353 | yes) echoscip-shell system . . echo. "-fsck " >> $OCS_PARAM_TMP;; |
| 2354 | *) echoscip-shell system . . echo. " " >> $OCS_PARAM_TMP;; |
| 2355 | esac |
| 2356 | case "$fsck_src_part_auto" in |
| 2357 | yes) echoscip-shell system . . echo. "-fsck-y " >> $OCS_PARAM_TMP;; |
| 2358 | *) echoscip-shell system . . echo. " " >> $OCS_PARAM_TMP;; |
| 2359 | esac |
| 2360 | fi |
| 2361 | |
| 2362 | # Question about checking the image is restorable or not. By default, no matter it's beginner or advanced mode, |
| 2363 | # we will ask. |
| 2364 | if [scip-shell system . . `[`. -z "$chk_img_restoreable_mod_save" ]; then |
| 2365 | $DIA --backtitle "$msg_nchc_free_software_labs" --title \ |
| 2366 | "$msg_nchc_clonezilla | $msg_mode: $ocs_mode_prompt" --menu "$msg_choose_if_checking_image_restorable" \ |
| 2367 | 0 0 0 $DIA_ESC \ |
| 2368 | " " "$msg_ocs_param_check_img_restorable" \ |
| 2369 | "-scs " "$msg_ocs_param_skip_checking_img_restorable" \ |
| 2370 | 2>> $OCS_PARAM_TMP |
| 2371 | else |
| 2372 | case "$chk_img_restoreable_mod_save" in |
| 2373 | yes) echoscip-shell system . . echo. " " >> $OCS_PARAM_TMP;; |
| 2374 | no) echoscip-shell system . . echo. "-scs " >> $OCS_PARAM_TMP;; |
| 2375 | esac |
| 2376 | fi |
| 2377 | |
| 2378 | # Question about encrypt the image. By default, no matter it's beginner or advanced mode, |
| 2379 | # we will ask. However, for some customized case, it it could be set via parameter gocrypt_ocs_img. |
| 2380 | if [scip-shell system . . `[`. -z "$gocrypt_ocs_img" ]; then |
| 2381 | $DIA --backtitle "$msg_nchc_free_software_labs" --title \ |
| 2382 | "$msg_nchc_clonezilla | $msg_mode: $ocs_mode_prompt" --menu "$msg_encrypt_image\n$msg_gocryptfs_is_used_for_clonezilla\n$msg_remember_passphrase_of_gocryptfs" \ |
| 2383 | 0 0 0 $DIA_ESC \ |
| 2384 | "-sgoc " "$msg_not_to_gocrypt_img" \ |
| 2385 | "-goc " "$msg_yes_to_gocrypt_img" \ |
| 2386 | "-enc " "$msg_yes_to_encrypt_img" \ |
| 2387 | 2>> $OCS_PARAM_TMP |
| 2388 | else |
| 2389 | case "$gocrypt_ocs_img" in |
| 2390 | yes) echoscip-shell system . . echo. "-goc " >> $OCS_PARAM_TMP;; |
| 2391 | no) echoscip-shell system . . echo. "-sgoc " >> $OCS_PARAM_TMP;; |
| 2392 | esac |
| 2393 | fi |
| 2394 | fi |
| 2395 | |
| 2396 | # Question about copy the log files to Clonezilla live USB drive. By default, no matter it's beginner or advanced mode, |
| 2397 | if [scip-shell system . . `[`. -z "$put_log_usb" ]; then |
| 2398 | $DIA --backtitle "$msg_nchc_free_software_labs" --title \ |
| 2399 | "$msg_nchc_clonezilla | $msg_mode: $ocs_mode_prompt" --menu "$msg_put_log_usb_or_not \n$msg_choose_default_param_if_no_idea" \ |
| 2400 | 0 0 0 $DIA_ESC \ |
| 2401 | "-plu " "$msg_put_log_to_OCS_USB_drive" \ |
| 2402 | " " "$msg_not_put_log_to_OCS_USB_drive" \ |
| 2403 | 2>> $OCS_PARAM_TMP |
| 2404 | else |
| 2405 | case "$put_log_usb" in |
| 2406 | yes) echoscip-shell system . . echo. "-plu " >> $OCS_PARAM_TMP;; |
| 2407 | no) echoscip-shell system . . echo. " " >> $OCS_PARAM_TMP;; |
| 2408 | esac |
| 2409 | fi |
| 2410 | |
| 2411 | # For both beginner and expert modes, if user has specified postaction, then we do not have to set it. Otherwise, ask it. |
| 2412 | if [scip-shell system . . `[`. -n "$postaction" ]; then |
| 2413 | echoscip-shell system . . echo. "-p $postaction " >> $OCS_PARAM_TMP |
| 2414 | else |
| 2415 | ocs_sr_param_postaction_after_clonescip-shell shell shell-project 0.0.0 ocs_sr_param_postaction_after_clone(). $OCS_PARAM_TMP |
| 2416 | fi |
| 2417 | |
| 2418 | # Force to strip the unnecessary quotation ', this is specially for dialog (from cdialog) in Mandriva and same reason to strip the unnecessary double quotation ", this is sepcially for dialog in OpenSuSE 11.1. Otherwise it will cause -p reboot become (containing space) '-p reboot', which is wrong option in dcs. |
| 2419 | LC_ALL=C perlscip-shell system . . perl. -pi -e "s/\'//g" $OCS_PARAM_TMP |
| 2420 | LC_ALL=C perlscip-shell system . . perl. -pi -e "s/\"//g" $OCS_PARAM_TMP |
| 2421 | # |
| 2422 | [scip-shell system . . `[`. -e "$vol_size_tmp" ] && rmscip-shell system . . rm. -f $vol_size_tmp |
| 2423 | |
| 2424 | } # end of set_ocs_sr_extra_param |
| 2425 | # |
| 2426 | check_DIA_set_ESCscip-shell shell shell-project 0.0.0 check_DIA_set_ESC().(){ |
| 2427 | # function to check dialog/Xdialog/whiptail |
| 2428 | # DIA_ESC is global variable, |
| 2429 | # man dialog: |
| 2430 | # A "--" by itself is used as an escape, i.e., the next token on the com- |
| 2431 | # mand-line is not treated as an option. |
| 2432 | # dialog --title -- --Not an option |
| 2433 | # 3 cases if those Not an option is like (-g auto, -x...): |
| 2434 | # (1) dialog can go with or without -- |
| 2435 | # (2) Xdialog can NOT go with -- |
| 2436 | # (3) whiptail can go only with -- |
| 2437 | local dia_="$1" |
| 2438 | # check DIA |
| 2439 | if ! type $dia_ &>/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 2440 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE |
| 2441 | echoscip-shell system . . echo. "$dia_: command not found!" |
| 2442 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 2443 | echoscip-shell system . . echo. "Program terminated!!!" |
| 2444 | exit 1 |
| 2445 | fi |
| 2446 | case "$dia_" in |
| 2447 | dialog|[Xgk]dialog) DIA_ESC="" ;; |
| 2448 | whiptail) DIA_ESC="--" ;; |
| 2449 | esac |
| 2450 | } # end of check_DIA_set_ESC |
| 2451 | # |
| 2452 | check_if_run_in_drbl_serverscip-shell shell shell-project 0.0.0 check_if_run_in_drbl_server().() { |
| 2453 | local prog="$1" |
| 2454 | # check if it s run in drbl server |
| 2455 | if [scip-shell system . . `[`. ! -d "$PXELINUX_DIR" ]; then |
| 2456 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE |
| 2457 | echoscip-shell system . . echo. "[$LOGNAME] You should run this program $prog in DRBL server, NOT in DRBL client or other machine." |
| 2458 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 2459 | echoscip-shell system . . echo. "Program terminated!" |
| 2460 | exit 1 |
| 2461 | fi |
| 2462 | } |
| 2463 | dialog_like_prog_help_promptscip-shell shell shell-project 0.0.0 dialog_like_prog_help_prompt().() { |
| 2464 | echoscip-shell system . . echo. " -d0, --dialog Use dialog" |
| 2465 | echoscip-shell system . . echo. " -d1, --Xdialog Use Xdialog" |
| 2466 | echoscip-shell system . . echo. " -d2, --whiptail Use whiptail" |
| 2467 | echoscip-shell system . . echo. " -d3, --gdialog Use gdialog" |
| 2468 | echoscip-shell system . . echo. " -d4, --kdialog Use kdialog" |
| 2469 | } |
| 2470 | root_over_nfsscip-shell shell shell-project 0.0.0 root_over_nfs().() { |
| 2471 | local root_over_nfs |
| 2472 | root_over_nfs="$(grepscip-shell system . . grep. -Ew "^[[:space:]]*([[:digit:]]+\.){3}[[:digit:]]+:/tftpboot/node_root([[:space:]]+|$)" /proc/mountsscip-shell filesystem . . `/proc/mounts`. | awkscip-shell system . . awk. -F " " '{print $2}')" |
| 2473 | if [scip-shell system . . `[`. "$root_over_nfs" = "/scip-shell filesystem . . `/`." ]; then |
| 2474 | echoscip-shell system . . echo. "yes" |
| 2475 | rc=0 |
| 2476 | else |
| 2477 | echoscip-shell system . . echo. "no" |
| 2478 | rc=1 |
| 2479 | fi |
| 2480 | return $rc |
| 2481 | } |
| 2482 | # |
| 2483 | make_random_passwordscip-shell shell shell-project 0.0.0 make_random_password().(){ |
| 2484 | # Copyright (C) 2007 Bryan McLellan <[email protected]> |
| 2485 | # Licensed under the GNU GPL version 2 or greater, see COPYING |
| 2486 | # generate a random password of length passed out of characters in array char. returns password in $random_password |
| 2487 | # replaces external perl password generation script |
| 2488 | # Modified by Steven Shiau, remove 0, 1, add [ ] ^ ! $ % |
| 2489 | local randchar="" |
| 2490 | [scip-shell system . . `[`. -z "$1" ] && lenpass=6 || lenpass=$1 |
| 2491 | |
| 2492 | # To avoid confusing, no 0, 1 for passwd, the O (oh) and l (L) will be clear. |
| 2493 | char=(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z 2 3 4 5 6 7 8 9 \[ \] ^ ! \$ %) |
| 2494 | lenchars=${#char[*]} |
| 2495 | |
| 2496 | for (( x=0 ; x<${lenpass} ; x+=1 )); |
| 2497 | do |
| 2498 | let rand=${RANDOM}%${lenchars} |
| 2499 | randchar=${randchar}${char[$rand]} |
| 2500 | done |
| 2501 | |
| 2502 | random_password=${randchar} |
| 2503 | } |
| 2504 | # |
| 2505 | is_boot_from_livescip-shell shell shell-project 0.0.0 is_boot_from_live().() { |
| 2506 | # function to check if the running OS is boot from live cd/usb stick ? |
| 2507 | if [scip-shell system . . `[`. -e /etc/debian_versionscip-shell filesystem . . `/etc/debian_version`. -a \ |
| 2508 | -n "$(grepscip-shell system . . grep. -iEo "(boot=casper|boot=live)" /proc/cmdlinescip-shell filesystem . . `/proc/cmdline`.)" ]; then |
| 2509 | return 0 |
| 2510 | else |
| 2511 | return 1 |
| 2512 | fi |
| 2513 | } |
| 2514 | # |
| 2515 | ask_nic_devscip-shell shell shell-project 0.0.0 ask_nic_dev().() { |
| 2516 | # chosen_nics is a global variable |
| 2517 | local dia_type req_nic_no dia_prompt nic_tmp |
| 2518 | local nic_no dia_def_status NETDEVICES count hw_scan_tmp DEVICELIST dev_model link_status hwaddr DEVICELIST read_cache |
| 2519 | local enable_channel_bonding="no" |
| 2520 | # link_max_cache_sec is from drbl-ocs.conf |
| 2521 | # The file name prefix for link status file. It will be used like /tmp/linked-status.eth0 |
| 2522 | # ocs_nic_type is a global variable |
| 2523 | local link_status_cache_pref="/tmp/linked-statusscip-shell filesystem . . `/tmp/linked-status`." |
| 2524 | |
| 2525 | while [scip-shell system . . `[`. $# -gt 0 ]; do |
| 2526 | case "$1" in |
| 2527 | -e|--enable-channel-bonding) |
| 2528 | enable_channel_bonding="yes" |
| 2529 | shift;; |
| 2530 | -*) echoscip-shell system . . echo. "${0}: ${1}: invalid option in ask_nic_dev." | teescip-shell system . . tee. --append ${OCS_LOGFILE} >&2 |
| 2531 | echoscip-shell system . . echo. "$msg_program_stop" | teescip-shell system . . tee. --append ${OCS_LOGFILE} |
| 2532 | [scip-shell system . . `[`. "$save_restore_error_log" = "yes" ] && copy_error_log |
| 2533 | exit 2 ;; |
| 2534 | *) break ;; |
| 2535 | esac |
| 2536 | done |
| 2537 | |
| 2538 | dia_prompt="$1" |
| 2539 | dia_type="$2" |
| 2540 | req_nic_no="$3" |
| 2541 | nic_tmp="$(mktempscip-shell system . . mktemp. /tmp/netbonding.XXXXXXscip-shell filesystem . . `/tmp/netbonding.XXXXXX`.)" |
| 2542 | trap "[ -f "$nic_tmp" ] && rm -f $nic_tmp" HUP INT QUIT TERM EXIT |
| 2543 | |
| 2544 | case "$dia_type" in |
| 2545 | menu) dia_def_status="";; |
| 2546 | checklist) dia_def_status="on";; |
| 2547 | esac |
| 2548 | |
| 2549 | # ocs_nic_type is from: |
| 2550 | # (1) boot parameter, hence in /etc/ocs/ocs-live.conf |
| 2551 | # (2) assigned by ocs-live-netcfg |
| 2552 | case "$ocs_nic_type" in |
| 2553 | wired) |
| 2554 | NETDEVICES="$(grepscip-shell system . . grep. -E "^[[:print:]]+:[[:space:]]+" /proc/net/devscip-shell filesystem . . `/proc/net/dev`. | awkscip-shell system . . awk. -F: '! /wlan.*:|wl.*:|lo:/{print $1}' | sortscip-shell system . . sort.)" |
| 2555 | ;; |
| 2556 | wireless) |
| 2557 | NETDEVICES="$(awkscip-shell system . . awk. -F: '/wlan.*:|wl.*:/{print $1}scip-shell filesystem . . `/wlan.*:|wl.*:/{print $1}`.' /proc/net/devscip-shell filesystem . . `/proc/net/dev`. | sortscip-shell system . . sort.)" |
| 2558 | ;; |
| 2559 | *) |
| 2560 | echoscip-shell system . . echo. "ocs_nic_type is not wired or wireless. No idea how to process." |
| 2561 | echoscip-shell system . . echo. "$msg_program_stop!" |
| 2562 | my_ocs_exitscip-shell shell shell-project 0.0.0 my_ocs_exit(). 1 |
| 2563 | ;; |
| 2564 | esac |
| 2565 | # make it in a single line |
| 2566 | NETDEVICES="$(echoscip-shell system . . echo. $NETDEVICES)" |
| 2567 | nic_no="$(echoscip-shell system . . echo. $NETDEVICES | wcscip-shell system . . wc. -w)" |
| 2568 | if [scip-shell system . . `[`. "$nic_no" -lt "$req_nic_no" ]; then |
| 2569 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE |
| 2570 | echoscip-shell system . . echo. "The requested NIC number is: $req_nic_no, while the NIC number on this system is: $nic_no" |
| 2571 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 2572 | show_nic_dev_status_on_system |
| 2573 | echoscip-shell system . . echo. "$msg_program_stop!" |
| 2574 | my_ocs_exitscip-shell shell shell-project 0.0.0 my_ocs_exit(). 1 |
| 2575 | fi |
| 2576 | # Check if it makes sense when channel bonding is enabled |
| 2577 | if [scip-shell system . . `[`. "$enable_channel_bonding" = "yes" ]; then |
| 2578 | if [scip-shell system . . `[`. "$nic_no" -lt 2 ]; then |
| 2579 | echoscip-shell system . . echo. "Disable channnel bonding since there is only one NIC found." |
| 2580 | enable_channel_bonding="no" |
| 2581 | fi |
| 2582 | fi |
| 2583 | |
| 2584 | if [scip-shell system . . `[`. -z "$NETDEVICES" ]; then |
| 2585 | $DIA --msgbox "$msg_no_nic_is_found" 0 0 |
| 2586 | if [scip-shell system . . `[`. -n "$nic_tmp" ]; then |
| 2587 | rmscip-shell system . . rm. -f "$nic_tmp" |
| 2588 | fi |
| 2589 | exit 1 |
| 2590 | else |
| 2591 | # We have to up the network card first so that ethtool can detect if it's linked or not. |
| 2592 | echoscip-shell system . . echo. -n "Try to up " |
| 2593 | for DEVICE in $NETDEVICES; do |
| 2594 | if [scip-shell system . . `[`. -z "$(drbl-get-ipadd $DEVICE)" ]; then |
| 2595 | echoscip-shell system . . echo. -n "$DEVICE... " |
| 2596 | ip link set $DEVICE up |
| 2597 | fi |
| 2598 | done |
| 2599 | echoscip-shell system . . echo. |
| 2600 | fi |
| 2601 | |
| 2602 | count="$(echoscip-shell system . . echo. "$NETDEVICES" | wcscip-shell system . . wc. -w)" |
| 2603 | |
| 2604 | if [scip-shell system . . `[`. "$count" -gt 1 ]; then |
| 2605 | hw_scan_tmp="$(mktempscip-shell system . . mktemp. /tmp/hw_scan.XXXXXXscip-shell filesystem . . `/tmp/hw_scan.XXXXXX`.)" |
| 2606 | time_now="$(LC_ALL=C datescip-shell system . . date. +%s)" |
| 2607 | # Read the cached linked status from file. |
| 2608 | if type lshw &>/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 2609 | echoscip-shell system . . echo. -n "Collecting the info of network devices... " |
| 2610 | lshw -businfo -class network 2>/dev/nullscip-shell filesystem . . `/dev/null`. > $hw_scan_tmp |
| 2611 | echoscip-shell system . . echo. "done!" |
| 2612 | fi |
| 2613 | DEVICELIST="" |
| 2614 | dev_model="" |
| 2615 | for DEVICE in $NETDEVICES; do |
| 2616 | dev_model="$(LC_ALL=C grepscip-shell system . . grep. -Ew "$DEVICE" $hw_scan_tmp | sedscip-shell system . . sed. -e "s/^.*$DEVICE[[:space:]]*network[[:space:]]*//g" | sedscip-shell system . . sed. -e "s/ /_/g")" |
| 2617 | [scip-shell system . . `[`. -z "$dev_model" ] && dev_model="Unknown_NIC" |
| 2618 | # only first 26 characters. |
| 2619 | dev_model="${dev_model:0:25}.." |
| 2620 | link_status="" |
| 2621 | read_cache="" |
| 2622 | if [scip-shell system . . `[`. -e "${link_status_cache_pref}.${DEVICE}" ]; then |
| 2623 | time_status_file="$(LC_ALL=C statscip-shell system . . stat. -c %Z "${link_status_cache_pref}.${DEVICE}")" |
| 2624 | if [scip-shell system . . `[`. "$((time_now - time_status_file))" -le "$link_max_cache_sec" ]; then |
| 2625 | read_cache="yes" |
| 2626 | fi |
| 2627 | fi |
| 2628 | if [scip-shell system . . `[`. "$read_cache" = "yes" ]; then |
| 2629 | echoscip-shell system . . echo. "Reading link status from cache file ${link_status_cache_pref}.${DEVICE}..." |
| 2630 | . ${link_status_cache_pref}.${DEVICE} |
| 2631 | else |
| 2632 | if [scip-shell system . . `[`. -n "$(echoscip-shell system . . echo. $DEVICE | grepscip-shell system . . grep. -Ew "(^wl.*|^wlan.*)")" ]; then |
| 2633 | echoscip-shell system . . echo. "$DEVICE is a wireless device. No need to detect its linking status." |
| 2634 | else |
| 2635 | echoscip-shell system . . echo. -n "Getting the linking status of $DEVICE. Timeout in $ocs_netlink_timeout secs." |
| 2636 | TIMEOUT="$ocs_netlink_timeout" |
| 2637 | while [scip-shell system . . `[`. "$link_status" = "no" -o -z "$link_status" ]; do |
| 2638 | sleepscip-shell system . . sleep. 1 |
| 2639 | link_status="$(LC_ALL=C ethtool $DEVICE | grepscip-shell system . . grep. -i "Link detected:" | cutscip-shell system . . cut. -d":" -f2 | sedscip-shell system . . sed. -e "s/ //g")" |
| 2640 | TIMEOUT="$(( $TIMEOUT - 1 ))" |
| 2641 | if [scip-shell system . . `[`. "$TIMEOUT" -le 0 ]; then |
| 2642 | echoscip-shell system . . echo. |
| 2643 | echoscip-shell system . . echo. -n "Timeout when finding linking status of $DEVICE." |
| 2644 | sleepscip-shell system . . sleep. 2 |
| 2645 | break |
| 2646 | else |
| 2647 | echoscip-shell system . . echo. -n "." |
| 2648 | fi |
| 2649 | done |
| 2650 | fi |
| 2651 | if [scip-shell system . . `[`. "$link_status" = "yes" ]; then |
| 2652 | echoscip-shell system . . echo. " Found status \"linked\"." |
| 2653 | else |
| 2654 | echoscip-shell system . . echo. " Status \"not linked\" or \"unknown\"." |
| 2655 | fi |
| 2656 | if [scip-shell system . . `[`. -z "$link_status" ]; then |
| 2657 | link_status="Unknown" |
| 2658 | fi |
| 2659 | echoscip-shell system . . echo. "link_status=\"${link_status}\"" > ${link_status_cache_pref}.${DEVICE} |
| 2660 | fi |
| 2661 | hwaddr="$(drbl-get-macadd $DEVICE)" |
| 2662 | DEVICELIST="$DEVICELIST ${DEVICE} $(rep_whspc_w_udrsc "$msg_link_detected"):${link_status}(${dev_model}|${hwaddr}) $dia_def_status" |
| 2663 | done |
| 2664 | rmscip-shell system . . rm. -f "$nic_tmp" |
| 2665 | [scip-shell system . . `[`. -f "$hw_scan_tmp" -a -n "$hw_scan_tmp" ] && rmscip-shell system . . rm. -f $hw_scan_tmp |
| 2666 | |
| 2667 | if [scip-shell system . . `[`. "$enable_channel_bonding" = "yes" ]; then |
| 2668 | DEVICELIST="$DEVICELIST bond0 $(rep_whspc_w_udrsc "$msg_use_channel_bonding") $dia_def_status" |
| 2669 | fi |
| 2670 | |
| 2671 | $DIA --backtitle "$msg_nchc_free_software_labs" --title \ |
| 2672 | "$msg_nchc_clonezilla" --${dia_type} "$dia_prompt" 0 0 0 $DEVICELIST 2>"$nic_tmp" |
| 2673 | # Force to strip the unnecessary quotation ', this is specially for dialog (from cdialog) in Mandriva and same reason to strip the unnecessary double quotation ", this is sepcially for dialog in OpenSuSE 11.1. Otherwise it will cause -p reboot become (containing space) '-p reboot', which is wrong option in dcs. |
| 2674 | LC_ALL=C perlscip-shell system . . perl. -pi -e "s/\'//g" $nic_tmp |
| 2675 | LC_ALL=C perlscip-shell system . . perl. -pi -e "s/\"//g" $nic_tmp |
| 2676 | chosen_nics="$(catscip-shell system . . cat. $nic_tmp)" |
| 2677 | else |
| 2678 | # Only 1 NIC, just use it. |
| 2679 | # Remove additional spaces |
| 2680 | chosen_nics="$(echoscip-shell system . . echo. $NETDEVICES)" |
| 2681 | fi |
| 2682 | |
| 2683 | if [scip-shell system . . `[`. -n "$nic_tmp" ]; then |
| 2684 | rmscip-shell system . . rm. -f "$nic_tmp" |
| 2685 | fi |
| 2686 | } # end of ask_nic_dev |
| 2687 | # |
| 2688 | detect_dhcp_srv_in_lanscip-shell shell shell-project 0.0.0 detect_dhcp_srv_in_lan().() { |
| 2689 | # Return global variable "use_existing_dhcp_srv", "DHCPOFFER_eth", "DHCPOFFER_siaddr", |
| 2690 | # "DHCPOFFER_yiaddr", "DHCPOFFER_netmask", "DHCPOFFER_prefix" |
| 2691 | local nic_n eth_pt dhcp_detect_bond_tmp dhcp_find_rc |
| 2692 | nic_n="$(LC_ALL=C get-nic-devs | wcscip-shell system . . wc. -l)" |
| 2693 | if [scip-shell system . . `[`. "$nic_n" -eq 0 ]; then |
| 2694 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE |
| 2695 | echoscip-shell system . . echo. "No any ethernet card found!" |
| 2696 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 2697 | echoscip-shell system . . echo. "$msg_program_stop" |
| 2698 | exit 1 |
| 2699 | elif [scip-shell system . . `[`. "$nic_n" -eq 1 ]; then |
| 2700 | eth_pt="$(LC_ALL=C get-nic-devs)" |
| 2701 | else |
| 2702 | # Multiple NICs, let user choose |
| 2703 | [scip-shell system . . `[`. -z "$ocs_nic_type" ] && ocs_nic_type="wired" |
| 2704 | [scip-shell system . . `[`. -z "$ocs_netlink_timeout" ] && ocs_netlink_timeout="12" |
| 2705 | ask_nic_devscip-shell shell shell-project 0.0.0 ask_nic_dev(). -e "$msg_choose_nic?" menu 1 # Obtain $chosen_nics |
| 2706 | if [scip-shell system . . `[`. -n "$chosen_nics" ]; then |
| 2707 | echoscip-shell system . . echo. "Chosen NIC: $chosen_nics" |
| 2708 | eth_pt="$chosen_nics" |
| 2709 | fi |
| 2710 | fi |
| 2711 | dhcp_detect_bond_tmp="$(mktempscip-shell system . . mktemp. /tmp/dhcp_detect_bond_tmp.XXXXXXscip-shell filesystem . . `/tmp/dhcp_detect_bond_tmp.XXXXXX`.)" |
| 2712 | dhcp_find_rc=1 |
| 2713 | echoscip-shell system . . echo. "Trying to find if existing DHCP service available on local network via ${eth_pt}..." |
| 2714 | while [scip-shell system . . `[`. "$dhcp_find_rc" -ne 0 ]; do |
| 2715 | drbl-find-dhcp-srv -i $eth_pt $dhcp_detect_bond_tmp |
| 2716 | dhcp_find_rc=$? |
| 2717 | if [scip-shell system . . `[`. "$dhcp_find_rc" -ne 0 ]; then |
| 2718 | echoscip-shell system . . echo. |
| 2719 | echoscip-shell system . . echo. "$msg_failed_to_find_any_dhcp_srv: $eth_pt" |
| 2720 | echoscip-shell system . . echo. "$msg_do_u_want_to_do_it_again" |
| 2721 | echoscip-shell system . . echo. -n "[Y/n] " |
| 2722 | read try_dhcp_again |
| 2723 | case "$try_dhcp_again" in |
| 2724 | n|N|[nN][oO]) |
| 2725 | echoscip-shell system . . echo. "$msg_program_stop" |
| 2726 | dhcp_find_rc=0 |
| 2727 | ;; |
| 2728 | *) |
| 2729 | echoscip-shell system . . echo. "$msg_ok_let_do_it" |
| 2730 | dhcp_find_rc=1 |
| 2731 | ;; |
| 2732 | esac |
| 2733 | fi |
| 2734 | done |
| 2735 | . $dhcp_detect_bond_tmp |
| 2736 | # Example for file dhcp_detect_bond_tmp: |
| 2737 | # DHCPOFFER_eth="eth0" |
| 2738 | # DHCPOFFER_siaddr="192.168.22.254" |
| 2739 | # DHCPOFFER_yiaddr="192.168.22.3" |
| 2740 | # DHCPOFFER_netmask="255.255.255.0" |
| 2741 | # DHCPOFFER_prefix="24" |
| 2742 | rmscip-shell system . . rm. -f $dhcp_detect_bond_tmp |
| 2743 | if [scip-shell system . . `[`. -n "$DHCPOFFER_siaddr" ]; then |
| 2744 | echoscip-shell system . . echo. $msg_delimiter_star_line |
| 2745 | echoscip-shell system . . echo. "$msg_found_dhcp_service_on_nic: $DHCPOFFER_eth" |
| 2746 | echoscip-shell system . . echo. "$msg_do_you_want_to_lease_ip_addr_from_existing_dhcp_srv: $DHCPOFFER_siaddr" |
| 2747 | echoscip-shell system . . echo. "$msg_will_use_available_ip_addr_from_dhcp_srv" |
| 2748 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 2749 | echoscip-shell system . . echo. "$msg_note_you_have_to_make_sure_enough_no_of_ip_addr" |
| 2750 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 2751 | echoscip-shell system . . echo. -n "[Y/n] " |
| 2752 | read use_existing_dhcp_srv_ans |
| 2753 | case "$use_existing_dhcp_srv_ans" in |
| 2754 | n|N|[nN][oO]) use_existing_dhcp_srv="no" ;; |
| 2755 | *) use_existing_dhcp_srv="yes" ;; |
| 2756 | esac |
| 2757 | fi |
| 2758 | } # end of detect_dhcp_srv_in_lan |
| 2759 | # |
| 2760 | config_drbl_live_networkscip-shell shell shell-project 0.0.0 config_drbl_live_network().(){ |
| 2761 | local eth_port_no configured_ip_no eth_port configured_port_list configured_ip_no |
| 2762 | local IP_no dhcp_detect_bond_tmp DHCPOFFER_netmask DHCPOFFER_prefix dhcp_find_rc |
| 2763 | local run_net_cfg try_dhcp_again manually_configure_ans |
| 2764 | # This function only works for Debian based network setting. |
| 2765 | # drbl_live_private_IP_alias_eth_def is global variable from drbl.conf. |
| 2766 | echoscip-shell system . . echo. "Detecting the network status..." |
| 2767 | eth_port_no="$(LC_ALL=C get-nic-devs | wcscip-shell system . . wc. -l)" |
| 2768 | configured_ip_no="$(LC_ALL=C get-all-nic-ip -i | wcscip-shell system . . wc. -w)" |
| 2769 | while [scip-shell system . . `[`. "$configured_ip_no" -lt "$eth_port_no" ]; do |
| 2770 | [scip-shell system . . `[`. -n "$(LC_ALL=C ip route show default 2>/dev/nullscip-shell filesystem . . `/dev/null`. | grepscip-shell system . . grep. -E "^default")" ] && config_gw_opt="--ignore-gw" |
| 2771 | [scip-shell system . . `[`. -n "$(LC_ALL=C grepscip-shell system . . grep. -E "^[[:space:]]*nameserver[[:space:]]+\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b" /etc/resolv.confscip-shell filesystem . . `/etc/resolv.conf`. 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" ] && config_dns_opt="--ignore-dns" |
| 2772 | # find the configured ports, we will exclude them. |
| 2773 | eth_port="$(LC_ALL=C get-nic-devs)" |
| 2774 | configured_port_list="" |
| 2775 | for i in $eth_port; do |
| 2776 | if [scip-shell system . . `[`. -n "$(LC_ALL=C drbl-get-ipadd $i)" ]; then |
| 2777 | configured_port_list="$configured_port_list $i" |
| 2778 | fi |
| 2779 | done |
| 2780 | echoscip-shell system . . echo. "The ethernet port(s) already configured: $configured_port_list" |
| 2781 | if [scip-shell system . . `[`. -n "$configured_port_list" ]; then |
| 2782 | ocs-live-netcfg --ip-add " " $config_gw_opt $config_dns_opt --ignore-dv "$configured_port_list" |
| 2783 | else |
| 2784 | ocs-live-netcfg --ip-add " " $config_gw_opt $config_dns_opt |
| 2785 | fi |
| 2786 | configured_ip_no="$(get-all-nic-ip -i | wcscip-shell system . . wc. -w)" |
| 2787 | [scip-shell system . . `[`. "$configured_ip_no" -eq "$eth_port_no" ] && break |
| 2788 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 2789 | echoscip-shell system . . echo. $msg_do_not_assign_default_gw_for_DRBL_NIC |
| 2790 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 2791 | echoscip-shell system . . echo. "$msg_continue_to_conf_another_NIC" |
| 2792 | echoscip-shell system . . echo. -n "[Y/n] " |
| 2793 | read continue_conf_eth |
| 2794 | case "$continue_conf_eth" in |
| 2795 | n|N|[nN][oO]) break ;; |
| 2796 | esac |
| 2797 | done |
| 2798 | |
| 2799 | IP_no="$(get-all-nic-ip -i | wcscip-shell system . . wc. -w)" |
| 2800 | if [scip-shell system . . `[`. "$IP_no" -eq 0 ]; then |
| 2801 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE |
| 2802 | echoscip-shell system . . echo. $msg_no_ip_address_is_configured |
| 2803 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 2804 | echoscip-shell system . . echo. "$msg_program_stop" |
| 2805 | exit 1 |
| 2806 | fi |
| 2807 | if [scip-shell system . . `[`. "$IP_no" -eq 1 ]; then |
| 2808 | echoscip-shell system . . echo. $msg_delimiter_star_line |
| 2809 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 2810 | echoscip-shell system . . echo. "Only one network interface was found and configured." |
| 2811 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 2812 | detect_dhcp_srv_in_lanscip-shell shell shell-project 0.0.0 detect_dhcp_srv_in_lan(). # Get use_existing_dhcp_srv and DHCPOFFER_eth |
| 2813 | eth_port="$DHCPOFFER_eth" |
| 2814 | |
| 2815 | if [scip-shell system . . `[`. "$use_existing_dhcp_srv" = "yes" ]; then |
| 2816 | # Add a virtual network device on physical net device |
| 2817 | drbl-add-vir-netdev $eth_port drbl0 |
| 2818 | echoscip-shell system . . echo. "Leasing IP address for virtual device drbl0..." |
| 2819 | dhcp_detect_vir_tmp="$(mktempscip-shell system . . mktemp. /tmp/dhcp_detect_vir_tmp.XXXXXXscip-shell filesystem . . `/tmp/dhcp_detect_vir_tmp.XXXXXX`.)" |
| 2820 | dhcp_find_rc=1 |
| 2821 | while [scip-shell system . . `[`. "$dhcp_find_rc" -ne 0 ]; do |
| 2822 | drbl-find-dhcp-srv -i drbl0 $dhcp_detect_vir_tmp |
| 2823 | dhcp_find_rc=$? |
| 2824 | if [scip-shell system . . `[`. "$dhcp_find_rc" -ne 0 ]; then |
| 2825 | echoscip-shell system . . echo. |
| 2826 | echoscip-shell system . . echo. "$msg_failed_to_find_any_dhcp_srv: drbl0" |
| 2827 | echoscip-shell system . . echo. "$msg_do_u_want_to_do_it_again" |
| 2828 | echoscip-shell system . . echo. "$msg_say_no_to_manually_config_it" |
| 2829 | echoscip-shell system . . echo. -n "[Y/n] " |
| 2830 | read try_dhcp_again |
| 2831 | case "$try_dhcp_again" in |
| 2832 | n|N|[nN][oO]) |
| 2833 | echoscip-shell system . . echo. $msg_delimiter_star_line |
| 2834 | echoscip-shell system . . echo. -n "$msg_do_you_want_to_manually_configure_it? (Y/n) " |
| 2835 | read manually_configure_ans |
| 2836 | case "$manually_configure_ans" in |
| 2837 | n|N|[nN][oO]) |
| 2838 | echoscip-shell system . . echo. "$msg_program_stop" |
| 2839 | dhcp_find_rc=0 |
| 2840 | # Saving mode, always copy error log to image dir. |
| 2841 | copy_error_log |
| 2842 | exit 1 |
| 2843 | ;; |
| 2844 | *) |
| 2845 | run_net_cfg="yes" |
| 2846 | while [scip-shell system . . `[`. "$run_net_cfg" = "yes" ]; do |
| 2847 | echoscip-shell system . . echo. $msg_delimiter_star_line |
| 2848 | echoscip-shell system . . echo. "$msg_what_is_the_ip_add_for_virtual_nic_drbl0" |
| 2849 | read drbl0_ip_prefix |
| 2850 | echoscip-shell system . . echo. "$msg_your_input_config_is: $drbl0_ip_prefix" |
| 2851 | echoscip-shell system . . echo. -n "$msg_is_that_correct (Y/n) " |
| 2852 | read input_check_ans |
| 2853 | case "$input_check_ans" in |
| 2854 | n|N|[nN][oO]) run_net_cfg="yes" ;; |
| 2855 | *) run_net_cfg="no" ;; |
| 2856 | esac |
| 2857 | done |
| 2858 | # Write to file |
| 2859 | drbl0_ip="$(echoscip-shell system . . echo. $drbl0_ip_prefix | awkscip-shell system . . awk. -F"/" '{print $1}')" |
| 2860 | drbl0_prefix="$(echoscip-shell system . . echo. $drbl0_ip_prefix | awkscip-shell system . . awk. -F"/" '{print $2}')" |
| 2861 | catscip-shell system . . cat. <<-DHCP_END > $dhcp_detect_vir_tmp |
| 2862 | DHCPOFFER_eth="drbl0" |
| 2863 | DHCPOFFER_siaddr="" |
| 2864 | DHCPOFFER_yiaddr="$drbl0_ip" |
| 2865 | DHCPOFFER_netmask="" |
| 2866 | DHCPOFFER_prefix="$drbl0_prefix" |
| 2867 | DHCP_END |
| 2868 | dhcp_find_rc=0 |
| 2869 | ;; |
| 2870 | esac |
| 2871 | ;; |
| 2872 | *) |
| 2873 | echoscip-shell system . . echo. "$msg_ok_let_do_it" |
| 2874 | dhcp_find_rc=1 |
| 2875 | ;; |
| 2876 | esac |
| 2877 | fi |
| 2878 | done |
| 2879 | # Reset variables before loading them. |
| 2880 | DHCPOFFER_eth="" |
| 2881 | DHCPOFFER_siaddr="" |
| 2882 | DHCPOFFER_yiaddr="" |
| 2883 | DHCPOFFER_netmask="" |
| 2884 | DHCPOFFER_prefix="" |
| 2885 | . $dhcp_detect_vir_tmp |
| 2886 | # Instead of using "dhclient -v drbl0" which will set routing table, we do not want. Here we use static address without routing table. |
| 2887 | if [scip-shell system . . `[`. -n "$DHCPOFFER_yiaddr" ]; then |
| 2888 | if [scip-shell system . . `[`. -z "$DHCPOFFER_prefix" ]; then |
| 2889 | # Since check_dhcp does not provide netmask/inet prefix length info, borrow it from bond card's info |
| 2890 | # ip command only accepts prefix length, not netmask. E.g. |
| 2891 | # 2: eth0 inet 192.168.76.254/24 brd 192.168.76.255 scope global eth0... |
| 2892 | DHCPOFFER_prefix="$(LC_ALL=C ip -o -f inet addr show $eth_port | awkscip-shell system . . awk. -F" " '{print $4}' | awkscip-shell system . . awk. -F"/" '{print $2}')" |
| 2893 | fi |
| 2894 | ip addr add $DHCPOFFER_yiaddr/$DHCPOFFER_prefix dev drbl0 |
| 2895 | else |
| 2896 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE |
| 2897 | echoscip-shell system . . echo. "Failed to lease DHCP IP address for network interface drbl0!" |
| 2898 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 2899 | echoscip-shell system . . echo. "$msg_program_stop!" |
| 2900 | my_ocs_exitscip-shell shell shell-project 0.0.0 my_ocs_exit(). 1 |
| 2901 | fi |
| 2902 | # Write result for later use in drblpush. |
| 2903 | if grepscip-shell system . . grep. -Eq "^use_existing_dhcp_srv=.*" /etc/drbl/drbl.confscip-shell filesystem . . `/etc/drbl/drbl.conf`.; then |
| 2904 | perlscip-shell system . . perl. -pi -e "s/^use_existing_dhcp_srv=.*/use_existing_dhcp_srv=yes # Modified by drbl-live/g" /etc/drbl/drbl.confscip-shell filesystem . . `/etc/drbl/drbl.conf`. |
| 2905 | else |
| 2906 | echoscip-shell system . . echo. "use_existing_dhcp_srv=yes # Modified by drbl-live" >> /etc/drbl/drbl.confscip-shell filesystem . . `/etc/drbl/drbl.conf`. |
| 2907 | fi |
| 2908 | rmscip-shell system . . rm. -f $dhcp_detect_vir_tmp |
| 2909 | elif [scip-shell system . . `[`. "$use_existing_dhcp_srv" = "no" ]; then |
| 2910 | # Write result for later use in drblpush. |
| 2911 | if grepscip-shell system . . grep. -Eq "^use_existing_dhcp_srv=.*" /etc/drbl/drbl.confscip-shell filesystem . . `/etc/drbl/drbl.conf`.; then |
| 2912 | perlscip-shell system . . perl. -pi -e "s/^use_existing_dhcp_srv=.*/use_existing_dhcp_srv=no # Modified by drbl-live/g" /etc/drbl/drbl.confscip-shell filesystem . . `/etc/drbl/drbl.conf`. |
| 2913 | else |
| 2914 | echoscip-shell system . . echo. "use_existing_dhcp_srv=no # Modified by drbl-live" >> /etc/drbl/drbl.confscip-shell filesystem . . `/etc/drbl/drbl.conf`. |
| 2915 | fi |
| 2916 | if [scip-shell system . . `[`. -z "$limit_pxe_drbl_client" ]; then |
| 2917 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 2918 | echoscip-shell system . . echo. "$msg_one_NIC_one_IP_limitation_prompt" |
| 2919 | echoscip-shell system . . echo. "$msg_if_lease_IP_add_to_pxe_etherboot_only" |
| 2920 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 2921 | echoscip-shell system . . echo. -n "[Y/n] " |
| 2922 | read limit_pxe_drbl_client_ans |
| 2923 | case "$limit_pxe_drbl_client_ans" in |
| 2924 | n|N|[nN][oO]) limit_pxe_drbl_client="no" ;; |
| 2925 | *) limit_pxe_drbl_client="yes" ;; |
| 2926 | esac |
| 2927 | else |
| 2928 | case "$limit_pxe_drbl_client" in |
| 2929 | n|N|[nN][oO]|y|Y|[yY][eE][sS]) truescip-shell system . . true. ;; |
| 2930 | *) |
| 2931 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE |
| 2932 | echoscip-shell system . . echo. "\"$limit_pxe_drbl_client\" is an unknown or unsupported option for limit_pxe_drbl_client." |
| 2933 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 2934 | echoscip-shell system . . echo. "$msg_program_stop" |
| 2935 | exit 1 |
| 2936 | ;; |
| 2937 | esac |
| 2938 | fi |
| 2939 | echoscip-shell system . . echo. -n "$msg_only_one_IP_so_create_alias_IP " |
| 2940 | alias_done="no" |
| 2941 | # Get the NIC device name for the only one device |
| 2942 | nic_dev_only="$(get-nic-devs | headscip-shell system . . head. -n 1)" |
| 2943 | i="$drbl_live_private_IP_alias_eth_def" |
| 2944 | while [scip-shell system . . `[`. "$alias_done" = "no" ]; do |
| 2945 | if ! ping -c 3 192.168.$i.254 &>/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 2946 | LC_ALL=C ip addr add 192.168.$i.254/255.255.255.0 dev $nic_dev_only label ${nic_dev_only}:1 && LC_ALL=C ip link set dev $nic_dev_only up |
| 2947 | alias_done="yes" |
| 2948 | else |
| 2949 | i=$((i+1)) |
| 2950 | fi |
| 2951 | done |
| 2952 | if ! grepscip-shell system . . grep. -E -e "^auto[[:space:]]+${nic_dev_only}:1" /etc/network/interfacesscip-shell filesystem . . `/etc/network/interfaces`.; then |
| 2953 | catscip-shell system . . cat. <<-NET_END >> /etc/network/interfacesscip-shell filesystem . . `/etc/network/interfaces`. |
| 2954 | auto ${nic_dev_only}:1 |
| 2955 | iface ${nic_dev_only}:1 inet static |
| 2956 | address 192.168.$i.254 |
| 2957 | netmask 255.255.255.0 |
| 2958 | NET_END |
| 2959 | fi |
| 2960 | fi |
| 2961 | |
| 2962 | echoscip-shell system . . echo. "$msg_done!" |
| 2963 | else |
| 2964 | # More than one IP address, so it's not necessary to use alias IP address. |
| 2965 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 2966 | echoscip-shell system . . echo. $msg_more_than_1_IP_some_for_DRBL_clients |
| 2967 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 2968 | fi |
| 2969 | |
| 2970 | if [scip-shell system . . `[`. -z "$(LC_ALL=C ip route show default 2>/dev/nullscip-shell filesystem . . `/dev/null`. | grepscip-shell system . . grep. -E "^default")" ]; then |
| 2971 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE |
| 2972 | echoscip-shell system . . echo. "No default gateway was configured! Did you enter it or the input gateway is the correct one ?" |
| 2973 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 2974 | echoscip-shell system . . echo. "The routing table:" |
| 2975 | echoscip-shell system . . echo. "---------------------------------------------------------" |
| 2976 | LC_ALL=C ip route show |
| 2977 | echoscip-shell system . . echo. "---------------------------------------------------------" |
| 2978 | echoscip-shell system . . echo. "$msg_program_stop" |
| 2979 | exit 1 |
| 2980 | fi |
| 2981 | } # end of config_drbl_live_network |
| 2982 | # |
| 2983 | get_existing_languagescip-shell shell shell-project 0.0.0 get_existing_language().(){ |
| 2984 | # show existing language file |
| 2985 | local ANS_TMP=$1 |
| 2986 | local rec_lang= |
| 2987 | local lang_shown |
| 2988 | local TMP=`mktempscip-shell system . . mktemp. /tmp/ocs.XXXXXXscip-shell filesystem . . `/tmp/ocs.XXXXXX`.` |
| 2989 | trap "[ -f "$TMP" ] && rm -f $TMP" HUP INT QUIT TERM EXIT |
| 2990 | numfiles=`LC_ALL=C lsscip-shell system . . ls. $DRBL_SCRIPT_PATH/lang/bash/*.UTF-8 2> /dev/nullscip-shell filesystem . . `/dev/null`. | wcscip-shell system . . wc. -l` |
| 2991 | numfiles=`LC_ALL=C exprscip-shell system . . expr. $numfiles + 0` |
| 2992 | # list the previous saved images |
| 2993 | # the list of images can be put in one page |
| 2994 | filelist="" |
| 2995 | numfiles=0 |
| 2996 | for file in $DRBL_SCRIPT_PATH/lang/bash/*.UTF-8; do |
| 2997 | fileinfo="$(basenamescip-shell system . . basename. $file)" |
| 2998 | fileinfo_="$(echoscip-shell system . . echo. $fileinfo | sedscip-shell system . . sed. -e "s/\.UTF-8//g")" |
| 2999 | # Convert to human can read, i.e. show "English" instead of "en_US" |
| 3000 | eval lang_shown=\$msg_locale_${fileinfo_} |
| 3001 | # Replace the space with "-" so that dialog won't fail. |
| 3002 | lang_shown="$(LC_ALL=C echoscip-shell system . . echo. $lang_shown | sedscip-shell system . . sed. -r -e "s/[[:space:]]/_/g")" |
| 3003 | if [scip-shell system . . `[`. -n "$lang_shown" ]; then |
| 3004 | filelist="$filelist $fileinfo $lang_shown" |
| 3005 | else |
| 3006 | filelist="$filelist $fileinfo $fileinfo_" |
| 3007 | fi |
| 3008 | numfiles=`LC_ALL=C exprscip-shell system . . expr. $numfiles + 1` |
| 3009 | done |
| 3010 | # Find the system lang setting "ocs_lang" |
| 3011 | [scip-shell system . . `[`. -e "/etc/ocs/ocs-live.confscip-shell filesystem . . `/etc/ocs/ocs-live.conf`." ] && . /etc/ocs/ocs-live.confscip-shell source . . `/etc/ocs/ocs-live.conf`. |
| 3012 | if [scip-shell system . . `[`. -n "$ocs_lang" ]; then |
| 3013 | preferred_lang_opt="--default-item $ocs_lang" |
| 3014 | fi |
| 3015 | |
| 3016 | if [scip-shell system . . `[`. "$numfiles" -gt 0 ]; then |
| 3017 | if [scip-shell system . . `[`. "$numfiles" -lt "$MAX_DIALOG_HEIGHT" ]; then |
| 3018 | height="$numfiles" |
| 3019 | else |
| 3020 | height="$MAX_DIALOG_HEIGHT" |
| 3021 | fi |
| 3022 | $DIA \ |
| 3023 | --backtitle "$msg_nchc_free_software_labs" \ |
| 3024 | --title "$msg_nchc_clonezilla | $msg_mode: $ocs_mode_prompt" \ |
| 3025 | $preferred_lang_opt \ |
| 3026 | --menu "$msg_choose_the_language_in_recovery_iso_zip:" 0 0 \ |
| 3027 | $height $filelist 2> $TMP |
| 3028 | rec_lang="$(catscip-shell system . . cat. $TMP)" |
| 3029 | else |
| 3030 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE |
| 3031 | echoscip-shell system . . echo. "No lanaguage file was found! $msg_program_stop!!!" |
| 3032 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 3033 | exit 1 |
| 3034 | fi |
| 3035 | [scip-shell system . . `[`. -f "$TMP" ] && rmscip-shell system . . rm. -f $TMP |
| 3036 | # return the valule |
| 3037 | echoscip-shell system . . echo. $rec_lang > $ANS_TMP |
| 3038 | } # end of get_existing_language |
| 3039 | # |
| 3040 | gen_locale_if_not_foundscip-shell shell shell-project 0.0.0 gen_locale_if_not_found().() { |
| 3041 | local lang_region_tmp="$1" |
| 3042 | local lang_tmp="$2" |
| 3043 | # Generate locale files. |
| 3044 | # The outputs for localedef --list-archive are like: |
| 3045 | # en_US.utf8 |
| 3046 | # zh_TW.utf8 |
| 3047 | # While we use en_US.UTF-8 or zh_TW.UTF-8 as the locale. |
| 3048 | # If it's not a archive, the locales will be saved as the name of a subdirectory in /usr/lib/locale where per-category compiled files are placed. |
| 3049 | [scip-shell system . . `[`. -z "$lang_region_tmp" ] && echoscip-shell system . . echo. "You should assign lang_region_tmp in function gen_locale_if_not_found!!!" && exit 1 |
| 3050 | [scip-shell system . . `[`. -z "$lang_tmp" ] && echoscip-shell system . . echo. "You should assign lang_tmp in function gen_locale_if_not_found!!!" && exit 1 |
| 3051 | if [scip-shell system . . `[`. -z "$(localedefscip-shell system . . localedef. --list-archive | sedscip-shell system . . sed. -e 's|\.utf8|.UTF-8|g' | grepscip-shell system . . grep. -iw "$lang_tmp")" ] && \ |
| 3052 | [ -z "$(unalias ls 2>/dev/nullscip-shell filesystem . . `/dev/null`.; lsscip-shell system . . ls. /usr/lib/localescip-shell filesystem . . `/usr/lib/locale`. 2>/dev/nullscip-shell filesystem . . `/dev/null`. | sedscip-shell system . . sed. -e 's|\.utf8|.UTF-8|g' | grepscip-shell system . . grep. -iw "$lang_tmp")" ] |
| 3053 | then |
| 3054 | echoscip-shell system . . echo. -n "Generating locale $lang_tmp by: localedef -f UTF-8 -i $lang_region_tmp $lang_tmp... " |
| 3055 | localedefscip-shell system . . localedef. -f UTF-8 -i $lang_region_tmp $lang_tmp |
| 3056 | echoscip-shell system . . echo. "done!" |
| 3057 | fi |
| 3058 | } # end of gen_locale_if_not_found |
| 3059 | # |
| 3060 | parse_cmdline_optionscip-shell shell shell-project 0.0.0 parse_cmdline_option().() { |
| 3061 | # The reason we have this function is some boot parameter is like xxx="-k -x", therefore we can not just use |
| 3062 | # case $param in |
| 3063 | # xxx=*) ... |
| 3064 | # method, since it won't catch the right xxx. It will just catch xxx="-k. |
| 3065 | # //NOTE// This function won't work for those boot parameter can not be a varialble, e.g. live-boot-media (with -, it's not a legal variable), since if we assign it by ". live-boot-media=/live-hd", it will failed. |
| 3066 | local param_ parse_tmp cmdl_file |
| 3067 | # |
| 3068 | while [scip-shell system . . `[`. $# -gt 0 ]; do |
| 3069 | case "$1" in |
| 3070 | -c|--cmdline-file) |
| 3071 | shift |
| 3072 | if [scip-shell system . . `[`. -z "$(echoscip-shell system . . echo. $1 |grepscip-shell system . . grep. ^-.)" ]; then |
| 3073 | # skip the -xx option, in case |
| 3074 | cmdl_file="$1" |
| 3075 | shift |
| 3076 | fi |
| 3077 | [scip-shell system . . `[`. -z "$cmdl_file" ] && echoscip-shell system . . echo. "-c is used, but no cmdl_file assigned." && exit 1 |
| 3078 | ;; |
| 3079 | -*) echoscip-shell system . . echo. "${0}: ${1}: invalid option" >&2 |
| 3080 | exit 2 ;; |
| 3081 | *) break ;; |
| 3082 | esac |
| 3083 | done |
| 3084 | param_="$1" |
| 3085 | parse_tmp="$(mktempscip-shell system . . mktemp. /tmp/cmdtmp.XXXXXXscip-shell filesystem . . `/tmp/cmdtmp.XXXXXX`.)" |
| 3086 | |
| 3087 | [scip-shell system . . `[`. -z "$cmdl_file" ] && cmdl_file="/proc/cmdlinescip-shell filesystem . . `/proc/cmdline`." |
| 3088 | if [scip-shell system . . `[`. ! -e "$cmdl_file" ]; then |
| 3089 | echoscip-shell system . . echo. "cmdl_file ($cmdl_file) does _NOT_ exist!" |
| 3090 | exit 1 |
| 3091 | fi |
| 3092 | |
| 3093 | for ik in $param_; do |
| 3094 | # The parameter maybe like: xxx=xyz, xxx="xyz", xxx="-k -x", or "xxx=-k -x" (see below) |
| 3095 | ### |
| 3096 | # The cases like xxx="-k -x" or "xxx=a b c", which allows spaces between " " |
| 3097 | # Possible complicated commands: |
| 3098 | # ocs_prerun="sshfs -o nonempty -p 22 [email protected]:/home/partimag/ /home/partimag" |
| 3099 | # ocs_prerun="mount -t cifs -o username=user,password=pass //127.0.0.1/test /home/partimag" |
| 3100 | # ocs_prerun="sudo mount -t cifs -o user=ghost,password=ghost123 //192.168.1.1/tftpboot$/images/clonezilla /home/partimag" # Ref: https://sourceforge.net/projects/clonezilla/forums/forum/663168/topic/4589215, for samba share with hidden share, a "$" is in the end of dir name. |
| 3101 | # Therefore we have to add "/" ":" "=" "," "@", "\\$" |
| 3102 | # |
| 3103 | # For gurb2 1.99, although \" is put in boot parameter, |
| 3104 | # it will be shown in /proc/cmdline as the following: |
| 3105 | # Boot parameters assigned -> /proc/cmdline |
| 3106 | # 4 cases: |
| 3107 | # (1) ocs_prerun="sleep 5" -> "ocs_prerun=sleep 5" (Yes, with " in the beginning and in the end. |
| 3108 | # (2) ocs_prerun='sleep 5' -> "ocs_prerun=sleep 5" |
| 3109 | # (3) ocs_prerun=\"sleep 5\" -> ocs_prerun=\"sleep 5\" |
| 3110 | # (4) ocs_prerun=dhclient -> ocs_prerun=dhclient |
| 3111 | # So far for syslinux (4.04), no such problem. Just use ocs_prerun="sleep 5". |
| 3112 | # Some examples about parsing these parameters: |
| 3113 | # ================= |
| 3114 | # ocs_prerun1="ps -efw |grep 'bound 169.254.9.223' &" |
| 3115 | # ocs_prerun2="ps -efw |grep '[a-z]'" |
| 3116 | # ocs_prerun3="sshfs -o nonempty -p 22 [email protected]:/home/partimag/ /home/partimag" |
| 3117 | # ocs_prerun4="mount -t cifs -o username=user,password=pass //127.0.0.1/test /home/partimag" |
| 3118 | # ocs_prerun5="sudo mount -t cifs -o user=ghost,password=ghost123 //192.168.1.1/tftpboot$/images/clonezilla /home/partimag" |
| 3119 | # "ocs_prerun6=sleep 5" |
| 3120 | # "ocs_prerun7=sleep 5" |
| 3121 | # ocs_prerun8=\"sleep 5\" |
| 3122 | # ocs_prerun9="sed -i -e '/[1-6]:23:/ d' -e '/1:2345:respawn/ d'" |
| 3123 | # ocs_prerun10="sed -i -e s@#T0@T0@g -e s@dev/tty@dev/ttyS0@g /etc/inittab" |
| 3124 | # ocs_prerun11="lsblk|grep ' 1 '|grep ..sd|sort -k4hr|sed 's|..\(sd..\).*|mount /dev/\1 /mnt|;1p;d'|bash" |
| 3125 | # ocs_prerun12="ps -efw |grep \"[a-z]\"" |
| 3126 | # ocs_repository=smb://name:[email protected]/images/ |
| 3127 | # ================= |
| 3128 | # ///NOTE/// We can not make it in _one_ case like this: |
| 3129 | # LC_ALL=C grep -oE -- "(\"|)*$ik=(\\\\\"|\")*([[:space:]]|[[:alnum:]]|_|-|\.|\/|:|=|,|@|\\$|>|\^|\*)*(\\\\\"|\")*([[:space:]]|$)+" $cmdl_file | sed -r -e "s|=\\\\\"|=\"|g" -e "s@\\\\\"([[:space:]]|$)+@\"@g" | sed -r -e 's|^\"(.*)=|\1=\"|g' > $parse_tmp |
| 3130 | # Since it might get wrong parsing like this: |
| 3131 | # root@debian:~# cat /proc/cmdline |
| 3132 | # initrd=/live/initrd.img boot=live config noswap nolocales edd=on nomodeset ocs_live_run="ocs-live-general" ocs_live_extra_param="" ocs_live_keymap="" ocs_live_batch="no" ocs_lang="" vga=788 ip= nosplash BOOT_IMAGE=/live/vmlinuz |
| 3133 | # root@debian:~# grep -oE -- '("|)*ocs_lang=(\\"|")*([[:space:]]|[[:alnum:]]|_|-|\.|\/|:|=|,|@|\$|>|\^|\*)*(\\"|")*([[:space:]]|$)+' /proc/cmdline |
| 3134 | # ocs_lang="" vga=788 ip= nosplash BOOT_IMAGE=/live/vmlinuz <- WRONG RESULT. We just want ocs_lang="" |
| 3135 | if LC_ALL=C grepscip-shell system . . grep. -Eq "($ik=\"|$ik=\\\\\")" $cmdl_file; then |
| 3136 | # For case like: ocs_prerun="sleep 5" or ocs_prerun=\"sleep 5\" |
| 3137 | LC_ALL=C grepscip-shell system . . grep. -oE -- "$ik=(\"|\\\\\")[^\"]*(\"|\\\\\")([[:space:]]|$)+" $cmdl_file | sedscip-shell system . . sed. -r -e "s|=\\\\\"|=\"|g" -e "s@\\\\\"([[:space:]]|$)+@\"@g" | sedscip-shell system . . sed. -r -e 's|^\"(.*)=|\1=\"|g' > $parse_tmp |
| 3138 | elif LC_ALL=C grepscip-shell system . . grep. -Eq "\"$ik=" $cmdl_file; then |
| 3139 | # For case like: "ocs_prerun=sleep 5", "ocs_prerun1=mount UUID=XXXYYZZ /mnt" |
| 3140 | # 2012/08/20 Without separating "=", it might fail in this case: |
| 3141 | # "ocs_prerun1=mount UUID=XXXYYZZ /mnt" -> ocs_prerun1=mount UUID="XXXYYZZ /mnt" |
| 3142 | # Therefore we have to use: sed -r -e 's|^\"(.*=)(.*=.*)*|\1\"\2|g' |
| 3143 | # 2020/12/26 When two "=" in the variable, e.g.,: |
| 3144 | # "ocs_live_run=ocs-sr -q2 -j2 -z1p -p poweroff savedisk autoname-wpfx=fox serialno=xyz" |
| 3145 | # it fails at: |
| 3146 | # ocs_live_run=ocs-sr -q2 -j2 -z1p -p poweroff savedisk autoname-wpfx="fox serialno=xyz" |
| 3147 | # since sed is greedy regex. |
| 3148 | # Therefore we have to use non-greedy regex language, perl, for this purpose: |
| 3149 | # perl -pi -e 's/(^")(.*?=)(.*=.*)*/$2"$3/g' $parse_tmp |
| 3150 | # Ref: http://stackoverflow.com/questions/9681393/sed-multiple-patterns-on-the-same-line-how-to-match-parse-first-one |
| 3151 | # https://www.ultraedit.com/support/tutorials-power-tips/ultraedit/non-greedy-perl-regex.html |
| 3152 | LC_ALL=C grepscip-shell system . . grep. -oE -- "\"$ik=[^\"]*\"([[:space:]]|$)+" $cmdl_file | \ |
| 3153 | sed -r -e "s|=\\\\\"|=\"|g" -e "s@\\\\\"([[:space:]]|$)+@\"@g" \ |
| 3154 | > $parse_tmp |
| 3155 | perlscip-shell system . . perl. -pi -e 's/(^")(.*?=)(.*=.*)*/$2"$3/g' $parse_tmp |
| 3156 | else |
| 3157 | # This is for case xxx=xyz, no space in its assignment |
| 3158 | LC_ALL=C grepscip-shell system . . grep. -oE -- "$ik=[^[:space:]]*([[:space:]]|$)+" $cmdl_file > $parse_tmp |
| 3159 | fi |
| 3160 | # now we can get the variables |
| 3161 | # . $parse_tmp <--- One more thing to do. |
| 3162 | # In we just read the variable using ". $parse_tmp", and it happends to have "$" in the variable, then the way will go wrong. E.g. the output file "/tmp/cmdtmp.XXXXXX" contains this line: |
| 3163 | # ocs_prerun="mount -t cifs -o user=steven,domain=ABC.COM,password=12$ABC34 //serv/images /home/partimag" |
| 3164 | # By running ". /tmp/cmdtmp.XXXXXX", the ocs_prerun will be: |
| 3165 | # mount -t cifs -o user=steven,domain=ABC.COM,password=12 //serv/images /home/partimag |
| 3166 | # It's because $ABC34 is nothing here. Therefore we have to protect "$" in the temp file. |
| 3167 | perlscip-shell system . . perl. -pi -e 's|\$|\\\$|g' $parse_tmp |
| 3168 | . $parse_tmp |
| 3169 | done |
| 3170 | [scip-shell system . . `[`. -f "$parse_tmp" ] && rmscip-shell system . . rm. -f $parse_tmp |
| 3171 | } # parse_cmdline_option |
| 3172 | # |
| 3173 | output_netinstall_boot_menuscip-shell shell shell-project 0.0.0 output_netinstall_boot_menu().() { |
| 3174 | local TDIR # Where netinstall kernel/initrd exists (e.g. /tftpboot/nbi_img) |
| 3175 | local NB_CFG_DIR_FNAME # Where pxeliux cfg file exists (e.g. /tftpboot/nbi_img/pxelinux.cfg/) |
| 3176 | local menu_hint ni_ver ni_arch boot_file_dir |
| 3177 | local nb_mode_="pxe" # Default mode if not assigned |
| 3178 | local usb_boot_media_="no" # Default not to prepend the setting for USB boot media |
| 3179 | # output the netinstall menu |
| 3180 | # Here 2 types: Linux and BSD |
| 3181 | # The netinstall kernel files (linux) or pxeboot file (bsd) in /tftpboot/nbi_img are, e.g.: |
| 3182 | # Type 1: for Linux, the file names are like: |
| 3183 | # vmlinuz-netinstall-CentOS-4.6-i386 |
| 3184 | # vmlinuz-netinstall-CentOS-4.6-x86_64 |
| 3185 | # vmlinuz-netinstall-CentOS-5.1-i386 |
| 3186 | # vmlinuz-netinstall-CentOS-5.1-x86_64 |
| 3187 | # vmlinuz-netinstall-Debian-etch-amd64 |
| 3188 | # vmlinuz-netinstall-Debian-etch-i386 |
| 3189 | # vmlinuz-netinstall-Debian-sarge-i386 |
| 3190 | # vmlinuz-netinstall-Fedora-7-i386 |
| 3191 | # vmlinuz-netinstall-Fedora-7-x86_64 |
| 3192 | |
| 3193 | # Type 2: for BSD, the file names are like: |
| 3194 | # OpenBSD-4.2-i386-pxeboot.0 |
| 3195 | # FreeBSD-7.0-i386-pxeboot.0 |
| 3196 | |
| 3197 | while [scip-shell system . . `[`. $# -gt 0 ]; do |
| 3198 | case "$1" in |
| 3199 | -e|--efi) nb_mode_="efi"; shift;; |
| 3200 | -p|--prefix) |
| 3201 | shift |
| 3202 | if [scip-shell system . . `[`. -z "$(echoscip-shell system . . echo. $1 |grepscip-shell system . . grep. ^-.)" ]; then |
| 3203 | # skip the -xx option, in case |
| 3204 | boot_file_dir="$1" |
| 3205 | shift |
| 3206 | fi |
| 3207 | if [scip-shell system . . `[`. -z "$boot_file_dir" ]; then |
| 3208 | echoscip-shell system . . echo. "-p is used, but no \"boot_file_dir\" assigned." |
| 3209 | echoscip-shell system . . echo. "$msg_program_stop" |
| 3210 | [scip-shell system . . `[`. "$save_restore_error_log" = "yes" ] && copy_error_log |
| 3211 | exit 1 |
| 3212 | fi |
| 3213 | ;; |
| 3214 | -u|--usb-boot-media) usb_boot_media_="yes"; shift;; |
| 3215 | -*) echoscip-shell system . . echo. "${0}: ${1}: invalid option" >&2 |
| 3216 | exit 2 ;; |
| 3217 | *) break ;; |
| 3218 | esac |
| 3219 | done |
| 3220 | |
| 3221 | TDIR="$1" |
| 3222 | NB_CFG_DIR_FNAME="$2" |
| 3223 | |
| 3224 | if [scip-shell system . . `[`. "$nb_mode_" = "efi" -a "$usb_boot_media_" = "yes" ]; then |
| 3225 | # This is for drbl-usb-netinstall use. For the netboot of DRBL clients, |
| 3226 | # the gen-grub-efi-nb-menu will prepend those configs for diskless clients. |
| 3227 | catscip-shell system . . cat. <<-PXE_END > $NB_CFG_DIR_FNAME |
| 3228 | # Netboot menu for grub |
| 3229 | set pref=/boot/grub |
| 3230 | set default="0" |
| 3231 | insmod efi_gop |
| 3232 | insmod efi_uga |
| 3233 | if [ x\$feature_default_font_path = xy ] ; then |
| 3234 | font=unicode |
| 3235 | else |
| 3236 | font=\$prefix/unifont.pf2 |
| 3237 | fi |
| 3238 | |
| 3239 | if loadfont \$font; then |
| 3240 | set gfxmode=auto |
| 3241 | insmod gfxterm |
| 3242 | terminal_output gfxterm |
| 3243 | fi |
| 3244 | set timeout=30 |
| 3245 | set hidden_timeout_quiet=false |
| 3246 | insmod png |
| 3247 | if background_image \$pref/drblwp.png; then |
| 3248 | set color_normal=black/white |
| 3249 | set color_highlight=green/white |
| 3250 | else |
| 3251 | set color_normal=white/black |
| 3252 | set color_highlight=black/white |
| 3253 | fi |
| 3254 | |
| 3255 | # Decide if the commands: linux/initrd (default) or linuxefi/initrdefi |
| 3256 | set linux_cmd=linux |
| 3257 | set initrd_cmd=initrd |
| 3258 | export linux_cmd initrd_cmd |
| 3259 | # Since "linux/initrd" works for uEFI boot, no matter it's secure boot or not. Just use them. |
| 3260 | # if [ "\${grub_cpu}" = "x86_64" -o "\${grub_cpu}" = "i386" ];then |
| 3261 | # set linux_cmd=linuxefi |
| 3262 | # set initrd_cmd=initrdefi |
| 3263 | # fi |
| 3264 | |
| 3265 | PXE_END |
| 3266 | fi |
| 3267 | |
| 3268 | # Type 1: Linux |
| 3269 | for inet in $TDIR/vmlinuz-netinstall-*; do |
| 3270 | # /tftpboot/nbi_img/vmlinuz-netinstall-CentOS-4-i386 |
| 3271 | # /tftpboot/nbi_img/initrd-netinstall-CentOS-4-i386.img |
| 3272 | |
| 3273 | [scip-shell system . . `[`. ! -e "$inet" ] && continue |
| 3274 | # Truncate "vmlinuz-" |
| 3275 | # For debina based, back convert x86-64 to x86_64, since alien convert x86_64 to x86-64. |
| 3276 | kernel="$(basenamescip-shell system . . basename. $inet)" |
| 3277 | inet_="$(basenamescip-shell system . . basename. $inet | sedscip-shell system . . sed. -e "s/^vmlinuz-//g" -e "s/x86-64/x86_64/g")" |
| 3278 | img_menu="$(echoscip-shell system . . echo. "$inet_" | awkscip-shell system . . awk. -F"-" '{print $1"-"$2"-"$3"-"$4}')" |
| 3279 | img="$(unalias ls 2>/dev/nullscip-shell filesystem . . `/dev/null`.; lsscip-shell system . . ls. $TDIR/*${inet_}* 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" |
| 3280 | img="$(basenamescip-shell system . . basename. $img)" |
| 3281 | |
| 3282 | extra_append="" |
| 3283 | if [scip-shell system . . `[`. -n "$(echoscip-shell system . . echo. $inet | grepscip-shell system . . grep. -i "\-debian-woody" 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" ]; then |
| 3284 | # For Debian Woody, we use extra options bf24 |
| 3285 | # refer to http://www.debianplanet.com/node.php?id=818&cid=13384 |
| 3286 | NETINSTALL_RAMDISK_SIZE="$NETINSTALL_RAMDISK_SIZE_DEF" |
| 3287 | extra_append="flavor=bf2.4" |
| 3288 | menu_hint="" |
| 3289 | elif [scip-shell system . . `[`. -n "$(echoscip-shell system . . echo. $inet | grepscip-shell system . . grep. -i "\-debian-sarge" 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" ]; then |
| 3290 | # For Debian Sarge, we need extra options in append |
| 3291 | # refer to http://opensource.nchc.org.tw/debian/dists/sarge/main/installer-i386/current/images/netboot/pxelinux.cfg/default |
| 3292 | NETINSTALL_RAMDISK_SIZE="$NETINSTALL_RAMDISK_SIZE_DEF" |
| 3293 | extra_append="root=/dev/rd/0 devfs=mount,dall rw --" |
| 3294 | menu_hint="" |
| 3295 | elif [scip-shell system . . `[`. -n "$(echoscip-shell system . . echo. $inet | grepscip-shell system . . grep. -iE "\-debian-etch" 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" ]; then |
| 3296 | # Ref: http://free.nchc.org.tw/debian/dists/etch/main/installer-i386/current/images/netboot//debian-installer/i386/pxelinux.cfg/default |
| 3297 | NETINSTALL_RAMDISK_SIZE="" |
| 3298 | extra_append="vga=normal" |
| 3299 | elif [scip-shell system . . `[`. -n "$(echoscip-shell system . . echo. $inet | grepscip-shell system . . grep. -iE "\-debian-" 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" ]; then |
| 3300 | # For version >= lenny, gtk netinstall mode is available, actually we can turn on it by adding "video=vesa:ywrap,mtrr vga=788" in the boot parameters. However, since normally those people use debian can accept text mode, we do not put "video=vesa:ywrap,mtrr vga=788" here. |
| 3301 | # http://free.nchc.org.tw/debian/dists/lenny/main/installer-i386/current/images/netboot/gtk/debian-installer/i386/boot-screens/txt.cfg |
| 3302 | NETINSTALL_RAMDISK_SIZE="" |
| 3303 | extra_append="vga=normal" |
| 3304 | menu_hint="# Hint: To turn on gtk mode installation, append 'video=vesa:ywrap,mtrr vga=788' in the boot parameters" |
| 3305 | elif [scip-shell system . . `[`. -n "$(echoscip-shell system . . echo. $inet | grepscip-shell system . . grep. -iE "\-redhat-" 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" ]; then |
| 3306 | # For RedHat, enable reiserfs when installing |
| 3307 | NETINSTALL_RAMDISK_SIZE="$NETINSTALL_RAMDISK_SIZE_DEF" |
| 3308 | extra_append="reiserfs" |
| 3309 | menu_hint="" |
| 3310 | elif [scip-shell system . . `[`. -n "$(echoscip-shell system . . echo. $inet | grepscip-shell system . . grep. -iE "\-fedora-" 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" ]; then |
| 3311 | # Fedora vmlinuz name e.g. vmlinuz-netinstall-Fedora-17-x86_64 |
| 3312 | ni_ver="$(echoscip-shell system . . echo. $inet | cutscip-shell system . . cut. -f 4 -d "-")" |
| 3313 | ni_arch="$(echoscip-shell system . . echo. $inet | cutscip-shell system . . cut. -f 5 -d "-")" |
| 3314 | # ramdisk_size only necessary for fedora 1-4, from fc5, it's initramfs, ramdisk_size is not used anymore |
| 3315 | if [scip-shell system . . `[`. -n "$(echoscip-shell system . . echo. $inet | grepscip-shell system . . grep. -iE "\-fedora-[1-4]-" 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" ]; then |
| 3316 | NETINSTALL_RAMDISK_SIZE="$NETINSTALL_RAMDISK_SIZE_DEF" |
| 3317 | else |
| 3318 | NETINSTALL_RAMDISK_SIZE="" |
| 3319 | fi |
| 3320 | if [scip-shell system . . `[`. -n "$(echoscip-shell system . . echo. $inet | grepscip-shell system . . grep. -iE "\-fedora-([5-9]|1[1-6])-" 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" ]; then |
| 3321 | # For Fedora 5 to 16. |
| 3322 | extra_append="" |
| 3323 | elif [scip-shell system . . `[`. -n "$(echoscip-shell system . . echo. $inet | grepscip-shell system . . grep. -iE "\-fedora-(1[7-9]|20)-" 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" ]; then |
| 3324 | # For Fedora 16 to 20. |
| 3325 | echoscip-shell system . . echo. "Using Fedora installation repository \"$fedora_url_site\" from drbl.conf" |
| 3326 | extra_append="inst.repo=$fedora_url_site/fedora/linux/releases/$ni_ver/Fedora/$ni_arch/os" |
| 3327 | else |
| 3328 | # For Fedora 21 or later |
| 3329 | echoscip-shell system . . echo. "Using Fedora installation repository \"$fedora_url_site\" from drbl.conf" |
| 3330 | extra_append="inst.repo=$fedora_url_site/fedora/linux/releases/$ni_ver/Server/$ni_arch/os" |
| 3331 | fi |
| 3332 | # For Fedora, enable reiserfs when installing |
| 3333 | menu_hint="" |
| 3334 | elif [scip-shell system . . `[`. -n "$(echoscip-shell system . . echo. $inet | grepscip-shell system . . grep. -iE "\-rockylinux\-" 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" ]; then |
| 3335 | # Rocky Linux vmlinuz name e.g. vmlinuz-netinstall-RockyLinux-9-x86_64 |
| 3336 | ni_ver="$(echoscip-shell system . . echo. $inet | cutscip-shell system . . cut. -f 4 -d "-")" |
| 3337 | ni_arch="$(echoscip-shell system . . echo. $inet | cutscip-shell system . . cut. -f 5 -d "-")" |
| 3338 | NETINSTALL_RAMDISK_SIZE="" |
| 3339 | echoscip-shell system . . echo. "Using Rocky Linux installation repository \"$rocky_url_site\" from drbl.conf" |
| 3340 | # http://free.nchc.org.tw/rocky/9/BaseOS/x86_64/os/ |
| 3341 | extra_append="inst.repo=$rocky_url_site/$path_to_rocky/$ni_ver/BaseOS/$ni_arch/os/" |
| 3342 | menu_hint="" |
| 3343 | elif [scip-shell system . . `[`. -n "$(echoscip-shell system . . echo. $inet | grepscip-shell system . . grep. -iE "\-ubuntu-[a-e]" 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" ]; then |
| 3344 | # For other Ubuntu: 5.10, 6.06, 6.10 |
| 3345 | # ref to ftp://linux.nchc.org.tw/distributions/ubuntu/dists/hoary/main/installer-i386/current/images/netboot/ubuntu-installer/i386/pxelinux.cfg/default |
| 3346 | NETINSTALL_RAMDISK_SIZE="$NETINSTALL_RAMDISK_SIZE_DEF" |
| 3347 | extra_append="root=/dev/rd/0 rw --" |
| 3348 | menu_hint="" |
| 3349 | elif [scip-shell system . . `[`. -n "$(echoscip-shell system . . echo. $inet | grepscip-shell system . . grep. -iE "\-ubuntu-[f-i]" 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" ]; then |
| 3350 | # For Ubuntu Feisty (7.04) |
| 3351 | # ref to http://opensource.nchc.org.tw/ubuntu/dists/feisty/main/installer-i386/current/images/netboot/ubuntu-installer/i386/pxelinux.cfg/default |
| 3352 | # It's initramfs, so ramdisk_size is no more. |
| 3353 | NETINSTALL_RAMDISK_SIZE="" |
| 3354 | extra_append="vga=normal --" |
| 3355 | menu_hint="" |
| 3356 | elif [scip-shell system . . `[`. -n "$(echoscip-shell system . . echo. $inet | grepscip-shell system . . grep. -iE "\-ubuntu\-[j-z]" 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" ]; then |
| 3357 | # Modern Ubuntu (Jammy 22.04, Noble 24.04 and later) |
| 3358 | ni_ver="$(echoscip-shell system . . echo. $inet | cutscip-shell system . . cut. -f 4 -d "-")" |
| 3359 | ni_arch="$(echoscip-shell system . . echo. $inet | cutscip-shell system . . cut. -f 5 -d "-")" |
| 3360 | NETINSTALL_RAMDISK_SIZE="" |
| 3361 | drbl_server_ip="$(get-all-nic-ip -b | awkscip-shell system . . awk. '{print $1}')" |
| 3362 | [scip-shell system . . `[`. -z "$drbl_server_ip" ] && drbl_server_ip="$(get-all-nic-ip -i | awkscip-shell system . . awk. '{print $1}')" |
| 3363 | extra_append="boot=casper netboot=nfs nfsroot=$drbl_server_ip:$drbl_common_root/ubuntu-iso/$ni_ver-$ni_arch ip=dhcp rw" |
| 3364 | menu_hint="# Hint: Ensure the Ubuntu Live Server ISO is extracted to: $drbl_common_root/ubuntu-iso/$ni_ver-$ni_arch/ (making sure to copy the hidden .disk directory as well)" |
| 3365 | elif [scip-shell system . . `[`. -n "$(echoscip-shell system . . echo. $inet | grepscip-shell system . . grep. -i "\-suse-" 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" ]; then |
| 3366 | # For SuSE |
| 3367 | # For extra_append, refer to something like |
| 3368 | # http://free.nchc.org.tw/SuSE/SuSE/i386/9.3/boot/loader/isolinux.cfg |
| 3369 | # use larger ramdisk size, overwrite the default one. |
| 3370 | NETINSTALL_RAMDISK_SIZE=128000 |
| 3371 | extra_append="splash=silent showopts" |
| 3372 | menu_hint="" |
| 3373 | elif [scip-shell system . . `[`. -n "$(echoscip-shell system . . echo. $inet | grepscip-shell system . . grep. -i "\-opensuse-" 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" ]; then |
| 3374 | # For OpenSuSE |
| 3375 | # For extra_append, refer to something like |
| 3376 | # http://ftp.cs.pu.edu.tw/Linux/OpenSuse/distribution/SL-10.0-OSS/inst-source/boot/loader/isolinux.cfg |
| 3377 | # use larger ramdisk size, overwrite the default one. |
| 3378 | NETINSTALL_RAMDISK_SIZE=128000 |
| 3379 | extra_append="splash=silent showopts" |
| 3380 | menu_hint="" |
| 3381 | else |
| 3382 | NETINSTALL_RAMDISK_SIZE="$NETINSTALL_RAMDISK_SIZE_DEF" |
| 3383 | extra_append="" |
| 3384 | menu_hint="" |
| 3385 | fi |
| 3386 | |
| 3387 | # skip if we can not find the menu, img or kernel. |
| 3388 | [scip-shell system . . `[`. -z "$img_menu" ] && continue |
| 3389 | [scip-shell system . . `[`. -z "$img" -o -z "$kernel" ] && continue |
| 3390 | |
| 3391 | # Generate the description: |
| 3392 | # EX for i: rh-8.0-netinstall |
| 3393 | # create the description for the netinstall image |
| 3394 | des="$(echoscip-shell system . . echo. $img_menu | sedscip-shell system . . sed. -e "s/^netinstall-//g" | sedscip-shell system . . sed. -e "s/-/ /g")" |
| 3395 | des="${des} installation via network" |
| 3396 | # For initramfs, ramdisk_size is no more. |
| 3397 | if [scip-shell system . . `[`. -n "$NETINSTALL_RAMDISK_SIZE" ]; then |
| 3398 | ramdisk_size_opt="ramdisk_size=$NETINSTALL_RAMDISK_SIZE" |
| 3399 | else |
| 3400 | ramdisk_size_opt="" |
| 3401 | fi |
| 3402 | |
| 3403 | if [scip-shell system . . `[`. "$nb_mode_" = "pxe" ]; then |
| 3404 | echoscip-shell system . . echo. "Adding $img_menu menu..." |
| 3405 | [scip-shell system . . `[`. -n "$verbose" ] && echoscip-shell system . . echo. "extra option in append: $extra_append" |
| 3406 | catscip-shell system . . cat. <<-PXE_END >> $NB_CFG_DIR_FNAME |
| 3407 | label $img_menu |
| 3408 | # MENU DEFAULT |
| 3409 | MENU HIDE |
| 3410 | MENU LABEL $des |
| 3411 | # MENU PASSWD |
| 3412 | kernel $boot_file_dir$kernel |
| 3413 | append initrd=$boot_file_dir$img $ramdisk_size_opt $extra_append |
| 3414 | $menu_hint |
| 3415 | TEXT HELP |
| 3416 | * Boot menu for BIOS machine |
| 3417 | * $des |
| 3418 | ENDTEXT |
| 3419 | |
| 3420 | PXE_END |
| 3421 | else |
| 3422 | # Only output x86-64/amd64 one for uEFI mode |
| 3423 | if [scip-shell system . . `[`. -n "$(echoscip-shell system . . echo. $kernel | grepscip-shell system . . grep. -iE -- "(x86-64|x86_64|amd64|i386)")" ]; then |
| 3424 | echoscip-shell system . . echo. "Adding $img_menu menu..." |
| 3425 | [scip-shell system . . `[`. -n "$verbose" ] && echoscip-shell system . . echo. "extra option in append: $extra_append" |
| 3426 | catscip-shell system . . cat. <<-PXE_END >> $NB_CFG_DIR_FNAME |
| 3427 | menuentry "$des" --id $img_menu { |
| 3428 | set check_signatures=no |
| 3429 | echo "Enter netinstall for $img_menu..." |
| 3430 | echo "Loading Linux kernel..." |
| 3431 | \$linux_cmd $boot_file_dir$kernel $ramdisk_size_opt $extra_append |
| 3432 | echo "Loading initial ramdisk..." |
| 3433 | \$initrd_cmd $boot_file_dir$img |
| 3434 | } |
| 3435 | |
| 3436 | PXE_END |
| 3437 | fi |
| 3438 | fi |
| 3439 | done |
| 3440 | |
| 3441 | # Type 2: BSD |
| 3442 | for inet in $TDIR/*-pxeboot.0; do |
| 3443 | # Ex: /tftpboot/nbi_img/FreeBSD-7.0-i386-pxeboot.0 |
| 3444 | [scip-shell system . . `[`. ! -e "$inet" ] && continue |
| 3445 | # Truncate "-pxeboot.0" |
| 3446 | inet_="$(basenamescip-shell system . . basename. $inet | sedscip-shell system . . sed. -e "s/-pxeboot.0//g")" |
| 3447 | img_menu="$(echoscip-shell system . . echo. "$inet_" | awkscip-shell system . . awk. -F"-" '{print $1"-"$2"-"$3}')-netinstall" |
| 3448 | img="$(unalias ls 2>/dev/nullscip-shell filesystem . . `/dev/null`.; lsscip-shell system . . ls. $TDIR/*${inet_}* 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" |
| 3449 | img="$(basenamescip-shell system . . basename. $img)" |
| 3450 | # create the description for the netinstall image |
| 3451 | des="$(echoscip-shell system . . echo. $img_menu | sedscip-shell system . . sed. -e "s/-netinstall$//g" | sedscip-shell system . . sed. -e "s/-/ /g")" |
| 3452 | des="${des} installation via network" |
| 3453 | [scip-shell system . . `[`. -z "$img_menu" ] && continue |
| 3454 | echoscip-shell system . . echo. "Adding $img_menu menu..." |
| 3455 | if [scip-shell system . . `[`. "$nb_mode_" = "pxe" ]; then |
| 3456 | catscip-shell system . . cat. <<-PXE_END >> $NB_CFG_DIR_FNAME |
| 3457 | label $img_menu |
| 3458 | # MENU DEFAULT |
| 3459 | MENU HIDE |
| 3460 | MENU LABEL $des |
| 3461 | # MENU PASSWD |
| 3462 | kernel $boot_file_dir$img |
| 3463 | TEXT HELP |
| 3464 | * Boot menu for BIOS machine |
| 3465 | * $des |
| 3466 | ENDTEXT |
| 3467 | |
| 3468 | PXE_END |
| 3469 | else |
| 3470 | catscip-shell system . . cat. <<-PXE_END >> $NB_CFG_DIR_FNAME |
| 3471 | menuentry "$des" --id $img_menu { |
| 3472 | echo "Enter netinstall for $img_menu..." |
| 3473 | echo "Loading Linux kernel..." |
| 3474 | \$linux_cmd $boot_file_dir$img |
| 3475 | } |
| 3476 | |
| 3477 | PXE_END |
| 3478 | fi |
| 3479 | done |
| 3480 | } # end of output_netinstall_boot_menu |
| 3481 | # |
| 3482 | get_syslinux_binary_for_dos_linuxscip-shell shell shell-project 0.0.0 get_syslinux_binary_for_dos_linux().() { |
| 3483 | local sysl_dir="$1" |
| 3484 | # syslinux_ver is not required. If it's not assigned, the latest one on the web will be used. |
| 3485 | local syslinux_ver="$2" |
| 3486 | local syslinux_tarball syslinux_ver_subdir syslinux_extra_c32 dirprefix syslinux_efi_coms |
| 3487 | local found_url valid_ulr |
| 3488 | [scip-shell system . . `[`. -z "$sysl_dir" -o ! -d "$sysl_dir" ] && echoscip-shell system . . echo. "No sysl_dir!" && exit 1 |
| 3489 | # syslinux_binsrc_url is like: |
| 3490 | # http://www.kernel.org/pub/linux/utils/boot/syslinux/ |
| 3491 | # For any version 4.xx, it will be found in http://www.kernel.org/pub/linux/utils/boot/syslinux/4.xx/. However, the latest one is in http://www.kernel.org/pub/linux/utils/boot/syslinux/ |
| 3492 | if [scip-shell system . . `[`. -z "$syslinux_ver" ]; then |
| 3493 | # If no version is assigned, find the latest one. |
| 3494 | syslinux_tarball="$(LC_ALL=C list_latest_tarball -f xz $syslinux_binsrc_url)" |
| 3495 | syslinux_ver="$(LC_ALL=C echoscip-shell system . . echo. "$syslinux_tarball" | sedscip-shell system . . sed. -e "s/^syslinux-//g" -e "s/.tar.xz//g")" |
| 3496 | else |
| 3497 | syslinux_tarball="syslinux-${syslinux_ver}.tar.xz" |
| 3498 | fi |
| 3499 | if [scip-shell system . . `[`. -z "$(echoscip-shell system . . echo. $syslinux_ver | grepscip-shell system . . grep. -iE -- "-pre[[:digit:]]+")" ]; then |
| 3500 | # Stable release, not testing version. |
| 3501 | # Convert the version number to subdir name, e..g 4.04 -> 4.xx |
| 3502 | syslinux_ver_subdir="$(LC_ALL=C echoscip-shell system . . echo. "$syslinux_ver" | sedscip-shell system . . sed. -r -e "s/\.[[:digit:]]*$/\.xx/g")" |
| 3503 | else |
| 3504 | # Testing release. File name is like: syslinux-6.02-pre16.tar.xz |
| 3505 | # The URL for such a testing version is like: http://free.nchc.org.tw/syslinux/Testing/6.02/ |
| 3506 | syslinux_ver_subdir="$(LC_ALL=C echoscip-shell system . . echo. "$syslinux_ver" | sedscip-shell system . . sed. -r -e "s/-pre[[:digit:]]+$//g")" |
| 3507 | syslinux_ver_subdir="Testing/$syslinux_ver_subdir" |
| 3508 | fi |
| 3509 | found_url="false" |
| 3510 | while [scip-shell system . . `[`. "$found_url" = "false" ]; do |
| 3511 | if `check_url $syslinux_binsrc_url/$syslinux_ver_subdir/$syslinux_tarball`; then |
| 3512 | valid_ulr="$syslinux_binsrc_url/$syslinux_ver_subdir/$syslinux_tarball" |
| 3513 | found_url="true" |
| 3514 | else |
| 3515 | # E.g., 6.04 -> 6.03 |
| 3516 | # Because Debian has syslinux like: 3:6.04~git20190206.bf6db5b4+dfsg1-1, but |
| 3517 | # actually 6.04 is not officially released on syslinux.org (Sep/25/2021). |
| 3518 | syslinux_ver="$(LC_ALL=C echoscip-shell system . . echo. "scale=2; $syslinux_ver - 0.01" | bc -l)" |
| 3519 | echoscip-shell system . . echo. "Try earlier syslinux version $syslinux_ver..." |
| 3520 | syslinux_tarball="syslinux-${syslinux_ver}.tar.xz" |
| 3521 | fi |
| 3522 | done |
| 3523 | echoscip-shell system . . echo. "Downloading $valid_ulr..." |
| 3524 | wget $wget_opt -P $sysl_dir $valid_ulr |
| 3525 | # For syslinux 6.x, due to EFI feature was added, *.c32 might be in different dirs, e.g. for menu.c32: |
| 3526 | # $ tar tvJf syslinux-5.10.tar.xz | grep -w menu.c32 |
| 3527 | # -rwxrwxr-x mfleming/syslinux 25808 2013-06-05 03:33 syslinux-5.10/com32/menu/menu.c32 |
| 3528 | # $ tar tvJf syslinux-6.01.tar.xz |grep -w menu.c32 |
| 3529 | # -rwxrwxr-x mfleming/syslinux 25708 2013-07-04 21:26 syslinux-6.01/bios/com32/menu/menu.c32 |
| 3530 | # -rwxrwxr-x mfleming/syslinux 26012 2013-07-04 21:27 syslinux-6.01/efi32/com32/menu/menu.c32 |
| 3531 | # -rwxrwxr-x mfleming/syslinux 31416 2013-07-04 21:28 syslinux-6.01/efi64/com32/menu/menu.c32 |
| 3532 | # Therefore we have to parse them... |
| 3533 | # //NOTE// The syslinux tarball (<= ver 6.03) from syslinux.org only contains x86 (32-bit) programs for GNU/Linux, no x86-64 ones. |
| 3534 | if [scip-shell system . . `[`. -n "$(tarscip-shell system . . tar. -tvJf $sysl_dir/syslinux-${syslinux_ver}.tar.xz | \ |
| 3535 | grep -w "bios/com32/menu/menu.c32")" ]; then |
| 3536 | dirprefix="bios/" |
| 3537 | else |
| 3538 | dirprefix_bios="" |
| 3539 | fi |
| 3540 | # For syslinux 5.x, ./com32/elflink/ldlinux/ldlinux.c32, ./com32/lib/libcom32.c32, and ./com32/libutil/libutil.c32 are required. |
| 3541 | for i in $sys_pxelinux_v5p_required_c32; do |
| 3542 | if [scip-shell system . . `[`. -n "$(LC_ALL=C tarscip-shell system . . tar. -tvJf $sysl_dir/syslinux-${syslinux_ver}.tar.xz | grepscip-shell system . . grep. -Ew $i)" ]; then |
| 3543 | syslinux_extra_c32="syslinux-${syslinux_ver}/${dirprefix}com32/elflink/ldlinux/ldlinux.c32 syslinux-${syslinux_ver}/${dirprefix}com32/lib/libcom32.c32 syslinux-${syslinux_ver}/${dirprefix}com32/libutil/libutil.c32" |
| 3544 | break |
| 3545 | fi |
| 3546 | done |
| 3547 | # Extract win32/syslinux.exe, linux/syslinux and more. This is for BIOS machine |
| 3548 | echoscip-shell system . . echo. "Extracting files..." |
| 3549 | mkdirscip-shell system . . mkdir. -p $sysl_dir/bios/ |
| 3550 | ( |
| 3551 | cd $sysl_dir/bios/ |
| 3552 | # From syslinux 3.73, linux/syslinux is hardlink to linux/syslinux-nomtools, therefore we have to use --wildcards to extract it. Otherwise it will fail. |
| 3553 | tarscip-shell system . . tar. --wildcards -xvJf ../syslinux-${syslinux_ver}.tar.xz syslinux-${syslinux_ver}/${dirprefix}com32/menu/menu.c32 syslinux-${syslinux_ver}/${dirprefix}com32/menu/vesamenu.c32 syslinux-${syslinux_ver}/${dirprefix}com32/chain/chain.c32 syslinux-${syslinux_ver}/${dirprefix}win32/syslinux.exe syslinux-${syslinux_ver}/${dirprefix}win64/syslinux64.exe syslinux-${syslinux_ver}/${dirprefix}linux/syslinux* syslinux-${syslinux_ver}/${dirprefix}extlinux/extlinux* syslinux-${syslinux_ver}/${dirprefix}mbr/mbr.bin syslinux-${syslinux_ver}/${dirprefix}core/isolinux.bin syslinux-${syslinux_ver}/${dirprefix}memdisk/memdisk $syslinux_extra_c32 |
| 3554 | mvscip-shell system . . mv. -f syslinux-${syslinux_ver}/${dirprefix}com32/menu/menu.c32 . |
| 3555 | mvscip-shell system . . mv. -f syslinux-${syslinux_ver}/${dirprefix}com32/menu/vesamenu.c32 . |
| 3556 | mvscip-shell system . . mv. -f syslinux-${syslinux_ver}/${dirprefix}com32/chain/chain.c32 . |
| 3557 | mvscip-shell system . . mv. -f syslinux-${syslinux_ver}/${dirprefix}win32/syslinux.exe . |
| 3558 | mvscip-shell system . . mv. -f syslinux-${syslinux_ver}/${dirprefix}win64/syslinux64.exe . |
| 3559 | mvscip-shell system . . mv. -f syslinux-${syslinux_ver}/${dirprefix}mbr/mbr.bin . |
| 3560 | mvscip-shell system . . mv. -f syslinux-${syslinux_ver}/${dirprefix}linux/syslinux . |
| 3561 | mvscip-shell system . . mv. -f syslinux-${syslinux_ver}/${dirprefix}extlinux/extlinux . |
| 3562 | mvscip-shell system . . mv. -f syslinux-${syslinux_ver}/${dirprefix}core/isolinux.bin . |
| 3563 | mvscip-shell system . . mv. -f syslinux-${syslinux_ver}/${dirprefix}memdisk/memdisk . |
| 3564 | if [scip-shell system . . `[`. -n "$syslinux_extra_c32" ]; then |
| 3565 | mvscip-shell system . . mv. -f syslinux-${syslinux_ver}/${dirprefix}com32/elflink/ldlinux/ldlinux.c32 . |
| 3566 | mvscip-shell system . . mv. -f syslinux-${syslinux_ver}/${dirprefix}com32/lib/libcom32.c32 . |
| 3567 | mvscip-shell system . . mv. -f syslinux-${syslinux_ver}/${dirprefix}com32/libutil/libutil.c32 . |
| 3568 | chmodscip-shell system . . chmod. 644 *.c32 |
| 3569 | fi |
| 3570 | ) |
| 3571 | # For EFI machine |
| 3572 | if [scip-shell system . . `[`. "$live_efi_boot_loader" = "syslinux" ]; then |
| 3573 | if [scip-shell system . . `[`. -n "$dirprefix" ]; then |
| 3574 | # This means the downloaded syslinux support EFI (for version >=6.01), then we should prepare that, too. Here we only add efi64, since efi32 is not very common for modern machine. |
| 3575 | # Ref: http://www.rodsbooks.com/efi-bootloaders/syslinux.html especially the tarball http://www.rodsbooks.com/efi-bootloaders/syslinux-6.01.pre5-1.tgz |
| 3576 | syslinux_efi_coms="menu.c32 vesamenu.c32 ldlinux.c32 chain.c32 libutil.c32 libcom32.c32" |
| 3577 | # ./efi64/efi/syslinux.efi -> bootx64.efi |
| 3578 | # ./efi64/com32/elflink/ldlinux/ldlinux.e64 |
| 3579 | mkdirscip-shell system . . mkdir. -p $sysl_dir/efi/ |
| 3580 | ( |
| 3581 | cd $sysl_dir/efi/ |
| 3582 | tarscip-shell system . . tar. --wildcards -xvJf ../syslinux-${syslinux_ver}.tar.xz \ |
| 3583 | syslinux-${syslinux_ver}/efi64/efi/syslinux.efi \ |
| 3584 | syslinux-${syslinux_ver}/efi64/com32/elflink/ldlinux/ldlinux.e64 \ |
| 3585 | syslinux-${syslinux_ver}/efi64/com32/menu/menu.c32 \ |
| 3586 | syslinux-${syslinux_ver}/efi64/com32/menu/vesamenu.c32 \ |
| 3587 | syslinux-${syslinux_ver}/efi64/com32/chain/chain.c32 \ |
| 3588 | syslinux-${syslinux_ver}/efi64/com32/lib/libcom32.c32 \ |
| 3589 | syslinux-${syslinux_ver}/efi64/com32/libutil/libutil.c32 |
| 3590 | |
| 3591 | mvscip-shell system . . mv. -f syslinux-${syslinux_ver}/efi64/efi/syslinux.efi bootx64.efi |
| 3592 | mvscip-shell system . . mv. -f syslinux-${syslinux_ver}/efi64/com32/elflink/ldlinux/ldlinux.e64 . |
| 3593 | mvscip-shell system . . mv. -f syslinux-${syslinux_ver}/efi64/com32/menu/menu.c32 . |
| 3594 | mvscip-shell system . . mv. -f syslinux-${syslinux_ver}/efi64/com32/menu/vesamenu.c32 . |
| 3595 | mvscip-shell system . . mv. -f syslinux-${syslinux_ver}/efi64/com32/chain/chain.c32 . |
| 3596 | mvscip-shell system . . mv. -f syslinux-${syslinux_ver}/efi64/com32/lib/libcom32.c32 . |
| 3597 | mvscip-shell system . . mv. -f syslinux-${syslinux_ver}/efi64/com32/libutil/libutil.c32 . |
| 3598 | chmodscip-shell system . . chmod. 644 ldlinux.e64 *.c32 |
| 3599 | ) |
| 3600 | fi |
| 3601 | fi |
| 3602 | } # end of get_syslinux_binary_for_dos_linux |
| 3603 | # |
| 3604 | put_syslinux_makeboot_for_usb_flashscip-shell shell shell-project 0.0.0 put_syslinux_makeboot_for_usb_flash().() { |
| 3605 | local t_dir="$1" |
| 3606 | # syslinux_ver is not required. If it's not assigned, the latest one on the web will be used. |
| 3607 | local syslinux_ver="$2" |
| 3608 | local sysl_dir sysl_extra_c32_chklist |
| 3609 | local latest_syslinux_v apt_tmpdir |
| 3610 | sysl_extra_c32_chklist="ldlinux.c32 libcom32.c32 libutil.c32" |
| 3611 | [scip-shell system . . `[`. -z "$t_dir" -o ! -d "$t_dir" ] && echoscip-shell system . . echo. "No t_dir!" && exit 1 |
| 3612 | # Function to put syslinux.exe and syslinux (linux ELF 32-bit LSB executable) in dir t_dir |
| 3613 | mkdirscip-shell system . . mkdir. -p $t_dir/utils/{linux,win32,win64,mbr} |
| 3614 | mkdirscip-shell system . . mkdir. -p $t_dir/utils/linux/{x86,x64} |
| 3615 | cpscip-shell system . . cp. -a $pxelinux_binsrc_dir/makeboot.sh $t_dir/utils/linux/ |
| 3616 | cpscip-shell system . . cp. -a $pxelinux_binsrc_dir/makeboot.bat $t_dir/utils/win32/ |
| 3617 | cpscip-shell system . . cp. -a $pxelinux_binsrc_dir/makeboot64.cmd $t_dir/utils/win64/ |
| 3618 | sysl_dir="$(mktempscip-shell system . . mktemp. -d /tmp/sysl_dir.XXXXXXscip-shell filesystem . . `/tmp/sysl_dir.XXXXXX`.)" |
| 3619 | get_syslinux_binary_for_dos_linuxscip-shell shell shell-project 0.0.0 get_syslinux_binary_for_dos_linux(). $sysl_dir $syslinux_ver |
| 3620 | # syslinux does not provide any option to find the version number. |
| 3621 | # Try to find the version of syslinux |
| 3622 | # Use strings to find the version, the output is like: |
| 3623 | # SYSLINUX 3.71 Debian-2008-08-04 |
| 3624 | if [scip-shell system . . `[`. -z "$syslinux_ver" ]; then |
| 3625 | SYSLINUX_VER="$(LC_ALL=C stringsscip-shell system . . strings. $sysl_dir/bios/syslinux | grepscip-shell system . . grep. -iE "^SYSLINUX.*[[:digit:]]+" | awkscip-shell system . . awk. -F" " '{print $2}')" |
| 3626 | else |
| 3627 | SYSLINUX_VER="$syslinux_ver" |
| 3628 | fi |
| 3629 | echoscip-shell system . . echo. "SYSLINUX version: $SYSLINUX_VER" > $t_dir/utils/linux/VERSION.txt |
| 3630 | cpscip-shell system . . cp. -a $t_dir/utils/linux/VERSION.txt $t_dir/utils/win32/ |
| 3631 | cpscip-shell system . . cp. -a $t_dir/utils/linux/VERSION.txt $t_dir/utils/win64/ |
| 3632 | echoscip-shell system . . echo. "Precompiled binary syslinux files were extracted from $syslinux_binsrc_url/syslinux-${syslinux_ver}.tar.xz" > $t_dir/utils/README.txt |
| 3633 | # For BIOS machine |
| 3634 | cpscip-shell system . . cp. -af $sysl_dir/bios/{isolinux.bin,memdisk,menu.c32,vesamenu.c32,chain.c32} $t_dir/syslinux/ |
| 3635 | # To make the version consistent, put them to isolinux dir, too. |
| 3636 | # Jan/19/2014 We have unified isolinux and syslinux dir as one dir syslinux only. |
| 3637 | # cp -af $sysl_dir/bios/{menu.c32,vesamenu.c32,chain.c32} $t_dir/isolinux/ |
| 3638 | cpscip-shell system . . cp. -af $sysl_dir/bios/syslinux.exe $t_dir/utils/win32/ |
| 3639 | cpscip-shell system . . cp. -af $sysl_dir/bios/syslinux64.exe $t_dir/utils/win64/ |
| 3640 | cpscip-shell system . . cp. -af $sysl_dir/bios/mbr.bin $t_dir/utils/mbr/ |
| 3641 | for i in $sysl_extra_c32_chklist; do |
| 3642 | if [scip-shell system . . `[`. -e $sysl_dir/bios/$i ]; then |
| 3643 | cpscip-shell system . . cp. -af $sysl_dir/bios/$i $t_dir/syslinux/ |
| 3644 | # To make the version consistent, put them to isolinux dir, too. |
| 3645 | # Jan/19/2014 We have unified isolinux and syslinux dir as one dir syslinux only. |
| 3646 | # cp -af $sysl_dir/bios/$i $t_dir/isolinux/ |
| 3647 | fi |
| 3648 | done |
| 3649 | if [scip-shell system . . `[`. -n "$(LC_ALL=C filescip-shell system . . file. $sysl_dir/bios/syslinux | grepscip-shell system . . grep. -iEwo "ELF 32-bit")" ]; then |
| 3650 | cpscip-shell system . . cp. -af $sysl_dir/bios/{syslinux,extlinux} $t_dir/utils/linux/x86 |
| 3651 | else |
| 3652 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 3653 | echoscip-shell system . . echo. "32-bit syslinux and extlinux not found!" |
| 3654 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 3655 | fi |
| 3656 | if [scip-shell system . . `[`. -n "$(LC_ALL=C filescip-shell system . . file. /usr/bin/syslinuxscip-shell filesystem . . `/usr/bin/syslinux`. | grepscip-shell system . . grep. -iEwo "ELF 64-bit")" ]; then |
| 3657 | # If it's Debian, use better way to get the right version of syslinux and extlinux, and overwrite the ones from syslinux zip file |
| 3658 | check_distribution_namescip-shell shell shell-project 0.0.0 check_distribution_name(). |
| 3659 | if [scip-shell system . . `[`. "$OS_type" = "DBN" ]; then |
| 3660 | # latest_syslinux_v is like: 3:6.03+dfsg-14.1+deb9u1 |
| 3661 | apt-getscip-shell system . . apt-get. update |
| 3662 | latest_syslinux_v="$(LC_ALL=C apt-cachescip-shell system . . apt-cache. show syslinux | grepscip-shell system . . grep. -iE "^Version:" | grepscip-shell system . . grep. -Ew "${SYSLINUX_VER}" | sortscip-shell system . . sort. -V -r | headscip-shell system . . head. -n 1 | awkscip-shell system . . awk. -F" " '{print $2}')" |
| 3663 | |
| 3664 | apt_tmpdir="$(mktempscip-shell system . . mktemp. -d /tmp/apt_deb.XXXXXXscip-shell filesystem . . `/tmp/apt_deb.XXXXXX`.)" |
| 3665 | ( |
| 3666 | cd $apt_tmpdir |
| 3667 | apt-getscip-shell system . . apt-get. download syslinux:amd64=${latest_syslinux_v} syslinux-common:amd64=${latest_syslinux_v} extlinux:amd64=${latest_syslinux_v=} isolinux:amd64=${latest_syslinux_v=} |
| 3668 | # apt-get download syslinux:amd64 syslinux-common:amd64 extlinux:amd64 isolinux:amd64 |
| 3669 | for ideb in $apt_tmpdir/*.deb; do |
| 3670 | dpkgscip-shell system . . dpkg. -x $ideb $apt_tmpdir/ |
| 3671 | done |
| 3672 | ) |
| 3673 | cpscip-shell system . . cp. -avf $apt_tmpdir/usr/bin/{syslinux,extlinux} $t_dir/utils/linux/x64/ |
| 3674 | cpscip-shell system . . cp. -avf $apt_tmpdir/usr/lib/syslinux/memdisk $t_dir/syslinux/ |
| 3675 | cpscip-shell system . . cp. -avf $apt_tmpdir/usr/lib/ISOLINUX/isolinux.bin $t_dir/syslinux/ |
| 3676 | cpscip-shell system . . cp. -avf $apt_tmpdir/usr/lib/syslinux/mbr/mbr.bin $t_dir/utils/mbr/ |
| 3677 | c32_mod="chain.c32 ldlinux.c32 libcom32.c32 libutil.c32 menu.c32 vesamenu.c32" |
| 3678 | for i in $c32_mod; do |
| 3679 | cpscip-shell system . . cp. -avf $apt_tmpdir/usr/lib/syslinux/modules/bios/$i $t_dir/syslinux/ |
| 3680 | done |
| 3681 | if [scip-shell system . . `[`. -n "$(echoscip-shell system . . echo. $apt_tmpdir | grepscip-shell system . . grep. -Ew "apt_deb")" ]; then |
| 3682 | rmscip-shell system . . rm. -rf $apt_tmpdir |
| 3683 | fi |
| 3684 | ( |
| 3685 | mkdirscip-shell system . . mkdir. $apt_tmpdir; cd $apt_tmpdir |
| 3686 | # apt-get download syslinux:i386=${latest_syslinux_v} extlinux:i386=${latest_syslinux_v=} |
| 3687 | apt-getscip-shell system . . apt-get. download syslinux:i386 extlinux:i386 |
| 3688 | for ideb in $apt_tmpdir/*.deb; do |
| 3689 | dpkgscip-shell system . . dpkg. -x $ideb $apt_tmpdir/ |
| 3690 | done |
| 3691 | ) |
| 3692 | # Only /usr/bin/{syslinux,extlinux}, for those *.c32 and other files, use those from amd64 deb. |
| 3693 | cpscip-shell system . . cp. -avf $apt_tmpdir/usr/bin/{syslinux,extlinux} $t_dir/utils/linux/x86/ |
| 3694 | else |
| 3695 | # Using the one from running AMD64 GNU/Linux. However, this might be different version from the downloaded syslinux zip file. |
| 3696 | cpscip-shell system . . cp. -af /usr/bin/{syslinux,extlinux}scip-shell filesystem . . `/usr/bin/{syslinux,extlinux}`. $t_dir/utils/linux/x64 |
| 3697 | fi |
| 3698 | else |
| 3699 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 3700 | echoscip-shell system . . echo. "64-bit syslinux and extlinux not found in the dir /usr/bin/!" |
| 3701 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 3702 | fi |
| 3703 | # For EFI machine |
| 3704 | if [scip-shell system . . `[`. "$live_efi_boot_loader" = "syslinux" ]; then |
| 3705 | if [scip-shell system . . `[`. -d "$sysl_dir/efi" ]; then |
| 3706 | mkdirscip-shell system . . mkdir. -p $t_dir/EFI/boot/ |
| 3707 | cpscip-shell system . . cp. -af $sysl_dir/efi/bootx64.efi $t_dir/EFI/boot/ |
| 3708 | cpscip-shell system . . cp. -af $sysl_dir/efi/ldlinux.e64 $t_dir/EFI/boot/ |
| 3709 | cpscip-shell system . . cp. -af $sysl_dir/efi/*.c32 $t_dir/EFI/boot/ |
| 3710 | fi |
| 3711 | fi |
| 3712 | [scip-shell system . . `[`. -d "$sysl_dir" -a -n "$(echoscip-shell system . . echo. $sysl_dir | grepscip-shell system . . grep. "sysl_dir")" ] && rmscip-shell system . . rm. -rf $sysl_dir |
| 3713 | } # end of put_syslinux_makeboot_for_usb_flash |
| 3714 | # |
| 3715 | create_live_required_debian_based_promptscip-shell shell shell-project 0.0.0 create_live_required_debian_based_prompt().() { |
| 3716 | # lh_ver_required is global varible from drbl-ocs.conf |
| 3717 | local lh_ver debootstrap_ver |
| 3718 | # live-helper package name was changed to be live-build after 2.0~a20 |
| 3719 | lh_ver="$(LC_ALL=C dpkg-queryscip-shell system . . dpkg-query. -W -f='${Version}\n' live-build)" |
| 3720 | if [scip-shell system . . `[`. -z "$lh_ver" ]; then |
| 3721 | # Try to find the old package name. |
| 3722 | lh_ver="$(LC_ALL=C dpkg-queryscip-shell system . . dpkg-query. -W -f='${Version}\n' live-helper)" |
| 3723 | fi |
| 3724 | debootstrap_ver="$(LC_ALL=C debootstrap --version | grepscip-shell system . . grep. -iEw "^debootstrap" | awkscip-shell system . . awk. -F" " '{print $2}')" |
| 3725 | mmdebstrap_ver="$(LC_ALL=C mmdebstrapscip-shell system . . mmdebstrap. --version | grepscip-shell system . . grep. -iEw "^mmdebstrap" | awkscip-shell system . . awk. -F" " '{print $2}')" |
| 3726 | if dpkgscip-shell system . . dpkg. --compare-versions "$lh_ver" "<<" "$lh_ver_required"; then |
| 3727 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE |
| 3728 | echoscip-shell system . . echo. "Required live helper or live build version: $lh_ver_required" |
| 3729 | echoscip-shell system . . echo. "Installed live helper or live build version: $lh_ver" |
| 3730 | echoscip-shell system . . echo. "You have to install patched live-helper or live-build (${lh_ver_required}drbl or later, modified by DRBL project)" |
| 3731 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 3732 | echoscip-shell system . . echo. "Program terminated!" |
| 3733 | exit 1 |
| 3734 | fi |
| 3735 | if dpkgscip-shell system . . dpkg. --compare-versions "$debootstrap_ver" "<<" "$debootstrap_ver_required"; then |
| 3736 | if dpkgscip-shell system . . dpkg. --compare-versions "$mmdebstrap_ver" "<<" "$mmdebstrap_ver_required"; then |
| 3737 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE |
| 3738 | echoscip-shell system . . echo. "Required debootstrap version: $debootstrap_ver_required" |
| 3739 | echoscip-shell system . . echo. "Installed debootstrap version: $debootstrap_ver" |
| 3740 | echoscip-shell system . . echo. "Required mmdebstrap version: $mmdebstrap_ver_required" |
| 3741 | echoscip-shell system . . echo. "Installed mmdebstrap version: $mmdebstrap_ver" |
| 3742 | echoscip-shell system . . echo. "You have to install debootstrap (version $debootstrap_ver_required or later) or mmdebstrap (verion $mmdebstrap_ver_required or later)." |
| 3743 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 3744 | echoscip-shell system . . echo. "Program terminated!" |
| 3745 | exit 1 |
| 3746 | fi |
| 3747 | fi |
| 3748 | if [scip-shell system . . `[`. "$batch_mode" = "no" ]; then |
| 3749 | echoscip-shell system . . echo. -n "Press enter to continue... " |
| 3750 | read |
| 3751 | fi |
| 3752 | } # End of create_live_required_debian_based_prompt |
| 3753 | # |
| 3754 | turn_on_ipv4_forwardscip-shell shell shell-project 0.0.0 turn_on_ipv4_forward().() { |
| 3755 | # Making the rules stick and load on boot: |
| 3756 | if grepscip-shell system . . grep. -q "^net.ipv4.ip_forward" /etc/sysctl.confscip-shell filesystem . . `/etc/sysctl.conf`. 2>/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 3757 | perlscip-shell system . . perl. -p -i -e "s/^net.ipv4.ip_forward.*/net.ipv4.ip_forward = 1/" /etc/sysctl.confscip-shell filesystem . . `/etc/sysctl.conf`. |
| 3758 | else |
| 3759 | echoscip-shell system . . echo. "net.ipv4.ip_forward = 1" >> /etc/sysctl.confscip-shell filesystem . . `/etc/sysctl.conf`. |
| 3760 | fi |
| 3761 | # Turn on ip_forward now. |
| 3762 | if [scip-shell system . . `[`. "$(catscip-shell system . . cat. /proc/sys/net/ipv4/ip_forwardscip-shell filesystem . . `/proc/sys/net/ipv4/ip_forward`.)" != "1" ]; then |
| 3763 | echoscip-shell system . . echo. "Turn on ip_forward now." |
| 3764 | echoscip-shell system . . echo. 1 > /proc/sys/net/ipv4/ip_forwardscip-shell filesystem . . `/proc/sys/net/ipv4/ip_forward`. |
| 3765 | else |
| 3766 | echoscip-shell system . . echo. "ip_forward is already on." |
| 3767 | fi |
| 3768 | } # end of turn_on_ipv4_forward |
| 3769 | # |
| 3770 | ask_if_beginner_or_expert_modescip-shell shell shell-project 0.0.0 ask_if_beginner_or_expert_mode().(){ |
| 3771 | local TMP mode |
| 3772 | # ocs_user_mode is global variable |
| 3773 | TMP="$(mktempscip-shell system . . mktemp. /tmp/menu-ocs.XXXXXXscip-shell filesystem . . `/tmp/menu-ocs.XXXXXX`.)" |
| 3774 | trap "[ -f "$TMP" ] && rm -f $TMP" HUP INT QUIT TERM EXIT |
| 3775 | $DIA --backtitle "$msg_nchc_free_software_labs" --title \ |
| 3776 | "$msg_nchc_clonezilla" --menu "$msg_select_beginner_or_expert_mode:" \ |
| 3777 | 0 0 0 \ |
| 3778 | "Beginner" "$msg_beginner_mode" \ |
| 3779 | "Expert" "$msg_expert_mode" \ |
| 3780 | "Exit" "$msg_exit. $msg_enter_cml" \ |
| 3781 | 2> $TMP |
| 3782 | mode="$(catscip-shell system . . cat. $TMP)" |
| 3783 | [scip-shell system . . `[`. -e "$TMP" ] && rmscip-shell system . . rm. -f $TMP |
| 3784 | case "$mode" in |
| 3785 | "Beginner") ocs_user_mode="beginner" ;; |
| 3786 | "Expert") ocs_user_mode="expert" ;; |
| 3787 | *) |
| 3788 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE |
| 3789 | echoscip-shell system . . echo. "$msg_program_stop!" |
| 3790 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 3791 | exit 1 |
| 3792 | esac |
| 3793 | } # end of ask_if_beginner_or_expert_mode |
| 3794 | # |
| 3795 | rep_whspc_w_udrscscip-shell shell shell-project 0.0.0 rep_whspc_w_udrsc().() { |
| 3796 | # Function to replace white space as "_", so in dialog we won't make it as 2 or more tags or items. |
| 3797 | local inp_txt="$1" |
| 3798 | local out_txt |
| 3799 | out_txt="$(echoscip-shell system . . echo. ${inp_txt} | sedscip-shell system . . sed. -r -e "s/[[:space:]]/_/g")" |
| 3800 | echoscip-shell system . . echo. "$out_txt" |
| 3801 | } # end of rep_whspc_w_udrsc |
| 3802 | # |
| 3803 | # Function copy_exec_drbl is borrowed from copy_exec from Debian's package initramfs-tools: /usr/share/initramfs-tools/hook-functions. The difference is that we use "cp -pL" instead of "ln -fs" in this function. This is because when we run mkpxeinitrd-net, we run cpio without "--dereference" (mkinitramfs uses cpio with "--dereference"), i.e. in mkpxeinitrd-net, we use: |
| 3804 | # find . | cpio --quiet -o -H newc | gzip -9 > $output_dir/initrd-$initrd_suffix.$kernel_ver.img ) |
| 3805 | # instead of |
| 3806 | # find . | cpio --quiet --dereference -o -H newc | gzip -9 > $output_dir/initrd-$initrd_suffix.$kernel_ver.img ) |
| 3807 | # The reason to do so is we use symbolic link to link the command to busybox in/usr/lib/mkpxeinitrd-net/initrd-skel/bin/. If we use --dereference, it will take a lot of space. This might be improved in the future. |
| 3808 | |
| 3809 | # $1 is the source path (e.g. /usr/bin/time) |
| 3810 | # $2 is the relative destination (e.g. /usr or /usr/time) |
| 3811 | # |
| 3812 | # The destination is interpreted in the same way "cp" would, meaning |
| 3813 | # (assuming /bin is a directory): |
| 3814 | # |
| 3815 | # "copy_exec_drbl /usr/bin/time /bin" -> /bin/time |
| 3816 | # "copy_exec_drbl /usr/bin/time /bin/mytime" -> /bin/mytime |
| 3817 | # |
| 3818 | # If $2 is left out, the same destination path as for the source arg will |
| 3819 | # be used and directories will be created as needed, so: |
| 3820 | # |
| 3821 | # "copy_exec_drbl /usr/bin/time" -> /usr/bin/time |
| 3822 | # |
| 3823 | copy_exec_drblscip-shell shell shell-project 0.0.0 copy_exec_drbl().() { |
| 3824 | local source target destination final_destination x nonoptlib |
| 3825 | local libname dirname |
| 3826 | |
| 3827 | source="${1}" |
| 3828 | if [scip-shell system . . `[`. -n "${2}" ]; then |
| 3829 | if [scip-shell system . . `[`. ! -d "${DESTDIR}/${2}" ]; then |
| 3830 | mkdirscip-shell system . . mkdir. -p "${DESTDIR}/${2}" |
| 3831 | fi |
| 3832 | target="${2}" |
| 3833 | else |
| 3834 | if [scip-shell system . . `[`. ! -e "${DESTDIR}/$(dirnamescip-shell system . . dirname. "${1}")" ]; then |
| 3835 | mkdirscip-shell system . . mkdir. -p "${DESTDIR}/$(dirnamescip-shell system . . dirname. "${1}")" |
| 3836 | fi |
| 3837 | target="${1}" |
| 3838 | fi |
| 3839 | |
| 3840 | if [scip-shell system . . `[`. -d "${DESTDIR}/${target}" ]; then |
| 3841 | destination="${target}/$(basenamescip-shell system . . basename. "${source}")" |
| 3842 | else |
| 3843 | destination="${target}" |
| 3844 | fi |
| 3845 | final_destination="${DESTDIR}/${destination}" |
| 3846 | |
| 3847 | if [scip-shell system . . `[`. -L "$final_destination" ]; then |
| 3848 | if [scip-shell system . . `[`. $(readlinkscip-shell system . . readlink. "${final_destination}") != "${source}" ]; then |
| 3849 | # echo "W:copy_exec_drbl: Not copying ${source} to \$DESTDIR${destination}, which is already a copy of $(readlink ${final_destination})" >&2 |
| 3850 | return |
| 3851 | fi |
| 3852 | else |
| 3853 | cpscip-shell system . . cp. -pL ${source} ${DESTDIR}/${destination} |
| 3854 | if [scip-shell system . . `[`. "${verbose}" = "y" ]; then |
| 3855 | echoscip-shell system . . echo. "Adding binary ${source}" |
| 3856 | fi |
| 3857 | fi |
| 3858 | |
| 3859 | # Copy the dependant libraries |
| 3860 | for x in $(lddscip-shell system . . ldd. ${source} 2>/dev/nullscip-shell filesystem . . `/dev/null`. | sedscip-shell system . . sed. -e ' |
| 3861 | /\//!d; |
| 3862 | /linux-gate/d; |
| 3863 | /=>/ {s/.*=>[[:blank:]]*\([^[:blank:]]*\).*/\1/}; |
| 3864 | s/[[:blank:]]*\([^[:blank:]]*\) (.*)/\1/' 2>/dev/nullscip-shell filesystem . . `/dev/null`.); do |
| 3865 | |
| 3866 | # Try to use non-optimised libraries where possible. |
| 3867 | # We assume that all HWCAP libraries will be in tls, |
| 3868 | # sse2, vfp or neon |
| 3869 | nonoptlib=$(echoscip-shell system . . echo. "${x}" | sedscip-shell system . . sed. -e 's#/lib/\(tls\|i686\|sse2\|neon\|vfp\).*/\(lib.*\)#/lib/\2#') |
| 3870 | |
| 3871 | if [scip-shell system . . `[`. -e "${nonoptlib}" ]; then |
| 3872 | x="${nonoptlib}" |
| 3873 | fi |
| 3874 | |
| 3875 | libname=$(basenamescip-shell system . . basename. "${x}") |
| 3876 | dirname=$(dirnamescip-shell system . . dirname. "${x}") |
| 3877 | |
| 3878 | mkdirscip-shell system . . mkdir. -p "${DESTDIR}/${dirname}" |
| 3879 | if [scip-shell system . . `[`. ! -e "${DESTDIR}/${dirname}/${libname}" ]; then |
| 3880 | cpscip-shell system . . cp. -pL "${x}" "${DESTDIR}/${dirname}" |
| 3881 | if [scip-shell system . . `[`. "${verbose}" = "y" ]; then |
| 3882 | echoscip-shell system . . echo. "Adding library ${x}" |
| 3883 | fi |
| 3884 | fi |
| 3885 | done |
| 3886 | } # end of copy_exec_drbl |
| 3887 | # |
| 3888 | get_block_line_in_upstart_confscip-shell shell shell-project 0.0.0 get_block_line_in_upstart_conf().() { |
| 3889 | local CFG_FILE="$1" |
| 3890 | local comment_status="$2" |
| 3891 | local comment |
| 3892 | [scip-shell system . . `[`. -e "$CFG_FILE" ] || exit 1 |
| 3893 | # There are 2 types of init config: |
| 3894 | # (1) |
| 3895 | # start on filesystem |
| 3896 | # (2) |
| 3897 | # start on (local-filesystems |
| 3898 | # and net-device-up IFACE=lo) |
| 3899 | # Wen can judge them by: grep -n -E "^start on[[:space:]]+\(" $CFG_FILE |
| 3900 | # Take /etc/init/gdm.conf as an example: |
| 3901 | # start on (filesystem |
| 3902 | # and started hal |
| 3903 | # and tty-device-added KERNEL=tty7 |
| 3904 | # and (graphics-device-added or stopped udevtrigger)) |
| 3905 | # By using: |
| 3906 | # grep -n -E "^start on[[:space:]]+\(" gdm.conf |
| 3907 | # We can get the results like: |
| 3908 | # ------------ |
| 3909 | # 9:start on (filesystem |
| 3910 | # ------------ |
| 3911 | # grep -n -E -A 1000 "^start on[[:space:]]+\(" gdm.conf | grep -E "\)" | head -n 1 |
| 3912 | # We can get the results like: |
| 3913 | # ------------ |
| 3914 | # 12- and (graphics-device-added or stopped udevtrigger)) |
| 3915 | # ------------ |
| 3916 | # so we know we can replace the one between line no. 9 and 12 |
| 3917 | if [scip-shell system . . `[`. "$comment_status" = "commented" ]; then |
| 3918 | comment="#" |
| 3919 | else |
| 3920 | comment="" |
| 3921 | fi |
| 3922 | if [scip-shell system . . `[`. -z "$(LC_ALL=C grepscip-shell system . . grep. -n -E "^${comment}[[:space:]]*start on[[:space:]]+\(" $CFG_FILE)" ]; then |
| 3923 | # Type 1 |
| 3924 | begin_line="$(LC_ALL=C grepscip-shell system . . grep. -n -E "^${comment}[[:space:]]*start on[[:space:]]+" $CFG_FILE | cutscip-shell system . . cut. -d":" -f1)" |
| 3925 | end_line="${begin_line}" |
| 3926 | else |
| 3927 | # Type 2 |
| 3928 | begin_line="$(LC_ALL=C grepscip-shell system . . grep. -n -E "^${comment}[[:space:]]*start on[[:space:]]+\(" $CFG_FILE | cutscip-shell system . . cut. -d":" -f1)" |
| 3929 | end_line="$(LC_ALL=C grepscip-shell system . . grep. -n -E -A 1000 "^${comment}[[:space:]]*start on[[:space:]]+\(" $CFG_FILE | grepscip-shell system . . grep. -E "\)" | headscip-shell system . . head. -n 1 | cutscip-shell system . . cut. -d "-" -f1)" |
| 3930 | fi |
| 3931 | echoscip-shell system . . echo. "$begin_line $end_line" |
| 3932 | } # end of get_block_line_in_upstart_conf |
| 3933 | # |
| 3934 | switch_upstart_servicescip-shell shell shell-project 0.0.0 switch_upstart_service().() { |
| 3935 | # The function to comment or uncomment the upstart /etc/init/*.conf |
| 3936 | local CFG_F="$1" |
| 3937 | local mod_want="$2" # "on" or "off" |
| 3938 | [scip-shell system . . `[`. -z "$CFG_F" ] && "No 'CFG_F' assigned in function switch_upstart_service!" && exit 1 |
| 3939 | [scip-shell system . . `[`. -z "$mod_want" ] && "No 'mod_want' assigned in function switch_upstart_service!" && exit 1 |
| 3940 | [scip-shell system . . `[`. -e /etc/lsb-releasescip-shell filesystem . . `/etc/lsb-release`. ] && . /etc/lsb-releasescip-shell source . . `/etc/lsb-release`. |
| 3941 | if [scip-shell system . . `[`. "$DISTRIB_RELEASE" \< 13.10 ]; then |
| 3942 | # Ubuntu < 13.10 |
| 3943 | # # Just edit the config file directly, so that it's could only be started manually. We can NOT just rename the *.conf. Otherwise the service can not be started manually in drbl-client-boot.conf. |
| 3944 | # If we want to turn on the service, the status now should be commented. |
| 3945 | case "$mod_want" in |
| 3946 | on) status="commented";; |
| 3947 | off) status="not_commented";; |
| 3948 | esac |
| 3949 | lines="$(get_block_line_in_upstart_confscip-shell shell shell-project 0.0.0 get_block_line_in_upstart_conf(). $CFG_F $status)" |
| 3950 | begin_line="$(echoscip-shell system . . echo. $lines | awkscip-shell system . . awk. -F" " '{print $1}')" |
| 3951 | end_line="$(echoscip-shell system . . echo. $lines | awkscip-shell system . . awk. -F" " '{print $2}')" |
| 3952 | case "$mod_want" in |
| 3953 | off) sub_cmd="if ($((begin_line))..$((end_line))) {s/^(.*)$/# \$1 # Modified by DRBL/g}" ;; |
| 3954 | on) sub_cmd="if ($((begin_line))..$((end_line))) {s/^#[[:space:]]?(.*)$/\$1/g}" ;; |
| 3955 | esac |
| 3956 | perlscip-shell system . . perl. -pi -e "$sub_cmd" $CFG_F |
| 3957 | |
| 3958 | # XXXXXXXXXXXXXXXXXXX This is wrong! If doing this, some required service could not be manually started in drbl-client-boot.conf. |
| 3959 | #case "$mod_want" in |
| 3960 | # off) |
| 3961 | # if [ -e "${CFG_F}" ]; then |
| 3962 | # mv ${CFG_F} ${CFG_F}.drbl-disabled |
| 3963 | # fi |
| 3964 | # ;; |
| 3965 | # on) |
| 3966 | # if [ -e "${CFG_F}.drbl-disabled" ]; then |
| 3967 | # mv ${CFG_F}.drbl-disabled ${CFG_F} |
| 3968 | # fi |
| 3969 | # ;; |
| 3970 | #esac |
| 3971 | else |
| 3972 | # Ubuntu 13.10 or later. |
| 3973 | # For upstart (>1.3) service, we can use override file (Ref: http://upstart.ubuntu.com/cookbook/#override-files) |
| 3974 | case "$mod_want" in |
| 3975 | off) echoscip-shell system . . echo. "manual" > ${CFG_F/.conf/}.override;; |
| 3976 | on) rmscip-shell system . . rm. -f ${CFG_F/.conf/}.override;; |
| 3977 | esac |
| 3978 | fi |
| 3979 | } # end of switch_upstart_service |
| 3980 | # |
| 3981 | canonical_hostname_prepscip-shell shell shell-project 0.0.0 canonical_hostname_prep().() { |
| 3982 | # This function is used to avoid the bug of nfs-utils 1.2.2-1: |
| 3983 | # statd wont't work without reverse lookups. Therefore lockd will fail. |
| 3984 | # Ref: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=579397 |
| 3985 | # The problem is not only on the server side, but also on the client side. |
| 3986 | local nfs_srv="$1" |
| 3987 | if ! host "$nfs_srv" &>/dev/nullscip-shell filesystem . . `/dev/null`. && \ |
| 3988 | [ -z "$(LC_ALL=C grepscip-shell system . . grep. -Ew "^[[:space:]]*$nfs_srv" /etc/hostsscip-shell filesystem . . `/etc/hosts`. )" ]; then |
| 3989 | echoscip-shell system . . echo. "# Dummy NFS server lookup to avoid NFS statd/lockd issue. Created by Clonezilla." >> /etc/hostsscip-shell filesystem . . `/etc/hosts`. |
| 3990 | echoscip-shell system . . echo. "$nfs_srv nfs-server" >> /etc/hostsscip-shell filesystem . . `/etc/hosts`. |
| 3991 | fi |
| 3992 | } # end of canonical_hostname_prep |
| 3993 | # |
| 3994 | get_debian_ubuntu_init_serv_control_progscip-shell shell shell-project 0.0.0 get_debian_ubuntu_init_serv_control_prog().() { |
| 3995 | # Find to use update-rc.d or insserv in Debian or Ubuntu |
| 3996 | # dbn_ubn_serv_control_prog is global value |
| 3997 | [scip-shell system . . `[`. -e /etc/lsb-releasescip-shell filesystem . . `/etc/lsb-release`. ] && . /etc/lsb-releasescip-shell source . . `/etc/lsb-release`. |
| 3998 | dbn_ubn_serv_control_prog="" |
| 3999 | if [scip-shell system . . `[`. "$DISTRIB_ID" = "Ubuntu" ]; then |
| 4000 | # Ubuntu, do not use insserv, otherwise it might confuse upstart and traditional rc |
| 4001 | dbn_ubn_serv_control_prog="use-update-rc-d" |
| 4002 | else |
| 4003 | # Debian, we check if insserv exists or not. |
| 4004 | if type insserv &>/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 4005 | dbn_ubn_serv_control_prog="use-insserv" |
| 4006 | else |
| 4007 | dbn_ubn_serv_control_prog="use-update-rc-d" |
| 4008 | fi |
| 4009 | fi |
| 4010 | } # end of get_debian_ubuntu_init_serv_control_prog |
| 4011 | # |
| 4012 | get_sort_V_optscip-shell shell shell-project 0.0.0 get_sort_V_opt().() { |
| 4013 | # A function to get if the "-V" option is supported on the system. This is because old version of sort does not support the option "-V", but newer one does. |
| 4014 | # Variable "sort_V_opt" is global variable. |
| 4015 | if [scip-shell system . . `[`. -n "$(LC_ALL=C sortscip-shell system . . sort. --help 2>&1 | grepscip-shell system . . grep. -i -- "--version-sort")" ]; then |
| 4016 | # Check if version sorting option is supported. If so, use it. |
| 4017 | sort_V_opt="-V" |
| 4018 | fi |
| 4019 | } # get_sort_V_opt |
| 4020 | # |
| 4021 | disable_apt_lang_translationscip-shell shell shell-project 0.0.0 disable_apt_lang_translation().() { |
| 4022 | local lang_cf_file="$1" # e.g. chroot/etc/apt/apt.conf.d/99lang |
| 4023 | if [scip-shell system . . `[`. -z "$lang_cf_file" ]; then |
| 4024 | echoscip-shell system . . echo. "No \"lang_cf_file\" in function disable_apt_lang_translation!" |
| 4025 | exit 1 |
| 4026 | fi |
| 4027 | mkdirscip-shell system . . mkdir. -p $(dirnamescip-shell system . . dirname. $lang_cf_file) |
| 4028 | catscip-shell system . . cat. <<-APT_END > $lang_cf_file |
| 4029 | Acquire |
| 4030 | { |
| 4031 | Retries "0"; |
| 4032 | Languages "none"; |
| 4033 | Translation "none"; |
| 4034 | }; |
| 4035 | APT_END |
| 4036 | } # end of disable_apt_lang_translation |
| 4037 | # |
| 4038 | get_latest_pkg_in_drbl_repositoryscip-shell shell shell-project 0.0.0 get_latest_pkg_in_drbl_repository().() { |
| 4039 | local branch pkg ktmp |
| 4040 | # pver is global variabl |
| 4041 | branch="$1" # e.g. live-experimental, unstable... |
| 4042 | pkg="$2" # e.g. live-boot |
| 4043 | if [scip-shell system . . `[`. -z "$branch" ]; then |
| 4044 | echoscip-shell system . . echo. "No \$branch in function get_latest_pkg_in_repository!" |
| 4045 | exit 1 |
| 4046 | fi |
| 4047 | if [scip-shell system . . `[`. -z "$pkg" ]; then |
| 4048 | echoscip-shell system . . echo. "No \$pkg in function get_latest_pkg_in_repository!" |
| 4049 | exit 1 |
| 4050 | fi |
| 4051 | ktmp="$(mktempscip-shell system . . mktemp. -d /tmp/live_pver.XXXXXXscip-shell filesystem . . `/tmp/live_pver.XXXXXX`. || exit 1)" |
| 4052 | echoscip-shell system . . echo. "Downloading $drbl_mirror_url/dists/drbl/$branch/binary-amd64/Packages.xz to finding latest $pkg version..." |
| 4053 | LC_ALL=C wget -q -P $ktmp/ $drbl_mirror_url/dists/drbl/$branch/binary-amd64/Packages.xz |
| 4054 | # The versions might be with epoch like: |
| 4055 | # 4.0.2-1.drbl15 |
| 4056 | # 1:20170623.drbl1 |
| 4057 | # Hence we add all of them as: |
| 4058 | # 0:4.0.2-1.drbl15 |
| 4059 | # 1:20170623.drbl1 |
| 4060 | pver="$(xzgrepscip-shell system . . xzgrep. -Ew -A 5 "^Package: $pkg([[:space:]]+|$)" $ktmp/Packages.xz | grepscip-shell system . . grep. -E "^Version:" | sedscip-shell system . . sed. -e "s/^Version: //g" | sedscip-shell system . . sed. -r -e "s/^([^:]+)$/0:\1/g" | sortscip-shell system . . sort. -V -r | uniqscip-shell system . . uniq. | headscip-shell system . . head. -n 1)" |
| 4061 | if [scip-shell system . . `[`. -z "$pver" ]; then |
| 4062 | # Clean Packages.xz to avoid wget using another name like Packages.xz.1 then search the next again |
| 4063 | rmscip-shell system . . rm. -f $ktmp/Packages.xz |
| 4064 | return 1 |
| 4065 | fi |
| 4066 | if [scip-shell system . . `[`. -n "$pver" ]; then |
| 4067 | # After the comparison is done, we have to change it back, i.e., |
| 4068 | # 0:4.0.2-1.drbl15 -> 4.0.2-1.drbl15 |
| 4069 | pver="$(echoscip-shell system . . echo. $pver | sedscip-shell system . . sed. -r -e "s/^0://g")" |
| 4070 | else |
| 4071 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 4072 | echoscip-shell system . . echo. "Warning!" |
| 4073 | echoscip-shell system . . echo. "Unable to find the latest package version in $drbl_mirror_url/dists/$i/main/binary-amd64/Packages.xz." |
| 4074 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 4075 | echoscip-shell system . . echo. -n "$msg_press_enter_to_continue" |
| 4076 | read |
| 4077 | fi |
| 4078 | [scip-shell system . . `[`. -d "$ktmp" -a -n "$(echoscip-shell system . . echo. $ktmp | grepscip-shell system . . grep. "live_pver")" ] && rmscip-shell system . . rm. -rf $ktmp |
| 4079 | return 0 |
| 4080 | } # end of get_latest_pkg_in_drbl_repository |
| 4081 | # |
| 4082 | gen_CDG_checksumsscip-shell shell shell-project 0.0.0 gen_CDG_checksums().() { |
| 4083 | # This function will generate Clonezilla, DRBL, GParted live checksum files, including MD5SUMS, SHA1SUMS, and a file called CHECKSUMS.TXT including MD5 and SHA1 checksums. |
| 4084 | local sum_file="CHECKSUMS.TXT" |
| 4085 | local sum_file_html="CHECKSUMS.php" |
| 4086 | local filetype="iso zip tar tar.gz" |
| 4087 | local sum_types="md5sum sha1sum sha256sum sha512sum b2sum b3sum" |
| 4088 | local sum_of |
| 4089 | echoscip-shell system . . echo. -n "Creating checksums..." |
| 4090 | rmscip-shell system . . rm. -f $sum_file $sum_file_html |
| 4091 | for jsum in $sum_types; do |
| 4092 | sum_of="$(echoscip-shell system . . echo. $jsum | trscip-shell system . . tr. "[a-z]" "[A-Z]")S" # e.g. md5sum -> MD5SUMS |
| 4093 | [scip-shell system . . `[`. -e "$sum_of" ] && rmscip-shell system . . rm. -f $sum_of |
| 4094 | for i in $filetype; do |
| 4095 | if [scip-shell system . . `[`. -n "$(lsscip-shell system . . ls. *.$i 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" ]; then |
| 4096 | echoscip-shell system . . echo. -n "." |
| 4097 | LC_ALL=C $jsum *.$i >> $sum_of |
| 4098 | fi |
| 4099 | done |
| 4100 | echoscip-shell system . . echo. "### ${sum_of}:" >> $sum_file |
| 4101 | catscip-shell system . . cat. ${sum_of} >> $sum_file |
| 4102 | echoscip-shell system . . echo. >> $sum_file |
| 4103 | done |
| 4104 | echoscip-shell system . . echo. " Done!" |
| 4105 | |
| 4106 | txt2html $sum_file > $sum_file_html |
| 4107 | } # end of gen_CDG_checksums |
| 4108 | # |
| 4109 | find_next_release_version_numberscip-shell shell shell-project 0.0.0 find_next_release_version_number().() { |
| 4110 | # Function to find the next release number in dir "$release_dir". This is used only for creating Clonezilla/DRBL/GParted live. |
| 4111 | local release_dir="$1" |
| 4112 | local next_v_major next_v_minor next_v_full |
| 4113 | # Default release dir is "release" |
| 4114 | [scip-shell system . . `[`. -z "$release_dir" ] && release_dir="release" |
| 4115 | # The dirs in release dir are like: |
| 4116 | # 2.0.0-28/ |
| 4117 | # 2.0.0-29/ |
| 4118 | # 2.0.0-30/ |
| 4119 | # zip-dest/ |
| 4120 | # zip-src/ |
| 4121 | # Find the last version, i.e. 2.0.0-30 |
| 4122 | version_now="$(LC_ALL=C findscip-shell system . . find. ./$release_dir/ -maxdepth 1 -type d -print 2>/dev/nullscip-shell filesystem . . `/dev/null`. | awkscip-shell system . . awk. -F"/" '{print $3}' | grepscip-shell system . . grep. -E "^[[:digit:]].*" | sortscip-shell system . . sort. -r -V | uniqscip-shell system . . uniq. | headscip-shell system . . head. -n 1)" |
| 4123 | # Increase the minor # (i.e. 30) by 1 |
| 4124 | if [scip-shell system . . `[`. -n "$version_now" ]; then |
| 4125 | next_v_major="$(LC_ALL=C echoscip-shell system . . echo. "$version_now" | awkscip-shell system . . awk. -F "-" '{print $1}')" |
| 4126 | next_v_minor="$(LC_ALL=C echoscip-shell system . . echo. "$version_now" | awkscip-shell system . . awk. -F "-" '{print $2}')" |
| 4127 | next_v_minor="$((next_v_minor + 1))" |
| 4128 | next_v_full="$next_v_major-$next_v_minor" |
| 4129 | fi |
| 4130 | if [scip-shell system . . `[`. -n "$next_v_major" -a -n "$next_v_minor" ]; then |
| 4131 | echoscip-shell system . . echo. "$next_v_full" |
| 4132 | return 0 |
| 4133 | else |
| 4134 | return 1 |
| 4135 | fi |
| 4136 | } # end of find_next_release_version_number |
| 4137 | # |
| 4138 | restore_lvm2_udevd_rulesscip-shell shell shell-project 0.0.0 restore_lvm2_udevd_rules().() { |
| 4139 | local new_fname reload_flag=false |
| 4140 | # Restore the udevd rules, which are disabled by ocs-lvm2-stop. |
| 4141 | echoscip-shell system . . echo. "Checking if udevd rules have to be restored..." |
| 4142 | for i in /lib/udev/rules.d/*.drblsave; do |
| 4143 | [scip-shell system . . `[`. ! -e "$i" ] && continue |
| 4144 | new_fname="$(echoscip-shell system . . echo. $i | sedscip-shell system . . sed. -r -e "s/\.drblsave$//g")" |
| 4145 | mvscip-shell system . . mv. -v "$i" "$new_fname" |
| 4146 | reload_flag="true" |
| 4147 | done |
| 4148 | # Reload the rules for udevd |
| 4149 | if [scip-shell system . . `[`. "$reload_flag" = "true" ]; then |
| 4150 | echoscip-shell system . . echo. "Running 'udevadm control --reload-rules' to reload udevd rules..." |
| 4151 | udevadm control --reload-rules |
| 4152 | fi |
| 4153 | } # End of restore_lvm2_udevd_rules |
| 4154 | |
| 4155 | # |
| 4156 | disable_lvm2_udevd_rulesscip-shell shell shell-project 0.0.0 disable_lvm2_udevd_rules().() { |
| 4157 | local node_rt="$1" # E.g. /tftpboot/node_root/. If $node_rt is not assigned, it's for the running system. E.g. Clonezilla live. If assigned, it's for Clonezilla SE used normally. |
| 4158 | # 2012/Nov/20 Ubuntu's lvm2 has a udevd rules will automatically active VG, therefore before using "vgchange -an" to deactive the VG, we have to disable it, then restore it later. |
| 4159 | auto_active_rules="$(LC_ALL=C grepscip-shell system . . grep. -Ew "^[^#].*vgchange -a y" $node_rt/lib/udev/rules.d/*.rules 2>/dev/nullscip-shell filesystem . . `/dev/null`. | awkscip-shell system . . awk. -F":" '{print $1}')" |
| 4160 | if [scip-shell system . . `[`. -n "$auto_active_rules" ]; then |
| 4161 | echoscip-shell system . . echo. "Found udevd rule causes block devices with LVM signatures to be automatically added to their volume group." |
| 4162 | echoscip-shell system . . echo. "Temporarily disable it otherwise the partition tool won't be able to inform the kernel the changes of partition table..." |
| 4163 | for i in $auto_active_rules; do |
| 4164 | mvscip-shell system . . mv. -v "${i}" "${i}.drblsave" |
| 4165 | done |
| 4166 | # Reload the rules for udevd for running system, i.e. Clonezilla live. For Clonezilla SE, since it's in /tftpboot/node_root/, during the booting it won't be started. |
| 4167 | if [scip-shell system . . `[`. -z "$node_rt" ]; then |
| 4168 | udevadm control --reload-rules |
| 4169 | fi |
| 4170 | fi |
| 4171 | } # end of disable_lvm2_udevd_rules |
| 4172 | # |
| 4173 | is_systemd_initscip-shell shell shell-project 0.0.0 is_systemd_init().() { |
| 4174 | # Function to test if system is really using systemd by checking if /sbin/init is link to /lib/systemd/systemd. |
| 4175 | local real_init re_code |
| 4176 | if [scip-shell system . . `[`. -x "/bin/systemctlscip-shell filesystem . . `/bin/systemctl`." -a -d "/lib/systemd/system/scip-shell filesystem . . `/lib/systemd/system/`." ]; then |
| 4177 | real_init="$(LC_ALL=C statscip-shell system . . stat. -c "%N" /sbin/initscip-shell filesystem . . `/sbin/init`. | awkscip-shell system . . awk. -F"->" '{print $2}' | sedscip-shell system . . sed. -r -e "s/^[[:space:]]*//g" -e "s/\`//g" -e "s/'//g")" |
| 4178 | if [scip-shell system . . `[`. -n "$real_init" ]; then |
| 4179 | if [scip-shell system . . `[`. "$(LC_ALL=C basenamescip-shell system . . basename. $real_init)" = "systemd" ]; then |
| 4180 | re_code=0 |
| 4181 | else |
| 4182 | re_code=1 |
| 4183 | fi |
| 4184 | else |
| 4185 | re_code=1 |
| 4186 | fi |
| 4187 | else |
| 4188 | re_code=1 |
| 4189 | fi |
| 4190 | return $re_code |
| 4191 | } # end of is_systemd_init |
| 4192 | # |
| 4193 | grand_jobs_before_exitscip-shell shell shell-project 0.0.0 grand_jobs_before_exit().() { |
| 4194 | # This function is used to collect the jobs before program aborting. |
| 4195 | # Including: |
| 4196 | # (1) Unmount ecryptfs if it exists. |
| 4197 | # (1.1) Unmount gocryptfs if it exists. |
| 4198 | # (2) Remove MULTIPATH_INFODIR temp dir. |
| 4199 | # (3) Remove partition_table from gen_proc_partitions_map_file |
| 4200 | |
| 4201 | #(1) |
| 4202 | umount_ecryptfs_mount_point_if_necessary |
| 4203 | umount_gocryptfs_mount_point_if_necessary |
| 4204 | |
| 4205 | #(2) |
| 4206 | if [scip-shell system . . `[`. -d "$MULTIPATH_INFODIR" -a \ |
| 4207 | -n "$(echoscip-shell system . . echo. $MULTIPATH_INFODIR | grepscip-shell system . . grep. -w "multipath_info")" ]; then |
| 4208 | rmscip-shell system . . rm. -f "$MULTIPATH_INFODIR/*" |
| 4209 | rmdirscip-shell system . . rmdir. $MULTIPATH_INFODIR |
| 4210 | fi |
| 4211 | #(3) |
| 4212 | if [scip-shell system . . `[`. -f "$partition_table" -a \ |
| 4213 | -n "$(echoscip-shell system . . echo. $partition_table | grepscip-shell system . . grep. -w "parttable-ocs")" ]; then |
| 4214 | rmscip-shell system . . rm. -f $partition_table |
| 4215 | fi |
| 4216 | } # end of grand_jobs_before_exit |
| 4217 | # |
| 4218 | my_ocs_exitscip-shell shell shell-project 0.0.0 my_ocs_exit().() { |
| 4219 | local ec="$1" |
| 4220 | grand_jobs_before_exitscip-shell shell shell-project 0.0.0 grand_jobs_before_exit(). |
| 4221 | exit $ec |
| 4222 | } # end of my_ocs_exit |
| 4223 | # |
| 4224 | drbl_service_ctlscip-shell shell shell-project 0.0.0 drbl_service_ctl().() { |
| 4225 | # Function to start/stop service, for systemd or sysv/upstart |
| 4226 | local srv_name="$1" |
| 4227 | local srv_action="$2" # start, stop, and restart only |
| 4228 | if [scip-shell system . . `[`. -n "$srv_name" -a -n "$srv_action" ]; then |
| 4229 | if is_systemd_initscip-shell shell shell-project 0.0.0 is_systemd_init(). && [scip-shell system . . `[`. -e "/lib/systemd/system/${srv_name}.service" ]; then |
| 4230 | systemctl $srv_action $srv_name |
| 4231 | else |
| 4232 | servicescip-shell system . . service. $srv_name $srv_action |
| 4233 | fi |
| 4234 | fi |
| 4235 | } # end of drbl_service_ctl |
| 4236 | # |
| 4237 | get_grub_efi_image_blockscip-shell shell shell-project 0.0.0 get_grub_efi_image_block().() { |
| 4238 | local IMG_NAME="$1" |
| 4239 | local GRUB_CONF_TMP="$2" |
| 4240 | [scip-shell system . . `[`. -z "$IMG_NAME" ] && exit 1 |
| 4241 | # By using |
| 4242 | # grep -Ei -n '^[[:space:]]*menuentry[[:space:]]+.*([[:space:]]|$)+' /tftpboot/nbi_img/grub/grub.cfg | grep -A1 -E "menuentry[[:space:]]+.*--id drbl-client([[:space:]]|$)+" |
| 4243 | # 29:menuentry "CentOS 7.1.1503 Linux (DRBL mode, mostly local resources)" { |
| 4244 | # 34:menuentry 'Clonezilla' { |
| 4245 | # so we know we can replace the one between line no. 29 and 34 |
| 4246 | if [scip-shell system . . `[`. -n "$GRUB_CONF_TMP" -a ! -e "$GRUB_CONF_TMP" ]; then |
| 4247 | return 2 |
| 4248 | fi |
| 4249 | between_lines="$(LC_ALL=C grepscip-shell system . . grep. -Ei -n -- "^[[:space:]]*[#]*menuentry[[:space:]]+.*([[:space:]]|$)+" $GRUB_CONF_TMP | grepscip-shell system . . grep. -Ei -A1 -- "menuentry[[:space:]]+.*$IMG_NAME([[:space:]]|$)+" | cutscip-shell system . . cut. -d":" -f1)" |
| 4250 | begin_line="$(LC_ALL=C echoscip-shell system . . echo. $between_lines | awkscip-shell system . . awk. -F" " '{print $1}')" |
| 4251 | end_line="$(LC_ALL=C echoscip-shell system . . echo. $between_lines | awkscip-shell system . . awk. -F" " '{print $2}')" |
| 4252 | # if end_line is nothing, it must be the last block, i.e. we can not find the next [.*] |
| 4253 | if [scip-shell system . . `[`. -z "$end_line" ]; then |
| 4254 | end_line="$(LC_ALL=C wcscip-shell system . . wc. -l $GRUB_CONF_TMP | awkscip-shell system . . awk. -F" " '{print $1}')" |
| 4255 | else |
| 4256 | # if not nothing, backword one line |
| 4257 | end_line="$(($end_line - 1))" |
| 4258 | fi |
| 4259 | echoscip-shell system . . echo. "$begin_line $end_line" |
| 4260 | } # end of get_grub_efi_image_block |
| 4261 | # |
| 4262 | set_specific_host_grub_efi_confscip-shell shell shell-project 0.0.0 set_specific_host_grub_efi_conf().() { |
| 4263 | local HOSTS="$*" |
| 4264 | local grub_eficfg grub_eficfg_MAC grub_eficfg_MIP OCS_TMP IP |
| 4265 | # prepare the HOSTNAME-IP-MAC table |
| 4266 | OCS_TMP=`mktempscip-shell system . . mktemp. /tmp/ocs_clean_tmp.XXXXXXscip-shell filesystem . . `/tmp/ocs_clean_tmp.XXXXXX`.` |
| 4267 | trap "[ -f "$OCS_TMP" ] && rm -f $OCS_TMP" HUP INT QUIT TERM EXIT |
| 4268 | parse_dhcpd_conf $OCS_TMP |
| 4269 | |
| 4270 | for ih in $HOSTS; do |
| 4271 | case "$ih" in |
| 4272 | *.*.*.*) |
| 4273 | # list by IP |
| 4274 | # the grub_eficfg will like "grub.cfg-drbl-192.168.177.2" |
| 4275 | grub_eficfg="grub.cfg-drbl-${ih}" |
| 4276 | # These files look like: grub.cfg-drbl:$MAC, e.g., grub.cfg-drbl-88:aa:bb:cc:dd:ee |
| 4277 | # We'd better to clean the grub.cfg-drbl:$MAC if it exists since maybe it's created by ocsmgrd when received the results from client in the previous save/restoration. Since grub.cfg-drbl:$MAC has higher priority than "C0A80001" style file in pxelinux, this is a must if we can find it, we have to remove it. |
| 4278 | # TODO: What if no MAC address setting in dhcpd.conf ? Then $OCS_TMP will be empty, then... ? |
| 4279 | grub_eficfg_MAC="grub.cfg-drbl-$(grepscip-shell system . . grep. ${ih} $OCS_TMP | awkscip-shell system . . awk. -F" " '{print $3}')" |
| 4280 | [scip-shell system . . `[`. -f "$GRUB_EFINB_DIR/$grub_eficfg_MAC" ] && rmscip-shell system . . rm. -f $GRUB_EFINB_DIR/$grub_eficfg_MAC |
| 4281 | ;; |
| 4282 | *:*:*:*:*:*) |
| 4283 | # list by MAC |
| 4284 | # for an Ethernet (ARP type 1) with address 88:99:AA:BB:CC:DD it would search for the filename grub.cfg-drbl-88:99:aa:bb:cc:dd (lowercase) |
| 4285 | grub_eficfg="$(echoscip-shell system . . echo. $ih | trscip-shell system . . tr. "[A-Z]" "[a-z]")" |
| 4286 | # append "grub.cfg-drbl-" in the beginning |
| 4287 | grub_eficfg="grub.cfg-drbl-$grub_eficfg" |
| 4288 | # We'd better to clean the IP-based setting file if it exists since maybe it's created by ocsmgrd when received the results from client in the previous save/restoration. Although grub.cfg-drbl-$MAC has higher priority than "grub.cfg-drbl-C0A80001" style file in grub_efi, this NOT a must if we can find it, but we remove it to avoid confusion. |
| 4289 | IP="$(grepscip-shell system . . grep. -E ${ih} $OCS_TMP | awkscip-shell system . . awk. -F" " '{print $2}')" |
| 4290 | grub_eficfg_MIP="grub.cfg-drbl-${IP}" |
| 4291 | [scip-shell system . . `[`. -f "$GRUB_EFINB_DIR/$grub_eficfg_MIP" ] && rmscip-shell system . . rm. -f $GRUB_EFINB_DIR/$grub_eficfg_MIP |
| 4292 | ;; |
| 4293 | esac |
| 4294 | echoscip-shell system . . echo. -n "Generate the grub uEFI netboot config file for host $ih ... " |
| 4295 | cpscip-shell system . . cp. -f $GRUB_EFINB_DIR/grub.cfg_skeleton $GRUB_EFINB_DIR/$grub_eficfg |
| 4296 | echoscip-shell system . . echo. "done!" |
| 4297 | done |
| 4298 | [scip-shell system . . `[`. -f "$OCS_TMP" ] && rmscip-shell system . . rm. -f $OCS_TMP |
| 4299 | } # end of set_specific_host_grub_efi_conf |
| 4300 | # |
| 4301 | check_entryid_in_grub_efi_cfgscip-shell shell shell-project 0.0.0 check_entryid_in_grub_efi_cfg().() { |
| 4302 | local ENTRY_ID="$1" |
| 4303 | local GRUB_CONF_TMP="$2" |
| 4304 | if [scip-shell system . . `[`. -z "$ENTRY_ID" ]; then |
| 4305 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE |
| 4306 | echoscip-shell system . . echo. "You must specify the image name! Program terminated!!!" |
| 4307 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 4308 | exit 1 |
| 4309 | fi |
| 4310 | if [scip-shell system . . `[`. -n "$GRUB_CONF_TMP" -a ! -e "$GRUB_CONF_TMP" ]; then |
| 4311 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 4312 | echoscip-shell system . . echo. "File $GRUB_CONF_TMP not found. No support for uEFI network boot." |
| 4313 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 4314 | return 2 |
| 4315 | fi |
| 4316 | if ! grepscip-shell system . . grep. -Eiq "^[[:space:]]*menuentry[[:space:]]+.*--id $ENTRY_ID" $GRUB_CONF_TMP; then |
| 4317 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE |
| 4318 | echoscip-shell system . . echo. "Unable to find the menuentry ($ENTRY_ID) ID! Make sure the $ENTRY_ID is labeled in $GRUB_CONF_TMP! Program terminated!!!" |
| 4319 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 4320 | exit 1 |
| 4321 | fi |
| 4322 | } # end of check_entryid_in_grub_efi_cfg |
| 4323 | # |
| 4324 | sub_default_grub_efi_imgscip-shell shell shell-project 0.0.0 sub_default_grub_efi_img().() { |
| 4325 | local ENTRY_ID="$1" # E.g. drbl-client, clonezilla-se-client |
| 4326 | local GRUB_CONF_TMP="$2" |
| 4327 | local ENTRY_LABEL="$3" |
| 4328 | local lines begin_line end_line |
| 4329 | if [scip-shell system . . `[`. -n "$GRUB_CONF_TMP" -a ! -e "$GRUB_CONF_TMP" ]; then |
| 4330 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 4331 | echoscip-shell system . . echo. "File $GRUB_CONF_TMP not found. No support for uEFI network boot." |
| 4332 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 4333 | return 2 |
| 4334 | fi |
| 4335 | check_entryid_in_grub_efi_cfgscip-shell shell shell-project 0.0.0 check_entryid_in_grub_efi_cfg(). "$ENTRY_ID" $GRUB_CONF_TMP |
| 4336 | # Set default menu and update the menuentry |
| 4337 | perlscip-shell system . . perl. -pi -e "s|^set default=.*|set default=$ENTRY_ID|g" $GRUB_CONF_TMP |
| 4338 | |
| 4339 | lines="$(get_grub_efi_image_blockscip-shell shell shell-project 0.0.0 get_grub_efi_image_block(). "--id $ENTRY_ID" $GRUB_CONF_TMP)" |
| 4340 | begin_line="$(echoscip-shell system . . echo. $lines | awkscip-shell system . . awk. -F" " '{print $1}')" |
| 4341 | end_line="$(echoscip-shell system . . echo. $lines | awkscip-shell system . . awk. -F" " '{print $2}')" |
| 4342 | |
| 4343 | if [scip-shell system . . `[`. -n "$ENTRY_LABEL" ]; then |
| 4344 | echoscip-shell system . . echo. The MENUENTRY LABEL is \"$ENTRY_LABEL\" |
| 4345 | # menuentry "Clonezilla" --id clonezilla-se-client { |
| 4346 | # -> |
| 4347 | # menuentry "Clonezilla: multicast restore precise-x86-20150504 to disk sda " --id clonezilla-se-client { |
| 4348 | sub_menu_label_cmd="if ($begin_line..$end_line) {s|^[[:space:]]*menuentry .*|menuentry \"$ENTRY_LABEL\" --id $ENTRY_ID \{|i}" |
| 4349 | perlscip-shell system . . perl. -pi -e "$sub_menu_label_cmd" $GRUB_CONF_TMP |
| 4350 | fi |
| 4351 | } # end of sub_default_grub_efi_img |
| 4352 | # |
| 4353 | add_opt_in_pxelinux_cfg_blockscip-shell shell shell-project 0.0.0 add_opt_in_pxelinux_cfg_block().() { |
| 4354 | # add something like: ocs_opt="--language 0 -g auto -p true restoredisk 2disks hda hdb" in pxelinux config file |
| 4355 | local prot_dq="\\\"" # protection double quotation for later use. |
| 4356 | while [scip-shell system . . `[`. $# -gt 0 ]; do |
| 4357 | case "$1" in |
| 4358 | -n|--no-dq) shift; prot_dq="" ;; |
| 4359 | -*) echoscip-shell system . . echo. "${0}: ${1}: invalid option in function add_opt_in_pxelinux_cfg_block" |
| 4360 | echoscip-shell system . . echo. "$msg_program_stop" |
| 4361 | [scip-shell system . . `[`. "$save_restore_error_log" = "yes" ] && copy_error_log |
| 4362 | exit 2 ;; |
| 4363 | *) break ;; |
| 4364 | esac |
| 4365 | done |
| 4366 | local label="$1" |
| 4367 | local opt_name="$2" # can be ocs_opt (for NFSRoot-based Clonezilla client) or ocs_live_run (for Clonezilla-live-based client) |
| 4368 | local opt_content="$3" |
| 4369 | local tag_found |
| 4370 | [scip-shell system . . `[`. -z "$label" ] && echoscip-shell system . . echo. "No label in add_opt_in_pxelinux_cfg_block!" && exit 1 |
| 4371 | [scip-shell system . . `[`. -z "$opt_name" ] && echoscip-shell system . . echo. "opt_name NOT specified in add_opt_in_pxelinux_cfg_block! Abort!" && exit 1 |
| 4372 | [scip-shell system . . `[`. -z "$opt_content" ] && echoscip-shell system . . echo. "opt_content NOT specified in add_opt_in_pxelinux_cfg_block! Abort!" && exit 1 |
| 4373 | # Make sure there is no white space in the end of opt_content, i.e. e.g. |
| 4374 | # "clonezilla -l en_US.UTF-8 -p reboot -k " -> "clonezilla -l en_US.UTF-8 -p reboot -k" |
| 4375 | # Otherwise it might cause the boot parameters to be wrongly parsed, i.e. the boot parameters: |
| 4376 | # ocs_live_run="clonezilla -l en_US.UTF-8 -p reboot -k " net.ifnames=0 |
| 4377 | # is wrongly parsed by Linux kernel 4.1 so that net.ifnames=0 won't take effect. |
| 4378 | opt_content="$(LC_ALL=C echoscip-shell system . . echo. "$opt_content" | sedscip-shell system . . sed. -r -e "s/[[:space:]]*$//g")" |
| 4379 | lines="$(get_pxecfg_image_blockscip-shell shell shell-project 0.0.0 get_pxecfg_image_block(). $label $PXE_CONF)" |
| 4380 | begin_line="$(echoscip-shell system . . echo. $lines | awkscip-shell system . . awk. -F" " '{print $1}')" |
| 4381 | end_line="$(echoscip-shell system . . echo. $lines | awkscip-shell system . . awk. -F" " '{print $2}')" |
| 4382 | if [scip-shell system . . `[`. -z "$begin_line" -o -z "$end_line" ]; then |
| 4383 | echoscip-shell system . . echo. "No \"$label\" found in $PXE_CONF, skip adding that." |
| 4384 | return 1 |
| 4385 | fi |
| 4386 | tag_found="$(LC_ALL=C headscip-shell system . . head. -n $end_line $PXE_CONF | tailscip-shell system . . tail. -n $(($end_line-$begin_line)) | grepscip-shell system . . grep. -Eiw "^[[:space:]]*append[[:space:]]*.*[[:space:]]+$opt_name=.*([[:space:]]+|$)")" |
| 4387 | if [scip-shell system . . `[`. -z "$tag_found" ]; then |
| 4388 | # append ocs_opt=... in the end of append kernel parameter. |
| 4389 | sub_menu_label_cmd="if ($begin_line..$end_line) {s|(^[[:space:]]*append[[:space:]]+.*)|\$1 $opt_name=${prot_dq}${opt_content}${prot_dq}|i}" |
| 4390 | LC_ALL=C perlscip-shell system . . perl. -pi -e "$sub_menu_label_cmd" $PXE_CONF |
| 4391 | else |
| 4392 | # overwrite existing ocs_opt=... |
| 4393 | # ocs_opt must be the last parameters in default append for pxelinux. |
| 4394 | # If tag if found, 3 cases: (1) with "" (e.g. ocs_daemonon="ssh", (2) without "" (e.g. ocs_daemonon=ssh) |
| 4395 | # (3) nothing (except space) after =, e.g. 'ocs_daemonon=' |
| 4396 | if [scip-shell system . . `[`. -n "$(echoscip-shell system . . echo. $tag_found | grepscip-shell system . . grep. -iE "$opt_name=\"[^\"]*\"")" ]; then |
| 4397 | # case 1, e.g. ocs_daemonon="ssh" |
| 4398 | sub_menu_label_cmd="if ($begin_line..$end_line) {s|(^[[:space:]]*append[[:space:]]*.*)[[:space:]]+$opt_name=\"[^\"]*\"([[:space:]]+.*$)|\$1 $opt_name=${prot_dq}${opt_content}${prot_dq}\$2|i}" |
| 4399 | else |
| 4400 | if [scip-shell system . . `[`. -n "$(echoscip-shell system . . echo. $tag_found | grepscip-shell system . . grep. -iE "$opt_name=[^[:space:]]+")" ]; then |
| 4401 | # case 2, e.g. ocs_daemonon=ssh |
| 4402 | sub_menu_label_cmd="if ($begin_line..$end_line) {s|(^[[:space:]]*append[[:space:]]*.*)[[:space:]]+$opt_name=[^[:space:]]+([[:space:]]+.*$)|\$1 $opt_name=${prot_dq}${opt_content}${prot_dq}\$2|i}" |
| 4403 | else |
| 4404 | # case 3, e.g. 'ocs_daemonon=', normally this is for 'locales=' or 'keyboard-layouts=' |
| 4405 | sub_menu_label_cmd="if ($begin_line..$end_line) {s|(^[[:space:]]*append[[:space:]]*.*)[[:space:]]+$opt_name=[[:space:]]+(.*$)|\$1 $opt_name=${prot_dq}${opt_content}${prot_dq} \$2|i}" |
| 4406 | fi |
| 4407 | fi |
| 4408 | LC_ALL=C perlscip-shell system . . perl. -pi -e "$sub_menu_label_cmd" $PXE_CONF |
| 4409 | fi |
| 4410 | } # end of add_opt_in_pxelinux_cfg_block |
| 4411 | # |
| 4412 | remove_opt_in_pxelinux_cfg_blockscip-shell shell shell-project 0.0.0 remove_opt_in_pxelinux_cfg_block().() { |
| 4413 | local label="$1" |
| 4414 | local opt_name="$2" # can be ocs_opt (for NFSRoot-based Clonezilla client) or ocs_live_run (for Clonezilla-live-based client) |
| 4415 | local tag_found |
| 4416 | [scip-shell system . . `[`. -z "$label" ] && echoscip-shell system . . echo. "No label in remove_opt_in_pxelinux_cfg_block!" && exit 1 |
| 4417 | # remove something like ocs_opt=... from the append .... like this in pxelinux config: |
| 4418 | # append ... ocs_opt="--language 0 -g auto -p true restoredisk 2disks hda hdb"... |
| 4419 | lines="$(get_pxecfg_image_blockscip-shell shell shell-project 0.0.0 get_pxecfg_image_block(). $label $PXE_CONF)" |
| 4420 | begin_line="$(echoscip-shell system . . echo. $lines | awkscip-shell system . . awk. -F" " '{print $1}')" |
| 4421 | end_line="$(echoscip-shell system . . echo. $lines | awkscip-shell system . . awk. -F" " '{print $2}')" |
| 4422 | if [scip-shell system . . `[`. -z "$begin_line" -o -z "$end_line" ]; then |
| 4423 | echoscip-shell system . . echo. "No \"$label\" found in $PXE_CONF, skip removing that." |
| 4424 | return 1 |
| 4425 | fi |
| 4426 | # 2 types of boot parameters, 1st one is with "=" (e.g. ocs_opt=...), the 2nd one is without "=" (e.g. quiet). Here first we test if the one with "=" is found or not. |
| 4427 | tag_found="$(LC_ALL=C headscip-shell system . . head. -n $end_line $PXE_CONF | tailscip-shell system . . tail. -n $(($end_line-$begin_line)) | grepscip-shell system . . grep. -Eiw "^[[:space:]]*append[[:space:]]*.*[[:space:]]+$opt_name=.*([[:space:]]+|$)")" |
| 4428 | if [scip-shell system . . `[`. -n "$tag_found" ]; then |
| 4429 | # 1st type, i.e. with "=". 3 types of them. |
| 4430 | # (1) with ", e.g. ocs_live_run="ocs-live-general" |
| 4431 | # (2) without ", e.g. ocs_live_run=ocs-live-general |
| 4432 | # (3) without " and nothing after '=', e.g. 'ocs_live_run=' |
| 4433 | |
| 4434 | # (1) with ", e.g. ocs_live_run="ocs-live-general" |
| 4435 | sub_menu_label_cmd="if ($begin_line..$end_line) {s|(^[[:space:]]*append[[:space:]]+.*)[[:space:]]+$opt_name=\"[^\"]*\"([[:space:]]+.*)|\$1\$2|i}" |
| 4436 | LC_ALL=C perlscip-shell system . . perl. -pi -e "$sub_menu_label_cmd" $PXE_CONF |
| 4437 | # (2) without ", e.g. ocs_live_run=ocs-live-general |
| 4438 | sub_menu_label_cmd="if ($begin_line..$end_line) {s|(^[[:space:]]*append[[:space:]]+.*)[[:space:]]+$opt_name=[^[:space:]]+([[:space:]]+.*)|\$1\$2|i}" |
| 4439 | LC_ALL=C perlscip-shell system . . perl. -pi -e "$sub_menu_label_cmd" $PXE_CONF |
| 4440 | # (3) without " and nothing after '=', e.g. 'ocs_live_run=' |
| 4441 | sub_menu_label_cmd="if ($begin_line..$end_line) {s|(^[[:space:]]*append[[:space:]]+.*)[[:space:]]+$opt_name=[[:space:]]+(.*)|\$1 \$2|i}" |
| 4442 | LC_ALL=C perlscip-shell system . . perl. -pi -e "$sub_menu_label_cmd" $PXE_CONF |
| 4443 | else |
| 4444 | # 2nd type, i.e. without "=", or nothing. Even if nothing, perl won't fail. Therefore just run it. |
| 4445 | sub_menu_label_cmd="if ($begin_line..$end_line) {s|(^[[:space:]]*append[[:space:]]+.*)[[:space:]]+$opt_name([[:space:]]+.*)|\$1\$2|i}" |
| 4446 | LC_ALL=C perlscip-shell system . . perl. -pi -e "$sub_menu_label_cmd" $PXE_CONF |
| 4447 | fi |
| 4448 | } # end of remove_opt_in_pxelinux_cfg_block() |
| 4449 | # |
| 4450 | override_opt_in_pxelinux_cfg_blockscip-shell shell shell-project 0.0.0 override_opt_in_pxelinux_cfg_block().() { |
| 4451 | # Function to override all the boot parameters. E.g. |
| 4452 | # kernel vmlinuz-pxe |
| 4453 | # append initrd=initrd-pxe.img devfs=nomount drblthincli=off quiet |
| 4454 | local update_mode |
| 4455 | update_mode="append" # By default this function is used to update the line begin with "append" |
| 4456 | while [scip-shell system . . `[`. $# -gt 0 ]; do |
| 4457 | case "$1" in |
| 4458 | -k|--kernel) shift; update_mode="kernel" ;; |
| 4459 | -*) echoscip-shell system . . echo. "${0}: ${1}: invalid option in function add_opt_in_pxelinux_cfg_block" |
| 4460 | echoscip-shell system . . echo. "$msg_program_stop" |
| 4461 | [scip-shell system . . `[`. "$save_restore_error_log" = "yes" ] && copy_error_log |
| 4462 | exit 2 ;; |
| 4463 | *) break ;; |
| 4464 | esac |
| 4465 | done |
| 4466 | local label="$1" |
| 4467 | local all_opts="$2" # all the boot parameters |
| 4468 | [scip-shell system . . `[`. -z "$label" ] && echoscip-shell system . . echo. "No label in override_opt_in_pxelinux_cfg_block!" && exit 1 |
| 4469 | lines="$(get_pxecfg_image_blockscip-shell shell shell-project 0.0.0 get_pxecfg_image_block(). $label $PXE_CONF)" |
| 4470 | begin_line="$(echoscip-shell system . . echo. $lines | awkscip-shell system . . awk. -F" " '{print $1}')" |
| 4471 | end_line="$(echoscip-shell system . . echo. $lines | awkscip-shell system . . awk. -F" " '{print $2}')" |
| 4472 | if [scip-shell system . . `[`. -z "$begin_line" -o -z "$end_line" ]; then |
| 4473 | echoscip-shell system . . echo. "No \"$label\" found in $PXE_CONF, skip overwriding that." |
| 4474 | return 1 |
| 4475 | fi |
| 4476 | sub_menu_label_cmd="if ($begin_line..$end_line) {s|(^[[:space:]]*${update_mode}[[:space:]]+).*$|\$1$all_opts|i}" |
| 4477 | LC_ALL=C perlscip-shell system . . perl. -pi -e "$sub_menu_label_cmd" $PXE_CONF |
| 4478 | } # end of override_opt_in_pxelinux_cfg_block |
| 4479 | # |
| 4480 | get_status_grub_efi_cfg_blockscip-shell shell shell-project 0.0.0 get_status_grub_efi_cfg_block().() { |
| 4481 | local ENTRY_ID="$1" |
| 4482 | local GRUB_CONF_TMP="$2" |
| 4483 | local lines begin_line end_line rc block_status |
| 4484 | [scip-shell system . . `[`. -z "$ENTRY_ID" -o -z "$GRUB_CONF_TMP" ] && return 1 |
| 4485 | if [scip-shell system . . `[`. -n "$GRUB_CONF_TMP" -a ! -e "$GRUB_CONF_TMP" ]; then |
| 4486 | return 2 |
| 4487 | fi |
| 4488 | lines="$(get_grub_efi_image_blockscip-shell shell shell-project 0.0.0 get_grub_efi_image_block(). "--id $ENTRY_ID" $GRUB_CONF_TMP)" |
| 4489 | begin_line=$(echoscip-shell system . . echo. $lines | awkscip-shell system . . awk. -F" " '{print $1}') |
| 4490 | end_line=$(echoscip-shell system . . echo. $lines | awkscip-shell system . . awk. -F" " '{print $2}') # end_line is useless in this function. Just keep it for completion |
| 4491 | if [scip-shell system . . `[`. -n "$(LC_ALL=C sedscip-shell system . . sed. -n "${begin_line}p" $GRUB_CONF_TMP | grepscip-shell system . . grep. -E "^#menuentry")" ]; then |
| 4492 | # Found something like: |
| 4493 | # #menuentry "Clonezilla" --id clonezilla-se-client { |
| 4494 | # so it's disabled. |
| 4495 | block_status="hide" |
| 4496 | else |
| 4497 | block_status="reveal" |
| 4498 | fi |
| 4499 | echoscip-shell system . . echo. "$block_status" |
| 4500 | } # end of get_status_grub_efi_cfg_block |
| 4501 | # |
| 4502 | add_opt_in_grub_efi_cfg_blockscip-shell shell shell-project 0.0.0 add_opt_in_grub_efi_cfg_block().() { |
| 4503 | # add something like: ocs_opt=\"--language 0 -g auto -p true restoredisk 2disks hda hdb\" in grub efi nb config file |
| 4504 | local prot_dq="\\\\\"" # protection double quotation for later use. |
| 4505 | local status_saved |
| 4506 | while [scip-shell system . . `[`. $# -gt 0 ]; do |
| 4507 | case "$1" in |
| 4508 | -n|--no-dq) shift; prot_dq="" ;; |
| 4509 | -*) echoscip-shell system . . echo. "${0}: ${1}: invalid option in function add_opt_in_grub_efi_cfg_block" |
| 4510 | echoscip-shell system . . echo. "$msg_program_stop" |
| 4511 | [scip-shell system . . `[`. "$save_restore_error_log" = "yes" ] && copy_error_log |
| 4512 | exit 2 ;; |
| 4513 | *) break ;; |
| 4514 | esac |
| 4515 | done |
| 4516 | local entry_id="$1" # e.g. "clonezilla-se-client" |
| 4517 | local opt_name="$2" # can be ocs_opt (for NFSRoot-based Clonezilla client) or ocs_live_run (for Clonezilla-live-based client) |
| 4518 | local opt_content="$3" |
| 4519 | local tag_found |
| 4520 | local sub_menu_entry_cmd |
| 4521 | [scip-shell system . . `[`. -z "$entry_id" ] && echoscip-shell system . . echo. "No entry_id in add_opt_in_grub_efi_cfg_block!" && exit 1 |
| 4522 | [scip-shell system . . `[`. -z "$opt_name" ] && echoscip-shell system . . echo. "opt_name NOT specified in add_opt_in_grub_efi_cfg_block! Abort!" && exit 1 |
| 4523 | [scip-shell system . . `[`. -z "$opt_content" ] && echoscip-shell system . . echo. "opt_content NOT specified in add_opt_in_grub_efi_cfg_block! Abort!" && exit 1 |
| 4524 | if [scip-shell system . . `[`. -n "$GRUB_CONF" -a ! -e "$GRUB_CONF" ]; then |
| 4525 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 4526 | echoscip-shell system . . echo. "File $GRUB_CONF not found. No support for uEFI network boot." |
| 4527 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 4528 | return 2 |
| 4529 | fi |
| 4530 | # Before adding option, we have to enable it because with grub there is no |
| 4531 | # way to hide unless with use # to comment the whole menuentry. |
| 4532 | # Save the status first |
| 4533 | status_saved="$(get_status_grub_efi_cfg_blockscip-shell shell shell-project 0.0.0 get_status_grub_efi_cfg_block(). "$entry_id" $GRUB_CONF)" |
| 4534 | hide_reveal_grub_efi_ent "$entry_id" reveal $GRUB_CONF |
| 4535 | # |
| 4536 | lines="$(get_grub_efi_image_blockscip-shell shell shell-project 0.0.0 get_grub_efi_image_block(). "--id $entry_id" $GRUB_CONF)" |
| 4537 | begin_line="$(echoscip-shell system . . echo. $lines | awkscip-shell system . . awk. -F" " '{print $1}')" |
| 4538 | end_line="$(echoscip-shell system . . echo. $lines | awkscip-shell system . . awk. -F" " '{print $2}')" |
| 4539 | if [scip-shell system . . `[`. -z "$begin_line" -o -z "$end_line" ]; then |
| 4540 | echoscip-shell system . . echo. "No \"$entry_id\" found in $GRUB_CONF, skip adding that." |
| 4541 | return 1 |
| 4542 | fi |
| 4543 | tag_found="$(LC_ALL=C headscip-shell system . . head. -n $end_line $GRUB_CONF | tailscip-shell system . . tail. -n $(($end_line-$begin_line)) | grepscip-shell system . . grep. -Eiw "^[[:space:]]*$linux_cmd[[:space:]]*.*[[:space:]]+$opt_name=.*([[:space:]]+|$)")" |
| 4544 | if [scip-shell system . . `[`. -z "$tag_found" ]; then |
| 4545 | # append ocs_opt=... in the end of linux kernel parameter. |
| 4546 | sub_menu_entry_cmd="if ($begin_line..$end_line) {s|(^[[:space:]]*\\\$linux_cmd[[:space:]]+.*)|\$1 $opt_name=${prot_dq}${opt_content}${prot_dq}|i}" |
| 4547 | LC_ALL=C perlscip-shell system . . perl. -pi -e "$sub_menu_entry_cmd" $GRUB_CONF |
| 4548 | else |
| 4549 | # overwrite existing ocs_opt=... |
| 4550 | # ocs_opt must be the last parameters in default append for grub efi nb. |
| 4551 | # If tag if found, 3 cases: (1) with "" (e.g. ocs_daemonon="ssh", (2) without "" (e.g. ocs_daemonon=ssh), |
| 4552 | # (3) nothing (except space) after =, e.g. 'ocs_daemonon=' |
| 4553 | if [scip-shell system . . `[`. -n "$(echoscip-shell system . . echo. $tag_found | grepscip-shell system . . grep. -iE "$opt_name=\\\\\"[^\"]*\\\\\"")" ]; then |
| 4554 | # case 1, e.g. ocs_daemonon="ssh" |
| 4555 | sub_menu_entry_cmd="if ($begin_line..$end_line) {s|(^[[:space:]]*\\\$linux_cmd[[:space:]]*.*)[[:space:]]+$opt_name=\"[^\"]*\"([[:space:]]+.*$)|\$1 $opt_name=${prot_dq}${opt_content}${prot_dq}\$2|i}" |
| 4556 | else |
| 4557 | if [scip-shell system . . `[`. -n "$(echoscip-shell system . . echo. $tag_found | grepscip-shell system . . grep. -iE "$opt_name=[^[:space:]]+")" ]; then |
| 4558 | # case 2, e.g. ocs_daemonon=ssh |
| 4559 | sub_menu_entry_cmd="if ($begin_line..$end_line) {s|(^[[:space:]]*\\\$linux_cmd[[:space:]]*.*)[[:space:]]+$opt_name=[^[:space:]]+([[:space:]]+.*$)|\$1 $opt_name=${prot_dq}${opt_content}${prot_dq}\$2|i}" |
| 4560 | else |
| 4561 | # case 3, e.g. 'ocs_daemonon=', normally this is for 'locales=' or 'keyboard-layouts=' |
| 4562 | sub_menu_entry_cmd="if ($begin_line..$end_line) {s|(^[[:space:]]*\\\$linux_cmd[[:space:]]*.*)[[:space:]]+$opt_name=[[:space:]]+(.*$)|\$1 $opt_name=${prot_dq}${opt_content}${prot_dq} \$2|i}" |
| 4563 | fi |
| 4564 | fi |
| 4565 | LC_ALL=C perlscip-shell system . . perl. -pi -e "$sub_menu_entry_cmd" $GRUB_CONF |
| 4566 | fi |
| 4567 | # Restore the status |
| 4568 | hide_reveal_grub_efi_ent "$entry_id" "$status_saved" $GRUB_CONF |
| 4569 | } # end of add_opt_in_grub_efi_cfg_block |
| 4570 | # |
| 4571 | remove_opt_in_grub_efi_cfg_blockscip-shell shell shell-project 0.0.0 remove_opt_in_grub_efi_cfg_block().() { |
| 4572 | local entry_id="$1" # e.g. "clonezilla-se-client" |
| 4573 | local opt_name="$2" # can be ocs_opt (for NFSRoot-based Clonezilla client) or ocs_live_run (for Clonezilla-live-based client) |
| 4574 | local tag_found |
| 4575 | local sub_menu_entry_cmd |
| 4576 | local status_saved |
| 4577 | [scip-shell system . . `[`. -z "$entry_id" ] && echoscip-shell system . . echo. "No entry_id in remove_opt_in_grub_efi_cfg_block!" && exit 1 |
| 4578 | if [scip-shell system . . `[`. -n "$GRUB_CONF" -a ! -e "$GRUB_CONF" ]; then |
| 4579 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 4580 | echoscip-shell system . . echo. "File $GRUB_CONF not found. No support for uEFI network boot." |
| 4581 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 4582 | return 2 |
| 4583 | fi |
| 4584 | # Before adding option, we have to enable it because with grub there is no |
| 4585 | # way to hide unless with use # to comment the whole menuentry. |
| 4586 | # Save the status first |
| 4587 | status_saved="$(get_status_grub_efi_cfg_blockscip-shell shell shell-project 0.0.0 get_status_grub_efi_cfg_block(). "$entry_id" $GRUB_CONF)" |
| 4588 | hide_reveal_grub_efi_ent "$entry_id" reveal $GRUB_CONF |
| 4589 | # remove something like ocs_opt=... from the append .... like this in pxelinux config: |
| 4590 | # append ... ocs_opt="--language 0 -g auto -p true restoredisk 2disks hda hdb"... |
| 4591 | lines="$(get_grub_efi_image_blockscip-shell shell shell-project 0.0.0 get_grub_efi_image_block(). "--id $entry_id" $GRUB_CONF)" |
| 4592 | begin_line="$(echoscip-shell system . . echo. $lines | awkscip-shell system . . awk. -F" " '{print $1}')" |
| 4593 | end_line="$(echoscip-shell system . . echo. $lines | awkscip-shell system . . awk. -F" " '{print $2}')" |
| 4594 | if [scip-shell system . . `[`. -z "$begin_line" -o -z "$end_line" ]; then |
| 4595 | echoscip-shell system . . echo. "No \"$entry_id\" found in $GRUB_CONF, skip removing that." |
| 4596 | return 1 |
| 4597 | fi |
| 4598 | # 2 types of boot parameters, 1st one is with "=" (e.g. ocs_opt=...), the 2nd one is without "=" (e.g. quiet). Here first we test if the one with "=" is found or not. |
| 4599 | tag_found="$(LC_ALL=C headscip-shell system . . head. -n $end_line $GRUB_CONF | tailscip-shell system . . tail. -n $(($end_line-$begin_line)) | grepscip-shell system . . grep. -Eiw "^[[:space:]]*$linux_cmd[[:space:]]*.*[[:space:]]+$opt_name=.*([[:space:]]+|$)")" |
| 4600 | if [scip-shell system . . `[`. -n "$tag_found" ]; then |
| 4601 | # 1st type, i.e. with "=". 2 types of them. |
| 4602 | # (1) with ", e.g. ocs_live_run="ocs-live-general" |
| 4603 | # (2) without ", e.g. ocs_live_run=ocs-live-general |
| 4604 | # (3) without " and nothing after '=', e.g. 'ocs_live_run=' |
| 4605 | |
| 4606 | # (1) with ", e.g. ocs_live_run="ocs-live-general" |
| 4607 | sub_menu_entry_cmd="if ($begin_line..$end_line) {s|(^[[:space:]]*\\\$linux_cmd[[:space:]]+.*)[[:space:]]+$opt_name=\\\\\"[^\"]*\\\\\"([[:space:]]+.*)|\$1\$2|i}" |
| 4608 | LC_ALL=C perlscip-shell system . . perl. -pi -e "$sub_menu_entry_cmd" $GRUB_CONF |
| 4609 | # (2) without ", e.g. ocs_live_run=ocs-live-general |
| 4610 | sub_menu_entry_cmd="if ($begin_line..$end_line) {s|(^[[:space:]]*\\\$linux_cmd[[:space:]]+.*)[[:space:]]+$opt_name=[^[:space:]]+([[:space:]]+.*)|\$1\$2|i}" |
| 4611 | LC_ALL=C perlscip-shell system . . perl. -pi -e "$sub_menu_entry_cmd" $GRUB_CONF |
| 4612 | # (3) without " and nothing after '=', e.g. 'ocs_live_run=' |
| 4613 | sub_menu_entry_cmd="if ($begin_line..$end_line) {s|(^[[:space:]]*\\\$linux_cmd[[:space:]]+.*)[[:space:]]+$opt_name=[[:space:]]+(.*)|\$1 \$2|i}" |
| 4614 | LC_ALL=C perlscip-shell system . . perl. -pi -e "$sub_menu_entry_cmd" $GRUB_CONF |
| 4615 | else |
| 4616 | # 2nd type, i.e. without "=", or nothing. Even if nothing, perl won't fail. Therefore just run it. |
| 4617 | sub_menu_entry_cmd="if ($begin_line..$end_line) {s|(^[[:space:]]*\\\$linux_cmd[[:space:]]+.*)[[:space:]]+$opt_name([[:space:]]+.*)|\$1\$2|i}" |
| 4618 | LC_ALL=C perlscip-shell system . . perl. -pi -e "$sub_menu_entry_cmd" $GRUB_CONF |
| 4619 | fi |
| 4620 | # Restore the status |
| 4621 | hide_reveal_grub_efi_ent "$entry_id" "$status_saved" $GRUB_CONF |
| 4622 | } # end of remove_opt_in_grub_efi_cfg_block |
| 4623 | # |
| 4624 | override_opt_in_grub_efi_cfg_blockscip-shell shell shell-project 0.0.0 override_opt_in_grub_efi_cfg_block().() { |
| 4625 | # Function to override all the boot parameters. A grub config block is like: |
| 4626 | # menuentry "Debian Testing-Unstable Linux (DRBL mode, mostly local resources)" --id drbl-client { |
| 4627 | # echo "Enter DRBL..." |
| 4628 | # echo "Loading Linux vmlinuz-pxe..." |
| 4629 | # linux vmlinuz-pxe boot=live union=overlay config components nomodeset quiet net.ifnames=0 nosplash username=drbl keyboard-layouts=us locales=en_US.UTF-8 drbl_live_noconfx ocs_daemonon="ssh" noeject netboot=nfs nfsroot=192.168.7.254:/tftpboot/node_root/clonezilla-live/ dcs_put_dticons="no" |
| 4630 | # echo "Loading initial ramdisk initrd-pxe.img..." |
| 4631 | # initrd initrd-pxe.img |
| 4632 | # } |
| 4633 | local update_mode kernel_f |
| 4634 | local sub_menu_entry_cmd |
| 4635 | local status_saved |
| 4636 | update_mode="linux" # By default this function is used to update the line begin with "linux" |
| 4637 | while [scip-shell system . . `[`. $# -gt 0 ]; do |
| 4638 | case "$1" in |
| 4639 | -i|--initrd) shift; update_mode="initrd" ;; |
| 4640 | -*) echoscip-shell system . . echo. "${0}: ${1}: invalid option in function override_opt_in_grub_efi_cfg_block" |
| 4641 | echoscip-shell system . . echo. "$msg_program_stop" |
| 4642 | [scip-shell system . . `[`. "$save_restore_error_log" = "yes" ] && copy_error_log |
| 4643 | exit 2 ;; |
| 4644 | *) break ;; |
| 4645 | esac |
| 4646 | done |
| 4647 | local entry_id="$1" # e.g. "clonezilla-se-client" |
| 4648 | local all_opts="$2" # all the boot parameters |
| 4649 | [scip-shell system . . `[`. -z "$entry_id" ] && echoscip-shell system . . echo. "No entry_id in override_opt_in_grub_efi_cfg_block!" && exit 1 |
| 4650 | if [scip-shell system . . `[`. -n "$GRUB_CONF" -a ! -e "$GRUB_CONF" ]; then |
| 4651 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 4652 | echoscip-shell system . . echo. "File $GRUB_CONF not found. No support for uEFI network boot." |
| 4653 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 4654 | return 2 |
| 4655 | fi |
| 4656 | # Before adding option, we have to enable it because with grub there is no |
| 4657 | # way to hide unless with use # to comment the whole menuentry. |
| 4658 | # Save the status first |
| 4659 | status_saved="$(get_status_grub_efi_cfg_blockscip-shell shell shell-project 0.0.0 get_status_grub_efi_cfg_block(). "$entry_id" $GRUB_CONF)" |
| 4660 | hide_reveal_grub_efi_ent "$entry_id" reveal $GRUB_CONF |
| 4661 | lines="$(get_grub_efi_image_blockscip-shell shell shell-project 0.0.0 get_grub_efi_image_block(). "--id $entry_id" $GRUB_CONF)" |
| 4662 | begin_line="$(echoscip-shell system . . echo. $lines | awkscip-shell system . . awk. -F" " '{print $1}')" |
| 4663 | end_line="$(echoscip-shell system . . echo. $lines | awkscip-shell system . . awk. -F" " '{print $2}')" |
| 4664 | if [scip-shell system . . `[`. -z "$begin_line" -o -z "$end_line" ]; then |
| 4665 | echoscip-shell system . . echo. "No \"$entry_id\" found in $GRUB_CONF, skip removing that." |
| 4666 | return 1 |
| 4667 | fi |
| 4668 | sub_menu_entry_cmd="if ($begin_line..$end_line) {s|(^[[:space:]]*${update_mode}[[:space:]]+).*$|\$1$all_opts|i}" |
| 4669 | LC_ALL=C perlscip-shell system . . perl. -pi -e "$sub_menu_entry_cmd" $GRUB_CONF |
| 4670 | # Update the echo command for kernel and initrd, too |
| 4671 | case "$update_mode" in |
| 4672 | linux) |
| 4673 | # When in this mode, the 1st parameter in linux "line" is kernel, e.g. |
| 4674 | # linux vmlinuz-pxe root=... ro quiet... |
| 4675 | kernel_f="$(echoscip-shell system . . echo. $all_opts | awkscip-shell system . . awk. -F" " '{print $1}')" |
| 4676 | sub_menu_entry_cmd="if ($begin_line..$end_line) {s|(^[[:space:]]*)echo \"Loading Linux kernel.*\"$|\$1echo \"Loading Linux kernel $kernel_f\"|i}" |
| 4677 | LC_ALL=C perlscip-shell system . . perl. -pi -e "$sub_menu_entry_cmd" $GRUB_CONF |
| 4678 | ;; |
| 4679 | initrd) |
| 4680 | sub_menu_entry_cmd="if ($begin_line..$end_line) {s|(^[[:space:]]*)echo \"Loading initial ramdisk.*\"$|\$1echo \"Loading initial ramdisk $all_opts\"|i}" |
| 4681 | LC_ALL=C perlscip-shell system . . perl. -pi -e "$sub_menu_entry_cmd" $GRUB_CONF |
| 4682 | ;; |
| 4683 | esac |
| 4684 | # Restore the status |
| 4685 | hide_reveal_grub_efi_ent "$entry_id" "$status_saved" $GRUB_CONF |
| 4686 | } # end of override_opt_in_grub_efi_cfg_block |
| 4687 | # |
| 4688 | confirm_continue_or_not_default_quitscip-shell shell shell-project 0.0.0 confirm_continue_or_not_default_quit().() { |
| 4689 | local ans_continue |
| 4690 | local job_before_quit job_des |
| 4691 | while [scip-shell system . . `[`. $# -gt 0 ]; do |
| 4692 | case "$1" in |
| 4693 | -d|--description) |
| 4694 | shift |
| 4695 | if [scip-shell system . . `[`. -z "$(echoscip-shell system . . echo. $1 |grepscip-shell system . . grep. ^-.)" ]; then |
| 4696 | # skip the -xx option, in case |
| 4697 | job_des="$1" |
| 4698 | shift |
| 4699 | fi |
| 4700 | if [scip-shell system . . `[`. -z "$job_des" ]; then |
| 4701 | echoscip-shell system . . echo. "-d is used, but no job_des assigned." |
| 4702 | echoscip-shell system . . echo. "$msg_program_stop" |
| 4703 | [scip-shell system . . `[`. "$save_restore_error_log" = "yes" ] && copy_error_log |
| 4704 | exit 1 |
| 4705 | fi |
| 4706 | ;; |
| 4707 | -*) echoscip-shell system . . echo. "${0}: ${1}: invalid option" |
| 4708 | echoscip-shell system . . echo. "$msg_program_stop" |
| 4709 | [scip-shell system . . `[`. "$save_restore_error_log" = "yes" ] && copy_error_log |
| 4710 | exit 2 ;; |
| 4711 | *) break ;; |
| 4712 | esac |
| 4713 | done |
| 4714 | job_before_quit="$1" |
| 4715 | if [scip-shell system . . `[`. -n "$job_des" ]; then |
| 4716 | echoscip-shell system . . echo. "$job_des" |
| 4717 | else |
| 4718 | echoscip-shell system . . echo. "$msg_are_u_sure_u_want_to_continue" |
| 4719 | fi |
| 4720 | echoscip-shell system . . echo. -n "[y/N] " |
| 4721 | read ans_continue |
| 4722 | case "$ans_continue" in |
| 4723 | y|Y|[yY][eE][sS]) |
| 4724 | echoscip-shell system . . echo. "$msg_ok_let_do_it!" |
| 4725 | ;; |
| 4726 | *) |
| 4727 | echoscip-shell system . . echo. "$msg_program_stop!" |
| 4728 | [scip-shell system . . `[`. -n "$job_before_quit" ] && $job_before_quit |
| 4729 | my_ocs_exitscip-shell shell shell-project 0.0.0 my_ocs_exit(). 1 |
| 4730 | ;; |
| 4731 | esac |
| 4732 | } # end of confirm_continue_or_not_default_quit |
| 4733 | # |
| 4734 | confirm_continue_or_not_default_continuescip-shell shell shell-project 0.0.0 confirm_continue_or_not_default_continue().() { |
| 4735 | local ans_continue |
| 4736 | local job_before_quit job_des |
| 4737 | while [scip-shell system . . `[`. $# -gt 0 ]; do |
| 4738 | case "$1" in |
| 4739 | -d|--description) |
| 4740 | shift |
| 4741 | if [scip-shell system . . `[`. -z "$(echoscip-shell system . . echo. $1 |grepscip-shell system . . grep. ^-.)" ]; then |
| 4742 | # skip the -xx option, in case |
| 4743 | job_des="$1" |
| 4744 | shift |
| 4745 | fi |
| 4746 | if [scip-shell system . . `[`. -z "$job_des" ]; then |
| 4747 | echoscip-shell system . . echo. "-d is used, but no job_des assigned." |
| 4748 | echoscip-shell system . . echo. "$msg_program_stop" |
| 4749 | [scip-shell system . . `[`. "$save_restore_error_log" = "yes" ] && copy_error_log |
| 4750 | exit 1 |
| 4751 | fi |
| 4752 | ;; |
| 4753 | -*) echoscip-shell system . . echo. "${0}: ${1}: invalid option" |
| 4754 | echoscip-shell system . . echo. "$msg_program_stop" |
| 4755 | [scip-shell system . . `[`. "$save_restore_error_log" = "yes" ] && copy_error_log |
| 4756 | exit 2 ;; |
| 4757 | *) break ;; |
| 4758 | esac |
| 4759 | done |
| 4760 | job_before_quit="$1" |
| 4761 | if [scip-shell system . . `[`. -n "$job_des" ]; then |
| 4762 | echoscip-shell system . . echo. "$job_des" |
| 4763 | else |
| 4764 | echoscip-shell system . . echo. "$msg_are_u_sure_u_want_to_continue" |
| 4765 | fi |
| 4766 | echoscip-shell system . . echo. -n "[Y/n] " |
| 4767 | read ans_continue |
| 4768 | case "$ans_continue" in |
| 4769 | n|N|[nN][oO]) |
| 4770 | echoscip-shell system . . echo. "$msg_program_stop!" |
| 4771 | [scip-shell system . . `[`. -n "$job_before_quit" ] && $job_before_quit |
| 4772 | my_ocs_exitscip-shell shell shell-project 0.0.0 my_ocs_exit(). 1 |
| 4773 | ;; |
| 4774 | *) |
| 4775 | echoscip-shell system . . echo. "$msg_ok_let_do_it!" |
| 4776 | ;; |
| 4777 | esac |
| 4778 | } # end of confirm_continue_or_not_default_continue |
| 4779 | # |
| 4780 | confirm_continue_no_default_answerscip-shell shell shell-project 0.0.0 confirm_continue_no_default_answer().() { |
| 4781 | local ans_ ans_continue continue_choice |
| 4782 | local job_before_quit job_des |
| 4783 | continue_choice="" |
| 4784 | while [scip-shell system . . `[`. $# -gt 0 ]; do |
| 4785 | case "$1" in |
| 4786 | -d|--description) |
| 4787 | shift |
| 4788 | if [scip-shell system . . `[`. -z "$(echoscip-shell system . . echo. $1 |grepscip-shell system . . grep. ^-.)" ]; then |
| 4789 | # skip the -xx option, in case |
| 4790 | job_des="$1" |
| 4791 | shift |
| 4792 | fi |
| 4793 | if [scip-shell system . . `[`. -z "$job_des" ]; then |
| 4794 | echoscip-shell system . . echo. "-d is used, but no job_des assigned." |
| 4795 | echoscip-shell system . . echo. "$msg_program_stop" |
| 4796 | [scip-shell system . . `[`. "$save_restore_error_log" = "yes" ] && copy_error_log |
| 4797 | exit 1 |
| 4798 | fi |
| 4799 | ;; |
| 4800 | -*) echoscip-shell system . . echo. "${0}: ${1}: invalid option" |
| 4801 | echoscip-shell system . . echo. "$msg_program_stop" |
| 4802 | [scip-shell system . . `[`. "$save_restore_error_log" = "yes" ] && copy_error_log |
| 4803 | exit 2 ;; |
| 4804 | *) break ;; |
| 4805 | esac |
| 4806 | done |
| 4807 | job_before_quit="$1" |
| 4808 | while [scip-shell system . . `[`. -z "$continue_choice" ]; do |
| 4809 | if [scip-shell system . . `[`. "$ocs_prompt_mode" = "tui" ]; then |
| 4810 | # Because dialog/whiptail "--yesno" must have a yes or no, we choose no here. |
| 4811 | $DIA --backtitle "$msg_nchc_free_software_labs" --title "$msg_nchc_clonezilla" \ |
| 4812 | --defaultno --yesno "${job_des:-$msg_are_u_sure_u_want_to_continue}" 0 0 |
| 4813 | ans_="$?" |
| 4814 | # Convert ans_ to ans_continue |
| 4815 | case "$ans_" in |
| 4816 | 0) # yes is chosen |
| 4817 | ans_continue="yes";; |
| 4818 | 1) # no is chosen |
| 4819 | ans_continue="no";; |
| 4820 | esac |
| 4821 | else |
| 4822 | if [scip-shell system . . `[`. -n "$job_des" ]; then |
| 4823 | echoscip-shell system . . echo. "$job_des" |
| 4824 | else |
| 4825 | echoscip-shell system . . echo. -n "$msg_are_u_sure_u_want_to_continue" |
| 4826 | fi |
| 4827 | echoscip-shell system . . echo. -n " [y/n] " |
| 4828 | read ans_continue |
| 4829 | fi |
| 4830 | case "$ans_continue" in |
| 4831 | y|Y|[yY][eE][sS]) |
| 4832 | continue_choice="yes" |
| 4833 | echoscip-shell system . . echo. "$msg_ok_let_do_it!" |
| 4834 | ;; |
| 4835 | n|N|[nN][oO]) |
| 4836 | continue_choice="no" |
| 4837 | echoscip-shell system . . echo. "$msg_program_stop!" |
| 4838 | [scip-shell system . . `[`. -n "$job_before_quit" ] && $job_before_quit |
| 4839 | my_ocs_exitscip-shell shell shell-project 0.0.0 my_ocs_exit(). 1 |
| 4840 | ;; |
| 4841 | *) |
| 4842 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 4843 | echoscip-shell system . . echo. "$msg_you_have_to_enter_yes_or_no!" |
| 4844 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 4845 | echoscip-shell system . . echo. $msg_delimiter_star_line |
| 4846 | ;; |
| 4847 | esac |
| 4848 | done |
| 4849 | } # end of confirm_continue_no_default_answer |
| 4850 | # |
| 4851 | filter_cl_gp_boot_paramscip-shell shell shell-project 0.0.0 filter_cl_gp_boot_param().(){ |
| 4852 | # Function to filter the boot parameters which should not be used in PXE RAM based drbl/clonezilla/gparted client. |
| 4853 | # Used for programs drbl-sl and drbl-live |
| 4854 | # (1) For /proc/cmdline, it's like (customized by user): |
| 4855 | # BOOT_IMAGE=/live/vmlinuz initrd=/live/initrd.img boot=live union=overlay username=user config components nomodeset quiet vga=785 ip= net.ifnames=0 nosplash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1 keyboard-layouts=NONE locales=en_US.UTF-8 drbl_live_noconfx ocs_daemonon="ssh" ocs_prerun1="ifconfig eth0 192.168.120.3; route add default gw 192.168.120.254 eth0; ifconfig eth1 192.168.7.254 netmask 255.255.255.0; echo nameserver 8.8.8.8 > /etc/resolv.conf" ocs_prerun2="mount -t nfs 192.168.120.254:/home/partimag /home/partimag" ocs_prerun3="drbl-live --batch --skip-pause-in-the-end --no-prompt-drbl-live start" ocs_prerun5="perl -pi -e 's/timeout 70/timeout 10/' /tftpboot/nbi_img/pxelinux.cfg/default" |
| 4856 | # (2) For isolinux.cfg or syslinux.cfg, it's like (customized by user): |
| 4857 | # append initrd=/live/initrd.img boot=live union=overlay username=user config components nomodeset quiet vga=785 ip= net.ifnames=0 nosplash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1 keyboard-layouts=NONE locales=en_US.UTF-8 drbl_live_noconfx ocs_daemonon="ssh" ocs_prerun1="ifconfig eth0 192.168.120.3; route add default gw 192.168.120.254 eth0; ifconfig eth1 192.168.7.254 netmask 255.255.255.0; echo nameserver 8.8.8.8 > /etc/resolv.conf" ocs_prerun2="mount -t nfs 192.168.120.254:/home/partimag /home/partimag" ocs_prerun3="drbl-live --batch --skip-pause-in-the-end --no-prompt-drbl-live start" ocs_prerun5="perl -pi -e 's/timeout 70/timeout 10/' /tftpboot/nbi_img/pxelinux.cfg/default" |
| 4858 | # (3) For grub.cfg, it's like: |
| 4859 | # $linux_cmd /live/vmlinuz boot=live union=overlay username=user config components quiet noswap edd=on nomodeset enforcing=0 locales= keyboard-layouts= ocs_live_run="ocs-live-general" ocs_live_extra_param="" ocs_live_batch="no" vga=788 ip= net.ifnames=0 splash i915.blacklist=yes radeonhd.blacklist=yes nouveau.blacklist=yes vmwgfx.enable_fbdev=1 |
| 4860 | # So the 1st two items should be removed |
| 4861 | awkscip-shell system . . awk. -F" " '{for (i=3; i<=NF; ++i) print $i}' | xargsscip-shell system . . xargs. echo |\ |
| 4862 | sed -r -e "s|append||g" |\ |
| 4863 | sed -r -e "s|BOOT_IMAGE=[^[:space:]]+[[:space:]]?||g" | \ |
| 4864 | sed -r -e "s|initrd=[^[:space:]]+[[:space:]]?||g" | \ |
| 4865 | sed -r -e "s|vga=[^[:space:]]+[[:space:]]?||g" | \ |
| 4866 | sed -r -e "s|ip=[^[:space:]]*[[:space:]]?||g" | \ |
| 4867 | sed -r -e "s|keyboard-layouts=[^[:space:]]+[[:space:]]?||g" | \ |
| 4868 | sed -r -e "s|locales=[^[:space:]]+[[:space:]]?||g" | \ |
| 4869 | sed -r -e "s|[^[:space:]]+.blacklist=[^[:space:]]+[[:space:]]?||g" | \ |
| 4870 | sed -r -e "s|vmwgfx.enable_fbdev=[^[:space:]]+[[:space:]]?||g" | \ |
| 4871 | sed -r -e "s|ocs_prerun[[:digit:]]*=\".*\"||g" | \ |
| 4872 | sed -r -e "s|ocs_daemon.*=\".*\"||g" | \ |
| 4873 | sed -r -e "s|drbl_live_noconfx||g" | \ |
| 4874 | sed -r -e "s|toram=?[^[:space:]]*[[:space:]]?||g" | \ |
| 4875 | sed -r -e "s|^[[:space:]]*||g" | \ |
| 4876 | sed -r -e "s|[[:space:]]+$||g" |
| 4877 | } # end of filter_cl_gp_boot_param |
| 4878 | # |
| 4879 | is_valid_IPv4_addscip-shell shell shell-project 0.0.0 is_valid_IPv4_add().() { |
| 4880 | local input_ip="$1" |
| 4881 | local rc=1 |
| 4882 | if [scip-shell system . . `[`. -n "$(echoscip-shell system . . echo. $input_ip | grepscip-shell system . . grep. -Eo "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$")" ]; then |
| 4883 | rc=0 |
| 4884 | else |
| 4885 | rc=1 |
| 4886 | fi |
| 4887 | return $rc |
| 4888 | } # end of is_valid_IPv4_add |
| 4889 | # |
| 4890 | deploy_pxecfg_grubefi_filesscip-shell shell shell-project 0.0.0 deploy_pxecfg_grubefi_files().(){ |
| 4891 | # This function will set the specific config or just keep the "default" |
| 4892 | if [scip-shell system . . `[`. "$LIST_HOST" = "on" ]; then |
| 4893 | # specify the nodes if assigned by user |
| 4894 | echoscip-shell system . . echo. "Create specific config for PXE and GRUB EFI NB client." |
| 4895 | set_specific_host_pxe_confscip-shell shell shell-project 0.0.0 set_specific_host_pxe_conf(). `catscip-shell system . . cat. $HOSTS_TMP` |
| 4896 | set_specific_host_grub_efi_confscip-shell shell shell-project 0.0.0 set_specific_host_grub_efi_conf(). `catscip-shell system . . cat. $HOSTS_TMP` |
| 4897 | else |
| 4898 | # for all clients, so we just keep the file pxelinux.cfg/default, no others. |
| 4899 | echoscip-shell system . . echo. "This is for all clients, so we remove other host-based PXE config files in $PXELINUX_DIR/ and keep $PXE_CONF." |
| 4900 | clean_stale_node_pxe_cfg |
| 4901 | clean_stale_node_grub_efi_cfg |
| 4902 | fi |
| 4903 | } # end of deploy_pxecfg_grubefi_files |
| 4904 | # |
| 4905 | gen_dnsmasq_cfgscip-shell shell shell-project 0.0.0 gen_dnsmasq_cfg().() { |
| 4906 | local srv_cfg="$1" |
| 4907 | local gen_mode="proxy" # default mode is proxy |
| 4908 | local dnsmasq_v pxelinux_fn |
| 4909 | local allow_1_nic="no" # By default should be in DRBL mode, i.e., 2 or more NICs. |
| 4910 | if [scip-shell system . . `[`. -z "$srv_cfg" ]; then |
| 4911 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE |
| 4912 | echoscip-shell system . . echo. "No config file assigned in function gen_dnsmasq_cfg!" |
| 4913 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 4914 | echoscip-shell system . . echo. "$msg_program_stop" |
| 4915 | exit 1 |
| 4916 | fi |
| 4917 | while [scip-shell system . . `[`. $# -gt 0 ]; do |
| 4918 | case "$1" in |
| 4919 | -a|--allow-1-nic) allow_1_nic="yes"; shift;; |
| 4920 | -r|--range) |
| 4921 | shift; gen_mode="range" |
| 4922 | if [scip-shell system . . `[`. -z "$(echoscip-shell system . . echo. $1 |grepscip-shell system . . grep. ^-.)" ]; then |
| 4923 | # skip the -xx option, in case |
| 4924 | dhcp_range="$1" |
| 4925 | shift |
| 4926 | fi |
| 4927 | [scip-shell system . . `[`. -z "$dhcp_range" ] && echoscip-shell system . . echo. "-m is used, but no dhcp_range was assigned." && exit 1 |
| 4928 | shift |
| 4929 | ;; |
| 4930 | -*) echoscip-shell system . . echo. "${0}: ${1}: invalid option in gen_dnsmasq_cfg." | teescip-shell system . . tee. -a ${OCS_LOGFILE} >&2 |
| 4931 | echoscip-shell system . . echo. "$msg_program_stop" | teescip-shell system . . tee. -a ${OCS_LOGFILE} |
| 4932 | [scip-shell system . . `[`. "$save_restore_error_log" = "yes" ] && copy_error_log |
| 4933 | exit 2 ;; |
| 4934 | *) break ;; |
| 4935 | esac |
| 4936 | done |
| 4937 | # Generate dnsmasq.conf |
| 4938 | catscip-shell system . . cat. <<-DNSMQSQ_END > $dnsmasq_cfg |
| 4939 | # Configured by DRBL/Clonezilla |
| 4940 | bind-interfaces |
| 4941 | log-dhcp |
| 4942 | dhcp-no-override |
| 4943 | enable-tftp |
| 4944 | tftp-root=$pxecfg_pd |
| 4945 | DNSMQSQ_END |
| 4946 | |
| 4947 | case "$gen_mode" in |
| 4948 | proxy) all_eth_dev="$(LC_ALL=C get-all-nic-ip -d)" |
| 4949 | uplink_eth="$(LC_ALL=C get-all-nic-ip -u)" |
| 4950 | for inet in $all_eth_dev; do |
| 4951 | if [scip-shell system . . `[`. "$allow_1_nic" = "no" ]; then |
| 4952 | # Do not allow 1 NIC, so skip if uplink is the same with all NIC. |
| 4953 | [scip-shell system . . `[`. "$inet" = "$uplink_eth" ] && continue |
| 4954 | fi |
| 4955 | ip="$(LC_ALL=C drbl-get-ipadd $inet)" |
| 4956 | echoscip-shell system . . echo. "dhcp-range=$ip,proxy" >> $dnsmasq_cfg |
| 4957 | done |
| 4958 | ;; |
| 4959 | range) echoscip-shell system . . echo. "dhcp-range=$dhcp_range" >> $dnsmasq_cfg;; |
| 4960 | *) echoscip-shell system . . echo. "${0}: ${1}: Unknown gen_mode in gen_dnsmasq_cfg." | teescip-shell system . . tee. -a ${OCS_LOGFILE} >&2 |
| 4961 | echoscip-shell system . . echo. "$msg_program_stop" | teescip-shell system . . tee. -a ${OCS_LOGFILE} |
| 4962 | [scip-shell system . . `[`. "$save_restore_error_log" = "yes" ] && copy_error_log |
| 4963 | exit 2 ;; |
| 4964 | esac |
| 4965 | |
| 4966 | # Older dnsmasq (<2.75) will automatically append ".0" to pxelinux |
| 4967 | dnsmasq_v="$(query_pkg_ver dnsmasq)" |
| 4968 | if [scip-shell system . . `[`. -z "$dnsmasq_v" ]; then |
| 4969 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 4970 | echoscip-shell system . . echo. "Package dnsmasq is not installed. Skip generating dnsmasq.conf." |
| 4971 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 4972 | return 1 |
| 4973 | fi |
| 4974 | # dnsmasq version >= 2.76 will not append ".0" to basename. |
| 4975 | # Ref: http://www.thekelleys.org.uk/dnsmasq/CHANGELOG (search basename) |
| 4976 | if [scip-shell system . . `[`. "$dnsmasq_v" \> "2.75" -o "$dnsmasq_v" = "2.76" ]; then |
| 4977 | pxelinux_fn="pxelinux.0" |
| 4978 | else |
| 4979 | pxelinux_fn="pxelinux" |
| 4980 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 4981 | echoscip-shell system . . echo. "Warning!" |
| 4982 | echoscip-shell system . . echo. "Package dnsmasq is too old. It's recommended to use version >= 2.75." |
| 4983 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 4984 | fi |
| 4985 | |
| 4986 | # pxe-service mode does not work for non-proxy mode. It fails for supporting uEFI secure netboot |
| 4987 | # Hence we use dhcp-boot for non-proxy mode. This is a workaround to support uEFI secure netboot. |
| 4988 | # Ref: http://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/2018q3/012476.html |
| 4989 | case "$gen_mode" in |
| 4990 | proxy) |
| 4991 | catscip-shell system . . cat. <<-DNSMQSQ_END >> $dnsmasq_cfg |
| 4992 | |
| 4993 | ## PXEClient:Arch:00000 |
| 4994 | pxe-service=X86PC, "Boot BIOS PXE", $pxelinux_fn |
| 4995 | |
| 4996 | ## PXEClient:Arch:00007 |
| 4997 | pxe-service=BC_EFI, "Boot UEFI BC", bootx64.efi |
| 4998 | |
| 4999 | ## PXEClient:Arch:00009 |
| 5000 | pxe-service=X86-64_EFI, "Boot UEFI X86-64", bootx64.efi |
| 5001 | |
| 5002 | pxe-prompt="Booting DRBL/Clonezilla Client", 1 |
| 5003 | DNSMQSQ_END |
| 5004 | ;; |
| 5005 | range) |
| 5006 | catscip-shell system . . cat. <<-DNSMQSQ_END >> $dnsmasq_cfg |
| 5007 | |
| 5008 | dhcp-boot=$pxelinux_fn |
| 5009 | dhcp-match=set:efi-x86_64,option:client-arch,7 |
| 5010 | dhcp-boot=tag:efi-x86_64,bootx64.efi |
| 5011 | DNSMQSQ_END |
| 5012 | ;; |
| 5013 | esac |
| 5014 | |
| 5015 | # TODO: Check secure netboot file exists. |
| 5016 | # AMD64: /usr/lib/shim/shimx64.efi.signed has been put in http root. |
| 5017 | # ARM64: /usr/lib/shim/shimaa64.efi.signed has been put in http root. |
| 5018 | |
| 5019 | # The following is only working for Clonezilla lite server. |
| 5020 | if ! is_drbl_clonezilla_live_env; then |
| 5021 | return 0 |
| 5022 | fi |
| 5023 | get_live_media_mnt_point |
| 5024 | # For HTTPBoot, we only need to assign one NIC port's IP add. |
| 5025 | all_eth_dev="$(LC_ALL=C get-all-nic-ip -d)" |
| 5026 | ip="" |
| 5027 | for inet in $all_eth_dev; do |
| 5028 | ip="$(LC_ALL=C drbl-get-ipadd $inet)" |
| 5029 | [scip-shell system . . `[`. -n "$ip" ] && break |
| 5030 | done |
| 5031 | if [scip-shell system . . `[`. -n "$ip" ]; then |
| 5032 | catscip-shell system . . cat. <<-DNSMQSQ_END >> $dnsmasq_cfg |
| 5033 | |
| 5034 | # Proxy DHCP menu triggers and vendor mapping for HTTP Boot architectures |
| 5035 | dhcp-pxe-vendor=PXEClient,HTTPClient |
| 5036 | |
| 5037 | # HTTPBoot support |
| 5038 | dhcp-match=set:efi-http64,option:client-arch,16 |
| 5039 | dhcp-option-force=tag:efi-http64,60,"HTTPClient" |
| 5040 | dhcp-boot=tag:efi-http64,"http://${ip}/tftpboot/nbi_img/shimx64.efi" |
| 5041 | |
| 5042 | dhcp-match=set:efi-http32,option:client-arch,15 |
| 5043 | dhcp-option-force=tag:efi-http32,60,"HTTPClient" |
| 5044 | dhcp-boot=tag:efi-http32,"http://${ip}/tftpboot/nbi_img/bootia32.efi" |
| 5045 | |
| 5046 | dhcp-match=set:efi-httparm,option:client-arch,19 |
| 5047 | dhcp-option-force=tag:efi-httparm,60,"HTTPClient" |
| 5048 | dhcp-boot=tag:efi-httparm,"http://${ip}/tftpboot/nbi_img/shimaa64.efi" |
| 5049 | DNSMQSQ_END |
| 5050 | fi |
| 5051 | } # end of gen_dnsmasq_cfg |
| 5052 | # |
| 5053 | query_pkg_verscip-shell shell shell-project 0.0.0 query_pkg_ver().() { |
| 5054 | local pkg_ rc |
| 5055 | pkg_="$1" |
| 5056 | if [scip-shell system . . `[`. -z $"pkg_" ]; then |
| 5057 | return 1 |
| 5058 | fi |
| 5059 | if [scip-shell system . . `[`. -e /etc/debian_versionscip-shell filesystem . . `/etc/debian_version`. ]; then |
| 5060 | # Debian, Ubuntu |
| 5061 | ver_="$(LC_ALL=C dpkg-queryscip-shell system . . dpkg-query. -W -f='${Version}\n' ${pkg_} 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" |
| 5062 | rc=$? |
| 5063 | else |
| 5064 | # Fedora, CentOS, RHEL, SuSE... |
| 5065 | ver_="$(LC_ALL=C rpm -q --qf "%{VERSION}\n" ${pkg_} 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" |
| 5066 | rc=$? |
| 5067 | fi |
| 5068 | if [scip-shell system . . `[`. "$rc" -eq 0 ]; then |
| 5069 | echoscip-shell system . . echo. "$ver_" |
| 5070 | fi |
| 5071 | return $rc |
| 5072 | } # end of query_pkg_ver |
| 5073 | # |
| 5074 | function check_urlscip-shell shell shell-project 0.0.0 check_url().(){ |
| 5075 | # Function to check if URL exists or not. |
| 5076 | # Ref: https://gist.github.com/hrwgc/7455343 |
| 5077 | local url_t="$1" |
| 5078 | local rc |
| 5079 | if [scip-shell system . . `[`. -n "$(LC_ALL=C wget --spider -S $url_t 2>&1 | grepscip-shell system . . grep. -E 'HTTP/1.1 200 OK')" ]; then |
| 5080 | rc=0 |
| 5081 | else |
| 5082 | rc=1 |
| 5083 | fi |
| 5084 | return $rc |
| 5085 | } # end of check_url |
| 5086 | # |
| 5087 | get_smtd_smmcb_switchscip-shell shell shell-project 0.0.0 get_smtd_smmcb_switch().() { |
| 5088 | # Function to assign the on/off switch for -smtd/-smmcb |
| 5089 | # For x86-64: off, others: on |
| 5090 | local running_cpu |
| 5091 | # smtd_smmcb_switch is a global variable |
| 5092 | running_cpu="$(unamescip-shell system . . uname. -m)" |
| 5093 | case "$running_cpu" in |
| 5094 | x86_64) smtd_smmcb_switch="off";; |
| 5095 | *) smtd_smmcb_switch="on";; |
| 5096 | esac |
| 5097 | } # end of get_smtd_smmcb_switch |