head	1.7;
access;
symbols;
locks; strict;
comment	@# @;


1.7
date	2005.05.17.17.19.11;	author tcheun;	state Exp;
branches;
next	1.6;

1.6
date	2005.05.13.09.01.38;	author tcheun1;	state Exp;
branches;
next	1.5;

1.5
date	2005.05.11.18.34.28;	author tcheun;	state Exp;
branches;
next	1.4;

1.4
date	2005.05.10.18.41.17;	author tcheun;	state Exp;
branches;
next	1.3;

1.3
date	2005.02.28.09.53.50;	author tcheun1;	state Exp;
branches;
next	1.2;

1.2
date	2005.02.27.12.10.17;	author tcheun;	state Exp;
branches;
next	1.1;

1.1
date	2005.02.23.23.01.37;	author tcheun;	state Exp;
branches;
next	;


desc
@@


1.7
log
@change comment
@
text
@#!/bin/bash
#
# Install booyo and derivates to harddisk
#
# GPL
#
# Author: Fabian Franz <knoppix-installer@@fabian-franz.de>
# Modifier: Myoung Tcheun <tcheun@@chollian.net>
#
# Fixes and help by: Joerg Schirottke <master@@kanotix.de>
#
# Based on work by Christian Perle & Klaus Knopper
#
# English Spellcheck by [...]

#
# Constants
#

VERSION="0.3-6"
CONFIG_FILE="$HOME/.knofig"
LOG="$HOME/.knofig_log"

TARGET_MNT_POINT="/mnt/hdinstall" # TR1 in old installer
TARGET_MNT_NAME="hdinstall" # TR1 in old installer

DEFAULT_USER="booyo"
DEFAULT_NAME="BOOYO User"
DEFAULT_DIR="BOOYO"

# This is not Kano's Knoppix
INSTALL_KANO="no"

MEM_SWAP_NEEDED=$((512*1000)) # need some lower so that people that have 512 MB can use this option
SWAP_MIN=$((128*1024))

ROOT_MIN_RAW=$(df -m "/$DEFAULT_DIR" | tail -1 | awk '{print $3}')
ROOT_MIN_CORR=$[ROOT_MIN_RAW*115/100] # + 15% Filesystem overhead
ROOT_MIN=$(($ROOT_MIN_CORR*1024))

# Localisation 
export TEXTDOMAINDIR="/usr/share/locale"
export TEXTDOMAIN=booyo-installer

#
# Include needed Bash-Modules
#

SEARCHPATH="/usr/share/booyo-installer"
[ -f ./modules/00-knoppix-utils.bm ] && SEARCHPATH="."

for i in $(find $SEARCHPATH -name "*.bm")
do
  . $i
done

#
# Main program
#

clean_exit(){
  [ -n "$TMPDIR" ] && rm -rf "$TMPDIR"
  logit $"booyo-installer terminated"
  logit
}

trap clean_exit EXIT

function logit
{
  TIME=$(date)
  [ -n "$*" ] && echo $TIME: "$@@" >> $LOG || echo >> $LOG
}

function exit_proc
{
  unset IFS
  $DIALOG --backtitle "$BT" --title $"Save configuration?" --yesno $"Do you want to save your configuration?" 10 60
  RC=$?
  [ $RC -eq 0 ] && save_config $CONFIG_FILE # save of configuration
  [ $RC -ne 255 ] && exit 0
  RC=0
}

function setup_dialog_messages()
{
  MAX=5 # number of steps

  BT=$"BOOYO Installation"" (v$VERSION)"
  DT=$"Installation of BOOYO to harddisk (Step 0/$MAX)"
  INIT_T=$"Initialisation of BOOYO-Installation"
  T1=$INIT_T
  ET=$"Installation failed"
  ST=$"Installation successfull"
  FATAL_DIALOG=$"Fatal dialog error"

  N=1; # Step 1
}

setup_dialog "booyo-installer" # FIXME! Check for Commandline-Params
setup_dialog_messages

