#!/bin/sh # $FreeBSD: ports/Tools/portbuild/scripts/clean-chroot,v 1.18 2010/12/01 02:27:35 linimon Exp $ # client-side script to clean up a chroot cleanup_mount() { chroot=$1 mount=$2 chrootnb=${chroot##*/} #chroot dir branch=${chroot%/*} #buildid dir branch=${branch%/*} #branch dir branch=${branch%/*} #branch name branch=${branch##*/} jname=${branch}-${chrootnb} # Stop the jail if running jls -qj ${jname} > /dev/null 2>&1 && jail -r ${jname} umount -f ${chroot}${mount} || echo "clean-chroot: Cleanup of ${chroot}${mount} on $(hostname) failed!" } arch=$1 branch=$2 buildid=$3 chroot=$4 clean=$5 pbd=${PORTBUILD_DATA:-/a/portbuild} . ${pbd}/${arch}/client.conf . ${pbd}/${arch}/common.conf . ${pbd}/${arch}/portbuild.conf if [ -f ${pbd}/${arch}/${branch}/builds/${buildid}/portbuild.conf ]; then . ${pbd}/${arch}/${branch}/builds/${buildid}/portbuild.conf fi . ${pbd}/${arch}/portbuild.$(hostname) # directories to clean cleandirs="${LOCALBASE} /compat /var/db/pkg" if [ ! -d "${chroot}" ]; then exit 0 fi if [ `realpath ${chroot}` = "/" ]; then # Don't spam the root file system if something has gone wrong! exit 1 fi if [ -f ${chroot}/tmp/jail.id ]; then pgrep -lfj `awk '{print $1}' ${chroot}/tmp/jail.id` pkill -j `awk '{print $1}' ${chroot}/tmp/jail.id` fi #umount ${chroot}/proc for i in ${ARCHS_REQUIRING_LINPROCFS}; do if [ ${i} = ${arch} ]; then cleanup_mount ${chroot} /compat/linux/proc break fi done for i in /a/ports /usr/src /dev/fd /dev; do cleanup_mount ${chroot} ${i} done if [ ! -z "${ccache_dir}" ]; then cleanup_mount ${chroot} /root/.ccache fi if [ "${use_zfs}" = "1" ]; then cleanup_mount ${chroot} "" zfs destroy -f ${chroot#/} elif [ "${use_tmpfs}" = "1" -a "${clean}" = "2" ]; then cleanup_mount ${chroot} "" if ! rm -rf ${chroot} >/dev/null 2>&1; then chflags -R noschg ${chroot} >/dev/null 2>&1 rm -rf ${chroot} >/dev/null 2>&1 fi # XXX possible race from cleanup and claim by next build? elif [ "${use_md_swap}" = "1" -a \( "${md_persistent}" != "1" -a "${clean}" -gt "0" \) -o "${clean}" = "2" ]; then cleanup_mount ${chroot} /used > /dev/null 2>&1 cleanup_mount ${chroot} "" mdconfig -d -u $(basename ${chroot}) if ! rm -rf ${chroot} >/dev/null 2>&1; then chflags -R noschg ${chroot} >/dev/null 2>&1 rm -rf ${chroot} >/dev/null 2>&1 fi else if [ "${clean}" = 1 ]; then rm -rf ${chroot}/tmp/* for dir in ${cleandirs}; do if ! rm -rf ${chroot}${dir} >/dev/null 2>&1; then chflags -R noschg ${chroot}${dir} >/dev/null 2>&1 rm -rf ${chroot}${dir} >/dev/null 2>&1 fi done test -x ${chroot}/sbin/ldconfig && chroot ${chroot} /sbin/ldconfig -R for i in ${ARCHS_REQUIRING_AOUT_COMPAT}; do if [ ${i} = ${arch} ]; then test -x ${chroot}/sbin/ldconfig && chroot ${chroot} /sbin/ldconfig -aout -R break fi done rm -rf ${chroot}/var/db/pkg/* rm -rf ${chroot}/used elif [ "${clean}" = 2 ]; then if ! rm -rf ${chroot} >/dev/null 2>&1; then chflags -R noschg ${chroot} >/dev/null 2>&1 rm -rf ${chroot} >/dev/null 2>&1 fi fi fi