summaryrefslogtreecommitdiffstats
path: root/build-initramfs.sh
diff options
context:
space:
mode:
authorJonathan Bauer2020-05-13 14:24:25 +0200
committerJonathan Bauer2020-05-13 14:24:25 +0200
commit3c2b4e96f2c58f9673630a64d2d859c070786bd3 (patch)
tree7e47377efebde3c195662f3e58b6e002830e5ce1 /build-initramfs.sh
parentbuild-initramfs.sh: formatting (diff)
downloadsystemd-init-3c2b4e96f2c58f9673630a64d2d859c070786bd3.tar.gz
systemd-init-3c2b4e96f2c58f9673630a64d2d859c070786bd3.tar.xz
systemd-init-3c2b4e96f2c58f9673630a64d2d859c070786bd3.zip
build-initramfs.sh: formatting + minor changes
Diffstat (limited to 'build-initramfs.sh')
-rwxr-xr-xbuild-initramfs.sh111
1 files changed, 63 insertions, 48 deletions
diff --git a/build-initramfs.sh b/build-initramfs.sh
index 5fef535a..f910e579 100755
--- a/build-initramfs.sh
+++ b/build-initramfs.sh
@@ -172,7 +172,8 @@ parse_command_line() {
file_path="$1"
if [[ "$file_path" == '' ]]; then
echo \
- "Error with given option \"$given_argument\": This option needs a path to save initramfs image to."
+ "Error with given option \"$given_argument\":" \
+ "This option needs a path to save initramfs image to."
return 1
fi
shift
@@ -195,7 +196,8 @@ parse_command_line() {
target="$1"
if [[ "$target" == '' ]]; then
echo \
- "Error with given option \"$given_argument\": This option needs a path create initramfs from."
+ "Error with given option \"$given_argument\":" \
+ "This option needs a path create initramfs from."
return 1
fi
shift
@@ -210,7 +212,8 @@ parse_command_line() {
kernel_version="$1"
if [ -z "$kernel_version" ]; then
echo \
- "Error with given option \"$given_argument\": This option needs a kernel version to build the initramfs for."
+ "Error with given option \"$given_argument\":" \
+ "This option needs a kernel version to build the initramfs for."
return 1
fi
shift
@@ -221,7 +224,8 @@ parse_command_line() {
kernel_headers="$1"
if [ -z "$kernel_headers" ]; then
echo \
- "Error with given option \"$given_argument\": This option needs the path to the kernel headers."
+ "Error with given option \"$given_argument\":" \
+ "This option needs the path to the kernel headers."
return 1
fi
shift
@@ -232,7 +236,8 @@ parse_command_line() {
qcow_handler="$1"
if [ -z "$qcow_handler" ]; then
echo \
- "Error with given option \"$given_argument\": This options needs to be either 'xmount' or 'kernel'."
+ "Error with given option \"$given_argument\":" \
+ "This options needs to be either 'xmount' or 'kernel'."
return 1
fi
shift
@@ -262,7 +267,7 @@ parse_command_line() {
}
## endregion
## region helper
-compile_dracut() {
+initialize_dracut() {
pushd "${_dracut_dir}"
# NOTE: On virtualbox shared folder symlinks are not allowed.
# NOTE: make the dracut-install binary (dracut-install resolves
@@ -298,9 +303,23 @@ main() {
print_help_message "$0"
exit 1
fi
- # prepare submodules for the dnbd3-rootfs module
+
+ # prepare remote modules and set core variables.
bootstrap
- # if no kernel was specified as dracut argument, use the running kernel's version
+
+ if [ "$full_cleanup" = "yes" ]; then
+ echo 'Removing all modules.'
+ rm "${_repo_dir}" "${_dracut_dir}" --recursive --force
+ exit $?
+ fi
+
+ if [ "$cleanup" = "yes" ]; then
+ echo 'Removing distribution specific files.'
+ cleanup
+ exit $?
+ fi
+
+ # Default to the running kernel's version if none were specified
echo "Building for:"
if [ -z "$kernel_version" ]; then
kernel_version="$(uname -r)"
@@ -311,13 +330,14 @@ main() {
kernel_headers="/lib/modules/${kernel_version}/build"
fi
if [ ! -f "${kernel_headers}/Makefile" ]; then
- echo 'Missing core dependency "linux-headers" for version to compile against given or current kernel.'
+ echo 'Missing kernel headers for given kernel!'
+ exit 1
fi
echo " * kernel headers: $kernel_headers"
[ -n "$qcow_handler" ] && echo " * qcow2 handler: $qcow_handler"
export _QCOW_HANDLER="$qcow_handler"
- if [ "$update" == "yes" ]; then
+ if [ "$update" = "yes" ]; then
pushd "${_repo_dir}"
git pull
popd
@@ -326,7 +346,7 @@ main() {
echo 'Checking dracut...'
if [ ! -f "${_dracut_dir}/dracut-install" ]; then
echo "Dracut isn't available yet loading it."
- compile_dracut
+ initialize_dracut
fi
for _dracut_module_dir in "${_repo_dir}/modules.d/"*; do
@@ -337,11 +357,13 @@ main() {
if [[ ! -L "$_dracut_module_target" || "$(readlink \
"$_dracut_module_target")" != "$_dracut_module_dir" ]]; then
echo \
- "Link ${_dracut_module} plugin into dracut modules folder ($_dracut_module_dir -> $_dracut_module_target)."
- if ! ln --symbolic --force "$_dracut_module_dir" "$_dracut_module_target"; then
+ "Link ${_dracut_module} plugin into dracut modules folder" \
+ "($_dracut_module_dir -> $_dracut_module_target)."
+ if ! ln --symbolic --force \
+ "$_dracut_module_dir" "$_dracut_module_target"; then
echo \
"Linking \"$_dracut_module_dir\" to \"$_dracut_module_target\" failed." \
- " We will copy them. So we have to recopy it every time to ensure that recompiled things take effect."
+ "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 \
"$_dracut_module_dir" \
"$_dracut_module_target"
@@ -349,47 +371,40 @@ main() {
fi
done
- _loglevel=''
- if [ "$verbose" == 'yes' ]; then
- _loglevel='--verbose'
- fi
+ # default dracut modules
_modules=(dnbd3-rootfs conf-tgz)
echo "Default modules: ${_modules[@]}"
- if [ "$debug" == 'yes' ]; then
- _loglevel="$_loglevel --stdlog 4"
+ if [ "$verbose" = "yes" ]; then
+ dracut_parameters+=("--verbose")
+ fi
+ if [ "$debug" = "yes" ]; then
+ dracut_parameters+=("--stdlog" "4")
_modules+=(i18n terminfo)
fi
- if [ "$use_systemd_in_initramfs" == 'yes' ]; then
+ if [ "$use_systemd_in_initramfs" = "yes" ]; then
_modules+=(systemd systemd-initrd dracut-systemd)
fi
- # Preprocess done - start build, cleanup or full cleanup
- if [[ "$full_cleanup" == 'yes' ]]; then
- echo 'Removing all modules.'
- rm "${_repo_dir}" "${_dracut_dir}" --recursive --force
- elif [[ "$cleanup" == 'yes' ]]; then
- echo 'Removing distribution specific files.'
- cleanup
- else
- . "${_repo_dir}/modules.d/dnbd3-rootfs/helper/build.inc"
- build_initialize_components
- if [[ "$initialize" == 'yes' ]]; then
- echo "Initialized."
- exit 0
- fi
- echo 'Build initramfs.'
-
- "${_dracut_dir}/dracut.sh" --local \
- $_loglevel --modules "${_modules[*]}" --conf /etc/dracut.conf \
- --confdir /etc/dracut.conf.d "${dracut_parameter[@]}" \
- --kver "${kernel_version}" "$file_path"
- _return_code=$?
- if [ "$_return_code" != 0 ]; then
- echo 'Building initial ram file system failed.'
- exit 1
- fi
- # NOTE: dracut generate the initramfs with 0600 permissions
- chmod 0644 "${file_path}"
+
+ # Initialize and exit if we are only preparing the build environment
+ . "${_repo_dir}/modules.d/dnbd3-rootfs/helper/build.inc"
+ build_initialize_components
+ if [ "$initialize" = "yes" ]; then
+ echo "Initialization succeeded."
+ exit 0
+ fi
+
+ echo 'Building initramfs...'
+ "${_dracut_dir}/dracut.sh" --local \
+ $_loglevel --modules "${_modules[*]}" --conf /etc/dracut.conf \
+ --confdir /etc/dracut.conf.d "${dracut_parameter[@]}" \
+ --kver "${kernel_version}" "$file_path"
+ _return_code=$?
+ if [ "$_return_code" != 0 ]; then
+ echo 'Building initramfs failed.'
+ exit 1
fi
+ # NOTE: dracut generate the initramfs with 0600 permissions
+ chmod 0644 "${file_path}"
}
main "$@"