#! /bin/sh
# -------------------------------------------------------------------------
# creates a fli4l-Floppy or Image                              3.0.1
#
# Creation: 2004-10-25 LanSpezi
# $Id: mkfli4l.sh 10619 2005-12-14 22:49:39Z arwin $
# -------------------------------------------------------------------------

# include cleanup-functions
. ./unix/scripts/_lib_cleanup.sh

# include function to check command-line
. ./unix/scripts/parse_cmd.sh

# check parameters from commandline and current env
parse_cmdline "$@"

if [ "$bool_cleanup" = "true" ]
then
  cleanup
  cleanup_fli4lfiles
  cleanup_mkfli4l
  exit 1
fi

if [ "$bool_error" = "false" -a "$bool_usage" = "false" ]
then
  if [ "$remoteupdate" = "true" -o "$bool_filesonly" = "true" ]
  then
    . unix/scripts/mkopt.sh
  else

    case "$boot_type"
    in
      dual*|fdx2)
        . unix/scripts/mkfloppy.sh
        ;;
      fd*)
        . unix/scripts/mkfloppy.sh
        ;;
      ls120)
	echo "- build of a bootable ls120-disk is not available" >> /tmp/mkfli4l_error.log
	bool_error=true
	;;
      netboot)
        . unix/scripts/mkopt.sh
        if [ "$bool_error" = "false" ]
        then
          . unix/scripts/mknetboot.sh
        fi
        ;;
      pxeboot)
        . unix/scripts/mkpxeboot.sh
        ;;
      hd|attached|integrated)
        . unix/scripts/mkopt.sh
        ;;
      cd)
        . unix/scripts/mkiso.sh
        ;;
      cdemul)
        . unix/scripts/mkiso_emul.sh
        ;;
      *)
        # otherboot
        if [ -f unix/scripts/mk${boot_type}.sh ]
        then
          . unix/scripts/mk${boot_type}.sh
        else
	  echo "- can not execute script for BOOT_TYPE=$boot_type" >> "/tmp/mkfli4l_error.log"
	  echo "- file not found: unix/scripts/mk$boot_type.sh" >> "/tmp/mkfli4l_error.log"
        fi
        ;;
    esac
  fi
fi

if [ "$bool_error" = "true" ]
then
  if [ "$dir_build" != "" ]
  then
    echo "An Error occured while creating fli4l-files" > "$dir_build/mkfli4l_error.log"
    echo "===========================================" >> "$dir_build/mkfli4l_error.log"
    cat /tmp/mkfli4l_error.log >> "$dir_build/mkfli4l_error.log"
    rm /tmp/mkfli4l_error.log
    touch "$dir_build/mkfli4l_error.flg"
    echo ""
    cat "$dir_build/mkfli4l_error.log"
    echo ""
    echo "hit RETURN to continue ..."
    read
  else
    echo ""
    echo "An Error occured while creating fli4l-files" 
    echo "==========================================="
    cat /tmp/mkfli4l_error.log
    rm /tmp/mkfli4l_error.log
    echo ""
    echo "hit RETURN to continue ..."
    read
  fi
  exit 1
fi

if [ "$remoteupdate" = "true" -a "$bool_usage" = "false" ]
then
  scp -P $remoteport "$dir_build/rc.cfg" "$dir_build/opt_tar.bz2" "$dir_build/kernel" "$dir_build/rootfs.img" "$dir_build/syslinux.cfg" ${remoteusername}@${remotehostname}:${remotepathname}
fi
exit 0
