Skip to content

Commit

Permalink
More tweaks by Marcus
Browse files Browse the repository at this point in the history
Thanks!
  • Loading branch information
mlschroe committed Sep 25, 2020
1 parent 8a95adc commit 48ba7f5
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 27 deletions.
3 changes: 2 additions & 1 deletion build-vm-ec2
Expand Up @@ -131,7 +131,7 @@ vm_detach_swap_ec2() {

vm_fixup_ec2() {
# No way to handle this via init= parameter here....
rm -rf "$BUILD_ROOT/sbin/init"
buildroot_rm /sbin/init
echo "#!/bin/sh" > "$BUILD_ROOT/sbin/init"
echo 'exec /.build/build "$@"' >> "$BUILD_ROOT/sbin/init"
chmod 0755 "$BUILD_ROOT/sbin/init"
Expand All @@ -146,6 +146,7 @@ vm_fixup_ec2() {
if ! test -e "$BUILD_ROOT/boot/grub/menu.lst"; then
assert_dirs boot/grub
mkdir -p "$BUILD_ROOT/boot/grub"
buildroot_rm /boot/grub/menu.lst
echo "serial --unit=0 --speed=9600" > "$BUILD_ROOT/boot/grub/menu.lst"
echo "terminal --dumb serial" >> "$BUILD_ROOT/boot/grub/menu.lst"
echo "default 0" >> "$BUILD_ROOT/boot/grub/menu.lst"
Expand Down
13 changes: 7 additions & 6 deletions build-vm-lxc
Expand Up @@ -44,7 +44,7 @@ lxcsh() {
vm_startup_lxc() {
lxc_get_id
LXCCONF="$BUILD_ROOT/.build.lxc.conf"
rm -rf "$LXCCONF"
buildroot_rm .build.lxc.conf
vm_startup_lxc_$LXC_TYPE
BUILDSTATUS="$?"
test "$BUILDSTATUS" != 255 || BUILDSTATUS=3
Expand All @@ -71,7 +71,7 @@ vm_startup_lxc_standalone() {
;;
esac
# XXX: do this always instead of leaking the hosts' one?
rm -rf "$BUILD_ROOT/etc/mtab"
buildroot_rm /etc/mtab
echo "rootfs / rootfs rw 0 0" > "$BUILD_ROOT/etc/mtab"
lxc-destroy -n "$LXCID" >/dev/null 2>&1 || true
mkdir -p "$LXCROOTFS"
Expand All @@ -94,8 +94,8 @@ vm_startup_lxc_standalone() {
cleanup_and_exit 1
;;
esac
if ! [ -r "$BUILD_ROOT/.build/_exitcode" ]; then
echo "'$BUILD_ROOT/.build/_exitcode' not found"
if ! [ -r "$BUILD_ROOT/.build/_exitcode" -a ! -L "$BUILD_ROOT/.build/_exitcode" ]; then
echo "'$BUILD_ROOT/.build/_exitcode' not found or symlink"
return 3
fi
exitcode=$(cat $BUILD_ROOT/.build/_exitcode)
Expand Down Expand Up @@ -149,15 +149,16 @@ vm_startup_lxc_libvirt() {
</domain>
EOF
# XXX: do this always instead of leaking the hosts' one?
buildroot_rm /etc/mtab
echo "rootfs / rootfs rw 0 0" > $BUILD_ROOT/etc/mtab
# could LOGFILE be used instead?
lxcsh create --console $LXCCONF | sed -ure 's/\x0d//g;:redo /.\x08/{s/.\x08//; b redo}'
exitcode="${PIPESTATUS[0]}"
if [ "$exitcode" -gt 0 ]; then
return $exitcode # libvirt errors
fi
if ! [ -r "$BUILD_ROOT/.build/_exitcode" ]; then
echo "'$BUILD_ROOT/.build/_exitcode' not found"
if ! [ -r "$BUILD_ROOT/.build/_exitcode" -a ! -L "$BUILD_ROOT/.build/_exitcode" ]; then
echo "'$BUILD_ROOT/.build/_exitcode' not found or symlink"
return 3
fi
exitcode=$(cat $BUILD_ROOT/.build/_exitcode)
Expand Down
8 changes: 6 additions & 2 deletions build-vm-zvm
Expand Up @@ -342,8 +342,10 @@ vm_initrd_obs_modules_zvm() {
current_kernel_version=$(ls lib/modules)
# copy modules from kernel that is installed to the buildsystem:
mkdir -p "$TEMPDIR/lib/modules/$3"
assert_dir_path "lib/modules/${3}"
while read module; do
(cd ${BUILD_ROOT}/lib/modules/${3}; \
assert_dir_path "lib/modules/${3}/${module%.xz}"
rsync -a --relative $module ${TEMPDIR}/lib/modules/$3)
done < <(cd $TEMPDIR/lib/modules/${current_kernel_version}; \
find . -name "*.xz")
Expand All @@ -366,8 +368,7 @@ vm_fixup_zvm() {
# have to copy kernel/initrd and run zipl to be able to IPL
# have to set init_script before unmounting, thus doing it statically for now.
zvm_init_script="/.build/build"
assert_dirs boot boot/zipl
mkdir -p $BUILD_ROOT/boot
assert_dir_path boot/zipl
mkdir -p $BUILD_ROOT/boot/zipl
vm_kernel="/.build.kernel.kvm"
test -e "${BUILD_ROOT}${vm_kernel}" -a ! -L "${BUILD_ROOT}${vm_kernel}" || cleanup_and_exit 1 "${vm_kernel} does not exist"
Expand All @@ -377,8 +378,11 @@ vm_fixup_zvm() {
vm_initrd="${vm_initrd}-${kernel_version}"
# copy initrd to build worker:
echo "copy $vm_initrd to $BUILD_ROOT"
rm -rf "${BUILD_ROOT}/boot/${vm_initrd}"
cp -a "${vm_initrd}" "${BUILD_ROOT}/boot"
# finally, install bootloader to the worker disk
# XXX/TODO: does zipl read or write ${BUILD_ROOT}${vm_initrd}? Either
# rm -rf the file or check for a symlink
zipl -t "$BUILD_ROOT/boot/zipl" -i "${BUILD_ROOT}${vm_kernel}" \
-r "${BUILD_ROOT}${vm_initrd}" \
--parameters "${zvm_param} init=$zvm_init_script rootfsopts=noatime"
Expand Down
29 changes: 29 additions & 0 deletions common_functions
Expand Up @@ -154,3 +154,32 @@ buildroot_umount() {
umount -n "$BUILD_ROOT/$d" 2>/dev/null || true
}

# rm that makes sure the file is gone
buildroot_rm() {
rm -rf "$BUILD_ROOT/$1"
test -e "$BUILD_ROOT/$1" && cleanup_and_exit 1 "could not remove $BUILD_ROOT/$1"
}


assert_dirs() {
local d rl
if test -z "$1" ; then
set usr sbin usr/bin usr/sbin etc .build .init_b_cache .init_b_cache/scripts .init_b_cache/rpms .preinstall_image proc proc/sys proc/sys/fs proc/sys/fs/binfmt_misc sys dev dev/pts dev/shm mnt
fi
for d in "$@" ; do
if test -L "$BUILD_ROOT/$d" ; then
rl="$(readlink "$BUILD_ROOT/$d")"
test "$d" = sbin -a "x$rl" = "xusr/sbin" && continue
test "$d" = sbin -a "x$rl" = "xusr/bin" && continue
test "$d" = usr/sbin -a "x$rl" = "xbin" && continue
cleanup_and_exit 1 "$d: illegal symlink to $rl"
else
test -e "$BUILD_ROOT/$d" -a ! -d "$BUILD_ROOT/$d" && cleanup_and_exit 1 "$d: not a directory"
fi
done
}

assert_dir_path() {
test "$1" != "${1%/*}" && assert_dir_path "${1%/*}"
assert_dir "$1"
}
18 changes: 0 additions & 18 deletions init_buildsystem
Expand Up @@ -203,24 +203,6 @@ preinstall_image_filter() {
done
}

assert_dirs() {
local d rl
if test -z "$1" ; then
set usr sbin usr/bin usr/sbin etc .build .init_b_cache .init_b_cache/scripts .init_b_cache/rpms .preinstall_image proc proc/sys proc/sys/fs proc/sys/fs/binfmt_misc sys dev dev/pts dev/shm mnt
fi
for d in "$@" ; do
if test -L "$BUILD_ROOT/$d" ; then
rl="$(readlink "$BUILD_ROOT/$d")"
test "$d" = sbin -a "x$rl" = "xusr/sbin" && continue
test "$d" = sbin -a "x$rl" = "xusr/bin" && continue
test "$d" = usr/sbin -a "x$rl" = "xbin" && continue
cleanup_and_exit 1 "$d: illegal symlink to $rl"
else
test -e "$BUILD_ROOT/$d" -a ! -d "$BUILD_ROOT/$d" && cleanup_and_exit 1 "$d: not a directory"
fi
done
}

preinstall_setup() {
cd "$BUILD_ROOT" || cleanup_and_exit 1
rm -rf build-preinstall
Expand Down

0 comments on commit 48ba7f5

Please sign in to comment.