home *** CD-ROM | disk | FTP | other *** search
Text File | 2005-11-10 | 33.4 KB | 1,160 lines |
- #!/bin/bash
- ##
- ## $Id: inst_rest,v 1.3 2005/10/12 12:59:30 kaber Exp $
- ## $Name: $
- ##
- ## (c) 2001/2002 Tom <Eckert.Thomas@gmx.net>
-
- trap '_terminate' 2; ## CTRL-C
- trap '_terminate' 15; ## kill $PID
-
- function _script_home() {
- local we_live_in=""
- local help=""
- local reset_extglob=""
- if [ ! -o extglob ]; then
- reset_extglob=1;
- shopt -s extglob
- fi
- case "$0" in
- /*)
- we_live_in="${0%/*}"
- if [ "$we_live_in" = "" ]; then
- we_live_in="/"
- fi
- ;;
- ../*)
- we_live_in="$PWD/${0%/*}"
- ;;
- ./*|[[:alnum:]]*)
- help="${0#.}";
- we_live_in="$PWD/${help%/*}";
- we_live_in="${we_live_in%/}";
- ;;
- *)
- _error "ERROR: unknown case for $FUNCNAME(), please check."
- ;;
- esac
- help=$we_live_in
- while [ "$(echo $help | grep -q "\.\."; echo $?)" = "0" ]
- do
- help=${help/\/+([[:alpha:]])\/../}
- done
- while [ "$(echo $help | grep -q "\."; echo $?)" = "0" ]
- do
- help=${help/\/./}
- done
- help=$(echo $help | sed -e 's@//@/@')
-
- we_live_in=$help
- echo "$we_live_in"
- if [ "$reset_extglob" = "1" ]; then
- shopt -u extglob
- fi
- }
- MY_LIB="inst_lib.func"
- MY_DIR="$(_script_home)"
- INST_LIB_VERSION=('$Name: $', '$Id: inst_rest,v 1.3 2005/10/12 12:59:30 kaber Exp $');
- function _debug() {
- local msg="$1";
- if [ "$DEBUG" = "1" ]; then
- case "$OUTPUT_FORMAT" in
- term*)
- echo -e "\033[1;34m${msg}\033[0m"
- ;;
- simple)
- echo -e "\033[1m${msg}\033[0m"
- ;;
- plain|*)
- echo -e "${msg}"
- ;;
- esac
- read -p "<ENTER>"
- case "$REPLY" in
- d0)
- echo "disabling DEBUG."
- DEBUG=0;
- ;;
- d)
- echo "DUMP OF ENVIRONMENT:"
- echo " sorry, not possible in binary version."
- ;;
- s*)
- echo "debug: hidden shell ;)"
- ;;
- esac
- fi
- }
- function _info() {
- local msg="$1";
- if [ "$INFO" = "1" ]; then
- case "$OUTPUT_FORMAT" in
- htm*)
- echo -e "<font color=\"green\" size=\"+1\">${msg}</font>"
- ;;
- term*)
- echo -e "\033[0;32m${msg}\033[0m"
- ;;
- simple)
- echo -e "\033[1m${msg}\033[0m"
- ;;
- plain|*)
- echo -e "${msg}"
- ;;
- esac
- fi
- }
- function _warning() {
- local msg="$1";
- if [ "$WARN_MSG" = "1" ]; then
- case "$OUTPUT_FORMAT" in
- htm*)
- echo -e "<font color=\"#FF8C00\" size=\"+1\">${msg}</font>"
- ;;
- term*)
- echo -e "\033[1;33m${msg}\033[0m"
- ;;
- simple)
- echo -e "\033[1m${msg}\033[0m"
- ;;
- plain|*)
- echo -e "${msg}"
- ;;
- esac
- fi
- WARNINGS_TOTAL=$((WARNINGS_TOTAL+1))
- }
- function _error() {
- local msg="$1";
- if [ "$ERROR_MSG" = "1" ]; then
- case "$OUTPUT_FORMAT" in
- htm*)
- echo -e "<font color=\"red\" size=\"+1\">${msg}</font>"
- ;;
- term*)
- echo -e "\033[1;31m${msg}\033[0m"
- if [ "$ERROR_SHELL" = "1" ]; then
- /bin/bash
- fi
- ;;
- simple)
- echo -e "\033[1m${msg}\033[0m"
- if [ "$ERROR_SHELL" = "1" ]; then
- :
- fi
- ;;
- plain|*)
- echo -e "${msg}"
- if [ "$ERROR_SHELL" = "1" ]; then
- :
- fi
- ;;
- esac
- fi
- if [ "$ERROR_EXIT" = "1" ]; then
- _terminate
- fi
- ERRORS_TOTAL=$((ERRORS_TOTAL+1))
- }
- function _redirection_dev_test() {
- if [ ! -c "$REDIR_DEVICE" ]; then
- _warning "WARNING:\"$REDIR_DEVICE\" is not a valid character device.\nSetting to \"/dev/null\"."
- REDIR_DEVICE="/dev/null"
- fi
- if [ "$(echo "MSGS are redirected to this tty." > $REDIR_DEVICE; echo $?)" != "0" ]; then
- _warning "WARNING:\"$REDIR_DEVICE\" is not configured.\nSetting to \"/dev/null\"."
- REDIR_DEVICE="/dev/null"
- fi
- _info "redirection-device (e.g. for tar) is \"$REDIR_DEVICE\"."
- }
- function _fs_extract_from_file() {
- local line
- local read_mode=$1
- local mount_point device fs_type label
- local e3_size;
- _info "parsing filesystem-info ..."
- _debug "debug:$FUNCNAME():starting ..."
- if [ ! -f $FS_INFO_FILE ]; then
- _info "ERROR:FS-INFO-file \"$FS_INFO_FILE\" not found."
- _info "Giving shell to debug, exiting afterwards."
- exit 1
- fi
- set $(eval $FS_INFO_FILE_CMD | grep -v "partition" |\
- cut -d" " -f3,1,5,7 | sed -e 's/\ /:/g' |\
- grep "^/")
- for line in $*
- do
- mount_point=""; device=""; fs_type=""; lable="";
- set $(echo $line | cut -d":" -f1,2,3,4 | sed -e 's/:/ /g')
- device=$1
- mount_point=$2
- fs_type=$3
- label=$4
- label=${label#[}
- label=${label%*]}
- case "$read_mode" in
- restore)
- if [ "$mount_point" = "$SERVICE_MOUNT_PREFIX" ]; then
- _debug "debug:skipping \"$line\"."
- else
- FS_INFO=(${FS_INFO[@]} "$line")
- fi
- ;;
- install)
- FS_INFO=(${FS_INFO[@]} "$line")
- ;;
- *)
- _info "unknown read_mode \"$read_mode\" in $FUNCNAME(), exiting."
- exit 1
- ;;
- esac
- done
- if [ "$(grep -q " ext3 " $FS_INFO_FILE; echo $?)" = "0" ]; then
- for line in $(grep "^ext3" $FS_INFO_FILE)
- do
- line=${line:5}
- FS_INFO_EXT3=(${FS_INFO_EXT3[@]} "$line")
- done
- fi
- _info "done with fs-info parsing."
- _debug "debug:FS_INFO[@]=${FS_INFO[@]}"
- }
- function _mkswap() {
- local device
- _info "creating swap space ..."
- device=$(eval $FS_INFO_FILE_CMD | grep "^/dev/.da" | grep "partition" | cut -d" " -f1)
- if [ -z "$device" ]; then
- _warning "WARNING:no swap-device found. Don't worry if you install DOS or Windows."
- _debug "debug:$FUNCNAME():wanna do something?"
- else
- # delete any possible volume signature
- dd if=/dev/zero of=$device bs=1k count=1
- mkswap $device
- fi
- _info "done with creating swap."
- }
- function _fs_split_local() {
- local line=$1
- local mount_point device fs_type label
- set $(echo $line | cut -d":" -f1,2,3,4 | sed -e 's/:/ /g')
- device=$1
- mount_point=$2
- fs_type=$3
- label=$4
- label=${label#[}
- label=${label%*]}
- echo "$mount_point $device $fs_type $label"
- }
- function _fs_debug_info() {
- local line
- local mount_point device fs_type label
- local size inode
- _info "all info known about the filesystems ..."
- _debug "debug:$FUNCNAME():all filesystem info known:"
- for line in ${FS_INFO[@]}
- do
- _debug "debug:line=$line:"
- _debug "debug:splitted info:"
- set $(_fs_split_local "$line")
- device=$1
- mount_point=$2
- fs_type=$3
- label=$4
- _info "\t;$mount_point;$device;$fs_type;$label;"
- done
- echo ""
- _info "EXT3-info:"
- for line in ${FS_INFO_EXT3[@]}
- do
- _debug "debug:line=$line:"
- _debug "debug:splitted info:"
- set $(echo "$line" | sed -e 's/:/ /g')
- mount_point=$1
- fs_type="FIX ON EXT3"
- size=$2
- inode=$3
- _info "\t;$mount_point;$fs_type;$size;$inode;"
- done
- _debug "debug:$FUNCNAME():end of this function."
- }
- function _version_info() {
- local detail=$1;
- case "$detail" in
- y*)
- echo -e "Library-version:\t${INST_LIB_VERSION[0]}"
- echo -e "Library-version:\t${INST_LIB_VERSION[1]}"
- echo -e "install/restore-version:${INST_REST_VERSION[0]}"
- echo -e "install/restore-version:${INST_REST_VERSION[1]}"
- ;;
- *)
- echo -e "Library-version:\t${INST_LIB_VERSION[0]}"
- echo -e "install/restore-version:${INST_REST_VERSION[0]}"
- ;;
- esac
- echo ""
- echo "(c) 2001/2002 Tom <Eckert.Thomas@gmx.net>"
- }
- function __auto_detection() {
- local lines="";
- local loc_mode="";
- if [ "$mode" = "auto" ]; then
- _info "checking kind of installation ..."
- lines=`cat /proc/pci | grep -A 1 "RAID" | grep -q 'id=13c1'; echo $?`
- if [ "$lines" = "0" ]; then
- _info "found a 3WARE-card ($(cat /proc/pci | grep -A 1 "RAID" | grep 'id=13c1' | wc -l) cards found)."
- _debug "debug:$FUNCNAME(): found a 3WARE ($(cat /proc/pci | grep -A 1 "RAID" | grep 'id=13c1' | wc -l) cards found)."
- loc_mode="scsi"
- fi
- if [ "$loc_mode" != "scsi" ]; then
- if [ -d "/proc/scsi/3w-xxxx" ]; then
- _info "found a 3WARE-card ($(ls -1 /proc/scsi/3w-xxxx|wc -l) cards found)."
- loc_mode="scsi"
- fi
- fi
- lines=`cat /proc/pci | grep "SCSI" | grep -q 'Adaptec'; echo $?`
- if [ "$lines" = "0" ]; then
- _info "found ADAPTEC SCSi-card ($(cat /proc/pci | grep "SCSI" | grep 'Adaptec' | wc -l) cards found)."
- _debug "debug:$FUNCNAME(): found ADAPTEC SCSi-card ($(cat /proc/pci | grep "SCSI" | grep 'Adaptec' | wc -l) cards found)."
- loc_mode="scsi"
- fi
- if [ "$loc_mode" != "scsi" ]; then
- if [ -d "/proc/scsi/aic7xxx" ]; then
- _info "found a 3WARE-card ($(ls -1 /proc/scsi/aic7xxx|wc -l) cards found)."
- loc_mode="scsi"
- fi
- fi
- if [ -d "/proc/scsi/gdth" ]; then
- _info "found an ICP-VORTEX-card ($(ls -1 /proc/scsi/gdth/|wc -l) cards found)."
- loc_mode="scsi"
- fi
- else
- loc_mode="$mode"
- fi
- case "$loc_mode" in
- scsi|3ware)
- mode="scsi";
- HDD_DEVICE="/dev/sda"
- FS_INFO_FILE_CMD='cat $FS_INFO_FILE | sed -e "s#/dev/@NOP@da#${HDD_DEVICE}#"'
- _debug "debug:$FUNCNAME():FS_INFO_FILE_CMD=$FS_INFO_FILE_CMD (HDD=$HDD_DEVICE)."
- ;;
- *)
- mode="singleide"
- FS_INFO_FILE_CMD='cat $FS_INFO_FILE | sed -e "s#/dev/@NOP@da#${HDD_DEVICE}#"'
- _debug "debug:$FUNCNAME():FS_INFO_FILE_CMD=$FS_INFO_FILE_CMD (HDD=$HDD_DEVICE)."
- ;;
- esac
- _info "doing a \"$mode\" installation."
- }
- function _usage() {
- echo "usage: ${0##*/} [-m mode] {-f tarfile} {-c conf-file} {-d <level>} |\\ "
- echo " {-o <format>}} {-Y} {-v|-V} | {-i|-r} | -h"
- echo " -m mode [singleide|scsi|auto]"
- echo " auto -- 3ware and Adaptec-SCSi supported."
- echo " -f tarfile full qualified path and name of image-file to use."
- echo " -c conf-file full qualified path and name of config-file to use."
- echo " overrides values from config-file."
- echo " -d <level> \"0\" to disable, any other value to enable debug-output."
- echo " -o <format> output info- and error-messages in <format>;"
- echo " possible values {html|term|simple|plain}."
- echo " html:for use with a calling wrapper. term:color."
- echo " -Y YES TO ALL -- if set you will not be asked any questions;"
- echo " DANGAROUS! Only use if you _really_ know what you do."
- echo " -v print short-version info and exit."
- echo " -V print long-version info and exit."
- echo " -i operate in install-mode."
- echo " -r operate in restore-mode."
- echo " -h print this help and exit."
- echo "Using default config-file \"$MY_DIR/inst.conf\"."
- }
- function _parameter_parsing() {
- local params="$*";
- local opt="";
- _debug "debug:$FUNCNAME():all params=$* | mode=$mode"
- OPTIND=1;
- while getopts d:m:f:c:vVo:!:Yirh opt $params
- do
- case "$opt" in
- h)
- echo "help requested, print usage."
- _usage
- exit 0
- ;;
- v)
- echo "version-info requested."
- _version_info
- exit 0
- ;;
- V)
- echo "version-info requested."
- _version_info "yes"
- exit 0
- ;;
- o)
- OUTPUT_FORMAT="$OPTARG"
- echo "output-format \"$OUTPUT_FORMAT\" requested."
- ;;
- Y)
- echo "YES TO ALL OPERATION REQUESTED BY USER!"
- YES_TO_ALL="1";
- ;;
- f)
- echo "tarfile specified."
- TARFILE="$OPTARG"
- ;;
- d)
- echo "debug request for \"$OPTARG\"."
- if [ "$OPTARG" = "0" ]; then
- DEBUG=0
- echo "debug output is DISABLED now."
- else
- DEBUG=1
- echo "debug output is ENABLED now."
- fi
- ;;
- m)
- mode="$OPTARG"
- echo "selected mode \"$mode\"."
- ;;
- c)
- CONF_FILE="$OPTARG"
- echo "user-specified config-file \"$CONF_FILE\"."
- ;;
- i)
- INST_OR_REST="install";
- echo "manual install-case selection."
- ;;
- r)
- INST_OR_REST="restore";
- echo "manual restore-case selection."
- ;;
- *)
- echo "unknown parameter! print usage and exit."
- _usage
- exit 1
- ;;
- esac
- done
- if [ "x$mode" = "x" ]; then
- echo "No mode specified -- this is mandatory!"
- return 1;
- fi
-
- __auto_detection
- _info "using tar-file \"$TARFILE\""
- }
- function __readlink() {
- local file="$1";
- local real_name="";
- if [ -z "$file" ]; then
- _debug "debug:$FUNCNAME():empty variable \$file -- check?"
- return -20
- fi
- if [ ! -e "$file" ]; then
- real_name="!file not found in $FUNCNAME()!"
- echo "$real_name"
- return -1
- fi
- if [ ! -L "$file" ]; then
- real_name="$file"
- echo "$real_name"
- return -2
- fi
- real_name=$(readlink $file 2> /dev/null);
- if [ "$?" != "0" ]; then
- if [ -f "$file" ]; then
- real_name="$file"
- else
- _error "ERROR:cannot find file \"$file\" ( $FUNCNAME() )."
- fi
- else
- if [ "$(echo $real_name | grep -q '^/'; echo $?)" != "0" ]; then
- real_name="${file%/*}/$real_name"
- elif [ -f "$real_name" ]; then
- :
- else
- _error "ERROR:this should never happen."
- fi
- fi
- echo "$real_name"
- }
- function _validate_data() {
- local real_name_main="";
- local real_name_service_root="";
- local real_name_service_kernel="";
- if [ ! -f "$TARFILE" ]; then
- _error "ERROR:the tar-file \"$TARFILE\" does not exist. exiting ..."
- exit 1
- fi
- if [ ! -f "$FS_INFO_FILE" ]; then
- _error "ERROR:the filesystem-info-file \"$FS_INFO_FILE\" does not exist. exiting ..."
- exit 1
- fi
- if [ ! -d "$MOUNT_PREFIX" ]; then
- _error "ERROR:cannot find mount-point \"$MOUNT_PREFIX\", not a directory. exiting ..."
- exit 1
- fi
-
- if [ "$INST_OR_REST" = "install" ]; then
- if [ ! -f "$PART_TABLE" ]; then
- _error "ERROR:partition-info-file \"$PART_TABLE\" not found. exiting ..."
- exit 1
- fi
- fi
- real_name_main="$(__readlink $TARFILE)"
- echo ""
- _info "summary of configuration:"
- _info "-------------------------"
- _info "config-file used: $CONF_FILE"
- _info "mode of installation: $mode"
- _info "main-system tarfile: $TARFILE"
- _info " ->$real_name_main"
- _info "post addon-script: ${ADDON_SCRIPT_POST:-not set}"
- _info "writing bootloader: $BOOTLOADER"
- if [ "$INST_OR_REST" = "install" ]; then
- if [ ! -z "$SERVICE_IMAGE_ROOT" ]; then
- real_name_service_root="$(__readlink $SERVICE_IMAGE_ROOT)"
- fi
- if [ ! -z "$SERVICE_IMAGE_KERNEL" ]; then
- real_name_service_kernel="$(__readlink $SERVICE_IMAGE_KERNEL)"
- fi
- echo "--- install-only-related information: ---"
- _info "partition-table in: $PART_TABLE"
- _info "restore-system tarfile: ${SERVICE_IMAGE:-not set, using split images (next 2 lines)}"
- _info "restore-sys ROOT,KERNEL:${SERVICE_IMAGE_ROOT:-not set, upgrade conf-file?},"
- _info " ->${real_name_service_root}"
- _info " ${SERVICE_IMAGE_KERNEL:-not set, using combined method.}"
- _info " ->${real_name_service_kernel}"
- _info "restore-sys mnt-point: $SERVICE_MOUNT_PREFIX"
- fi
- echo ""
- }
- function _inst_or_rest() {
- local pgm_name=${0##*/};
- case "$pgm_name" in
- install*|base_inst.tom)
- INST_OR_REST="install";
- ;;
- restore*)
- INST_OR_REST="restore";
- ;;
- *)
- echo ""
- echo "ERROR: I have an unknown name ;)"
- echo "If you call me with \"install*\" I'll install, if you call me with"
- echo "\"restore*\" the I'll restore (the star \"*\" refers to an arbritary"
- echo "string). Any other name is confusing me, sorry."
- _usage
- exit 1
- ;;
- esac
- }
- function _really_really() {
- local cmd_line="$1";
- local wait="10";
- local adv_opt="";
- _info "All your data will be lost if you proceed and the machine will be"
- _info "reset to factory defaults. If you want to continue type \"yes\"."
- _info "It is save to power off the machine if you want to cancel."
- read
- if [ "$REPLY" != "yes" -a "$REPLY" != "zes" ]; then
- echo ""
- _info "Please type \"yes\" if you want to restore the factory-defaults."
- _info "It is save to power off the machine if you want to cancel."
- sleep 2
- _info "starting over ..."
- sleep 1
- exec $0 $cmd_line
- fi
- _info "Here you can add advanced options: (simply press <ENTER> or wait \"$wait\" secs, \"-h\" for help)."
- while true
- do
- read -t $wait -p "advanced options? " adv_opt
- if [ "$adv_opt" = "-h" ]; then
- _usage
- adv_opt="";
- else
- break
- fi
- done
- _parameter_parsing "$adv_opt"
-
- }
- function _pre_message() {
- if [ ! "$PRE_MESSAGE" ]; then
- _debug "debug: No \"\$PRE_MESSAGE\" in \"$CONF_FILE\", using default."
- echo ""
- _info "About to install/restore system."
- _info "proceed with <ENTER>, poweroff machine to cancel"
- else
- _info "$PRE_MESSAGE"
- fi
- if [ "$YES_TO_ALL" != "1" ]; then
- read -p "<ENTER> to continue"
- else
- read -p "timeout 5secs" -t 5
- fi
- }
- function _post_message() {
- if [ ! "$POST_MESSAGE" ]; then
- _debug "debug:No \"\$POST_MESSAGE\" in \"$CONF_FILE\", using default."
- echo; echo
- _info " All done 8-) "
- echo; echo
- _info " The installation/restoration of the system finished."
- else
- _info "$POST_MESSAGE"
- fi
- }
- function _partition() {
- local rc="";
- _info "creating partitions (dd, sfdisk) ..."
- dd if=/dev/zero of=$HDD_DEVICE bs=1024 count=1
- cat $PART_TABLE | eval sed -e 's#/dev/@NOP@da#${HDD_DEVICE}#' | sfdisk --force -q $HDD_DEVICE
- rc=$?
- if [ "$rc" != "0" ]; then
- _error "ERROR:could not partition disk. Possible reasons:\nwrong mode \"$mode\", wrong kernel (unsupported controller), ...\nGiving shell to debug, exiting afterwards."
- fi
- _debug "done with partition table"
- }
-
- function _lvm_remove() {
- local vgs="$(pvs --noheadings --separator=';' -o pv_name,vg_name | grep "${HDD_DEVICE}" | cut -f2 -d';')"
- _debug "existing volume groups found on ${HDD_DEVICE}: $vgs"
- for vg in $vgs; do
- lvs --noheadings --separator=';' -o lv_name,vg_name | while read junk lvs; do
- local lv_name=$(echo $lvs | cut -f1 -d';')
- local vg_name=$(echo $lvs | cut -f2 -d';')
- if [ "$vg_name" == $vg ]; then
- _debug "removing logical volume: $lv_name"
- lvchange -a n $lv_name
- lvremove $lv_name
- fi
- done
- _debug "removing volume group: $vg"
- vgremove $vg
- done
- }
-
- function _lvm_create() {
- local rc=0
- local name
- local devices
-
- _info "creating lvm volumes ..."
-
- cat $LVM_TABLE | eval sed -e 's#/dev/@NOP@da#${HDD_DEVICE}#' |
- while read name devices; do
- for device in $devices; do
- dd if=/dev/zero of=$device bs=1k count=4
- pvcreate $device
- rc=$?
- if [ "$rc" != "0" ]; then
- _error "ERROR: could not initialize physical volume $device.\nGiving shell to debug, exiting afterwards."
- fi
- done
-
- vgcreate $name $devices
- rc=$?
- if [ "$rc" != "0" ]; then
- _error "ERROR: could not initialize volume group $name with $devices.\nGiving shell to debug, exiting afterwards."
- fi
-
- local pe="$(vgdisplay $name | sed -ne 's/.*Total PE *\([0-9]*\)/\1/p')"
- lvcreate -l $pe $name -n $name
- rc=$?
- if [ "$rc" != "0" ]; then
- _error "ERROR: could not initialize logical volume $name.\nGiving shell to debug, exiting afterwards."
- fi
- done
- }
-
- function __ext3_create_fs() {
- local device=$1;
- local mnt_point_tmp;
- local j_size_tmp;
- local journal_size;
- local journal_inode
- local help;
-
- EXT3_JOURNAL_NAME="journal.dat"
- _info "creating an EXT3 filesystem on $device ..."
- _debug "debug:$FUNCNAME():creating an EXT3 filesystem on $device ..."
- _debug "debug:$FUNCNAME():formating with ext2 first ..."
- eval $FORMAT_EXT2 $device
- _debug "debug:$FUNCNAME():mounting created ext2 ..."
- mount -t ext2 $device $MOUNT_PREFIX
- for help in ${FS_INFO_EXT3[@]}
- do
- set $(echo $help | sed -e 's/:/ /g')
- mnt_point_tmp=$1;
- journal_size=$2;
- journal_inode=$3;
- if [ "$mnt_point_tmp" = "$mount_point" ]; then
- break
- fi
- done
- _info "info:$FUNCNAME():creating journal for EXT3 (size=$journal_size,device=$device)"
- _info "FOOO:dd if=/dev/zero of=$MOUNT_PREFIX/$EXT3_JOURNAL_NAME bs=1 count=$journal_size"
- eval dd if=/dev/zero of=$MOUNT_PREFIX/$EXT3_JOURNAL_NAME bs=1 count=$journal_size
- chmod 0600 $MOUNT_PREFIX/$EXT3_JOURNAL_NAME
- chattr +i $MOUNT_PREFIX/$EXT3_JOURNAL_NAME
- j_size_tmp="$(ls -i $MOUNT_PREFIX/$EXT3_JOURNAL_NAME | sed -e 's@ *@ @' | cut -d" " -f 2)"
- if [ "$j_size_tmp" != "$journal_size" ]; then
- _error "ERROR: journal-inodes do _NOT_ match, the installed system will not work properlly!"
- _debug "debug:$FUNCNAME():ERROR: journal-inodes do _NOT_ match, the installed system will not work properlly!"
- fi
- umount $MOUNT_PREFIX
- _info "testmounting EXT3 (this may take a while) ..."
- _debug "debug:$FUNCNAME():testmounting (this may take a while) ..."
- mount -t ext3 -o journal=$journal_size $device $MOUNT_PREFIX
- _debug "debug:$FUNCNAME():mount complete, want to check? (umounting after ENTER)"
- umount $MOUNT_PREFIX
- }
- function _format() {
- local line
- local mount_point device fs_type label
- local formatter
- _info "creating swap, filesystems and labels ..."
- _mkswap
- for line in ${FS_INFO[@]}
- do
- set $(_fs_split_local "$line")
- mount_point=$1
- device=$2
- fs_type=$3
- label=$4
- _debug "debug:$FUNCNAME(): processing ;$mount_point;$device;$fs_type;$label;"
- case "$fs_type" in
- ext2)
- formatter="$(eval echo $FORMAT_EXT2)" ;;
- ext3)
- formatter="$(eval echo $FORMAT_EXT2) -j" ;;
- reiserfs)
- formatter="$FORMAT_REISERFS" ;;
- *)
- _error "ERROR:$FUNCNAME(): unknown filesystem \"$fs_type\".\nCheck fs-info file \"$FS_INFO_FILE\"."
- exit 1 ;;
- esac
- _info "creating $mount_point (format \"$fs_type\") ..."
- _debug "(command eval $formatter $device)"
- eval $formatter $device
- if [ "$?" != "0" ]; then
- _warning "WARNING: filesytem \"$fs_type\" on device \"$device\" NOT created without errors!"
- _debug "check?"
- fi
- done
- _info "done with creating filesystems"
- }
- function _mount_fs() {
- local m_or_u=$1;
- local mount_extra_opts=$2;
- local line
- local mount_point device fs_type label
- local ii
- _debug "debug:$FUNCNAME():starting ..."
- case "$m_or_u" in
- m*)
- _info "mounting filesystems ..."
- UMOUNT_HELPER=""
- for line in ${FS_INFO[@]}
- do
- set $(_fs_split_local "$line")
- mount_point=$1
- device=$2
- fs_type=$3
- label=$4
- _debug "debug:$FUNCNAME(): processing :$mount_point $device $fs_type $label:"
- _info "mounting $mount_point ..."
- _debug "(command eval mount $mount_extra_opts -t $fs_type $device $MOUNT_PREFIX/$mount_point)"
- if [ ! -d $MOUNT_PREFIX/$mount_point ]; then
- mkdir -p $MOUNT_PREFIX/$mount_point
- if [ ! $? ]; then
- _error "ERROR: cannot mkdir $MOUNT_PREFIX/$mount_point"
- _error "giving shell to debug (exiting afterwards) ..."
- exit 1
- fi
- fi
- UMOUNT_HELPER="$MOUNT_PREFIX/$mount_point $UMOUNT_HELPER"
- eval mount $mount_extra_opts -t $fs_type $device $MOUNT_PREFIX/$mount_point
- done
- _info "done with mounting filesystems"
- ;;
- u*)
- _info "umounting filesystems ..."
- _debug "debug:UMOUNT_HELPER=$UMOUNT_HELPER"
- for ii in $UMOUNT_HELPER
- do
- umount $ii
- done
- _info "done with umounting."
- ;;
- *)
- _info "ERROR:$FUNCNAME():should never happen, unknown option \"$m_or_u\","
- _info "\tallowed values are m* or u*."
- exit 1
- esac
- }
- function _main_system_create() {
- _info "extracting main-system archive ..."
- _info "This may take several minutes (progress on \"$REDIR_DEVICE\")."
- _debug "debug:$FUNCNAME():wanna do something? ;)"
- cd $MOUNT_PREFIX
- tar xvpzf $TARFILE 1> $REDIR_DEVICE
- cd /
- _info "done with archive."
- }
- function _restore_system_create() {
- local real_name="";
- _info "creating service-system ..."
- if [ "x$SERVICE_IMAGE" = "x" ]; then
- if [ ! -f "$SERVICE_IMAGE_ROOT" ]; then
- _warning "service-ROOT-image \"$SERVICE_IMAGE_ROOT\" not found. Exit from func."
- _debug "debug:$FUNCNAME():service-ROOT-image \"$SERVICE_IMAGE_ROOT\" not found. Exit from func."
- return -1
- fi
- if [ ! -f "$SERVICE_IMAGE_KERNEL" ]; then
- _warning "service-KERNEL-image \"$SERVICE_IMAGE_KERNEL\" not found. Exit from func."
- _debug "debug:$FUNCNAME():service-KERNEL-image \"$SERVICE_IMAGE_KERNEL\" not found. Exit from func."
- return -2
- fi
- _info "extracting service-ROOT-image :$SERVICE_IMAGE_ROOT: ..."
- _debug "debug:extracting service-ROOT-image :$SERVICE_IMAGE_ROOT: ..."
- tar xvzpf $SERVICE_IMAGE_ROOT -C $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX > $REDIR_DEVICE
- if [ "$?" != "0" ]; then
- _error "ERROR:service-ROOT-image not extracted without errors (\"$FUNCNAME()\")."
- fi
- _info "extracting service-KERNEL-image :$SERVICE_IMAGE_KERNEL: ..."
- _debug "debug:extracting service-KERNEL-image :$SERVICE_IMAGE_KERNEL: ..."
- tar xvzpf $SERVICE_IMAGE_KERNEL -C $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX > $REDIR_DEVICE
- if [ "$?" != "0" ]; then
- _error "ERROR:service-KERNEL-image not extracted without errors (\"$FUNCNAME()\")."
- fi
- else
- if [ ! -f "$SERVICE_IMAGE" ]; then
- _warning "service-image \"$SERVICE_IMAGE\" not found. Exit from func."
- _debug "debug:$FUNCNAME():service-image \"$SERVICE_IMAGE\" not found. Exit from func."
- return -3
- fi
- _info "extracting service-image :$SERVICE_IMAGE: ..."
- _debug "debug:extracting service-image :$SERVICE_IMAGE: ..."
- tar xvzpf $SERVICE_IMAGE -C $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX > $REDIR_DEVICE
- if [ "$?" != "0" ]; then
- _error "ERROR:service-image not extracted without errors (\"$FUNCNAME()\")."
- fi
- fi
- if [ ! -d "$MOUNT_PREFIX$SERVICE_MOUNT_PREFIX/$INST_ON_SERVICE" ]; then
- _warning "WARNING: dest-path for inst_sys not found (\"$MOUNT_PREFIX$SERVICE_MOUNT_PREFIX/$INST_ON_SERVICE\"), creating ..."
- mkdir -p $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX/$INST_ON_SERVICE
- fi
- _info "copying restore-script and creating symlink :$RESTORE_SCRIPT: ..."
- _debug "debug:copying restore-script and creating symlink :$RESTORE_SCRIPT: ..."
- cp -a $RESTORE_SCRIPT $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX/$INST_ON_SERVICE
- (cd $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX &&\
- ln -s $INST_ON_SERVICE/${RESTORE_SCRIPT##*/} restore)
- if [ ! -z "$ADDON_SCRIPT_PRE" ]; then
- if [ -x "$MY_DIR/$ADDON_SCRIPT_PRE" ]; then
- _info "copying addon-pre-script ..."
- _debug "debug:$FUNCNAME(): \"cp -a $MY_DIR/$ADDON_SCRIPT_PRE $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX/$INST_ON_SERVICE\"".
- cp -a $MY_DIR/$ADDON_SCRIPT_PRE $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX/$INST_ON_SERVICE
- else
- _warning "Addon-pre-script \"$MY_DIR/$ADDON_SCRIPT_PRE\" definded but not existend or executable."
- _warning "The recovery system may not work correctly!"
- fi
- else
- _info "No addon-pre-script defined."
- fi
- if [ ! -z "$ADDON_SCRIPT_POST" ]; then
- if [ -x "$MY_DIR/$ADDON_SCRIPT_POST" ]; then
- _info "copying addon-post-script ..."
- _debug "debug:$FUNCNAME(): \"cp -a $MY_DIR/$ADDON_SCRIPT_POST $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX/$INST_ON_SERVICE\"".
- cp -a $MY_DIR/$ADDON_SCRIPT_POST $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX/$INST_ON_SERVICE
- else
- _warning "Addon-post-script \"$MY_DIR/$ADDON_SCRIPT_POST\" definded but not existent or executable."
- _warning "The recovery system may not work correctly!"
- fi
- else
- _info "No addon-post-script defined."
- fi
- #_info "Checking if function-library \"$MY_DIR/$MY_LIB\" should be installed ..."
- #if [ "$(head -n 1 $RESTORE_SCRIPT | grep -q '^#!/bin/bash'; echo $?)" = "0" ]; then
- # _info " installing library on $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX/$INST_ON_SERVICE."
- # cp $MY_DIR/$MY_LIB $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX/$INST_ON_SERVICE
- #else
- # _info " no need to install function-library."
- #fi
- _info "copying $CONF_FILE and $FS_INFO_FILE..."
- _debug "debug:$FUNCNAME():interaction?"
- cp $CONF_FILE $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX/$INST_ON_SERVICE
- cp $FS_INFO_FILE $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX/$INST_ON_SERVICE
- if [ "${CONF_FILE##*/}" != "inst.conf" ]; then
- _info "symlinking config-file \"ln -s ${CONF_FILE##*/} inst.conf\" ..."
- (cd $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX/$INST_ON_SERVICE && \
- ln -s ${CONF_FILE##*/} inst.conf)
- else
- _info "no need to symlink config-file -- fine."
- fi
- real_name="$(__readlink $TARFILE)"
- if [ ! -f "$real_name" ]; then
- _error "ERROR:$FUNCNAME():main-system tarfile on realname \"$real_name\" not found!"
- _error "RESTORE-SYSTEM will NOT WORK in this installation!"
- _debug "debug:shell to debug? (continueing afterwards)"
- fi
- _info "copy image :$real_name: to service partition ..."
- cp -a $real_name $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX/$INST_ON_SERVICE
- if [ "$TARFILE" != "$real_name" ]; then
- _info " creating symlink ..."
- (cd $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX/$INST_ON_SERVICE && ln -s ${real_name##*/} ${TARFILE##*/})
- else
- _info " no symlink needed."
- fi
- _info "done with service system."
- }
- function _bootloader_create() {
- _info "writing bootloader \"$BOOTLOADER\" ..."
- case "$BOOTLOADER" in
- lilo)
- _lilo_create ;;
- grub)
- _grub_create ;;
- *)
- _error "ERROR: unknown bootloader \"$BOOTLOADER\", please check."
- _error "Giving shell to debug, exiting afterwards."
- exit 1
- ;;
- esac
- _debug "done with BOOTLOADER."
- }
- function _lilo_create() {
- local liloconf="$MOUNT_PREFIX/etc/lilo.conf"
- local tmplilo="$MOUNT_PREFIX/etc/lilo.conf.restore"
- _info "writing LILO for \"$mode\" ..."
- case "$mode" in
- singleide)
- cp $liloconf $MOUNT_PREFIX/foo
- sed 's/sda/hda/g' $MOUNT_PREFIX/foo > $liloconf
- cp $MOUNT_PREFIX/etc/fstab $MOUNT_PREFIX/foo
- sed 's/sda/hda/g' $MOUNT_PREFIX/foo > $MOUNT_PREFIX/etc/fstab
- rm -f $MOUNT_PREFIX/foo
- ;;
- scsi|3ware)
- cp $liloconf $MOUNT_PREFIX/foo
- sed 's/hda/sda/g' $MOUNT_PREFIX/foo > $liloconf
- cp $MOUNT_PREFIX/etc/fstab $MOUNT_PREFIX/foo
- sed 's/hda/sda/g' $MOUNT_PREFIX/foo > $MOUNT_PREFIX/etc/fstab
- rm -f $MOUNT_PREFIX/foo
- ;;
- *)
- _info "unknown mode \"$mode\". shell to debug, exiting afterwards."
- exit 1;
- ;;
- esac
- if [ "$INST_OR_REST" = "restore" ]; then
- _debug "debug:$FUNCNAME():rewriting lilo.conf for restore."
- _debug "debug:CAUTION: this is only tested with Charlie!!"
- cp $liloconf $liloconf.org
- eval sed -e 's#=/boot#=$MOUNT_PREFIX/boot#' $liloconf.org > $MOUNT_PREFIX/foo
- eval sed -e 's#=$SERVICE_MOUNT_PREFIX#=#' $MOUNT_PREFIX/foo > $tmplilo
- rm -f $MOUNT_PREFIX/foo
- $MOUNT_PREFIX/$LILO -s /mnt/boot/boot.bak -C $tmplilo
- else
- eval chroot $MOUNT_PREFIX $LILO
- fi
- if [ $? -ne 0 ]; then
- _error "ERROR: lilo not written correctly."
- fi
- _info "done with LILO."
- }
- function _grub_create() {
- _debug "debug:$FUNCNAME() starting ..."
- _info "writing GRUB ..."
- case "$mode" in
- singleide)
- cp $MOUNT_PREFIX/boot/grub/menu.lst $MOUNT_PREFIX/foo
- sed 's/sda/hda/g' $MOUNT_PREFIX/foo > $MOUNT_PREFIX/boot/grub/menu.lst
- cp $MOUNT_PREFIX/etc/fstab $MOUNT_PREFIX/foo
- sed 's/sda/hda/g' $MOUNT_PREFIX/foo > $MOUNT_PREFIX/etc/fstab
- _debug "debug: right before removing $MOUNT_PREFIX/foo."
- rm -f $MOUNT_PREFIX/foo
- ;;
- scsi|3ware)
- cp $MOUNT_PREFIX/boot/grub/menu.lst $MOUNT_PREFIX/foo
- sed 's/hda/sda/g' $MOUNT_PREFIX/foo > $MOUNT_PREFIX/boot/grub/menu.lst
- cp $MOUNT_PREFIX/etc/fstab $MOUNT_PREFIX/foo
- sed 's/hda/sda/g' $MOUNT_PREFIX/foo > $MOUNT_PREFIX/etc/fstab
- _debug "debug: right before removing $MOUNT_PREFIX/foo."
- rm -f $MOUNT_PREFIX/foo
- ;;
- *)
- _error "ERROR:wrong mode \"$mode\". Don't know to handle with GRUB."
- _debug "debug:$FUNCNAME():wanna do something?"
- ;;
- esac
- _debug "info:$FUNCNAME(): writing GRUB with commands from :$GRUB_COMMANDS: ..."
- echo -e "$GRUB_COMMANDS" | \
- /sbin/grub --batch --no-floppy
- if [ $? -ne 0 ]; then
- _warning "WARNING:error during GRUB-execution. Most likely your system will not\nbe able to boot."
- else
- _info "GRUB written."
- fi
- _debug "info:$FUNCNAME(): GRUB written."
- }
- function _exporter() {
- local export_funcs="_debug \
- _info \
- _warning \
- _error";
- local export_vars="INST_OR_REST \
- MY_DIR \
- MOUNT_PREFIX \
- SERVICE_MOUNT_PREFIX \
- INST_ON_SERVICE";
- export -f $export_funcs
- export $export_vars
- }
- function _print_error_stats() {
- local help="";
- echo
- _info "Warnings and errors in this run:"
- _info "--------------------------------"
- if [ "$WARNINGS_TOTAL" = "0" ]; then
- _info " WARNINGS $WARNINGS_TOTAL"
- else
- _warning " WARNINGS $WARNINGS_TOTAL"
- fi
- if [ "$ERRORS_TOTAL" = "0" ]; then
- _info " ERRORS $ERRORS_TOTAL"
- else
- help=$ERROR_EXIT
- ERROR_EXIT=0
- _warning " ERRORS $ERRORS_TOTAL"
- ERROR_EXIT=$help
- fi
- echo
- }
- function _terminate() {
- _info "termination requested, cleaning up ..."
- _info "umounting all filesystems to make start-over easier ..."
- cd /
- _mount_fs "umount"
- _info "Bye. Have fun!"
- exit 1
- }
- declare -a FS_INFO;
- declare -a FS_INFO_EXT3;## this holds the fs-info for ext3-fs (assigned by
- UMOUNT_HELPER="";
- WARNINGS_TOTAL=0;
- ERRORS_TOTAL=0;
- INST_OR_REST="";
- YES_TO_ALL="0";
- INST_REST_VERSION=('$Name: $', '$Id: inst_rest,v 1.3 2005/10/12 12:59:30 kaber Exp $');
- _parameter_parsing "$*"
- if [ -z "$CONF_FILE" ]; then
- echo "using default config-file."
- CONF_FILE="$MY_DIR/inst.conf"
- fi
- if [ -f $CONF_FILE ]; then
- echo "conf-file \"$CONF_FILE\" exists."
- . $CONF_FILE
- else
- echo "ERROR: config-file \"$CONF_FILE\" not found."
- exit 1
- fi
- if [ -z "$INST_OR_REST" ]; then
- echo "try to determine install-/restore-mode from filename ..."
- _debug "debug:MAIN():try to determine install-/restore-mode from filename."
- _inst_or_rest
- else
- echo "install-/restore-mode set by user on cmd-line to \"$INST_OR_REST\"."
- _debug "debug:MAIN():install-/restore-mode set by user on cmd-line."
- fi
- if [ "$INST_OR_REST" = "restore" ]; then
- DEBUG=0;
- fi
- if [ "$INST_OR_REST" = "install" ]; then
- DO_PARTITION=1
- DO_LVM=1
- DO_RESTORE=1
- else
- DO_PARTITION=0
- DO_LVM=1
- DO_RESTORE=0
- fi
- _parameter_parsing "$*"
- if [ $? -ne 0 ]; then
- _usage
- exit 1
- fi
- _redirection_dev_test
- _version_info "yes"
- _validate_data
- mount -t proc proc /proc >/dev/null 2>/dev/null
- _debug "done with mount-proc"
- _pre_message
- if [ "$YES_TO_ALL" != "1" ]; then
- _really_really "$*"
- fi
- _exporter
- if [ ! -z "$ADDON_SCRIPT_PRE" ]; then
- if [ -x "$MY_DIR/$ADDON_SCRIPT_PRE" ]; then
- _info "executing ADDON-script \"$MY_DIR/$ADDON_SCRIPT_PRE\" ..."
- _debug "debug:executing ADDON-script $MY_DIR/$ADDON_SCRIPT_PRE ..."
- eval $MY_DIR/$ADDON_SCRIPT_PRE
- _info "done with addon-script."
- else
- _warning "WARNING:ADDON-script \"$MY_DIR/$ADDON_SCRIPT_PRE\" not exec. or not found."
- _debug "debug:ADDON-script \"$MY_DIR/$ADDON_SCRIPT_PRE\" not exec. or not found."
- fi
- fi
- if [ "$INST_OR_REST" = "install" ]; then
- _fs_extract_from_file "install"
- else
- _fs_extract_from_file "restore"
- fi
- if [ "$DEBUG" = "1" ]; then
- _fs_debug_info
- fi
- if [ "$DO_LVM" = "1" ]; then
- _lvm_remove
- fi
- if [ "$DO_PARTITION" = "1" ]; then
- _partition
- fi
- if [ "$DO_LVM" = "1" ]; then
- _lvm_create
- fi
- _format
- _mount_fs "mount"
- _main_system_create
- if [ "$DO_RESTORE" = "1" ]; then
- _restore_system_create
- fi
- if [ ! -z "$ADDON_SCRIPT_POST" ]; then
- if [ -x "$MY_DIR/$ADDON_SCRIPT_POST" ]; then
- _info "executing ADDON-script \"$MY_DIR/$ADDON_SCRIPT_POST\" ..."
- _debug "debug:executing ADDON-script $MY_DIR/$ADDON_SCRIPT_POST ..."
- eval $MY_DIR/$ADDON_SCRIPT_POST
- _info "done with addon-script."
- else
- _warning "WARNING:ADDON-script \"$MY_DIR/$ADDON_SCRIPT_POST\" not exec. or not found."
- _debug "debug:ADDON-script \"$MY_DIR/$ADDON_SCRIPT_POST\" not exec. or not found."
- fi
- fi
- _bootloader_create
- TIME_END="$(date "+%s")";
- if [ "$INST_OR_REST" = "install" ]; then
- if [ "$YES_TO_ALL" != "1" ]; then
- _info "opening shell ...(all FS are still mounted!)"
- _info "<CTRL-D> to leave shell."
- fi
- fi
- _mount_fs "umount"
- _post_message
- _print_error_stats
- echo
- _info " -> RETURN to halt"
- if [ "$YES_TO_ALL" != "1" ]; then
- read -p "<ENTER> to halt."
- halt -d -f -p
- fi
-