Replace 'system' with '@system' where applicable, to be more greppable.
[catalyst.git] / targets / support / livecdfs-update.sh
old mode 100755 (executable)
new mode 100644 (file)
index c2faf7b..5aaa38e
@@ -1,11 +1,8 @@
 #!/bin/bash
-# Copyright 1999-2005 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo/src/catalyst/targets/support/livecdfs-update.sh,v 1.57 2006/07/26 22:38:45 wolf31o2 Exp $
 
-. /tmp/chroot-functions.sh
+RUN_DEFAULT_FUNCS="no"
 
-update_env_settings
+source /tmp/chroot-functions.sh
 
 # Allow root logins to our CD by default
 if [ -e /etc/sshd/sshd_config ]
@@ -17,6 +14,9 @@ fi
 # Turn off udev tarball
 sed -i 's:RC_DEVICE_TARBALL="yes":RC_DEVICE_TARBALL="no":' /etc/conf.d/rc
 
+# Turn off udev coldplugging
+sed -i 's:RC_COLDPLUG="yes":RC_COLDPLUG="no":' /etc/conf.d/rc
+
 # Clean up the time and set to UTC
 rm -rf /etc/localtime
 cp /usr/share/zoneinfo/UTC /etc/localtime
@@ -30,13 +30,26 @@ else
        echo 'HOSTNAME="livecd"' > /etc/conf.d/hostname
        echo "127.0.0.1 livecd.gentoo livecd localhost" > /etc/hosts
 fi
-echo 'OVERRIDE=0' > /etc/conf.d/domainname
-echo 'DNSDOMAIN="gentoo"' >> /etc/conf.d/domainname
+
+# Since we're an official Gentoo release, we do things the official Gentoo way.
+# As such, we override livecd/users.
+case ${clst_livecd_type} in
+       gentoo-release-live*)
+               user_comment="Gentoo default user"
+               clst_livecd_users="gentoo"
+       ;;
+       gentoo-gamecd)
+               user_comment="Gentoo GameCD default user"
+               clst_livecd_users="gamecd"
+       ;;
+esac
 
 # Add any users
 if [ -n "${clst_livecd_users}" ]
 then
        first_user=$(echo ${clst_livecd_users} | cut -d' ' -f1)
+       default_comment="Default LiveCD User"
+       [ -z "${user_comment}" ] && user_comment=${default_comment}
 
        # Here we check to see if games exists for bug #125498
        if [ "$(getent group games | cut -d: -f1)" != "games" ]
@@ -44,10 +57,16 @@ then
                echo "Adding games group"
                groupadd -g 35 games
        fi
+       if [ "$(getent group plugdev | cut -d: -f1)" != "plugdev" ]
+       then
+               echo "Adding plugdev group"
+               groupadd plugdev
+       fi
        for x in ${clst_livecd_users}
        do
-               useradd -G users,wheel,audio,games,cdrom,usb -c "Default LiveCD User" \
-                       -m ${x}
+               useradd -G users,wheel,audio,plugdev,games,cdrom,disk,floppy,usb \
+                       -g 100 -c "${user_comment}" -m ${x}
+               chown -R ${x}:users /home/${x}
                if [ -n "${clst_livecd_xdm}" -a -n "${clst_livecd_xsession}" ]
                then
                        echo "[Desktop]" > /home/${x}/.dmrc
@@ -73,8 +92,15 @@ ln -sf net.lo net.eth4
 # Add this for hwsetup/mkx86config
 mkdir -p /etc/sysconfig
 
+# Tweak the livecd fstab so that users know not to edit it
+# http://bugs.gentoo.org/show_bug.cgi?id=60887
+echo "####################################################" > /etc/fstab
+echo "## ATTENTION: THIS IS THE FSTAB ON THE LIVECD    ##" >> /etc/fstab
+echo "## PLEASE EDIT THE FSTAB at /mnt/gentoo/etc/fstab ##" >> /etc/fstab
+echo "####################################################" >> /etc/fstab
+
 # fstab tweaks
