inst_xgl.sh

inst_xgl.sh

#!/bin/bash 

# inst_xgl.sh:
#
# Install OpenGL and Xgl support for ATI [and NVIDIAs] graphic cards.
# Particular tasks are:
# - Upgrade Linux-kernel to the latest version.
# - Install OpenGL drivers for ATI or nVidia.
#   ATI's fglrx driver supports Radeon 8500+ and the X-series cards up to X850.
# - Install Xgl modules for Xorg.7
# - Install some other gadgets such as wallpaper, desktop search(beagle) and firestarter.
# 
# This code modifies the following files. You'll find a backup in the same directory as the file itself.
#	/etc/apt/sources.list
#	/etc/X11/xorg.conf
#	/etc/gdm/gdm.conf
#	/etc/gdm/gdm.conf-custom
#	$HOME/.Xsession
#
# Return the files into their original state if you're going to follow other Xgl-guides.
#
# Usage:
# $ sudo sh inst_xgl.sh 
#
# Related information:
# 
# o--> http://www.ubuntuforums.org/showthread.php?t=148351 
# 
# https://wiki.ubuntu.com/QuinnsXglAndCompizHowto?highlight=%28compiz%29%7C%28xgl%29
#
# https://wiki.ubuntu.com/XglHowto
#
# http://placelibre.ath.cx/keyes/
#
# http://www.ubuntuforums.org/showthread.php?t=148351
# http://www.ubuntuforums.org/showthread.php?t=131267
# http://ubuntuforums.org/showthread.php?t=127090
#
# ATI: http://wiki.cchtml.com/index.php/Ubuntu_Installation_Guide#Ubuntu_6.04_.28Dapper_Drake.29
# 
# NVIDIA: http://easylinux.info/wiki/Ubuntu_dapper#How_to_install_Xgl.2FCompiz_.28Nvidia.29
#         http://ueluei.blogspot.com/2006/03/xgl-on-ubuntu-for-nvidia-users.html
#
# I you run KDE/Kubuntu: http://www.ubuntuforums.org/showthread.php?t=131253
#                      
# SuSE provides these instructions: http://www.suseblog.com/?p=62
#
# ------------------------------------------------------------------------
# History:
# 15.march.2006  moma : 
# + Version 0.1 of this bash script.

# 16.march.2006  moma : 
# + Improved identification of CPU type in the upgrade_kernel() function.
# + Fixed error on backup of /etc/gdm/gdm.conf* and $HOME/.Xsession.
# + Thanks to Ufc (forum.ubuntu-fi.org).
# 
# + Removed unnecessary usage of sudo. Sudo/root privilege is checked by check_root(). 
# + Check the presence of ATI or NVIDIA cards before any other actions.
# + Thanks to LittleLion (forum.ubuntu-fi.org).
# 
# + Added support for NVIDIA video cards.
#
# 19.march.2006  moma : 
# + GNOME-desktop is now compulsory. Added check_GNOME() function.
# + My impression is that Xgl/Compiz on KDE doesn't work very well yet.
#
# + Added a penguin (svg image) on the roof of the cube.
# + You can change the image. 
# + Start 'gconf-editor' and browse to: apps -> compiz -> plugins -> cube...
# 
# + Downloaded some nice wallpapers into $HOME/wallpaper/
# + Install advanced tools for local desktop search (beagled, beagle-search).
#
# 27.march.2006  moma : 
# + I had to comment out some "apt-get remove ..." statements because they also 
# + removed drivers for nvidia.  You can bring the drivers back by doing:
# + sudo apt-get install --reinstall linux-686  (or linux-k7).
#   
# 28.march.2006  moma : 
# + check_distro_release() function will now accept both Ubuntu 6.04 and 6.06.
#
# 07.june.2006  moma : 
# + INST_SKYDOME=0 disables installation of skydome.

# ------------------------------------------------------------------------

# This must be "GNOME" 
DESK="GNOME"

