| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | # Author: Steven Shiau <steven _at_ clonezilla org> |
| 3 | # License: GPL |
| 4 | # |
| 5 | # Note: This code is modified from http://cdprojekte.mattiasschlenker.de/Public/DSL-frominitrd/2.2b-0.0/script/pxedsl.sh |
| 6 | # Ref: |
| 7 | # http://news.mattiasschlenker.de/2006/02/22/pxe-booting-damnsmalllinux/#more-10 |
| 8 | # |
| 9 | # SL: Small Linux (Damn Small Linux, Puppy Linux, Clonezilla live, GParted live..) |
| 10 | # |
| 11 | # Load DRBL setting and functions |
| 12 | DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}" |
| 13 | |
| 14 | . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions |
| 15 | . /etc/drbl/drbl-ocs.confscip-shell source . . `/etc/drbl/drbl-ocs.conf`. |
| 16 | . $DRBL_SCRIPT_PATH/sbin/ocs-functions |
| 17 | |
| 18 | # Settings |
| 19 | SL_ISO_URL_EXAMPLE="http://downloads.sourceforge.net/clonezilla/clonezilla-live-3.0.2-21-amd64.iso" |
| 20 | # The method for netboot's root file system. "fetch" means the client will download the filesystem.squashfs from tftpd server, "nfsroot" means client will mount the nfs server. By default we use fetch. "nfsroot" only works for Debian-live based system (e.g. Clonezilla live, GParted live...) |
| 21 | rootfs_location="fetch" |
| 22 | # Force to update the PXELinux config file |
| 23 | force_to_update_pxecfg="yes" |
| 24 | |
| 25 | # List all supported SL_NAME |
| 26 | # // On 2009/05/25, we remove the support for PLD, INSERT, PUD, since those projects are not developed any more. As for GeeXbox, since we do not have time, it's removed, too. |
| 27 | # // 2013/03/13, DSL and PuppyLinux were removed. Not so useful to provide this. |
| 28 | #supported_SL_dists="DSL PuppyLinux INSERT PLD Debian-live GeeXbox PUD-Linux" |
| 29 | supported_SL_dists="Clonezilla-live GParted-live" |
| 30 | |
| 31 | # The buffer ratio for iso to container |
| 32 | buffer_ratio_for_iso_to_container="1.25" |
| 33 | |
| 34 | # The default estimation ratio for client's ram to use this small linux, |
| 35 | # we estimate it as 3 times of the initrd. For some distribution we might overwrite this value if necessary. |
| 36 | client_ram_to_initrd_ratio="3" |
| 37 | |
| 38 | # |
| 39 | batch_mode="off" |
| 40 | # Prompt messages after installation. |
| 41 | booting_messages="on" |
| 42 | |
| 43 | # By default when Clonezilla live is used, not to add ocs_server |
| 44 | add_ocs_server="no" |
| 45 | # By default when in fetch mode, the squashfs file will be copied, not link |
| 46 | use_link_in_fetch_mode="no" |
| 47 | |
| 48 | # Functions |
| 49 | USAGEscip-shell shell shell-project 0.0.0 USAGE().() { |
| 50 | echoscip-shell system . . echo. "Load small GNU/Linux ($supported_SL_dists) Linux to DRBL environment." |
| 51 | echoscip-shell system . . echo. "Usage: $0 [OPTION] [SL-ISO|SL-INDEX]" |
| 52 | echoscip-shell system . . echo. "OPTION:" |
| 53 | language_help_prompt_by_idx_no |
| 54 | echoscip-shell system . . echo. "-b, --batch-mode Run clone in batch mode." |
| 55 | echoscip-shell system . . echo. "-e, --fetch-link Use symbolic link when the mode is fetch for root file system." |
| 56 | echoscip-shell system . . echo. "-i, --install ISO: Load Small Linux ISO into DRBL environment, you must put the iso file in the current working dir. This conflicts with \"-p\" option." |
| 57 | echoscip-shell system . . echo. "-d, --distribution DIST: Assign the small GNU/Linux distribution as DIST. Available names are: $supported_SL_dists." |
| 58 | echoscip-shell system . . echo. "-f, --use-nfsroot By default the boot parameter to load the root file system (e.g. filesystem.squashfs) is fetch. With this option, nfsroot is used. //NOTE// This function only works for live-initramfs based system. E.g. Clonezilla live or GParted live." |
| 59 | echoscip-shell system . . echo. "-k, --keep-pxecfg Keep the pxelinux config file without updating the boot parameters." |
| 60 | echoscip-shell system . . echo. "-n, --no-prompt-boot-message Skip the prompt messages about booting via PXE or etherboot in the end of execution." |
| 61 | echoscip-shell system . . echo. "-o, --add-ocs-server Add ocs_server in the boot parameters for Clonezilla live." |
| 62 | echoscip-shell system . . echo. "-p, --live-path PATH: Assign the mounted or unzipped live system as PATH. This conflicts with \"-i\" option." |
| 63 | echoscip-shell system . . echo. "-s, --server-ip IP_ADDR: Assign the tftp or NFS server's IP address to be used in Clonezilla/GParted live." |
| 64 | echoscip-shell system . . echo. "-u, --uninstall DIST: Uninstall Small Linux DIST." |
| 65 | echoscip-shell system . . echo. "-V, --dist-version VER: Assign the version of small GNU/Linux version number as VER." |
| 66 | echoscip-shell system . . echo. "-v, --verbose: Verbose mode." |
| 67 | echoscip-shell system . . echo. "SL-ISO is one of $supported_SL_dists ISO file, used with installation." |
| 68 | echoscip-shell system . . echo. "S-L-INDEX is one of $supported_SL_dists, used with uninstallation." |
| 69 | echoscip-shell system . . echo. "Ex: To load Clonezilla live, run '$0 -i clonezilla-live-3.0.2-21-amd64.iso'" |
| 70 | echoscip-shell system . . echo. " To load GParted live, run '$0 -i gparted-live-1.4.0-6-amd64.iso'" |
| 71 | for isl in $supported_SL_dists; do |
| 72 | echoscip-shell system . . echo. " To remove $isl, run '$0 -u $isl'" |
| 73 | done |
| 74 | echoscip-shell system . . echo. " To remove all Small Linux, run '$0 -u all'" |
| 75 | } |
| 76 | # |
| 77 | get_rootfs_location_optscip-shell shell shell-project 0.0.0 get_rootfs_location_opt().() { |
| 78 | rootfs_location_opt="" |
| 79 | case "$rootfs_location" in |
| 80 | "fetch") |
| 81 | if is_drbl_clonezilla_live_env; then |
| 82 | # Check if file exists in the http URL. If the return code is 200 then it exists. |
| 83 | url_path="$server_IP/$squashfs_file" |
| 84 | if [scip-shell system . . `[`. "$(curlscip-shell system . . curl. -s -L -o /dev/nullscip-shell filesystem . . `/dev/null`. -w "%{http_code}" -I "http://$url_path")" -eq 200 ]; then |
| 85 | rootfs_location_opt="fetch=http://$url_path" |
| 86 | else |
| 87 | rootfs_location_opt="fetch=tftp://$url_path" |
| 88 | fi |
| 89 | fi |
| 90 | ;; |
| 91 | "nfsroot") |
| 92 | rootfs_location_opt="netboot=nfs nfsroot=$server_IP:$drbl_common_root/clonezilla-live/" ;; |
| 93 | esac |
| 94 | } # end of get_rootfs_location_opt |
| 95 | # get rootfile |
| 96 | get_SL_rootfilescip-shell shell shell-project 0.0.0 get_SL_rootfile().(){ |
| 97 | # this function must be used after iso is mounted, we need to find version inside it for some distribution (such as PLD). |
| 98 | case "$(echoscip-shell system . . echo. $SL_OS | trscip-shell system . . tr. "[A-Z]" "[a-z]")" in |
| 99 | dsl|DamnSmallLinux) |
| 100 | rootfile="$rootfile_path/KNOPPIX" |
| 101 | # DSL does not have any extra file, the only one is KNOPPIX |
| 102 | extra_sys_file="" |
| 103 | ;; |
| 104 | puppy|PuppyLinux) |
| 105 | rootfile="$rootfile_path/pup_${SL_VER}.sfs" |
| 106 | # Puppy 2.12, there is a /zdrv_212.sfs <-- deprecated. |
| 107 | [scip-shell system . . `[`. -f "$isomnt/$rootfile_path/zdrv_${SL_VER}.sfs" ] && extra_sys_file="$rootfile_path/zdrv_${SL_VER}.sfs" |
| 108 | ;; |
| 109 | clonezilla-live|gparted-live) |
| 110 | rootfile="$rootfile_path/filesystem.squashfs" |
| 111 | extra_sys_file="" |
| 112 | ;; |
| 113 | esac |
| 114 | } # end of get_SL_rootfile |
| 115 | # |
| 116 | prepare_param_in_pxe_grub_cfgscip-shell shell shell-project 0.0.0 prepare_param_in_pxe_grub_cfg().(){ |
| 117 | # This function must be used after ramdisk_size is calculated. |
| 118 | case "$(echoscip-shell system . . echo. $SL_OS | trscip-shell system . . tr. "[A-Z]" "[a-z]")" in |
| 119 | dsl|DamnSmallLinux) |
| 120 | append_param_in_grub_cfg="ramdisk_size=$ramdisk_size init=/etc/init lang=us apm=power-off vga=791 nomce noapic quiet BOOT_IMAGE=knoppix frominitrd" |
| 121 | append_param_in_pxe_cfg="initrd=$nbi_initrd $append_param_in_grub_cfg" |
| 122 | ;; |
| 123 | puppy|PuppyLinux) |
| 124 | # from version 216, init is ready when released, and no bootparam_trigger is necessary. Now drbl-SL only supports puppy from version 4.2.1 |
| 125 | bootparam_trigger="" |
| 126 | use_modified_init="no" |
| 127 | append_param_in_grub_cfg="" |
| 128 | append_param_in_pxe_cfg="initrd=$nbi_initrd $append_param_in_grub_cfg" |
| 129 | ;; |
| 130 | clonezilla-live) |
| 131 | if [scip-shell system . . `[`. -z "$server_IP" ]; then |
| 132 | # Find the IP address of this server. Here we choose the first one in the list of those connected to DRBL clients. |
| 133 | server_IP="$(LC_ALL=C get-all-nic-ip -b | awkscip-shell system . . awk. -F" " '{print $1}')" |
| 134 | fi |
| 135 | if [scip-shell system . . `[`. "$add_ocs_server" = "yes" ]; then |
| 136 | ocs_serer_opt="ocs_server=\"$server_IP\"" |
| 137 | fi |
| 138 | get_rootfs_location_optscip-shell shell shell-project 0.0.0 get_rootfs_location_opt(). |
| 139 | if [scip-shell system . . `[`. -z "$cl_gp_boot_param" ]; then |
| 140 | append_param_in_grub_cfg="boot=live union=overlay noswap noeject nolocales vga=788 $rootfs_location_opt $ocs_serer_opt" |
| 141 | append_param_in_pxe_cfg="initrd=$nbi_initrd $append_param_in_grub_cfg" |
| 142 | else |
| 143 | append_param_in_grub_cfg="$cl_gp_boot_param noeject $rootfs_location_opt $ocs_serer_opt" |
| 144 | append_param_in_pxe_cfg="initrd=$nbi_initrd $append_param_in_grub_cfg" |
| 145 | if is_drbl_live_env; then |
| 146 | # We will reuse the filesystem.squashfs from DRBL live, however, it's not like that of Clonezilla live, therefore more option are needed here. |
| 147 | clonezilla_se_live_opts="hostname=ocs-client \ |
| 148 | username=$assgned_username systemd.unit=multi-user.target drbl_live_noconfx \ |
| 149 | stick-to-pxe-srv dhcp-vendor-id=DRBLClient \ |
| 150 | drbl_prerun1=\"mkdir -p /var/lib/live/clonezilla/ocs-live.d\" \ |
| 151 | drbl_prerun2=\"grep -qsE ^sudo -i ocs-live-run-menu /home/$assgned_username/.bash_profile || echo sudo -i ocs-live-run-menu >> /home/$assgned_username/.bash_profile\"" |
| 152 | append_param_in_grub_cfg="$append_param_in_grub_cfg $clonezilla_se_live_opts" |
| 153 | append_param_in_pxe_cfg="$append_param_in_pxe_cfg $clonezilla_se_live_opts" |
| 154 | fi |
| 155 | fi |
| 156 | ;; |
| 157 | gparted-live) |
| 158 | if [scip-shell system . . `[`. -z "$server_IP" ]; then |
| 159 | # Find the IP address of this server. Here we choose the first one in the list, since it's just an example. |
| 160 | server_IP="$(LC_ALL=C get-all-nic-ip -i | awkscip-shell system . . awk. -F" " '{print $1}')" |
| 161 | fi |
| 162 | get_rootfs_location_optscip-shell shell shell-project 0.0.0 get_rootfs_location_opt(). |
| 163 | if [scip-shell system . . `[`. -z "$cl_gp_boot_param" ]; then |
| 164 | assgned_username="user" # The live system uses the default username as "user" |
| 165 | gparted_se_live_opts="username=$assgned_username" |
| 166 | append_param_in_grub_cfg="boot=live union=overlay noswap noeject nolocales vga=788 $rootfs_location_opt " |
| 167 | append_param_in_pxe_cfg="initrd=$nbi_initrd $append_param_in_grub_cfg" |
| 168 | else |
| 169 | append_param_in_grub_cfg="$cl_gp_boot_param noeject $rootfs_location_opt" |
| 170 | append_param_in_pxe_cfg="initrd=$nbi_initrd $append_param_in_grub_cfg" |
| 171 | fi |
| 172 | ;; |
| 173 | esac |
| 174 | } # end of prepare_param_in_pxe_grub_cfg |
| 175 | # |
| 176 | create_linuxrc_pxe_initrd_with_rootfs_insertedscip-shell shell shell-project 0.0.0 create_linuxrc_pxe_initrd_with_rootfs_inserted().(){ |
| 177 | case "$initrd_type" in |
| 178 | ext2) |
| 179 | # prepare the size for initrd. |
| 180 | iso_size="$(statscip-shell system . . stat. -c "%s" $SL_ISO)" # unit: bytes |
| 181 | container_need_in_KB="$(echoscip-shell system . . echo. "scale=0; $iso_size * $buffer_ratio_for_iso_to_container / 1024.0" | bc -l)" # unit: KB |
| 182 | client_RAM_required="$(echoscip-shell system . . echo. "scale=0; $container_need_in_KB * $client_ram_to_initrd_ratio / 1024.0" | bc -l)" |
| 183 | # ramdisk_size is for client booting use (kernel parameter). |
| 184 | ramdisk_size="$container_need_in_KB" |
| 185 | echoscip-shell system . . echo. "New NBI initrd size (uncompressed): $container_need_in_KB KB. Use ramdisk_size=$ramdisk_size in bootparam." |
| 186 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 187 | echoscip-shell system . . echo. "$msg_RAM_size_for_SL_drbl_client: $client_RAM_required MB." |
| 188 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 189 | echoscip-shell system . . echo. "Creating the modified ramdisk will take a while, please be patient." |
| 190 | |
| 191 | # Unpack initrd |
| 192 | echoscip-shell system . . echo. 'Creating container...' |
| 193 | ddscip-shell system . . dd. if=/dev/zeroscip-shell filesystem . . `/dev/zero`. of=$wd/initrd.img bs=1024 count=$container_need_in_KB |
| 194 | echoscip-shell system . . echo. 'Formatting container...' |
| 195 | mkfs.ext2 -q -F -L "${SL_NAME}-initrd" $wd/initrd.img |
| 196 | echoscip-shell system . . echo. 'Unpacking old initrd...' |
| 197 | $uncompress_to_stdout "$oldinitrd" > $wd/oldinitrd.img |
| 198 | mkdirscip-shell system . . mkdir. $wd/initrd.tmp |
| 199 | mkdirscip-shell system . . mkdir. $wd/oldinitrd.tmp |
| 200 | # Mount initrd |
| 201 | mountscip-shell system . . mount. -o loop $wd/initrd.img $wd/initrd.tmp |
| 202 | mountscip-shell system . . mount. -o loop $wd/oldinitrd.img $wd/oldinitrd.tmp |
| 203 | # |
| 204 | if [scip-shell system . . `[`. -z "$SL_VER" ]; then |
| 205 | if [scip-shell system . . `[`. -e $wd/oldinitrd.tmp/PUPPYVERSION ]; then |
| 206 | SL_VER="$(catscip-shell system . . cat. $wd/oldinitrd.tmp/PUPPYVERSION)" |
| 207 | elif [scip-shell system . . `[`. -e $isomnt/GEEXBOX/etc/version ]; then |
| 208 | # only if the modified version exists, otherwise we ust default one. |
| 209 | SL_VER_TMP="$(catscip-shell system . . cat. $isomnt/GEEXBOX/etc/version)" |
| 210 | if [scip-shell system . . `[`. -e "$DRBL_SCRIPT_PATH/setup/files/$SL_NAME/$SL_VER_TMP/linuxrc.$SL_NAME-$SL_VER_TMP.drbl" ]; then |
| 211 | SL_VER="$SL_VER_TMP" |
| 212 | else |
| 213 | SL_VER="default" |
| 214 | fi |
| 215 | else |
| 216 | SL_VER="default" |
| 217 | fi |
| 218 | fi |
| 219 | |
| 220 | # |
| 221 | get_SL_rootfilescip-shell shell shell-project 0.0.0 get_SL_rootfile(). |
| 222 | prepare_param_in_pxe_grub_cfgscip-shell shell shell-project 0.0.0 prepare_param_in_pxe_grub_cfg(). |
| 223 | |
| 224 | echoscip-shell system . . echo. 'Copying content of the old initrd...' |
| 225 | ( cpscip-shell system . . cp. -a $wd/oldinitrd.tmp/* $wd/initrd.tmp ) |
| 226 | mkdirscip-shell system . . mkdir. -p $wd/initrd.tmp/$rootfile_path_in_initrd |
| 227 | echoscip-shell system . . echo. 'Copying root image...' |
| 228 | cpscip-shell system . . cp. -af $isomnt/$rootfile $wd/initrd.tmp/$rootfile_path_in_initrd/ |
| 229 | if [scip-shell system . . `[`. -n "$extra_sys_file" ]; then |
| 230 | cpscip-shell system . . cp. -af $isomnt/$extra_sys_file $wd/initrd.tmp/$rootfile_path_in_initrd/ |
| 231 | fi |
| 232 | if [scip-shell system . . `[`. "$use_modified_init" = "yes" ]; then |
| 233 | if [scip-shell system . . `[`. -e $DRBL_SCRIPT_PATH/setup/files/$SL_NAME/$SL_VER/linuxrc.$SL_NAME-$SL_VER.drbl ]; then |
| 234 | echoscip-shell system . . echo. "Copying modified linuxrc from $DRBL_SCRIPT_PATH/setup/files/$SL_NAME/$SL_VER/..." |
| 235 | cpscip-shell system . . cp. -f $DRBL_SCRIPT_PATH/setup/files/$SL_NAME/$SL_VER/linuxrc.$SL_NAME-$SL_VER.drbl $wd/initrd.tmp/linuxrc |
| 236 | else |
| 237 | echoscip-shell system . . echo. "Copying modified linuxrc from $DRBL_SCRIPT_PATH/setup/files/$SL_NAME/default/..." |
| 238 | cpscip-shell system . . cp. -f $DRBL_SCRIPT_PATH/setup/files/$SL_NAME/default/linuxrc.$SL_NAME-default.drbl $wd/initrd.tmp/linuxrc |
| 239 | fi |
| 240 | else |
| 241 | echoscip-shell system . . echo. "The linuxrc from $SL_FULL_NAME is ready for PXE boot." |
| 242 | fi |
| 243 | |
| 244 | # Umount initrd |
| 245 | umountscip-shell system . . umount. $wd/initrd.tmp |
| 246 | umountscip-shell system . . umount. $wd/oldinitrd.tmp |
| 247 | |
| 248 | # Pack the initrd again: |
| 249 | echoscip-shell system . . echo. 'Packing initrd...' |
| 250 | $compress_to_stdout $wd/initrd.img > $pxecfg_pd/$nbi_initrd |
| 251 | |
| 252 | # Remove the initrd |
| 253 | echoscip-shell system . . echo. 'Removing temporary copy of initrd...' |
| 254 | rmscip-shell system . . rm. $wd/initrd.img |
| 255 | # Remove the old original initrd |
| 256 | echoscip-shell system . . echo. 'Removing temporary copy of original initrd...' |
| 257 | rmscip-shell system . . rm. $wd/oldinitrd.img |
| 258 | |
| 259 | # Copy the linux kernel |
| 260 | cpscip-shell system . . cp. -f "$kernel" $pxecfg_pd/$nbi_kernel |
| 261 | ;; |
| 262 | |
| 263 | cpio) |
| 264 | mkdirscip-shell system . . mkdir. -p $wd/initrd.tmp |
| 265 | mkdirscip-shell system . . mkdir. -p $wd/oldinitrd.tmp |
| 266 | (cd $wd/oldinitrd.tmp/; $uncompress_to_stdout "$oldinitrd" | cpio -idm) |
| 267 | # |
| 268 | if [scip-shell system . . `[`. -z "$SL_VER" ]; then |
| 269 | if [scip-shell system . . `[`. -e $wd/oldinitrd.tmp/PUPPYVERSION ]; then |
| 270 | SL_VER="$(catscip-shell system . . cat. $wd/oldinitrd.tmp/PUPPYVERSION)" |
| 271 | else |
| 272 | SL_VER="default" |
| 273 | fi |
| 274 | fi |
| 275 | |
| 276 | # |
| 277 | get_SL_rootfilescip-shell shell shell-project 0.0.0 get_SL_rootfile(). |
| 278 | prepare_param_in_pxe_grub_cfgscip-shell shell shell-project 0.0.0 prepare_param_in_pxe_grub_cfg(). |
| 279 | |
| 280 | echoscip-shell system . . echo. 'Copying content of the old initrd...' |
| 281 | ( cpscip-shell system . . cp. -a $wd/oldinitrd.tmp/* $wd/initrd.tmp/ ) |
| 282 | mkdirscip-shell system . . mkdir. -p $wd/initrd.tmp/$rootfile_path_in_initrd |
| 283 | echoscip-shell system . . echo. 'Copying root image...' |
| 284 | cpscip-shell system . . cp. -a $isomnt/$rootfile $wd/initrd.tmp/$rootfile_path_in_initrd/ |
| 285 | if [scip-shell system . . `[`. -n "$extra_sys_file" ]; then |
| 286 | cpscip-shell system . . cp. -af $isomnt/$extra_sys_file $wd/initrd.tmp/$rootfile_path_in_initrd/ |
| 287 | fi |
| 288 | if [scip-shell system . . `[`. "$use_modified_init" = "yes" ]; then |
| 289 | echoscip-shell system . . echo. "Copying modified linuxrc from $DRBL_SCRIPT_PATH/setup/files/$SL_NAME/$SL_VER/..." |
| 290 | cpscip-shell system . . cp. -f $DRBL_SCRIPT_PATH/setup/files/$SL_NAME/$SL_VER/linuxrc.$SL_NAME-$SL_VER.drbl $wd/initrd.tmp/linuxrc |
| 291 | else |
| 292 | echoscip-shell system . . echo. "The linuxrc from $SL_FULL_NAME is ready for PXE boot." |
| 293 | fi |
| 294 | |
| 295 | # Pack the initrd again: |
| 296 | echoscip-shell system . . echo. "Packing the new initrd... $msg_this_might_take_several_minutes..." |
| 297 | (cd $wd/initrd.tmp/; findscip-shell system . . find. . | cpio -o -H newc | gzipscip-shell system . . gzip. -9 > $pxecfg_pd/$nbi_initrd) |
| 298 | |
| 299 | # Remove the working dir |
| 300 | echoscip-shell system . . echo. 'Removing temporary working dir...' |
| 301 | [scip-shell system . . `[`. -d "$wd" -a -n "$(echoscip-shell system . . echo. $wd | grepscip-shell system . . grep. "drbl_sl_wd")" ] && rmscip-shell system . . rm. -rf $wd |
| 302 | |
| 303 | # Copy the linux kernel |
| 304 | cpscip-shell system . . cp. -f "$kernel" $pxecfg_pd/$nbi_kernel |
| 305 | ;; |
| 306 | esac |
| 307 | } # end of create_linuxrc_pxe_initrd_with_rootfs_inserted |
| 308 | |
| 309 | # |
| 310 | put_pxe_initrd_without_rootfs_insertedscip-shell shell shell-project 0.0.0 put_pxe_initrd_without_rootfs_inserted().(){ |
| 311 | #///NOTE/// This function is deprecated! We keep it just in case we need in the future. |
| 312 | cpscip-shell system . . cp. -f $oldinitrd $pxecfg_pd/$nbi_initrd |
| 313 | initrd_size="$(statscip-shell system . . stat. -c "%s" $pxecfg_pd/$nbi_initrd)" # unit: bytes |
| 314 | initrd_size_in_KB=$(echoscip-shell system . . echo. "scale=0; $initrd_size / 1024.0" | bc -l) |
| 315 | client_RAM_required="$(echoscip-shell system . . echo. "scale=0; $initrd_size_in_KB * $client_ram_to_initrd_ratio / 1024.0" | bc -l)" |
| 316 | # ramdisk_size is for client booting use (kernel parameter). |
| 317 | ramdisk_size="$initrd_size_in_KB" |
| 318 | echoscip-shell system . . echo. "New NBI initrd size (uncompressed): $initrd_size_in_KB KB. Use ramdisk_size=$ramdisk_size in bootparam." |
| 319 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 320 | echoscip-shell system . . echo. "$msg_RAM_size_for_SL_drbl_client: $client_RAM_required MB." |
| 321 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 322 | get_SL_rootfilescip-shell shell shell-project 0.0.0 get_SL_rootfile(). |
| 323 | prepare_param_in_pxe_grub_cfgscip-shell shell shell-project 0.0.0 prepare_param_in_pxe_grub_cfg(). |
| 324 | # Copy the linux kernel |
| 325 | cpscip-shell system . . cp. -f $kernel $pxecfg_pd/$nbi_kernel |
| 326 | chmodscip-shell system . . chmod. 644 $pxecfg_pd/$nbi_kernel $pxecfg_pd/$nbi_initrd |
| 327 | } # end of put_pxe_initrd_without_rootfs_inserted |
| 328 | # |
| 329 | create_casper_pxe_initrd_with_rootfs_insertedscip-shell shell shell-project 0.0.0 create_casper_pxe_initrd_with_rootfs_inserted().(){ |
| 330 | #///NOTE/// This function is deprecated! We keep it just in case we need in the future. |
| 331 | case "$(echoscip-shell system . . echo. $SL_OS | trscip-shell system . . tr. "[A-Z]" "[a-z]")" in |
| 332 | debian-live-etch|Debian-live) |
| 333 | [scip-shell system . . `[`. -z "$SL_VER" ] && SL_VER="etch" |
| 334 | get_SL_rootfilescip-shell shell shell-project 0.0.0 get_SL_rootfile(). |
| 335 | # it's initramfs, so no more loop mount, just use cpio |
| 336 | mkdirscip-shell system . . mkdir. $wd/initrd.tmp |
| 337 | (cd $wd/initrd.tmp; $uncompress_to_stdout "$oldinitrd" | cpio -idm) |
| 338 | mkdirscip-shell system . . mkdir. -p $wd/initrd.tmp/$rootfile_path_in_initrd |
| 339 | echoscip-shell system . . echo. "Copying root image. $msg_this_might_take_several_minutes" |
| 340 | cpscip-shell system . . cp. -f $isomnt/$rootfile $wd/initrd.tmp/$rootfile_path_in_initrd/ |
| 341 | if [scip-shell system . . `[`. "$use_modified_init" = "yes" ]; then |
| 342 | echoscip-shell system . . echo. "Copying modified casper from $DRBL_SCRIPT_PATH/setup/files/$SL_NAME/$SL_VER/..." |
| 343 | cpscip-shell system . . cp. -f $DRBL_SCRIPT_PATH/setup/files/$SL_NAME/$SL_VER/casper.$SL_NAME-$SL_VER.drbl $wd/initrd.tmp/scripts/casper |
| 344 | fi |
| 345 | # create initramfs |
| 346 | echoscip-shell system . . echo. "Creating initramfs $pxecfg_pd/$nbi_initrd, $msg_this_might_take_several_minutes" |
| 347 | ( cd $wd/initrd.tmp |
| 348 | findscip-shell system . . find. . | cpio --quiet -o -H newc | gzipscip-shell system . . gzip. -9 > $pxecfg_pd/$nbi_initrd |
| 349 | ) |
| 350 | initramfs_size="$(statscip-shell system . . stat. -c "%s" $pxecfg_pd/$nbi_initrd)" # unit: bytes |
| 351 | initramfs_size_in_KB=$(echoscip-shell system . . echo. "scale=0; $initramfs_size / 1024.0" | bc -l) |
| 352 | client_RAM_required="$(echoscip-shell system . . echo. "scale=0; $initramfs_size_in_KB * $client_ram_to_initrd_ratio / 1024.0" | bc -l)" |
| 353 | # initramfs, we do not have to assign ramdisk_size in bootparam. |
| 354 | echoscip-shell system . . echo. "The new initrd size is: $initramfs_size_in_KB KB." |
| 355 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 356 | echoscip-shell system . . echo. "$msg_RAM_size_for_SL_drbl_client: $client_RAM_required MB." |
| 357 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 358 | prepare_param_in_pxe_grub_cfgscip-shell shell shell-project 0.0.0 prepare_param_in_pxe_grub_cfg(). |
| 359 | cpscip-shell system . . cp. -f $kernel $pxecfg_pd/$nbi_kernel |
| 360 | chmodscip-shell system . . chmod. 644 $pxecfg_pd/$nbi_kernel $pxecfg_pd/$nbi_initrd |
| 361 | ;; |
| 362 | PUD|pud) |
| 363 | if [scip-shell system . . `[`. -z "$SL_VER" ]; then |
| 364 | # iso file name is like PUD-0.4.6.10.iso, try to guess. |
| 365 | SL_VER="$(basenamescip-shell system . . basename. $SL_ISO | sedscip-shell system . . sed. -e "s/^PUD-//g" -e "s/.iso$//g")" |
| 366 | fi |
| 367 | get_SL_rootfilescip-shell shell shell-project 0.0.0 get_SL_rootfile(). |
| 368 | # it's initramfs, so no more loop mount, just use cpio |
| 369 | mkdirscip-shell system . . mkdir. $wd/initrd.tmp |
| 370 | (cd $wd/initrd.tmp; $uncompress_to_stdout "$oldinitrd" | cpio -idm) |
| 371 | mkdirscip-shell system . . mkdir. -p $wd/initrd.tmp/$rootfile_path_in_initrd |
| 372 | echoscip-shell system . . echo. "Copying root image. $msg_this_might_take_several_minutes" |
| 373 | cpscip-shell system . . cp. -f $isomnt/$rootfile $wd/initrd.tmp/$rootfile_path_in_initrd/ |
| 374 | if [scip-shell system . . `[`. "$use_modified_init" = "yes" ]; then |
| 375 | echoscip-shell system . . echo. "Copying modified casper from $DRBL_SCRIPT_PATH/setup/files/$SL_NAME/$SL_VER/..." |
| 376 | cpscip-shell system . . cp. -f $DRBL_SCRIPT_PATH/setup/files/$SL_NAME/$SL_VER/casper.$SL_NAME-$SL_VER.drbl $wd/initrd.tmp/scripts/casper |
| 377 | else |
| 378 | echoscip-shell system . . echo. "The linuxrc from $SL_FULL_NAME is ready for PXE boot." |
| 379 | fi |
| 380 | # create initramfs |
| 381 | echoscip-shell system . . echo. "Creating initramfs $pxecfg_pd/$nbi_initrd, $msg_this_might_take_several_minutes" |
| 382 | ( cd $wd/initrd.tmp |
| 383 | findscip-shell system . . find. . | cpio --quiet -o -H newc | gzipscip-shell system . . gzip. -9 > $pxecfg_pd/$nbi_initrd |
| 384 | ) |
| 385 | initramfs_size="$(statscip-shell system . . stat. -c "%s" $pxecfg_pd/$nbi_initrd)" # unit: bytes |
| 386 | initramfs_size_in_KB=$(echoscip-shell system . . echo. "scale=0; $initramfs_size / 1024.0" | bc -l) |
| 387 | client_RAM_required="$(echoscip-shell system . . echo. "scale=0; $initramfs_size_in_KB * $client_ram_to_initrd_ratio / 1024.0" | bc -l)" |
| 388 | # initramfs, we do not have to assign ramdisk_size in bootparam. |
| 389 | echoscip-shell system . . echo. "The new initrd size is: $initramfs_size_in_KB KB." |
| 390 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 391 | echoscip-shell system . . echo. "$msg_RAM_size_for_SL_drbl_client: $client_RAM_required MB." |
| 392 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 393 | prepare_param_in_pxe_grub_cfgscip-shell shell shell-project 0.0.0 prepare_param_in_pxe_grub_cfg(). |
| 394 | cpscip-shell system . . cp. -f $kernel $pxecfg_pd/$nbi_kernel |
| 395 | chmodscip-shell system . . chmod. 644 $pxecfg_pd/$nbi_kernel $pxecfg_pd/$nbi_initrd |
| 396 | ;; |
| 397 | esac |
| 398 | } # end of create_casper_pxe_initrd_with_rootfs_inserted |
| 399 | # |
| 400 | put_kernel_initrd_root_fs_on_pxe_serverscip-shell shell shell-project 0.0.0 put_kernel_initrd_root_fs_on_pxe_server().() { |
| 401 | # Copy the linux kernel |
| 402 | echoscip-shell system . . echo. "Copying kernel $kernel as $pxecfg_pd/$nbi_kernel..." |
| 403 | cpscip-shell system . . cp. -af $kernel $pxecfg_pd/$nbi_kernel |
| 404 | echoscip-shell system . . echo. "Copying initrd $oldinitrd as $pxecfg_pd/$nbi_initrd..." |
| 405 | cpscip-shell system . . cp. -af $oldinitrd $pxecfg_pd/$nbi_initrd |
| 406 | get_SL_rootfilescip-shell shell shell-project 0.0.0 get_SL_rootfile(). |
| 407 | case "$rootfs_location" in |
| 408 | "fetch") |
| 409 | echoscip-shell system . . echo. "Copying root image $isomnt/$rootfile to $pxecfg_pd... $msg_this_might_take_several_minutes" |
| 410 | case "$use_link_in_fetch_mode" in |
| 411 | yes) lnscip-shell system . . ln. -fsv $isomnt/$rootfile $pxecfg_pd/$squashfs_file ;; |
| 412 | no) rsyncscip-shell system . . rsync. -aP $isomnt/$rootfile $pxecfg_pd/$squashfs_file ;; |
| 413 | esac |
| 414 | ;; |
| 415 | "nfsroot") |
| 416 | echoscip-shell system . . echo. "Copying root image $isomnt/$rootfile to $drbl_common_root/clonezilla-live/... $msg_this_might_take_several_minutes" |
| 417 | mkdirscip-shell system . . mkdir. -p $drbl_common_root/clonezilla-live/live/ |
| 418 | # In DRBL live server when unfs3 is used, we can use mount --bind to make this |
| 419 | if is_drbl_live_env; then |
| 420 | if mountpointscip-shell system . . mountpoint. $drbl_common_root/clonezilla-live/live/ &>/dev/nullscip-shell filesystem . . `/dev/null`. ; then |
| 421 | umountscip-shell system . . umount. $drbl_common_root/clonezilla-live/live/ |
| 422 | fi |
| 423 | mountscip-shell system . . mount. --bind $isomnt/$rootfile_path $drbl_common_root/clonezilla-live/live/ |
| 424 | else |
| 425 | rsyncscip-shell system . . rsync. -aP $isomnt/$rootfile $drbl_common_root/clonezilla-live/live/ |
| 426 | fi |
| 427 | ;; |
| 428 | esac |
| 429 | prepare_param_in_pxe_grub_cfgscip-shell shell shell-project 0.0.0 prepare_param_in_pxe_grub_cfg(). |
| 430 | chmodscip-shell system . . chmod. 644 $pxecfg_pd/$nbi_kernel $pxecfg_pd/$nbi_initrd |
| 431 | } # end of put_kernel_initrd_root_fs_on_pxe_server |
| 432 | # |
| 433 | umount_and_clean_tmp_working_dirsscip-shell shell shell-project 0.0.0 umount_and_clean_tmp_working_dirs().(){ |
| 434 | if [scip-shell system . . `[`. "$iso_mnt_flag" = "true" ]; then |
| 435 | # It's mounted by this program. |
| 436 | if mountpointscip-shell system . . mountpoint. $isomnt &>/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 437 | umountscip-shell system . . umount. $isomnt |
| 438 | fi |
| 439 | fi |
| 440 | [scip-shell system . . `[`. -d "$isomnt" -a -n "$(echoscip-shell system . . echo. $isomnt | grepscip-shell system . . grep. "drblsl_tmp")" ] && rmscip-shell system . . rm. -rf $isomnt |
| 441 | [scip-shell system . . `[`. -d "$wd" -a -n "$(echoscip-shell system . . echo. $wd | grepscip-shell system . . grep. "drbl_sl_wd")" ] && rmscip-shell system . . rm. -rf $wd |
| 442 | } # end of umount_and_clean_tmp_working_dirs |
| 443 | # |
| 444 | get_SL_OS_NAMEscip-shell shell shell-project 0.0.0 get_SL_OS_NAME().(){ |
| 445 | if [scip-shell system . . `[`. "$(echoscip-shell system . . echo. $SL_ISO | grepscip-shell system . . grep. -i "clonezilla-live")" ]; then |
| 446 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 447 | echoscip-shell system . . echo. "This ISO file $SL_ISO is for Clonezilla live." |
| 448 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 449 | SL_OS="clonezilla-live" |
| 450 | elif [scip-shell system . . `[`. "$(echoscip-shell system . . echo. $SL_ISO | grepscip-shell system . . grep. -i "gparted-live")" ]; then |
| 451 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 452 | echoscip-shell system . . echo. "This ISO file $SL_ISO is for GParted live." |
| 453 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 454 | SL_OS="gparted-live" |
| 455 | else |
| 456 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE |
| 457 | echoscip-shell system . . echo. "Unknown Small Linux distribution! This script only works with $supported_SL_dists! Program terminated!!!" |
| 458 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 459 | exit 1 |
| 460 | fi |
| 461 | } # end of get_SL_OS_NAME |
| 462 | |
| 463 | # |
| 464 | install_SLscip-shell shell shell-project 0.0.0 install_SL().(){ |
| 465 | # 2 cases, (1) live iso/zip (2) path where iso is mounted or zip is uncompressed. |
| 466 | # Case (1) |
| 467 | local grub_cfg_f lines begin_line end_line search_cmd |
| 468 | if [scip-shell system . . `[`. "$source_mode" = "iso-zip" ]; then |
| 469 | if [scip-shell system . . `[`. -z "$SL_ISO" ]; then |
| 470 | USAGEscip-shell shell shell-project 0.0.0 USAGE(). |
| 471 | exit 1 |
| 472 | fi |
| 473 | |
| 474 | if [scip-shell system . . `[`. ! -f "$SL_ISO" ]; then |
| 475 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE |
| 476 | echoscip-shell system . . echo. "$SL_ISO is NOT found!" |
| 477 | echoscip-shell system . . echo. "You have to prepare the iso file. For example, if you want to use Clonezilla live, you can get it via this command:" |
| 478 | echoscip-shell system . . echo. "wget $SL_ISO_URL_EXAMPLE" |
| 479 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 480 | exit 1 |
| 481 | fi |
| 482 | |
| 483 | # Program file might give different results: |
| 484 | # ISO 9660 CD-ROM filesystem data # file vesion 5.03 |
| 485 | # x86 boot sector # file version 4.10 |
| 486 | # For file version 5.17 in Jessie: |
| 487 | # debian-7.4.0-i386-netinst.iso: DOS/MBR boot sector; partition 1 : ID=0x17, active, start-CHS (0x0,2,1), end-CHS (0x114,63,32), startsector 64, 567232 sectors |
| 488 | case "$SL_ISO" in |
| 489 | *.iso) |
| 490 | if [scip-shell system . . `[`. -z "$(LC_ALL=C filescip-shell system . . file. -Lsk $SL_ISO | grepscip-shell system . . grep. -i "ISO 9660 CD-ROM filesystem data")" ] &&\ |
| 491 | [ -z "$(LC_ALL=C filescip-shell system . . file. -Lsk $SL_ISO | grepscip-shell system . . grep. -i "x86 boot sector")" ] &&\ |
| 492 | [ -z "$(LC_ALL=C filescip-shell system . . file. -Lsk $SL_ISO | grepscip-shell system . . grep. -i "DOS/MBR boot sector")" ] |
| 493 | then |
| 494 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE |
| 495 | echoscip-shell system . . echo. "$SL_ISO is not an ISO 9660 CD-ROM filesystem data file!" |
| 496 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 497 | echoscip-shell system . . echo. "Program terminated!" |
| 498 | exit 1 |
| 499 | fi |
| 500 | ;; |
| 501 | *.zip) |
| 502 | if [scip-shell system . . `[`. -z "$(LC_ALL=C filescip-shell system . . file. -Lsk $SL_ISO | grepscip-shell system . . grep. -i "Zip archive data")" ] |
| 503 | then |
| 504 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE |
| 505 | echoscip-shell system . . echo. "$SL_ISO is not a zip file!" |
| 506 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 507 | echoscip-shell system . . echo. "Program terminated!" |
| 508 | exit 1 |
| 509 | fi |
| 510 | ;; |
| 511 | esac |
| 512 | elif [scip-shell system . . `[`. "$source_mode" = "live-path" ]; then |
| 513 | # Case (2): live-path. From the 1st line in file |
| 514 | # /lib/live/mount/medium/{Clonezilla-Live-Version,DRBL-Live-Version,GParted-Live-Version} |
| 515 | # we can get the file name. Its content is like: |
| 516 | # ================================== |
| 517 | # clonezilla-live-2.4.2-49-i686-pae |
| 518 | # This Clonezilla live iso file was created by this command: |
| 519 | # ocs-iso -s --extra-boot-param quiet -y 6.03 -i 2.4.2-49-i686-pae |
| 520 | # ================================== |
| 521 | # Jun/15/2016 In order to work with toram=live mechanism, we also put those *-Live-Version |
| 522 | # in /lib/live/mount/medium/live/, therefore we have check these files, too |
| 523 | # /lib/live/mount/medium/live/{Clonezilla-Live-Version,DRBL-Live-Version,GParted-Live-Version} |
| 524 | # //NOTE// For backward compatibility both of these two types of files have to be checked. |
| 525 | # User might use newer DRBL environment to deploy old version of clonezilla/drbl/gparted live. |
| 526 | if [scip-shell system . . `[`. -e "$LIVE_PATH/Clonezilla-Live-Version" ]; then |
| 527 | SL_ISO="$(headscip-shell system . . head. -n 1 $LIVE_PATH/Clonezilla-Live-Version)" |
| 528 | elif [scip-shell system . . `[`. -e "$LIVE_PATH/live/Clonezilla-Live-Version" ]; then |
| 529 | SL_ISO="$(headscip-shell system . . head. -n 1 $LIVE_PATH/live/Clonezilla-Live-Version)" |
| 530 | elif [scip-shell system . . `[`. -e "$LIVE_PATH/DRBL-Live-Version" -o \ |
| 531 | -e "$LIVE_PATH/live/DRBL-Live-Version" ]; then |
| 532 | # To avoid confusion, we switch drbl-live to Clonezilla live since this small linux won't be really DRBL, we just need it work as Clonezilla live. |
| 533 | #SL_ISO="$(head -n 1 $LIVE_PATH/DRBL-Live-Version)" |
| 534 | SL_ISO="clonezilla-live-0.0.0-0" |
| 535 | elif [scip-shell system . . `[`. -e "$LIVE_PATH/GParted-Live-Version" ]; then |
| 536 | SL_ISO="$(headscip-shell system . . head. -n 1 $LIVE_PATH/GParted-Live-Version)" |
| 537 | elif [scip-shell system . . `[`. -e "$LIVE_PATH/live/GParted-Live-Version" ]; then |
| 538 | SL_ISO="$(headscip-shell system . . head. -n 1 $LIVE_PATH/live/GParted-Live-Version)" |
| 539 | else |
| 540 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE |
| 541 | echoscip-shell system . . echo. "File $LIVE_PATH/Clonezilla-Live-Version, $LIVE_PATH/DRBL-Live-Version, $LIVE_PATH/GParted-Live-Version, or" |
| 542 | echoscip-shell system . . echo. "$LIVE_PATH/live/Clonezilla-Live-Version, $LIVE_PATH/live/DRBL-Live-Version or $LIVE_PATH/live/GParted-Live-Version not found!" |
| 543 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 544 | echoscip-shell system . . echo. "$msg_program_stop." |
| 545 | echoscip-shell system . . echo. -n "$msg_press_enter_to_continue..." |
| 546 | read |
| 547 | exit 1 |
| 548 | fi |
| 549 | fi |
| 550 | # get SL_OS name from iso file name |
| 551 | # Ugly, since it's not easy to know which one is which one, here we just judge them by file name. |
| 552 | [scip-shell system . . `[`. -z "$SL_OS" ] && get_SL_OS_NAMEscip-shell shell shell-project 0.0.0 get_SL_OS_NAME(). |
| 553 | |
| 554 | # Assign different usernames for the clonezilla/drbl/gparted live (RAM) clients. |
| 555 | # E.g. |
| 556 | # clonezilla-live -> clonezilla |
| 557 | # drbl-live -> drbl |
| 558 | assgned_username="$(echoscip-shell system . . echo. $SL_OS | trscip-shell system . . tr. "[A-Z]" "[a-z]" | awkscip-shell system . . awk. -F"-" '{print $1}')" |
| 559 | |
| 560 | # Some settings for SL |
| 561 | # insert_rootfs=yes => we have to put the root/main filesystem from SL in initrd |
| 562 | # init_type: linuxrc or casper |
| 563 | # use_modified_init: yes or no. |
| 564 | # 2 types of init: linuxrc or casper. Some are not ready for PXE, we have to mofify, some are ready. |
| 565 | # Basically there are 6 types of SL: |
| 566 | # (1) linuxrc is ready for PXE, initrd is ready for PXE (insert_rootfs=no, use_modified_init=no). Actually if insert_rootfs=no, use_modified_init must be no. Ex: PLD |
| 567 | # (2) linuxrc is ready for PXE, initrd is NOT ready for PXE (insert_rootfs=yes, use_modified_init=no). Ex: Insert 1.39a or later |
| 568 | # (3) linuxrc is NOT ready for PXE, initrd is NOT ready for PXE (insert_rootfs=yesyes, use_modified_init=yes). Ex:DSL, PuppyLinux, GeeXbox |
| 569 | # (4) casper is ready for PXE, initrd is ready for PXE (insert_rootfs=no, use_modified_init=yes). Actually no such SL now (2007/02/19), maybe in the future when they accept our patch. |
| 570 | # (5) casper is NOT ready for PXE, initrd is NOT ready for PXE (insert_rootfs=yes, use_modified_init=yes). Ex: Debian Live, PUD. |
| 571 | # (6) casper is ready for PXE, initrd is NOT ready for PXE (insert_rootfs=yes, use_modified_init=yes). Actually no such SL now (2007/02/19), maybe in the future when they accept our patch. |
| 572 | |
| 573 | case "$(echoscip-shell system . . echo. $SL_OS | trscip-shell system . . tr. "[A-Z]" "[a-z]")" in |
| 574 | dsl|DamnSmallLinux) |
| 575 | # SL_NAME: in one word |
| 576 | SL_NAME="DSL" |
| 577 | SL_FULL_NAME="Damn Small Linux" |
| 578 | # e.g. dsl-4.4.10.iso -> 4.4.10 |
| 579 | SL_VER="$(basenamescip-shell system . . basename. $SL_ISO | sedscip-shell system . . sed. -e "s/^dsl-//g" -e "s/.iso$//g")" |
| 580 | # In DSL, boot kernel files are linux24 and minirt24.gz in /boot/isolinux/ |
| 581 | bootfiles_path="/boot/isolinuxscip-shell filesystem . . `/boot/isolinux`." |
| 582 | # in DSL, it's cloop file /cdrom/KNOPPIX/KNOPPIX |
| 583 | rootfile_path="/KNOPPIXscip-shell filesystem . . `/KNOPPIX`." |
| 584 | rootfile_path_in_initrd="/cdrom/KNOPPIXscip-shell filesystem . . `/cdrom/KNOPPIX`." |
| 585 | insert_rootfs="yes" |
| 586 | init_type="linuxrc" |
| 587 | use_modified_init="yes" |
| 588 | initrd_type="ext2" |
| 589 | squashfs="no" |
| 590 | ;; |
| 591 | puppy|PuppyLinux) |
| 592 | # SL_NAME: in one word |
| 593 | SL_NAME="PuppyLinux" |
| 594 | SL_FULL_NAME="Puppy Linux" |
| 595 | # In PuppyLinux, boot kernel files are vmlinuz and initrd.gz in / |
| 596 | bootfiles_path="/scip-shell filesystem . . `/`." |
| 597 | # in PuppyLinux, it's squashfs, name is like pup_211.sfs in / |
| 598 | rootfile_path="/scip-shell filesystem . . `/`." |
| 599 | rootfile_path_in_initrd="/scip-shell filesystem . . `/`." |
| 600 | insert_rootfs="yes" |
| 601 | init_type="linuxrc" |
| 602 | use_modified_init="yes" |
| 603 | initrd_type="cpio" |
| 604 | squashfs="no" |
| 605 | ;; |
| 606 | clonezilla-live|gparted-live) |
| 607 | # SL_NAME: in one word |
| 608 | case "$(echoscip-shell system . . echo. $SL_OS | trscip-shell system . . tr. "[A-Z]" "[a-z]")" in |
| 609 | clonezilla-live) |
| 610 | SL_NAME="Clonezilla-live" |
| 611 | SL_FULL_NAME="Clonezilla Live" |
| 612 | # e.g. clonezilla-live-1.2.2-14.iso -> 1.2.2-14 |
| 613 | SL_VER="$(basenamescip-shell system . . basename. $SL_ISO | sedscip-shell system . . sed. -e "s/^clonezilla-live-//g" -e "s/.iso$//g" -e "s/.zip$//g")" |
| 614 | ;; |
| 615 | gparted-live) |
| 616 | SL_NAME="GParted-live" |
| 617 | SL_FULL_NAME="GParted Live" |
| 618 | # e.g. gparted-live-0.4.5-2.iso -> 0.4.5-2 |
| 619 | SL_VER="$(basenamescip-shell system . . basename. $SL_ISO | sedscip-shell system . . sed. -e "s/^gparted-live-//g" -e "s/.iso$//g" -e "s/.zip$//g")" |
| 620 | ;; |
| 621 | esac |
| 622 | # In Clonezilla/GParted live, boot kernel file is vmlinuz1 in /isolinux/ |
| 623 | bootfiles_path="/livescip-shell filesystem . . `/live`." |
| 624 | # in Clonezilla/GParted live, name is like /live/filesystem.squashfs |
| 625 | rootfile_path="/livescip-shell filesystem . . `/live`." |
| 626 | rootfile_path_in_initrd="" # useless |
| 627 | insert_rootfs="no" |
| 628 | init_type="live" |
| 629 | use_modified_init="no" |
| 630 | initrd_type="" # useless |
| 631 | squashfs="yes" |
| 632 | ;; |
| 633 | esac |
| 634 | |
| 635 | # |
| 636 | if [scip-shell system . . `[`. "$batch_mode" != "on" ]; then |
| 637 | echoscip-shell system . . echo. "$msg_delimiter_star_line" |
| 638 | echoscip-shell system . . echo. "$msg_this_script_will_create_SL_diskless: $SL_FULL_NAME" |
| 639 | echoscip-shell system . . echo. -n "$msg_are_u_sure_u_want_to_continue [Y/n] " |
| 640 | read confirm_ans |
| 641 | case "$confirm_ans" in |
| 642 | n|N|[nN][oO]) |
| 643 | echoscip-shell system . . echo. "$msg_program_stop" |
| 644 | exit 1 |
| 645 | ;; |
| 646 | *) |
| 647 | echoscip-shell system . . echo. "$msg_ok_let_do_it" |
| 648 | ;; |
| 649 | esac |
| 650 | fi |
| 651 | |
| 652 | # |
| 653 | if [scip-shell system . . `[`. "$source_mode" = "iso-zip" ]; then |
| 654 | iso_mnt_flag="" |
| 655 | isomnt="$(mktempscip-shell system . . mktemp. -d /tmp/drblsl_tmp.XXXXXXscip-shell filesystem . . `/tmp/drblsl_tmp.XXXXXX`.)" |
| 656 | wd="$(mktempscip-shell system . . mktemp. -d drbl_sl_wd.XXXXXX)" |
| 657 | if [scip-shell system . . `[`. -n "$(echoscip-shell system . . echo. $SL_ISO | grepscip-shell system . . grep. -iE "\.iso")" ]; then |
| 658 | echoscip-shell system . . echo. "Mounting the iso file $SL_ISO at mounting point $isomnt" |
| 659 | mountscip-shell system . . mount. -o loop $SL_ISO $isomnt |
| 660 | iso_mnt_flag="true" |
| 661 | elif [scip-shell system . . `[`. -n "$(echoscip-shell system . . echo. $SL_ISO | grepscip-shell system . . grep. -iE "\.zip")" ]; then |
| 662 | unzip $SL_ISO -d $isomnt |
| 663 | else |
| 664 | echoscip-shell system . . echo. "$SL_ISO: Unknown file format! Program terminated!" |
| 665 | fi |
| 666 | elif [scip-shell system . . `[`. "$source_mode" = "live-path" ]; then |
| 667 | isomnt="$LIVE_PATH" |
| 668 | fi |
| 669 | |
| 670 | # Find kernel |
| 671 | echoscip-shell system . . echo. "Finding the kernel and initrd from iso..." |
| 672 | for i in $isomnt/$bootfiles_path/*; do |
| 673 | # sometimes it's "Linux kernel x86", sometimes it's "Linux x86 kernel" |
| 674 | # In Ubuntu Sarge (file 4.17-2ubuntu1): |
| 675 | # For DSL: linux24: Linux x86 kernel root=0x301-ro vga=normal, bzImage, version 2.4.26 (root@Knoppix) #1 SMP Sa |
| 676 | # For Puppy: vmlinuz: Linux kernel x86 boot executable RO-rootFS, root_dev 0x341, swap_dev 0x1, Normal VGA |
| 677 | # For INSERT: vmlinuz: Linux kernel x86 boot executable RO-rootFS, root_dev 0x806, swap_dev 0x1, Normal VGA |
| 678 | # The problem is that, for some distribution, like INSERT, there is another file "memtest86": memtest86: Linux x86 kernel |
| 679 | # For Clonezilla live iso, there is another one: eb.zli (etherboot) |
| 680 | # For old file, like Debian Sarge (file 4.12-1) or RH9 (file-3.39-9): |
| 681 | # In Debian Sarge: vmlinuz-2.6.8-2-686: x86 boot sector |
| 682 | # In RH9: vmlinuz-2.4.20-28.9smp: x86 boot sector |
| 683 | # In OpenSuSE 11.3: "file -Ls vmlinuz" gives: |
| 684 | # vmlinuz: Linux/x86 Kernel, Setup Version 0x20a, bzImage, Version 3.2.0, Version 3.2.0-24, RO-rootFS, swap_dev 0x4, Normal VGA |
| 685 | if [scip-shell system . . `[`. -n "$(LC_ALL=C filescip-shell system . . file. -Lsk $i | grepscip-shell system . . grep. -iE "(Linux x86 kernel|Linux kernel x86 boot executable|Linux\/x86 Kernel|x86 boot sector)")" ]; then |
| 686 | # Ugly |
| 687 | # we skip memtest, etherboot, ipxe, freedos... |
| 688 | if [scip-shell system . . `[`. -z "$(LC_ALL=C echoscip-shell system . . echo. $i | grepscip-shell system . . grep. -iE "(memtest|mt86|eb.zli|memdisk|gpxe.lkn|ipxe.lkn|ipxe.efi|freedos|fdos)")" ]; then |
| 689 | kernel="$i" |
| 690 | break |
| 691 | fi |
| 692 | fi |
| 693 | done |
| 694 | if [scip-shell system . . `[`. -n "$kernel" ]; then |
| 695 | echoscip-shell system . . echo. "Found the kernel: $kernel" |
| 696 | else |
| 697 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE |
| 698 | echoscip-shell system . . echo. "The kernel does NOT exist! Program terminated!" |
| 699 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 700 | umount_and_clean_tmp_working_dirsscip-shell shell shell-project 0.0.0 umount_and_clean_tmp_working_dirs(). |
| 701 | exit 1 |
| 702 | fi |
| 703 | |
| 704 | # Find initrd |
| 705 | # UGLY! Here we assume only one gzip/cpio file exists, and it's initrd. |
| 706 | for i in $isomnt/$bootfiles_path/* $isomnt/$rootfile_path/*; do |
| 707 | if [scip-shell system . . `[`. -n "$(LC_ALL=C filescip-shell system . . file. -Lsk $i | grepscip-shell system . . grep. -iE "gzip compressed data")" ]; then |
| 708 | oldinitrd="$i" |
| 709 | uncompress_to_stdout="gunzip -c" |
| 710 | compress_to_stdout="gzip -c" |
| 711 | break |
| 712 | elif [scip-shell system . . `[`. -n "$(LC_ALL=C filescip-shell system . . file. -Lsk $i | grepscip-shell system . . grep. -iE "XZ compressed data")" ]; then |
| 713 | oldinitrd="$i" |
| 714 | uncompress_to_stdout="xzcat" |
| 715 | compress_to_stdout="xz -c" |
| 716 | break |
| 717 | elif [scip-shell system . . `[`. -e "$(dirnamescip-shell system . . dirname. $i)/../Clonezilla-Live-Version" -a -n "$(echoscip-shell system . . echo. $i | grepscip-shell system . . grep. -iE "initrd.img")" ]; then |
| 718 | # This is a workaround for CentOS 5, since its "file" command won't tell XZ format. For Clonezilla live 2.x, we have used XZ format for initrd. |
| 719 | oldinitrd="$i" |
| 720 | uncompress_to_stdout="xzcat" |
| 721 | compress_to_stdout="xz -c" |
| 722 | break |
| 723 | elif [scip-shell system . . `[`. -n "$(LC_ALL=C echoscip-shell system . . echo. $i | grepscip-shell system . . grep. -iE "\/miniroot.lz$")" ]; then |
| 724 | # For INSERT, the initrd is miniroot.lz, which is lzma format. Most of the program file does not have the magic for that. |
| 725 | oldinitrd="$i" |
| 726 | |
| 727 | # There are two types of lzma, although they all said they are 4.32/4.33 |
| 728 | # (1) MDV2007, Ubuntu Etch |
| 729 | # LZMA 4.32 Copyright (c) 1999-2005 Igor Pavlov 2005-12-09 |
| 730 | # Usage: LZMA <e|d> inputFile outputFile [<switches>...] |
| 731 | # e: encode file |
| 732 | # d: decode file |
| 733 | # -si: read data from stdin |
| 734 | # -so: write data to stdout |
| 735 | # (2) Debian Etch |
| 736 | # lzma 4.32.0beta3 Copyright (C) 2006 Ville Koskinen |
| 737 | # Based on LZMA SDK 4.43 Copyright (C) 1999-2006 Igor Pavlov |
| 738 | # -c --stdout output to standard output |
| 739 | # -d --decompress force decompression |
| 740 | # -z --compress force compression |
| 741 | if [scip-shell system . . `[`. -n "$(LC_ALL=C lzmascip-shell system . . lzma. --h 2>&1 | grepscip-shell system . . grep. -iEw "\-so:")" ]; then |
| 742 | uncompress_to_stdout="lzma d -so" |
| 743 | compress_to_stdout="lzma e -so" |
| 744 | else |
| 745 | uncompress_to_stdout="lzma -d -c -S .lz" |
| 746 | compress_to_stdout="lzma -z -c" |
| 747 | fi |
| 748 | break |
| 749 | elif [scip-shell system . . `[`. -n "$(LC_ALL=C filescip-shell system . . file. -Lsk $i | grepscip-shell system . . grep. -i "ASCII cpio archive")" ]; then |
| 750 | oldinitrd="$i" |
| 751 | break |
| 752 | fi |
| 753 | done |
| 754 | if [scip-shell system . . `[`. -n "$oldinitrd" ]; then |
| 755 | echoscip-shell system . . echo. "Found the initrd: $oldinitrd" |
| 756 | else |
| 757 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE |
| 758 | echoscip-shell system . . echo. "The initrd does NOT exist! Program terminated!" |
| 759 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 760 | umount_and_clean_tmp_working_dirsscip-shell shell shell-project 0.0.0 umount_and_clean_tmp_working_dirs(). |
| 761 | exit 1 |
| 762 | fi |
| 763 | # we rename the NBI kernel and img, like dsl-linux24 and dsl-minirt24.gz |
| 764 | nbi_kernel="${SL_NAME}-${kernel##*/}" |
| 765 | nbi_initrd="${SL_NAME}-${oldinitrd##*/}" |
| 766 | if [scip-shell system . . `[`. "$squashfs" = "yes" ]; then |
| 767 | get_SL_rootfilescip-shell shell shell-project 0.0.0 get_SL_rootfile(). |
| 768 | squashfs_file="${SL_NAME}-${rootfile##*/}" |
| 769 | fi |
| 770 | # For Clonezilla/GParted live, we should try to find the boot parameters now |
| 771 | case "$(echoscip-shell system . . echo. $SL_OS | trscip-shell system . . tr. "[A-Z]" "[a-z]")" in |
| 772 | clonezilla-live|gparted-live) |
| 773 | initrd_filename="$(basenamescip-shell system . . basename. $oldinitrd)" |
| 774 | # The append line e.g.: |
| 775 | # append initrd=/live/initrd1.img boot=live union=aufs ocs_live_run="ocs-live-general" ocs_live_extra_param="" ocs_live_keymap="" ocs_live_batch="no" ocs_lang="" vga=791 nolocales |
| 776 | # We have to remove ip=frommedia because the /etc/resolv.conf got in live-boot (actually this program scripts/live-bottom/23networking) won't be copied to /etc/resolv.conf if ip=frommedia exists in boot parameters. |
| 777 | # 2012/Nov/1 The patched live-boot 2.0.15-1.drbl15 has fixed this issue, and live-boot 3.x has no such issue. Therefore no more removing ip=frommedia. |
| 778 | # 2014/Jan/19 The syslinux and isolinux dirs have been unified in one dir "syslinux" |
| 779 | if [scip-shell system . . `[`. -e $isomnt/boot/grub/grub.cfg ]; then |
| 780 | grub_cfg_f="$isomnt/boot/grub/grub.cfg" |
| 781 | else |
| 782 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE |
| 783 | echoscip-shell system . . echo. "File grub.cfg was _NOT_ found in live system!" |
| 784 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 785 | echoscip-shell system . . echo. "$msg_program_stop" |
| 786 | exit 1 |
| 787 | fi |
| 788 | # Assign and filter out the ocs_prerun* in case it's preseed by users. |
| 789 | # (1) ocs_prerun* |
| 790 | # (2) "drbl_live_noconfx" which we will add later |
| 791 | # (3) "username", we will add it later |
| 792 | # (4) more... Check function filter_cl_gp_boot_param. |
| 793 | # get the description from grub config. It's more precise than isolinux.cfg we used before. |
| 794 | # because we can locate default menu by "--id live-default". |
| 795 | lines="$(get_grub_efi_image_block live-default $grub_cfg_f)" |
| 796 | begin_line="$(echoscip-shell system . . echo. $lines | awkscip-shell system . . awk. -F" " '{print $1}')" |
| 797 | end_line="$(echoscip-shell system . . echo. $lines | awkscip-shell system . . awk. -F" " '{print $2}')" |
| 798 | search_cmd="if ($begin_line..$end_line) {print}" |
| 799 | cl_gp_boot_param="$(LC_ALL=C perlscip-shell system . . perl. -n -e "$search_cmd" $grub_cfg_f | \ |
| 800 | grep -iw "\$linux_cmd" | filter_cl_gp_boot_param)" |
| 801 | ;; |
| 802 | esac |
| 803 | |
| 804 | # |
| 805 | case "$insert_rootfs" in |
| 806 | yes) |
| 807 | case "$init_type" in |
| 808 | "linuxrc") create_linuxrc_pxe_initrd_with_rootfs_insertedscip-shell shell shell-project 0.0.0 create_linuxrc_pxe_initrd_with_rootfs_inserted(). ;; |
| 809 | "casper") create_casper_pxe_initrd_with_rootfs_insertedscip-shell shell shell-project 0.0.0 create_casper_pxe_initrd_with_rootfs_inserted(). ;; |
| 810 | esac |
| 811 | ;; |
| 812 | no) |
| 813 | case "$squashfs" in |
| 814 | "yes") put_kernel_initrd_root_fs_on_pxe_serverscip-shell shell shell-project 0.0.0 put_kernel_initrd_root_fs_on_pxe_server(). ;; |
| 815 | *) put_pxe_initrd_without_rootfs_insertedscip-shell shell shell-project 0.0.0 put_pxe_initrd_without_rootfs_inserted(). ;; |
| 816 | esac |
| 817 | ;; |
| 818 | esac |
| 819 | # |
| 820 | umount_and_clean_tmp_working_dirsscip-shell shell shell-project 0.0.0 umount_and_clean_tmp_working_dirs(). |
| 821 | |
| 822 | # append the config file in pxelinux dir. |
| 823 | if [scip-shell system . . `[`. -z "$(grepscip-shell system . . grep. -E "^[[:space:]]*label[[:space:]]+$SL_NAME[[:space:]]*$" $PXELINUX_DIR/default)" ] || [scip-shell system . . `[`. "$force_to_update_pxecfg" = "yes" ]; then |
| 824 | if [scip-shell system . . `[`. -n "$(grepscip-shell system . . grep. -E "^[[:space:]]*label[[:space:]]+$SL_NAME[[:space:]]*$" $PXELINUX_DIR/default)" ]; then |
| 825 | echoscip-shell system . . echo. "First removing $SL_NAME setting in $PXELINUX_DIR/default..." |
| 826 | delete_label_block_pxe_img $SL_NAME $PXELINUX_DIR/default |
| 827 | fi |
| 828 | echoscip-shell system . . echo. "Append the $SL_FULL_NAME config in $PXELINUX_DIR/default..." |
| 829 | catscip-shell system . . cat. <<-SL_PXE >> $PXELINUX_DIR/default |
| 830 | label $SL_NAME |
| 831 | # MENU DEFAULT |
| 832 | # MENU HIDE |
| 833 | MENU LABEL $SL_FULL_NAME $SL_VER (Ramdisk) |
| 834 | # MENU PASSWD |
| 835 | KERNEL $nbi_kernel |
| 836 | APPEND $append_param_in_pxe_cfg |
| 837 | |
| 838 | TEXT HELP |
| 839 | $SL_FULL_NAME $SL_VER runs on RAM |
| 840 | ENDTEXT |
| 841 | |
| 842 | SL_PXE |
| 843 | fi |
| 844 | |
| 845 | # append the config file in grub efi dir. |
| 846 | if [scip-shell system . . `[`. -z "$(grepscip-shell system . . grep. -E "^[[:space:]]*menuentry[[:space:]]+\"$SL_NAME\"[[:space:]]*--id clonezilla-live-client {$" $GRUB_EFINB_DIR/grub.cfg)" ] || [scip-shell system . . `[`. "$force_to_update_pxecfg" = "yes" ]; then |
| 847 | if [scip-shell system . . `[`. -n "$(grepscip-shell system . . grep. -E "^[[:space:]]*menuentry[[:space:]]+\"$SL_NAME\"[[:space:]]*--id clonezilla-live-client {$" $GRUB_EFINB_DIR/grub.cfg)" ]; then |
| 848 | echoscip-shell system . . echo. "First removing $SL_NAME setting in $GRUB_EFINB_DIR/grub.cfg..." |
| 849 | delete_menuentry_block_grub_img clonezilla-live-client $GRUB_EFINB_DIR/grub.cfg |
| 850 | fi |
| 851 | echoscip-shell system . . echo. "Append the $SL_FULL_NAME config in $GRUB_EFINB_DIR/grub.cfg..." |
| 852 | catscip-shell system . . cat. <<-SL_PXE >> $GRUB_EFINB_DIR/grub.cfg |
| 853 | menuentry "$SL_NAME $SL_VER (Ramdisk)" --id clonezilla-live-client { |
| 854 | # This is Clonezilla live especially to be run for Clonezilla SE. |
| 855 | # Do _NOT_ edit unless you know what you are doing! |
| 856 | echo "Enter $SL_FULL_NAME $SL_VER (Ramdisk)..." |
| 857 | echo 'Loading $nbi_kernel...' |
| 858 | \$linux_cmd $nbi_kernel $append_param_in_pxe_cfg |
| 859 | echo 'Loading initial ramdisk $nbi_initrd...' |
| 860 | \$initrd_cmd $nbi_initrd |
| 861 | } |
| 862 | |
| 863 | SL_PXE |
| 864 | fi |
| 865 | # Put the version number |
| 866 | catscip-shell system . . cat. <<-SL_INFO_PXE > $pxecfg_pd/${SL_NAME}-info.txt |
| 867 | $SL_FULL_NAME version: $SL_VER |
| 868 | Files were extracted from "$(basenamescip-shell system . . basename. $SL_ISO)" |
| 869 | SL_INFO_PXE |
| 870 | # Put the prompt messages |
| 871 | echoscip-shell system . . echo. "$msg_delimiter_star_line" |
| 872 | if [scip-shell system . . `[`. "$booting_messages" = "on" ]; then |
| 873 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 874 | echoscip-shell system . . echo. "$msg_all_set_you_can_turn_on_clients" |
| 875 | #echo "$msg_note! $msg_etherboot_5_4_is_required" |
| 876 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 877 | fi |
| 878 | } # end of install_SL |
| 879 | |
| 880 | # |
| 881 | uninstall_SLscip-shell shell shell-project 0.0.0 uninstall_SL().(){ |
| 882 | # convert |
| 883 | case "$SL_TO_BE_REMOVED" in |
| 884 | [aA][lL][lL]) |
| 885 | SL_TO_BE_REMOVED="$supported_SL_dists" |
| 886 | ;; |
| 887 | esac |
| 888 | echoscip-shell system . . echo. "Uninstalling installed Small Linux..." |
| 889 | for id in $SL_TO_BE_REMOVED; do |
| 890 | if [scip-shell system . . `[`. -z "$(echoscip-shell system . . echo. "$supported_SL_dists" | grepscip-shell system . . grep. -Ew "$id")" ]; then |
| 891 | echoscip-shell system . . echo. "$SL_TO_BE_REMOVED is an unknown Small Linux! Program terminated!" |
| 892 | exit 1 |
| 893 | fi |
| 894 | # remove the block in pxelinux |
| 895 | if [scip-shell system . . `[`. -n "$(grepscip-shell system . . grep. -E "^[[:space:]]*label[[:space:]]+$id[[:space:]]*$" $PXELINUX_DIR/default)" ]; then |
| 896 | echoscip-shell system . . echo. "Removing $id setting in $PXELINUX_DIR/default..." |
| 897 | delete_label_block_pxe_img $id $PXELINUX_DIR/default |
| 898 | fi |
| 899 | if [scip-shell system . . `[`. -n "$(grepscip-shell system . . grep. -E "^[[:space:]]*menuentry[[:space:]]+\"$SL_NAME\"[[:space:]]*--id clonezilla-live-client {$" $GRUB_EFINB_DIR/grub.cfg)" ]; then |
| 900 | echoscip-shell system . . echo. "First removing $SL_NAME setting in $GRUB_EFINB_DIR/grub.cfg..." |
| 901 | delete_menuentry_block_grub_img clonezilla-live-client $GRUB_EFINB_DIR/grub.cfg |
| 902 | fi |
| 903 | # remove vmlinuz and initrd |
| 904 | if [scip-shell system . . `[`. -n "$(lsscip-shell system . . ls. $pxecfg_pd/${id}-* 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" ]; then |
| 905 | echoscip-shell system . . echo. "Removing installed $id if it exists..." |
| 906 | rmscip-shell system . . rm. -fv $pxecfg_pd/${id}-* |
| 907 | fi |
| 908 | if ! is_drbl_live_env; then |
| 909 | # When it's not in drbl live env, the files are copied to $drbl_common_root/clonezilla-live/, therefore we remove them. Otherwise it's a mount point. |
| 910 | if [scip-shell system . . `[`. -d "$drbl_common_root/clonezilla-live/" ]; then |
| 911 | rmscip-shell system . . rm. -rfv $drbl_common_root/clonezilla-live/* |
| 912 | fi |
| 913 | fi |
| 914 | done |
| 915 | } # end of uninstall_SL |
| 916 | |
| 917 | ############# |
| 918 | ### MAIN ### |
| 919 | ############# |
| 920 | # |
| 921 | check_if_root |
| 922 | |
| 923 | # Parse command-line options |
| 924 | while [scip-shell system . . `[`. $# -gt 0 ]; do |
| 925 | case "$1" in |
| 926 | -b|--batch-mode) shift; batch_mode="on" ;; |
| 927 | -e|--fetch-link) shift; use_link_in_fetch_mode="yes" ;; |
| 928 | -l|--language) |
| 929 | shift |
| 930 | if [scip-shell system . . `[`. -z "$(echoscip-shell system . . echo. $1 |grepscip-shell system . . grep. ^-.)" ]; then |
| 931 | # skip the -xx option, in case |
| 932 | specified_lang="$1" |
| 933 | [scip-shell system . . `[`. -z "$specified_lang" ] && USAGEscip-shell shell shell-project 0.0.0 USAGE(). && exit 1 |
| 934 | shift |
| 935 | fi |
| 936 | ;; |
| 937 | -i|--install) |
| 938 | shift; mode="install" |
| 939 | if [scip-shell system . . `[`. -z "$(echoscip-shell system . . echo. $1 |grepscip-shell system . . grep. ^-.)" ]; then |
| 940 | # skip the -xx option, in case |
| 941 | SL_ISO="$1" |
| 942 | [scip-shell system . . `[`. -z "$SL_ISO" ] && USAGEscip-shell shell shell-project 0.0.0 USAGE(). && exit 1 |
| 943 | shift |
| 944 | fi |
| 945 | ;; |
| 946 | -p|--live-path) |
| 947 | shift; mode="install" |
| 948 | if [scip-shell system . . `[`. -z "$(echoscip-shell system . . echo. $1 |grepscip-shell system . . grep. ^-.)" ]; then |
| 949 | # skip the -xx option, in case |
| 950 | LIVE_PATH="$1" |
| 951 | [scip-shell system . . `[`. -z "$LIVE_PATH" ] && USAGEscip-shell shell shell-project 0.0.0 USAGE(). && exit 1 |
| 952 | shift |
| 953 | fi |
| 954 | ;; |
| 955 | -d|--distribution) |
| 956 | shift; |
| 957 | if [scip-shell system . . `[`. -z "$(echoscip-shell system . . echo. $1 |grepscip-shell system . . grep. ^-.)" ]; then |
| 958 | # skip the -xx option, in case |
| 959 | SL_OS="$1" |
| 960 | [scip-shell system . . `[`. -z "$SL_OS" ] && USAGEscip-shell shell shell-project 0.0.0 USAGE(). && exit 1 |
| 961 | shift |
| 962 | fi |
| 963 | ;; |
| 964 | -f|--use-nfsroot) shift; rootfs_location="nfsroot" ;; |
| 965 | -k|--keep-pxecfg) shift; force_to_update_pxecfg="no" ;; |
| 966 | -n|--no-prompt-boot-message) shift; booting_messages="off";; |
| 967 | -o|--add-ocs-server) shift; add_ocs_server="yes" ;; |
| 968 | -s|--server-ip) |
| 969 | shift; |
| 970 | if [scip-shell system . . `[`. -z "$(echoscip-shell system . . echo. $1 |grepscip-shell system . . grep. ^-.)" ]; then |
| 971 | # skip the -xx option, in case |
| 972 | server_IP="$1" |
| 973 | [scip-shell system . . `[`. -z "$server_IP" ] && USAGEscip-shell shell shell-project 0.0.0 USAGE(). && exit 1 |
| 974 | shift |
| 975 | fi |
| 976 | ;; |
| 977 | -u|--uninstall) |
| 978 | shift; mode="uninstall" |
| 979 | if [scip-shell system . . `[`. -z "$(echoscip-shell system . . echo. $1 |grepscip-shell system . . grep. ^-.)" ]; then |
| 980 | # skip the -xx option, in case |
| 981 | SL_TO_BE_REMOVED="$1" |
| 982 | [scip-shell system . . `[`. -z "$SL_TO_BE_REMOVED" ] && USAGEscip-shell shell shell-project 0.0.0 USAGE(). && exit 1 |
| 983 | shift |
| 984 | fi |
| 985 | ;; |
| 986 | -V|--dist-version) |
| 987 | shift; |
| 988 | if [scip-shell system . . `[`. -z "$(echoscip-shell system . . echo. $1 |grepscip-shell system . . grep. ^-.)" ]; then |
| 989 | # skip the -xx option, in case |
| 990 | SL_VER="$1" |
| 991 | [scip-shell system . . `[`. -z "$SL_VER" ] && USAGEscip-shell shell shell-project 0.0.0 USAGE(). && exit 1 |
| 992 | shift |
| 993 | fi |
| 994 | ;; |
| 995 | -v|--verbose) |
| 996 | verbose="on" |
| 997 | verbose_opt="-v" |
| 998 | shift ;; |
| 999 | *) USAGEscip-shell shell shell-project 0.0.0 USAGE(). && exit 1 ;; |
| 1000 | esac |
| 1001 | done |
| 1002 | # mode is essential |
| 1003 | [scip-shell system . . `[`. -z "$mode" ] && USAGEscip-shell shell shell-project 0.0.0 USAGE(). && exit 1 |
| 1004 | |
| 1005 | # Load the language file |
| 1006 | ask_and_load_lang_set $specified_lang |
| 1007 | |
| 1008 | # |
| 1009 | if [scip-shell system . . `[`. -n "$SL_ISO" ]; then |
| 1010 | source_mode="iso-zip" |
| 1011 | elif [scip-shell system . . `[`. -n "$LIVE_PATH" ]; then |
| 1012 | source_mode="live-path" |
| 1013 | fi |
| 1014 | |
| 1015 | # run it |
| 1016 | case "$mode" in |
| 1017 | install) install_SLscip-shell shell shell-project 0.0.0 install_SL().;; |
| 1018 | uninstall) uninstall_SLscip-shell shell shell-project 0.0.0 uninstall_SL().;; |
| 1019 | esac |