summaryrefslogtreecommitdiffstats
path: root/builder/modules.d/dnbd3-rootfs/hooks/fetch-config.sh
diff options
context:
space:
mode:
Diffstat (limited to 'builder/modules.d/dnbd3-rootfs/hooks/fetch-config.sh')
-rwxr-xr-xbuilder/modules.d/dnbd3-rootfs/hooks/fetch-config.sh53
1 files changed, 53 insertions, 0 deletions
diff --git a/builder/modules.d/dnbd3-rootfs/hooks/fetch-config.sh b/builder/modules.d/dnbd3-rootfs/hooks/fetch-config.sh
new file mode 100755
index 00000000..23c5f004
--- /dev/null
+++ b/builder/modules.d/dnbd3-rootfs/hooks/fetch-config.sh
@@ -0,0 +1,53 @@
+#!/usr/bin/env bash
+# -*- coding: utf-8 -*-
+# region imports
+source '/usr/lib/rebash/core.sh'
+core.import exceptions
+core.import logging
+type emergency_shell >/dev/null 2>&1 || source /lib/dracut-lib.sh
+# endregion
+exceptions.try
+{
+logging.set_commands_level debug
+logging.set_level debug
+[[ "$SLX_LOG_FILE_PATH" == "" ]] && SLX_LOG_FILE_PATH=/var/log/openslx
+logging.set_log_file "$SLX_LOG_FILE_PATH"
+
+# NOTE: "getarg" raises an exception so deactivate exceptions for now.
+exceptions.deactivate
+configuration_file_name="$(getarg slx_configuration_filename=)"
+if [ -z "$configuration_file_name" ]; then
+ configuration_file_name='config'
+fi
+slx_server="$(getarg slxsrv=)"
+slx_server_base="$(getarg slxbase=)"
+exceptions.activate
+
+logging.info 'Getting configuration file.'
+IFS_backup="$IFS"
+IFS=','
+for host in ${slx_server}; do
+ logging.info "Trying host \"$host\"."
+ if wget --timeout 5 \
+ "http://${host}/${slx_server_base}/${configuration_file_name}" \
+ --output-document '/etc/openslx'
+ then
+ break
+ fi
+done
+IFS="$IFS_backup"
+
+if [[ ! -e "/etc/openslx" ]]; then
+ logging.warn "Downloading OpenSLX configuration file from any of the servers \"${slx_server}\" at location \"${slx_server_base}/${configuration_file_name}\" failed. Return code: $return_code"
+ exit 1
+fi
+}
+exceptions.catch
+{
+ logging.error "$exceptions_last_traceback"
+ emergency_shell "error in ${BASH_SOURCE[0]}"
+}
+# region vim modline
+# vim: set tabstop=4 shiftwidth=4 expandtab:
+# vim: foldmethod=marker foldmarker=region,endregion:
+# endregion