#!/bin/sh

init(){
  echo
  export modname="hakchi"
  export modpath="/$modname"
  export mountpoint="/newroot"
  export temppath="/tmp"
  export bootVersion="1.0.1"
  echo "$modname init script version: $bootVersion"

  /bin/busybox --install -s /bin/
  mkdir -p "$temppath"
  for dir in etc lib usr; do
    [ -e "/$dir" ] || ln -s "$mountpoint/$dir" "/$dir"
  done
  export PATH="/sbin:$modpath/rootfs/bin:/bin:$mountpoint/sbin:/usr/sbin:$mountpoint/bin:/usr/bin"

  source "$modpath/config"
  source "$modpath/script/base"

  if [ -d "$modpath/transfer" ]; then
    source "$modpath/script/transfer"
  else
    mount_base
  fi

  if [ -f "$preinit" ]; then
    export preinit
    PATH="$rootfs/sbin:$rootfs/usr/sbin:$rootfs/bin:$rootfs/usr/bin:$PATH"
    "$rootfs/bin/busybox" sh -c "source "$preinit" && preinit"
  else
    umount_base
  fi
}

init
echo
