summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortorben2015-10-29 12:50:57 +0100
committertorben2015-10-29 12:50:57 +0100
commit4b24b0e3d5caa69b522d23f3cef4c65688fc6fdc (patch)
treea2a51082b35838116c3821b28e00ef9d848bbaba
parentWrite automatic dracut module into dracut module system integration. (diff)
downloadsystemd-init-4b24b0e3d5caa69b522d23f3cef4c65688fc6fdc.tar.gz
systemd-init-4b24b0e3d5caa69b522d23f3cef4c65688fc6fdc.tar.xz
systemd-init-4b24b0e3d5caa69b522d23f3cef4c65688fc6fdc.zip
Adding needed dependencies to automatic dependency checker.
Fixing some bugs. Refactoring.
-rwxr-xr-xbuild_initramfs.sh103
1 files changed, 56 insertions, 47 deletions
diff --git a/build_initramfs.sh b/build_initramfs.sh
index 99a4bb9a..05d345a0 100755
--- a/build_initramfs.sh
+++ b/build_initramfs.sh
@@ -29,24 +29,28 @@
# ------------
# - bash (or any bash like shell)
-# - cpio - Copies files into or out of a cpio or tar archive. The archive
-# can be another file on the disk, a magnetic tape, or a pipe.
-# - git - The stupid content tracker.
-# - test - Check file types and compare values (part of the shell).
-# - shift - Shifts the command line arguments (part of the shell).
-# - echo - Display a line of text (part of coreutils).
-# - mktemp - Create a temporary file or directory (part of coreutils).
-# - cat - Concatenate files and print on the standard output (part of
-# coreutils).
-# - rm - Remove files or directories (part of coreutils).
-# - sed - Stream editor for filtering and transforming text.
-# - wget - The non-interactive network downloader.
-# - xz - Compress or decompress .xz and lzma files.
-# - tar - The GNU version of the tar archiving utility.
-# - grep - Searches the named input files (or standard input if no files
-# are named, or if a single hyphen-minus (-) is given as file
-# name) for lines containing a match to the given PATTERN. By
-# default, grep prints the matching lines.
+# - cpio - Copies files into or out of a cpio or tar archive. The
+# archive can be another file on the disk, a magnetic tape,
+# or a pipe.
+# - git - The stupid content tracker.
+# - test - Check file types and compare values (part of the shell).
+# - shift - Shifts the command line arguments (part of the shell).
+# - echo - Display a line of text (part of coreutils).
+# - mktemp - Create a temporary file or directory (part of coreutils).
+# - cat - Concatenate files and print on the standard output (part of
+# coreutils).
+# - rm - Remove files or directories (part of coreutils).
+# - sed - Stream editor for filtering and transforming text.
+# - gzip - Compress or expand files.
+# - curl - Transfer a URL
+# - tar - The GNU version of the tar archiving utility.
+# - make - GNU make utility to maintain groups of programs.
+# - cmake - The "cmake" executable is the CMake command-line interface.
+# - linux-headers - GNU make utility to maintain groups of programs.
+# - grep - Searches the named input files (or standard input if no
+# files are named, or if a single hyphen-minus (-) is given
+# as file name) for lines containing a match to the given
+# PATTERN. By default, grep prints the matching lines.
# Optional dependencies
# ---------------------
@@ -75,7 +79,7 @@ function build_initramfs() {
"$_SCOPE" _VERBOSE='no'
"$_SCOPE" _LOAD_ENVIRONMENT='no'
local dependencies=(bash cpio git test shift echo mktemp cat rm sed \
- wget xz tar grep)
+ gzip curl tar grep make cmake)
"$_SCOPE" _DEPENDENCIES="${dependencies[*]}"
"$_SCOPE" _KERNEL_MODULE_DIRECTORY="builder/dnbd3-qcow2-rootfs/kernel_modules/"
"$_SCOPE" _STANDARD_OUTPUT=/dev/null
@@ -91,8 +95,8 @@ function build_initramfs() {
function build_initramfs_print_usage_message() {
# Prints a description about how to use this program.
cat << EOF
-$__NAME__ This tool provides a generic way to install systemd based remote
-linux initramfs.
+$__NAME__ provides a generic way to install systemd based remote linux
+initramfs.
EOF
}
function build_initramfs_print_usage_examples() {
@@ -120,11 +124,11 @@ EOF
function build_initramfs_print_help_message() {
# Provides a help message for this module.
echo -e "\nUsage: $0 [options]\n"
- archInstallPrintUsageMessage "$@"
+ build_initramfs_print_usage_message "$@"
echo -e '\nExamples:\n'
- archInstallPrintUsageExamples "$@"
+ build_initramfs_print_usage_examples "$@"
echo -e '\nOption descriptions:\n'
- archInstallPrintCommandLineOptionDescription "$@"
+ build_initramfs_print_command_line_option_description "$@"
echo
}
function build_initramfs_command_line_interface() {
@@ -164,7 +168,7 @@ EOF
esac
done
if [[ "$UID" != '0' ]]; then
- archInstallLog 'critical' \
+ build_initramfs_log 'critical' \
"You have to run this script as \"root\" not as \"${USER}\"."
exit 2
fi
@@ -211,14 +215,14 @@ EOF
#
# Examples:
#
- # >>> archInstallPerformDependencyCheck "mkdir pacstrap mktemp"
+ # >>> build_initramfs_perform_dependency_check "mkdir pacstrap mktemp"
# ...
local dependenciesToCheck="$1" && \
local result=0 && \
local dependency && \
for dependency in ${dependenciesToCheck[*]}; do
if ! hash "$dependency" 1>"$_STANDARD_OUTPUT" 2>/dev/null; then
- archInstallLog 'critical' \
+ build_initramfs_log 'critical' \
"Needed dependency \"$dependency\" isn't available." && \
result=1
fi
@@ -241,7 +245,7 @@ EOF
https://www.kernel.org/pub/linux/utils/boot/dracut/dracut-043.tar.gz | \
tar --extract --gzip --directory dracut --strip-components 1 \
1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT" && \
- cd dracut 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT" && \
+ pushd dracut 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT" && \
# NOTE: On virtualbox shared folder symlinks are not allowed.
# make the dracut-install binary (dracut-install resolves dependencies etc.)
build_initramfs_log 'Compile dracut.' && \
@@ -254,12 +258,7 @@ EOF
# >>> make dracut-install
cp install/dracut-install dracut-install 1>"$_STANDARD_OUTPUT" \
2>"$_ERROR_OUTPUT" && \
- cd - 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT"
- build_initramfs_log \
- 'Copy dnbd3 qcow2 plugin into dracut modules folder.' && \
- cp --recursive builder/dnbd3-qcow2-rootfs/ \
- dracut/modules.d/90dndb3-qcow2-rootfs \
- 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT"
+ popd 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT"
return $?
}
function build_initramfs_compile_nbd() {
@@ -271,11 +270,11 @@ EOF
# ...
# Provides the following file:
# ${_KERNEL_MODULE_DIRECTORY}/nbd/nbd.ko
- cd "${_KERNEL_MODULE_DIRECTORY}/nbd" \
+ pushd "${_KERNEL_MODULE_DIRECTORY}/nbd" \
1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT" && \
build_initramfs_log 'Compile the nbd kernel module.' && \
make 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT" && \
- cd - 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT" && \
+ popd 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT"
return $?
# TODO make clean
}
@@ -288,12 +287,15 @@ EOF
# ...
# Provides the following file:
# ${_KERNEL_MODULE_DIRECTORY}/dnbd3/build/dnbd3.ko
- cd $_KERNEL_MODULE_DIRECTORY \
+ rm --recursive --force ${_KERNEL_MODULE_DIRECTORY}/dnbd3 \
+ 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT" && \
+ pushd $_KERNEL_MODULE_DIRECTORY \
1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT" && \
git clone git://git.openslx.org/dnbd3.git \
1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT" && \
cd dnbd3 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT" && \
./build.sh 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT" && \
+ popd 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT"
return $?
# TODO rm -rf build
}
@@ -302,21 +304,28 @@ EOF
# region controller
- if [[ "$0" == *"${__NAME__}.bash" ]]; then
+ if [[ "$0" == *"${__NAME__}.sh" ]]; then
build_initramfs_perform_dependency_check "${_DEPENDENCIES[*]}" || \
build_initramfs_log 'error' 'Satisfying main dependencies failed.'
build_initramfs_command_line_interface "$@" || return $?
- build_initramfs_log 'Checking dracut.'
+ build_initramfs_log 'Checking dracut.' && \
if ! [[ -d ./dracut ]]; then
- build_initramfs_initialize_dracut && \
- build_initramfs_compile_nbd && \
- build_initramfs_compile_dnbd3 && \
- # TODO add dnbd3-qcow2-rootfs to modules.d
- build_initramfs_log 'Build initramfs.' && \
- ./dracut.sh --local --verbose --force 1>"$_STANDARD_OUTPUT" \
- 2>"$_ERROR_OUTPUT"
+ build_initramfs_log "Dracut isn't available yet loading it." && \
+ build_initramfs_initialize_dracut
fi
+ # TODO Provide note if compilation doesn't work that we need
+ # "linux-headers".
+ build_initramfs_compile_nbd && \
+ build_initramfs_compile_dnbd3 && \
+ build_initramfs_log 'Build initramfs.' && \
+ build_initramfs_log \
+ 'Copy dnbd3 qcow2 plugin into dracut modules folder.' && \
+ cp --recursive builder/dnbd3-qcow2-rootfs/ \
+ dracut/modules.d/90dndb3-qcow2-rootfs \
+ 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT" && \
+ dracut/dracut.sh --local --verbose --force \
+ 1>"$_STANDARD_OUTPUT" 2>"$_ERROR_OUTPUT"
fi
return 0
@@ -326,7 +335,7 @@ EOF
# region footer
-if [[ "$0" == *"${__NAME__}.bash" || $(echo "$@" | grep --extended-regexp \
+if [[ "$0" == *"${__NAME__}.sh" || $(echo "$@" | grep --extended-regexp \
'(^| )(-l|--load-environment)($| )') ]]; then
"$__NAME__" "$@"
fi