summaryrefslogtreecommitdiffstats
path: root/helper
diff options
context:
space:
mode:
authorSimon Rettberg2014-07-27 00:10:16 +0200
committerSimon Rettberg2014-07-27 00:10:16 +0200
commit62d78729a32dd136feddede21a5dc6e9c3dbe2d7 (patch)
treedccd7c833bb33825c45922397dd84d629d25f05f /helper
parent[rfs-s31] fix busybox copying v2 (diff)
downloadtm-scripts-62d78729a32dd136feddede21a5dc6e9c3dbe2d7.tar.gz
tm-scripts-62d78729a32dd136feddede21a5dc6e9c3dbe2d7.tar.xz
tm-scripts-62d78729a32dd136feddede21a5dc6e9c3dbe2d7.zip
helpers/includes now should include an __init function and not just do stuff right away when being sourced
Diffstat (limited to 'helper')
-rw-r--r--helper/fileutil.inc5
-rw-r--r--helper/logging.inc32
-rw-r--r--helper/string.inc6
3 files changed, 20 insertions, 23 deletions
diff --git a/helper/fileutil.inc b/helper/fileutil.inc
index 10b4bbc7..9dc2c07b 100644
--- a/helper/fileutil.inc
+++ b/helper/fileutil.inc
@@ -31,4 +31,9 @@ tarcopy () {
[ "x${PS[1]}" != "x0" ] && perror "unpacking-part of tar-copy from '$SHORT' to '$TO' failed. (${PS[1]})"
}
+# usage: CANONICALIZED_PATH=$(canonalize <path>)
+# usage with relative path requires you to be in the correct directory.
+canonicalize() {
+ cd -P -- "$(dirname -- "$1")" && printf '%s\n' "$(pwd -P)/$(basename -- "$1")"
+}
diff --git a/helper/logging.inc b/helper/logging.inc
index 8b102d4c..2e8eeeb7 100644
--- a/helper/logging.inc
+++ b/helper/logging.inc
@@ -1,22 +1,14 @@
+[ -n "$MLTK_QUIET" ] && return 0
-if [ "x$MLTK_QUIET" == "x" ]; then #ifndef _MLTK_QUIET
-#define _MLTK_QUIET
-
-MLTK_QUIET=0
-
-exec 6>&2
-
-LOG_DIR=${ROOT_DIR}/logs
-
-mkdir -p "$LOG_DIR"
-
-exec 8>&0 # This redirection is used for chroot debugging
+# This module is an exception, it doesn't use __init but runs commands directly...
+# Otherwise we cannot ensure that other module's init functions won't run first
+# and mess up the fds
set_quiet () {
if [ "x$MLTK_QUIET" != "x1" ]; then
exec 6>&1 > "$LOG_DIR/stdout.log"
exec 7>&2 2> "$LOG_DIR/stderr.log"
- MLTK_QUIET="1"
+ MLTK_QUIET=1
fi
}
@@ -25,7 +17,7 @@ unset_quiet () {
exec 1>&6 6>&-
exec 2>&7 7>&-
exec 6>&2
- MLTK_QUIET="0"
+ MLTK_QUIET=0
fi
}
@@ -34,7 +26,7 @@ pinfo () {
echo -e "\033[38;5;10m[info]\033[0m $TOOL_STR $@" >&6
}
-perror () {
+perror () {
echo -e "\033[38;5;9m[error]\033[0m $TOOL_STR $@" >&6
qnd_exit
}
@@ -51,5 +43,11 @@ pdebug () {
fi
}
-#endif
-fi
+exec 6>&2
+exec 8>&0 # This redirection is used for chroot debugging
+
+MLTK_QUIET=0
+declare -rg LOG_DIR=${ROOT_DIR}/logs
+mkdir -p "$LOG_DIR" || perror "Could not create '$LOG_DIR'"
+true
+
diff --git a/helper/string.inc b/helper/string.inc
index 75baf2ca..077f1719 100644
--- a/helper/string.inc
+++ b/helper/string.inc
@@ -12,12 +12,6 @@ itrim () {
sed -r 's/^\s+//g;s/\s+$//g'
}
-# usage: CANONICALIZED_STRING=$(canonalize <path>)
-# usage with relative path requires you to be in the correct directory.
-canonicalize() {
- cd -P -- "$(dirname -- "$1")" && printf '%s\n' "$(pwd -P)/$(basename -- "$1")"
-}
-
escape_search() {
sed -e 's/[]\/()$*.^|[]/\\&/g'