c2faf7b8f38641beb01d43dfacd3f885cb592e65
[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.57 2006/07/26 22:38:45 wolf31o2 Exp $
5
6 . /tmp/chroot-functions.sh
7
8 update_env_settings
9
10 # Allow root logins to our CD 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         first_user=$(echo ${clst_livecd_users} | cut -d' ' -f1)
40
41         # Here we check to see if games exists for bug #125498
42         if [ "$(getent group games | cut -d: -f1)" != "games" ]
43         then
44                 echo "Adding games group"
45                 groupadd -g 35 games
46         fi
47         for x in ${clst_livecd_users}
48         do
49                 useradd -G users,wheel,audio,games,cdrom,usb -c "Default LiveCD User" \
50                         -m ${x}
51                 if [ -n "${clst_livecd_xdm}" -a -n "${clst_livecd_xsession}" ]
52                 then
53                         echo "[Desktop]" > /home/${x}/.dmrc
54                         echo "Session=${clst_livecd_xsession}" >> /home/${x}/.dmrc
55                         chown -R ${x}:users /home/${x}
56                 fi
57         done
58 fi
59
60 # Setup sudoers
61 if [ -f /etc/sudoers ]
62 then
63         sed -i '/NOPASSWD: ALL/ s/^# //' /etc/sudoers
64 fi
65
66 # Setup links for ethernet devices
67 cd /etc/init.d
68 ln -sf net.lo net.eth1
69 ln -sf net.lo net.eth2
70 ln -sf net.lo net.eth3
71 ln -sf net.lo net.eth4
72
73 # Add this for hwsetup/mkx86config
74 mkdir -p /etc/sysconfig
75
76 # fstab tweaks
77 echo "tmpfs     /                                       tmpfs   defaults        0 0" > /etc/fstab
78 echo "tmpfs     /lib/firmware                   tmpfs   defaults        0 0" >> /etc/fstab
79 echo "tmpfs     /usr/portage                    tmpfs   defaults        0 0" >> /etc/fstab
80 # If /usr/lib/X11/xkb/compiled then make it tmpfs
81 if [ -d /usr/lib/X11/xkb/compiled ]
82 then
83         echo "tmpfs     /usr/lib/X11/xkb/compiled       tmpfs   defaults        0 0" >> \
84                 /etc/fstab
85 fi
86
87 # devfs tweaks
88 [ -e /etc/devfsd.conf ] && sed -i '/dev-state/ s:^:#:' /etc/devfsd.conf
89
90 # Tweak the livecd fstab so that users know not to edit it
91 # http://bugs.gentoo.org/show_bug.cgi?id=60887
92 mv /etc/fstab /etc/fstab.old
93 echo "####################################################" >> /etc/fstab
94 echo "## ATTENTION: THIS IS THE FSTAB ON THE LIVECD      ##" >> /etc/fstab
95 echo "## PLEASE EDIT THE FSTAB at /mnt/gentoo/etc/fstab ##" >> /etc/fstab        
96 echo "####################################################" >> /etc/fstab
97 cat /etc/fstab.old >> /etc/fstab
98 rm /etc/fstab.old
99
100 # Add some helpful aliases
101 echo "alias cp='cp -i'" >> /etc/profile
102 echo "alias mv='mv -i'" >> /etc/profile
103 echo "alias rm='rm -i'" >> /etc/profile
104 echo "alias ls='ls --color=auto'" >> /etc/profile
105 echo "alias ll='ls -l'" >> /etc/profile
106 echo "alias grep='grep --color=auto'" >> /etc/profile
107
108 # Make sure we have the latest pci,usb and hotplug ids
109 [ -x /sbin/update-pciids ] && /sbin/update-pciids
110 [ -x /sbin/update-usbids ] && /sbin/update-usbids
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 # Setup configured display manager
123 if [ -n "${clst_livecd_xdm}" ]
124 then
125         sed -i "s:#DISPLAYMANAGER=\"xdm\":DISPLAYMANAGER=\"${clst_livecd_xdm}\":" \
126                 /etc/rc.conf
127 fi
128
129 # Setup configured default X Session
130 if [ -n "${clst_livecd_xsession}" ]
131 then
132         sed -i "s:#XSESSION=\"Gnome\":XSESSION=\"${clst_livecd_xsession}\":" \
133                 /etc/rc.conf
134 fi
135
136 # touch /etc/asound.state
137 touch /etc/asound.state
138
139 # Tweak the MOTD for Gentoo releases 
140 case ${clst_livecd_type} in
141         gentoo-release-universal )
142                 cat /etc/generic.motd.txt /etc/universal.motd.txt \
143                         /etc/minimal.motd.txt > /etc/motd
144                 sed -i 's:^##GREETING:Welcome to the Gentoo Linux Universal Installation CD!:' /etc/motd
145         ;;
146         gentoo-release-minimal )
147                 cat /etc/generic.motd.txt /etc/minimal.motd.txt > /etc/motd
148                 sed -i 's:^##GREETING:Welcome to the Gentoo Linux Minimal Installation CD!:' /etc/motd
149         ;;
150         gentoo-release-livecd )
151                 cat /etc/generic.motd.txt \
152                         /etc/minimal.motd.txt /etc/livecd.motd.txt > /etc/motd
153                 sed -i -e 's:^##GREETING:Welcome to the Gentoo Linux LiveCD!:' \
154                         -e "s:##DISPLAY_MANAGER:${clst_livecd_xdm}:" /etc/motd
155         ;;
156         gentoo-gamecd )
157                 cat /etc/generic.motd.txt /etc/gamecd.motd.txt > /etc/motd
158                 sed -i 's:^##GREETING:Welcome to the Gentoo Linux ##GAME_NAME GameCD!:' /etc/motd
159         ;;
160 esac
161
162 rm -f /etc/generic.motd.txt /etc/universal.motd.txt /etc/minimal.motd.txt /etc/livecd.motd.txt /etc/gamecd.motd.txt
163
164 # Setup splash/bootsplash (if called for)
165 if [ "${clst_livecd_splash_type}" == "bootsplash" -a -n \
166         "${clst_livecd_splash_theme}" ]
167 then
168         if [ -d /etc/bootsplash/${clst_livecd_splash_theme} ]
169         then
170                 sed -i 's:BOOTSPLASH_THEME=\"gentoo\":BOOTSPLASH_THEME=\"${clst_livecd_splash_theme}\":' /etc/conf.d/bootsplash
171                 rm -f /etc/bootsplash/default
172                 ln -s "/etc/bootsplash/${clst_livecd_splash_theme}" \
173                         /etc/bootsplash/default
174         else
175                 echo "Error, cannot setup bootsplash theme ${clst_livecd_splash_theme}"
176                 exit 1
177         fi
178 elif [ "${clst_livecd_splash_type}" == "gensplash" -a -n \
179         "${clst_livecd_splash_theme}" ]
180 then
181         if [ -d /etc/splash/${clst_livecd_splash_theme} ]
182         then
183                 sed -i \
184                         -e "s:# SPLASH_THEME=\"gentoo\":SPLASH_THEME=\"${clst_livecd_splash_theme}\":" \
185                         -e "/^# SPLASH_TTYS=/ s/^#//" \
186                         /etc/conf.d/splash
187                 sed -i \
188                         -e 's/type}" cachedir "${spl_/type}" tmpfs "${spl_/' \
189                         /sbin/splash-functions.sh
190                 rm -f /etc/splash/default
191                 ln -s /etc/splash/${clst_livecd_splash_theme} /etc/splash/default
192         else
193                 echo "Error, cannot setup splash theme ${clst_livecd_splash_theme}"
194                 exit 1
195         fi
196 fi
197
198 # Create firmware directory if it does not exist
199 [ ! -d /lib/firmware ] && mkdir -p /lib/firmware
200
201 # tar up the firmware so that it does not get clobbered by the livecd mounts
202 if [ -n "$(ls /lib/firmware)" ]
203 then
204         cd /lib/firmware
205         if [ -n "$(ls /usr/lib/hotplug/firmware)" ]
206         then
207                 cp -r /usr/lib/hotplug/firmware/* /lib/firmware
208         fi
209         /bin/tar cjpf /lib/firmware.tar.bz2 .
210         rm -rf /lib/firmware/*
211         mkdir -p /usr/lib/hotplug
212         rm -rf /usr/lib/hotplug/firmware
213         ln -sf /lib/firmware /usr/lib/hotplug/firmware
214 fi
215
216 # Clear out locales
217 case ${clst_livecd_type} in
218         gentoo-release-minimal|gentoo-release-universal|gentoo-gamecd)
219                 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}*
220         ;;
221 esac
222
223 # Post configuration
224 case ${clst_livecd_type} in
225         gentoo-gamecd )
226                 # We grab our configuration
227                 if [ -e /tmp/gamecd.conf ]
228                 then
229                         source /tmp/gamecd.conf || exit 1
230                         rm /tmp/gamecd.conf
231
232                         # Here we replace out game information into several files
233                         sed -i -e "s:##GAME_NAME:${GAME_NAME}:" /etc/motd
234
235                         # Here we setup our xinitrc
236                         echo "exec ${GAME_EXECUTABLE}" > /etc/X11/xinit/xinitrc
237                 fi
238
239                 # This is my hack to reduce tmpfs usage
240                 mkdir -p /usr/livecd/db/pkg/x11-base
241                 mv -f /var/db/pkg/x11-base/xorg* /usr/livecd/db/pkg/x11-base
242                 rm -rf /var/db
243
244                 touch /etc/startx
245                 ;;
246         gentoo-release-livecd )
247                 # First we setup the livecd-kernel package
248                 if [ -e /opt/installer/misc/mkvardb ]
249                 then
250                         chmod +x /opt/installer/misc/mkvardb
251                         /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)
252                 fi
253
254                 # Setup Gnome theme
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/theme Clearlooks
260                         gconftool-2 --direct \
261                                 --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults \
262                                 --type string --set /apps/metacity/general/theme Clearlooks
263                         gconftool-2 --direct \
264                                 --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults \
265                                 --type string --set /desktop/gnome/interface/gtk_key_theme \
266                                 Clearlooks
267                         gconftool-2 --direct \
268                                 --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults \
269                                 --type string --set /desktop/gnome/interface/gtk_theme \
270                                 Clearlooks
271                         gconftool-2 --direct \
272                                 --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults \
273                                 --type string --set /desktop/gnome/interface/font_name "Sans 9"
274                 fi
275
276                 # Setup GDM
277                 if [ "${clst_livecd_xdm}" == "gdm" ]
278                 then
279                         if [ ! -e /etc/X11/gdm/gdm.conf ] && [ -e /usr/share/gdm/defaults.conf ]
280                         then
281                                 if [ -n "${clst_livecd_users}" ] && [ -n "${first_user}" ]
282                                 then
283                                         sedxtra="\nTimedLogin=${first_user}"
284                                 else
285                                         sedxtra=""
286                                 fi
287
288                                 sed     -i \
289                                         -e "s:\(\[daemon\]\)$:\1\nTimedLoginEnable=true\nTimedLoginDelay=10${sedxtra}:" \
290                                         -e 's:\(\[greeter\]\)$:\1\nGraphicalTheme=gentoo-emergence:' \
291                                         /etc/X11/gdm/custom.conf
292                         else
293                                 cp -f /etc/X11/gdm/gdm.conf /etc/X11/gdm/gdm.conf.old
294                                 sed -i \
295                                         -e 's:TimedLoginEnable=false:TimedLoginEnable=true:' \
296                                         -e 's:TimedLoginDelay=30:TimedLoginDelay=10:' \
297                                         -e 's:AllowRemoteRoot=true:AllowRemoteRoot=false:' \
298                                         -e ':^#GraphicalTheme=: s:^#::' \
299                                         -e 's:^GraphicalTheme=.*$:GraphicalTheme=gentoo-emergence:' \
300                                         /etc/X11/gdm/gdm.conf
301
302                                 if [ -n "${clst_livecd_users}" ] && [ -n "${first_user}" ]
303                                 then
304                                         sed -i \
305                                                 -e "s:TimedLogin=:TimedLogin=${first_user}:" \
306                                                 /etc/X11/gdm/gdm.conf
307                                 fi
308                         fi
309                 fi
310
311
312                 # This gives us our list of system packages for the installer
313                 mkdir -p /usr/livecd
314                 USE="-* $(cat /var/db/pkg/sys-libs/glibc*/USE)" emerge -ep system | grep -e '^\[ebuild' | sed -e 's:^\[ebuild .\+\] ::' > /usr/livecd/systempkgs.txt
315
316                 # This is my hack to reduce tmpfs usage
317                 cp -r /usr/portage/profiles /usr/livecd
318                 cp -r /usr/portage/eclass /usr/livecd
319                 rm -rf /usr/livecd/profiles/{co*,default-{1*,a*,b*,d*,h*,i*,m*,p*,s*,x*},g*,hardened-*,n*,x*}
320                 mv -f /etc/gconf /usr/livecd
321                 mv -f /var/db /usr/livecd
322
323                 # This gives us a proper cache for portage/installer
324                 tar cjf /usr/livecd/metadata.tar.bz2 /var/cache/edb/dep/usr/portage
325
326                 # We remove kernel sources from our vdb
327                 rm -rf /usr/livecd/db/pkg/sys-kernel/*sources*
328
329                 # Clear out lastlog
330                 rm -f /var/log/lastlog && touch /var/log/lastlog
331
332                 # Create our installer icons
333                 if [ -e /usr/share/applications/installer-gtk.desktop ]
334                 then
335                         if [ -n "${clst_livecd_users}" ]
336                         then
337                                 for username in ${clst_livecd_users}
338                                 do
339                                         mkdir -p /home/${username}/Desktop
340                                         cp /usr/share/applications/installer-gtk.desktop \
341                                                 /home/${username}/Desktop
342                                         cp /usr/share/applications/installer-faq.desktop \
343                                                 /home/${username}/Desktop
344                                         cp /usr/share/applications/installer-dialog.desktop \
345                                                 /home/${username}/Desktop
346                                         sed -i -e 's:Exec=installer-dialog:Exec=installer dialog:' \
347                                                 /home/${username}/Desktop/installer-dialog.desktop
348                                         sed -i -e 's:Exec=installer-gtk:Exec=installer:' \
349                                                 /home/${username}/Desktop/installer-gtk.desktop
350                                         chown -R ${username}:100 /home/${username}
351                                 done
352                         fi
353                 fi
354                 ;;
355         generic-livecd )
356                 # This is my hack to reduce tmpfs usage
357                 mkdir -p /usr/livecd
358                 mv -f /etc/gconf /usr/livecd
359                 if [ -e /usr/livecd/grppkgs.txt ]
360                 then
361                         rm -f /usr/livecd/grppkgs.txt
362                 fi
363                 if [ -e /usr/livecd/kernelpkgs.txt ]
364                 then
365                         rm -f /usr/livecd/kernelpkgs.txt
366                 fi
367
368                 touch /etc/startx
369                 ;;
370         * )
371                 if [ -e /usr/livecd/grppkgs.txt ]
372                 then
373                         rm -f /usr/livecd/grppkgs.txt
374                 fi
375                 if [ -e /usr/livecd/kernelpkgs.txt ]
376                 then
377                         rm -f /usr/livecd/kernelpkgs.txt
378                 fi
379                 ;;
380 esac
381
382 # We want the first user to be used when auto-starting X
383 if [ -e /etc/startx ]
384 then
385         sed -i \
386                 "s/##STARTX/source /etc/profile && su - ${first_user} -c startx/" \
387                 /root/.bashrc
388 fi
389
390 if [ -e /lib/rcscripts/addons/udev-start.sh ]
391 then
392         sed -i "s:\t\[\[ -x /sbin/evms_activate:\t\[\[ -x \${CDBOOT} \]\] \&\& \[\[ -x /sbin/evms_activate:" /lib/rcscripts/addons/udev-start.sh
393 fi