Fixed generation of grppkgs.txt and kernelpkgs.txt for the Installer. This is 2...
[catalyst.git] / targets / support / livecdfs-update.sh
1 #!/bin/bash
2 # Copyright 1999-2005 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.37 2006/02/13 22:26:44 wolf31o2 Exp $
5
6 . /tmp/chroot-functions.sh
7
8 update_env_settings
9
10 # Allow root logins to the livecd by default
11 if [ -e /etc/sshd/sshd_config ]
12 then
13         sed -i 's:^#PermitRootLogin\ yes:PermitRootLogin\ yes:' \
14                 /etc/ssh/sshd_config
15 fi
16
17 # Turn off udev tarball
18 sed -i 's:RC_DEVICE_TARBALL="yes":RC_DEVICE_TARBALL="no":' /etc/conf.d/rc
19
20 # Clean up the time and set to UTC
21 rm -rf /etc/localtime
22 cp /usr/share/zoneinfo/UTC /etc/localtime
23
24 # Setup the hostname
25 if [ "${clst_livecd_type}" == "gentoo-gamecd" ]
26 then
27         echo 'HOSTNAME="gamecd"' > /etc/conf.d/hostname
28         echo "127.0.0.1 gamecd.gentoo gamecd localhost" > /etc/hosts
29 else
30         echo 'HOSTNAME="livecd"' > /etc/conf.d/hostname
31         echo "127.0.0.1 livecd.gentoo livecd localhost" > /etc/hosts
32 fi
33 echo 'OVERRIDE=0' > /etc/conf.d/domainname
34 echo 'DNSDOMAIN="gentoo"' >> /etc/conf.d/domainname
35
36 # Add any users
37 if [ -n "${clst_livecd_users}" ]
38 then
39         for x in ${clst_livecd_users}
40         do
41                 useradd -G users,wheel,audio,games,cdrom,usb -c "Default LiveCD User" \
42                         -m $x
43                 if [ -n "${clst_livecd_xdm}" -a -n "${clst_livecd_xsession}" ]
44                 then
45                         echo "[Desktop]" > /home/$x/.dmrc
46                         echo "Session=${clst_livecd_xsession}" >> /home/$x/.dmrc
47                         chown -R $x:users /home/$x
48                 fi
49         done
50 fi
51
52 # Setup sudoers
53 if [ -f /etc/sudoers ]
54 then
55         sed -i '/NOPASSWD: ALL/ s/^# //' /etc/sudoers
56 fi
57
58 # We want the first user to be used when auto-starting X
59 if [ -n "${clst_livecd_users}" -a -e /etc/startx ]
60 then
61         first_user=$(echo ${clst_livecd_users} | cut -d' ' -f1)
62         sed -i "s/##STARTX/su - $first_user -c startx/" /root/.bashrc
63 fi
64
65 # Setup DHCP on all detected ethernet devices
66 echo "iface_eth0=\"dhcp\""> /etc/conf.d/net
67 echo "iface_eth1=\"dhcp\"" >> /etc/conf.d/net
68 echo "iface_eth2=\"dhcp\"" >> /etc/conf.d/net
69 echo "iface_eth3=\"dhcp\"" >> /etc/conf.d/net
70 echo "iface_eth4=\"dhcp\"" >> /etc/conf.d/net
71
72 # Setup links for ethernet devices
73 cd /etc/init.d
74 ln -sf net.lo net.eth1
75 ln -sf net.lo net.eth2
76 ln -sf net.lo net.eth3
77 ln -sf net.lo net.eth4
78
79 # Add this for hwsetup/mkx86config
80 mkdir -p /etc/sysconfig
81
82 # fstab tweaks
83 echo "tmpfs     /                                       tmpfs   defaults        0 0" > /etc/fstab
84 echo "tmpfs     /lib/firmware                   tmpfs   defaults        0 0" >> /etc/fstab
85 echo "tmpfs     /usr/portage                    tmpfs   defaults        0 0" >> /etc/fstab
86 # If /usr/lib/X11/xkb/compiled then make it tmpfs
87 if [ -d /usr/lib/X11/xkb/compiled ]
88 then
89         echo "tmpfs     /usr/lib/X11/xkb/compiled       tmpfs   defaults        0 0" >> \
90                 /etc/fstab
91 fi
92
93 # devfs tweaks
94 [ -e /etc/devfsd.conf ] && sed -i '/dev-state/ s:^:#:' /etc/devfsd.conf
95
96 # Tweak the livecd fstab so that users know not to edit it
97 # http://bugs.gentoo.org/show_bug.cgi?id=60887
98 mv /etc/fstab /etc/fstab.old
99 echo "####################################################" >> /etc/fstab
100 echo "## ATTENTION: THIS IS THE FSTAB ON THE LIVECD      ##" >> /etc/fstab
101 echo "## PLEASE EDIT THE FSTAB at /mnt/gentoo/etc/fstab ##" >> /etc/fstab        
102 echo "####################################################" >> /etc/fstab
103 cat /etc/fstab.old >> /etc/fstab
104 rm /etc/fstab.old
105
106 # Add some helpful aliases
107 echo "alias cp='cp -i'" >> /etc/profile
108 echo "alias mv='mv -i'" >> /etc/profile
109 echo "alias rm='rm -i'" >> /etc/profile
110 echo "alias ls='ls --color=auto'" >> /etc/profile
111 echo "alias ll='ls -l'" >> /etc/profile
112 echo "alias grep='grep --color=auto'" >> /etc/profile
113
114 # Make sure we have the latest pci,usb and hotplug ids
115 [ -x /sbin/update-pciids ] && /sbin/update-pciids
116 [ -x /sbin/update-usbids ] && /sbin/update-usbids
117 if [ -d /usr/share/hwdata ]
118 then
119         [ -f /usr/share/hwdata/pci.ids ] && rm -f /usr/share/hwdata/pci.ids
120         [ -f /usr/share/hwdata/usb.ids ] && rm -f /usr/share/hwdata/usb.ids
121         ln -s /usr/share/misc/pci.ids /usr/share/hwdata/pci.ids
122         ln -s /usr/share/misc/usb.ids /usr/share/hwdata/usb.ids
123 fi
124
125 # Setup opengl in /etc (if configured)
126 [ -x /usr/sbin/openglify ] && /usr/sbin/openglify
127
128 # Setup configured display manager
129 if [ -n "${clst_livecd_xdm}" ]
130 then
131         sed -i "s:#DISPLAYMANAGER=\"xdm\":DISPLAYMANAGER=\"${clst_livecd_xdm}\":" \
132                 /etc/rc.conf
133         rc-update add xdm default
134 fi
135
136 # Setup configured default X Session
137 if [ -n "${clst_livecd_xsession}" ]
138 then
139         sed -i "s:#XSESSION=\"Gnome\":XSESSION=\"${clst_livecd_xsession}\":" \
140                 /etc/rc.conf
141 fi
142
143 # touch /etc/asound.state
144 touch /etc/asound.state
145
146 # Tweak the MOTD for Gentoo releases 
147 case ${clst_livecd_type} in
148         gentoo-release-universal )
149                 cat /etc/generic.motd.txt /etc/universal.motd.txt \
150                         /etc/minimal.motd.txt > /etc/motd
151                 sed -i 's:^##GREETING:Welcome to the Gentoo Linux Universal Installation CD!:' /etc/motd
152         ;;
153         gentoo-release-minimal )
154                 cat /etc/generic.motd.txt /etc/minimal.motd.txt > /etc/motd
155                 sed -i 's:^##GREETING:Welcome to the Gentoo Linux Minimal Installation CD!:' /etc/motd
156         ;;
157         gentoo-release-livecd )
158                 cat /etc/generic.motd.txt \
159                         /etc/minimal.motd.txt /etc/livecd.motd.txt > /etc/motd
160                 sed -i -e 's:^##GREETING:Welcome to the Gentoo Linux LiveCD!:' \
161                         -e "s:##DISPLAY_MANAGER:${clst_livecd_xdm}:" /etc/motd
162         ;;
163         gentoo-gamecd )
164                 cat /etc/generic.motd.txt /etc/gamecd.motd.txt > /etc/motd
165                 sed -i 's:^##GREETING:Welcome to the Gentoo Linux ##GAME_NAME GameCD!:' /etc/motd
166         ;;
167 esac
168
169 rm -f /etc/generic.motd.txt /etc/universal.motd.txt /etc/minimal.motd.txt /etc/livecd.motd.txt /etc/gamecd.motd.txt
170
171 # Setup splash/bootsplash (if called for)
172 if [ "${clst_livecd_splash_type}" == "bootsplash" -a -n \
173         "${clst_livecd_splash_theme}" ]
174 then
175         if [ -d /etc/bootsplash/${clst_livecd_splash_theme} ]
176         then
177                 sed -i 's:BOOTSPLASH_THEME=\"gentoo\":BOOTSPLASH_THEME=\"${clst_livecd_splash_theme}\":' /etc/conf.d/bootsplash
178                 rm -f /etc/bootsplash/default
179                 ln -s "/etc/bootsplash/${clst_livecd_splash_theme}" \
180                         /etc/bootsplash/default
181         else
182                 echo "Error, cannot setup bootsplash theme ${clst_livecd_splash_theme}"
183                 exit 1
184         fi
185 elif [ "${clst_livecd_splash_type}" == "gensplash" -a -n \
186         "${clst_livecd_splash_theme}" ]
187 then
188         if [ -d /etc/splash/${clst_livecd_splash_theme} ]
189         then
190                 sed -i 's:# SPLASH_THEME="gentoo":SPLASH_THEME=\"${clst_livecd_splash_theme}\":' /etc/conf.d/splash
191                 rm -f /etc/splash/default
192                 ln -s /etc/splash/${clst_livecd_splash_theme} /etc/splash/default
193         else
194                 echo "Error, cannot setup splash theme ${clst_livecd_splash_theme}"
195                 exit 1
196         fi
197 fi
198
199 # Create firmware directory if it does not exist
200 [ ! -d /lib/firmware ] && mkdir -p /lib/firmware
201
202 # tar up the firmware so that it does not get clobbered by the livecd mounts
203 if [ -n "$(ls /lib/firmware)" ]
204 then
205         cd /lib/firmware
206         if [ -n "$(ls /usr/lib/hotplug/firmware)" ]
207         then
208                 cp /usr/lib/hotplug/firmware/* /lib/firmware
209         fi
210         /bin/tar cjpf /lib/firmware.tar.bz2 .
211         rm -f /lib/firmware/*
212         mkdir -p /usr/lib/hotplug
213         rm -rf /usr/lib/hotplug/firmware
214         ln -sf /lib/firmware /usr/lib/hotplug/firmware
215 fi
216
217 # Clear out locales
218 case ${clst_livecd_type} in
219         gentoo-release-minimal|gentoo-release-universal|gentoo-gamecd)
220                 rm -rf /usr/lib/locale/{a,b,c,d,e{l,n_{A,B,C,D,G,H,I,N,P,S,US.,Z},s,t,u},f,g,h,i,j,k,l,m,n,o,p,r,s,t,u,v,w,x,y,z}*
221         ;;
222 esac
223
224 # Post configuration
225 case ${clst_livecd_type} in
226         gentoo-gamecd )
227                 # We grab our configuration
228                 if [ -e /tmp/gamecd.conf ]
229                 then
230                         source /tmp/gamecd.conf || exit 1
231                         rm /tmp/gamecd.conf
232
233                         # Here we replace out game information into several files
234                         sed -i -e "s:##GAME_NAME:${GAME_NAME}:" /etc/motd
235
236                         # Here we setup our xinitrc
237                         echo "exec ${GAME_EXECUTABLE}" > /etc/X11/xinit/xinitrc
238                 fi
239
240                 # This is my hack to reduce tmpfs usage
241                 mkdir -p /usr/livecd/db/pkg/x11-base
242                 mv -f /var/db/pkg/x11-base/xorg* /usr/livecd/db/pkg/x11-base
243                 rm -rf /var/db
244
245                 touch /etc/startx
246                 ;;
247         gentoo-release-livecd )
248                 # First we setup the livecd-kernel package
249                 if [ -e /opt/installer/misc/mkvardb ]
250                 then
251                         chmod +x /opt/installer/misc/mkvardb
252                         /opt/installer/misc/mkvardb -p livecd-kernel -c sys-kernel -v ${clst_version_stamp} --provide "virtual/alsa" /boot/kernel* /boot/initr* $(for i in $(find "/lib/modules/" -type f); do grep --quiet "${i}" /var/db/pkg/*/*/CONTENTS || echo ${i}; done)
253                 fi
254
255                 if [ "${clst_livecd_xsession}" == "gnome" ]
256                 then
257                         gconftool-2 --direct \
258                                 --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults \
259                                 --type string --set /desktop/gnome/interface/icon_theme Crux
260                         gconftool-2 --direct \
261                                 --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults \
262                                 --type string --set /desktop/gnome/interface/theme Crux
263                         gconftool-2 --direct \
264                                 --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults \
265                                 --type string --set /apps/metacity/general/theme Crux
266                         gconftool-2 --direct \
267                                 --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults \
268                                 --type string --set /desktop/gnome/interface/gtk_key_theme \
269                                 Clearlooks
270                         gconftool-2 --direct \
271                                 --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults \
272                                 --type string --set /desktop/gnome/interface/gtk_theme \
273                                 Clearlooks
274                         gconftool-2 --direct \
275                                 --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults \
276                                 --type string --set /desktop/gnome/interface/font_name "Sans 9"
277                 fi
278
279                 # This gives us our list of system packages for the installer
280                 mkdir -p /usr/livecd
281                 USE="-* $(cat /var/db/pkg/sys-libs/glibc*/USE)" emerge -ep system | grep -e '^\[ebuild' | sed -e 's:^\[ebuild .\+\] ::' > /usr/livecd/systempkgs.txt
282
283                 # This is my hack to reduce tmpfs usage
284                 cp -r /usr/portage/profiles /usr/livecd
285                 cp -r /usr/portage/eclass /usr/livecd
286                 rm -rf /usr/livecd/profiles/{co*,default-{1*,a*,b*,d*,h*,i*,m*,p*,s*,x*},g*,hardened-*,n*,x*}
287                 mv -f /etc/gconf /usr/livecd
288                 mv -f /var/db /usr/livecd
289
290                 # This gives us a proper cache for portage
291                 tar cjf /usr/livecd/metadata.tar.bz2 /var/cache/edb/dep/usr/portage
292                 ;;
293         generic-livecd )
294                 # This is my hack to reduce tmpfs usage
295                 mkdir -p /usr/livecd
296                 mv -f /etc/gconf /usr/livecd
297
298                 touch /etc/startx
299                 ;;
300         * )
301                 if [ -e /usr/livecd/grppkgs.txt ]
302                 then
303                         rm -f /usr/livecd/grppkgs.txt
304                 fi
305                 if [ -e /usr/livecd/kernelpkgs.txt ]
306                 then
307                         rm -f /usr/livecd/kernelpkgs.txt
308                 fi
309                 ;;
310 esac
311