summaryrefslogtreecommitdiffstats
path: root/scripts/scrubtree
blob: 16f445c4a4e3de728794f81bffea19dfd1c525a5 (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
75
76
77
78
79
80
81
82
#!/bin/bash
#
# scrubtree
#
# Copyright (C) 2007  Red Hat, Inc.  All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

DEBUG=""

if [ "$1" == "--debug" ]; then
    DEBUG="--debug"
    shift
fi

if [ -z "$1" ]; then
    echo "Usage: $0 /path/to/tree"
    exit 1
fi

p=$1

ARCH=`uname -m | sed -e 's/i.86/i386/'`

if [ $ARCH = x86_64 -o $ARCH = s390x ]; then
    LIBDIR=lib64
else
    LIBDIR=lib
fi

# Must create ld.so.conf, because ldconfig does not cache
# dirs specified on the command line.
touch $p/etc/ld.so.conf
mkdir $p/proc
mount -t proc proc $p/proc
echo /usr/kerberos/$LIBDIR > $p/etc/ld.so.conf
(cd $p; /usr/sbin/chroot $p usr/sbin/ldconfig )

if [ $ARCH != s390 -a $ARCH != s390x ]; then
    rm -f $p/usr/sbin/ldconfig 
fi
rm $p/etc/ld.so.conf

#
# make sure we have links for programs supplied by busybox
#
# HOWEVER dont clobber existing programs supplied by other packages if exist
#
mv $p/usr/sbin/busybox.anaconda $p/usr/bin/busybox
(cd $p/usr/bin;
set $(./busybox 2>&1| awk '/^\t([[:alnum:]\-_\.\[]+,)+/' | sed 's/,//g' | sed 's/ +//');
dontclobber=(sh busybox reboot shutdown poweroff)
while [ -n "$1" ]; do
    save=
    for n in ${dontclobber[@]} ; do
	if [ "$1" == "$n" ]; then
	    save=$n
	fi
    done
    # if it's not in our list and it doesn't exist, link to busybox
    if [ -z "$save" -a ! -f "$1" -a ! -f "$p/usr/sbin/$1" ]; then
	ln -sf ./busybox $1
    else
	[ -n "$DEBUG" ] && echo "Overriding busybox version of $1"
    fi
    shift
done
)

umount $p/proc