#!/bin/bash

DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/opt/drbl/}"
. $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
. $DRBL_SCRIPT_PATH/conf/drbl-ocs.conf
. $DRBL_SCRIPT_PATH/sbin/ocs-functions

if ! grep -q -Ew ocs_prerun /proc/cmdline; then
  exit 1
fi
parse_cmdline_option "ocs_prerun"

if [ -n "$ocs_prerun" ]; then
  # run it
  echo "Found ocs_prerun parameter in boot parameters... Running $ocs_prerun..."
  # Since "$ocs_prerun" might not be exe mode, so we test it if it's script, use . $ocs_prerun, else, run it directly.
  if [ "$(LANG=C file -Ls $ocs_prerun 2>/dev/null | grep -iE "shell script")" ]; then
    . $ocs_prerun
  else
    $ocs_prerun
  fi
fi
