Fix some exception handling in catalyst_support.py
[catalyst.git] / targets / support / livecdfs-update.sh
1 #!/bin/bash
2 # Copyright 1999-2004 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.11 2005/04/21 14:23:12 rocket Exp $
5
6 . /tmp/chroot-functions.sh
7 update_env_settings
8
9 # allow root logins to the livecd by default
10 if [ -e /etc/sshd/sshd_config ]
11 then
12         sed -i 's:^#PermitRootLogin\ yes:PermitRootLogin\ yes:' /etc/ssh/sshd_config
13 fi
14
15 # turn off udev tarball
16 sed -i 's:RC_DEVICE_TARBALL="yes":RC_DEVICE_TARBALL="no":' /etc/conf.d/rc
17
18 # Comment out current getty settings
19 sed -i -e '/^c[0-9]/ s/^/#/' /etc/inittab
20
21 # Add our own getty settings
22 for x in 1 2 3 4 5 6
23 do
24         echo "c${x}:12345:respawn:/sbin/agetty -nl /bin/bashlogin 38400 tty${x} linux" >> /etc/inittab
25 done
26
27 # Do some livecd_type specific inittab changes
28 case ${clst_livecd_type} in
29         gnap)
30                 sed -i "s/^#c1:/c1:/" /etc/inittab
31                 sed -i "/^.*bashlogin.*$/ d" /etc/inittab
32         ;;
33 esac
34
35 # clean up the time and set to UTC
36 rm -rf /etc/localtime
37 cp /usr/share/zoneinfo/UTC /etc/localtime
38
39 # setup the hostname
40 case ${clst_livecd_type} in
41         gnap)
42                 echo "gentoo" > /etc/dnsdomainname
43                 echo "127.0.0.1 livecd.gentoo livecd localhost" > /etc/hosts
44                 ;;
45         gentoo-gamecd)
46                 echo "gamecd" > /etc/hostname
47                 echo "gentoo" > /etc/dnsdomainname
48                 echo "127.0.0.1 gamecd.gentoo gamecd localhost" > /etc/hosts
49                 ;;
50         gentoo-*)
51                 echo "livecd" > /etc/hostname
52                 echo "gentoo" > /etc/dnsdomainname
53                 echo "127.0.0.1 livecd.gentoo livecd localhost" > /etc/hosts
54                 ;;
55         *)
56                 echo "catalyst-livecd" > /etc/hostname
57                 echo "gentoo" > /etc/dnsdomainname
58                 echo "127.0.0.1 catalyst-livecd.gentoo livecd localhost" > /etc/hosts
59                 ;;
60 esac
61
62 # Add any users
63 if [ -n "${clst_livecd_users}" ]
64 then
65         for x in ${clst_livecd_users}
66         do
67                 useradd -G users,wheel,audio,games,cdrom,usb -c "Default LiveCD User" -m $x
68         done
69 fi
70
71 # setup sudoers
72 if [ -f /etc/sudoers ]
73 then
74         sed -i '/NOPASSWD: ALL/ s/^# //' /etc/sudoers
75 fi
76
77 # we want the first user to be used when auto-starting X
78 if [ -n "${clst_livecd_users}" -a -e /etc/startx ]
79 then
80         first_user=$(echo ${clst_livecd_users} | cut -d' ' -f1)
81         sed -i "s/startx/su - $first_user -c startx/" /root/.bashrc
82 fi
83
84 # setup dhcp on all detected ethernet devices
85 echo "iface_eth0=\"dhcp\""> /etc/conf.d/net
86 echo "iface_eth1=\"dhcp\"" >> /etc/conf.d/net
87 echo "iface_eth2=\"dhcp\"" >> /etc/conf.d/net
88 echo "iface_eth3=\"dhcp\"" >> /etc/conf.d/net
89 echo "iface_eth4=\"dhcp\"" >> /etc/conf.d/net
90
91 # setup links for ethernet devices
92 cd /etc/init.d
93 ln -sf net.eth0 net.eth1
94 ln -sf net.eth0 net.eth2
95 ln -sf net.eth0 net.eth3
96 ln -sf net.eth0 net.eth4
97
98 # add this for hwsetup/mkx86config
99 mkdir -p /etc/sysconfig
100
101 # fstab tweaks
102 echo "tmpfs     /                                       tmpfs   defaults        0 0" > /etc/fstab
103 echo "tmpfs     /lib/firmware                   tmpfs   defaults        0 0" >> /etc/fstab
104 # if /usr/lib/X11/xkb/compiled then make it tmpfs
105 if [ -d /usr/lib/X11/xkb/compiled ]
106 then
107         echo "tmpfs     /usr/lib/X11/xkb/compiled       tmpfs   defaults        0 0" >> /etc/fstab
108 fi
109
110 # devfs tweaks
111 sed -i '/dev-state/ s:^:#:' /etc/devfsd.conf
112
113 # tweak the livecd fstab so that users know not to edit it
114 # http://bugs.gentoo.org/show_bug.cgi?id=60887
115 mv /etc/fstab /etc/fstab.old
116 echo "####################################################" >> /etc/fstab
117 echo "## ATTENTION: THIS IS THE FSTAB ON THE LIVECD     ##" >> /etc/fstab     
118 echo "## PLEASE EDIT THE FSTAB at /mnt/gentoo/etc/fstab ##" >> /etc/fstab     
119 echo "####################################################" >> /etc/fstab
120 cat /etc/fstab.old >> /etc/fstab
121 rm /etc/fstab.old
122
123 # add some helpful aliases
124 echo "alias cp='cp -i'" >> /etc/profile
125 echo "alias mv='mv -i'" >> /etc/profile
126 echo "alias rm='rm -i'" >> /etc/profile
127 echo "alias ls='ls --color=auto'" >> /etc/profile
128 echo "alias grep='grep --color=auto'" >> /etc/profile
129
130 # make sure we have the latest pci and hotplug ids
131 if [ -d /usr/share/hwdata ]
132 then
133         [ -f /usr/share/hwdata/pci.ids ] && rm -f /usr/share/hwdata/pci.ids
134         [ -f /usr/share/hwdata/usb.ids ] && rm -f /usr/share/hwdata/usb.ids
135         ln -s /usr/share/misc/pci.ids /usr/share/hwdata/pci.ids
136         ln -s /usr/share/misc/usb.ids /usr/share/hwdata/usb.ids
137 fi
138
139 # setup opengl in /etc (if configured)
140 #[ -x /usr/sbin/openglify ] && /usr/sbin/openglify
141 mkdir -p /etc/opengl
142
143 # touch /etc/asound.state
144 touch /etc/asound.state
145
146 # tweak the motd for gentoo releases 
147 case ${clst_livecd_type} in
148         gentoo-release-universal )
149                 cat /etc/generic.motd.txt /etc/universal.motd.txt \
150                         /etc/minimal.motd.txt > /etc/motd
151                 sed -i 's:^##GREETING:Welcome to the Gentoo Linux Universal Installation CD!:' /etc/motd
152         ;;
153         gentoo-release-minimal )
154                 cat /etc/generic.motd.txt /etc/minimal.motd.txt > /etc/motd
155                 sed -i 's:^##GREETING:Welcome to the Gentoo Linux Minimal Installation CD!:' /etc/motd
156         ;;
157         gentoo-release-livecd )
158                 cat /etc/generic.motd.txt /etc/universal.motd.txt \
159                         /etc/minimal.motd.txt /etc/livecd.motd.txt > /etc/motd
160                 sed -i 's:^##GREETING:Welcome to the Gentoo Linux LiveCD!:' /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 "${clst_livecd_splash_theme}" ]
172 then
173         if [ -d /etc/bootsplash/${clst_livecd_splash_theme} ]
174         then
175                 sed -i 's:BOOTSPLASH_THEME=\"gentoo\":BOOTSPLASH_THEME=\"${clst_livecd_splash_theme}\":' /etc/conf.d/bootsplash
176                 rm /etc/bootsplash/default
177                 ln -s "/etc/bootsplash/${clst_livecd_splash_theme}" /etc/bootsplash/default
178         else
179                 echo "Error, cannot setup bootsplash theme ${clst_livecd_splash_theme}"
180                 exit 1
181         fi
182
183 elif [ "${clst_livecd_splash_type}" == "gensplash" -a -n "${clst_livecd_splash_theme}" ]
184 then
185         if [ -d /etc/splash/${clst_livecd_splash_theme} ]
186         then
187                 sed -i 's:# SPLASH_THEME="gentoo":SPLASH_THEME=\"${clst_livecd_splash_theme}\":' /etc/conf.d/splash
188                 rm /etc/splash/default
189                 ln -s /etc/splash/${clst_livecd_splash_theme} /etc/splash/default
190         else
191                 echo "Error, cannot setup splash theme ${clst_livecd_splash_theme}"
192                 exit 1
193         fi
194 fi
195
196 # Create firmware directory if it does not exist
197 [ ! -d /lib/firmware ] && mkdir -p /lib/firmware
198
199 # tar up the firmware so that it does not get clobbered by the livecd mounts
200 if [ -n "$(ls /lib/firmware)" ]
201 then
202         cd /lib/firmware
203         if [ -n "$(ls /usr/lib/hotplug/firmware)" ]
204         then
205                 cp /usr/lib/hotplug/firmware/* /lib/firmware
206         fi
207         tar cvjpf /lib/firmware.tar.bz2 .
208         rm -f /lib/firmware/*
209         mkdir -p /usr/lib/hotplug
210         rm -rf /usr/lib/hotplug/firmware
211         ln -sf /lib/firmware /usr/lib/hotplug/firmware
212 fi
213
214 # Post configuration
215 case ${clst_livecd_type} in
216         gentoo-gamecd )
217                 # we grab our configuration
218                 if [ -e /tmp/gamecd.conf ]
219                 then
220
221                     source /tmp/gamecd.conf || exit 1
222                     rm /tmp/gamecd.conf
223
224                     # here we replace out game information into several files
225                     sed -i -e "s:##GAME_NAME:${GAME_NAME}:" /etc/motd
226
227                     # here we setup our xinitrc
228                     echo "exec ${GAME_EXECUTABLE}" > /etc/X11/xinit/xinitrc
229                 fi
230
231                 # This is my hack to reduce tmpfs usage
232                 mkdir -p /usr/livecd/db/pkg/x11-base
233                 mv -f /var/db/pkg/x11-base/xorg* /usr/livecd/db/pkg/x11-base
234                 rm -rf /var/db
235
236                 touch /etc/startx
237                 ;;
238         gentoo-release-livecd )
239                 # first we setup the livecd-kernel package
240                 if [ -e /opt/installer/misc/mkvardb ]
241                 then
242                         chmod +x /opt/installer/misc/mkvardb
243                         /opt/installer/misc/mkvardb -p livecd-kernel -c sys-kernel -v 2005.0 /boot/kernel* /boot/initrd* $(for i in $(find "/lib/modules/$(uname -r)" -type f); do grep --quiet "${i}" /var/db/pkg/*/*/CONTENTS || echo ${i}; done)
244                 fi
245
246                 # This is my hack to reduce tmpfs usage
247                 mkdir -p /usr/livecd
248                 mv -f /usr/portage/profiles /usr/livecd
249                 rm -rf /usr/livecd/profiles/{co*,default-{1*,a*,b*,d*,h*,i*,m*,p*,s*,x*},g*,hardened-*,n*,x*}
250                 mv -f /etc/gconf /usr/livecd
251                 mv -f /var/db /usr/livecd
252                 ;;
253         generic-livecd )
254                 # This is my hack to reduce tmpfs usage
255                 mkdir -p /usr/livecd
256                 mv -f /etc/gconf /usr/livecd
257
258                 touch /etc/startx
259                 ;;
260 esac
261