Revert "livecdfs-update.sh: Escape ampersands in STARTX sed expression"
[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-live*)
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/portage/make.conf /etc/portage/make.conf.old
116 echo "####################################################" >> /etc/portage/make.conf
117 echo "## ATTENTION: THIS IS THE MAKE.CONF ON THE LIVECD ##" >> /etc/portage/make.conf
118 echo "## PLEASE EDIT /mnt/gentoo/etc/portage/make.conf INSTEAD  ##" >> /etc/portage/make.conf
119 echo "####################################################" >> /etc/portage/make.conf
120 cat /etc/portage/make.conf.old >> /etc/portage/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-live*)
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 # Clear out locales
224 case ${clst_livecd_type} in
225         gentoo-release-minimal|gentoo-release-universal|gentoo-gamecd)
226                 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}*
227         ;;
228 esac
229
230 # Post configuration
231 case ${clst_livecd_type} in
232         gentoo-gamecd )
233                 # We grab our configuration
234                 if [ -e /tmp/gamecd.conf ]
235                 then
236                         source /tmp/gamecd.conf || exit 1
237                         rm /tmp/gamecd.conf
238
239                         # Here we replace out game information into several files
240                         sed -i -e "s:##GAME_NAME:${GAME_NAME}:" /etc/motd
241
242                         # Here we setup our xinitrc
243                         echo "exec ${GAME_EXECUTABLE}" > /etc/X11/xinit/xinitrc
244                 fi
245
246                 # This is my hack to reduce tmpfs usage
247                 mkdir -p /usr/livecd/db/pkg/x11-base
248                 mv -f /var/db/pkg/x11-base/xorg* /usr/livecd/db/pkg/x11-base
249                 rm -rf /var/db
250
251                 touch /etc/startx
252                 ;;
253         gentoo-release-live*)
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/font_name "Sans 9"
260                 fi
261
262                 # Remove locking on screensaver
263                 gconftool-2 --direct \
264                         --config-source=xml:readwrite:/etc/gconf/gconf.xml.defaults -s \
265                         -t bool /apps/gnome-screensaver/lock_enabled false >/dev/null
266
267                 # Setup GDM
268                 if [ "${clst_livecd_xdm}" == "gdm" ]
269                 then
270                         if [ ! -e /etc/X11/gdm/gdm.conf ] && [ -e /usr/share/gdm/defaults.conf ]
271                         then
272                                 if [ -n "${clst_livecd_users}" ] && [ -n "${first_user}" ]
273                                 then
274                                         sedxtra="\nTimedLogin=${first_user}"
275                                 else
276                                         sedxtra=""
277                                 fi
278
279                                 cp -f /etc/X11/gdm/custom.conf /etc/X11/gdm/custom.conf.old
280
281                                 sed     -i \
282                                         -e "s:\(\[daemon\]\)$:\1\nTimedLoginEnable=true\nTimedLoginDelay=10${sedxtra}:" \
283                                         -e 's:\(\[greeter\]\)$:\1\nGraphicalTheme=gentoo-emergence:' \
284                                         /etc/X11/gdm/custom.conf
285                         else
286                                 cp -f /etc/X11/gdm/gdm.conf /etc/X11/gdm/gdm.conf.old
287                                 sed -i \
288                                         -e 's:TimedLoginEnable=false:TimedLoginEnable=true:' \
289                                         -e 's:TimedLoginDelay=30:TimedLoginDelay=10:' \
290                                         -e 's:AllowRemoteRoot=true:AllowRemoteRoot=false:' \
291                                         -e ':^#GraphicalTheme=: s:^#::' \
292                                         -e 's:^GraphicalTheme=.*$:GraphicalTheme=gentoo-emergence:' \
293                                         /etc/X11/gdm/gdm.conf
294
295                                 if [ -n "${clst_livecd_users}" ] && [ -n "${first_user}" ]
296                                 then
297                                         sed -i \
298                                                 -e "s:TimedLogin=:TimedLogin=${first_user}:" \
299                                                 /etc/X11/gdm/gdm.conf
300                                 fi
301                         fi
302                 fi
303
304                 # This gives us our list of system packages for the installer
305                 mkdir -p /usr/livecd
306                 ### XXX: Andrew says we don't need this anymore
307                 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
308
309                 # This is my hack to reduce tmpfs usage
310                 cp -r /usr/portage/profiles /usr/livecd
311                 cp -r /usr/portage/eclass /usr/livecd
312                 rm -rf /usr/livecd/profiles/{co*,default-{1*,a*,b*,d*,h*,i*,m*,p*,s*,x*},g*,hardened-*,n*,x*}
313                 mv -f /etc/gconf /usr/livecd
314                 ln -sf /usr/livecd/gconf /etc/gconf
315                 mv -f /var/db /usr/livecd
316                 ln -sf /usr/livecd/db /var/db
317
318                 # Clear out lastlog
319                 rm -f /var/log/lastlog && touch /var/log/lastlog
320
321                 # Create our Handbook icon
322                 [ -e /docs/handbook/index.html ] && create_handbook_icon
323                 [ -n "${clst_livecd_overlay}" ] && [ -e ${clst_livecd_overlay}/docs/handbook/index.html ] && create_handbook_icon
324
325                 # Copy our icons into place and build home directories
326                 if [ -n "${clst_livecd_users}" ]
327                 then
328                         for username in ${clst_livecd_users}
329                         do
330                                 mkdir -p /home/${username}/Desktop
331                                 # Copy our Handbook icon
332                                 [ -e /usr/share/applications/gentoo-handbook.desktop ] && \
333                                         cp -f /usr/share/applications/gentoo-handbook.desktop \
334                                         /home/${username}/Desktop
335                                 # Copy our installer icons
336                                 if [ -e /usr/share/applications/installer-gtk.desktop ]
337                                 then
338                                         cp -f /usr/share/applications/installer-gtk.desktop \
339                                                 /home/${username}/Desktop
340                                         cp -f /usr/share/applications/installer-dialog.desktop \
341                                                 /home/${username}/Desktop
342                                         sed -i -e \
343                                                 's:Exec=installer-dialog:Exec=sudo installer-dialog:' \
344                                                 /home/${username}/Desktop/installer-dialog.desktop
345                                         sed -i -e 's:Exec=installer-gtk:Exec=installer:' \
346                                                 /home/${username}/Desktop/installer-gtk.desktop
347                                 fi
348                                 chown -R ${username}:100 /home/${username}
349                         done
350                 fi
351                 ;;
352         generic-livecd )
353                 # This is my hack to reduce tmpfs usage
354                 mkdir -p /usr/livecd
355
356                 if [ -d /etc/gconf ]
357                 then
358                         mv -f /etc/gconf /usr/livecd
359                         ln -sf /usr/livecd/gconf /etc/gconf
360                 fi
361
362                 if [ -e /usr/livecd/kernelpkgs.txt ]
363                 then
364                         rm -f /usr/livecd/kernelpkgs.txt
365                 fi
366
367                 touch /etc/startx
368                 ;;
369         * )
370                 if [ -e /usr/livecd/kernelpkgs.txt ]
371                 then
372                         rm -f /usr/livecd/kernelpkgs.txt
373                 fi
374                 ;;
375 esac
376
377 # We want the first user to be used when auto-starting X
378 if [ -e /etc/startx ]
379 then
380         sed -i \
381                 "s:##STARTX:source /etc/profile && su - ${first_user} -c startx:" \
382                 /root/.bashrc
383 fi
384
385 if [ -e /lib/rcscripts/addons/udev-start.sh ]
386 then
387         sed -i "s:\t\[\[ -x /sbin/evms_activate:\t\[\[ -x \${CDBOOT} \]\] \&\& \[\[ -x /sbin/evms_activate:" /lib/rcscripts/addons/udev-start.sh
388 fi