#!/bin/sh

# Read flags from bootloader, and store to /tmp/.boot.cnf .
BOOTPARAM_CNFFILE="/tmp/.boot.cnf"
CNFREPO="/tmp/.cnfrepo"
BOOT_DEVICE_FILE="/tmp/.boot_device"

read_args() {
  [ -z "$CMDLINE" ] && CMDLINE=$( cat /proc/cmdline )
  for arg in $CMDLINE; do
    optarg=$( expr "x$arg" : 'x[^=]*=\(.*\)' )
    case $arg in
      root)
        # Write boot device (/dev/sda, etc) to BOOT_DEVICE_FILE, if runs extreme mode.
        echo "$optarg" >> $BOOT_DEVICE_FILE
	;;

      forcefb)
        echo "COCON_FORCEFB=1"  >> $BOOTPARAM_CNFFILE
        ;;
      forcexdrv)
        echo "COCON_FORCEXDRV=1" >> $BOOTPARAM_CNFFILE
        ;;
#            dropbear)
#                echo "COCON_DROPBEAR=1"  >> $BOOTPARAM_CNFFILE
#                ;;
#            stopbeforex)
#                echo "COCON_XDEBUG=1"  >> $BOOTPARAM_CNFFILE
#                ;;
#            delayreadcfg)
#                echo "COCON_DELAY_CFG=1"  >> $BOOTPARAM_CNFFILE
#                ;;
    esac
  done
}

read_args

# parse to repository file
if [ -f "$BOOTPARAM_CNFFILE" ];
then
  coconcnf_parse -c "$BOOTPARAM_CNFFILE" -m "$CNFREPO" -b
fi