-echo "tmpfs    /                                       tmpfs   defaults        0 0" > /etc/fstab
+echo "tmpfs    /                                       tmpfs   defaults        0 0" >> /etc/fstab
 echo "tmpfs    /lib/firmware                   tmpfs   defaults        0 0" >> /etc/fstab
 echo "tmpfs    /usr/portage                    tmpfs   defaults        0 0" >> /etc/fstab
 # If /usr/lib/X11/xkb/compiled then make it tmpfs
@@ -84,19 +110,18 @@ then
                /etc/fstab
 fi
 
+# Tweak the livecd make.conf so that users know not to edit it
+# http://bugs.gentoo.org/show_bug.cgi?id=144647
+mv /etc/portage/make.conf /etc/portage/make.conf.old
+echo "####################################################" >> /etc/portage/make.conf
+echo "## ATTENTION: THIS IS THE MAKE.CONF ON THE LIVECD ##" >> /etc/portage/make.conf
+echo "## PLEASE EDIT /mnt/gentoo/etc/portage/make.conf INSTEAD  ##" >> /etc/portage/make.conf
+echo "####################################################" >> /etc/portage/make.conf
+cat /etc/portage/make.conf.old >> /etc/portage/make.conf
+
 # devfs tweaks
 [ -e /etc/devfsd.conf ] && sed -i '/dev-state/ s:^:#:' /etc/devfsd.conf
 
-# Tweak the livecd fstab so that users know not to edit it
-# http://bugs.gentoo.org/show_bug.cgi?id=60887
-mv /etc/fstab /etc/fstab.old
-echo "####################################################" >> /etc/fstab
-echo "## ATTENTION: THIS IS THE FSTAB ON THE LIVECD     ##" >> /etc/fstab
-echo "## PLEASE EDIT THE FSTAB at /mnt/gentoo/etc/fstab ##" >> /etc/fstab       
-echo "####################################################" >> /etc/fstab
-cat /etc/fstab.old >> /etc/fstab
-rm /etc/fstab.old
-
 # Add some helpful aliases
 echo "alias cp='cp -i'" >> /etc/profile
 echo "alias mv='mv -i'" >> /etc/profile
@@ -105,15 +130,28 @@ echo "alias ls='ls --color=auto'" >> /etc/profile
 echo "alias ll='ls -l'" >> /etc/profile
 echo "alias grep='grep --color=auto'" >> /etc/profile
 
-# Make sure we have the latest pci,usb and hotplug ids
+# Make sure we have the latest pci,usb and hotplug ids.  Older versions of
+# pciutils and usbutils used /sbin, where newer versions use /usr/sbin.
 [ -x /sbin/update-pciids ] && /sbin/update-pciids
 [ -x /sbin/update-usbids ] && /sbin/update-usbids
+[ -x /usr/sbin/update-pciids ] && /usr/sbin/update-pciids
+[ -x /usr/sbin/update-usbids ] && /usr/sbin/update-usbids
 if [ -d /usr/share/hwdata ]
 then
-       [ -f /usr/share/hwdata/pci.ids ] && rm -f /usr/share/hwdata/pci.ids
-       [ -f /usr/share/hwdata/usb.ids ] && rm -f /usr/share/hwdata/usb.ids
-       ln -s /usr/share/misc/pci.ids /usr/share/hwdata/pci.ids
-       ln -s /usr/share/misc/usb.ids /usr/share/hwdata/usb.ids
+       # If we have uncompressed pci and usb ids files, symlink them.
+       [ -f /usr/share/misc/pci.ids ] && [ -f /usr/share/hwdata/pci.ids ] && \
+               rm -f /usr/share/hwdata/pci.ids && ln -s /usr/share/misc/pci.ids \
+               /usr/share/hwdata/pci.ids
+       [ -f /usr/share/misc/usb.ids ] && [ -f /usr/share/hwdata/usb.ids ] && \
+               rm -f /usr/share/hwdata/usb.ids && ln -s /usr/share/misc/usb.ids \
+               /usr/share/hwdata/usb.ids
+       # If we have compressed pci and usb files, we download our own copies.
+       [ -f /usr/share/misc/pci.ids.gz ] && [ -f /usr/share/hwdata/pci.ids ] && \
+               rm -f /usr/share/hwdata/pci.ids && wget -O /usr/share/hwdata/pci.ids \
+               http://pciids.sourceforge.net/v2.2/pci.ids
+       [ -f /usr/share/misc/usb.ids.gz ] && [ -f /usr/share/hwdata/usb.ids ] && \
+               rm -f /usr/share/hwdata/usb.ids && wget -O /usr/share/hwdata/usb.ids \
+               http://www.linux-usb.org/usb.ids
 fi
 
 # Setup opengl in /etc (if configured)
