]> git.sur5r.net Git - bacula/rescue/blob - rescue/linux/cdrom/makebinaries
Add new mkcdrec code
[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 $R/bin
15 mkdir -p $R/cdrom
16 mkdir -p $R/etc $R/initrd $R/lib $R/mnt $R/mnt/cdrom
17 mkdir -p $R/proc $R/root $R/sbin $R/tmp $R/var $R/usr
18 mkdir -p $R/dev $R/sys $R/initrd $R/sysroot
19 mkdir -p $R/etc/terminfo $R/etc/terminfo/l
20 mkdir -p $R/var/lib $R/var/log $R/var/run $R/var/state
21 mkdir -p $R/var/lib/nfs 
22 mkdir -p $R/var/log/news
23 touch $R/var/log/news/news.crit $R/var/log/news/news.err $R/var/log/news.notice
24
25 cd $R
26 ln -sf sbin bin
27 cd usr
28 ln -sf ../sbin sbin
29 cd $TOPDIR
30
31 #
32 # Some users have a different shell for root, so be
33 #  sure to add it to the rootsbin list. Note, the shell may
34 #  be copied twice, but it is not worth the effort to run uniq
35 #  here.
36 #
37 TMPFILE=`mktemp -t bin.XXXXXXXXXX`
38 if [ $? !=  0 ]; then
39    echo "Could not make temp file"
40    exit 1
41 fi
42 cat rootsbin.list >${TMPFILE}
43 # Try to find the shell program for root
44 command=`grep ^root: /etc/passwd | cut -d ':' -f 7`
45 command=`basename $command`
46 if [ x$command != "xbash" ] ; then
47    echo "roottree/sbin/$command" >>${TMPFILE}
48 fi
49
50 echo "Building root /sbin. Some Could not find messages are normal ..."
51 for file in `cat ${TMPFILE}` ; do
52     command=`basename $file`
53     fullfile=`which $command 2> /dev/null`
54     if [ x$fullfile != x ] ; then
55 #       echo "updating $command in roottree with $fullfile"
56         cp -fp  $fullfile $file
57         if [ $? != 0 ] ; then
58            echo "Update failed."
59            exit 1
60         fi
61         strip $file 2>/dev/null
62     else
63         echo "==== Could not find $command on your system ===="
64         rm -f $file
65     fi
66 done
67 rm -f ${TMPFILE}
68
69 cd roottree/sbin
70 ln -sf halt reboot
71 # Eliminate recursive link
72 rm -f sbin
73 cd $TOPDIR
74
75 # Copy all needed shared libraries
76 echo "Building root shared libaries ..."
77 rm -f `find roottree/lib/ -maxdepth 1 -type f 2>/dev/null`
78 #
79 # Statically linked binaries create an error
80 # message from ldd, so we ignore those
81 #
82 for lib in `find roottree/sbin/ -type f -exec ldd {} \; | awk '{print $3}' | sort | uniq` ; do
83   if [ -e $lib ] ; then
84      cp -fp $lib roottree/lib/
85      if [ $? != 0 ] ; then
86         echo "Update failed."
87         exit 1
88      fi
89   fi
90 done
91 #
92 # Wouldn't you know, there is one so that is critical to have or
93 #  nothing will load on 2.6 kernels.
94 #
95 cp -fp /lib/ld-linux.so.* roottree/lib/
96 strip `find roottree/lib/ -maxdepth 1 -type f` 2>/dev/null
97
98 # Grab grub RedHat
99 if [ -d /usr/share/grub ] ; then
100    mkdir -p roottree/usr/share/grub
101    cp -fpR /usr/share/grub/* roottree/usr/share/grub
102 elif [ -d /lib/grub ] ; then
103    mkdir -p roottree/lib/grub
104    cp -fpR /lib/grub/* roottree/lib/grub
105 elif [ -d /usr/lib/grub ] ; then
106    mkdir -p roottree/usr/lib/grub
107    cp -fpR /usr/lib/grub* roottree/usr/lib/grub
108 else
109    echo "======= Warning could not find grub scripts ========"
110 fi
111
112 if [ -d /lib/udev ] ; then
113    rm -rf $R/lib/udev
114    cp -fpR /lib/udev $R/lib/
115 fi
116
117 #
118 # Get a bunch of stuff from /etc
119 #
120 echo "Building /etc ..."
121 # SuSE 10.1
122 if [ -f /etc/rc.status ]; then
123    cp -fp /etc/rc.status $R/etc/
124 fi
125 # copy the whole sysconfig directory
126 if [ -d /etc/sysconfig ]; then
127    rm -rf $R/etc/sysconfig
128    cp -fpR /etc/sysconfig/ $R/etc/
129 fi
130 # comment out HWADDR in any ifcfg-eth* file, otherwise ifconfig won't start
131 for i in `ls $R/etc/sysconfig/network*/ifcfg-eth*`
132 do
133   grep ^HWADDR $i >/dev/null 2>&1
134   if [ $? -eq 0 ]; then
135      sed -e 's/HWADDR/#HWADDR/' < $i > /tmp/temp.$$
136      mv -f /tmp/temp.$$ $i
137   fi
138 done
139
140 if [ -d /etc/syslog-ng ] ; then
141    cp -fpR /etc/syslog-ng/ $R/etc/
142 fi
143
144 cp -p /etc/services roottree/etc/
145 if [ $? != 0 ] ; then
146    echo "Update failed."
147    exit 1
148 fi
149
150 for file in `cat rootetc.list` ; do
151    if [ -f $file ] ; then
152       cp -fp $file roottree/etc/
153    else
154       echo "==== Could not find $file in /etc ===="
155    fi
156 done
157
158 # RedHat has a non-standard rc.d/init.d layout
159 if [ -d /etc/rc.d/init.d ]; then
160    cp -a /etc/rc.d/ $R/etc/
161    (cd $R/etc; ln -sf rc.d init.d)
162    rcdtarget=$R/etc/rc.d
163 elif [ -d /etc/init.d ]; then
164    cp -a /etc/init.d/ $R/etc/
165    (cd $R/etc; ln -sf init.d rc.d)
166    rcdtarget=$R/etc/init.d
167 fi
168 cp -f $R/etc/rc ${rcdtarget}/
169 cp -a ${MKCDREC_DIR}/etc/rc.d/*  ${rcdtarget}
170 cat /dev/null > $R/etc/rc.d/rc.inits
171 chmod +x $R/etc/rc.d/rc.inits
172 touch $R/etc/rc.d/rc.local
173
174 if [ -f /etc/modules.conf ] ; then
175    cp -fp /etc/modules.conf roottree/etc/
176 fi
177 if [ -f /etc/modprobe.conf ] ; then
178    cp -fp /etc/modprobe.conf roottree/etc/
179 fi
180 if [ -f /etc/modprobe.conf.local ] ; then
181    cp -fp /etc/modprobe.conf.local roottree/etc/
182 fi
183 if [ -d /etc/modprobe.d ] ; then
184    cp -a /etc/modprobe.d roottree/etc/
185 fi
186
187 rm -rf roottree/etc/pam.d
188 if [ -d /etc/pam.d ] ; then
189    cp -a /etc/pam.d roottree/etc/
190    if [ -e /etc/pam.conf ] ; then
191       cp -fp /etc/pam.conf roottree/etc/
192    fi
193 fi
194
195 if [ -d /etc/hotplug ] ; then
196    cp -a /etc/hotplug $R/etc
197 fi
198 if [ -d /etc/hotplug.d ] ; then
199    cp -a /etc/hotplug.d $R/etc
200 fi
201 if [ -d /etc/udev ]; then
202    cp -a /etc/udev $R/etc
203 fi
204 if [ -d /etc/dev.d ]; then
205    cp -a /etc/dev.d $R/etc
206 fi                  
207
208
209 if [ -f /etc/rc.status ] ; then
210    cp -fp /etc/rc.status roottree/etc/
211 fi
212
213
214 if [ -e /etc/ssh ] ; then
215    cp -a /etc/ssh roottree/etc/
216    echo "====================================================="
217    echo "====                                             ===="
218    echo "==== Warning your /etc/ssh directory was copied. ===="
219    echo "==== Keep this directory and the CDROM secure.   ===="
220    echo "====                                             ===="
221    echo "====================================================="
222 fi
223 if [ -e /etc/security ] ; then
224   cp -a /etc/security roottree/etc/
225 fi
226
227 #
228 # Pull a few files needed by PAM
229 #
230 if [ -f /lib/libnss_files.so.1 ] ; then
231   cp -fp /lib/libnss_files.so.1 roottree/lib/
232 fi
233 cp -fp /lib/libnss_files.so.* roottree/lib/
234 cp -a /lib/security roottree/lib/