#!/bin/bash ############################################################################## # # # cust-menu, (C) 2007-2011 S. Georgaras # # # # This file is part of Clonezilla-SysRescCD. # # # # Clonezilla-SysRescCD is free software: you can redistribute it and/or # # modify it under the terms of the GNU General Public License as published # # by the Free Software Foundation, either version 2 of the License, or # # (at your option) any later version. # # # # Clonezilla-SysRescCD is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License along # # with Clonezilla-SysRescCD. If not, see . # # # ############################################################################## function findCFGfile(){ if [ -e isolinux-restore-cd.cfg ];then templateCFG="./isolinux-restore-cd.cfg" elif [ -r /live/image/restorecd/isolinux-restore-cd.cfg ];then templateCFG="/live/image/restorecd/isolinux-restore-cd.cfg" elif [ -r /tmp/restorecd/isolinux-restore-cd.cfg ];then templateCFG="/tmp/restorecd/isolinux-restore-cd.cfg" elif [ -r /restorecd/isolinux-restore-cd.cfg ];then templateCFG="/restorecd/isolinux-restore-cd.cfg" else whiptail --backtitle Clonezilla-SysRescCD --title " Execution Error " --msgbox "This is not a stand-alone script and should not be executed by the command line This script will terminate now" 0 0 exit 1 fi } function find2RamCFGfile(){ if [ -e isolinux-restore-cd-ram.cfg ];then templateCFG="./isolinux-restore-cd-ram.cfg" elif [ -r /live/image/restorecd/isolinux-restore-cd-ram.cfg ];then templateCFG="/live/image/restorecd/isolinux-restore-cd-ram.cfg" elif [ -r /tmp/restorecd/isolinux-restore-cd-ram.cfg ];then templateCFG="/tmp/restorecd/isolinux-restore-cd-ram.cfg" elif [ -r /restorecd/isolinux-restore-cd-ram.cfg ];then templateCFG="/restorecd/isolinux-restore-cd-ram.cfg" else whiptail --backtitle Clonezilla-SysRescCD --title " Execution Error " --msgbox "This is not a stand-alone script and should not be executed by the command line This script will terminate now" 0 0 exit 1 fi } function import_parameters_to_cfg(){ # -> $1 - template cfg file # <- $2 - final cfg file local outCFG="$2".tmp # read parameters inserted by the user # they are found in the isolinux.cfg file # created by Clonezilla Live local paramLine=`grep 'append' $2 | sed '2,$d'` local ocs_live_extra_param="$(echo "$paramLine" | sed 's|.*ocs_live_extra_param="\([^"]*\)".*|\1|')" local ocs_live_keymap="$(echo "$paramLine" | sed 's|.*ocs_live_keymap="\([^"]*\)".*|\1|')" local ocs_lang="$(echo "$paramLine" | sed 's|.*ocs_lang="\([^"]*\)".*|\1|')" # replace with current values sed "s|ocs_live_extra_param=\"[^\"]*\"|ocs_live_extra_param=\"$ocs_live_extra_param\"| s|ocs_live_keymap=\"[^\"]*\"|ocs_live_keymap=\"$ocs_live_keymap\"| s|ocs_lang=\"[^\"]*\"|ocs_lang=\"$ocs_lang\"| " $1 > $outCFG && mv $outCFG $2 } function copy_PNG_SYSLINUX(){ local targetPNG=/restorecd/ocswp.png if [ -n "$bootImg" ];then targetPNG="$bootImg";fi SYSLINUX_FILE=`echo $finalCFG | sed 's{isolinux{syslinux{g'` SYS=`dirname $finalCFG` sed 's{noprompt {{g' $finalCFG > $SYSLINUX_FILE cp "$targetPNG" $SYS cp "$targetPNG" `echo $SYS | sed 's{isolinux{syslinux{g'` } type=ISO # Parse command-line options while [ $# -gt 0 ]; do case "$1" in -publisher) shift if [ -z "$(echo $1 |grep ^-.)" ]; then # skip the -xx option, in case isoPublisher="$1" shift fi # [ -z "$target_iso_prefix" ] && USAGE && exit 1 ;; -V) shift if [ -z "$(echo $1 |grep ^-.)" ]; then # skip the -xx option, in case isoLabel="$1" shift fi # [ -z "$target_iso_prefix" ] && USAGE && exit 1 ;; -z) type=ZIP shift ;; -o) ORIGINAL_INSERT_MODE=y shift ;; *) break; ;; esac done # # # # # # # # # the CFG file can be found as # # # /tmp/ocs_isosys*/isolinux/isolinux.cfg # # # or # # # /home/partimag/ocs_isosys*/isolinux/isolinux.cfg # # # # # # if [ "$type" = ISO ];then type=ISO # finalCFG=/tmp/ocs_isosys*/isolinux/isolinux.cfg finalCFG=`find /tmp -name isolinux.cfg` else type=ZIP # finalCFG=/home/partimag/ocs_isosys*/isolinux/isolinux.cfg finalCFG=`find /home/partimag -name isolinux.cfg` fi if [ ! -e $finalCFG ];then dialog --backtitle Clonezilla-SysRescCD --title " File not found " --msgbox " The original cfg file ($finalCFG) does not exit!!! This script will terminate now" 0 0 exit 1 fi # Check if -s has been used (only iso) if [ -n "$ORIGINAL_INSERT_MODE" ];then # When -s is used, do nothing # findCFGfile # import_parameters_to_cfg $templateCFG $finalCFG # copy_PNG_SYSLINUX exit fi whiptail --backtitle Clonezilla-SysRescCD --title ' Customization section ' --yesno "Do you want to further customize the $type file? You will have the chance to change the Title and Text of the Boot Screen, and set the Default menu item and Boot Delay" 11 60 if [ $? -eq 1 ];then CUSTOMIZE=no fi if [ "$1" = "prog_only" ];then find2RamCFGfile else findCFGfile fi import_parameters_to_cfg $templateCFG $finalCFG ############################################################################## # # Menu Customization # ############################################################################## if [ -z "$CUSTOMIZE" ];then if [ -e $HOME/.last-cust-menu-values ];then whiptail --backtitle Clonezilla-SysRescCD --title ' Config found!!!' --yesno 'You can use the same values you inserted on a previous customization. Do you want to use these values?' 11 45 if [ $? -eq 0 ];then . $HOME/.last-cust-menu-values useOldCustomizationValues=yes fi fi # DVD Title if [ -z "$useOldCustomizationValues" ];then whiptail --backtitle Clonezilla-SysRescCD --title ' Menu Title ' --inputbox 'Insert the Title for the menu' 8 60 "$(grep 'MENU TITLE' $finalCFG | sed 's|^ *MENU TITLE *||' | sed 's| *||g')" 2>/tmp/answer menuTitle=`cat /tmp/answer` echo "menuTitle=$menuTitle" | sed 's/ /\\ /g' >> $HOME/.last-cust-menu-values rm /tmp/answer 2>/dev/null # Item caption whiptail --backtitle Clonezilla-SysRescCD --title ' Menu Items Caption ' --inputbox 'Insert the Caption for each menu item' 8 60 'Clonezilla Live' 2>/tmp/answer itemCaption=`cat /tmp/answer` echo "itemCaption=$itemCaption" | sed 's/ /\\ /g' >> $HOME/.last-cust-menu-values rm /tmp/answer 2>/dev/null # whiptail --backtitle Clonezilla-SysRescCD --title ' Boot delay ' --inputbox 'Insert the boot delay in seconds' 8 60 30 2>/tmp/answer bootDelay=`cat /tmp/answer` if [ "$bootDelay" = "30" ];then bootDelay='' fi echo "bootDelay=$bootDelay" | sed 's/ /\\ /g' >> $HOME/.last-cust-menu-values rm /tmp/answer 2>/dev/null # # Default boot item # echo "whiptail --backtitle Clonezilla-SysRescCD --title ' Default Boot Item ' --menu 'Select Item 6 - Boot from the first hard disk to maintain current setting ' 0 60 0 \\" > /tmp/q.$$ grep 'MENU LABEL' "$templateCFG" | sed '/---/d' | sed 's|^.*MENU LABEL *||' | sed "s|^|'|" | sed "s|$|'|" | awk '{print NR " " ""$0"" " "}' | tr -d '\n$' > /tmp/qq.$$ oldCaption=`sed 's|^1 *.||' /tmp/qq.$$ | sed "s| *-.*||"` echo "oldCaption=$oldCaption" | sed 's/ /\\ /g' >> $HOME/.last-cust-menu-values if [ -n "$itemCaption" ];then sed "s/$oldCaption/$itemCaption/g" /tmp/qq.$$ >> /tmp/q.$$ else cat /tmp/qq.$$ >> /tmp/q.$$ fi echo "2>/tmp/answer" >> /tmp/q.$$ rm /tmp/qq.$$ . /tmp/q.$$ rm /tmp/q.$$ defItem=`cat /tmp/answer` if [ $defItem -gt 6 ];then ((defItem++));fi ((defItem++)) #if [ $defItem -eq 6 ];then defItem='';fi if [ $defItem -eq 7 ];then defItem='';fi rm /tmp/answer 2>/dev/null echo "defItem=$defItem" | sed 's/ /\\ /g' >> $HOME/.last-cust-menu-values # Boot Screen Image whiptail --backtitle Clonezilla-SysRescCD --title ' Boot Screen Image ' --inputbox 'Insert the Image to be displayed on the Boot Screen The file must be a 640x480 32-bit png image' 0 60 ocswp.png 2>/tmp/answer bootImage=`cat /tmp/answer` if [ "$bootImage" = "ocswp.png" ];then bootImage='' fi echo "bootImage=$bootImage" | sed 's/ /\\ /g' >> $HOME/.last-cust-menu-values rm /tmp/answer 2>/dev/null if [ "$type" = "ISO" ];then # ISO Label whiptail --backtitle Clonezilla-SysRescCD --title ' ISO Label ' --inputbox 'Insert the Volume Label of the ISO file' 0 60 "$isoLabel" 2>/tmp/answer isoLabelTMP=`cat /tmp/answer` if [ -z "$isoLabelTMP" ];then isoLabelTMP="$isoLabel" fi echo "isoLabelTMP=$isoLabelTMP" | sed 's/ /\\ /g' >> $HOME/.last-cust-menu-values rm /tmp/answer 2>/dev/null # Publisher ID whiptail --backtitle Clonezilla-SysRescCD --title ' Publisher ID ' --inputbox 'Insert the Publisher ID of the ISO file' 0 60 "$isoPublisher" 2>/tmp/answer isoPublisherTMP=`cat /tmp/answer` if [ -z "$isoPublisherTMP" ];then isoPublisherTMP="$isoPublisher" fi echo "isoPublisherTMP=$isoPublisherTMP" | sed 's/ /\\ /g' >> $HOME/.last-cust-menu-values rm /tmp/answer 2>/dev/null echo "$isoLabelTMP" > /tmp/isodata echo "$isoPublisherTMP" >> /tmp/isodata fi fi ############################################################################ # # Insert user data to file # ############################################################################ if [ -n "$menuTitle" ];then sed "s|^ *MENU TITLE .*|MENU TITLE $menuTitle|" $finalCFG > $finalCFG.$$ && mv $finalCFG.$$ $finalCFG fi if [ -n "$itemCaption" ];then sed "s|MENU LABEL *$oldCaption *-|MENU LABEL $itemCaption -|" $finalCFG > $finalCFG.$$ && mv $finalCFG.$$ $finalCFG fi if [ -n "$bootDelay" ];then sed "s|[tT][iI][mM][eE][oO][uU][tT] .*| timeout "$bootDelay"0|" $finalCFG > $finalCFG.$$ && mv $finalCFG.$$ $finalCFG fi if [ -n "$defItem" ];then sed 's|^ *MENU DEFAULT| # MENU DEFAULT|' $finalCFG > $finalCFG.$$ && mv $finalCFG.$$ $finalCFG addIt=`grep -n 'MENU DEFAULT' $finalCFG | sed 's|:.*||' | sed -n ""$defItem"p"` sed ""$addIt"s|# *MENU *DEFAULT|MENU DEFAULT|" $finalCFG > $finalCFG.$$ && mv $finalCFG.$$ $finalCFG fi if [ -n "$bootImage" ];then if [ -e "$bootImage" ] || [ -e /home/partimag/"$bootImage" ] ;then bootImg="$bootImage" fi fi fi copy_PNG_SYSLINUX