initial commit: 1.5.0
[systemrescuecd.git] / mainfiles / fsscript.sh
1 #!/bin/bash
2
3 # This is an example fsscript for use with the livecd-stage2 target (key
4 # livecd/fsscript).  This file is copied into the rootfs of the CD after the
5 # kernel(s) and any external modules have been compiled and is then executed
6 # within the context of the chroot.
7
8 # define hostname
9 rm -f /etc/conf.d/hostname
10 echo "HOSTNAME=sysresccd" > /etc/conf.d/hostname
11 sed -i -e 's/livecd/sysresccd/g' /etc/hosts
12
13 # clean the resolv.conf file ("dig . ns" to get list of root DNS)
14 echo "nameserver 8.8.8.8" > /etc/resolv.conf
15
16 # change the default shell
17 chsh -s /bin/zsh root
18
19 # remove .svn files
20 #find / -name ".svn" -exec rm -rf {} \; >/dev/null 2>&1
21
22 # Remove python precompiled files
23 find /usr/lib -name "*.py?" -exec rm -f {} \; >/dev/null 2>&1
24
25 # remove warning from clock service
26 sed -i -e 's:#TIMEZONE="Factory":TIMEZONE="Europe/London":g' /etc/conf.d/clock
27
28 # remove warning from freshclam when clamd not running
29 sed -i -e 's:NotifyClamd:#NotifyClamd:' /etc/freshclam.conf
30
31 # disable DHCP by default in autoconfig
32 sed -i -e 's/ewarn "Skipping DHCP broadcast detection as requested on boot commandline ..."//' /etc/init.d/autoconfig
33 sed -i -e 's/DHCP="yes"/DHCP="no"/' /etc/init.d/autoconfig
34
35 # running hwsetup disturbs the speakup, so run "hwsetup -f" when speakup is used
36 sed -i -e 's!\[ -x /usr/sbin/hwsetup \] && hwsetup!cat /proc/cmdline | grep -qF "speakup=" \&\& speakupopt=" -f" ; \[ -x /usr/sbin/hwsetup \] \&\& hwsetup ${speakupopt}!g' /etc/init.d/autoconfig
37
38 # disable netplug
39 sed -i -e 's/"netplugd"//' /etc/init.d/net.lo
40
41 # make ssh-keygen silent in the sshd initscript
42 sed -i -e 's!/usr/bin/ssh-keygen!/usr/bin/ssh-keygen -q!g' /etc/init.d/sshd
43
44 # disable ALSA sound by default in autoconfig
45 sed -i -e 's/GPM="yes"/GPM="no"/' /etc/init.d/autoconfig
46 sed -i -e 's/ALSA="yes"/ALSA="no"/' /etc/init.d/autoconfig
47 sed -i -e 's/NFS="yes"/NFS="no"/' /etc/init.d/autoconfig
48 sed -i -e 's/PCMCIA="yes"/PCMCIA="no"/' /etc/init.d/autoconfig
49 sed -i -e 's/Skipping ALSA detection as requested on command line .../Skipping ALSA detection .../' /etc/init.d/autoconfig
50
51 # /etc/udev/rules.d/75-persistent-net-generator.rules conflicts with the sysresccd "nameif=xxx" option
52 #sed -i -e 's!^ENV{INTERFACE_NEW}!#ENV{INTERFACE_NEW}!g' /etc/udev/rules.d/75-persistent-net-generator.rules
53
54 # /sbin/livecd-functions.sh expect 'cdroot' in /proc/cmdline (we removed cdroot)
55 sed -i -e 's!for x in ${CMDLINE}!for x in ${CMDLINE} cdroot!g' /sbin/livecd-functions.sh
56
57 # allow freshclam
58 chown clamav:clamav /var/log/clamav
59 chown clamav:clamav /var/run/clamav
60 chown clamav:clamav /var/lib/clamav
61 chown clamav:clamav /var/lib/clamav/*
62
63 # remove warnings about files with a modification time in the future!
64 sed -i -e 's!if \[\[ ${clock_screw} == 1 \]\]!if \[\[ ${clock_screw} == 2 \]\]!g' /etc/init.d/depscan.sh
65 sed -i -e 's!if \[\[ ${clock_screw} == 1 \]\]!if \[\[ ${clock_screw} == 2 \]\]!g' /sbin/depscan.sh
66
67 # don't overwrite /proc/sys/kernel/printk in /etc/init.d/autoconfig
68 # http://www.sysresccd.org/forums/viewtopic.php?p=5800
69 sed -i -r -e 's!echo "[0-9]" > /proc/sys/kernel/printk!!g' /etc/init.d/autoconfig
70
71 # fix /sbin/livecd-functions.sh that fixes inittab
72 # http://www.sysresccd.org/forums/viewtopic.php?t=2040&postdays=0&postorder=asc&start=15
73 sed -i -e 's!s0:12345:respawn:/sbin/agetty -nl /bin/bashlogin!s0:12345:respawn:/sbin/agetty -L -nl /bin/bashlogin!g' /sbin/livecd-functions.sh
74
75 # prevent the firmware extraction from displaying warnings when the clock is wrong
76 sed -i -e 's!tar xjf /lib/firmware.tar.bz2!tar xjfm /lib/firmware.tar.bz2!g' /etc/init.d/autoconfig
77
78 # fix a bug in the default mtools configuration file
79 sed -i -e 's!SAMPLE FILE!#SAMPLE FILE!g' /etc/mtools/mtools.conf
80
81 # don't use fbdev as the default xorg driver since framebuffer is disabled
82 sed -i -e 's![ -z "${XMODULE}" ] && XMODULE="fbdev"![ -z "${XMODULE}" ] && XMODULE="vesa"!g' /usr/sbin/mkxf86config.sh
83
84 # prevent sshd from complaining
85 touch /var/log/lastlog
86
87 # preserve the 'ar' and 'strings' binaries from the binutils package (and its libs)
88 cp -a /usr/i486-pc-linux-gnu/binutils-bin/*/ar /usr/sbin/
89 cp -a /usr/i486-pc-linux-gnu/binutils-bin/*/strings /usr/sbin/
90 cp -a /usr/lib/binutils/i486-pc-linux-gnu/*/libbfd*.so /usr/lib/
91
92 # provide a symblink to libstdc++.so.6 so that we can install all packages
93 ln -s /lib/lib/gcc/i486-pc-linux-gnu/*/libstdc++.so.6 /usr/lib/libstdc++.so.6
94
95 # replace the strings-static binary (provided by app-forensics/chkrootkit) to save splace
96 rm -f /usr/sbin/strings-static ; ln -s /usr/sbin/strings /usr/sbin/strings-static
97
98 # make space by removing the redundant insmod.static binary
99 rm -f /sbin/insmod.static ; ln -s /sbin/insmod /sbin/insmod.static
100
101 # remove rdev-rebuild temp files
102 rm -f /var/cache/revdep-rebuild/*
103
104 # manage mksquashfs/unsquashfs programs
105 [ ! -f /usr/bin/mksquashfs-lzma ] && ln -s /usr/bin/mksquashfs /usr/bin/mksquashfs-lzma
106 [ ! -f /usr/bin/unsquashfs-lzma ] && ln -s /usr/bin/unsquashfs /usr/bin/unsquashfs-lzma
107
108 # create link for reiserfsck
109 [ ! -f /sbin/fsck.reiserfs ] && ln /sbin/reiserfsck /sbin/fsck.reiserfs
110
111 # prevent the /etc/init.d/net.eth* from being run --> they break the network (done via "ethx, dns, gateway")
112 rm -f /etc/init.d/net.eth*
113
114 # remove xfce icons for missing programs
115 rm -f /usr/share/applications/{xfce4-file-manager.desktop,xfce4-help.desktop}
116
117 # fix the "xfce4-logout" entry in the menu
118 sed -i -e 's!xfce4-session-logout!killall xinit!g' /usr/share/applications/xfce4-logout.desktop
119
120 # decompress oscar files
121 if [ -f /usr/share/oscar/oscar.tar.gz ]
122 then
123         tar xfzp /usr/share/oscar/oscar.tar.gz -C /usr/share/oscar
124         rm -rf /usr/share/oscar/oscar.tar.gz
125 fi
126
127 # prepare the runxserver script
128 rm -f /usr/bin/X
129 ln -s /root/runxserver /usr/bin/X
130
131 # for programs that expect syslog
132 ln -s /usr/sbin/syslog-ng /usr/sbin/syslog
133
134 # install the 32bits kernel modules
135 for modtar in /lib/modules/*.tar.bz2
136 do
137         echo '--------------------------------------------------------------'
138         kerver=$(basename $modtar | sed -e 's/.tar.bz2//')
139         echo "DECOMPRESS32 (version [$kerver]): tar xfjp $modtar -C /lib/modules/"
140         tar xfjp $modtar -C /lib/modules/
141         echo "DEPMOD32: depmod -ae -v $kerver"
142         depmod -ae -v $kerver > /dev/null
143         rm -f $modtar
144         echo '--------------------------------------------------------------'
145 done
146
147 # install the 64bits kernel modules
148 for modtar in /lib64/modules/*.tar.bz2
149 do
150         echo '--------------------------------------------------------------'
151         kerver=$(basename $modtar | sed -e 's/.tar.bz2//')
152         echo "DECOMPRESS64 (version [$kerver]): tar xfjp $modtar -C /lib64/modules/"
153         tar xfjp $modtar -C /lib64/modules/
154         echo "LINK64: ln -s /lib64/modules/$kerver /lib/modules/$kerver"
155         ln -s /lib64/modules/$kerver /lib/modules/$kerver
156         echo "DEPMOD64: depmod -ae -v $kerver"
157         depmod -ae -v $kerver > /dev/null
158         rm -f $modtar
159         echo '--------------------------------------------------------------'
160 done
161
162 # workaround for new libexpat version
163 [ -h /usr/lib/libexpat.so.0 ] || ln -s /usr/lib/libexpat.so /usr/lib/libexpat.so.0
164
165 # strip kernel modules which are in the sysrcd.dat to save space
166 find /lib/modules -name "*.ko" -exec strip --strip-unneeded '{}' \;
167 find /lib64/modules -name "*.ko" -exec strip --strip-unneeded '{}' \;
168
169 # update /etc/make.profile
170 rm -rf /etc/make.profile
171 ln -s ../usr/portage/profiles/default/linux/x86/10.0 /etc/make.profile
172
173 # update the database for locate
174 echo "--> locate -u"
175 locate -u >/dev/null 2>&1
176
177 # create the apropos / whatis database
178 echo "--> makewhatis"
179 makewhatis >/dev/null 2>&1
180
181 # create the locales:
182 localedef -i /usr/share/i18n/locales/en_US -f UTF-8 /usr/lib/locale/en_US.utf8
183 localedef -i /usr/share/i18n/locales/en_US -f ISO-8859-1 /usr/lib/locale/en_US
184 localedef -i /usr/share/i18n/locales/de_DE -f ISO-8859-1 /usr/lib/locale/de_DE
185 localedef -i /usr/share/i18n/locales/fr_FR -f ISO-8859-1 /usr/lib/locale/fr_FR
186