-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathScriptFunctions
executable file
·81 lines (74 loc) · 2.41 KB
/
ScriptFunctions
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
73
74
75
76
77
78
79
80
81
#!/bin/sh (source)
. GoboPath
# OverlayFS-aware executable path finder.
# This function is used to define "scriptPath" below and also by our "which" wrapper.
ExecutablePath() {
local execpath="$(readlink -f "$1")"
if [ "$(dirname "$execpath")" = "$goboSystem/Index/bin" ]
then
base="$(basename $execpath)"
overlay_dirs="$(grep "^overlay $goboSystem/Index/bin" /proc/self/mounts | sed 's/.*lowerdir=\(.*\),upperdir=.*/\1/g')"
for lower_dir in $(echo "$overlay_dirs" | tr -s ":" "\n" | grep -v "$goboSystem/Index/bin")
do
[ -e "$lower_dir/$base" ] && execpath="$lower_dir/$base" && break
done
fi
echo "$execpath"
}
export PATH=$PATH:$goboExecutables
export scriptName=`basename "$0"`
export scriptPath="$(dirname "$(ExecutablePath "$0")" 2> /dev/null)"
export scriptVersion="$(basename "$(readlink -f "$scriptPath/..")")"
# Find_Conf is not available yet
bootOptions="${goboSettings}/BootScripts/Options"
[ -e "$bootOptions" ] && source "$bootOptions"
scriptOptions="${goboSettings}/Scripts/Options"
[ -e "$scriptOptions" ] && source "$scriptOptions"
userOptions="${goboUserSettings}/Scripts/Options"
[ -e "$userOptions" ] && source "$userOptions"
Import() {
var="$(echo $1|sed 's/\./_/g')"
local cmd="echo \${Imported$var}"
if ! [ `eval $cmd` ]
then
eval "Imported$var=$1"
for try in "${scriptPath}/$1.import" \
"${scriptPath}/../Functions/$1" \
"${goboPrefix}/Programs/Scripts/Current/Functions/$1" \
"/Programs/Scripts/Current/Functions/$1"
do
if [ -e "$try.sh" ]
then
. "$try.sh"
fi
if [ -e "$try" ]
then
. "$try"
return
fi
done
echo "Missing import: $1"
exit 1
fi
}
# An easy and safe way to declare parameters in a function.
# Pass to this function: (a) your function's received parameters
# and (b) their names, like in 'Parameters "$@" first second'.
# Variables according to the given names will be created.
Parameters() {
shopt -s expand_aliases 2>/dev/null
# (( $# % 2 == 0 )) || { echo "Invalid number of parameters"; exit 1; }
shopt -u expand_aliases 2>/dev/null
local var val middle i
middle=$(($#/2))
i=1
while [ $i -le $middle ]
do
eval var='${'$((middle + i))'}'
val='${'$i'}'
eval ${var}'="'"$val"'"'
i=$((i+1))
done
}
Import Log
Import "Log$logMode"