diff options
author | torben | 2016-12-01 10:30:54 +0100 |
---|---|---|
committer | torben | 2016-12-01 10:30:54 +0100 |
commit | 09d5a988fdd0fc897c167e9d773dcc1293743955 (patch) | |
tree | a3c92fe7d77686e53850de55ed61deea34fc12ed /builder | |
parent | a (diff) | |
parent | duh 2.0 (diff) | |
download | systemd-init-09d5a988fdd0fc897c167e9d773dcc1293743955.tar.gz systemd-init-09d5a988fdd0fc897c167e9d773dcc1293743955.tar.xz systemd-init-09d5a988fdd0fc897c167e9d773dcc1293743955.zip |
Merge branch 'master' of git.openslx.org:openslx-ng/systemd-init
Diffstat (limited to 'builder')
-rwxr-xr-x | builder/bootnet-conf/module-setup.sh | 13 | ||||
-rwxr-xr-x | builder/bootnet-conf/scripts/gen-bootnet-conf.sh | 18 | ||||
-rwxr-xr-x | builder/build-initramfs.sh | 61 | ||||
-rwxr-xr-x | builder/conf-tgz/hooks/fetch-config-tgz.sh | 42 | ||||
-rwxr-xr-x | builder/conf-tgz/hooks/unpack-config-tgz.sh | 72 | ||||
-rwxr-xr-x | builder/conf-tgz/module-setup.sh | 46 | ||||
-rwxr-xr-x | builder/dnbd3-rootfs/hooks/fetch-config.sh | 4 | ||||
-rwxr-xr-x | builder/dns/module-setup.sh | 13 | ||||
-rwxr-xr-x | builder/dns/scripts/gen-resolv-conf.sh | 11 | ||||
-rwxr-xr-x | builder/ib-conf/module-setup.sh | 13 | ||||
-rwxr-xr-x | builder/ib-conf/scripts/gen-ib-conf.sh | 24 |
11 files changed, 290 insertions, 27 deletions
diff --git a/builder/bootnet-conf/module-setup.sh b/builder/bootnet-conf/module-setup.sh new file mode 100755 index 00000000..f1d6697f --- /dev/null +++ b/builder/bootnet-conf/module-setup.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +check() { + # Tell dracut that this module should only be included if it is required + # explicitly. + return 255 +} +depends() { + echo dnbd3-rootfs +} +install() { + inst_hook pre-pivot 50 "$moddir/scripts/gen-bootnet-conf.sh" +} diff --git a/builder/bootnet-conf/scripts/gen-bootnet-conf.sh b/builder/bootnet-conf/scripts/gen-bootnet-conf.sh new file mode 100755 index 00000000..ec82f143 --- /dev/null +++ b/builder/bootnet-conf/scripts/gen-bootnet-conf.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +type emergency_shell >/dev/null 2>&1 || source /lib/dracut-lib.sh + +mac="$(getargs BOOTIF=)" +mac="$(echo $mac | cut -c 4- | tr '-' ':')" +if [ -n "${mac}" ]; then + cat << EOF >> "${NEWROOT}/etc/sysconfig/network-scripts/ifcfg-bootnet" +DEVICE=bootnet +NAME=bootnet +HWADDR=${mac} +BOOTPROTO=dhcp +ONBOOT=yes +NM_CONTROLLED=yes +EOF +else + echo "Could not parse MAC" +fi diff --git a/builder/build-initramfs.sh b/builder/build-initramfs.sh index b705fece..dcab3b1d 100755 --- a/builder/build-initramfs.sh +++ b/builder/build-initramfs.sh @@ -43,9 +43,11 @@ if ! [[ -d "$_needed_location" ]]; then ' git submodule update --remote popd - cp --recursive \ - "${_temporary_repository_location}/builder/dnbd3-rootfs" \ - "$_needed_location" + for mod in dnbd3-rootfs conf-tgz dns ib-conf bootnet-conf; do + cp --recursive \ + "${_temporary_repository_location}/builder/${mod}" \ + "$(dirname $_needed_location)/${mod}" + done rm --recursive --force "$_temporary_repository_location" fi set +o errexit @@ -203,9 +205,10 @@ parse_command_line() { debug >>> parse_command_line -p + +doc_test_capture_stderr +doc_test_contains - Error with given option "-p": +doc_test_ellipsis + Error with given option "-p": Traceback (most recent call first): ... @@ -240,9 +243,10 @@ parse_command_line() { yes >>> parse_command_line -t; echo $? + +doc_test_capture_stderr +doc_test_contains - Error with given option "-t": +doc_test_ellipsis + Error with given option "-t": Traceback (most recent call first): ... @@ -262,9 +266,10 @@ parse_command_line() { vim htop >>> parse_command_line --no-available-option; echo $? + +doc_test_capture_stderr +doc_test_contains - Error with given option "--no-available-option": +doc_test_ellipsis + Error with given option "--no-available-option": Traceback (most recent call first): ... ' @@ -547,30 +552,33 @@ main() { logging.info "Dracut isn't available yet loading it." initialize_dracut fi - - _dracut_modules_source='../../dnbd3-rootfs' - _dracut_modules_target="$(dirname "${BASH_SOURCE[0]}")/dracut/modules.d/90dnbd3-rootfs" - if [[ ! -L "$_dracut_modules_target" || "$(readlink \ - "$_dracut_modules_target")" != "$_dracut_modules_source" ]] - then - logging.info \ - "Link dnbd3 plugin into dracut modules folder ($_dracut_modules_source -> $_dracut_modules_target)." - if ! ln --symbolic --force "$_dracut_modules_source" \ - "$_dracut_modules_target" 2>/dev/null; then - logging.warn \ - "Linking \"$_dracut_modules_source\" to \"$_dracut_modules_target\" failed. We will copy them. So we have to recopy it every time to ensure that recompiled things take effect." - cp --recursive --force --no-target-directory \ - "$(dirname "${BASH_SOURCE[0]}")/$(basename "$_dracut_modules_source")" \ - "$_dracut_modules_target" + + declare -A _dracut_modules=( [dnbd3]='../../dnbd3-rootfs' [conf]='../../conf-tgz' [dns]='../../dns' [ib]='../../ib-conf' [bootnet]='../../bootnet-conf') + for mod in dnbd3 conf dns ib bootnet; do + _dracut_modules_source="${_dracut_modules[$mod]}" + _dracut_modules_target="$(dirname "${BASH_SOURCE[0]}")/dracut/modules.d/90$(basename "${_dracut_modules[$mod]}")" + if [[ ! -L "$_dracut_modules_target" || "$(readlink \ + "$_dracut_modules_target")" != "$_dracut_modules_source" ]] + then + logging.info \ + "Link ${mod} plugin into dracut modules folder ($_dracut_modules_source -> $_dracut_modules_target)." + if ! ln --symbolic --force "$_dracut_modules_source" \ + "$_dracut_modules_target" 2>/dev/null; then + logging.warn \ + "Linking \"$_dracut_modules_source\" to \"$_dracut_modules_target\" failed. We will copy them. So we have to recopy it every time to ensure that recompiled things take effect." + cp --recursive --force --no-target-directory \ + "$(dirname "${BASH_SOURCE[0]}")/$(basename "$_dracut_modules_source")" \ + "$_dracut_modules_target" + fi fi - fi + done # endregion # region prepare and perform final dracut call _loglevel='' if [ "$verbose" == 'yes' ]; then _loglevel='--verbose' fi - _modules='dnbd3-rootfs' + _modules='dnbd3-rootfs conf-tgz dns ib-conf bootnet-conf' if [ "$debug" == 'yes' ]; then _loglevel="$_loglevel --stdlog 4" _modules="$_modules i18n terminfo" @@ -598,7 +606,8 @@ main() { logging.set_commands_level debug # shellcheck disable=SC2086 "$(dirname "${BASH_SOURCE[0]}")/dracut/dracut.sh" --local \ - $_loglevel --modules "$_modules" "${dracut_parameter[@]}" \ + $_loglevel --modules "$_modules" --conf /etc/dracut.conf \ + --confdir /etc/dracut.conf.d "${dracut_parameter[@]}" \ "$file_path" _return_code=$? logging.set_commands_level "$_commands_log_level_backup" @@ -613,7 +622,9 @@ main() { exceptions.deactivate } # endregion -core.is_main && main "$@" +if core.is_main; then + main "$@" +fi # region vim modline # vim: set tabstop=4 shiftwidth=4 expandtab: # vim: foldmethod=marker foldmarker=region,endregion: diff --git a/builder/conf-tgz/hooks/fetch-config-tgz.sh b/builder/conf-tgz/hooks/fetch-config-tgz.sh new file mode 100755 index 00000000..8c3bed23 --- /dev/null +++ b/builder/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/conf-tgz/hooks/unpack-config-tgz.sh b/builder/conf-tgz/hooks/unpack-config-tgz.sh new file mode 100755 index 00000000..083fbc6e --- /dev/null +++ b/builder/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/conf-tgz/module-setup.sh b/builder/conf-tgz/module-setup.sh new file mode 100755 index 00000000..946344bf --- /dev/null +++ b/builder/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 +} diff --git a/builder/dnbd3-rootfs/hooks/fetch-config.sh b/builder/dnbd3-rootfs/hooks/fetch-config.sh index 7921a99f..23c5f004 100755 --- a/builder/dnbd3-rootfs/hooks/fetch-config.sh +++ b/builder/dnbd3-rootfs/hooks/fetch-config.sh @@ -29,7 +29,7 @@ IFS=',' for host in ${slx_server}; do logging.info "Trying host \"$host\"." if wget --timeout 5 \ - "http://${host}/${slx_server_base}${configuration_file_name}" \ + "http://${host}/${slx_server_base}/${configuration_file_name}" \ --output-document '/etc/openslx' then break @@ -38,7 +38,7 @@ 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" + 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 } diff --git a/builder/dns/module-setup.sh b/builder/dns/module-setup.sh new file mode 100755 index 00000000..3bad6548 --- /dev/null +++ b/builder/dns/module-setup.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +check() { + # Tell dracut that this module should only be included if it is required + # explicitly. + return 255 +} +depends() { + echo base +} +install() { + inst_hook pre-mount 50 "$moddir/scripts/gen-resolv-conf.sh" +} diff --git a/builder/dns/scripts/gen-resolv-conf.sh b/builder/dns/scripts/gen-resolv-conf.sh new file mode 100755 index 00000000..1601bb12 --- /dev/null +++ b/builder/dns/scripts/gen-resolv-conf.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +type emergency_shell >/dev/null 2>&1 || source /lib/dracut-lib.sh + +CONFFILE="/etc/resolv.conf" + +DNS=$(getargs dns=) +HOSTNAME=$(getargs hostname=) + +[ -n "$DNS" ] && echo "nameserver $DNS" >> "$CONFFILE" +[ -n "$HOSTNAME" ] && echo "$HOSTNAME" >> /etc/hostname diff --git a/builder/ib-conf/module-setup.sh b/builder/ib-conf/module-setup.sh new file mode 100755 index 00000000..0a80d89e --- /dev/null +++ b/builder/ib-conf/module-setup.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +check() { + # Tell dracut that this module should only be included if it is required + # explicitly. + return 255 +} +depends() { + echo dnbd3-rootfs +} +install() { + inst_hook pre-pivot 50 "$moddir/scripts/gen-ib-conf.sh" +} diff --git a/builder/ib-conf/scripts/gen-ib-conf.sh b/builder/ib-conf/scripts/gen-ib-conf.sh new file mode 100755 index 00000000..2d4b7a27 --- /dev/null +++ b/builder/ib-conf/scripts/gen-ib-conf.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +type emergency_shell >/dev/null 2>&1 || source /lib/dracut-lib.sh + +IPSUFFIX=$( + ip -4 -o addr show dev bootnet | \ + awk '{split($4,a,"/");split(a[1],b,".");print b[3]"."b[4]}' +) + +cat << EOF >> "${NEWROOT}/etc/sysconfig/network-scripts/ifcfg-ib0" +DEVICE=ib0 +NAME=ib0 +TYPE=Infiniband +BOOTPROTO=static +IPADDR=10.12.${IPSUFFIX} +BROADCAST=10.12.255.255 +NETWORK=10.12.0.0 +NETMASK=255.255.0.0 +ONBOOT=yes +NM_CONTROLLED=yes +CONNECTED_MODE=yes +MTU=65520 +EOF + |