# If 1, then install skydome effects; background image and a svg-image 
# on the top side of the cube.  Study: http://macslow.thepimp.net/?p=31
INST_SKYDOME=0
SKYDOME_FILES="http://www.ubuntuforums.org/attachment.php?attachmentid=6740&d=1141567636"

# Templates and utilities on http://www.futuredesktop.org/dapper/
UTILITY_DIR="http://home.online.no/~osmoma/dapper/"

check_root () {
  xit=$1;shift
  msg=$@
  if [ "$UID" -ne "0" ]; then
    echo $msg
    if [ ${xit:-"0"} -eq "1" ]; then
      exit -1
    fi
  fi
}

# ------------------------------------------

die () {
  echo "Error:$1"
  exit -1	
}

# ------------------------------------------

debug () {
if test ${DEBUG_INST:-0} -ne 0; then
  echo "$@"
fi 
}

# ------------------------------------------

get_User()
{
 if [ -n "$USERNAME" ]; then 
   echo "$USERNAME"
 else
   echo $(echo $HOME | sed 's/^.*home\///' | sed 's/\/.*$//')
 fi 
}

# ------------------------------------------

backup_file()
{
 fil="$1"; shift

 if [ ! -f "$fil" ]; then 
   echo "Error: \"$fil\" does not exist !"
   return  -1
 fi 

 cp --backup=t "$fil" "$fil.backup"
}

# ------------------------------------------

upgrade_kernel()
{
 echo "Checking kernel version."

 kern=$(uname -r)

 case $kern in 
 *-386) 
     if (cat /proc/cpuinfo | grep -i "model name"  | grep "AMD"); then 
         new_kern="AMD Linux-k7"
         apt-get -y install --reinstall linux-k7  linux-restricted-modules-k7  linux-restricted-modules-$(uname -r)
     else
         new_kern="Linux-686"
         apt-get -y install --reinstall linux-686  linux-restricted-modules-686 linux-restricted-modules-$(uname -r)
     fi

     echo "Installation of new kernel ($new_kern) is ready."

     echo; echo
     echo 
     echo "Reboot your PC and choose the latest kernel by selecting the top-most menu-selection from the GRUB-menu. Re-run this script after reboot to complete the setup of Xgl. (\"sudo sh $0\")"
     echo 
     exit 2
  ;;

 *-k7) 
     apt-get -y install linux-restricted-modules-k7 linux-restricted-modules-$(uname -r)
     apt-get -y install --reinstall linux-k7
     echo "Kernel $kern is OK."
  ;;
 
 *-686*) 
     apt-get -y install linux-restricted-modules-686 linux-restricted-modules-$(uname -r)
     apt-get -y install --reinstall linux-686
     echo "Kernel $kern is OK."
  ;;

 esac  
}

# ------------------------------------------

