summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjandob2016-03-10 14:58:56 +0100
committerjandob2016-03-10 14:58:56 +0100
commitd5b40c2644a90a686a181f5cc2eb5634692dbf26 (patch)
tree62a40da92b9b274506c8cb223f9087e6b14de5ae
parentrebash update (diff)
parentFix some tests. (diff)
downloadsystemd-init-d5b40c2644a90a686a181f5cc2eb5634692dbf26.tar.gz
systemd-init-d5b40c2644a90a686a181f5cc2eb5634692dbf26.tar.xz
systemd-init-d5b40c2644a90a686a181f5cc2eb5634692dbf26.zip
Merge branch 'master' of git.openslx.org:openslx-ng/systemd-init
-rwxr-xr-xbuilder/build-initramfs.sh175
-rwxr-xr-xbuilder/dnbd3-rootfs/module-setup.sh74
-rwxr-xr-xbuilder/dnbd3-rootfs/scripts/container-unpack-xmount.sh2
3 files changed, 200 insertions, 51 deletions
diff --git a/builder/build-initramfs.sh b/builder/build-initramfs.sh
index 710676a5..846663a4 100755
--- a/builder/build-initramfs.sh
+++ b/builder/build-initramfs.sh
@@ -16,13 +16,12 @@
# --------
# Start install progress command (Assuming internet is available):
-# >>> ./build_initramfs.sh
+# >>> ./build-initramfs.sh
# Note that you only get very necessary output until you provide "--verbose" as
# commandline options.
## region ensure presence of needed dependencies
-
set -o errexit
_needed_location="$(dirname "${BASH_SOURCE[0]}")/dnbd3-rootfs"
if ! [[ -d "$_needed_location" ]]; then
@@ -48,9 +47,7 @@ if ! [[ -d "$_needed_location" ]]; then
rm --recursive --force "$_temporary_repository_location"
fi
set +o errexit
-
## endregion
-
source "$(dirname "${BASH_SOURCE[0]}")/dnbd3-rootfs/scripts/rebash/core.sh"
core.import exceptions
exceptions.activate
@@ -65,7 +62,6 @@ dracut_parameter='--force --no-hostonly'
verbose='no'
debug='no'
target=''
-create_system_image=''
cleanup='no'
full_cleanup='no'
use_systemd_in_initramfs='no'
@@ -96,21 +92,33 @@ declare -A optional_package_dependencies=(
# region functions
## region command line interface
print_usage_message() {
- # Prints a description about how to use this program.
+ local __doc__='
+ Prints a description about how to use this program.
+
+ >>> print_usage_message &>/dev/null
+ '
logging.cat << EOF
This program provides a generic way to install systemd based remote linux
initramfs.
EOF
}
print_usage_examples() {
- # Prints a description about how to use this program by providing examples.
+ local __doc__='
+ Prints a description about how to use this program by providing examples.
+
+ >>> print_usage_examples &>/dev/null
+ '
logging.cat << EOF
Start install progress:
>>> ./build_initramfs.sh
EOF
}
print_command_line_option_description() {
- # Prints descriptions about each available command line option.
+ local __doc__='
+ Prints descriptions about each available command line option.
+
+ >>> print_command_line_option_description &>/dev/null
+ '
logging.cat << EOF
-h --help Shows this help message.
@@ -126,9 +134,6 @@ print_command_line_option_description() {
-f --full-cleanup Removes all retrieved and compiled files (usefull to retrieve latest version of all nested modules).
--i --create-system-image Creates an image under given path from current system.
- (default: "$create_system_image").
-
-t --target Creates an image against given target template filesystem. If not
explicitly speicifed current system will be used as template system
(default: "$target").
@@ -144,7 +149,11 @@ concatenated.).
EOF
}
print_help_message() {
- # Provides a help message for this module.
+ local __doc__='
+ Provides a help message for this module.
+
+ >>> print_help_message &>/dev/null
+ '
logging.plain "\nUsage: $0 [options]\n"
print_usage_message "$@"
logging.plain '\nExamples:\n'
@@ -154,7 +163,91 @@ print_help_message() {
logging.plain
}
parse_command_line() {
- # Provides the command line interface and interactive questions.
+ local __doc__='
+ Provides the command line interface and interactive questions.
+
+ >>> parse_command_line -h &>/dev/null
+
+ >>> echo "$verbose"
+ no
+ >>> logging.get_level
+ critical
+ >>> parse_command_line -v
+ >>> echo "$verbose"
+ >>> logging.get_level
+ yes
+ info
+
+ >>> echo "$debug"
+ no
+ >>> parse_command_line --debug
+ >>> echo "$debug"
+ >>> logging.get_level
+ yes
+ debug
+
+ >>> parse_command_line -p; echo $?
+ +doc_test_contains
+ Error with given option "-p":
+ +doc_test_ellipsis
+ Traceback (most recent call first):
+ ...
+
+ >>> echo "$file_path"
+ /boot/initramfs.img
+ >>> parse_command_line -p /tmp/test.img
+ >>> echo "$file_path"
+ /tmp/test.img
+
+ >>> echo "$cleanup"
+ no
+ >>> parse_command_line --cleanup
+ >>> echo "$cleanup"
+ yes
+
+ >>> echo "$full_cleanup"
+ no
+ >>> parse_command_line --full-cleanup
+ >>> echo "$full_cleanup"
+ yes
+
+ >>> echo "$full_cleanup"
+ no
+ >>> parse_command_line --full-cleanup
+ >>> echo "$full_cleanup"
+ yes
+
+ >>> echo "$use_systemd_in_initramfs"
+ no
+ >>> parse_command_line -s
+ >>> echo "$use_systemd_in_initramfs"
+ yes
+
+ >>> parse_command_line -t; echo $?
+ +doc_test_contains
+ Error with given option "-t":
+ +doc_test_ellipsis
+ Traceback (most recent call first):
+ ...
+
+ >>> [[ "$target" = "" ]]
+ >>> parse_command_line -t /tmp/
+ >>> echo "$target"
+ /tmp/
+
+ >>> echo "$dracut_parameter"
+ --force --no-hostonly
+ >>> parse_command_line - --test
+ >>> echo "$dracut_parameter"
+ --force --no-hostonly --test
+
+ >>> parse_command_line --no-available-option; echo $?
+ +doc_test_contains
+ Error with given option "--no-available-option":
+ +doc_test_ellipsis
+ Traceback (most recent call first):
+ ...
+ '
while true; do
case "$1" in
-h|--help)
@@ -175,7 +268,7 @@ parse_command_line() {
file_path="$1"
if [[ "$file_path" == '' ]]; then
logging.critical \
- "This options needs a path to save initramfs image to."
+ "Error with given option "$1": This option needs a path to save initramfs image to."
return 1
fi
shift
@@ -192,22 +285,12 @@ parse_command_line() {
shift
use_systemd_in_initramfs='yes'
;;
- -i|--create-system-image)
- shift
- create_system_image="$1"
- if [[ "$create_system_image" == '' ]]; then
- logging.critical \
- "This options needs a path to save image to."
- return 1
- fi
- shift
- ;;
-t|--target)
shift
target="$1"
if [[ "$target" == '' ]]; then
logging.critical \
- "This options needs a path create initramfs from."
+ "Error with given option "$1": This option needs a path create initramfs from."
return 1
fi
shift
@@ -225,7 +308,7 @@ parse_command_line() {
break
;;
*)
- logging.critical "Given argument: \"$1\" is not available."
+ logging.critical "Error with given option "$1": This argument is not available."
return 1
esac
done
@@ -247,8 +330,14 @@ parse_command_line() {
## endregion
## region helper
dependency_check() {
- # Check for given dependencies with given dependency checker and log
- # corresponding messages.
+ local __doc__='
+ Check for given dependencies with given dependency checker and log
+ corresponding messages.
+
+ Example:
+
+ `dependency_check core dependencies utils_dependency_check program`
+ '
local result=0
eval 'for dependency_group in "${!'$1'_'$2'[@]}"; do
@@ -276,12 +365,13 @@ dependency_check() {
return $result
}
initialize_dracut() {
- # Downloads and compiles dracut.
- #
- # Examples:
- #
- # >>> initialize_dracut
- # ...
+ local __doc__='
+ Downloads and compiles dracut.
+
+ Example:
+
+ `initialize_dracut`
+ '
if [[ ! -f "$(dirname "${BASH_SOURCE[0]}")/dracut/install/dracut-install" ]]
then
mkdir --parents "$(dirname "${BASH_SOURCE[0]}")/dracut"
@@ -307,11 +397,13 @@ initialize_dracut() {
return $?
}
cleanup() {
- # Removes distribution specific generated files.
- #
- # Examples:
- #
- # >>> cleanup
+ local __doc__='
+ Removes distribution specific generated files.
+
+ Example:
+
+ `cleanup`
+ '
local plugin_path="$(dirname "${BASH_SOURCE[0]}")/dnbd3-rootfs/"
source "${plugin_path}module-setup.sh"
moddir="$(cd "$plugin_path" &>/dev/null && pwd)"
@@ -443,10 +535,7 @@ fi
if [ "$use_systemd_in_initramfs" == 'yes' ]; then
_modules="$_modules systemd systemd-initrd dracut-systemd"
fi
-if [[ "$create_system_image" != '' ]]; then
- logging.info 'Create system image.'
- create_qcow2_system "$create_system_image"
-elif [[ "$full_cleanup" == 'yes' ]]; then
+if [[ "$full_cleanup" == 'yes' ]]; then
logging.info 'Removing all modules.'
rm "$(dirname "${BASH_SOURCE[0]}")/dnbd3-rootfs" \
"$(dirname "${BASH_SOURCE[0]}")/dracut" --recursive --force
diff --git a/builder/dnbd3-rootfs/module-setup.sh b/builder/dnbd3-rootfs/module-setup.sh
index 550111ba..9f412a47 100755
--- a/builder/dnbd3-rootfs/module-setup.sh
+++ b/builder/dnbd3-rootfs/module-setup.sh
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
-# region header
+# region imports
source "$(dirname "${BASH_SOURCE[0]}")/scripts/rebash/core.sh"
core.import exceptions
core.import logging
@@ -8,8 +8,34 @@ core.import utils
core.import "$(core_abs_path "$(dirname "${BASH_SOURCE[0]}")/scripts/build.sh")"
# endregion
# region forward "build-initrfams.sh" logging configuration if present.
-# set log level via dracut logging options
_parse_dracut_args() {
+ local __doc__='
+ Set log level via dracut logging options and returns current debug state.
+
+ >>> echo "$debug"
+ false
+ >>> _parse_dracut_args; echo $?
+ 1
+
+ >>> _parse_dracut_args --stdlog 3; echo $?
+ 1
+
+ >>> _parse_dracut_args --stdlog 4; echo $?
+ >>> logging.get_commands_level
+ >>> logging.get_level
+ 0
+ debug
+ debug
+
+ >>> logging.get_level
+ critical
+ >>> _parse_dracut_args --verbose
+ >>> logging.get_level
+ info
+
+ >>> _parse_dracut_args --stdlog 4 --unknown-dracut-option; echo $?
+ 0
+ '
local verbose=false
local debug=false
while true; do
@@ -44,8 +70,14 @@ _debug=0
_parse_dracut_args ${dracut_args[*]} || _debug=$?
# endregion
clean() {
- # NOTE: This method is currently triggered manually and not supported by
- # dracut itself.
+ local __doc__='
+ Removes all compiled kernel specific files.
+ NOTE: This method is triggered manually and not supported by dracut itself.
+
+ Example:
+
+ `clean`
+ '
build_clean_xmount "$moddir/binaries/xmount/"
build_clean_qemu_xmount "$moddir/binaries/qemu-xmount/"
build_clean_dnbd3 "$moddir/binaries/dnbd3/"
@@ -53,9 +85,15 @@ clean() {
"$moddir/binaries/systemd-preserve-process-marker/"
return 0
}
-# region dracut plugin api
+# region dracut plugin api
check() {
- # Checks weather all template system assumptions are satisfied
+ local __doc__='
+ Checks weather all template system assumptions are satisfied.
+
+ Example:
+
+ `check`
+ '
exceptions.activate
# NOTE: xmount must be compiled before qemu_xmount
local xmount_is_built=true
@@ -106,15 +144,37 @@ check() {
return 255
}
depends() {
- # NOTE: btrfs module should be used if it would work.
+ local __doc__='
+ Outputs all dependent dracut modules to make this module work.
+
+ >>> depends
+ +doc_test_contains
+ base
+ '
echo base network bash kernel-modules shutdown
}
installkernel() {
+ local __doc__='
+ Copies all needed kernel modules into initramfs file needed work at
+ runtime.
+
+ Example:
+
+ `installkernel`
+ '
inst "$moddir/binaries/dnbd3/build/dnbd3.ko" \
/usr/lib/modules/current/extra/dnbd3.ko
instmods dm_snapshot btrfs crc32c
}
install() {
+ local __doc__='
+ Copies all needed files into the initramfs image and registers all needed
+ dracut hooks.
+
+ Example:
+
+ `install`
+ '
# region binaries
inst "$moddir/binaries/dnbd3/build/dnbd3-client" /usr/bin/dnbd3-client
inst \
diff --git a/builder/dnbd3-rootfs/scripts/container-unpack-xmount.sh b/builder/dnbd3-rootfs/scripts/container-unpack-xmount.sh
index b5a3e999..9da0baac 100755
--- a/builder/dnbd3-rootfs/scripts/container-unpack-xmount.sh
+++ b/builder/dnbd3-rootfs/scripts/container-unpack-xmount.sh
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
-source "/usr/lib/rebash/core.sh"
+source '/usr/lib/rebash/core.sh'
core.import exceptions
exceptions.activate