summaryrefslogtreecommitdiff
path: root/network/netqmail/tests/makechroot
blob: 06435ef2d3d2555376102d6ed63642497a487a48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/sh
#set -x

# A function to make a file local (not hard-linked to the real file)
# One should run this on any file that the test might modify
make_local()
{
  while [ $# -gt 0 ]
  do
    cp -a $CHROOT/$1 $CHROOT/$1.new
    mv $CHROOT/$1.new $CHROOT/$1
    shift
  done
}

CHROOT=${CHROOT:-/tmp/t5}
VERBOSE_ADDCHROOT=${VERBOSE_ADDCHROOT:-true}
export VERBOSE_ADDCHROOT
PKGDIR=${PKGDIR:-/usr/packages}
[ -n "$MKCHROOT_IGNORE_LN_ERRORS" ] && LNE='2>/dev/null' || LNE=

# These are options
INSTALL_DAEMONTOOLS=${INSTALL_DAEMONTOOLS:-no}
STRIP_INITTAB_SV=${STRIP_INITTAB_SV:-yes}
STRIP_QMAIL_USERS_GROUPS=${STRIP_QMAIL_USERS_GROUPS:-yes}

[ ! -d $CHROOT/proc/1 ] || umount $CHROOT/proc
rm -rf $CHROOT
mkchroot $CHROOT
addchroot $CHROOT tar pkgtools
mkdir -p $CHROOT$PKGDIR
eval ln $PKGDIR/netqmail* $PKGDIR/daemontools* $CHROOT$PKGDIR $LNE \|\| \
  cp -a $PKGDIR/netqmail* $PKGDIR/daemontools* $CHROOT$PKGDIR
addchroot $CHROOT ucspi-tcp mkchroot

# Set up Slackware install DB for mkchroot
for i in packages scripts
do
  mkdir $CHROOT/var/log/$i
  (cd /var/log/$i; ls -1 | while read j; do [ -d $j ] ||
    eval ln $j $CHROOT/var/log/$i $LNE \|\| cp -a $j $CHROOT/var/log/$i; done)
done

addchroot $CHROOT etc
make_local etc/{group,gshadow,passwd,shadow}
addchroot $CHROOT sysvinit
addchroot $CHROOT sysvinit-scripts
make_local etc/inittab
[ $STRIP_INITTAB_SV != yes ] ||
{
  cat $CHROOT/etc/inittab | grep -E -v '^SV:' >$CHROOT/etc/inittab.new
  mv $CHROOT/etc/inittab.new $CHROOT/etc/inittab
}
addchroot $CHROOT sed util-linux gzip network-scripts shadow ncurses
mkdir $CHROOT/root $CHROOT/proc
[ $INSTALL_DAEMONTOOLS = no ] || addchroot $CHROOT daemontools

[ $STRIP_QMAIL_USERS_GROUPS != yes ] ||
{
  mount -tproc proc $CHROOT/proc
  
  for i in alias qmail{d,l,p,q,r,s}
  do
    grep -q ^$i: $CHROOT/etc/passwd && chroot $CHROOT userdel $i
  done
  for i in nofiles qmail
  do
    grep -q ^$i: $CHROOT/etc/group && chroot $CHROOT groupdel $i
  done
  umount $CHROOT/proc
}

# inst_check needs these
addchroot $CHROOT procps-ng gawk net-tools