index : builder | |
Archlinux32 build system | gitolite user |
summaryrefslogtreecommitdiff |
author | Erich Eckner <git@eckner.net> | 2017-06-27 10:33:20 +0200 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2017-06-27 10:33:20 +0200 |
commit | 60c1992c6065eb1aaf5cb76f4e30cae7ba24b87c (patch) | |
tree | ceba3f03f2f7e70e7c4d8d9208d5de345c8fbef0 | |
parent | 5f41f8c2ad892465c894c705b6a8b3180fa429b9 (diff) |
-rwxr-xr-x | bin/common-functions | 47 |
diff --git a/bin/common-functions b/bin/common-functions index 32c2e0a..59b7577 100755 --- a/bin/common-functions +++ b/bin/common-functions @@ -427,9 +427,16 @@ make_source_info() { )" fi + bail_out() { + err=$? + recursively_umount_and_rm "${overlays_dir}" + exit ${err} + } + overlays_dir="$(mktemp -d)" - sudo mount -t tmpfs none "${overlays_dir}" + sudo mount -t tmpfs none "${overlays_dir}" || \ + bail_out mkdir \ "${overlays_dir}/lower" \ @@ -437,28 +444,52 @@ make_source_info() { "${overlays_dir}/work" \ "${overlays_dir}/merged" - echo "${content}" > \ + echo "${content}" | \ + sed '/^\$Id\$$/d' > \ "${overlays_dir}/lower/PKGBUILD" mkdir "${overlays_dir}/lower/etc" - head -c16 /dev/random | \ - hexdump -e '"%x"' > \ + hexdump -n 16 -e '4/4 "%08x" 1 "\n"' /dev/urandom > \ "${overlays_dir}/lower/etc/machine-id" - sudo mount -t overlay overlay -o lowerdir="${overlays_dir}/lower":"/",upperdir="${overlays_dir}/upper",workdir="${overlays_dir}/work" "${overlays_dir}/merged" + sudo mount -t overlay overlay -o lowerdir="${overlays_dir}/lower":"/",upperdir="${overlays_dir}/upper",workdir="${overlays_dir}/work" "${overlays_dir}/merged" || \ + bail_out sudo systemd-nspawn -q \ -D "${overlays_dir}/merged" \ --register=no \ - ${base_dir}/bin/mksrcinfo + ${base_dir}/bin/mksrcinfo || \ + bail_out - sudo umount -l "${overlays_dir}/merged" + sudo umount -l "${overlays_dir}/merged" || \ + bail_out mv \ "${overlays_dir}/upper/.SRCINFO" \ "${output}" - sudo umount -l "${overlays_dir}" + sudo umount -l "${overlays_dir}" || \ + bail_out rmdir "${overlays_dir}" } + +# recursively_umount_and_rm $dir +# umount all mountpoints in $dir which are also in $dir's +# filesystem, possibly also $dir itself and then +# rm -rf --one-file-system $dir + +recursively_umount_and_rm() { + local dir="$1" + + if [ -z "${dir}" ]; then + >&2 echo 'ERROR: recursively_umount_and_rm requires an argument' + exit 42 + fi + + find "${dir}" \ + -xdev -depth -type d \ + -exec 'mountpoint' '-q' '{}' ';' \ + -exec 'sudo' 'umount' '-l' '{}' ';' + rm -rf --one-file-system "${dir}" +} |