diff options
Diffstat (limited to 'rc.d/init.d/functions')
-rwxr-xr-x[-rw-r--r--] | rc.d/init.d/functions | 78 |
1 files changed, 72 insertions, 6 deletions
diff --git a/rc.d/init.d/functions b/rc.d/init.d/functions index 2e3da964..b8bd20bc 100644..100755 --- a/rc.d/init.d/functions +++ b/rc.d/init.d/functions @@ -5,6 +5,13 @@ # TEXTDOMAIN=initscripts +TEXTDOMAINDIR=/etc/locale +LOCPATH=/etc/locale +export TEXTDOMAINDIR LOCPATH + +TMP=/tmp +TMPDIR=/tmp +export TMP TMPDIR # Make sure umask is sane umask 022 @@ -55,8 +62,6 @@ systemctl_redirect () { action "$s" /bin/systemctl $options $command "$prog.service" } -# Get a sane screen width -[ -z "${COLUMNS:-}" ] && COLUMNS=80 if [ -z "${CONSOLETYPE:-}" ]; then if [ -c "/dev/stderr" ] && [ -r "/dev/stderr" ]; then @@ -66,6 +71,10 @@ if [ -z "${CONSOLETYPE:-}" ]; then fi fi +# Get a sane screen width, and default to 80 when exact info not available +[ -z "${COLUMNS:-}" ] && COLUMNS=`stty -a 2>/dev/null | sed -n 's/.*columns \([0-9]*\);.*/\1/p'` +[ -z "${COLUMNS:-}" ] && COLUMNS=80 + if [ -z "${NOLOCALE:-}" ] && [ -z "${LANGSH_SOURCED:-}" ] && \ [ -f /etc/sysconfig/i18n -o -f /etc/locale.conf ] ; then . /etc/profile.d/lang.sh 2>/dev/null @@ -108,6 +117,60 @@ if [ -z "${BOOTUP:-}" ]; then fi fi +gprintf() { + if [ -x /bin/gettext -a -n "$1" ]; then + if [ -n "$GP_LANG" ]; then + local TEXT=`LC_ALL=$GP_LANG LANGUAGE=$GP_LANGUAGE gettext -e --domain=$TEXTDOMAIN -- "$1"` + else + local TEXT=`gettext -e --domain=$TEXTDOMAIN -- "$1"` + fi + else + local TEXT=$1 + fi + [ "${1#*\\n}" ] || TEXT="$TEXT\n" + + shift + printf -- "$TEXT" "$@" +} + +# Frontend to gprintf (support up to 4 %s in format string) +# returns the message transleted in GPRINTF_MSG and +# the resting parms in GPRINTF_REST +# This simplifies a lot the call of functions like action, +# now with i18n support +gprintf_msg_rest() { +case "$1" in + *%s*%s*%s*%s*) + GPRINTF_MSG=$(gprintf "$1" "$2" "$3" "$4" "$5") + shift 5;; + *%s*%s*%s*) + GPRINTF_MSG=$(gprintf "$1" "$2" "$3" "$4") + shift 4;; + *%s*%s*) + GPRINTF_MSG=$(gprintf "$1" "$2" "$3") + shift 3;; + *%s*) + GPRINTF_MSG=$(gprintf "$1" "$2") + shift 2;; + *) + GPRINTF_MSG=$(gprintf "$1") + shift;; +esac +GPRINTF_REST="$@" +} + +# Check if $pid (could be plural) are running with +# the same root as this script +inmyroot() { + local i r + + for i in $* ; do + [ "/proc/$i/root" -ef "/proc/$$/root" ] && r="$r $i" + done + echo "$r" +} + + # Check if any of $pid (could be plural) are running checkpid() { local i @@ -579,6 +642,7 @@ update_boot_stage() { # Log that something succeeded success() { + gprintf_msg_rest "$@" [ "$BOOTUP" != "verbose" -a -z "${LSB:-}" ] && echo_success return 0 } @@ -586,6 +650,7 @@ success() { # Log that something failed failure() { local rc=$? + gprintf_msg_rest "$@" [ "$BOOTUP" != "verbose" -a -z "${LSB:-}" ] && echo_failure [ -x /bin/plymouth ] && /bin/plymouth --details return $rc @@ -594,6 +659,7 @@ failure() { # Log that something passed, but may have had errors. Useful for fsck passed() { local rc=$? + gprintf_msg_rest "$@" [ "$BOOTUP" != "verbose" -a -z "${LSB:-}" ] && echo_passed return $rc } @@ -601,6 +667,7 @@ passed() { # Log a warning warning() { local rc=$? + gprintf_msg_rest "$@" [ "$BOOTUP" != "verbose" -a -z "${LSB:-}" ] && echo_warning return $rc } @@ -608,11 +675,10 @@ warning() { # Run some action. Log its output. action() { local STRING rc + gprintf_msg_rest "$@" + echo -n "$GPRINTF_MSG " - STRING=$1 - echo -n "$STRING " - shift - "$@" && success $"$STRING" || failure $"$STRING" + $GPRINTF_REST && success "$GPRINTF_MSG" || failure "$GPRINTF_MSG" rc=$? echo return $rc |