Updated hostname/domainname creation for new baselayout.
[catalyst.git] / targets / support / livecdfs-update.sh
1 #!/bin/bash
2 # Copyright 1999-2004 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4 # $Header: /var/cvsroot/gentoo/src/catalyst/targets/support/livecdfs-update.sh,v 1.16 2005/06/22 13:29:13 wolf31o2 Exp $
5
6 . /tmp/chroot-functions.sh
7 update_env_settings
8
9 # allow root logins to the livecd by default
10 if [ -e /etc/sshd/sshd_config ]
11 then
12         sed -i 's:^#PermitRootLogin\ yes:PermitRootLogin\ yes:' /etc/ssh/sshd_config
13 fi
14
15 # turn off udev tarball
16 sed -i 's:RC_DEVICE_TARBALL="yes":RC_DEVICE_TARBALL="no":' /etc/conf.d/rc
17
18 # Do some livecd_type specific inittab changes
19 case ${clst_livecd_type} in
20         gnap)
21                 sed -i "s/^#c1:/c1:/" /etc/inittab
22                 sed -i "/^.*bashlogin.*$/ d" /etc/inittab
23         ;;
24 esac
25
26 # clean up the time and set to UTC
27 rm -rf /etc/localtime
28 cp /usr/share/zoneinfo/UTC /etc/localtime
29
30 # setup the hostname
31 if [ "${clst_livecd_type}" == "gentoo-gamecd" ]
32 then
33         echo 'HOSTNAME="gamecd"' > /etc/conf.d/hostname
34         echo "127.0.0.1 gamecd.gentoo gamecd localhost" > /etc/hosts
35 else
36         echo 'HOSTNAME="livecd"' > /etc/conf.d/hostname
37         echo "127.0.0.1 livecd.gentoo livecd localhost" > /etc/hosts
38 fi
39 echo 'OVERRIDE=0' > /etc/conf.d/domainname
40 echo 'DNSDOMAIN="gentoo"' >> /etc/conf.d/domainname
41
42 # Add any users
43 if [ -n "${clst_livecd_users}" ]
44 then
45         for x in ${clst_livecd_users}
46         do
47                 useradd -G users,wheel,audio,games,cdrom,usb -c "Default LiveCD User" -m $x
48         done
49 fi
50
51 # setup sudoers
52 if [ -f /etc/sudoers ]
53 then
54         sed -i '/NOPASSWD: ALL/ s/^# //' /etc/sudoers
55 fi
56
57 # we want the first user to be used when auto-starting X
58 if [ -n "${clst_livecd_users}" -a -e /etc/startx ]
59 then
60         first_user=$(echo ${clst_livecd_users} | cut -d' ' -f1)
61         sed -i "s/startx/su - $first_user -c startx/" /root/.bashrc
62 fi
63
64 # setup dhcp on all detected ethernet devices
65 echo "iface_eth0=\"dhcp\""> /etc/conf.d/net
66 echo "iface_eth1=\"dhcp\"" >> /etc/conf.d/net
67 echo "iface_eth2=\"dhcp\"" >> /etc/conf.d/net
68 echo "iface_eth3=\"dhcp\"" >> /etc/conf.d/net
69 echo "iface_eth4=\"dhcp\"" >> /etc/conf.d/net
70
71 # setup links for ethernet devices
72 cd /etc/init.d
73 ln -sf net.eth0 net.eth1
74 ln -sf net.eth0 net.eth2
75 ln -sf net.eth0 net.eth3
76 ln -sf net.eth0 net.eth4
77
78 # add this for hwsetup/mkx86config
79 mkdir -p /etc/sysconfig
80
81 # fstab tweaks
82 echo "tmpfs     /                                       tmpfs   defaults        0 0" > /etc/fstab
83 echo "tmpfs     /lib/firmware                   tmpfs   defaults        0 0" >> /etc/fstab
84 # if /usr/lib/X11/xkb/compiled then make it tmpfs
85 if [ -d /usr/lib/X11/xkb/compiled ]
86 then
87         echo "tmpfs     /usr/lib/X11/xkb/compiled       tmpfs   defaults        0 0" >> /etc/fstab
88 fi
89
90 # devfs tweaks
91 sed -i '/dev-state/ s:^:#:' /etc/devfsd.conf
92
93 # tweak the livecd fstab so that users know not to edit it
94 # http://bugs.gentoo.org/show_bug.cgi?id=60887
95 mv /etc/fstab /etc/fstab.old
96 echo "####################################################" >> /etc/fstab
97 echo "## ATTENTION: THIS IS THE FSTAB ON THE LIVECD     ##" >> /etc/fstab     
98 echo "## PLEASE EDIT THE FSTAB at /mnt/gentoo/etc/fstab ##" >> /etc/fstab     
99 echo "####################################################" >> /etc/fstab
100 cat /etc/fstab.old >> /etc/fstab
101 rm /etc/fstab.old
102
103 # add some helpful aliases
104 echo "alias cp='cp -i'" >> /etc/profile
105 echo "alias mv='mv -i'" >> /etc/profile
106 echo "alias rm='rm -i'" >> /etc/profile
107 echo "alias ls='ls --color=auto'" >> /etc/profile
108 echo "alias grep='grep --color=auto'" >> /etc/profile
109
110 # make sure we have the latest pci and hotplug ids
111 if [ -d /usr/share/hwdata ]
112 then
113         [ -f /usr/share/hwdata/pci.ids ] && rm -f /usr/share/hwdata/pci.ids
114         [ -f /usr/share/hwdata/usb.ids ] && rm -f /usr/share/hwdata/usb.ids
115         ln -s /usr/share/misc/pci.ids /usr/share/hwdata/pci.ids
116         ln -s /usr/share/misc/usb.ids /usr/share/hwdata/usb.ids
117 fi
118
119 # setup opengl in /etc (if configured)
120 [ -x /usr/sbin/openglify ] && /usr/sbin/openglify
121
122 # touch /etc/asound.state
123 touch /etc/asound.state
124
125 # tweak the motd for gentoo releases 
126 case ${clst_livecd_type} in
127         gentoo-release-universal )
128                 cat /etc/generic.motd.txt /etc/universal.motd.txt \
129                         /etc/minimal.motd.txt > /etc/motd
130                 sed -i 's:^##GREETING:Welcome to the Gentoo Linux Universal Installation CD!:' /etc/motd
131         ;;
132         gentoo-release-minimal )
133                 cat /etc/generic.motd.txt /etc/minimal.motd.txt > /etc/motd
134                 sed -i 's:^##GREETING:Welcome to the Gentoo Linux Minimal Installation CD!:' /etc/motd
135         ;;
136         gentoo-release-livecd )
137                 cat /etc/generic.motd.txt /etc/universal.motd.txt \
138                         /etc/minimal.motd.txt /etc/livecd.motd.txt > /etc/motd
139                 sed -i 's:^##GREETING:Welcome to the Gentoo Linux LiveCD!:' /etc/motd
140         ;;
141         gentoo-gamecd )
142                 cat /etc/generic.motd.txt /etc/gamecd.motd.txt > /etc/motd
143                 sed -i 's:^##GREETING:Welcome to the Gentoo Linux ##GAME_NAME GameCD!:' /etc/motd
144         ;;
145 esac
146
147 rm -f /etc/generic.motd.txt /etc/universal.motd.txt /etc/minimal.motd.txt /etc/livecd.motd.txt /etc/gamecd.motd.txt
148
149 # setup splash/bootsplash (if called for)
150 if [ "${clst_livecd_splash_type}" == "bootsplash" -a -n "${clst_livecd_splash_theme}" ]
151 then
152         if [ -d /etc/bootsplash/${clst_livecd_splash_theme} ]
153         then
154                 sed -i 's:BOOTSPLASH_THEME=\"gentoo\":BOOTSPLASH_THEME=\"${clst_livecd_splash_theme}\":' /etc/conf.d/bootsplash
155                 rm /etc/bootsplash/default
156                 ln -s "/etc/bootsplash/${clst_livecd_splash_theme}" /etc/bootsplash/default
157         else
158                 echo "Error, cannot setup bootsplash theme ${clst_livecd_splash_theme}"
159                 exit 1
160         fi
161
162 elif [ "${clst_livecd_splash_type}" == "gensplash" -a -n "${clst_livecd_splash_theme}" ]
163 then
164         if [ -d /etc/splash/${clst_livecd_splash_theme} ]
165         then
166                 sed -i 's:# SPLASH_THEME="gentoo":SPLASH_THEME=\"${clst_livecd_splash_theme}\":' /etc/conf.d/splash
167                 rm /etc/splash/default
168                 ln -s /etc/splash/${clst_livecd_splash_theme} /etc/splash/default
169         else
170                 echo "Error, cannot setup splash theme ${clst_livecd_splash_theme}"
171                 exit 1
172         fi
173 fi
174
175 # Create firmware directory if it does not exist
176 [ ! -d /lib/firmware ] && mkdir -p /lib/firmware
177
178 # tar up the firmware so that it does not get clobbered by the livecd mounts
179 if [ -n "$(ls /lib/firmware)" ]
180 then
181         cd /lib/firmware
182         if [ -n "$(ls /usr/lib/hotplug/firmware)" ]
183         then
184                 cp /usr/lib/hotplug/firmware/* /lib/firmware
185         fi
186         tar cvjpf /lib/firmware.tar.bz2 .
187         rm -f /lib/firmware/*
188         mkdir -p /usr/lib/hotplug
189         rm -rf /usr/lib/hotplug/firmware
190         ln -sf /lib/firmware /usr/lib/hotplug/firmware
191 fi
192
193 # Post configuration
194 case ${clst_livecd_type} in
195         gentoo-gamecd )
196                 # we grab our configuration
197                 if [ -e /tmp/gamecd.conf ]
198                 then
199
200                     source /tmp/gamecd.conf || exit 1
201                     rm /tmp/gamecd.conf
202
203                     # here we replace out game information into several files
204                     sed -i -e "s:##GAME_NAME:${GAME_NAME}:" /etc/motd
205
206                     # here we setup our xinitrc
207                     echo "exec ${GAME_EXECUTABLE}" > /etc/X11/xinit/xinitrc
208                 fi
209
210                 # This is my hack to reduce tmpfs usage
211                 mkdir -p /usr/livecd/db/pkg/x11-base
212                 mv -f /var/db/pkg/x11-base/xorg* /usr/livecd/db/pkg/x11-base
213                 rm -rf /var/db
214
215                 touch /etc/startx
216                 ;;
217         gentoo-release-livecd )
218                 # first we setup the livecd-kernel package
219                 if [ -e /opt/installer/misc/mkvardb ]
220                 then
221                         chmod +x /opt/installer/misc/mkvardb
222                         /opt/installer/misc/mkvardb -p livecd-kernel -c sys-kernel -v 2005.0 /boot/kernel* /boot/initrd* $(for i in $(find "/lib/modules/$(uname -r)" -type f); do grep --quiet "${i}" /var/db/pkg/*/*/CONTENTS || echo ${i}; done)
223                 fi
224
225                 # This is my hack to reduce tmpfs usage
226                 mkdir -p /usr/livecd
227                 mv -f /usr/portage/profiles /usr/livecd
228                 rm -rf /usr/livecd/profiles/{co*,default-{1*,a*,b*,d*,h*,i*,m*,p*,s*,x*},g*,hardened-*,n*,x*}
229                 mv -f /etc/gconf /usr/livecd
230                 mv -f /var/db /usr/livecd
231                 ;;
232         generic-livecd )
233                 # This is my hack to reduce tmpfs usage
234                 mkdir -p /usr/livecd
235                 mv -f /etc/gconf /usr/livecd
236
237                 touch /etc/startx
238                 ;;
239 esac
240