Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / examples / chroot-setup / LINUX2
blobf9c6184d8e987908ffcef3977c6f92413ec5447e
1 #! /bin/sh
3 # LINUX2 - shell script to set up a Postfix chroot jail for Linux
4 # Tested on SuSE Linux 5.3 (libc5) and 7.0 (glibc2.1)
6 # Other testers reported as working:
8 # 2001-01-15 Debian sid (unstable)
9 # Christian Kurz <shorty@getuid.de>
11 # Copyright (c) 2000 - 2001 by Matthias Andree
12 # Redistributable unter the MIT-style license that follows:
13 # Abstract: "do whatever you want except hold somebody liable or change
14 # the copyright information".
16 # Permission is hereby granted, free of charge, to any person obtaining a copy
17 # of this software and associated documentation files (the "Software"), to
18 # deal in the Software without restriction, including without limitation the
19 # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
20 # sell copies of the Software, and to permit persons to whom the Software is
21 # furnished to do so, subject to the following conditions:
23 # The above copyright notice and this permission notice shall be included in
24 # all copies or substantial portions of the Software.
26 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
31 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
32 # IN THE SOFTWARE.
34 # 2000-09-29
35 # v0.1: initial release
37 # 2000-12-05
38 # v0.2: copy libdb.* for libnss_db.so
39 # remove /etc/localtime in case it's a broken symlink
40 # restrict find to maxdepth 1 (faster)
42 # Revision 1.4 2001/01/15 09:36:35 emma
43 # add note it was successfully tested on Debian sid
45 # 20060101 /lib64 support by Keith Owens.
48 CP="cp -p"
50 cond_copy() {
51 # find files as per pattern in $1
52 # if any, copy to directory $2
53 dir=`dirname "$1"`
54 pat=`basename "$1"`
55 lr=`find "$dir" -maxdepth 1 -name "$pat"`
56 if test ! -d "$2" ; then exit 1 ; fi
57 if test "x$lr" != "x" ; then $CP $1 "$2" ; fi
60 set -e
61 umask 022
63 POSTFIX_DIR=${POSTFIX_DIR-/var/spool/postfix}
64 cd ${POSTFIX_DIR}
66 mkdir -p etc lib usr/lib/zoneinfo
67 test -d /lib64 && mkdir -p lib64
69 # find localtime (SuSE 5.3 does not have /etc/localtime)
70 lt=/etc/localtime
71 if test ! -f $lt ; then lt=/usr/lib/zoneinfo/localtime ; fi
72 if test ! -f $lt ; then lt=/usr/share/zoneinfo/localtime ; fi
73 if test ! -f $lt ; then echo "cannot find localtime" ; exit 1 ; fi
74 rm -f etc/localtime
76 # copy localtime and some other system files into the chroot's etc
77 $CP -f $lt /etc/services /etc/resolv.conf /etc/nsswitch.conf etc
78 $CP -f /etc/host.conf /etc/hosts /etc/passwd etc
79 ln -s -f /etc/localtime usr/lib/zoneinfo
81 # copy required libraries into the chroot
82 cond_copy '/lib/libnss_*.so*' lib
83 cond_copy '/lib/libresolv.so*' lib
84 cond_copy '/lib/libdb.so*' lib
85 if test -d /lib64; then
86 cond_copy '/lib64/libnss_*.so*' lib64
87 cond_copy '/lib64/libresolv.so*' lib64
88 cond_copy '/lib64/libdb.so*' lib64
91 postfix reload