Fixing my own bug in livecdfs-update.sh and rolling 2.0_rc43.
[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.45 2006/04/19 15:34:08 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         # Here we check to see if games exists for bug #125498
40         if [ "$(getent group games | cut -d: -f1)" != "games" ]
41         then
42                 echo "Adding games group"
43                 groupadd -g 35 games
44         fi
45         for x in ${clst_livecd_users}
46         do
47                 useradd -G users,wheel,audio,games,cdrom,usb -c "Default LiveCD User" \
48                         -m $x
49                 if [ -n "${clst_livecd_xdm}" -a -n "${clst_livecd_xsession}" ]
50                 then
51                         echo "[Desktop]" > /home/$x/.dmrc
52                         echo "Session=${clst_livecd_xsession}" >> /home/$x/.dmrc
53                         chown -R $x:users /home/$x
54                 fi
55         done
56 fi
57
58 # Setup sudoers
59 if [ -f /etc/sudoers ]
60 then
61         sed -i '/NOPASSWD: ALL/ s/^# //' /etc/sudoers
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.lo net.eth1
74 ln -sf net.lo net.eth2
75 ln -sf net.lo net.eth3
76 ln -sf net.lo 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 echo "tmpfs     /usr/portage                    tmpfs   defaults        0 0" >> /etc/fstab
85 # If /usr/lib/X11/xkb/compiled then make it tmpfs
86 if [ -d /usr/lib/X11/xkb/compiled ]
87 then
88         echo "tmpfs     /usr/lib/X11/xkb/compiled       tmpfs   defaults        0 0" >> \
89                 /etc/fstab
90 fi
91
92 # devfs tweaks
93 [ -e /etc/devfsd.conf ] && sed -i '/dev-state/ s:^:#:' /etc/devfsd.conf
94
95 # Tweak the livecd fstab so that users know not to edit it
96 # http://bugs.gentoo.org/show_bug.cgi?id=60887
97 mv /etc/fstab /etc/fstab.old
98 echo "####################################################" >> /etc/fstab
99 echo "## ATTENTION: THIS IS THE FSTAB ON THE LIVECD      ##" >> /etc/fstab
100 echo "## PLEASE EDIT THE FSTAB at /mnt/gentoo/etc/fstab ##" >> /etc/fstab        
101 echo "####################################################" >> /etc/fstab
102 cat /etc/fstab.old >> /etc/fstab
103 rm /etc/fstab.old
104
105 # Add some helpful aliases
106 echo "alias cp='cp -i'" >> /etc/profile
107 echo "alias mv='mv -i'" >> /etc/profile
108 echo "alias rm='rm -i'" >> /etc/profile
109 echo "alias ls='ls --color=auto'" >> /etc/profile
110 echo "alias ll='ls -l'" >> /etc/profile
111 echo "alias grep='grep --color=auto'" >> /etc/profile
112
113 # Make sure we have the latest pci,usb and hotplug ids
114 [ -x /sbin/update-pciids ] && /sbin/update-pciids
115 [ -x /sbin/update-usbids ] && /sbin/update-usbids
116 if [ -d /usr/share/hwdata ]
117 then
118         [ -f /usr/share/hwdata/pci.ids ] && rm -f /usr/share/hwdata/pci.ids
119         [ -f /usr/share/hwdata/usb.ids ] && rm -f /usr/share/hwdata/usb.ids
120         ln -s /usr/share/misc/pci.ids /usr/share/hwdata/pci.ids
121         ln -s /usr/share/misc/usb.ids /usr/share/hwdata/usb.ids
122 fi
123
124 # Setup opengl in /etc (if configured)
125 [ -x /usr/sbin/openglify ] && /usr/sbin/openglify
126
127 # Setup configured display manager
128 if [ -n "${clst_livecd_xdm}" ]
129 then
130         sed -i "s:#DISPLAYMANAGER=\"xdm\":DISPLAYMANAGER=\"${clst_livecd_xdm}\":" \
131                 /etc/rc.conf
132         rc-update add xdm default
133 fi
134
135 # Setup configured default X Session
136 if [ -n "${clst_livecd_xsession}" ]
137 then
138         sed -i "s:#XSESSION=\"Gnome\":XSESSION=\"${clst_livecd_xsession}\":" \
139                 /etc/rc.conf
140 fi
141
142 # touch /etc/asound.state
143 touch /etc/asound.state
144
145 # Tweak the MOTD for Gentoo releases 
146 case ${clst_livecd_type} in
147         gentoo-release-universal )
148                 cat /etc/generic.motd.txt /etc/universal.motd.txt \
149                         /etc/minimal.motd.txt > /etc/motd
150                 sed -i 's:^##GREETING:Welcome to the Gentoo Linux Universal Installation CD!:' /etc/motd
151         ;;
152         gentoo-release-minimal )
153                 cat /etc/generic.motd.txt /etc/minimal.motd.txt > /etc/motd
154                 sed -i 's:^##GREETING:Welcome to the Gentoo Linux Minimal Installation CD!:' /etc/motd
155         ;;
156         gentoo-release-livecd )
157                 cat /etc/generic.motd.txt \
158                         /etc/minimal.motd.txt /etc/livecd.motd.txt > /etc/motd
159                 sed -i -e 's:^##GREETING:Welcome to the Gentoo Linux LiveCD!:' \
160                         -e "s:##DISPLAY_MANAGER:${clst_livecd_xdm}:" /etc/motd
161         ;;
162         gentoo-gamecd )
163                 cat /etc/generic.motd.txt /etc/gamecd.motd.txt > /etc/motd
164                 sed -i 's:^##GREETING:Welcome to the Gentoo Linux ##GAME_NAME GameCD!:' /etc/motd
165         ;;
166 esac
167
168 rm -f /etc/generic.motd.txt /etc/universal.motd.txt /etc/minimal.motd.txt /etc/livecd.motd.txt /etc/gamecd.motd.txt
169
170 # Setup splash/bootsplash (if called for)
171 if [ "${clst_livecd_splash_type}" == "bootsplash" -a -n \
172         "${clst_livecd_splash_theme}" ]
173 then
174         if [ -d /etc/bootsplash/${clst_livecd_splash_theme} ]
175         then
176                 sed -i 's:BOOTSPLASH_THEME=\"gentoo\":BOOTSPLASH_THEME=\"${clst_livecd_splash_theme}\":' /etc/conf.d/bootsplash
177                 rm -f /etc/bootsplash/default
178                 ln -s "/etc/bootsplash/${clst_livecd_splash_theme}" \
179                         /etc/bootsplash/default
180         else
181                 echo "Error, cannot setup bootsplash theme ${clst_livecd_splash_theme}"
182                 exit 1
183         fi
184 elif [ "${clst_livecd_splash_type}" == "gensplash" -a -n \
185         "${clst_livecd_splash_theme}" ]
186 then
187         if [ -d /etc/splash/${clst_livecd_splash_theme} ]
188         then
189                 sed -i 's:# SPLASH_THEME="gentoo":SPLASH_THEME=\"${clst_livecd_splash_theme}\":' /etc/conf.d/splash
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 /usr/lib/hotplug/firmware/* /lib/firmware
208         fi
209         /bin/tar cjpf /lib/firmware.tar.bz2 .
210         rm -f /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/icon_theme Clearlooks
260                         gconftool-2 --direct \
261                                 --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults \
262                                 --type string --set /desktop/gnome/interface/theme Clearlooks
263                         gconftool-2 --direct \
264                                 --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults \
265                                 --type string --set /apps/metacity/general/theme Clearlooks
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                 # Setup GDM
280                 if [ "${clst_livecd_xdm}" == "gdm" ]
281                 then
282                         cp -f /etc/X11/gdm/gdm.conf /etc/X11/gdm/gdm.conf.old
283                         sed -e 's:TimedLoginEnable=false:TimedLoginEnable=true:' \
284                                 -e 's:TimedLoginDelay=30:TimedLoginDelay=10:' \
285                                 -e 's:AllowRemoteRoot=true:AllowRemoteRoot=false:' \
286                                 -e 's:#GraphicalTheme=circles:GraphicalTheme=gentoo-emergence:' \
287                                 -e ':^#GraphicalTheme=: s:^#::' \
288                                 -i /etc/X11/gdm/gdm.conf
289                         if [ -n "${clst_livecd_users}" -a -n "${first_user}" ]
290                         then
291                                 sed -e "s:TimedLogin=:TimedLogin=${first_user}:" \
292                                         -i /etc/X11/gdm/gdm.conf
293                         else
294                                 sed -e "s:TimedLogin=:TimedLogin=gentoo:" \
295                                         -i /etc/X11/gdm/gdm.conf
296                         fi
297                 fi
298
299                 # This gives us our list of system packages for the installer
300                 mkdir -p /usr/livecd
301                 USE="-* $(cat /var/db/pkg/sys-libs/glibc*/USE)" emerge -ep system | grep -e '^\[ebuild' | sed -e 's:^\[ebuild .\+\] ::' > /usr/livecd/systempkgs.txt
302
303                 # This is my hack to reduce tmpfs usage
304                 cp -r /usr/portage/profiles /usr/livecd
305                 cp -r /usr/portage/eclass /usr/livecd
306                 rm -rf /usr/livecd/profiles/{co*,default-{1*,a*,b*,d*,h*,i*,m*,p*,s*,x*},g*,hardened-*,n*,x*}
307                 mv -f /etc/gconf /usr/livecd
308                 mv -f /var/db /usr/livecd
309
310                 # This gives us a proper cache for portage/installer
311                 tar cjf /usr/livecd/metadata.tar.bz2 /var/cache/edb/dep/usr/portage
312
313                 # We remove kernel sources from our vdb
314                 rm -rf /usr/livecd/db/pkg/sys-kernel/*sources*
315
316                 # Clear out lastlog
317                 rm -f /var/log/lastlog && touch /var/log/lastlog
318
319                 # Create our installer icons
320                 if [ -e /usr/share/applications/installer-gli.desktop ]
321                 then
322                         if [ -n "${clst_livecd_users}" ]
323                         then
324                                 for username in ${clst_livecd_users}
325                                 do
326                                         mkdir -p /home/${username}/Desktop
327                                         cp /usr/share/applications/installer-gtk.desktop \
328                                                 /home/${username}/Desktop
329                                         cp /usr/share/applications/installer-faq.desktop \
330                                                 /home/${username}/Desktop
331                                         cp /usr/share/applications/installer-dialog.desktop \
332                                                 /home/${username}/Desktop
333                                         sed -e 's:Exec=installer:Exec=sudo installer:' \
334                                                 /home/${username}/Desktop/installer-dialog.desktop
335                                         sed -e 's:Exec=installer:Exec=sudo installer:' \
336                                                 /home/${username}/Desktop/installer-gtk.desktop
337                                         chown -R ${username}:100 /home/${username}
338                                 done
339                         fi
340                 fi
341                 ;;
342         generic-livecd )
343                 # This is my hack to reduce tmpfs usage
344                 mkdir -p /usr/livecd
345                 mv -f /etc/gconf /usr/livecd
346                 if [ -e /usr/livecd/grppkgs.txt ]
347                 then
348                         rm -f /usr/livecd/grppkgs.txt
349                 fi
350                 if [ -e /usr/livecd/kernelpkgs.txt ]
351                 then
352                         rm -f /usr/livecd/kernelpkgs.txt
353                 fi
354
355                 touch /etc/startx
356                 ;;
357         * )
358                 if [ -e /usr/livecd/grppkgs.txt ]
359                 then
360                         rm -f /usr/livecd/grppkgs.txt
361                 fi
362                 if [ -e /usr/livecd/kernelpkgs.txt ]
363                 then
364                         rm -f /usr/livecd/kernelpkgs.txt
365                 fi
366                 ;;
367 esac
368
369 # We want the first user to be used when auto-starting X
370 if [ -n "${clst_livecd_users}" -a -e /etc/startx ]
371 then
372         first_user=$(echo ${clst_livecd_users} | cut -d' ' -f1)
373         sed -i "s/##STARTX/source /etc/profile && su - $first_user -c startx/" \
374                 /root/.bashrc
375 fi
376
377 if [-e /lib/rcscripts/addons/udev-start.sh ]
378 then
379         sed -i "s:\t\[\[ -x /sbin/evms_activate:\t\[\[ -x \${CDBOOT} \]\] \&\& \[\[ -x /sbin/evms_activate:" /lib/rcscripts/addons/udev-start.sh
380 fi