@@ -122,8 +160,12 @@ fi
 # Setup configured display manager
 if [ -n "${clst_livecd_xdm}" ]
 then
-       sed -i "s:#DISPLAYMANAGER=\"xdm\":DISPLAYMANAGER=\"${clst_livecd_xdm}\":" \
+       sed -i \
+               -e "s:^#\\?DISPLAYMANAGER=.\+$:DISPLAYMANAGER=\"${clst_livecd_xdm}\":" \
                /etc/rc.conf
+       sed -i \
+               -e "s:^#\\?DISPLAYMANAGER=.\+$:DISPLAYMANAGER=\"${clst_livecd_xdm}\":" \
+               /etc/conf.d/xdm
 fi
 
 # Setup configured default X Session
@@ -136,24 +178,24 @@ fi
 # touch /etc/asound.state
 touch /etc/asound.state
 
-# Tweak the MOTD for Gentoo releases 
+# Tweak the MOTD for Gentoo releases
 case ${clst_livecd_type} in
-       gentoo-release-universal )
+       gentoo-release-universal)
                cat /etc/generic.motd.txt /etc/universal.motd.txt \
                        /etc/minimal.motd.txt > /etc/motd
                sed -i 's:^##GREETING:Welcome to the Gentoo Linux Universal Installation CD!:' /etc/motd
        ;;
-       gentoo-release-minimal )
+       gentoo-release-minimal)
                cat /etc/generic.motd.txt /etc/minimal.motd.txt > /etc/motd
                sed -i 's:^##GREETING:Welcome to the Gentoo Linux Minimal Installation CD!:' /etc/motd
        ;;
-       gentoo-release-livecd )
+       gentoo-release-live*)
                cat /etc/generic.motd.txt \
                        /etc/minimal.motd.txt /etc/livecd.motd.txt > /etc/motd
                sed -i -e 's:^##GREETING:Welcome to the Gentoo Linux LiveCD!:' \
                        -e "s:##DISPLAY_MANAGER:${clst_livecd_xdm}:" /etc/motd
        ;;
-       gentoo-gamecd )
+       gentoo-gamecd)
                cat /etc/generic.motd.txt /etc/gamecd.motd.txt > /etc/motd
                sed -i 's:^##GREETING:Welcome to the Gentoo Linux ##GAME_NAME GameCD!:' /etc/motd
        ;;
@@ -161,22 +203,8 @@ esac
 
 rm -f /etc/generic.motd.txt /etc/universal.motd.txt /etc/minimal.motd.txt /etc/livecd.motd.txt /etc/gamecd.motd.txt
 
-# Setup splash/bootsplash (if called for)
-if [ "${clst_livecd_splash_type}" == "bootsplash" -a -n \
-       "${clst_livecd_splash_theme}" ]
-then
-       if [ -d /etc/bootsplash/${clst_livecd_splash_theme} ]
-       then
-               sed -i 's:BOOTSPLASH_THEME=\"gentoo\":BOOTSPLASH_THEME=\"${clst_livecd_splash_theme}\":' /etc/conf.d/bootsplash
-               rm -f /etc/bootsplash/default
-               ln -s "/etc/bootsplash/${clst_livecd_splash_theme}" \
-                       /etc/bootsplash/default
-       else
-               echo "Error, cannot setup bootsplash theme ${clst_livecd_splash_theme}"
-               exit 1
-       fi
-elif [ "${clst_livecd_splash_type}" == "gensplash" -a -n \
-       "${clst_livecd_splash_theme}" ]
+# Setup splash (if called for)
+if [ -n "${clst_livecd_splash_theme}" ]
 then
        if [ -d /etc/splash/${clst_livecd_splash_theme} ]
        then
