2018-01-07 23:18:45 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2020-07-18 23:31:29 +00:00
|
|
|
function join_by { local d=$1; shift; echo -n "$1"; shift; printf "%s" "${@/#/$d}"; }
|
|
|
|
|
2018-01-07 23:18:45 +00:00
|
|
|
function isURL {
|
|
|
|
local value=$1
|
|
|
|
|
2019-11-21 19:50:06 +00:00
|
|
|
if [[ ${value:0:8} == "https://" || ${value:0:7} == "http://" ]]; then
|
2018-01-07 23:18:45 +00:00
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function isTrue {
|
|
|
|
local value=${1,,}
|
|
|
|
|
|
|
|
result=
|
|
|
|
|
|
|
|
case ${value} in
|
|
|
|
true|on)
|
|
|
|
result=0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
result=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
return ${result}
|
2019-02-03 15:49:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function isDebugging {
|
2019-09-15 14:54:13 +00:00
|
|
|
if [[ -v DEBUG ]] && [[ ${DEBUG^^} = TRUE ]]; then
|
2019-02-03 15:49:59 +00:00
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function debug {
|
|
|
|
if isDebugging; then
|
2020-03-06 15:52:17 +00:00
|
|
|
log "DEBUG: $*"
|
2019-02-03 15:49:59 +00:00
|
|
|
fi
|
2019-11-21 19:50:06 +00:00
|
|
|
}
|
2020-03-06 15:52:17 +00:00
|
|
|
|
|
|
|
function logn {
|
|
|
|
echo -n "[init] $*"
|
|
|
|
}
|
|
|
|
|
|
|
|
function log {
|
|
|
|
echo "[init] $*"
|
|
|
|
}
|
2020-04-11 15:41:20 +00:00
|
|
|
|
2020-05-23 14:15:10 +00:00
|
|
|
function logAutopause {
|
|
|
|
echo "[Autopause loop] $*"
|
|
|
|
}
|
|
|
|
|
|
|
|
function logAutopauseAction {
|
|
|
|
echo "[$(date -Iseconds)] [Autopause] $*"
|
|
|
|
}
|
|
|
|
|
2020-04-11 15:41:20 +00:00
|
|
|
function normalizeMemSize {
|
|
|
|
local scale=1
|
|
|
|
case ${1,,} in
|
|
|
|
*k)
|
|
|
|
scale=1024;;
|
|
|
|
*m)
|
|
|
|
scale=1048576;;
|
|
|
|
*g)
|
|
|
|
scale=1073741824;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
val=${1:0: -1}
|
|
|
|
echo $(( val * scale ))
|
|
|
|
}
|
2020-04-13 23:29:44 +00:00
|
|
|
|
|
|
|
function versionLessThan {
|
|
|
|
local activeParts
|
|
|
|
IFS=. read -ra activeParts <<< "${VANILLA_VERSION}"
|
|
|
|
|
|
|
|
local givenParts
|
|
|
|
IFS=. read -ra givenParts <<< "$1"
|
|
|
|
|
2020-04-18 02:15:44 +00:00
|
|
|
if (( ${#activeParts[@]} < 2 )); then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2020-05-20 13:17:58 +00:00
|
|
|
if (( ${#activeParts[@]} == 2 )); then
|
|
|
|
if (( activeParts[0] < givenParts[0] )) || \
|
|
|
|
(( activeParts[0] == givenParts[0] && activeParts[1] < givenParts[1] )); then
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
2020-04-13 23:29:44 +00:00
|
|
|
else
|
2020-05-20 13:17:58 +00:00
|
|
|
if (( activeParts[0] < givenParts[0] )) || \
|
|
|
|
(( activeParts[0] == givenParts[0] && activeParts[1] < givenParts[1] )) || \
|
|
|
|
(( activeParts[0] == givenParts[0] && activeParts[1] == givenParts[1] && activeParts[2] < givenParts[2] )); then
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
2020-04-13 23:29:44 +00:00
|
|
|
fi
|
2020-06-19 16:31:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
requireVar() {
|
|
|
|
if [ ! -v $1 ]; then
|
|
|
|
log "ERROR: $1 is required to be set"
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-07-19 20:01:19 +00:00
|
|
|
if [ -z "${!1}" ]; then
|
|
|
|
log "ERROR: $1 is required to be set"
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-06-19 16:31:56 +00:00
|
|
|
}
|
2020-07-26 18:19:45 +00:00
|
|
|
|
|
|
|
function writeEula() {
|
|
|
|
if ! echo "# Generated via Docker on $(date)
|
|
|
|
eula=${EULA,,}
|
|
|
|
" > /data/eula.txt; then
|
|
|
|
log "ERROR: unable to write eula to /data. Please make sure attached directory is writable by uid=${UID}"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
}
|