#! /bin/sh # $Id$ if [ "$1" = "-u" ];then u=true shift else u=false fi # Do not rebuild the tree if it looks as already setup. if [ "$1" = "-s" ];then soft=true shift else soft=false fi if [ "$1" = "-h" ];then echo >&2 "$0 [/var/lib/mock/]..." exit 1 fi if [ $# = 0 ];then l="`echo /var/lib/mock/*`" else l="$*" fi set -e trap 'echo >&2 FATAL ERROR' EXIT rc=0 for r in $l;do r="`echo "$r"|tr -s /`" r="${r#/var/lib/mock/}" r="${r%/}" rpath="/var/lib/mock/$r/root" if [ ! -d "$rpath" ];then echo >&2 "$rpath does not exist" exit 1 fi echo >&2 -n "Locking $rpath/MOCK.mocksetup-lock ..." if ! lockfile -1 -r 1 -s 1 $rpath/MOCK.mocksetup-lock;then rm -f $rpath/MOCK.mocksetup-lock lockfile -1 -r 1 -s 1 $rpath/MOCK.mocksetup-lock fi echo >&2 " done" if $soft && [ -f $rpath/MOCK ];then rm -f $rpath/MOCK.mocksetup-lock echo >&2 "Unlocked $rpath/MOCK.mocksetup-lock ." continue fi l="" b="" for p in /proc/*/root;do l="`readlink $p || :`" if [ "${l#/var/lib/mock/$r/}" != "$l" ];then p="${p#/proc/}" p="${p%/root}" b="$b $p" fi done if [ -n "$b" ];then echo >&2 "$rpath has existing processes: $b" rc=1 rm -f $rpath/MOCK.mocksetup-lock echo >&2 "Unlocked $rpath/MOCK.mocksetup-lock ." continue fi rm -f $rpath/MOCK # It fails on already mounted /proc. But we do not need it. # mock -q -r $r chroot true echo "$rpath lock check" for n in passwd group;do cat /etc/$n $rpath/etc/$n|perl -ne 'print if /^(?:[^:]*:){2}(10\d\d):/'|sort|uniq -u|tee -a $rpath/etc/$n done if [ ! -f $rpath/etc/mtab-orig ];then c="mv -f $rpath/etc/mtab $rpath/etc/mtab-orig" echo $c; $c c="ln -s /proc/mounts $rpath/etc/mtab" echo $c; $c fi cp -p /etc/resolv.conf $rpath/etc/resolv.conf dir="/dev/pts" c="umount $rpath$dir" if $c 2>&1|grep -v ': not \(mounted\|found\)$';then echo $c fi dir="/dev/shm" c="umount $rpath$dir" if $c 2>&1|grep -v ': not \(mounted\|found\)$';then echo $c fi test -e $rpath/dev/pts && rmdir $rpath/dev/pts if ! $u;then mkdir -p $rpath/dev/pts fi test -e $rpath/dev/shm && rmdir $rpath/dev/shm if ! $u;then mkdir -p $rpath/dev/shm fi rm -f $rpath/dev/null if ! $u;then mknod -m 666 $rpath/dev/null c 1 3 fi rm -f $rpath/dev/full if ! $u;then mknod -m 666 $rpath/dev/full c 1 7 fi rm -f $rpath/dev/zero if ! $u;then mknod -m 666 $rpath/dev/zero c 1 5 fi rm -f $rpath/dev/random if ! $u;then mknod -m 666 $rpath/dev/random c 1 8 fi rm -f $rpath/dev/urandom if ! $u;then mknod -m 444 $rpath/dev/urandom c 1 9 fi rm -f $rpath/dev/tty if ! $u;then mknod -m 666 $rpath/dev/tty c 5 0 fi rm -f $rpath/dev/console if ! $u;then mknod -m 600 $rpath/dev/console c 5 1 fi rm -f $rpath/dev/ptmx if ! $u;then mknod -m 666 $rpath/dev/ptmx c 5 2 fi rm -f $rpath/dev/stdin if ! $u;then ln -s /proc/self/fd/0 $rpath/dev/stdin fi rm -f $rpath/dev/stdout if ! $u;then ln -s /proc/self/fd/1 $rpath/dev/stdout fi rm -f $rpath/dev/stderr if ! $u;then ln -s /proc/self/fd/2 $rpath/dev/stderr fi rm -f $rpath/dev/fd if ! $u;then ln -s /proc/self/fd $rpath/dev/fd fi mkdir -p $rpath/unsafe for dir in /home /usr/local/bin /proc /sys /root /unsafe;do c="umount $rpath$dir" if $c 2>&1|grep -v ': not mounted$';then echo $c fi if ! $u;then c="mount --bind $dir $rpath$dir" echo $c; $c fi done if ! $u;then c="mount -t tmpfs mock_shmfs $rpath/dev/shm" echo $c; $c c="mount -t devpts -o mode=620,gid=5 mock_devpts $rpath/dev/pts" echo $c; $c fi c="umount $rpath/var/cache/yum" if $c 2>&1|grep -v ': not mounted$';then echo $c fi if ! $u;then if [ -d /var/cache/mock/$r/yum_cache ];then cr=$r else cr=`echo $r|sed 's/-[^-]*$//'` fi c="mount --bind /var/cache/mock/$cr/yum_cache $rpath/var/cache/yum" echo $c; $c fi rm -f $rpath/usr/local/lib/debug if ! $u;then ln -s ../../lib/debug $rpath/usr/local/lib/debug fi rm -f $rpath/usr/local/src/debug if ! $u;then ln -s ../../src/debug $rpath/usr/local/src/debug fi rm -f $rpath/usr/local/share/gdb if ! $u;then mkdir -p $rpath/usr/local/share ln -s ../../share/gdb $rpath/usr/local/share/gdb fi # Old systems incl. RHEL-6 do not feature it. if [ -d $rpath/etc/sudoers.d ];then rm -f $rpath/etc/sudoers.d/inteltest if ! $u;then : # ln /etc/sudoers.d/inteltest $rpath/etc/sudoers.d/inteltest fi fi if ! $u;then echo $r >$rpath/MOCK fi rm -f $rpath/MOCK.mocksetup-lock echo >&2 "Unlocked $rpath/MOCK.mocksetup-lock ." done trap 'echo >&2 done' EXIT exit $rc