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