summaryrefslogtreecommitdiffstats
path: root/builder/dnbd3-rootfs/scripts/utils.sh
diff options
context:
space:
mode:
Diffstat (limited to 'builder/dnbd3-rootfs/scripts/utils.sh')
-rw-r--r--builder/dnbd3-rootfs/scripts/utils.sh99
1 files changed, 99 insertions, 0 deletions
diff --git a/builder/dnbd3-rootfs/scripts/utils.sh b/builder/dnbd3-rootfs/scripts/utils.sh
new file mode 100644
index 00000000..3c72dbca
--- /dev/null
+++ b/builder/dnbd3-rootfs/scripts/utils.sh
@@ -0,0 +1,99 @@
+UTILS_KERNEL_MODULE_DIRECTORY="builder/dnbd3-qcow2-rootfs/kernel_modules/"
+UTILS_STANDARD_OUTPUT=/dev/null
+UTILS_ERROR_OUTPUT=/dev/null
+
+function utils_log() {
+ # Handles logging messages. Returns non zero and exit on log level
+ # error to support chaining the message into toolchain.
+ #
+ # Examples:
+ #
+ # >>> build_initramfs_log
+ # info: test
+ # >>> build_initramfs_log debug message
+ # debug: message
+ # >>> build_initramfs_log info message '\n'
+ #
+ # info: message
+ local loggingType='info' && \
+ local message="$1" && \
+ if [ "$2" ]; then
+ loggingType="$1"
+ message="$2"
+ fi
+ if [ "$_VERBOSE" == 'yes' ] || [ "$loggingType" == 'error' ] || \
+ [ "$loggingType" == 'critical' ]; then
+ if [ "$3" ]; then
+ echo -e -n "$3"
+ fi
+ echo -e "${loggingType}: $message"
+ fi
+ if [ "$loggingType" == 'error' ]; then
+ exit 1
+ fi
+ return 0
+}
+function compile_nbd() {
+ # Downloads and compiles nbd.
+ #
+ # Examples:
+ #
+ # >>> build_initramfs_compile_nbd
+ # ...
+ # Provides the following file:
+ # ${_KERNEL_MODULE_DIRECTORY}/nbd/nbd.ko
+ pushd "${_KERNEL_MODULE_DIRECTORY}/nbd" \
+ 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT" && \
+ build_initramfs_log 'Compile the nbd kernel module.' && \
+ make 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT" && \
+ popd 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT"
+ return $?
+ # TODO make clean
+}
+function compile_dnbd3() {
+ # Downloads and compiles dnbd3.
+ #
+ # Examples:
+ #
+ # >>> build_initramfs_compile_dnbd3
+ # ...
+ # Provides the following file:
+ # ${_KERNEL_MODULE_DIRECTORY}/dnbd3/build/dnbd3.ko
+ rm --recursive --force ${_KERNEL_MODULE_DIRECTORY}/dnbd3 \
+ 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT" && \
+ pushd $_KERNEL_MODULE_DIRECTORY \
+ 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT" && \
+ git clone git://git.openslx.org/dnbd3.git \
+ 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT" && \
+ cd dnbd3 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT" && \
+ ./build.sh 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT" && \
+ popd 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT"
+ return $?
+ # TODO rm -rf build
+}
+function compile_systemd_preserve_process_marker() {
+ # Compiles simple c program.
+ pushd && \
+ make && \
+ popd
+ return $?
+}
+function utils_dependency_check() {
+ # This function check if all given dependencies are present.
+ #
+ # Examples:
+ #
+ # >>> build_initramfs_perform_dependency_check "mkdir pacstrap mktemp"
+ # ...
+ local dependenciesToCheck="$1" && \
+ local result=0 && \
+ local dependency && \
+ for dependency in ${dependenciesToCheck[*]}; do
+ if ! hash "$dependency" 1>"$_STANDARD_OUTPUT" 2>/dev/null; then
+ build_initramfs_log 'critical' \
+ "Needed dependency \"$dependency\" isn't available." && \
+ result=1
+ fi
+ done
+ return $result
+}