/
functions.sh
executable file
·72 lines (59 loc) · 1.83 KB
/
functions.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/sh
### BEGIN INIT INFO
# Provides: functions.sh
# Required-Start:
# Required-Stop:
# Short-Description: Replicates Gentoo's functions.sh
# Description: Replicates Gentoo's functions.sh in a portable way.
# Obviously borrow heavily from the original rc script
# written by Roy Marples
### END INIT INFO
# Copyright (c) 2015 Marcus Downing <marcus.downing@gmail.com>
# Released under the 2-clause BSD license.
eindent() {
. "$EFUNCTIONS_DIR/eindent"
}
eoutdent() {
. "$EFUNCTIONS_DIR/eoutdent"
}
# http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac
abspath() {
if readlink -f "$1" 2>&1 | grep -q 'readlink: illegal option -- f'; then
TARGET_FILE="$1"
cd `dirname "$TARGET_FILE"`
TARGET_FILE=`basename "$TARGET_FILE"`
# Iterate down a (possible) chain of symlinks
while [ -L "$TARGET_FILE" ]
do
TARGET_FILE="`readlink "$TARGET_FILE"`"
cd "`dirname "$TARGET_FILE"`"
TARGET_FILE="`basename "$TARGET_FILE"`"
done
# Compute the canonicalized name by finding the physical path
# for the directory we're in and appending the target file.
PHYS_DIR="`pwd -P`"
RESULT="$PHYS_DIR/$TARGET_FILE"
else
RESULT="$(readlink -f "$1")"
fi
echo $RESULT
}
if [ -x "/etc/init.d/functions.sh" ]; then
HERE="$(abspath "/etc/init.d/functions.sh")"
else
HERE="$(abspath "$0")"
fi
DIR="$(dirname "$HERE")"
export EFUNCTIONS_DIR="$DIR/efunctions"
export PATH="$PATH:$EFUNCTIONS_DIR"
if [ -n "$TERM" ] && [ "$TERM" = unknown ] ; then
export TERM=dumb
fi
if [ -z "$TERMINFO" ]; then
export TERMINFO=$(whereis terminfo | grep -o '^[^ ]* [^ ]*' | grep -o '[^ ]*$')
fi
export EFUNCTIONS_ECHO="$(which echo)"
if [ "yes" != "$EFUNCTIONS_LOADED" ]; then
export EINFO_INDENT=0
fi
export EFUNCTIONS_LOADED="yes"