4 if [ "$1" = "-u" ];then
10 # Do not rebuild the tree if it looks as already setup.
11 if [ "$1" = "-s" ];then
17 if [ "$1" = "-h" ];then
18 echo >&2 "$0 [/var/lib/mock/]<ROOTNAME>..."
22 l="`echo /var/lib/mock/*`"
27 trap 'echo >&2 FATAL ERROR' EXIT
30 r="`echo "$r"|tr -s /`"
31 r="${r#/var/lib/mock/}"
33 rpath="/var/lib/mock/$r/root"
34 if [ ! -d "$rpath" ];then
35 echo >&2 "$rpath does not exist"
39 echo >&2 -n "Locking $rpath/MOCK.mocksetup-lock ..."
40 if ! lockfile -1 -r 1 -s 1 $rpath/MOCK.mocksetup-lock;then
41 rm -f $rpath/MOCK.mocksetup-lock
42 lockfile -1 -r 1 -s 1 $rpath/MOCK.mocksetup-lock
46 if $soft && [ -f $rpath/MOCK ];then
47 rm -f $rpath/MOCK.mocksetup-lock
48 echo >&2 "Unlocked $rpath/MOCK.mocksetup-lock ."
54 for p in /proc/*/root;do
55 l="`readlink $p || :`"
56 if [ "${l#/var/lib/mock/$r/}" != "$l" ];then
63 echo >&2 "$rpath has existing processes: $b"
65 rm -f $rpath/MOCK.mocksetup-lock
66 echo >&2 "Unlocked $rpath/MOCK.mocksetup-lock ."
72 # It fails on already mounted /proc. But we do not need it.
73 # mock -q -r $r chroot true echo "$rpath lock check"
75 for n in passwd group;do
76 cat /etc/$n $rpath/etc/$n|perl -ne 'print if /^(?:[^:]*:){2}(10\d\d):/'|sort|uniq -u|tee -a $rpath/etc/$n
78 if [ ! -f $rpath/etc/mtab-orig ];then
79 c="mv -f $rpath/etc/mtab $rpath/etc/mtab-orig"
81 c="ln -s /proc/mounts $rpath/etc/mtab"
85 cmp -s /etc/resolv.conf $rpath/etc/resolv.conf \
86 || cp -p /etc/resolv.conf $rpath/etc/resolv.conf
90 if $c 2>&1|grep -v ': not \(mounted\|found\)$';then
96 if $c 2>&1|grep -v ': not \(mounted\|found\)$';then
100 test -e $rpath/dev/pts && (rmdir $rpath/dev/pts || :)
102 mkdir -p $rpath/dev/pts
104 test -e $rpath/dev/shm && (rmdir $rpath/dev/shm || :)
106 mkdir -p $rpath/dev/shm
108 rm -f $rpath/dev/null
110 mknod -m 666 $rpath/dev/null c 1 3
112 rm -f $rpath/dev/full
114 mknod -m 666 $rpath/dev/full c 1 7
116 rm -f $rpath/dev/zero
118 mknod -m 666 $rpath/dev/zero c 1 5
120 rm -f $rpath/dev/random
122 mknod -m 666 $rpath/dev/random c 1 8
124 rm -f $rpath/dev/urandom
126 mknod -m 444 $rpath/dev/urandom c 1 9
130 mknod -m 666 $rpath/dev/tty c 5 0
132 rm -f $rpath/dev/console
134 mknod -m 600 $rpath/dev/console c 5 1
136 rm -f $rpath/dev/ptmx
138 mknod -m 666 $rpath/dev/ptmx c 5 2
140 rm -f $rpath/dev/stdin
142 ln -s /proc/self/fd/0 $rpath/dev/stdin
144 rm -f $rpath/dev/stdout
146 ln -s /proc/self/fd/1 $rpath/dev/stdout
148 rm -f $rpath/dev/stderr
150 ln -s /proc/self/fd/2 $rpath/dev/stderr
154 ln -s /proc/self/fd $rpath/dev/fd
157 # Must be before umount of /quad
158 for cache in yum dnf;do
159 c="umount $rpath/var/cache/$cache"
160 if $c 2>&1|grep -v ': not \(mounted\|found\)$';then
164 if [ -d /var/cache/mock/$r/${cache}_cache ];then
167 cr=`echo $r|sed 's/-[^-]*$//'`
169 if [ -d /var/cache/mock/$cr/${cache}_cache ];then
170 c="mount --bind /var/cache/mock/$cr/${cache}_cache $rpath/var/cache/${cache}"
177 for dir in /home /usr/local/bin /proc /sys /root /quad;do
178 c="umount $rpath$dir"
179 if $c 2>&1|grep -v ': not \(mounted\|found\)$';then
183 c="mount --bind $dir $rpath$dir"
189 c="mount -t tmpfs mock_shmfs $rpath/dev/shm"
191 c="mount -t devpts -o mode=620,gid=5 mock_devpts $rpath/dev/pts"
195 rm -f $rpath/usr/local/lib/debug
197 ln -s ../../lib/debug $rpath/usr/local/lib/debug
200 rm -f $rpath/usr/local/src/debug
202 ln -s ../../src/debug $rpath/usr/local/src/debug
205 rm -f $rpath/usr/local/share/gdb
207 mkdir -p $rpath/usr/local/share
208 ln -s ../../share/gdb $rpath/usr/local/share/gdb
211 # Old systems incl. RHEL-6 do not feature it.
212 if [ -d $rpath/etc/sudoers.d ];then
213 rm -f $rpath/etc/sudoers.d/inteltest
215 # ln /etc/sudoers.d/inteltest $rpath/etc/sudoers.d/inteltest
223 rm -f $rpath/MOCK.mocksetup-lock
224 echo >&2 "Unlocked $rpath/MOCK.mocksetup-lock ."
226 trap 'echo >&2 done' EXIT