]> git.sur5r.net Git - bacula/rescue/blob - rescue/linux/cdrom/makebinaries
b0f78ea650b8c3382e913b3a8253a97c3445941f
[bacula/rescue] / rescue / linux / cdrom / makebinaries
1 #!/bin/sh
2
3 # this script finds all binaries and updates them with the ones 
4 # from your system, in order to maintain them more easily.
5 # Be careful. If you have specially made binaries (perhaps lean ones),
6 # they will be overwritten.
7
8 TOPDIR=`pwd`
9 R=roottree
10 PATH="/sbin:/bin:/usr/sbin:/usr/bin:$PATH"
11
12
13 # Cleanup and make necessary directories
14 rm -rf $R/sbin
15 mkdir -p $R/etc $R/initrd $R/lib $R/mnt $R/mnt/cdrom
16 mkdir -p $R/proc $R/root $R/sbin $R/tmp $R/var 
17 mkdir -p $R/dev $R/sys $R/initrd $R/sysroot
18 mkdir -p $R/etc/terminfo $R/etc/terminfo/l
19 mkdir -p $R/var/lib $R/var/log $R/var/run $R/var/state
20 mkdir -p $R/var/lib/nfs 
21 mkdir -p $R/var/log/news
22 touch $R/var/log/news/news.crit $R/var/log/news/news.err $R/var/log/news.notice
23
24 cd $R
25 ln -sf sbin bin
26 cd $TOPDIR
27
28 #
29 # Some users have a different shell for root, so be
30 #  sure to add it to the rootsbin list. Note, the shell may
31 #  be copied twice, but it is not worth the effort to run uniq
32 #  here.
33 #
34 TMPFILE=`mktemp -t bin.XXXXXXXXXX`
35 if [ $? !=  0 ]; then
36    echo "Could not make temp file"
37    exit 1
38 fi
39 cat rootsbin.list >${TMPFILE}
40 command=`grep ^root: /etc/passwd | cut -d ':' -f 7`
41 command=`basename $command`
42 if [ x$command != "xbash" ] ; then
43    echo "roottree/sbin/$command" >>${TMPFILE}
44 fi
45
46 echo "Building root /sbin. Some Could not find messages are normal ..."
47 for file in `cat ${TMPFILE}` ; do
48     command=`basename $file`
49     fullfile=`which $command 2> /dev/null`
50     if [ x$fullfile != x ] ; then
51 #       echo "updating $command in roottree with $fullfile"
52         cp -fpd $fullfile $file
53         if [ $? != 0 ] ; then
54            echo "Update failed."
55            exit 1
56         fi
57         strip $file 2>/dev/null
58     else
59         echo "==== Could not find $command on your system ===="
60         rm -f $file
61     fi
62 done
63 rm -f ${TMPFILE}
64
65 cd roottree/sbin
66 ln -sf halt reboot
67 # Eliminate recursive link
68 rm -f sbin
69 cd $TOPDIR
70
71 # Copy all needed shared libraries
72 echo "Building root shared libaries ..."
73 rm -f `find roottree/lib/ -maxdepth 1 -type f 2>/dev/null`
74 #
75 # Statically linked binaries create an error
76 # message from ldd, so we ignore those
77 #
78 for lib in `find roottree/sbin/ -type f -exec ldd {} \; | awk '{print $3}' | sort | uniq` ; do
79   if [ -e $lib ] ; then
80      cp -fp $lib roottree/lib/
81      if [ $? != 0 ] ; then
82         echo "Update failed."
83         exit 1
84      fi
85   fi
86 done
87 #
88 # Wouldn't you know, there is one so that is critical to have or
89 #  nothing will load on 2.6 kernels.
90 #
91 cp -fp /lib/ld-linux.so.* roottree/lib/
92 strip `find roottree/lib/ -maxdepth 1 -type f` 2>/dev/null
93
94 # Grab grub crap
95 if [ -e /usr/share/grub ] ; then
96    mkdir -p roottree/usr/share/grub
97    cp -fpr /usr/share/grub/* roottree/usr/share/grub
98 elif [ -e /lib/grub ] ; then
99    mkdir -p roottree/lib/grub
100    cp -fpr /lib/grub/* roottree/lib/grub
101 else
102    echo "======= Warning could not find grub scripts ========"
103 fi
104
105 #
106 # Get a bunch of stuff from /etc
107 #
108 echo "Building /etc ..."
109 cp -p /etc/services roottree/etc/
110 if [ $? != 0 ] ; then
111    echo "Update failed."
112    exit 1
113 fi
114
115 for file in `cat rootetc.list` ; do
116    if [ -e $file ] ; then
117       cp -fp $file roottree/etc/
118    else
119       echo "==== Could not find $file in /etc ===="
120    fi
121 done
122 if [ -e /etc/modules.conf ] ; then
123    cp -fp /etc/modules.conf roottree/etc/
124 fi
125 if [ -e /etc/modprobe.conf ] ; then
126    cp -fp /etc/modprobe.conf roottree/etc/
127 fi
128 rm -rf roottree/etc/pam.d
129 if [ -e /etc/pam.d ] ; then
130    cp -a /etc/pam.d roottree/etc/
131    if [ -e /etc/pam.conf ] ; then
132       cp -fp /etc/pam.conf roottree/etc/
133    fi
134 fi
135
136 if [ -e /etc/init.d ] ; then
137    rm -rf roottree/etc/init.d
138    cp -aL /etc/init.d roottree/etc/
139 fi
140
141 if [ -e /etc/udev ] ; then
142    rm -rf roottree/etc/udev
143    cp -aL /etc/udev roottree/etc/
144 fi
145
146
147 if [ -e /etc/ssh ] ; then
148    cp -a /etc/ssh roottree/etc/
149    echo "====================================================="
150    echo "====                                             ===="
151    echo "==== Warning your /etc/ssh directory was copied. ===="
152    echo "==== Keep this directory and the CDROM secure.   ===="
153    echo "====                                             ===="
154    echo "====================================================="
155 fi
156 if [ -e /etc/security ] ; then
157   cp -a /etc/security roottree/etc/
158 fi
159
160 #
161 # Pull a few files needed by PAM
162 #
163 if [ -f /lib/libnss_files.so.1 ] ; then
164   cp -fp /lib/libnss_files.so.1 roottree/lib/
165 fi
166 cp -fp /lib/libnss_files.so.* roottree/lib/
167 cp -a /lib/security roottree/lib/