#!/bin/bash # Copyright 2010 Rob Landley licensed under GPLv2 if test $1 == "-d" { global DELETE := '1' shift } # Clean up a chroot directory global ZAP := $[readlink -f $1 !2 >/dev/null] if test ! -d $ZAP { echo "usage: zapchroot [-d] dirname" exit 1 } global i := $[readlink -f $[pwd]] if test $ZAP == $(i:0:${#ZAP}) { echo "Sanity check failed: cwd is under zapdir" > !2 exit 1 } # Iterate through the second entry of /proc/mounts in reverse order for i in [$[awk '{print $2}' /proc/mounts | tac]] { # De-escape octal versions of space, tab, backslash, newline... global i := $[echo -e $i] # Skip entries that aren't under our chroot test $ZAP != $(i:0:${#ZAP}) && continue echo "Umounting: $i" umount $i }