# installTcPackages - install tiny core packages
# parameter:
#  $@ - list of package names
# return:
#  0 is installed
#  1 something went wrong
installTcPackages(){
  while [ $# -gt 0 ];
  do
    su tc -c "tce-load -s -w -i $1" 2>&1 >/dev/null
    shift
  done
} 

# beginLogEntry - starts a new log entry
# parameter:
#  $1 - log message
# return:
#  none
# hint:
#  The log entries are saved in file /var/log/installer.log by default.
#  The location can be changed with the variable $LOGFILE_PATH
beginLogEntry(){
  echo -n "$1... " | tee -a ${LOGFILE_PATH:-/var/log/installer.log}
}

# finishLogEntry - finishs a started log entry
# parameter:
#  $1 - result of log content
# return:
#  none
# hint:
#  The log entries are saved in file /var/log/installer.log by default.
#  The location can be changed with the variable $LOGFILE_PATH
finishLogEntry(){
  echo "$1" | tee -a ${LOGFILE_PATH:-/var/log/installer.log}
}

# getAnswerfile - downloads Answerfile
# parameter:
#  $1 - remote answerfile path 
#  $2 - local path answerfile path 
# return:
#  0 - no error 
#  1 - error occurred
getAnswerfile() {
  local retval=1
 
  if [ $# -eq 2 ];
  then
    wget -q -O $2 $1
    retval=$?
  fi

  return ${retval} 
}

# runChroot - prepare and run a chroot environment for second stage installer
# parameter:
#  $1 - path of second stage installer script inside the chroot environment
# return:
#  none
runChroot(){
  mkdir -p /target/{dev/pts,proc,sys}
  mount /dev /target/dev --bind
  mount devpts /target/dev/pts -t devpts
  mount none /target/proc -t proc
  mount none /target/sys -t sysfs
    
  LANG=C.UTF-8 chroot /target $1
    
  umount /target/sys
  umount /target/proc
  umount /target/dev/pts
  umount /dev /target/dev
}