/etc/init.d/functions and action in centos and debian

Viewed 461

In centos.

source  /etc/init.d/functions
action "work done"  /bin/true
action  "wrong"  /bin/false

It show as below.

work done   [OK]
wrong       [FAILED]

I found that no /etc/init.d/functions in debian ,how to use action "work done" /bin/true then?
Copy the file /etc/init.d/functions in centos into usb,and copy the file /etc/init.d/functions from usb into my debian?

1 Answers

You can probably copy that script over but there might be some files and binaries that the script is using that are only available in CentOS. If you only need the fancy output of the function action(), here is a minimal script for that.

success() {
  echo -en "\\033[60G[\\033[1;32m  OK  \\033[0;39m]\r"
  return 0
}

failure() {
  local rc=$?
  echo -en "\\033[60G[\\033[1;31mFAILED\\033[0;39m]\r"
  [ -x /bin/plymouth ] && /bin/plymouth --details
  return $rc
}

action() {
  local STRING=$1
  echo -n "$STRING "
  shift
  "$@" && success $"$STRING" || failure $"$STRING"
  local rc=$?
  echo
  return $rc
}

Note however that the original functions script does more by checking the type of console and other stuff.

Related