summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bootstrap/CentOS-719
-rw-r--r--bootstrap/CentOS-818
-rw-r--r--bootstrap/Ubuntu-1816
-rwxr-xr-xbuild-initramfs.sh146
4 files changed, 160 insertions, 39 deletions
diff --git a/bootstrap/CentOS-7 b/bootstrap/CentOS-7
index 19f9f0b2..5d19e4b9 100644
--- a/bootstrap/CentOS-7
+++ b/bootstrap/CentOS-7
@@ -1,5 +1,4 @@
-
-declare -A _core=(
+declare -A core_repo=(
[handler]="git"
[path]="systemd-init"
[url]="git://git.openslx.org/openslx-ng/systemd-init.git"
@@ -7,15 +6,15 @@ declare -A _core=(
[commit]="c63e555a86"
)
-declare -A module_dracut=(
+declare -A core_dracut=(
[handler]="http"
- [path]="${_core[path]}/builder/dracut"
+ [path]="dracut"
[url]="https://www.kernel.org/pub/linux/utils/boot/dracut/dracut-047.tar.gz"
)
declare -A module_dnbd3=(
[handler]="git"
- [path]="${_core[path]}/builder/modules.d/dnbd3-rootfs/binaries/dnbd3"
+ [path]="${core_repo[path]}/modules.d/dnbd3-rootfs/binaries/dnbd3"
[url]="git://git.openslx.org/dnbd3.git"
[branch]="master"
[commit]="c881c79"
@@ -23,7 +22,7 @@ declare -A module_dnbd3=(
declare -A module_qemu_xmount=(
[handler]="git"
- [path]="${_core[path]}/builder/modules.d/dnbd3-rootfs/binaries/qemu-xmount"
+ [path]="${core_repo[path]}/modules.d/dnbd3-rootfs/binaries/qemu-xmount"
[url]="git://github.com/eaas-framework/qemu.git"
[branch]="libxmount_input"
[commit]="4873cd023da8511ed9792a318d1456c949046123"
@@ -31,7 +30,7 @@ declare -A module_qemu_xmount=(
declare -A module_xmount=(
[handler]="git"
- [path]="${_core[path]}/builder/modules.d/dnbd3-rootfs/binaries/xmount"
+ [path]="${core_repo[path]}/modules.d/dnbd3-rootfs/binaries/xmount"
[url]="git://github.com/eaas-framework/xmount.git"
[branch]="master"
[commit]="0151375"
@@ -40,7 +39,7 @@ declare -A module_xmount=(
declare -A module_kernel_qcow2_util_linux=(
[handler]="git"
[url]="git://git.openslx.org/openslx/kernel-qcow2-util-linux.git"
- [path]="${_core[path]}/builder/modules.d/dnbd3-rootfs/binaries/kernel-qcow2-util-linux"
+ [path]="${core_repo[path]}/modules.d/dnbd3-rootfs/binaries/kernel-qcow2-util-linux"
[branch]="kernel-qcow2"
[commit]="0692b96"
)
@@ -48,7 +47,7 @@ declare -A module_kernel_qcow2_util_linux=(
declare -A module_kernel_qcow2_linux=(
[handler]="git"
[url]="git://git.openslx.org/openslx/kernel-qcow2-linux.git"
- [path]="${_core[path]}/builder/modules.d/dnbd3-rootfs/binaries/kernel-qcow2-linux"
+ [path]="${core_repo[path]}/modules.d/dnbd3-rootfs/binaries/kernel-qcow2-linux"
[branch]="kernel-qcow2-linux-4.19.y"
[commit]="f9b4646"
)
@@ -56,7 +55,7 @@ declare -A module_kernel_qcow2_linux=(
declare -A module_rebash=(
[handler]="git"
[url]="https://github.com/jandob/rebash.git"
- [path]="${_core[path]}/builder/modules.d/dnbd3-rootfs/scripts/rebash"
+ [path]="${core_repo[path]}/modules.d/dnbd3-rootfs/scripts/rebash"
[branch]="master"
[commit]="6ca5b39"
)
diff --git a/bootstrap/CentOS-8 b/bootstrap/CentOS-8
index bb8f7e02..3e6292f8 100644
--- a/bootstrap/CentOS-8
+++ b/bootstrap/CentOS-8
@@ -1,20 +1,20 @@
-declare -A _core=(
+declare -A core_repo=(
[handler]="git"
[path]="systemd-init"
[url]="git://git.openslx.org/openslx-ng/systemd-init.git"
[branch]="downloader"
)
-declare -A module_dracut=(
+declare -A core_dracut=(
[handler]="http"
- [path]="${_core[path]}/builder/dracut"
+ [path]="dracut"
[url]="https://www.kernel.org/pub/linux/utils/boot/dracut/dracut-047.tar.gz"
)
declare -A module_dnbd3=(
[handler]="git"
- [path]="${_core[path]}/builder/modules.d/dnbd3-rootfs/binaries/dnbd3"
+ [path]="${core_repo[path]}/modules.d/dnbd3-rootfs/binaries/dnbd3"
[url]="git://git.openslx.org/dnbd3-ng.git"
[branch]="master"
[commit]="b57dadc2d"
@@ -22,7 +22,7 @@ declare -A module_dnbd3=(
declare -A module_qemu_xmount=(
[handler]="git"
- [path]="${_core[path]}/builder/modules.d/dnbd3-rootfs/binaries/qemu-xmount"
+ [path]="${core_repo[path]}/modules.d/dnbd3-rootfs/binaries/qemu-xmount"
[url]="git://github.com/eaas-framework/qemu.git"
[branch]="libxmount_input"
[commit]="4873cd023da8511ed9792a318d1456c949046123"
@@ -30,7 +30,7 @@ declare -A module_qemu_xmount=(
declare -A module_xmount=(
[handler]="git"
- [path]="${_core[path]}/builder/modules.d/dnbd3-rootfs/binaries/xmount"
+ [path]="${core_repo[path]}/modules.d/dnbd3-rootfs/binaries/xmount"
[url]="git://github.com/eaas-framework/xmount.git"
[branch]="master"
[commit]="0151375"
@@ -39,7 +39,7 @@ declare -A module_xmount=(
declare -A module_kernel_qcow2_util_linux=(
[handler]="git"
[url]="git://git.openslx.org/openslx/kernel-qcow2-util-linux.git"
- [path]="${_core[path]}/builder/modules.d/dnbd3-rootfs/binaries/kernel-qcow2-util-linux"
+ [path]="${core_repo[path]}/modules.d/dnbd3-rootfs/binaries/kernel-qcow2-util-linux"
[branch]="kernel-qcow2"
[commit]="0692b96"
)
@@ -47,7 +47,7 @@ declare -A module_kernel_qcow2_util_linux=(
declare -A module_kernel_qcow2_linux=(
[handler]="git"
[url]="git://git.openslx.org/openslx/kernel-qcow2-linux.git"
- [path]="${_core[path]}/builder/modules.d/dnbd3-rootfs/binaries/kernel-qcow2-linux"
+ [path]="${core_repo[path]}/modules.d/dnbd3-rootfs/binaries/kernel-qcow2-linux"
[branch]="kernel-qcow2-linux-4.18.x-centos"
[commit]="0761b3e9e03"
)
@@ -55,7 +55,7 @@ declare -A module_kernel_qcow2_linux=(
declare -A module_rebash=(
[handler]="git"
[url]="https://github.com/jandob/rebash.git"
- [path]="${_core[path]}/builder/modules.d/dnbd3-rootfs/scripts/rebash"
+ [path]="${core_repo[path]}/modules.d/dnbd3-rootfs/scripts/rebash"
[branch]="master"
[commit]="6ca5b39"
)
diff --git a/bootstrap/Ubuntu-18 b/bootstrap/Ubuntu-18
index 7f73db72..e8efbac8 100644
--- a/bootstrap/Ubuntu-18
+++ b/bootstrap/Ubuntu-18
@@ -1,19 +1,19 @@
-declare -A _core=(
+declare -A core_repo=(
[handler]="git"
[path]="systemd-init"
[url]="git://git.openslx.org/openslx-ng/systemd-init.git"
[branch]="downloader"
)
-declare -A module_dracut=(
+declare -A core_dracut=(
[handler]="http"
- [path]="${_core[path]}/builder/dracut"
+ [path]="dracut"
[url]="https://www.kernel.org/pub/linux/utils/boot/dracut/dracut-047.tar.gz"
)
declare -A module_dnbd3=(
[handler]="git"
- [path]="${_core[path]}/builder/modules.d/dnbd3-rootfs/binaries/dnbd3"
+ [path]="${core_repo[path]}/modules.d/dnbd3-rootfs/binaries/dnbd3"
[url]="git://git.openslx.org/dnbd3.git"
[branch]="master"
[commit]="c881c79"
@@ -21,7 +21,7 @@ declare -A module_dnbd3=(
declare -A module_qemu_xmount=(
[handler]="git"
- [path]="${_core[path]}/builder/modules.d/dnbd3-rootfs/binaries/qemu-xmount"
+ [path]="${core_repo[path]}/modules.d/dnbd3-rootfs/binaries/qemu-xmount"
[url]="git://github.com/eaas-framework/qemu.git"
[branch]="libxmount_input"
[commit]="4873cd023da8511ed9792a318d1456c949046123"
@@ -29,7 +29,7 @@ declare -A module_qemu_xmount=(
declare -A module_xmount=(
[handler]="git"
- [path]="${_core[path]}/builder/modules.d/dnbd3-rootfs/binaries/xmount"
+ [path]="${core_repo[path]}/modules.d/dnbd3-rootfs/binaries/xmount"
[url]="git://github.com/eaas-framework/xmount.git"
[branch]="master"
[commit]="0151375"
@@ -38,7 +38,7 @@ declare -A module_xmount=(
declare -A module_kernel_qcow2_util_linux=(
[handler]="git"
[url]="git://git.openslx.org/openslx/kernel-qcow2-util-linux.git"
- [path]="${_core[path]}/builder/modules.d/dnbd3-rootfs/binaries/kernel-qcow2-util-linux"
+ [path]="${core_repo[path]}/modules.d/dnbd3-rootfs/binaries/kernel-qcow2-util-linux"
[branch]="kernel-qcow2"
[commit]="0692b96"
)
@@ -46,7 +46,7 @@ declare -A module_kernel_qcow2_util_linux=(
declare -A module_kernel_qcow2_linux=(
[handler]="git"
[url]="git://git.openslx.org/openslx/kernel-qcow2-linux.git"
- [path]="${_core[path]}/builder/modules.d/dnbd3-rootfs/binaries/kernel-qcow2-linux"
+ [path]="${core_repo[path]}/modules.d/dnbd3-rootfs/binaries/kernel-qcow2-linux"
[branch]="kernel-qcow2-linux-4.19.y"
[commit]="f9b4646"
)
diff --git a/build-initramfs.sh b/build-initramfs.sh
index 31f39118..ae8384ff 100755
--- a/build-initramfs.sh
+++ b/build-initramfs.sh
@@ -4,6 +4,7 @@
# 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
+# Thiago Abdo (tjabdo@inf.ufpr.br) 06.11.2019
# License
# -------
@@ -12,10 +13,15 @@
# see http://creativecommons.org/licenses/by/3.0/deed.de
## endregion
-# I think this are the same...
+# Afaik the idea here was to have the root dir where build-initramfs.sh
+# is called from and the repo dir where the systemd-init.git is cloned to:
+# <root_dir>
+# |- build-initramfs.sh
+# |- dracut
+# |- systemd-init
declare -rg _root_dir="$(readlink -f $(dirname ${BASH_SOURCE[0]}))"
-declare -rg _repo_dir="${_root_dir}"
+# TODO clean these up
file_path='/boot/initramfs.img'
dracut_parameter=(--force --no-hostonly)
verbose='no'
@@ -25,6 +31,118 @@ cleanup='no'
full_cleanup='no'
use_systemd_in_initramfs='no'
+
+declare -rg _bootstrap_modules="bootstrap.conf"
+
+bootstrap() {
+ if [ ! -f "$_bootstrap_modules" ]; then
+ echo "Missing modules definition file: $_bootstrap_modules"
+ print_help_message 1
+ exit 1
+ fi
+
+ . "$_bootstrap_modules"
+
+ if [[ ! -v core_dracut[@] ]] || [[ ! -v core_repo[@] ]]; then
+ echo "Missing core modules for dracut & systemd-init"
+ exit 1
+ fi
+
+ declare -rg _repo_dir="$(readlink -f ${core_repo[path]})"
+ declare -rg _dracut_dir="$(readlink -f ${core_dracut[path]})"
+
+ echo "Modules file: $_bootstrap_modules"
+ echo "Core modules: ${!core_*}"
+ echo "Modules: ${!module_*}"
+ echo ""
+
+
+ for module in "${!core_@}" "${!module_@}"; do
+ declare -n _ref="$module"
+ if [ -n "$(ls -A "${_ref[path]}" 2> /dev/null)" ]; then
+ echo "'${_ref[path]}' not empty, skipping..."
+ continue
+ fi
+ echo "######################### $module #########################"
+ echo "Handler: ${_ref[handler]}"
+ echo " URL: ${_ref[url]}"
+ echo " Branch: ${_ref[branch]}"
+ echo " Commit: ${_ref[commit]}"
+ echo " Path: ${_ref[path]}"
+ handler_${_ref[handler]} \
+ "${_ref[path]}" \
+ "${_ref[url]}" \
+ "${_ref[branch]}" \
+ "${_ref[commit]}"
+
+ # apply patches if any are required
+ shopt -s nullglob
+ pushd "${_ref[path]}"
+ for patch in "${_repo_dir}/patches/${_ref[path]##*/}/"*.patch; do
+ patch -p1 < "$patch"
+ done
+ popd
+
+ done
+}
+
+handler_git() {
+ local path="$1"
+ local url="$2"
+ local branch="$3"
+ local commit="$4"
+
+ mkdir -p "$path"
+
+ local gitargs=( \
+ "--depth" "1" \
+ "--single-branch" \
+ )
+ if [ -n "$branch" ]; then
+ gitargs+=("--branch" "$branch")
+ fi
+ git clone "${gitargs[@]}" "${url}" "${path}"
+
+ [ -z "$commit" ] && return 0
+
+ # make sure given commit in in the fetched history
+ local revision="$branch"
+ if [ -n "$commit" ]; then
+ revision="$commit"
+ fi
+
+ # manual "shallow clone" since not all server allow it...
+ pushd "$path"
+ local i=50
+ while ! git rev-parse --quiet --verify $revision^{commit}; do
+ git fetch --depth=$(( i+=50 ))
+ done
+ git reset --hard "$revision"
+ popd
+}
+
+handler_http() {
+ local path="$1"
+ local url="$2"
+
+ mkdir --parents "$path"
+
+ curl \
+ --location \
+ --max-redirs 5 \
+ --max-time 7 \
+ --connect-timeout 2 \
+ --retry 3 \
+ --retry-max-time 12 \
+ "$url" \
+ | tar \
+ --extract \
+ --gzip \
+ --directory "$path" \
+ --strip-components 1
+}
+
+
print_help_message() {
echo "TODO"
}
@@ -141,8 +259,8 @@ parse_command_line() {
}
## endregion
## region helper
-initialize_dracut() {
- pushd "${_root_dir}/dracut"
+compile_dracut() {
+ pushd "${_dracut_dir}"
# NOTE: On virtualbox shared folder symlinks are not allowed.
# NOTE: make the dracut-install binary (dracut-install resolves
# dependencies etc.)
@@ -155,8 +273,8 @@ initialize_dracut() {
# If symlinks would be available we could simply use:
# >>> make dracut-install
popd
- cp "${_root_dir}/dracut/install/dracut-install" \
- "${_root_dir}/dracut/dracut-install"
+ cp "${_dracut_dir}/install/dracut-install" \
+ "${_dracut_dir}/dracut-install"
return $?
}
@@ -165,17 +283,20 @@ initialize_dracut() {
# TODO: Does this still work?
cleanup() {
local plugin_path
- plugin_path="${_root_dir}/modules.d/dnbd3-rootfs"
+ plugin_path="${_repo_dir}/modules.d/dnbd3-rootfs"
source "${plugin_path}/module-setup.sh"
moddir="$(cd "$plugin_path" &>/dev/null && pwd)"
clean
return $?
}
+
main() {
if ! parse_command_line "$@"; then
print_help_message "$0"
exit 1
fi
+ # prepare submodules for the dnbd3-rootfs module
+ bootstrap
# if no kernel was specified as dracut argument, use the running kernel's version
echo "Building for:"
if [ -z "$kernel_version" ]; then
@@ -200,16 +321,16 @@ main() {
fi
echo 'Checking dracut...'
- if [[ ! -f "${_root_dir}/dracut/dracut-install" ]]; then
+ if [ ! -f "${_dracut_dir}/dracut-install" ]; then
echo "Dracut isn't available yet loading it."
- initialize_dracut
+ compile_dracut
fi
for _dracut_module_dir in "${_repo_dir}/modules.d/"*; do
[ -d "${_dracut_module_dir}" ] || continue
_dracut_module="$(basename $_dracut_module_dir)"
# TODO allow module-specific priority
- _dracut_module_target="${_root_dir}/dracut/modules.d/00${_dracut_module}"
+ _dracut_module_target="${_dracut_dir}/modules.d/00${_dracut_module}"
if [[ ! -L "$_dracut_module_target" || "$(readlink \
"$_dracut_module_target")" != "$_dracut_module_dir" ]]; then
echo \
@@ -241,7 +362,7 @@ main() {
# Preprocess done - start build, cleanup or full cleanup
if [[ "$full_cleanup" == 'yes' ]]; then
echo 'Removing all modules.'
- rm "${_repo_dir}" "${_root_dir}/dracut" --recursive --force
+ rm "${_repo_dir}" "${_dracut_dir}" --recursive --force
elif [[ "$cleanup" == 'yes' ]]; then
echo 'Removing distribution specific files.'
cleanup
@@ -254,7 +375,7 @@ main() {
fi
echo 'Build initramfs.'
- "${_root_dir}/dracut/dracut.sh" --local \
+ "${_dracut_dir}/dracut.sh" --local \
$_loglevel --modules "${_modules[*]}" --conf /etc/dracut.conf \
--confdir /etc/dracut.conf.d "${dracut_parameter[@]}" \
--kver "${kernel_version}" "$file_path"
@@ -267,4 +388,5 @@ main() {
chmod 0644 "${file_path}"
fi
}
+
main "$@"