blob: 212bda758ec980beb4ad5a54e39be5366c5d3b44 (
plain) (
tree)
|
|
#!/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
{
[[ "$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
# check if system's uuid was set
if [ -s "/run/system-uuid" ]; then
uuid=$(cat "/run/system-uuid")
if [ -n "$uuid" ]; then
uuid_url="?uuid=$uuid"
fi
fi
logging.info "Download SLX configuration from: \"$slx_server\"."
(
IFS=','
for TIMEOUT in 1 1 2 3; do
if wget -q -t 2 -T $TIMEOUT \
"http://${slx_server#@}/${slx_server_base}/${configuration_file_name}${uuid_url}" \
--output-document '/etc/openslx.tmp'; then
break
fi
done
)
if [[ ! -s "/etc/openslx.tmp" ]]; 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"
return 1
fi
# remember kcl server and base
(
echo "SLX_KCL_SERVERS='$slx_server'"
echo "SLX_BASE_PATH='$slx_server_base'"
echo '#_RCONFIG_TAG'
) > /etc/openslx
# finally copy remote config into it
cat /etc/openslx.tmp >> /etc/openslx
# slxsrv overrides SLX_DNBD3_SERVERS if prefixed with @
[ "${slx_server#@}" != "${slx_server}" ] && sed -i "s/^SLX_DNBD3_SERVERS=.*/SLX_DNBD3_SERVERS='${slx_server#@}'/" "/etc/openslx"
}
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
|