check_distro_release()
{
 rel="$1"; shift
 msg="$@"

 echo -e  "Checking Linux distribution and version. Expecting Ubuntu 6.04 or 6.06.\n"
 cat /etc/*release*
 echo; echo  

 if (! cat /etc/*release* | egrep -qi "$rel"); then 
   echo "Error: $msg"
   exit -2
 fi 

 echo -e "Distro and version are OK.\n"
}

# ------------------------------------------

check_GNOME()
{
 msg="$@"; shift
 if [ -f /etc/init.d/gdm ] || [ -d /etc/gdm/ ]; then 
    return 0
 else
   echo -e "\n${msg}\n"; 
   exit -4;
 fi  
}

update_system()
{
 pushd . 

 # Check sources.list 
 if (! grep -qi "Dapper Drake:" /etc/apt/sources.list ); then  
   # make backup
   backup_file /etc/apt/sources.list 

   cd /tmp
   rm sources.list 
 
   wget -c "$UTILITY_DIR/sources.list"
   if [ -f sources.list ]; then 
     cp sources.list /etc/apt 
   fi 
 fi 

 echo -e "Updating system and program files.\n"

 dpkg --configure -a

 apt-get update
 apt-get -y upgrade 

 echo -e "\nSystem is now up-to-date.\n"
 popd
}

# ------------------------------------------

check_ATI_Nvidia()
{
  msg=$1; shift

  CARD=$( graphic_card )

  if test "x$CARD" = "x"; then 
   echo -e "\n$msg\n"
   exit -3
  fi
}

graphic_card()
{
 #  ATI
 #  NVIDIA
 #  or not supported card

 lspci | egrep -i "VGA|Display" | grep -qi "ATI Technologies"
 if [ $? -eq 0 ]; then 
   echo "ATI" 
 fi 

 lspci | egrep -i "VGA|Display" | grep -qi "Nvidia"
 if [ $? -eq 0 ]; then 
  echo "NVIDIA"
 fi

 echo ""
}

# ------------------------------------------
setup_OpenGL_NVIDIA()
{
 echo -e "\n Install Nvidia's graphic driver\n"

 # Make backup 
 backup_file /etc/X11/xorg.conf 

 apt-get -y remove xorg-common

 # Reinstall 
 apt-get -y install nvidia-kernel-common nvidia-glx

 # Load 'nvidia' at next boot
 chmod 0666 /etc/modules
 grep nvidia /etc/modules || echo nvidia >> /etc/modules
 chmod 0644 /etc/modules

 nvidia-glx-config enable

 # Modify /etc/X11/xorg.conf 

 # Comment out 'Load "dri"   '
 sed -e 's/^[ \t]*Load[ \t]*"dri"/## Load 	"dri"/' -i /etc/X11/xorg.conf 

 # Comment out 'Load "GLcore"  '
 sed -e 's/^[ \t]*Load[ \t]*"GLcore"/## Load 	"GLcore"/' -i /etc/X11/xorg.conf 

 # Driver  "nvidia"
 sed -e 's/"nv"/"nvidia"/' -i /etc/X11/xorg.conf 

 # Driver  "nvidia"
 sed -e 's/"vesa"/"nvidia"/' -i /etc/X11/xorg.conf 

 # Final fix 
 nvidia-xconfig
}

# ------------------------------------------

setup_OpenGL_ATI()
{
 echo -e "\n Install ATI's fglrx graphic driver\n"

 # make backup 
 backup_file /etc/X11/xorg.conf 

 apt-get -y remove xorg-common

 # Reinstall
 # apt-get -y install --reinstall xorg-driver-fglrx xorg-driver-fglrx-dev xserver-xorg-driver-ati
 apt-get -y install xorg-driver-fglrx xorg-driver-fglrx-dev xserver-xorg-driver-ati

 # Load 'fglrx' at next boot
 chmod 0666 /etc/modules
 grep fglrx /etc/modules || echo fglrx >> /etc/modules
 chmod 0644 /etc/modules

 # Generate initial values
 aticonfig --initial

 # Configure xorg.conf manually
 sudo dpkg-reconfigure xserver-xorg

 # Replace 'ati' with 'fglrx'
 sed -e 's/"ati"/"fglrx"/' -i /etc/X11/xorg.conf 

}

# ------------------------------------------

setup_OpenGL()
{
  case $( graphic_card ) in 

    ATI*) 
      echo "Found an ATI graphic card..."
      setup_OpenGL_ATI
      ;;

    NVI*) 
      echo "Found a NVIDIA graphic card..."
      setup_OpenGL_NVIDIA
      ;;

    *) echo -e "Your graphic card is not supported!"; exit -1
    ;;

  esac
}

# ------------------------------------------

setup_Xgl()
{

 apt-get update 

 # Purge it 
 # apt-get -y remove --purge libglitz1 libglitz-glx1 xserver-xgl compiz compiz-gnome compiz-kde 

 # Reinstall
 # apt-get -y install --reinstall libgl1-mesa libglitz1 libglitz-glx1 xserver-xgl compiz 
 apt-get -y install libgl1-mesa libglitz1 libglitz-glx1 xserver-xgl compiz 

 apt-get -y install gset-compiz

 case "$DESK" in 
   [Kk][dD][eE]*) apt-get -y install compiz-kde 
   ;;

   *) apt-get -y install compiz-gnome 
   ;;
 esac

 # Set transparency of a window (transset 0.5)
 apt-get -y install transset

 # -----------------------------------------------
 # Skydome effects

 if test $INST_SKYDOME -eq 1; then 
   pushd .

   cd /tmp
   rm -fr compiz*
   wget --force-html -O compizskydome.tar.gz  "$SKYDOME_FILES"
   
   tar -xvzf compizskydome.tar.gz 
   cd compiz_*

   # Remove KDE related debs
   rm  *-kde*deb

   # Update compiz and libsvg* for GNOME
   if [ -s compiz-gnome* ]; then 
    
     INSTALLED_VERSION=$(dpkg -I /var/cache/apt/archives/compiz-gnome* | grep Version)
     THIS_VERSION=$(dpkg -I compiz-gnome*deb | grep Version)

     echo "Installed Compiz is: $INSTALLED_VERSION  ----  This Compiz is: $THIS_VERSION"

     if [[ "$THIS_VERSION" > "$INSTALLED_VERSION" ]]; then  
         dpkg -i *deb
     fi
   fi 

   popd
 fi 
 # -----------------------------------------------

 # Get a beautiful splash image. It is shown immediately after the login dialog.
 pushd . 
 cd /tmp
 rm -fr background*  *svg *png

 wget -c "$UTILITY_DIR/background.tar.gz"
 tar -xvzf background.tar.gz
 mv -f background.png /usr/share/compiz/

 # ---
 # Put a SVG-image on the top of the cube. D/L it from http://openclipart.org
 wget http://openclipart.org/clipart/animals/emperor_penguin_ralf_ste_01.svg
 if test ! -f emperor_penguin_ralf_ste_01.svg; then 
   wget http://upload.wikimedia.org/wikipedia/en/1/15/Svg.svg
   mv Svg.svg /usr/share/compiz/roof_image.svg
 else
   mv  emperor_penguin_ralf_ste_01.svg /usr/share/compiz/roof_image.svg
 fi 
 popd

 # -----------------------------------------------
 # Config files

 CARD=$( graphic_card )

 # Get USER
 ACTUAL_USER=$(get_User)

 # ------Edit $HOME/.Xsession----------------------

 XSESS="$HOME/.Xsession"

 touch "$XSESS"
 backup_file "$XSESS"

 pushd . 
 cd /tmp

 rm Xsession* $XSESS 2>/dev/null 

 wget "$UTILITY_DIR/Xsession.$CARD"
 cp -f "Xsession.$CARD" "$XSESS"

 chmod +x "$XSESS"
 chown -R $ACTUAL_USER:$ACTUAL_USER "$XSESS"

 # Add keyboard layout
 KB=$(grep XkbLayout /etc/X11/xorg.conf | sed 's/^.*Layout"//' | sed 's/[" \t]//g')

 # sudo echo "xmodmap /usr/share/xmodmap/xmodmap.${KB}" >> "$XSESS"
 sed -e "s/KBD-REPLACE-THIS/$KB/" -i "$XSESS"

 # Create initial $HOME/.gconf/apps/compiz folder (for 'gconf-editor')
 wget "$UTILITY_DIR/compiz.tar"

 tar -xvf compiz.tar -C $HOME/.gconf/apps/
 chown -R $ACTUAL_USER:$ACTUAL_USER  $HOME/.gconf/apps/compiz

 popd

# ------Get /etc/gdm/gdm.conf* --------------------

 backup_file "/etc/gdm/gdm.conf"
 backup_file "/etc/gdm/gdm.conf-custom"

 pushd .
 cd /tmp

 rm gdm.conf*

 # Download either: gdm.conf.ATI or gdm.conf.NVIDIA etc.
 wget -c "$UTILITY_DIR/gdm.conf.$CARD"
 wget -c "$UTILITY_DIR/gdm.conf-custom.$CARD"

 cp -f "gdm.conf.$CARD" /etc/gdm/gdm.conf 
 cp -f "gdm.conf-custom.$CARD" /etc/gdm/gdm.conf-custom

 popd 


 # Set "s" superuser bit on /usr/bin/Xgl
 sudo chmod --reference=/usr/bin/X /usr/bin/Xgl 


 # Prepare directory list over dynamic libraries (/etc/ld.so.conf)
 touch /etc/ld.so.conf
 grep -qi "/usr/lib" /etc/ld.so.conf || echo "/usr/lib" >> /etc/ld.so.conf
 grep -qi "/usr/local/lib" /etc/ld.so.conf || echo "/usr/local/lib" >> /etc/ld.so.conf
 grep -qi "/usr/X11R6/lib" /etc/ld.so.conf || echo "/usr/X11R6/lib" >> /etc/ld.so.conf

 # update library cache
 ldconfig 
}

# ------------------------------------------

setup_necessities()
{
  
 # To set Norwegian keyboard support
 apt-get -y install xkbsel xkbutils

 # Basic compilers
 apt-get -y install build-essential

 # FTP-file transafer, manuals and mc(file manager)
 apt-get -y install gftp manpages mc 

 # Cd/DVD burner 
 apt-get -y install gnomebaker streamtuner streamripper

 # Firestarter firewall front-end & BUM (service manager)
 apt-get -y install firestarter bum 


 # Load a some nice wallpaper
 pushd .
 mkdir $HOME/wallpaper; cd $HOME/wallpaper

 wget -c "ftp://mirror.linuxsoft.cz/wallpapers/69/wall--12120013022003.jpg"
 wget -c "ftp://mirror.linuxsoft.cz/wallpapers/242/928-2.jpg"
 wget -c http://tinyurl.com/bkyo2  http://tinyurl.com/b5f9z  http://tinyurl.com/7bkso 
 wget -c "http://art.gnome.org/download/backgrounds/gnome/1221/GNOME-GnomeGallery_1280x1024.png"

 ACTUAL_USER=$(get_User)

 sudo -u "$ACTUAL_USER" gconftool-2 --set --type=string /desktop/gnome/background/picture_filename "$HOME/wallpaper/GNOME-GnomeGallery_1280x1024.png"

# "$HOME/wallpaper/928-2.jpg"

 chown -R $ACTUAL_USER:$ACTUAL_USER "$HOME/wallpaper/"

 echo "You'll find other wallpapers in $HOME/wallpaper/"

 # ----
 # Install tools for advanced desktop search. Get Beagle (beagle-search).
 apt-get -y install beagle  
 
 # Create an icon and shortcut 
 echo "[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Exec=beagle-search
TryExec=
Icon=/usr/share/pixmaps/system-search.png
X-GNOME-DocPath=
Terminal=false
Name[en_NO]=Desktop search
GenericName[en_NO]=
Comment[en_NO]=" >  "$HOME/Desktop/Desktop search.desktop"

 # Change owner 
 chown "$ACTUAL_USER":"$ACTUAL_USER" "$HOME/Desktop/Desktop search.desktop"

 # Re/start beagle dameon
 sudo -u "$ACTUAL_USER" beagled --replace & 

 popd

 # Refresh panels & menus
 killall gnome-panel 
}

# ------------------------------------------

xorg_config()
{

echo -e "\n1) Check your /etc/X11/xorg.conf. The \"Modules\" and keyborad's \"InputDevice\" sections should be similar to this:\n"

CARD=$( graphic_card )
if test "$CARD" = "NVIDIA"; then 

cat << EOF
Section "Module"
        Load    "bitmap"
        Load    "ddc"
        Load    "extmod"
        Load    "freetype"
        Load    "glx"
        Load    "int10"
        Load    "type1"
        Load    "vbe"
EndSection

Section "Device"
	# Note! This identifier name is used in the "Screen" section.
	Identifier "nVidia display driver"

	# Note!  Use "nvidia" instead of "nv".  (use "vesa" in case of problems)
	Driver     "nvidia"

	# Check wheather these options work with your nVidia card.
	Option    "AllowGLXWithComposite" "true"
	Option    "RenderAccel"  "true"

	# Wanna see the nVidia's logo?
	# Option    "NoLogo"
EndSection

EOF

# ATI card 
else
cat << EOF
Section "Module"
	Load	"bitmap"
	Load	"ddc"
	Load	"dri"
	Load	"extmod"
	Load	"freetype"
	Load	"glx"
	Load	"int10"
	Load	"type1"
	Load	"vbe"
EndSection

Section "Device"
	# Note! This identifier name is used in the "Screen" section.
	Identifier	"ATI Technologies, Inc. Radeon R350 NH [Radeon 9800 Pro]"

        # Note!  Use "fglrx" driver instead of "ati". (use "vesa" in case of problems)
	Driver		"fglrx"
	BusID		"PCI:1:0:0"
EndSection

EOF

fi 

cat << EOF Section "InputDevice" Identifier "Generic Keyboard" Driver "kbd" Option "CoreKeyboard" Option "XkbRules" "xorg" Option "XkbModel" "pc105" Option "XkbLayout" "no" EndSection EOF echo "! However, replace the norwegian keyboard line (\"XkbLayout\" \"no\") with correct one." echo echo "! You may also check the \"xmodmap /usr/share/xmodmap/xmodmap.no\" line in \"$HOME/.Xsession\" file. Replace .no with the country code for your language and keyboard." } # ------------------------------------------ # main() # Has ATI or Nvidia? check_ATI_Nvidia "Error: You must have ATIs or NVIDIAs graphic card to use this script." # Is GNOME? check_GNOME "Error: This setup script works on GNOME-desktop only. Apt-get \"gnome-desktop\" first." # Run as sudo/root? check_root 1 "Error: You must run this script with admin privileges. Like: sudo sh $0." # Ubuntu 6.04/06? check_distro_release "=6.04|=6.06" "Wrong distro or version. You must run a development or final release of Ubuntu 6.04 or 6.06 (Dapper Drake)." # apt-get upgrade update_system # Install -686(intel) or k7(AMD) kernel. upgrade_kernel # Just apt-get some necessary tools setup_necessities # Setup OpenGL drivers and prepare /etc/X11/xorg.conf setup_OpenGL # Setup Xgl (X server) and Compiz (window manager) setup_Xgl # Inform about xorg.conf xorg_config echo "-------------------------------------------------------------" echo -e "2) Backup:" echo "This script backed up and modified the following files:" echo echo "/etc/apt/sources.list" echo "/etc/X11/xorg.conf" echo "/etc/gdm/gdm.conf" echo "/etc/gdm/gdm.conf-custom" echo "$HOME/.Xsession" echo echo "The backup is in the same directory as the original." echo "-------------------------------------------------------------" echo "3) SETUP OF XGL & COMPIZ IS DONE & READY. REBOOT YOUR COMPUTER." echo -e "RTFM: http://en.opensuse.org/Compiz/ has a good guide on howto maneuver in your 3D-boosted desktop environment.\n" echo "-------------------------------------------------------------" echo "Do NOT forget to configure your Firestarter! Firestarter is a GUI for Linux' iptables firewall." echo "Do menu selection: Applications -> System Tools -> Firestarter."
echo 
echo "Check also this Dapper 6.06 starter guide: http://easylinux.info/wiki/Ubuntu_dapper"


© All Right Reserved 2019-2020 futuredesktop.org