summaryrefslogtreecommitdiffstats
path: root/builder/dnbd3-rootfs/scripts/build-functions.sh
diff options
context:
space:
mode:
authortorben2015-12-03 15:08:05 +0100
committertorben2015-12-03 15:08:05 +0100
commitf5c40128d22a57fb381cfa95a62662293152f764 (patch)
treed34898670401575b2553fa21c9122d808a4de411 /builder/dnbd3-rootfs/scripts/build-functions.sh
parentupdate rebash (diff)
downloadsystemd-init-f5c40128d22a57fb381cfa95a62662293152f764.tar.gz
systemd-init-f5c40128d22a57fb381cfa95a62662293152f764.tar.xz
systemd-init-f5c40128d22a57fb381cfa95a62662293152f764.zip
Provide cleanup api.
Diffstat (limited to 'builder/dnbd3-rootfs/scripts/build-functions.sh')
-rw-r--r--builder/dnbd3-rootfs/scripts/build-functions.sh131
1 files changed, 131 insertions, 0 deletions
diff --git a/builder/dnbd3-rootfs/scripts/build-functions.sh b/builder/dnbd3-rootfs/scripts/build-functions.sh
new file mode 100644
index 00000000..3a56d32b
--- /dev/null
+++ b/builder/dnbd3-rootfs/scripts/build-functions.sh
@@ -0,0 +1,131 @@
+source "$(dirname "${BASH_SOURCE[0]}")/rebash/core.sh"
+core.import logging
+
+function utils_compile_nbd() {
+ # Downloads and compiles nbd.
+ #
+ # Examples:
+ #
+ # >>> utils_compile_nbd path/to/nbd/directory/
+ # ...
+ # Provides the following file:
+ # "$1/nbd.ko"
+ pushd "$1"
+ logging.info 'Compile the nbd kernel module.'
+ make
+ popd
+ return $?
+}
+function utils_clean_nbd() {
+ # Cleans nbd specific generated files
+ #
+ # Examples:
+ #
+ # >>> utils_clean_nbd path/to/nbd/directory/
+ # ...
+ # Removes the following file:
+ # "$1/nbd.ko"
+ pushd "$1"
+ make clean
+ popd
+ return $?
+}
+function utils_compile_dnbd3() {
+ # Downloads and compiles dnbd3.
+ #
+ # Examples:
+ #
+ # >>> utils_compile_dnbd3 path/to/dnbd3/directory/
+ # ...
+ # Provides the following file:
+ # "$1/build/dnbd3.ko"
+ pushd "$1/.."
+ rm --recursive --force "$1"
+ git clone git://git.openslx.org/dnbd3.git
+ cd dnbd3
+ ./build.sh
+ popd
+ return $?
+}
+function utils_clean_dnbd3() {
+ # Removes generated dnbd3 specific files.
+ #
+ # Examples:
+ #
+ # >>> utils_clean_dnbd3 path/to/dnbd3/directory/
+ # ...
+ # Removes the following directory:
+ # "$1/build"
+ rm --recursive --force "$1/build"
+ return $?
+}
+function utils_compile_systemd_preserve_process_marker() {
+ # Compiles simple c program.
+ #
+ # Examples:
+ #
+ # >>> utils_compile_systemd_preserve_process_marker path/to/program/folder
+ pushd "$1"
+ make
+ popd
+ return $?
+}
+function utils_clean_systemd_preserve_process_marker() {
+ # Removes compiled simple c program.
+ #
+ # Examples:
+ #
+ # >>> utils_clean_systemd_preserve_process_marker path/to/program/folder
+ pushd "$1"
+ make clean
+ popd
+ return $?
+}
+function utils_dependency_check() {
+ # This function check if all given dependencies are present.
+ #
+ # Examples:
+ #
+ # >>> utils_dependency_check "mkdir pacstrap mktemp"
+ # ...
+ local dependenciesToCheck="$1"
+ local result=0
+ local dependency
+ for dependency in ${dependenciesToCheck[*]}; do
+ if ! hash "$dependency" 2>/dev/null; then
+ build_initramfs_log 'critical' \
+ "Needed dependency \"$dependency\" isn't available."
+ result=1
+ fi
+ done
+ return $result
+}
+function utils_mount_partition() {
+ # Mounts a partition at given offset.
+ #
+ # Examples:
+ #
+ # >>> utils_mount_partition /dev/DEVICE_NAME PARTITION_IDENTIFIER
+ # ...
+ local device="$1"
+ local partition_identifier="$2"
+ local loop_device="$(losetup --find)"
+
+ local sector_size="$(blockdev --getbsz "$device")"
+ local partition_info="(partx --raw --noheadings --output START,NAME,UUID \
+ "$device" 2>/dev/null| grep part)"
+ local offset_sectors="$(echo "$partition_identifier" | \
+ cut --delimiter=' ' --fields=1)"
+ if [ -z "$offset_sectors" ]; then
+ logging.warn "could not find partition with identifier \"$partition_identifier\" on device $device"
+ return 1
+ fi
+ # NOTE: Could overflow on 32bit systems
+ # logging.warn "$(("$offset_sectors"*512))"
+ local offset_bytes="$(echo | awk -v x="$offset_sectors" -v y="$sector_size" '{print x * y}')"
+
+ # NOTE: Test if mount works directly (problem with btrfs device id).
+ # mount --verbose --options loop,offset="$offset_bytes" "$device" "$mount_point"
+ losetup --verbose --offset "$offset_bytes" "$loop_device" "$device"
+ echo "$loop_device"
+}