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