home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2006 February / PCpro_2006_02.ISO / inst_sys / cbs / inst_rest < prev    next >
Encoding:
Text File  |  2005-11-10  |  33.4 KB  |  1,160 lines

  1. #!/bin/bash
  2. ##
  3. ## $Id: inst_rest,v 1.3 2005/10/12 12:59:30 kaber Exp $
  4. ## $Name:  $
  5. ##
  6. ## (c) 2001/2002 Tom <Eckert.Thomas@gmx.net>
  7.  
  8. trap '_terminate' 2;        ## CTRL-C
  9. trap '_terminate' 15;        ## kill $PID
  10.  
  11. function _script_home() {
  12.     local we_live_in=""
  13.     local help=""
  14.     local reset_extglob=""
  15.     if [ ! -o extglob ]; then
  16.         reset_extglob=1;
  17.         shopt -s extglob
  18.     fi
  19.     case "$0" in
  20.         /*)
  21.             we_live_in="${0%/*}"
  22.             if [ "$we_live_in" = "" ]; then
  23.                 we_live_in="/"
  24.             fi
  25.         ;;
  26.         ../*)
  27.             we_live_in="$PWD/${0%/*}"
  28.         ;;
  29.         ./*|[[:alnum:]]*)
  30.             help="${0#.}";        
  31.             we_live_in="$PWD/${help%/*}";
  32.             we_live_in="${we_live_in%/}";
  33.         ;;
  34.         *)
  35.             _error "ERROR: unknown case for $FUNCNAME(), please check."
  36.         ;;
  37.     esac
  38.     help=$we_live_in
  39.     while [ "$(echo $help | grep -q "\.\."; echo $?)" = "0" ]
  40.     do
  41.         help=${help/\/+([[:alpha:]])\/../}
  42.     done
  43.     while [ "$(echo $help | grep -q "\."; echo $?)" = "0" ]
  44.     do
  45.         help=${help/\/./}
  46.     done
  47.     help=$(echo $help | sed -e 's@//@/@')
  48.     
  49.     we_live_in=$help
  50.     echo "$we_live_in"
  51.     if [ "$reset_extglob" = "1" ]; then
  52.         shopt -u extglob
  53.     fi
  54. }
  55. MY_LIB="inst_lib.func"
  56. MY_DIR="$(_script_home)"
  57. INST_LIB_VERSION=('$Name:  $', '$Id: inst_rest,v 1.3 2005/10/12 12:59:30 kaber Exp $');    
  58. function _debug() {
  59.     local msg="$1";
  60.     if [ "$DEBUG" = "1" ]; then
  61.         case "$OUTPUT_FORMAT" in
  62.             term*)
  63.                 echo -e "\033[1;34m${msg}\033[0m"
  64.             ;;
  65.             simple)
  66.                 echo -e "\033[1m${msg}\033[0m"
  67.             ;;
  68.             plain|*)
  69.                 echo -e "${msg}"
  70.             ;;
  71.         esac
  72.         read -p "<ENTER>"
  73.         case "$REPLY" in
  74.             d0)
  75.                 echo "disabling DEBUG."
  76.                 DEBUG=0;
  77.             ;;
  78.             d)
  79.                 echo "DUMP OF ENVIRONMENT:"
  80.                 echo "  sorry, not possible in binary version."
  81.             ;;
  82.             s*)
  83.                 echo "debug: hidden shell ;)"
  84.             ;;
  85.         esac
  86.     fi
  87. }
  88. function _info() {
  89.     local msg="$1";
  90.     if [ "$INFO" = "1" ]; then
  91.         case "$OUTPUT_FORMAT" in
  92.             htm*)
  93.                 echo -e "<font color=\"green\" size=\"+1\">${msg}</font>"
  94.             ;;
  95.             term*)
  96.                 echo -e "\033[0;32m${msg}\033[0m"
  97.             ;;
  98.             simple)
  99.                 echo -e "\033[1m${msg}\033[0m"
  100.             ;;
  101.             plain|*)
  102.                 echo -e "${msg}"
  103.             ;;
  104.         esac
  105.     fi
  106. }
  107. function _warning() {
  108.     local msg="$1";
  109.     if [ "$WARN_MSG" = "1" ]; then
  110.         case "$OUTPUT_FORMAT" in
  111.             htm*)
  112.                 echo -e "<font color=\"#FF8C00\" size=\"+1\">${msg}</font>"
  113.             ;;
  114.             term*)
  115.                 echo -e "\033[1;33m${msg}\033[0m"
  116.             ;;
  117.             simple)
  118.                 echo -e "\033[1m${msg}\033[0m"
  119.             ;;
  120.             plain|*)
  121.                 echo -e "${msg}"
  122.             ;;
  123.         esac
  124.     fi
  125.     WARNINGS_TOTAL=$((WARNINGS_TOTAL+1))
  126. }
  127. function _error() {
  128.     local msg="$1";
  129.     if [ "$ERROR_MSG" = "1" ]; then
  130.         case "$OUTPUT_FORMAT" in
  131.             htm*)
  132.                 echo -e "<font color=\"red\" size=\"+1\">${msg}</font>"
  133.             ;;
  134.             term*)
  135.                 echo -e "\033[1;31m${msg}\033[0m"
  136.                 if [ "$ERROR_SHELL" = "1" ]; then
  137.                     /bin/bash
  138.                 fi
  139.             ;;
  140.             simple)
  141.                 echo -e "\033[1m${msg}\033[0m"
  142.                 if [ "$ERROR_SHELL" = "1" ]; then
  143.                     :
  144.                 fi
  145.             ;;
  146.             plain|*)
  147.                 echo -e "${msg}"
  148.                 if [ "$ERROR_SHELL" = "1" ]; then
  149.                     :
  150.                 fi
  151.             ;;
  152.         esac
  153.     fi
  154.     if [ "$ERROR_EXIT" = "1" ]; then
  155.         _terminate
  156.     fi
  157.     ERRORS_TOTAL=$((ERRORS_TOTAL+1))
  158. }
  159. function _redirection_dev_test() {
  160.     if [ ! -c "$REDIR_DEVICE" ]; then
  161.         _warning "WARNING:\"$REDIR_DEVICE\" is not a valid character device.\nSetting to \"/dev/null\"."
  162.         REDIR_DEVICE="/dev/null"
  163.     fi
  164.     if [ "$(echo "MSGS are redirected to this tty." > $REDIR_DEVICE; echo $?)" != "0" ]; then
  165.         _warning "WARNING:\"$REDIR_DEVICE\" is not configured.\nSetting to \"/dev/null\"."
  166.         REDIR_DEVICE="/dev/null"
  167.     fi
  168.     _info "redirection-device (e.g. for tar) is \"$REDIR_DEVICE\"."
  169. }
  170. function _fs_extract_from_file() {
  171.     local line
  172.     local read_mode=$1
  173.     local mount_point device fs_type label
  174.     local e3_size;
  175.     _info "parsing filesystem-info ..."
  176.     _debug "debug:$FUNCNAME():starting ..."
  177.     if [ ! -f $FS_INFO_FILE ]; then
  178.         _info "ERROR:FS-INFO-file \"$FS_INFO_FILE\" not found."
  179.         _info "Giving shell to debug, exiting afterwards."
  180.         exit 1
  181.     fi
  182.     set $(eval $FS_INFO_FILE_CMD | grep -v "partition" |\
  183.         cut -d" " -f3,1,5,7 | sed -e 's/\ /:/g' |\
  184.         grep "^/")
  185.     for line in $*
  186.     do
  187.         mount_point="";    device=""; fs_type=""; lable="";
  188.         set $(echo $line | cut -d":" -f1,2,3,4 | sed -e 's/:/ /g')
  189.         device=$1
  190.         mount_point=$2
  191.         fs_type=$3
  192.         label=$4
  193.         label=${label#[}
  194.         label=${label%*]}
  195.         case "$read_mode" in
  196.             restore)
  197.                 if [ "$mount_point" = "$SERVICE_MOUNT_PREFIX" ]; then
  198.                     _debug "debug:skipping \"$line\"."
  199.                 else
  200.                     FS_INFO=(${FS_INFO[@]} "$line")
  201.                 fi
  202.             ;;
  203.             install)
  204.                 FS_INFO=(${FS_INFO[@]} "$line")
  205.             ;;
  206.             *)
  207.                 _info "unknown read_mode \"$read_mode\" in $FUNCNAME(), exiting."
  208.                 exit 1
  209.             ;;
  210.         esac
  211.     done
  212.     if [ "$(grep -q " ext3 " $FS_INFO_FILE; echo $?)" = "0" ]; then
  213.         for line in $(grep "^ext3" $FS_INFO_FILE)
  214.         do
  215.             line=${line:5}
  216.             FS_INFO_EXT3=(${FS_INFO_EXT3[@]} "$line")
  217.         done
  218.     fi
  219.     _info "done with fs-info parsing."
  220.     _debug "debug:FS_INFO[@]=${FS_INFO[@]}"
  221. }
  222. function _mkswap() {
  223.     local device
  224.     _info "creating swap space ..."
  225.     device=$(eval $FS_INFO_FILE_CMD | grep "^/dev/.da" | grep "partition" | cut -d" " -f1)
  226.     if [ -z "$device" ]; then
  227.         _warning "WARNING:no swap-device found. Don't worry if you install DOS or Windows."
  228.         _debug "debug:$FUNCNAME():wanna do something?"
  229.     else
  230.         # delete any possible volume signature
  231.             dd if=/dev/zero of=$device bs=1k count=1
  232.         mkswap $device
  233.     fi
  234.     _info "done with creating swap."
  235. }
  236. function _fs_split_local() {
  237.     local line=$1
  238.     local mount_point device fs_type label
  239.     set $(echo $line | cut -d":" -f1,2,3,4 | sed -e 's/:/ /g')
  240.     device=$1
  241.     mount_point=$2
  242.     fs_type=$3
  243.     label=$4
  244.     label=${label#[}
  245.     label=${label%*]}
  246.     echo "$mount_point $device $fs_type $label"
  247. }
  248. function _fs_debug_info() {
  249.     local line
  250.     local mount_point device fs_type label
  251.     local size inode
  252.     _info "all info known about the filesystems ..."
  253.     _debug "debug:$FUNCNAME():all filesystem info known:"
  254.     for line in ${FS_INFO[@]}
  255.     do
  256.         _debug "debug:line=$line:"
  257.         _debug "debug:splitted info:"
  258.         set $(_fs_split_local "$line")
  259.         device=$1
  260.         mount_point=$2
  261.         fs_type=$3
  262.         label=$4
  263.         _info "\t;$mount_point;$device;$fs_type;$label;"
  264.     done
  265.     echo ""
  266.     _info "EXT3-info:"
  267.     for line in ${FS_INFO_EXT3[@]}
  268.     do
  269.         _debug "debug:line=$line:"
  270.         _debug "debug:splitted info:"
  271.         set $(echo "$line" | sed -e 's/:/ /g')
  272.         mount_point=$1
  273.         fs_type="FIX ON EXT3"
  274.         size=$2
  275.         inode=$3
  276.         _info "\t;$mount_point;$fs_type;$size;$inode;"
  277.     done
  278.     _debug "debug:$FUNCNAME():end of this function."
  279. }
  280. function _version_info() {
  281.     local detail=$1;
  282.     case "$detail" in
  283.         y*)
  284.             echo -e "Library-version:\t${INST_LIB_VERSION[0]}"
  285.             echo -e "Library-version:\t${INST_LIB_VERSION[1]}"
  286.             echo -e "install/restore-version:${INST_REST_VERSION[0]}"
  287.             echo -e "install/restore-version:${INST_REST_VERSION[1]}"
  288.         ;;
  289.         *)
  290.             echo -e "Library-version:\t${INST_LIB_VERSION[0]}"
  291.             echo -e "install/restore-version:${INST_REST_VERSION[0]}"
  292.         ;;
  293.     esac
  294.     echo ""
  295.     echo "(c) 2001/2002 Tom <Eckert.Thomas@gmx.net>"
  296. }
  297. function __auto_detection() {
  298.     local lines="";
  299.     local loc_mode="";
  300.     if [ "$mode" = "auto" ]; then
  301.         _info "checking kind of installation ..."
  302.         lines=`cat /proc/pci | grep -A 1 "RAID" | grep -q 'id=13c1'; echo $?`
  303.         if [ "$lines" = "0" ]; then
  304.             _info "found a 3WARE-card ($(cat /proc/pci | grep -A 1 "RAID" | grep 'id=13c1' | wc -l) cards found)."
  305.             _debug "debug:$FUNCNAME(): found a 3WARE ($(cat /proc/pci | grep -A 1 "RAID" | grep 'id=13c1' | wc -l) cards found)."
  306.             loc_mode="scsi"
  307.         fi
  308.         if [ "$loc_mode" != "scsi" ]; then
  309.             if [ -d "/proc/scsi/3w-xxxx" ]; then
  310.                 _info "found a 3WARE-card ($(ls -1 /proc/scsi/3w-xxxx|wc -l) cards found)."
  311.                 loc_mode="scsi"
  312.             fi
  313.         fi
  314.         lines=`cat /proc/pci | grep "SCSI" | grep -q 'Adaptec'; echo $?`
  315.         if [ "$lines" = "0" ]; then
  316.             _info "found ADAPTEC SCSi-card ($(cat /proc/pci | grep "SCSI" | grep 'Adaptec' | wc -l) cards found)."
  317.             _debug "debug:$FUNCNAME(): found ADAPTEC SCSi-card ($(cat /proc/pci | grep "SCSI" | grep 'Adaptec' | wc -l) cards found)."
  318.             loc_mode="scsi"
  319.         fi
  320.         if [ "$loc_mode" != "scsi" ]; then
  321.             if [ -d "/proc/scsi/aic7xxx" ]; then
  322.                 _info "found a 3WARE-card ($(ls -1 /proc/scsi/aic7xxx|wc -l) cards found)."
  323.                 loc_mode="scsi"
  324.             fi
  325.         fi
  326.         if [ -d "/proc/scsi/gdth" ]; then
  327.             _info "found an ICP-VORTEX-card ($(ls -1 /proc/scsi/gdth/|wc -l) cards found)."
  328.             loc_mode="scsi"
  329.         fi
  330.     else
  331.         loc_mode="$mode"
  332.     fi
  333.     case "$loc_mode" in
  334.         scsi|3ware)
  335.             mode="scsi";
  336.             HDD_DEVICE="/dev/sda"
  337.             FS_INFO_FILE_CMD='cat $FS_INFO_FILE | sed -e "s#/dev/@NOP@da#${HDD_DEVICE}#"'
  338.             _debug "debug:$FUNCNAME():FS_INFO_FILE_CMD=$FS_INFO_FILE_CMD (HDD=$HDD_DEVICE)."
  339.         ;;
  340.         *)
  341.             mode="singleide"
  342.             FS_INFO_FILE_CMD='cat $FS_INFO_FILE | sed -e "s#/dev/@NOP@da#${HDD_DEVICE}#"'
  343.             _debug "debug:$FUNCNAME():FS_INFO_FILE_CMD=$FS_INFO_FILE_CMD (HDD=$HDD_DEVICE)."
  344.         ;;
  345.     esac
  346.     _info "doing a \"$mode\" installation."
  347. }
  348. function _usage() {
  349.     echo "usage: ${0##*/} [-m mode] {-f tarfile} {-c conf-file} {-d <level>} |\\ "
  350.     echo "    {-o <format>}} {-Y} {-v|-V} | {-i|-r} | -h"
  351.     echo "  -m mode    [singleide|scsi|auto]"
  352.     echo "        auto -- 3ware and Adaptec-SCSi supported."
  353.     echo "  -f tarfile    full qualified path and name of image-file to use."
  354.     echo "  -c conf-file    full qualified path and name of config-file to use."
  355.     echo "        overrides values from config-file."
  356.     echo "  -d <level>    \"0\" to disable, any other value to enable debug-output."
  357.     echo "  -o <format>    output info- and error-messages in <format>;"
  358.     echo "        possible values {html|term|simple|plain}."
  359.     echo "        html:for use with a calling wrapper. term:color."
  360.     echo "  -Y        YES TO ALL -- if set you will not be asked any questions;"
  361.     echo "        DANGAROUS! Only use if you _really_ know what you do."
  362.     echo "  -v        print short-version info and exit."
  363.     echo "  -V        print long-version info and exit."
  364.     echo "  -i        operate in install-mode."
  365.     echo "  -r        operate in restore-mode."
  366.     echo "  -h        print this help and exit."
  367.     echo "Using default config-file \"$MY_DIR/inst.conf\"."
  368. }
  369. function _parameter_parsing() {
  370.     local params="$*";
  371.     local opt="";    
  372.     _debug "debug:$FUNCNAME():all params=$* | mode=$mode"
  373.     OPTIND=1;
  374.     while getopts d:m:f:c:vVo:!:Yirh opt $params
  375.     do
  376.         case "$opt" in
  377.             h)
  378.                 echo "help requested, print usage."
  379.                 _usage
  380.                 exit 0
  381.             ;;
  382.             v)
  383.                 echo "version-info requested."
  384.                 _version_info
  385.                 exit 0
  386.             ;;
  387.             V)
  388.                 echo "version-info requested."
  389.                 _version_info "yes"
  390.                 exit 0
  391.             ;;
  392.             o)
  393.                 OUTPUT_FORMAT="$OPTARG"
  394.                 echo "output-format \"$OUTPUT_FORMAT\" requested."
  395.             ;;
  396.             Y)
  397.                 echo "YES TO ALL OPERATION REQUESTED BY USER!"
  398.                 YES_TO_ALL="1";
  399.             ;;
  400.             f)
  401.                 echo "tarfile specified."
  402.                 TARFILE="$OPTARG"
  403.             ;;
  404.             d)
  405.                 echo "debug request for \"$OPTARG\"."
  406.                 if [ "$OPTARG" = "0" ]; then
  407.                     DEBUG=0
  408.                     echo "debug output is DISABLED now."
  409.                 else
  410.                     DEBUG=1
  411.                     echo "debug output is ENABLED now."
  412.                 fi
  413.             ;;
  414.             m)
  415.                 mode="$OPTARG"
  416.                 echo "selected mode \"$mode\"."
  417.             ;;
  418.             c)
  419.                 CONF_FILE="$OPTARG"
  420.                 echo "user-specified config-file \"$CONF_FILE\"."
  421.             ;;
  422.             i)
  423.                 INST_OR_REST="install";
  424.                 echo "manual install-case selection."
  425.             ;;
  426.             r)
  427.                 INST_OR_REST="restore";
  428.                 echo "manual restore-case selection."
  429.             ;;
  430.             *)
  431.                 echo "unknown parameter! print usage and exit."
  432.                 _usage
  433.                 exit 1
  434.             ;;
  435.         esac
  436.     done
  437.     if [ "x$mode" = "x" ]; then
  438.         echo "No mode specified -- this is mandatory!"
  439.         return 1;
  440.     fi
  441.                 
  442.     __auto_detection
  443.     _info "using tar-file \"$TARFILE\""
  444. }
  445. function __readlink() {
  446.     local file="$1";
  447.     local real_name="";
  448.     if [ -z "$file" ]; then
  449.         _debug "debug:$FUNCNAME():empty variable \$file -- check?"
  450.         return -20
  451.     fi
  452.     if [ ! -e "$file" ]; then
  453.         real_name="!file not found in $FUNCNAME()!"
  454.         echo "$real_name"
  455.         return -1
  456.     fi
  457.     if [ ! -L "$file" ]; then
  458.         real_name="$file"
  459.         echo "$real_name"
  460.         return -2
  461.     fi
  462.     real_name=$(readlink $file 2> /dev/null);
  463.     if [ "$?" != "0" ]; then
  464.         if [ -f "$file" ]; then
  465.             real_name="$file"
  466.         else
  467.             _error "ERROR:cannot find file \"$file\" ( $FUNCNAME() )."
  468.         fi
  469.     else
  470.         if [ "$(echo $real_name | grep -q '^/'; echo $?)" != "0" ]; then
  471.             real_name="${file%/*}/$real_name"
  472.         elif [ -f "$real_name" ]; then
  473.             :
  474.         else
  475.             _error "ERROR:this should never happen."
  476.         fi
  477.     fi
  478.     echo "$real_name"
  479. }
  480. function _validate_data() {
  481.     local real_name_main="";    
  482.     local real_name_service_root="";    
  483.     local real_name_service_kernel="";    
  484.     if [ ! -f "$TARFILE" ]; then
  485.         _error "ERROR:the tar-file \"$TARFILE\" does not exist. exiting ..."
  486.         exit 1
  487.     fi
  488.     if [ ! -f "$FS_INFO_FILE" ]; then
  489.         _error "ERROR:the filesystem-info-file \"$FS_INFO_FILE\" does not exist. exiting ..."
  490.         exit 1
  491.     fi
  492.     if [ ! -d "$MOUNT_PREFIX" ]; then
  493.         _error "ERROR:cannot find mount-point \"$MOUNT_PREFIX\", not a directory. exiting ..."
  494.         exit 1
  495.     fi
  496.     
  497.     if [ "$INST_OR_REST" = "install" ]; then
  498.         if [ ! -f "$PART_TABLE" ]; then
  499.             _error "ERROR:partition-info-file \"$PART_TABLE\" not found. exiting ..."
  500.             exit 1
  501.         fi
  502.     fi
  503.     real_name_main="$(__readlink $TARFILE)"
  504.     echo ""
  505.     _info "summary of configuration:"
  506.     _info "-------------------------"
  507.     _info "config-file used:    $CONF_FILE"
  508.     _info "mode of installation:    $mode"
  509.     _info "main-system tarfile:    $TARFILE"
  510.     _info "            ->$real_name_main"
  511.     _info "post addon-script:    ${ADDON_SCRIPT_POST:-not set}"
  512.     _info "writing bootloader:    $BOOTLOADER"
  513.     if [ "$INST_OR_REST" = "install" ]; then
  514.         if [ ! -z "$SERVICE_IMAGE_ROOT" ]; then
  515.             real_name_service_root="$(__readlink $SERVICE_IMAGE_ROOT)"
  516.         fi
  517.         if [ ! -z "$SERVICE_IMAGE_KERNEL" ]; then
  518.             real_name_service_kernel="$(__readlink $SERVICE_IMAGE_KERNEL)"
  519.         fi
  520.         echo "--- install-only-related information: ---"
  521.         _info "partition-table in:    $PART_TABLE"
  522.         _info "restore-system tarfile:    ${SERVICE_IMAGE:-not set, using split images (next 2 lines)}"
  523.         _info "restore-sys ROOT,KERNEL:${SERVICE_IMAGE_ROOT:-not set, upgrade conf-file?},"
  524.         _info "            ->${real_name_service_root}"
  525.         _info "            ${SERVICE_IMAGE_KERNEL:-not set, using combined method.}"
  526.         _info "            ->${real_name_service_kernel}"
  527.         _info "restore-sys mnt-point:    $SERVICE_MOUNT_PREFIX"
  528.     fi
  529.     echo ""
  530. }
  531. function _inst_or_rest() {
  532.     local pgm_name=${0##*/};    
  533.     case "$pgm_name" in
  534.         install*|base_inst.tom)
  535.             INST_OR_REST="install";
  536.         ;;
  537.         restore*)
  538.             INST_OR_REST="restore";
  539.         ;;
  540.         *)
  541.             echo ""
  542.             echo "ERROR: I have an unknown name ;)"
  543.             echo "If you call me with \"install*\" I'll install, if you call me with"
  544.             echo "\"restore*\" the I'll restore (the star \"*\" refers to an arbritary"
  545.             echo "string). Any other name is confusing me, sorry."
  546.             _usage
  547.             exit 1
  548.         ;;
  549.     esac
  550. }
  551. function _really_really() {
  552.     local cmd_line="$1";
  553.     local wait="10";
  554.     local adv_opt="";
  555.     _info "All your data will be lost if you proceed and the machine will be"
  556.     _info "reset to factory defaults. If you want to continue type \"yes\"."
  557.     _info "It is save to power off the machine if you want to cancel."
  558.     read
  559.     if [ "$REPLY" != "yes" -a "$REPLY" != "zes" ]; then
  560.         echo ""
  561.         _info "Please type \"yes\" if you want to restore the factory-defaults."
  562.         _info "It is save to power off the machine if you want to cancel."
  563.         sleep 2
  564.         _info "starting over ..."
  565.         sleep 1
  566.         exec $0 $cmd_line
  567.     fi
  568.     _info "Here you can add advanced options: (simply press <ENTER> or wait \"$wait\" secs, \"-h\" for help)."
  569.     while true
  570.     do
  571.         read -t $wait -p "advanced options? " adv_opt
  572.         if [ "$adv_opt" = "-h" ]; then
  573.             _usage
  574.             adv_opt="";
  575.         else
  576.             break
  577.         fi
  578.     done
  579.     _parameter_parsing "$adv_opt"
  580.     
  581. }
  582. function _pre_message() {
  583.     if [ ! "$PRE_MESSAGE" ]; then
  584.         _debug "debug: No \"\$PRE_MESSAGE\" in \"$CONF_FILE\", using default."
  585.         echo ""
  586.         _info "About to install/restore system."
  587.         _info "proceed with <ENTER>, poweroff machine to cancel"
  588.     else
  589.         _info "$PRE_MESSAGE"
  590.     fi
  591.     if [ "$YES_TO_ALL" !=  "1" ]; then
  592.         read -p "<ENTER> to continue"
  593.     else
  594.         read -p "timeout 5secs" -t 5
  595.     fi
  596. }
  597. function _post_message() {
  598.     if [ ! "$POST_MESSAGE" ]; then
  599.         _debug "debug:No \"\$POST_MESSAGE\" in \"$CONF_FILE\", using default."
  600.         echo; echo
  601.         _info " All done  8-) "
  602.         echo; echo
  603.         _info " The installation/restoration of the system finished."
  604.     else
  605.         _info "$POST_MESSAGE"
  606.     fi
  607. }
  608. function _partition() {
  609.     local rc="";
  610.     _info "creating partitions (dd, sfdisk) ..."
  611.     dd if=/dev/zero of=$HDD_DEVICE bs=1024 count=1
  612.     cat $PART_TABLE | eval sed -e 's#/dev/@NOP@da#${HDD_DEVICE}#' | sfdisk --force -q $HDD_DEVICE
  613.     rc=$?
  614.     if [ "$rc" != "0" ]; then
  615.         _error "ERROR:could not partition disk. Possible reasons:\nwrong mode \"$mode\", wrong kernel (unsupported controller), ...\nGiving shell to debug, exiting afterwards."
  616.     fi
  617.     _debug "done with partition table"
  618. }
  619.  
  620. function _lvm_remove() {
  621.     local vgs="$(pvs --noheadings --separator=';' -o pv_name,vg_name | grep "${HDD_DEVICE}" | cut -f2 -d';')"
  622.     _debug "existing volume groups found on ${HDD_DEVICE}: $vgs"
  623.     for vg in $vgs; do
  624.         lvs --noheadings --separator=';' -o lv_name,vg_name | while read junk lvs; do
  625.             local lv_name=$(echo $lvs | cut -f1 -d';')
  626.             local vg_name=$(echo $lvs | cut -f2 -d';')
  627.             if [ "$vg_name" == $vg ]; then
  628.                 _debug "removing logical volume: $lv_name"
  629.                 lvchange -a n $lv_name
  630.                 lvremove $lv_name
  631.             fi
  632.         done
  633.         _debug "removing volume group: $vg"
  634.         vgremove $vg
  635.     done
  636. }
  637.  
  638. function _lvm_create() {
  639.     local rc=0
  640.     local name
  641.     local devices
  642.  
  643.     _info "creating lvm volumes ..."
  644.  
  645.     cat $LVM_TABLE | eval sed -e 's#/dev/@NOP@da#${HDD_DEVICE}#' |
  646.     while read name devices; do
  647.         for device in $devices; do
  648.                 dd if=/dev/zero of=$device bs=1k count=4
  649.             pvcreate $device
  650.             rc=$?
  651.             if [ "$rc" != "0" ]; then
  652.                 _error "ERROR: could not initialize physical volume $device.\nGiving shell to debug, exiting afterwards."
  653.             fi
  654.         done
  655.  
  656.         vgcreate $name $devices
  657.         rc=$?
  658.         if [ "$rc" != "0" ]; then
  659.             _error "ERROR: could not initialize volume group $name with $devices.\nGiving shell to debug, exiting afterwards."
  660.         fi
  661.  
  662.         local pe="$(vgdisplay $name | sed -ne 's/.*Total PE *\([0-9]*\)/\1/p')"
  663.         lvcreate -l $pe $name -n $name
  664.         rc=$?
  665.         if [ "$rc" != "0" ]; then
  666.             _error "ERROR: could not initialize logical volume $name.\nGiving shell to debug, exiting afterwards."
  667.         fi
  668.     done
  669. }
  670.  
  671. function __ext3_create_fs() {
  672.     local device=$1;
  673.     local mnt_point_tmp;
  674.     local j_size_tmp;
  675.     local journal_size;
  676.     local journal_inode
  677.     local help;
  678.     
  679.     EXT3_JOURNAL_NAME="journal.dat"
  680.     _info "creating an EXT3 filesystem on $device ..."
  681.     _debug "debug:$FUNCNAME():creating an EXT3 filesystem on $device ..."
  682.     _debug "debug:$FUNCNAME():formating with ext2 first ..."
  683.     eval $FORMAT_EXT2 $device
  684.     _debug "debug:$FUNCNAME():mounting created ext2 ..."
  685.     mount -t ext2 $device $MOUNT_PREFIX
  686.     for help in ${FS_INFO_EXT3[@]}
  687.     do
  688.         set $(echo $help | sed -e 's/:/ /g')
  689.         mnt_point_tmp=$1;
  690.         journal_size=$2;
  691.         journal_inode=$3;
  692.         if [ "$mnt_point_tmp" = "$mount_point" ]; then
  693.             break
  694.         fi
  695.     done
  696.     _info "info:$FUNCNAME():creating journal for EXT3 (size=$journal_size,device=$device)"
  697.     _info "FOOO:dd if=/dev/zero of=$MOUNT_PREFIX/$EXT3_JOURNAL_NAME bs=1 count=$journal_size"
  698.     eval dd if=/dev/zero of=$MOUNT_PREFIX/$EXT3_JOURNAL_NAME bs=1 count=$journal_size
  699.     chmod 0600 $MOUNT_PREFIX/$EXT3_JOURNAL_NAME
  700.     chattr +i $MOUNT_PREFIX/$EXT3_JOURNAL_NAME
  701.     j_size_tmp="$(ls -i $MOUNT_PREFIX/$EXT3_JOURNAL_NAME | sed -e 's@ *@ @' | cut -d" " -f 2)"
  702.     if [ "$j_size_tmp" != "$journal_size" ]; then
  703.         _error "ERROR: journal-inodes do _NOT_ match, the installed system will not work properlly!"
  704.         _debug "debug:$FUNCNAME():ERROR: journal-inodes do _NOT_ match, the installed system will not work properlly!"
  705.     fi
  706.     umount $MOUNT_PREFIX
  707.     _info "testmounting EXT3 (this may take a while) ..."
  708.     _debug "debug:$FUNCNAME():testmounting (this may take a while) ..."
  709.     mount -t ext3 -o journal=$journal_size $device $MOUNT_PREFIX
  710.     _debug "debug:$FUNCNAME():mount complete, want to check? (umounting after ENTER)"
  711.     umount $MOUNT_PREFIX
  712. }
  713. function _format() {
  714.     local line
  715.     local mount_point device fs_type label
  716.     local formatter
  717.     _info "creating swap, filesystems and labels ..."
  718.     _mkswap
  719.     for line in ${FS_INFO[@]}
  720.     do
  721.         set $(_fs_split_local "$line")
  722.         mount_point=$1
  723.         device=$2
  724.         fs_type=$3
  725.         label=$4
  726.         _debug "debug:$FUNCNAME(): processing ;$mount_point;$device;$fs_type;$label;"
  727.         case "$fs_type" in
  728.             ext2)
  729.                 formatter="$(eval echo $FORMAT_EXT2)"    ;;
  730.             ext3)
  731.                 formatter="$(eval echo $FORMAT_EXT2) -j"    ;;
  732.             reiserfs)
  733.                 formatter="$FORMAT_REISERFS"    ;;
  734.             *)
  735.                 _error "ERROR:$FUNCNAME(): unknown filesystem \"$fs_type\".\nCheck fs-info file \"$FS_INFO_FILE\"."
  736.                 exit 1 ;;
  737.         esac
  738.         _info "creating $mount_point (format \"$fs_type\") ..."
  739.         _debug "(command eval $formatter $device)"
  740.         eval $formatter $device
  741.         if [ "$?" != "0" ]; then
  742.             _warning "WARNING: filesytem \"$fs_type\" on device \"$device\" NOT created without errors!"
  743.             _debug "check?"
  744.         fi
  745.     done
  746.     _info "done with creating filesystems"
  747. }
  748. function _mount_fs() {
  749.     local m_or_u=$1;    
  750.     local mount_extra_opts=$2;
  751.     local line
  752.     local mount_point device fs_type label
  753.     local ii
  754.     _debug "debug:$FUNCNAME():starting ..."
  755.     case "$m_or_u" in
  756.     m*)
  757.         _info "mounting filesystems ..."
  758.         UMOUNT_HELPER=""
  759.         for line in ${FS_INFO[@]}
  760.         do
  761.             set $(_fs_split_local "$line")
  762.             mount_point=$1
  763.             device=$2
  764.             fs_type=$3
  765.             label=$4
  766.             _debug "debug:$FUNCNAME(): processing :$mount_point $device $fs_type $label:"
  767.             _info "mounting $mount_point ..."
  768.             _debug "(command eval mount $mount_extra_opts -t $fs_type $device $MOUNT_PREFIX/$mount_point)"
  769.             if [ ! -d $MOUNT_PREFIX/$mount_point ]; then
  770.                 mkdir -p $MOUNT_PREFIX/$mount_point
  771.                 if [ ! $? ]; then
  772.                     _error "ERROR: cannot mkdir $MOUNT_PREFIX/$mount_point"
  773.                     _error "giving shell to debug (exiting afterwards) ..."
  774.                     exit 1
  775.                 fi
  776.             fi
  777.             UMOUNT_HELPER="$MOUNT_PREFIX/$mount_point $UMOUNT_HELPER"
  778.             eval mount $mount_extra_opts -t $fs_type $device $MOUNT_PREFIX/$mount_point
  779.         done
  780.         _info "done with mounting filesystems"
  781.     ;;
  782.     u*)
  783.         _info "umounting filesystems ..."
  784.         _debug "debug:UMOUNT_HELPER=$UMOUNT_HELPER"
  785.         for ii in $UMOUNT_HELPER
  786.         do
  787.             umount $ii
  788.         done
  789.         _info "done with umounting."
  790.     ;;
  791.     *)
  792.         _info "ERROR:$FUNCNAME():should never happen, unknown option \"$m_or_u\","
  793.         _info "\tallowed values are m* or u*."
  794.         exit 1
  795. esac
  796. }
  797. function _main_system_create() {
  798.     _info "extracting main-system archive ..."
  799.     _info "This may take several minutes (progress on \"$REDIR_DEVICE\")."
  800.     _debug "debug:$FUNCNAME():wanna do something? ;)"
  801.     cd $MOUNT_PREFIX
  802.     tar xvpzf $TARFILE 1> $REDIR_DEVICE
  803.     cd /
  804.     _info "done with archive."
  805. }
  806. function _restore_system_create() {
  807.     local real_name="";
  808.     _info "creating service-system  ..."
  809.     if [ "x$SERVICE_IMAGE" = "x" ]; then
  810.         if [ ! -f "$SERVICE_IMAGE_ROOT" ]; then
  811.             _warning "service-ROOT-image \"$SERVICE_IMAGE_ROOT\" not found. Exit from func."
  812.             _debug "debug:$FUNCNAME():service-ROOT-image \"$SERVICE_IMAGE_ROOT\" not found. Exit from func."
  813.             return -1
  814.         fi
  815.         if [ ! -f "$SERVICE_IMAGE_KERNEL" ]; then
  816.             _warning "service-KERNEL-image \"$SERVICE_IMAGE_KERNEL\" not found. Exit from func."
  817.             _debug "debug:$FUNCNAME():service-KERNEL-image \"$SERVICE_IMAGE_KERNEL\" not found. Exit from func."
  818.             return -2
  819.         fi
  820.         _info "extracting service-ROOT-image :$SERVICE_IMAGE_ROOT: ..."
  821.         _debug "debug:extracting service-ROOT-image :$SERVICE_IMAGE_ROOT: ..."
  822.         tar xvzpf $SERVICE_IMAGE_ROOT -C $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX > $REDIR_DEVICE
  823.         if [ "$?" != "0" ]; then
  824.             _error "ERROR:service-ROOT-image not extracted without errors (\"$FUNCNAME()\")."
  825.         fi
  826.         _info "extracting service-KERNEL-image :$SERVICE_IMAGE_KERNEL: ..."
  827.         _debug "debug:extracting service-KERNEL-image :$SERVICE_IMAGE_KERNEL: ..."
  828.         tar xvzpf $SERVICE_IMAGE_KERNEL -C $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX > $REDIR_DEVICE
  829.         if [ "$?" != "0" ]; then
  830.             _error "ERROR:service-KERNEL-image not extracted without errors (\"$FUNCNAME()\")."
  831.         fi
  832.     else
  833.         if [ ! -f "$SERVICE_IMAGE" ]; then
  834.             _warning "service-image \"$SERVICE_IMAGE\" not found. Exit from func."
  835.             _debug "debug:$FUNCNAME():service-image \"$SERVICE_IMAGE\" not found. Exit from func."
  836.             return -3
  837.         fi
  838.         _info "extracting service-image :$SERVICE_IMAGE: ..."
  839.         _debug "debug:extracting service-image :$SERVICE_IMAGE: ..."
  840.         tar xvzpf $SERVICE_IMAGE -C $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX > $REDIR_DEVICE
  841.         if [ "$?" != "0" ]; then
  842.             _error "ERROR:service-image not extracted without errors (\"$FUNCNAME()\")."
  843.         fi
  844.     fi
  845.     if [ ! -d "$MOUNT_PREFIX$SERVICE_MOUNT_PREFIX/$INST_ON_SERVICE" ]; then
  846.         _warning "WARNING: dest-path for inst_sys not found (\"$MOUNT_PREFIX$SERVICE_MOUNT_PREFIX/$INST_ON_SERVICE\"), creating ..."
  847.         mkdir -p $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX/$INST_ON_SERVICE
  848.     fi
  849.     _info "copying restore-script and creating symlink :$RESTORE_SCRIPT: ..."
  850.     _debug "debug:copying restore-script and creating symlink :$RESTORE_SCRIPT: ..."
  851.     cp -a $RESTORE_SCRIPT $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX/$INST_ON_SERVICE
  852.     (cd $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX &&\
  853.          ln -s $INST_ON_SERVICE/${RESTORE_SCRIPT##*/} restore)
  854.     if [ ! -z "$ADDON_SCRIPT_PRE" ]; then
  855.         if [ -x "$MY_DIR/$ADDON_SCRIPT_PRE" ]; then
  856.             _info "copying addon-pre-script ..."
  857.             _debug "debug:$FUNCNAME(): \"cp -a $MY_DIR/$ADDON_SCRIPT_PRE $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX/$INST_ON_SERVICE\"".
  858.             cp -a $MY_DIR/$ADDON_SCRIPT_PRE $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX/$INST_ON_SERVICE
  859.         else
  860.             _warning "Addon-pre-script \"$MY_DIR/$ADDON_SCRIPT_PRE\" definded but not existend or executable."
  861.             _warning "The recovery system may not work correctly!"
  862.         fi
  863.     else
  864.         _info "No addon-pre-script defined."
  865.     fi
  866.     if [ ! -z "$ADDON_SCRIPT_POST" ]; then
  867.         if [ -x "$MY_DIR/$ADDON_SCRIPT_POST" ]; then
  868.             _info "copying addon-post-script ..."
  869.             _debug "debug:$FUNCNAME(): \"cp -a $MY_DIR/$ADDON_SCRIPT_POST $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX/$INST_ON_SERVICE\"".
  870.             cp -a $MY_DIR/$ADDON_SCRIPT_POST $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX/$INST_ON_SERVICE
  871.         else
  872.             _warning "Addon-post-script \"$MY_DIR/$ADDON_SCRIPT_POST\" definded but not existent or executable."
  873.             _warning "The recovery system may not work correctly!"
  874.         fi
  875.     else
  876.         _info "No addon-post-script defined."
  877.     fi
  878.     #_info "Checking if function-library \"$MY_DIR/$MY_LIB\" should be installed ..."
  879.     #if [ "$(head -n 1 $RESTORE_SCRIPT | grep -q '^#!/bin/bash'; echo $?)" = "0" ]; then
  880.     #    _info "  installing library on $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX/$INST_ON_SERVICE."
  881.     #    cp $MY_DIR/$MY_LIB $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX/$INST_ON_SERVICE
  882.     #else
  883.     #    _info "  no need to install function-library."
  884.     #fi
  885.     _info "copying $CONF_FILE and $FS_INFO_FILE..."
  886.     _debug "debug:$FUNCNAME():interaction?"
  887.     cp $CONF_FILE $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX/$INST_ON_SERVICE
  888.     cp $FS_INFO_FILE $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX/$INST_ON_SERVICE
  889.     if [ "${CONF_FILE##*/}" != "inst.conf" ]; then
  890.         _info "symlinking config-file \"ln -s ${CONF_FILE##*/} inst.conf\" ..."
  891.         (cd $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX/$INST_ON_SERVICE && \
  892.             ln -s ${CONF_FILE##*/} inst.conf)
  893.     else
  894.         _info "no need to symlink config-file -- fine."
  895.     fi
  896.     real_name="$(__readlink $TARFILE)"
  897.     if [ ! -f "$real_name" ]; then
  898.         _error "ERROR:$FUNCNAME():main-system tarfile on realname \"$real_name\" not found!"
  899.         _error "RESTORE-SYSTEM will NOT WORK in this installation!"
  900.         _debug "debug:shell to debug? (continueing afterwards)"
  901.     fi
  902.     _info "copy image :$real_name: to service partition ..."
  903.     cp -a $real_name $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX/$INST_ON_SERVICE
  904.     if [ "$TARFILE" != "$real_name" ]; then
  905.         _info "  creating symlink ..."
  906.         (cd $MOUNT_PREFIX$SERVICE_MOUNT_PREFIX/$INST_ON_SERVICE && ln -s ${real_name##*/} ${TARFILE##*/})
  907.     else
  908.         _info "  no symlink needed."
  909.     fi
  910.     _info "done with service system."
  911. }
  912. function _bootloader_create() {
  913.     _info "writing bootloader \"$BOOTLOADER\" ..."
  914.     case "$BOOTLOADER" in
  915.         lilo)
  916.             _lilo_create    ;;
  917.         grub)
  918.             _grub_create    ;;
  919.         *)
  920.             _error "ERROR: unknown bootloader \"$BOOTLOADER\", please check."
  921.             _error "Giving shell to debug, exiting afterwards."
  922.             exit 1
  923.         ;;
  924.     esac
  925.     _debug "done with BOOTLOADER."
  926. }
  927. function _lilo_create() {
  928.     local liloconf="$MOUNT_PREFIX/etc/lilo.conf"
  929.     local tmplilo="$MOUNT_PREFIX/etc/lilo.conf.restore"
  930.     _info "writing LILO for \"$mode\" ..."
  931.     case "$mode" in
  932.         singleide)
  933.             cp $liloconf $MOUNT_PREFIX/foo
  934.             sed 's/sda/hda/g' $MOUNT_PREFIX/foo > $liloconf
  935.             cp $MOUNT_PREFIX/etc/fstab $MOUNT_PREFIX/foo
  936.             sed 's/sda/hda/g' $MOUNT_PREFIX/foo > $MOUNT_PREFIX/etc/fstab
  937.             rm -f $MOUNT_PREFIX/foo
  938.         ;;
  939.         scsi|3ware)
  940.             cp $liloconf $MOUNT_PREFIX/foo
  941.             sed 's/hda/sda/g' $MOUNT_PREFIX/foo > $liloconf
  942.             cp $MOUNT_PREFIX/etc/fstab $MOUNT_PREFIX/foo
  943.             sed 's/hda/sda/g' $MOUNT_PREFIX/foo > $MOUNT_PREFIX/etc/fstab
  944.             rm -f $MOUNT_PREFIX/foo
  945.         ;;
  946.         *)
  947.             _info "unknown mode \"$mode\". shell to debug, exiting afterwards."
  948.             exit 1;
  949.         ;;
  950.     esac
  951.     if [ "$INST_OR_REST" = "restore" ]; then
  952.         _debug "debug:$FUNCNAME():rewriting lilo.conf for restore."
  953.         _debug "debug:CAUTION: this is only tested with Charlie!!"
  954.         cp $liloconf $liloconf.org
  955.         eval sed -e 's#=/boot#=$MOUNT_PREFIX/boot#' $liloconf.org > $MOUNT_PREFIX/foo
  956.         eval sed -e 's#=$SERVICE_MOUNT_PREFIX#=#' $MOUNT_PREFIX/foo > $tmplilo
  957.         rm -f $MOUNT_PREFIX/foo
  958.         $MOUNT_PREFIX/$LILO -s /mnt/boot/boot.bak -C $tmplilo
  959.     else
  960.         eval chroot $MOUNT_PREFIX $LILO
  961.     fi
  962.     if [ $? -ne 0 ]; then
  963.         _error "ERROR: lilo not written correctly."
  964.     fi
  965.     _info "done with LILO."
  966. }
  967. function _grub_create() {
  968.     _debug "debug:$FUNCNAME() starting ..."
  969.     _info "writing GRUB ..."
  970.     case "$mode" in
  971.         singleide)
  972.             cp $MOUNT_PREFIX/boot/grub/menu.lst $MOUNT_PREFIX/foo
  973.             sed 's/sda/hda/g' $MOUNT_PREFIX/foo > $MOUNT_PREFIX/boot/grub/menu.lst
  974.             cp $MOUNT_PREFIX/etc/fstab $MOUNT_PREFIX/foo
  975.             sed 's/sda/hda/g' $MOUNT_PREFIX/foo > $MOUNT_PREFIX/etc/fstab
  976.             _debug "debug: right before removing $MOUNT_PREFIX/foo."
  977.             rm -f $MOUNT_PREFIX/foo
  978.         ;;
  979.         scsi|3ware)
  980.             cp $MOUNT_PREFIX/boot/grub/menu.lst $MOUNT_PREFIX/foo
  981.             sed 's/hda/sda/g' $MOUNT_PREFIX/foo > $MOUNT_PREFIX/boot/grub/menu.lst
  982.             cp $MOUNT_PREFIX/etc/fstab $MOUNT_PREFIX/foo
  983.             sed 's/hda/sda/g' $MOUNT_PREFIX/foo > $MOUNT_PREFIX/etc/fstab
  984.             _debug "debug: right before removing $MOUNT_PREFIX/foo."
  985.             rm -f $MOUNT_PREFIX/foo
  986.         ;;
  987.         *)
  988.             _error "ERROR:wrong mode \"$mode\". Don't know to handle with GRUB."
  989.             _debug "debug:$FUNCNAME():wanna do something?"
  990.         ;;
  991.     esac
  992.     _debug "info:$FUNCNAME(): writing GRUB with commands from :$GRUB_COMMANDS: ..."
  993.     echo -e "$GRUB_COMMANDS" | \
  994.         /sbin/grub --batch --no-floppy
  995.     if [ $? -ne 0 ]; then
  996.         _warning "WARNING:error during GRUB-execution. Most likely your system will not\nbe able to boot."
  997.     else
  998.         _info "GRUB written."
  999.     fi
  1000.     _debug "info:$FUNCNAME(): GRUB written."
  1001. }
  1002. function _exporter() {
  1003.     local export_funcs="_debug \
  1004.         _info \
  1005.         _warning \
  1006.         _error";
  1007.     local export_vars="INST_OR_REST \
  1008.         MY_DIR \
  1009.         MOUNT_PREFIX \
  1010.         SERVICE_MOUNT_PREFIX \
  1011.         INST_ON_SERVICE";
  1012.     export -f $export_funcs
  1013.     export $export_vars
  1014. }
  1015. function _print_error_stats() {
  1016.     local help="";    
  1017.     echo
  1018.     _info "Warnings and errors in this run:"
  1019.     _info "--------------------------------"
  1020.     if [ "$WARNINGS_TOTAL" = "0" ]; then
  1021.         _info "  WARNINGS  $WARNINGS_TOTAL"
  1022.     else
  1023.         _warning "  WARNINGS  $WARNINGS_TOTAL"
  1024.     fi
  1025.     if [ "$ERRORS_TOTAL" = "0" ]; then
  1026.         _info "  ERRORS    $ERRORS_TOTAL"
  1027.     else
  1028.         help=$ERROR_EXIT
  1029.         ERROR_EXIT=0
  1030.         _warning "  ERRORS    $ERRORS_TOTAL"
  1031.         ERROR_EXIT=$help
  1032.     fi
  1033.     echo
  1034. }
  1035. function _terminate() {
  1036.     _info "termination requested, cleaning up ..."
  1037.     _info "umounting all filesystems to make start-over easier ..."
  1038.     cd /
  1039.     _mount_fs "umount"
  1040.     _info "Bye. Have fun!"
  1041.     exit 1
  1042. }
  1043. declare -a FS_INFO;    
  1044. declare -a FS_INFO_EXT3;## this holds the fs-info for ext3-fs (assigned by
  1045. UMOUNT_HELPER="";    
  1046. WARNINGS_TOTAL=0;
  1047. ERRORS_TOTAL=0;
  1048. INST_OR_REST="";    
  1049. YES_TO_ALL="0";        
  1050. INST_REST_VERSION=('$Name:  $', '$Id: inst_rest,v 1.3 2005/10/12 12:59:30 kaber Exp $');
  1051. _parameter_parsing "$*"
  1052. if [ -z "$CONF_FILE" ]; then
  1053.     echo "using default config-file."
  1054.     CONF_FILE="$MY_DIR/inst.conf"
  1055. fi
  1056. if [ -f $CONF_FILE ]; then
  1057.     echo "conf-file \"$CONF_FILE\" exists."
  1058.     . $CONF_FILE
  1059. else
  1060.     echo "ERROR: config-file \"$CONF_FILE\" not found."
  1061.     exit 1
  1062. fi
  1063. if [ -z "$INST_OR_REST" ]; then
  1064.     echo "try to determine install-/restore-mode from filename ..."
  1065.     _debug "debug:MAIN():try to determine install-/restore-mode from filename."
  1066.     _inst_or_rest
  1067. else
  1068.     echo "install-/restore-mode set by user on cmd-line to \"$INST_OR_REST\"."
  1069.     _debug "debug:MAIN():install-/restore-mode set by user on cmd-line."
  1070. fi
  1071. if [ "$INST_OR_REST" = "restore" ]; then
  1072.     DEBUG=0;
  1073. fi
  1074. if [ "$INST_OR_REST" = "install" ]; then
  1075.     DO_PARTITION=1
  1076.     DO_LVM=1
  1077.     DO_RESTORE=1
  1078. else
  1079.     DO_PARTITION=0
  1080.     DO_LVM=1
  1081.     DO_RESTORE=0
  1082. fi
  1083. _parameter_parsing "$*"
  1084. if [ $? -ne 0 ]; then
  1085.     _usage
  1086.     exit 1
  1087. fi
  1088. _redirection_dev_test
  1089. _version_info "yes"
  1090. _validate_data
  1091. mount -t proc proc /proc >/dev/null 2>/dev/null
  1092. _debug "done with mount-proc"
  1093. _pre_message
  1094. if [ "$YES_TO_ALL" != "1" ]; then
  1095.     _really_really "$*"
  1096. fi
  1097. _exporter
  1098. if [ ! -z "$ADDON_SCRIPT_PRE" ]; then
  1099.     if [ -x "$MY_DIR/$ADDON_SCRIPT_PRE" ]; then
  1100.         _info "executing ADDON-script \"$MY_DIR/$ADDON_SCRIPT_PRE\" ..."
  1101.         _debug "debug:executing ADDON-script $MY_DIR/$ADDON_SCRIPT_PRE ..."
  1102.         eval $MY_DIR/$ADDON_SCRIPT_PRE
  1103.         _info "done with addon-script."
  1104.     else
  1105.         _warning "WARNING:ADDON-script \"$MY_DIR/$ADDON_SCRIPT_PRE\" not exec. or not found."
  1106.         _debug "debug:ADDON-script \"$MY_DIR/$ADDON_SCRIPT_PRE\" not exec. or not found."
  1107.     fi
  1108. fi
  1109. if [ "$INST_OR_REST" = "install" ]; then
  1110.     _fs_extract_from_file "install"
  1111. else
  1112.     _fs_extract_from_file "restore"
  1113. fi
  1114. if [ "$DEBUG" = "1" ]; then
  1115.     _fs_debug_info
  1116. fi
  1117. if [ "$DO_LVM" = "1" ]; then
  1118.     _lvm_remove
  1119. fi
  1120. if [ "$DO_PARTITION" = "1" ]; then
  1121.     _partition
  1122. fi
  1123. if [ "$DO_LVM" = "1" ]; then
  1124.     _lvm_create
  1125. fi
  1126. _format
  1127. _mount_fs "mount"
  1128. _main_system_create
  1129. if [ "$DO_RESTORE" = "1" ]; then
  1130.     _restore_system_create
  1131. fi
  1132. if [ ! -z "$ADDON_SCRIPT_POST" ]; then
  1133.     if [ -x "$MY_DIR/$ADDON_SCRIPT_POST" ]; then
  1134.         _info "executing ADDON-script \"$MY_DIR/$ADDON_SCRIPT_POST\" ..."
  1135.         _debug "debug:executing ADDON-script $MY_DIR/$ADDON_SCRIPT_POST ..."
  1136.         eval $MY_DIR/$ADDON_SCRIPT_POST
  1137.         _info "done with addon-script."
  1138.     else
  1139.         _warning "WARNING:ADDON-script \"$MY_DIR/$ADDON_SCRIPT_POST\" not exec. or not found."
  1140.         _debug "debug:ADDON-script \"$MY_DIR/$ADDON_SCRIPT_POST\" not exec. or not found."
  1141.     fi
  1142. fi
  1143. _bootloader_create
  1144. TIME_END="$(date "+%s")";    
  1145. if [ "$INST_OR_REST" = "install" ]; then
  1146.     if [ "$YES_TO_ALL" != "1" ]; then
  1147.         _info "opening shell ...(all FS are still mounted!)"
  1148.         _info "<CTRL-D> to leave shell."
  1149.     fi
  1150. fi
  1151. _mount_fs "umount"
  1152. _post_message
  1153. _print_error_stats
  1154. echo
  1155. _info " -> RETURN to halt" 
  1156. if [ "$YES_TO_ALL" != "1" ]; then
  1157.     read -p "<ENTER> to halt."
  1158.     halt -d -f -p
  1159. fi
  1160.