43 lines
958 B
Bash
43 lines
958 B
Bash
|
#!/bin/sh
|
||
|
# -*- mode: sh; tab-width: 8; encoding: utf-8-unix -*-
|
||
|
|
||
|
ROLE=base
|
||
|
prog=$( basename $0 .bash )
|
||
|
|
||
|
. /usr/local/bin/usr_local_tput.bash
|
||
|
error () { ERROR "$prog $2" ; exit $1 ; }
|
||
|
|
||
|
# must be run as root
|
||
|
if [ "$( id -u )" != "0" ] ; then
|
||
|
echo ERROR: $0 run as root
|
||
|
exit 0
|
||
|
fi
|
||
|
if [ "$#" -eq "0" ] ; then
|
||
|
error 2 "give an absolute directory name as argument"
|
||
|
fi
|
||
|
root=$1
|
||
|
if [ ! -d "$1" ] ; then
|
||
|
error 3 "give an absolute directory name for chroot - $root"
|
||
|
fi
|
||
|
|
||
|
mount | grep $root/ | while read a on elt rest ; do
|
||
|
umount $elt || { ERROR "unmounting $elt" ; exit 5 ; }
|
||
|
done
|
||
|
|
||
|
mount | grep bind | while read a on elt rest ; do
|
||
|
umount $elt || { ERROR "unmounting $elt" ; exit 6 ; }
|
||
|
done
|
||
|
|
||
|
umount -R $root
|
||
|
|
||
|
lsof $root/usr 2>/dev/null \
|
||
|
| sed -e 's@^[a-z]* *@@' -e 's@ .*@@' \
|
||
|
| grep -v "$$\\|COMMAND" | sort -r -u | while read pid ; do
|
||
|
INFO "killing $pid"
|
||
|
kill $pid
|
||
|
sleep 10
|
||
|
#? kill -9 $pid
|
||
|
done
|
||
|
|
||
|
exit 0
|