@@ -184,9 +212,6 @@ then
                        -e "s:# SPLASH_THEME=\"gentoo\":SPLASH_THEME=\"${clst_livecd_splash_theme}\":" \
                        -e "/^# SPLASH_TTYS=/ s/^#//" \
                        /etc/conf.d/splash
-               sed -i \
-                       -e 's/type}" cachedir "${spl_/type}" tmpfs "${spl_/' \
-                       /sbin/splash-functions.sh
                rm -f /etc/splash/default
                ln -s /etc/splash/${clst_livecd_splash_theme} /etc/splash/default
        else
@@ -202,15 +227,8 @@ fi
 if [ -n "$(ls /lib/firmware)" ]
 then
        cd /lib/firmware
-       if [ -n "$(ls /usr/lib/hotplug/firmware)" ]
-       then
-               cp -r /usr/lib/hotplug/firmware/* /lib/firmware
-       fi
-       /bin/tar cjpf /lib/firmware.tar.bz2 .
+       /bin/tar -I bzip2 -cpf /lib/firmware.tar.bz2 .
        rm -rf /lib/firmware/*
-       mkdir -p /usr/lib/hotplug
-       rm -rf /usr/lib/hotplug/firmware
-       ln -sf /lib/firmware /usr/lib/hotplug/firmware
 fi
 
 # Clear out locales
@@ -243,36 +261,20 @@ case ${clst_livecd_type} in
 
                touch /etc/startx
                ;;
-       gentoo-release-livecd )
-               # First we setup the livecd-kernel package
-               if [ -e /opt/installer/misc/mkvardb ]
-               then
-                       chmod +x /opt/installer/misc/mkvardb
-                       /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)
-               fi
-
+       gentoo-release-live*)
                # Setup Gnome theme
                if [ "${clst_livecd_xsession}" == "gnome" ]
                then
-                       gconftool-2 --direct \
-                               --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults \
-                               --type string --set /desktop/gnome/interface/theme Clearlooks
-                       gconftool-2 --direct \
-                               --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults \
-                               --type string --set /apps/metacity/general/theme Clearlooks
-                       gconftool-2 --direct \
-                               --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults \
-                               --type string --set /desktop/gnome/interface/gtk_key_theme \
-                               Clearlooks
-                       gconftool-2 --direct \
-                               --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults \
-                               --type string --set /desktop/gnome/interface/gtk_theme \
-                               Clearlooks
                        gconftool-2 --direct \
                                --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults \
                                --type string --set /desktop/gnome/interface/font_name "Sans 9"
                fi
 
+               # Remove locking on screensaver
+               gconftool-2 --direct \
+                       --config-source=xml:readwrite:/etc/gconf/gconf.xml.defaults -s \
+                       -t bool /apps/gnome-screensaver/lock_enabled false >/dev/null
+
                # Setup GDM
                if [ "${clst_livecd_xdm}" == "gdm" ]
                then
@@ -285,6 +287,8 @@ case ${clst_livecd_type} in
                                        sedxtra=""
                                fi
 
+                               cp -f /etc/X11/gdm/custom.conf /etc/X11/gdm/custom.conf.old
+
                                sed     -i \
                                        -e "s:\(\[daemon\]\)$:\1\nTimedLoginEnable=true\nTimedLoginDelay=10${sedxtra}:" \
                                        -e 's:\(\[greeter\]\)$:\1\nGraphicalTheme=gentoo-emergence:' \
@@ -308,58 +312,64 @@ case ${clst_livecd_type} in
                        fi
                fi
 
-
                # This gives us our list of system packages for the installer
                mkdir -p /usr/livecd
-               USE="-* $(cat /var/db/pkg/sys-libs/glibc*/USE)" emerge -ep system | grep -e '^\[ebuild' | sed -e 's:^\[ebuild .\+\] ::' > /usr/livecd/systempkgs.txt
+               ### XXX: Andrew says we don't need this anymore
+               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
 
                # This is my hack to reduce tmpfs usage
                cp -r /usr/portage/profiles /usr/livecd
                cp -r /usr/portage/eclass /usr/livecd
                rm -rf /usr/livecd/profiles/{co*,default-{1*,a*,b*,d*,h*,i*,m*,p*,s*,x*},g*,hardened-*,n*,x*}
                mv -f /etc/gconf /usr/livecd
