summaryrefslogtreecommitdiffstats
path: root/builder/modules.d/conf-tgz
diff options
context:
space:
mode:
Diffstat (limited to 'builder/modules.d/conf-tgz')
-rwxr-xr-xbuilder/modules.d/conf-tgz/hooks/fetch-config-tgz.sh42
-rwxr-xr-xbuilder/modules.d/conf-tgz/hooks/unpack-config-tgz.sh72
-rwxr-xr-xbuilder/modules.d/conf-tgz/module-setup.sh46
3 files changed, 160 insertions, 0 deletions
diff --git a/builder/modules.d/conf-tgz/hooks/fetch-config-tgz.sh b/builder/modules.d/conf-tgz/hooks/fetch-config-tgz.sh
new file mode 100755
index 00000000..8c3bed23
--- /dev/null
+++ b/builder/modules.d/conf-tgz/hooks/fetch-config-tgz.sh
@@ -0,0 +1,42 @@
+#!/usr/bin/env bash
+# -*- coding: utf-8 -*-
+
+source '/usr/lib/rebash/core.sh'
+core.import exceptions
+core.import logging
+type emergency_shell >/dev/null 2>&1 || source /lib/dracut-lib.sh
+
+exceptions.try
+{
+ logging.set_commands_level debug
+ logging.set_level debug
+ # NOTE: "getarg" raises an exception so deactivate exceptions for now.
+ exceptions.deactivate
+ slx_server="$(getarg slxsrv=)"
+ slx_server_base="$(getarg slxbase=)"
+ exceptions.activate
+
+ logging.info "Download config.tgz from '${slx_server}'..."
+ IFS_backup="$IFS"
+ IFS=','
+ for host in ${slx_server}; do
+ logging.info "Trying host \"$host\"."
+ if wget --timeout 5 \
+ "http://${host}/${slx_server_base}/config.tgz" \
+ --output-document "/etc/config.tgz"
+ then
+ break
+ fi
+ done
+ IFS="$IFS_backup"
+
+ if [[ ! -e "/etc/config.tgz" ]]; then
+ logging.warn "Downloading 'config.tgz' from '${slx_server}' failed. Return code: $return_code"
+ exit 1
+ fi
+}
+exceptions.catch
+{
+ logging.error "$exceptions_last_traceback"
+ emergency_shell "error in ${BASH_SOURCE[0]}"
+}
diff --git a/builder/modules.d/conf-tgz/hooks/unpack-config-tgz.sh b/builder/modules.d/conf-tgz/hooks/unpack-config-tgz.sh
new file mode 100755
index 00000000..083fbc6e
--- /dev/null
+++ b/builder/modules.d/conf-tgz/hooks/unpack-config-tgz.sh
@@ -0,0 +1,72 @@
+#!/usr/bin/env bash
+# -*- coding: utf-8 -*-
+
+source '/usr/lib/rebash/core.sh'
+core.import exceptions
+core.import logging
+type emergency_shell >/dev/null 2>&1 || source /lib/dracut-lib.sh
+
+# this module unpacks the config.tgz
+temporary_extract_directory="$(mktemp -d)"
+exceptions.try
+{
+ logging.set_commands_level debug
+ logging.set_level debug
+ exceptions.activate
+ if [[ -e "/etc/config.tgz" ]]; then
+ tar --extract --preserve-permissions \
+ --file="/etc/config.tgz" \
+ --directory="$temporary_extract_directory"
+ fi
+}
+exceptions.catch
+{
+ logging.error "Failed to extract '/etc/config.tgz' to '$temporary_extract_directory'."
+ logging.error "$exceptions_last_traceback"
+ emergency_shell "error in ${BASH_SOURCE[0]}"
+}
+# extracted to temporary directory, now check for SLX_LOCAL_CONFIGURATION
+source "/etc/openslx"
+exceptions.try
+{
+ logging.set_commands_level debug
+ logging.set_level debug
+ exceptions.activate
+ if [[ -z "$SLX_LOCAL_CONFIGURATION" ]]; then
+ logging.warn "SLX_LOCAL_CONFIGURATION is not set in '/etc/openslx'."
+ exit 0
+ fi
+ if [[ ! -d "${temporary_extract_directory}/openslx-configs/${SLX_LOCAL_CONFIGURATION}" ]]; then
+ logging.warn "SLX_LOCAL_CONFIGURATION is set but no corresponding folder found in '/etc/config.tgz'."
+ exit 0
+ fi
+ # still here? then process to merge the localized configuration files with the common files.
+ cd "${temporary_extract_directory}/openslx-configs/${SLX_LOCAL_CONFIGURATION}"
+ tar --create --preserve-permissions * | tar --extract --preserve-permissions --directory "${temporary_extract_directory}"
+}
+exceptions.catch
+{
+ # errors here are not critical, so no emergency shell
+ logging.error "Failed to merge local configuration files for '$SLX_LOCAL_CONFIGURATION'."
+ logging.error "$exceptions_last_traceback"
+ emergency_shell "error in ${BASH_SOURCE[0]}"
+}
+
+# now just copy everything from the temporary_extract_directory to the future root
+exceptions.try
+{
+ logging.set_commands_level debug
+ logging.set_level debug
+ exceptions.activate
+ cd "${temporary_extract_directory}"
+ # purge openslx-configs/
+ rm -rf "openslx-configs"
+ tar --create --preserve-permissions * | tar --extract --preserve-permissions --directory "${NEWROOT}"
+}
+exceptions.catch
+{
+ # errors here are not critical, so no emergency shell
+ logging.error "Failed to copy extracted configuration files to '$NEWROOT'."
+ logging.error "$exceptions_last_traceback"
+ emergency_shell "error in ${BASH_SOURCE[0]}"
+}
diff --git a/builder/modules.d/conf-tgz/module-setup.sh b/builder/modules.d/conf-tgz/module-setup.sh
new file mode 100755
index 00000000..946344bf
--- /dev/null
+++ b/builder/modules.d/conf-tgz/module-setup.sh
@@ -0,0 +1,46 @@
+#!/usr/bin/env bash
+# -*- coding: utf-8 -*-
+
+source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd '../' && \
+ cd *'dnbd3-rootfs/scripts/rebash' && pwd)/core.sh"
+core.import exceptions
+core.import logging
+
+check() {
+ local __doc__='
+ Checks whether needed assumptions are satisfied.
+
+ Example:
+
+ `check`
+ '
+
+ # Here we could build our package file.
+
+ # Tell dracut that this module should only be included if it is required
+ # explicitly.
+ return 255
+}
+depends() {
+ local __doc__='
+ Outputs all dependent dracut modules to make this module work.
+
+ >>> depends
+ +doc_test_contains
+ base
+ '
+ echo base
+}
+install() {
+ local __doc__='
+ Copies all needed files into the initramfs image and registers all needed
+ dracut hooks.
+
+ Example:
+
+ `install`
+ '
+ inst_hook pre-mount 10 "$moddir/hooks/fetch-config-tgz.sh"
+ inst_hook pre-pivot 10 "$moddir/hooks/unpack-config-tgz.sh"
+ inst_multiple tar wget mktemp
+}