diff options
author | Jonathan Bauer | 2019-09-16 17:06:40 +0200 |
---|---|---|
committer | Jonathan Bauer | 2019-09-16 17:06:40 +0200 |
commit | dd9b081f33052a3d48cb66e9856fe3804cdcd97d (patch) | |
tree | 4b0a2d1eafb95c5af0de097e4cd016d8ccf9d934 /builder | |
parent | Merge branch 'master' into nobash (diff) | |
download | systemd-init-dd9b081f33052a3d48cb66e9856fe3804cdcd97d.tar.gz systemd-init-dd9b081f33052a3d48cb66e9856fe3804cdcd97d.tar.xz systemd-init-dd9b081f33052a3d48cb66e9856fe3804cdcd97d.zip |
more cleanup
Diffstat (limited to 'builder')
-rwxr-xr-x | builder/build-initramfs.sh | 118 |
1 files changed, 16 insertions, 102 deletions
diff --git a/builder/build-initramfs.sh b/builder/build-initramfs.sh index d9017e74..fa57857a 100755 --- a/builder/build-initramfs.sh +++ b/builder/build-initramfs.sh @@ -3,15 +3,14 @@ # region header # Copyright Torben Sickert (info["~at~"]torben.website) 29.10.2015 # Janosch Dobler (info["~at~"]jandob.com) 29.10.2015 - +# Jonathan Bauer (jonathan.bauer@rz.uni-freiburg.de) 19.09.2019 # License # ------- # This library written by Torben Sickert and Janosch Dobler stand under a # creative commons naming 3.0 unported license. # see http://creativecommons.org/licenses/by/3.0/deed.de -# This tool provides a generic way to install systemd based remote linux -# initramfs. +## endregion declare -rg _root_dir="$(readlink -f $(dirname ${BASH_SOURCE[0]}))" declare -rg _repo_dir="${_root_dir}/systemd-init.git" @@ -25,6 +24,7 @@ if [ ! -e "$_repo_dir" ]; then if ! hash git; then echo "Needed dependency \"git\" isn't available." echo "Please install \"git\" or provide the main repository in \"${_repo_dir}\"." + exit 1 fi git clone --branch "$_git_branch" --single-branch --depth 1 \ "$_git_source" "${_repo_dir}" @@ -70,44 +70,10 @@ cleanup='no' full_cleanup='no' use_systemd_in_initramfs='no' -print_command_line_option_description() { - cat << EOF --h --help Shows this help message. - --v --verbose Tells you what is going on (default: "$verbose"). - --d --debug Gives you any output from all tools which are used - (default: "$debug"). - --p --file-path Target location for initramfs file - (default: "$file_path"). - --c --cleanup Removes all distribution specific compiled files. - --f --full-cleanup Removes all retrieved and compiled files (usefull to retrieve latest version of all nested modules). - --t --target Creates an image against given target template filesystem. If not - explicitly specified current system will be used as template system - (default: "$target"). - --i --init Initializes the various repositories and build the required - dependencies but do not build the initramfs. Use this to accelerate - subsequent calls of this script. - --k --kernel-version Creates an image for the given kernel version. Will - require the presence of kernel headers for this version. - (default: "$(uname -r)") - --s --use-systemd-in-initramfs Use Systemd as init process in initramfs - (improved performance but less features) - (default: "$use_systemd_in_initramfs"). - -Additional dracut parameter and normal parameter can be added by delimiting -them via a single dash (-) (default: "$dracut_parameter" with -"--modules" and dynamically determined modules. Additional custom modules are -concatenated.). -EOF +print_help_message() { + echo "help" } + parse_command_line() { while true; do case "$1" in @@ -129,7 +95,7 @@ parse_command_line() { shift file_path="$1" if [[ "$file_path" == '' ]]; then - logging.critical \ + echo \ "Error with given option \"$given_argument\": This option needs a path to save initramfs image to." return 1 fi @@ -152,7 +118,7 @@ parse_command_line() { shift target="$1" if [[ "$target" == '' ]]; then - logging.critical \ + echo \ "Error with given option \"$given_argument\": This option needs a path create initramfs from." return 1 fi @@ -217,23 +183,10 @@ parse_command_line() { done return 0 - if [[ "$UID" != '0' ]]; then - logging.critical \ - "You have to run this script as \"root\" not as \"${USER}\"." - exit 2 - fi - return 0 } ## endregion ## region helper initialize_dracut() { - local __doc__=' - Downloads and compiles dracut. - - Example: - - `initialize_dracut` - ' # First check what version to get # Autodetect the kmod version present on the system to decide which dracut version to get # * v47 requires kmod >= 23 (Available in Ubuntu 18.04) @@ -270,37 +223,18 @@ initialize_dracut() { # TODO does this even works? cleanup() { - # shellcheck disable=SC2016,SC2034 - local __doc__=' - Removes distribution specific generated files. - - Example: - - `cleanup` - ' local plugin_path plugin_path="${_root_dir}/modules.d/dnbd3-rootfs" - # shellcheck disable=SC1090 source "${plugin_path}/module-setup.sh" - # shellcheck disable=SC2034 moddir="$(cd "$plugin_path" &>/dev/null && pwd)" clean return $? } -## endregion -# endregion -# region controller main() { - # shellcheck disable=SC2016,SC2034 - local __doc__=' - Main Entry point for the build initramfs logic. Triggers command line - parsing and calls sub routines depending on given command line arguments. - - Example: - - `main` - ' - # region sanity check kernel version and qcow handler + if ! parse_command_line "$@"; then + print_help_message "$0" + exit 1 + fi # if no kernel was specified as dracut argument, use the running kernel's version echo "Building for:" if [ -z "$kernel_version" ]; then @@ -315,23 +249,16 @@ main() { echo 'Missing core dependency "linux-headers" for version to compile against given or current kernel.' fi echo " * kernel headers: $kernel_headers" - [ -n "$qcow_handler" ] && logging.info " * qcow2 handler: $qcow_handler" + [ -n "$qcow_handler" ] && echo " * qcow2 handler: $qcow_handler" export _QCOW_HANDLER="$qcow_handler" - # endregion - - if ! parse_command_line "$@"; then - print_help_message "$0" - exit 1 - fi if [ "$update" == "yes" ]; then pushd "${_repo_dir}" git pull popd fi - # endregion - # region handle dependencies which can be resolved automatically - echo 'Checking dracut...' + + echo 'Checking dracut...' if [[ ! -f "${_root_dir}/dracut/dracut-install" ]]; then echo "Dracut isn't available yet loading it." initialize_dracut @@ -359,25 +286,18 @@ main() { fi fi done - # endregion - # region prepare modules and perform final dracut call _loglevel='' if [ "$verbose" == 'yes' ]; then _loglevel='--verbose' fi - _modules='dnbd3-rootfs conf-tgz' + _modules='dnbd3-rootfs conf-tgz systemd systemd-initrd dracut-systemd' echo "Default modules: ${_modules}" if [ "$debug" == 'yes' ]; then _loglevel="$_loglevel --stdlog 4" # TODO check if we always want this _modules="$_modules i18n terminfo" fi - # TODO does non-systemd initramfs even works nowadays? - # Why you we want to do SysV-init style??? - if [ "$use_systemd_in_initramfs" == 'yes' ]; then - _modules="$_modules systemd systemd-initrd dracut-systemd" - fi # Preprocess done - start build, cleanup or full cleanup if [[ "$full_cleanup" == 'yes' ]]; then echo 'Removing all modules.' @@ -404,10 +324,4 @@ main() { chmod 0644 "${file_path}" fi } -# endregion main "$@" - -# region vim modline -# vim: set tabstop=4 shiftwidth=4 expandtab: -# vim: foldmethod=marker foldmarker=region,endregion: -# endregion |