#!/bin/bash
#
# /etc/bash.common.sh
#	/LinuxRC/linuxrc.common.sh
#	/root/Customization/Customizations.common.sh
#
#
#
# 06-Nov-04 amo Date-of-Birth
# 13-Nov-04 amo Split off ramdisk options into linuxrc.Commands.Help.txt
# 20-Nov-04 amo Split off common mount and checking to linuxrc.common.sh
# 23-Nov-04 amo Use CFRW to debug mount CF as rw vs ro options -> linuxrc -> /etc/fstab
# 17-Mar-05 amo Added bootUSB in addition to bootCF
# 03-Sep-05 amo Added BootMsg variable
# 11-Sep-05 amo Moved some global variables into common ( CUSTOM )
# 12-Sep-05 amo New VER, RELEASE gloabl variable for Release Version
# 28-Sep-05 amo Release as 2005.0928, change $RELEASE
# 29-Sep-05 amo Use Generic Release Names ( SBM-test ) and Finalize while copying into $RELEASE
#
#
#
#
# Define the path
# ----------------
PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"
#
CUSTOM="/mnt/Customizations"
#
# do NOT change $VER
VER=SBM-test
#
# Change Release versions
# -----------------------
#ELEASE="/opt/Bootable.2005/TGZ"
#ELEASE="/opt/Bootable.2005/Bootable.2005.0911"
#ELEASE="/opt/Bootable.2005/Bootable.2005.0928"
RELEASE="/opt/Bootable.2005/Bootable.2005.test"
#
#
export PATH CUSTOM VER
#
#
# Leave the variable alone if it was already defined
# --------------------------------------------------
if [ -z "$DebugMsg" ];
then
  # explicitly turn it off
  DebugMsg="off"
fi
#
export DebugMsg
#
#
#
# Mount the CompactFlash as ro
# ----------------------------
#       - rw causes it to fail to boot
CFRW="ro"
# CFRW="rw"
#
#
# -----------------
# Echo the mssages
# -----------------
#       BootMsg defined from lilo/grub: boot:  BootMsg=1
#
function BootMsg
{
  msg="$1"
  #
  # just echo the messages unless "debug" is turned off
  # ----------------------
  if [ "$DebugMsg" != "off" ];
  then
    echo "$msg"
  fi
  #
} # BootMsg
#
#
# Exit if the Commands fails
# ==========================
#
function docmd
{
  cmd="$1"
  fix="$2"
  #
  ERR=""
  #
  # check for the mount commands
  mnt=`echo "$cmd" | grep ^mount | cut -d ' ' -f 1`
  #
  # check for comments
  com=`echo "$cmd" | grep ^#     | cut -d ' ' -f 1`
  #
  #
  if [ "$com" = "#" ];
  then
    #
    # not a command
    BootMsg "$cmd"
    #
  else
    #
#   BootMsg ""
    BootMsg "$cmd"
    eval "$cmd"
    #
    stat=$?
    #
    if [ $stat != 0 ];
    then
      BootMsg ""
      BootMsg "ERROR: Failed: ${stat}: $cmd "
      echo    "ERROR: Failed: ${stat}: $cmd "
      #
      # mount and df fails depending on /proc being mounted or not
      #		32 == it wants " mount -t type "
      if [ "$mnt" = "mount" -a $stat != 32 ];
      then
        BootMsg " already mounted"
        BootMsg ""
      else
        BootMsg "#"
        BootMsg "# Aborting: $0 "
        BootMsg "#"
        echo    "# Aborting: $0 "
        #
        ERR="1"
      fi
    fi
    #
    # show what's mounted after the mount command
    #	-
    #	- use space in front of " mount" to avoid these debug messages
    #	-
    #
    if [ "$mnt" = "mount" ];
    then
      docmd "cat /proc/mounts"
#     ls -la /etc/mtab
      docmd "cat /etc/mtab"
      docmd "df"
#     docmd "mount"
    fi
    #
    # -a "$ERREXIT" = "exit-on-critical-error" ];
    #
    if [ ! -z "$ERR" ];
    then
      #
      # show any helpful hints to fix the problem
      #
      if [ ! -z "$fix" ] ;
      then
        #
        echo "#     Try to Fix it with: $fix "
        echo "#"
        #
      fi
      #
      exit 1 
    fi
  fi
  #
} # docmd
#
#
#
# Check /proc
# ===========
#
function mount_proc
{
  #
  if [ ! -f /proc/mounts ];
  then
    #
    # Mount /proc filesystem
    # ----------------------
    #ocmd "mount -n -t proc proc /proc"
    #
    # knoppix uses none and /dev/pts
    docmd " mount -n -t proc  none /proc"
    #ocmd " mount -n -t devfs none /dev/pts"
    #
  else
    #
    BootMsg "#"
    BootMsg "# /proc already mounted "
    BootMsg "#"
    #
  fi
  #
} # mount_proc
#
#
# End of linuxrc.common.sh file

