#!/bin/sh
export PATH="/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin"

catiffile() {
  echo -n $STATUS
  if [ -d $1 ]; then
    if /bin/cp --parents -R $1 $ROOT; then
      echo_success
      return 1
    fi
  fi
  if [ -f $1 ]; then
    if /bin/cp --parents $1 $ROOT; then
      echo_success
      return 1
    fi
  fi
  echo_failure
  return 0
}

catifexec() {
  echo -n $STATUS
  if [ -x $1 ]; then
    if $* > $ROOT/`/bin/basename $1` 2>&1; then
      echo_success
      return 1
    fi
  fi
  echo_failure
  return 0
}

# The following was borrowed from the Red Hat 6.x init scripts function 
# to aid in letting the user know the application was still working.
#
# Get a sane screen width
[ -z "$COLUMNS" ] && COLUMNS=80

# Read in our configuration
if [ -z "$BOOTUP" ]; then
  if [ -f /etc/sysconfig/init ]; then
      . /etc/sysconfig/init
  else
    # This all seem confusing? Look in /etc/sysconfig/init,
    # or in /usr/doc/initscripts-*/sysconfig.txt
    BOOTUP=color
    RES_COL=60
    MOVE_TO_COL="echo -en \\033[300C\\033[$[${COLUMNS}-${RES_COL}]D"
    SETCOLOR_SUCCESS="echo -en \\033[1;32m"
    SETCOLOR_FAILURE="echo -en \\033[1;31m"
    SETCOLOR_WARNING="echo -en \\033[1;33m"
    SETCOLOR_NORMAL="echo -en \\033[0;39m"
    LOGLEVEL=1
  fi
fi

echo_success() {
  [ "$BOOTUP" = "color" ] && $MOVE_TO_COL
  echo -n "[  "
  [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS
  echo -n "OK"
  [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
  echo "  ]"
  return 0
}

echo_failure() {
  [ "$BOOTUP" = "color" ] && $MOVE_TO_COL
  echo -n "["
  [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
  echo -n "FAILED"
  [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
  echo "]"
  return 1
}

echo_passed() {
  [ "$BOOTUP" = "color" ] && $MOVE_TO_COL
  echo -n "["
  [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
  echo -n "PASSED"
  [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
  echo "]"
  return 1
}


