#!/bin/sh

###########################################
# Ubuntu-Fixes for the ASUS EeePC 701/900 #
# with GUI(Zenity) based on x2on`s script #
# Version 0.5   			  #
# by elmurato				  #
# http://forum.eeepcnews.de 		  #
###########################################

zenity --question --text="This will install the Ubuntu-Fixes for your EeePC. Continue?" --title="Ubuntu-Fixes for the ASUS EeePC"
if test $? -eq 0
then
 (
 CDIR=`pwd`

 echo "# Gnome: Setting smaller font sizes..."
 gconftool-2 --set /apps/nautilus/preferences/desktop_font --type string "Sans 8"
 gconftool-2 --set /desktop/gnome/interface/document_font_name --type string "Sans 8"
 gconftool-2 --set /desktop/gnome/interface/font_name --type string "Sans 8"
 gconftool-2 --set /apps/metacity/general/titlebar_font --type string "Sans Bold 8"
 gconftool-2 --set /desktop/gnome/interface/monospace_font_name --type string "Monospace 9"
 echo "5"
 echo "# Gnome: Smaller toolbars icons only..."
 gconftool-2 --set /desktop/gnome/interface/toolbar_style --type string "icons"
 echo "10"
 echo "# Gnome: Disabling UI sounds..."
 gconftool-2 --set /desktop/gnome/sound/event_sounds --type bool 0
 echo "15"
 echo "# Gnome: Fixing mute key..."
 gconftool-2 --set /desktop/gnome/sound/default_mixer_tracks --type list --list-type string "[PCM]"
 echo "20"
 echo "# Gnome: Fullscreen with <Alt>-F11..."
 gconftool-2 --set /apps/metacity/window_keybindings/toggle_fullscreen --type string "<Alt>F11"
 echo "25"
 echo "# Gnome: Setting suspend when closing lid, blank screen..."
 gconftool-2 --set /apps/gnome-power-manager/actions/sleep_type_battery --type string "suspend"
 gconftool-2 --set /apps/gnome-power-manager/actions/sleep_type_ac --type string "suspend"
 gconftool-2 --set /apps/gnome-power-manager/buttons/lid_battery --type string "suspend"
 gconftool-2 --set /apps/gnome-power-manager/buttons/lid_ac --type string "blank"
 gconftool-2 --set /apps/gnome-power-manager/timeout/sleep_computer_ac --type int 0
 gconftool-2 --set /apps/gnome-power-manager/timeout/sleep_computer_battery --type int 300
 gconftool-2 --set /apps/gnome-power-manager/timeout/sleep_display_ac --type int 300
 gconftool-2 --set /apps/gnome-power-manager/timeout/sleep_display_battery --type int 60
 echo "30"
 echo "# Gnome: Don't display battery warning..."
 gconftool-2 --set /apps/gnome-power-manager/notify/low_capacity --type bool 0
 echo "35"
 echo "# Gnome: Unconstraining windows to the top of the screen..."
 gconftool-2 --type bool --set /apps/compiz/plugins/move/allscreens/options/constrain_y 0
 echo "40"

 echo "# Installing ACPI..."
 sudo apt-get update
 echo "40"
 sudo apt-get install -y -f build-essential module-assistant eeepc-acpi-source  --force-yes
 echo "40"
 sudo m-a a-i eeepc-acpi
 echo "40"
 
 STR=`cat /etc/modules | grep "eeepc-acpi"`
 if test $? -eq 1
 then
  sudo cp /etc/modules ~/modules.tmp
  sudo chmod 777 ~/modules.tmp
  echo "eeepc-acpi" >> ~/modules.tmp
  sudo chmod 644 ~/modules.tmp
  sudo mv ~/modules.tmp /etc/modules
  echo "60"
 fi

 echo "# Installing OSD..."
 wget http://eee-osd.googlecode.com/files/eee-osd_2.1-0eeeXubuntu1_i386.deb
 sudo dpkg -i eee-osd_2.1-0eeeXubuntu1_i386.deb
 echo "75"

 echo "# Installing WLAN..."
 sudo apt-get update
 sudo apt-get install build-essential
 wget http://snapshots.madwifi.org/madwifi-hal-0.10.5.6-current.tar.gz
 tar zxvf madwifi-hal-0.10.5.6-current.tar.gz
 cd madwifi-hal-0.10.5.6-r*
 make clean
 make
 sudo make install
 cd ..
 sudo rm -r madwifi-hal-0.10.5.6-r* madwifi-hal-0.10.5.6-current.tar.gz
 echo "90"

 if test $? -eq 0
 then
  MODEL=`zenity --list --text "Please select your model:" --title "Configuring Sound" --column Model "EeePC 701" "EeePC 900"`
  case $MODEL in
   "EeePC 701") echo "# Configuring Sound for EeePC 701..."
        echo "options snd-hda-intel model=3stack-dig" > ~/snd-hda-intel.tmp
        sudo mv ~/snd-hda-intel.tmp /etc/modprobe.d/snd-hda-intel
        echo "95";;
   "EeePC 900") echo "# Configuring Sound for EeePC 900..."
        echo "options snd-hda-intel model=auto" > ~/snd-hda-intel.tmp
        sudo mv ~/snd-hda-intel.tmp /etc/modprobe.d/snd-hda-intel
        echo "95";;
   *) echo "# ERROR: No model selected"
      sh sound;;
  esac
 fi

 echo "# Removing temporary files..."
 sudo rm $CDIR/eee-osd_2.1-0eeeXubuntu1_i386.deb
 sudo rm $CDIR/madwifi-ng-r3366+ar5007.tar.gz
 sudo rm -r $CDIR/madwifi-ng-r3366+ar5007
 echo "100"

 echo "# Installation completed! Please reboot now."
 ) |
 zenity --progress --title="Ubuntu-Fixes for the ASUS EeePC" --text="Initializing" --percentage=0 --width=400
fi

