From 581b377a8c03d2d162afacdecbee7065add54091 Mon Sep 17 00:00:00 2001 From: CyberLeo Date: Sat, 16 Oct 2010 22:59:58 -0500 Subject: [PATCH] script/makepkg: add chprepare and chdestroy; trim down unnecessary actions in chstartup and chshutdown --- script/makepkg | 65 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 12 deletions(-) diff --git a/script/makepkg b/script/makepkg index 64318df..4fd4005 100755 --- a/script/makepkg +++ b/script/makepkg @@ -21,22 +21,53 @@ leaf_ports() { # ######## +# Prepare a chroot for work +chprepare() { + # Verify environment sanity + [ -d "${chroot_dir}" ] && omg "${chroot_dir}: directory exists; purging" && chdestroy + mount | grep -q "${chroot_dir}" && wtf "Stuff is mounted under ${chroot_dir}; cannot continue" + [ -d "${seed_dir}" -a -f "${seed_dir}/COPYRIGHT" ] || wtf "Use 'makeworld' to create a root build first" + [ -f "/usr/ports/UPDATING" ] || wtf "Need ports tree in /usr/ports to build" + [ -f "/usr/src/sys/conf/newvers.sh" ] || omg "No base sourcetree in /usr/src" + + meh "Setting up chroot tree" + + # Just in case we're aborted partway through the prepare + trap "chdestroy" exit hup int term kill + + # Populate initial seed + mkdir -p "$(dirname "${chroot_dir}")" || wtf "chroot path create failed" + cp -pR "${seed_dir}" "${chroot_dir}" || wtf "chroot seeding failed" + + # Create mountpoint directories + mkdir -p "${chroot_dir}/dev" || wtf "mkdir /dev failed" + mkdir -p "${chroot_dir}/usr/src" || wtf "mkdir /usr/src failed" + mkdir -p "${chroot_dir}/usr/obj" || wtf "mkdir /usr/obj failed" + mkdir -p "${chroot_dir}/usr/ports" || wtf "mkdir /usr/ports failed" + mkdir -p "${chroot_dir}/var/ports/distfiles" || wtf "mkdir /var/ports/distfiles failed" + + # Create pkg directories + mkdir -p "${pkg_dir}" || wtf "mkdir ${chroot_pkg_dir} failed" + mkdir -p "${bdeps_dir}" || wtf "mkdir ${chroot_bdeps_dir} failed" + + trap "" exit hup int term kill + meh "Chroot tree set up in ${chroot_dir}" + return 0 +} + # Set up chroot mounts and runtime configuration chstartup() { + [ -d "${chroot_dir}" -a -a -f "${chroot_dir}/COPYRIGHT" -a -d "${chroot_dir}/dev" ] || wtf "Chroot not prepared" + # Necessary mountpoints - mkdir -p "${chroot_dir}/dev" || return 1 - mount -t devfs devfs "${chroot_dir}/dev" || return 1 - mkdir -p "${chroot_dir}/usr/ports" || return 1 - mount -t nullfs -r /usr/ports "${chroot_dir}/usr/ports" || return 1 - mkdir -p "${chroot_dir}/var/ports/distfiles" || return 1 - mount -t nullfs -w "${dist_dir}" "${chroot_dir}/var/ports/distfiles" || return 1 + mount -t devfs devfs "${chroot_dir}/dev" || wtf "mount /dev failed" + mount -t nullfs -r /usr/src "${chroot_dir}/usr/src" || wtf "mount /usr/src failed" + mount -t nullfs -r /usr/ports "${chroot_dir}/usr/ports" || wtf "mount /usr/ports failed" + mount -t nullfs -w "${dist_dir}" "${chroot_dir}/var/ports/distfiles" || wtf "mount /var/ports/distfiles failed" # Chroot configuration - cp -f /etc/resolv.conf "${chroot_dir}/etc/resolv.conf" || return 1 - - # Target package directories - mkdir -p "${pkg_dir}" || return 1 - mkdir -p "${bdeps_dir}" || return 1 + cp -f /etc/resolv.conf "${chroot_dir}/etc/resolv.conf" || wtf "seeding /etc/resolv.conf failed" + return 0 } # Unmount all chroot directories @@ -49,9 +80,18 @@ chshutdown() { return 0 } +# Remove all chroot contents +chdestroy() { + chshutdown + chflags -R noschg "${chroot_dir}" || wtf "noschg failed" + rm -Rf "${chroot_dir}" || wtf "chroot removal failed" + return 0 +} + # Evaluate a command line within the chroot cheval() { chroot "${chroot_dir}" env -i ${chroot_env} /bin/sh -c "cd ${chroot_pkg_dir}; ${*}" + return $? } # Run chrooted make @@ -59,6 +99,7 @@ chmake() { local port="/usr/ports/${1##/usr/ports/}" shift cheval "make -C ${port} ${*}" + return $? } ######## @@ -325,7 +366,7 @@ ROOT="$(realpath "$(dirname "${0}")/../worlds")" base_dir="${ROOT}/${TARGET}/${CONFIG}" # Root tree for chroot seeding -root_dir="${base_dir}/root" +seed_dir="${base_dir}/root" # Directory where distfiles will be stored between builds (common to all configs) dist_dir="${ROOT}/seed/distfiles" -- 2.42.0