+               ln -sf /usr/livecd/gconf /etc/gconf
                mv -f /var/db /usr/livecd
-
-               # This gives us a proper cache for portage/installer
-               tar cjf /usr/livecd/metadata.tar.bz2 /var/cache/edb/dep/usr/portage
-
-               # We remove kernel sources from our vdb
-               rm -rf /usr/livecd/db/pkg/sys-kernel/*sources*
+               ln -sf /usr/livecd/db /var/db
 
                # Clear out lastlog
                rm -f /var/log/lastlog && touch /var/log/lastlog
 
-               # Create our installer icons
-               if [ -e /usr/share/applications/installer-gtk.desktop ]
+               # Create our Handbook icon
+               [ -e /docs/handbook/index.html ] && create_handbook_icon
+               [ -n "${clst_livecd_overlay}" ] && [ -e ${clst_livecd_overlay}/docs/handbook/index.html ] && create_handbook_icon
+
+               # Copy our icons into place and build home directories
+               if [ -n "${clst_livecd_users}" ]
                then
-                       if [ -n "${clst_livecd_users}" ]
-                       then
-                               for username in ${clst_livecd_users}
-                               do
-                                       mkdir -p /home/${username}/Desktop
-                                       cp /usr/share/applications/installer-gtk.desktop \
-                                               /home/${username}/Desktop
-                                       cp /usr/share/applications/installer-faq.desktop \
+                       for username in ${clst_livecd_users}
+                       do
+                               mkdir -p /home/${username}/Desktop
+                               # Copy our Handbook icon
+                               [ -e /usr/share/applications/gentoo-handbook.desktop ] && \
+                                       cp -f /usr/share/applications/gentoo-handbook.desktop \
+                                       /home/${username}/Desktop
+                               # Copy our installer icons
+                               if [ -e /usr/share/applications/installer-gtk.desktop ]
+                               then
+                                       cp -f /usr/share/applications/installer-gtk.desktop \
                                                /home/${username}/Desktop
-                                       cp /usr/share/applications/installer-dialog.desktop \
+                                       cp -f /usr/share/applications/installer-dialog.desktop \
                                                /home/${username}/Desktop
-                                       sed -i -e 's:Exec=installer-dialog:Exec=installer dialog:' \
+                                       sed -i -e \
+                                               's:Exec=installer-dialog:Exec=sudo installer-dialog:' \
                                                /home/${username}/Desktop/installer-dialog.desktop
                                        sed -i -e 's:Exec=installer-gtk:Exec=installer:' \
                                                /home/${username}/Desktop/installer-gtk.desktop
-                                       chown -R ${username}:100 /home/${username}
-                               done
-                       fi
+                               fi
+                               chown -R ${username}:100 /home/${username}
+                       done
                fi
                ;;
        generic-livecd )
                # This is my hack to reduce tmpfs usage
                mkdir -p /usr/livecd
-               mv -f /etc/gconf /usr/livecd
-               if [ -e /usr/livecd/grppkgs.txt ]
+
+               if [ -d /etc/gconf ]
                then
-                       rm -f /usr/livecd/grppkgs.txt
+                       mv -f /etc/gconf /usr/livecd
+                       ln -sf /usr/livecd/gconf /etc/gconf
                fi
+
                if [ -e /usr/livecd/kernelpkgs.txt ]
                then
                        rm -f /usr/livecd/kernelpkgs.txt
@@ -368,10 +378,6 @@ case ${clst_livecd_type} in
                touch /etc/startx
                ;;
        * )
-               if [ -e /usr/livecd/grppkgs.txt ]
-               then
-                       rm -f /usr/livecd/grppkgs.txt
-               fi
                if [ -e /usr/livecd/kernelpkgs.txt ]
                then
                        rm -f /usr/livecd/kernelpkgs.txt
@@ -383,7 +389,7 @@ esac
 if [ -e /etc/startx ]
 then
        sed -i \
-               "s/##STARTX/source /etc/profile && su - ${first_user} -c startx/" \
+               "s:##STARTX:source /etc/profile \&\& su - ${first_user} -c startx:" \
                /root/.bashrc
 fi