-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib-bash.sh
executable file
·76 lines (64 loc) · 2.73 KB
/
lib-bash.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
73
74
75
76
#!/bin/bash
# Author: Norbert Kiszka and others
# License: GPL v2
# Library primarly intented for a Orange Rigol project, which can be found at https://github.com/norbertkiszka/rigol-orangerigol-build
# Some of code is a copy from https://sourceforge.net/projects/libbash/
if [ "$__LIB_BASH_REQUIRED_MINIMAL_BASH_VERSION" != "" ] ; then
__message="Lib-Bash: Here we go again"
if [ -e /usr/games/cowsay ] ; then
/usr/games/cowsay "$__message"
else
echo "$__message"
fi
#return
fi
__lib_bash_filename="$(basename "$BASH_SOURCE")"
__lib_bash_real_filename="$(realpath "$BASH_SOURCE")"
if [ ${#BASH_SOURCE[@]} -eq 1 ] && [ "${1}" != "libignoredirect" ] ; then
__lib_bash_called_directly="y"
__message="${__lib_bash_filename} called directly"
if [ -e /usr/games/cowsay ] ; then
/usr/games/cowsay "$__message"
else
echo "$__message"
fi
else
set -e
__lib_bash_called_directly=""
fi
__LIB_BASH_VERSION="0.2.11"
if [ "${LIB_BASH_VERSION}" == "" ] ; then
readonly LIB_BASH_VERSION="${__LIB_BASH_VERSION}"
readonly __LIB_BASH_REQUIRED_MINIMAL_BASH_VERSION="4.2"
elif [ "${LIB_BASH_VERSION}" != "${__LIB_BASH_VERSION}" ]; then
echo "${__lib_bash_filename} called again but now we have another version!!!"
echo "Please restart bash if You want to load other version."
exit 1
fi
# Arg1: version to test
# Arg2: required version
# Borrowed from a https://unix.stackexchange.com/questions/285924/how-to-compare-a-programs-version-in-a-shell-script and changed a little bit
version_is_eqal_or_greater_than()
{
if [ "$(printf '%s\n' "${2}" "${1}" | sort -V | head -n1)" = "${2}" ]; then
return 0
else
return 1
fi
}
if ! version_is_eqal_or_greater_than "${BASH_VERSION}" "${__LIB_BASH_REQUIRED_MINIMAL_BASH_VERSION}" ; then
echo "This lib requires bash version "${__LIB_BASH_REQUIRED_MINIMAL_BASH_VERSION}" or greater but ${BASH_VERSION} was detected"
exit 1
fi
ROOT=`pwd` # For external use. Please dont overwrite this - I can't make it readonly since this lib can be called multiple times inside same enviroment.
__lib_bash_build_libdir="$(dirname $BASH_SOURCE)/lib"
source ${__lib_bash_build_libdir}/colors.sh
source ${__lib_bash_build_libdir}/sctrace.sh
source ${__lib_bash_build_libdir}/errorhandling.sh
source ${__lib_bash_build_libdir}/sys.sh
source ${__lib_bash_build_libdir}/whiptail-menu.sh
source ${__lib_bash_build_libdir}/git.sh
# Variable from app (from a user script)
if [ "$REQUIRED_LIB_BASH_VERSION_AT_LEAST" != "" ] && ! version_is_eqal_or_greater_than "${LIB_BASH_VERSION}" "${REQUIRED_LIB_BASH_VERSION_AT_LEAST}" ; then
error "This app requires lib-bash version "${REQUIRED_LIB_BASH_VERSION_AT_LEAST}" or greater but ${LIB_BASH_VERSION} was detected. Please execute git pull inside $(dirname $BASH_SOURCE) in order to update lib-bash."
fi