#
# Variables and Config File Management
#

function add_var
{
  case "$REGISTERED" in *$1*) return 1;; esac
  REGISTERED="$REGISTERED $1"
}

function register_vars
{
  for i in $@@;
  do
    add_var "$i"
  done
}

#
# Syntax: base, comment, allowed, checkfunc, default
#

function register_var
{
  export $1"_COMMENT"="$2"
  export $1"_ALLOWED"="$3"
  export $1"_CHECKIT"="$4"
  export $1"_DEFAULT"="$5"
  [ -z "${!1}" -a -n "$5" ] && export $1="$5"
}

function update_status
{
  echo -e "XXX\n$*\nXXX"
  logit "$*"
}


#
# FIXME: This management sucks!
#

# Beware: The real modules are set by module_system_set_modules

MODULES=(hd swap user userpass rootpass boot system)
#MODULES=(hd swap name user userpass rootpass host services boot)
NUM_MODULES=${#MODULES[@@]}
MODULES_AUTO="swap"
#MODULES_AUTO="swap services"
MODULES_NUMAUTO=$(echo $MODULES_AUTO | wc -w | tr -d ' ')
MODULES_LOAD="hd swap boot system"
#MODULES_LOAD="hd swap services boot system"

function create_config
{
  T1=$"Choose Install Type"
  
  # Configure system as the _very_ first
  # TODO: How to get back there ...

  module_system 0 || return 1
  if [ "$SYSTEM_MODULE" == "configured" ]
  then
  	# Set MODULES / NUM_MODULES for the configured system type.
  	module_system_set_modules
  fi
  
  NUM_REAL_MODULES=$[$NUM_MODULES-$MODULES_NUMAUTO]
  T1=$"Creating BOOYO Configuration Step (0/$NUM_REAL_MODULES)"
  N=1
  I=0
  DIR=0
  while [ "$I" -lt "$NUM_MODULES" ];
  do
    "module_${MODULES[$I]}" $DIR
    RC=$?
    DIR=0
    [ $RC -eq 1 ] && DIR=-1
    [ $RC -eq 0 ] && DIR=1
    I=$[$I+$DIR]
    [ $I -lt 0 ] && return 1
    stringinstring "${MODULES[$I]}" "$MODULES_AUTO" || N=$[$N+$DIR]
  done
  INSTALL_READY="yes"
  register_vars "INSTALL_READY"
  return 0
}

function check_param
{
  TEMP=$(eval echo \$$1"_ALLOWED")
  if [ -n "$TEMP" ]
  then
    if ! stringinstring "$2|" "$TEMP|"
    then
      DEFAULT_TEMP=$(eval echo \$$1"_DEFAULT")
      msgbox $"Error: Unknown value $2 for $1\nSetting to default value ($DEFAULT_TEMP)." 10 60
      export "$1"="$DEFAULT_TEMP"
      logit $"Error: Unknown value $2 for $1\nSetting to default value ($DEFAULT_TEMP)."
    fi
  fi
  
  TEMP=$(eval echo \$$1"_CHECKIT")
  if [ -n "$TEMP" ]
  then
    if ! $TEMP
    then
      msgbox $"Error: Check failed for $1 ($2)\nThe configuration module will now be started." 10 60
      export "$1"=""
      logit $"Error: Check failed for $1 ($2)\nThe configuration module will now be started."

      RC=1
      while [ "$RC" -eq "1" ]
      do
        ${TEMP/_check/} 1
        RC=$?
      done
    fi
  fi
  return 0
}

function load_config
{
  T1=$"Loading BOOYO configuration"
  if [ -z "$1" ]
  then
    wizard $"Here you can input a filename to load an existing configuration" --inputbox $"Input the configuration filename to be loaded" 10 60 "$CONFIG_USER"
    [ $? -ne 0 ] && return 1
    CONFIG_USER=$(cat $TMP)
    if [ ! -r "$CONFIG_USER" ]
    then
      msgbox $"File $CONFIG_USER could not be found. The loading of the configuration will be aborted." 10 60
      return 1
    fi
    set -- "$CONFIG_USER"
  fi
  logit "$T1 $1"
  . $1

  for i in $MODULES_LOAD
  do
    "module_${i}_defaults"
  done
  
  for i in $REGISTERED; 
  do
    #echo "$i=${!i}"
    #echo check_param "$i" "${!i}"
    check_param "$i" "${!i}"
  done
}

function save_config
{
  T1=$"Saving BOOYO configuration"
  if [ -z "$1" ]
  then
    wizard $"Here you can input a filename to save the configuration" --inputbox $"Input a filename for the configuration" 10 60 "$CONFIG_USER"
    [ $? -ne 0 ] && return 1
    CONFIG_USER=$(cat $TMP)
    [ -z "$CONFIG_USER" ] && return 1
    if [ -r "$CONFIG_USER" ]
    then
      wizard $"If you click yes, the file will be overwritten, otherwise this script will abort" --defaultno --yesno $"Do you really want to overwrite $CONFIG_USER?" 10 60
      [ $? -ne 0 ] && return 1
    fi
    set -- "$CONFIG_USER"
  fi
  logit "$T1 $1"
  echo "REGISTERED=\"$REGISTERED\"" > $1
  for i in $REGISTERED; 
  do
    [ "${!i}" = "configured" ] && echo "" >> $1
    TEMP=$(eval echo \$$i"_COMMENT")
    [ -n "$TEMP" ] && echo "# $TEMP" >> $1
    TEMP=$(eval echo \$$i"_ALLOWED")
    [ -n "$TEMP" ] && echo "#" $"Possible are:" $TEMP >> $1
    TEMP=$(eval echo \$$i"_CHECKIT")
    [ -n "$TEMP" ] && echo "#" $"This value will be checked by function" $TEMP >> $1
    TEMP=$(eval echo \$$i"_DEFAULT")
    [ -n "$TEMP" ] && echo "#" $"Default value is:" $TEMP >> $1
    
    echo "$i=\"${!i}\"" >> $1
  done
}

function show_install_options
{
  echo > $TMP
  I=0
  # System needs an extra sausage (german limerick ;-) )
#  module_system_showinfo >> $TMP

  while [ "$I" -lt "$NUM_MODULES" ]
  do
    "module_${MODULES[$I]}_showinfo"
    I=$[I+1]
  done >> $TMP
  echo "" >> $TMP
  echo $"Several of this options can only be changed in the Configurationfile $CONFIG_FILE." >> $TMP
  echo $"The Installation will now be started. The author, modifier and knopper.net give no warranty against any damage caused by this script." >> $TMP
  echo "" >> $TMP
  echo $"Do you want to proceed with these parameters?" >> $TMP
  DISP_TEXT=$(cat $TMP)
  wizard $"Make sure you agree to all parameters, if so proceed with the installation." --defaultno --yesno "$DISP_TEXT" 35 60
}

function old_installer
{
	if [ "$INSTALL_TYPE" = "FC3" ]
	then
		system_type_FC3
	else
		system_type_booyo1
	fi
	return 0
}

function do_install
{
  echo ""
  INSTALL_LIST="module_hd_doaction module_swap_doaction update_fstab old_installer add_bootmanager :"
  INSTALL_LIST_NUM=$[6-1]
  N=0;
  for i in $INSTALL_LIST
  do
    echo $[$N*100/$INSTALL_LIST_NUM]
    "${i}"
    [ $? -ne 0 ] && return 1
    N=$[$N+1]
  done
  return 0
}

function start_install
{
 if [ -z "$INSTALL_READY" ]
 then
   create_config
   [ $? -ne 0 ] && return 1
 fi
 T1=$"Starting BOOYO installation"
 if [ -z "$INSTALL_READY" ];
 then
   msgbox $"Error: No complete Configuration found" 10 60
   return 1
 fi
 show_install_options
 [ $? -ne 0 ] && return 1
 touch $TMPDIR/errors
 save_config $CONFIG_FILE
 T1=$"Starting BOOYO installation"
 do_install | $DIALOG --backtitle "$BT" --title "$T1" --gauge $"Installing" 10 60
 RC=$?
 MODULE_ERROR=$(<$TMPDIR/errors)
 if [ -n "$MODULE_ERROR" ]
 then
   msgbox "Error: $MODULE_ERROR" 10 60
   return 1
 fi
 [ $RC -ne "0" ] && return 1

 #
 # FLOPPY DISK!
 #

# if [ "$BOOT_DISK" = "yes" ]
# then
#   $DIALOG --backtitle "$BT" --title $"Creating floppy disk" --yesno $"Please insert now an empty floppy disk into your floppydrive. Warning: All data on it will be lost. If you don't want to create a disk you can choose No." 0 0
#   if [ $? -eq 0 ]
#   then
#     make_floppy
#   fi
# fi
 
 for i in $HD_MAP
 do
   point=$(echo $i | cut -d":" -f2)
   umount $TARGET_MNT_POINT$point
 done
		      
 # Just to be sure :-)
 umount $TARGET_MNT_POINT/proc
 umount $TARGET_MNT_POINT
 # Success Message and end installer
 #T1=$"Success!"
 T1=$ST
 
 msgbox $"BOOYO was successfully installed to hd." 15 60
 logit $"BOOYO was successfully installed to hd."
 exit 0
}

function menu_main
{
  T1=$"BOOYO Main-Menu"
  do_menu $"Thats the main menu\nChoose the action you want" $"Choose an action" \
  "create_config" $"Configure Installation" $"Create a new configuration" \
  "start_install" $"Start installation" $"Start the installation" \
  "action-part-later" $"Partition" $"Partition the hard disk" \
  "load_config" $"Load config" $"Load an existing configuration" \
  "save_config" $"Save config" $"Save the configuration" \
  "exit_proc" $"Quit" $"Quit the program"
}

function main()
{
logit $"BOOYO-installer started"
msgbox $"This script will install BOOYO to harddisk. \
Note that this version is still an very early version \
and under heavy development.
The author, modifier and knopper.net take no responsibility \
for data loss or hardware damage. \
\n\nAuthor: Fabian Franz <knoppix-installer@@fabian-franz.de> \
\nModifier: Myoung Tcheun <tcheun@@chollian.net> \
\nbased on the very good work by Christian Perle <perle@@itm.tu-clausthal.de> \
\nfixes by Joerg Schirottke <master@@kanotix.de>" 20 64
rebuildfstab -r
while ! check_partition_ok;
do
  msgbox $"The installer detected that the installation requierements are not fullfilled yet.\
\n\nPlease make sure that you have an free partition with at least $[ROOT_MIN/(1024*1024)] GB to install BOOYO on. \
Also we need a swap partition with at least $[SWAP_MIN/1024] MB, if you don't have 512 MB Memory or more.\
\n\nIn the following menu, you can start some tools to partition your harddrive.\
\nIf you really really know what you are doing start with: IGNORE_CHECK=1 sudo booyo-installer to avoid the menu." 21 60
  menu_part
done
logit $"Partition check succeeded"
[ -f "$CONFIG_FILE" ] && load_config $CONFIG_FILE # auto load of configuration

while true;
do
  menu_main
done
}

#
# UNTESTED-Please DO!
# Added non-interactive mode, FF 29.09.2003
#

function ni-main
{
  logit $"booyo-installer started"
  
  rebuildfstab -r
  logit $"Partition check succeeded"
  
  if [ ! -f "$CONFIG_FILE" ]
  then
  	echo $"Config file $CONFIG_FILE could not be found. This is necessary for non-interactive mode."
  	return
  fi
  load_config $CONFIG_FILE # auto load of configuration
 
  touch $TMPDIR/errors
  T1=$"Starting BOOYO installation"
  do_install | $DIALOG --backtitle "$BT" --title "$T1" --gauge $"Installing" 10 60
  RC=$?
  MODULE_ERROR=$(<$TMPDIR/errors)
  
  if [ -n "$MODULE_ERROR" ]
  then
    msgbox "Error: $MODULE_ERROR" 10 60
    return 1
  fi

  for i in $HD_MAP
  do
    point=$(echo $i | cut -d":" -f2)
    umount $TARGET_MNT_POINT$point
  done
		      
  # Just to be sure :-)
  umount $TARGET_MNT_POINT/proc
  umount $TARGET_MNT_POINT
  # Success Message and end installer
  logit $"BOOYO was successfully installed to hd."
  exit 0
}

if [ "$1" = "--non-interactive" ]
then
  ni-main
  exit 1 # something did go wrong
fi

if [ $UID -eq 0 ];
then
  main
else
  echo $"root permission needed."
fi

@


1.6
log
@change system type
@
text
@d154 1
a154 1
#MODULES_LOAD="hd swap services boot"
@


1.5
log
@adjust menu size
@
text
@d313 1
a313 1
	if [ "$INSTALL_TYPE" = "experienced" ]
d315 1
a315 1
		system_type_experienced
d317 1
a317 1
		system_type_beginner
@


1.4
log
@remove make_floppy
@
text
@d418 3
a420 3
\n\nModifier: Myoung Tcheun <tcheun@@chollian.net> \
\n\nbased on the very good work by Christian Perle <perle@@itm.tu-clausthal.de> \
\nfixes by Joerg Schirottke <master@@kanotix.de>" 20 60
@


1.3
log
@almost done
@
text
@d147 1
a147 4
<<<<<<< booyo-installer
MODULES=(hd swap name user userpass rootpass host services boot system)
=======
MODULES=(hd swap name user userpass rootpass host services boot system)
a148 1
>>>>>>> 1.2
d150 2
a151 1
MODULES_AUTO="swap services"
d153 1
a153 4
<<<<<<< booyo-installer
MODULES_LOAD="hd swap services boot system"
=======
MODULES_LOAD="hd swap services boot system"
a154 1
>>>>>>> 1.2
d370 8
a377 8
 if [ "$BOOT_DISK" = "yes" ]
 then
   $DIALOG --backtitle "$BT" --title $"Creating floppy disk" --yesno $"Please insert now an empty floppy disk into your floppydrive. Warning: All data on it will be lost. If you don't want to create a disk you can choose No." 0 0
   if [ $? -eq 0 ]
   then
     make_floppy
   fi
 fi
@


1.2
log
@BOOT_LOADER 은 grub 로 fix 했슴.

SYSTEM_TYPE 를 INSTALL_TYPE 로 변경했슴.
@
text
@d147 3
d152 1
d156 3
d161 1
d165 1
a165 1
#  T1=$"Choose System Type"
d170 3
a172 3
#  module_system 0 || return 1
#  if [ "$SYSTEM_MODULE" == "configured" ]
#  then
d174 2
a175 2
#  	module_system_set_modules
#  fi
d320 6
a325 14
#	if [ "$SYSTEM_TYPE" = "knoppix" ]
#	then
#		system_type_knoppix
#		return 0
#	fi
#	
#	system_type_beginner
#	
#	[ "$SYSTEM_TYPE" = "beginner" ] && return 0
#
#	update_status $"Converting Knoppix to Debian..."
#
#	system_services
	system_type_booyo
@


1.1
log
@add booyo-installer
@
text
@d147 2
a148 2
#MODULES=(hd swap name user userpass rootpass host services boot system)
MODULES=(hd swap name user userpass rootpass host services boot)
d152 2
a153 2
#MODULES_LOAD="hd swap services boot system"
MODULES_LOAD="hd swap services boot"
@

