Share Pastebin
Guest
Public paste!

donkey_hatstand

By: a guest | May 1st, 2009 | Syntax: None | Size: 16.82 KB | Hits: 107 | Expires: Never
Copy text to clipboard
  1. #!/bin/dash
  2. # This is an installation script for auto installing additional support for
  3. # FSC laptops Amilo A16xx
  4. # Written by Assaf Paz (damagedspline@aim.com || damagedspline@gmail.com)
  5.  
  6. SUCCESS=1
  7. CURRENT_DIR=$(pwd)
  8. KERNEL_VER=$(uname -r)
  9. AR5005G_OPTION="options ath_pci rfkill=0"
  10. PACKAGES_UPDATED=FALSE
  11. SCRIPT_VER=0.6.3
  12. INSTALL_DIR=/usr/local/src
  13. LATEST_ATHEROS="http://homepage.ntlworld.com/roadrash/laptop/madwifi-hal-0.10.5.6-r3861-20080903.tar.gz"
  14. ACERHK_HASH="97EB47F12529D73FE215F47"
  15. DEBIAN_KEY="A70DAF536070D3A1"
  16.  
  17. [ "$DEBUG_SCRIPT" = "TRUE" ] && set -x
  18.  
  19. printMessage()
  20. {
  21.     echo "\033[1m$1\033[0m"
  22. }
  23.  
  24. checkVersion ()
  25. {
  26.     #check ubuntu version
  27.     if [ -n "$(grep -i 7.10 /etc/issue)" ]; then
  28.         LINUX_VER=Gutsy
  29.     else if [ -n "$(grep -i 7.04 /etc/issue)" ]; then
  30.             LINUX_VER=Fiesty
  31.         else if [ -n "$(grep -i celina /etc/issue)" ]; then
  32.                 LINUX_VER=Celina
  33.              else if [ -n "$(grep -i hardy /etc/issue)" -o -n "$(grep -i 8.04 /etc/issue)" -o -n "$(grep -i elyssa /etc/issue)" ]; then
  34.                         LINUX_VER=Hardy
  35.                 else if [ -n "$(grep -i intrepid /etc/issue)" -o -n "$(grep -i 8.10 /etc/issue)" ]; then
  36.                         LINUX_VER=Intrepid
  37.                 else if [ -n "$(grep -i ubuntu /etc/issue)" -o -n "$(grep -i 9.04 /etc/issue)" ]; then
  38.                         LINUX_VER=Intrepid
  39.                      else
  40.  
  41.                         printMessage "Error: Linux version is unsupported. This script will only work on Ubuntu 7.04 <= ver or Linux Mint Celina"
  42.                         return 1
  43.                         fi
  44.                      fi
  45.                 fi
  46.              fi
  47.         fi
  48.     fi
  49.     return 0
  50. }
  51.  
  52. #check the arch
  53. checkArch()
  54. {
  55.     if [ "$(uname -m)" != "i686" ]; then
  56.         printMessage "Error: Sorry, for now this script will only work on 32bit systems"
  57.         return 1
  58.     fi
  59.     return 0
  60. }
  61.  
  62. #check laptop model
  63. checkModel()
  64. {
  65.     if [ -z "$(grep -i a1650g /var/lib/acpi-support/system-product-name)" ]; then
  66.         if [ -z "$(grep -i 1718 /var/lib/acpi-support/system-product-name)"]; then
  67.             printMessage "Could not detect Amilo A1650G or LI1718."    
  68.             if [ -z "$(dpkg --list acpi-support | grep ^ii)" ]; then
  69.                 printMessage "Probably caused because acpi-support is missing. Trying to reinstall..."     
  70.                 installPackagesIfNeeded acpi-support
  71.                 return checkModel
  72.             else
  73.                 printMessage "Error: Sorry, for now this script is only intended for Amilo A1650G && LI1718"
  74.             fi
  75.             return 1
  76.         else
  77.             ACERHK_OPTION="options acerhk force_series=6805 autowlan=1"
  78.             MODEL="LI1718"
  79.         fi
  80.     else
  81.         ACERHK_OPTION="options acerhk autowlan=1"
  82.         MODEL="A1650G"
  83.     fi
  84.     return 0
  85. }
  86.  
  87. #print the welcome message
  88. printWelcome()
  89. {
  90.     printMessage "Welcome to the Fujitsu-Siemens Amilo A16xx automated patch for Ubuntu $LINUX_VER"
  91.     echo ;
  92.     printMessage "This script will enable some of the laptop features such as the Special buttons:"
  93.     printMessage "Wireless, Browser and Fancy Fan"
  94.     echo ;
  95.     return 0
  96. }
  97.  
  98. #check superuser
  99. checkSuperUser()
  100. {
  101.     if [ ! $(id -u) = 0 ]; then
  102.         printMessage "Error: To run this script, one must be with root privileges. Rerun this script prefixed by sudo"
  103.         return 1
  104.     fi
  105.     return 0
  106. }
  107.  
  108. #check that all of the needed prerequisits are met
  109. checkPrerequisits()
  110. {
  111.     checkVersion && \
  112.     checkArch && \
  113.     checkModel && \
  114.     checkSuperUser || return 1
  115.    
  116.     return 0
  117. }
  118.  
  119. #print predefined error message
  120. printError()
  121. {
  122.         case "$1" in
  123.                 setup)
  124.                         printMessage "Missing some required files... I you haven't run the setup yet, you should. If you have, you should try remove and run setup again."
  125.                         ;;
  126.                 already)
  127.                         printMessage "fscamiloa16xx has already been setup, nothing to do."
  128.                         ;;
  129.                 download)
  130.                         printMessage "Error: Unable to download file $2"
  131.                         ;;
  132.                 ndiswrapper)
  133.                         printMessage "Error: ndisdriver driver installation failed, setup will continue non-the-less but wireless is not likely to work...;"
  134.                         printMessage "Error:...please try to install the driver manually using 'sudo ndiswrapper -i <driver inf file name>'"                 ;;
  135.         esac
  136.         return 0;
  137. }
  138.  
  139. #install the given packages if needed
  140. installPackagesIfNeeded()
  141. {
  142.         for package in $*; do
  143.                 if [ -z "$(dpkg --list $package | grep ^ii)" ]; then
  144.                         if [ "$PACKAGES_UPDATED" = "FALSE" ]; then
  145.                                 printMessage "Updating package lists. This may take a while..."
  146.                                 if ! apt-get update > /dev/null ; then
  147.                                        printMessage "Error: Unable to update package lists... Probably won't be able install packages either..."
  148.                                         return 1
  149.                                 fi
  150.                                 PACKAGES_UPDATED=TRUE
  151.                         fi
  152.                         printMessage "Installing required package: $package"
  153.                         if ! apt-get -qy install $package ; then
  154.                                 printMessage "Error: Unable to install required package $package"
  155.                                 return 1
  156.                         fi
  157.                 fi
  158.         done
  159.         return 0
  160. }
  161.  
  162. #add a given line ($1) into a given file ($2)
  163. addLineToFile()
  164. {
  165.         cp $2 $2.part1
  166.         echo $1 > $2.part2
  167.         cat $2.part1 $2.part2 > $2
  168.         rm -f $2.part1 $2.part2
  169.         return 0
  170. }
  171.  
  172. #blacklist a given module ($1) if not already been blacklisted
  173. blacklistModule()
  174. {
  175.         printMessage "Blacklisting $1"
  176.         if [ -z "$(cat /etc/modprobe.d/blacklist.conf | grep $1)" ]; then
  177.                 addLineToFile "blacklist $1" /etc/modprobe.d/blacklist.conf
  178.                 if [ -n "lsmod |grep $1" ]; then
  179.                         rmmod "$1"
  180.                 fi
  181.         fi
  182.         #check for successful blacklisting
  183.         if [ -z "$(cat /etc/modprobe.d/blacklist.conf | grep $1)" ]; then
  184.                 printMessage "Error: Blacklisting of $1 failed. You should manually add \"blacklist $1\" to /etc/modprobe.d/blacklist"
  185.                 printMessage "Please report this error to damagedspline@google.com"    
  186.         fi
  187.         return 0
  188. }
  189.  
  190. #unblacklist a given module ($1) if was blacklisted
  191. unblacklistModule()
  192. {
  193.         printMessage "UnBlacklisting $1"
  194.         if [ -z "$(cat /etc/modprobe.d/blacklist.conf | grep $1)" ]; then
  195.                 grep -v $1 /etc/modprobe.d/blacklist.conf > blacklist.fsc
  196.                 mv blacklist.fsc /etc/modprobe.d/blacklist.conf
  197.         fi
  198.         return 0
  199. }
  200.  
  201. #do not load a given module ($1) if was previously set to load
  202. unsetLoadModule()
  203. {
  204.         printMessage "Unsetting module load for $1"
  205.         if [ -z "$(cat /etc/options | grep $1)" ]; then
  206.                 grep -v $1 /etc/options > options.fsc
  207.                 mv options.fsc /etc/options
  208.         fi
  209.         return 0
  210. }
  211.  
  212. #setup the machine - $1 = setup/check/remove
  213. doSetup()
  214. {
  215.         cd $INSTALL_DIR
  216.  
  217.         if [ "$1" = "setup" ]; then
  218.                 cp $CURRENT_DIR/$0 /etc/init.d
  219.                 if [ -e /etc/rc5.d/S99fsca16xx ]; then
  220.                         sudo update-rc.d -f fsca16xx.sh remove              
  221.                 fi
  222.                 sudo update-rc.d fsca16xx.sh defaults
  223.                 if [ ! -d fsca16xx ]; then
  224.                         if [ "$1" = "check" ]; then
  225.                                 printError setup
  226.                                 return 1
  227.                         fi
  228.                         mkdir fsca16xx
  229.                 fi
  230.                 cp /etc/modules $INSTALL_DIR/fsca16xx/modules.bak
  231.                 cp /etc/modprobe.d/options $INSTALL_DIR/fsca16xx/options.bak
  232.                 cp /etc/modprobe.d/blacklist.conf $INSTALL_DIR/fsca16xx/blacklist.bak
  233.                 cp /usr/lib/pm-utils/defaults $INSTALL_DIR/fsca16xx/defaults.bak
  234.                 cp /etc/modprobe.d/alsa-base.conf $INSTALL_DIR/fsca16xx/alsa-base.bak
  235.         fi
  236.  
  237.         cd fsca16xx
  238.  
  239.         if [ "$1" = "remove" ]; then
  240.                 rm -f /etc/rc5.d/S99fsca16xx
  241.                 sudo update-rc.d -f fsca16xx.sh remove
  242.                 rm -f /etc/acpi/fsc-cpuspeed.sh
  243.                 rm -f /etc/acpi/fsc-wireless.sh
  244.                 rm -f /usr/share/hotkeys/fsca16xx.def
  245.                 rm -f /usr/share/gnome/autostart/hotkeys.desktop
  246.                 rm -f /etc/init.d/fsca16xx.sh
  247.                 mv $INSTALL_DIR/fsca16xx/modules.bak /etc/modules
  248.                 mv $INSTALL_DIR/fsca16xx/options.bak /etc/modprobe.d/options
  249.                 mv $INSTALL_DIR/fsca16xx/blacklist.bak /etc/modprobe.d/blacklist.conf
  250.                 mv $INSTALL_DIR/fsca16xx/defaults.bak /usr/lib/pm-utils/defaults
  251.                 mv $INSTALL_DIR/fsca16xx/alsa-base.bak /etc/modprobe.d/alsa-base.conf
  252.                 rm -Rf $INSTALL_DIR/fsca16xx                
  253.                 return 0
  254.         fi
  255.  
  256.         if [ -z "$(modinfo acerhk | grep $ACERHK_HASH)" -a ! "$LINUX_VER" = "Intrepid" ]; then
  257.                 if [ ! -d acerhk-0.5.35 ]; then
  258.                         if [ "$1" = "check" ]; then
  259.                                 printError setup
  260.                                 return 1
  261.                         fi
  262.  
  263.                         printMessage "Trying to download precompiled kernel module for Special Buttons"
  264.                         if ! wget -q http://fscamiloa16xx.googlecode.com/svn/trunk/$LINUX_VER/$KERNEL_VER/acerhk.ko; then
  265.                                 printMessage "Warning: No precompiled modules for $KERNEL_VER, trying to recompile"
  266.                                 if [ ! -e acerhk-current.tgz ]; then                   
  267.                                         if ! wget -q http://homepage.ntlworld.com/roadrash/laptop/acerhk-current.tgz; then
  268.                                                 printMessage "Error: Unable to download acerhk source code"
  269.                                                 exit 1
  270.                                         fi
  271.                                         printMessage "AcerHK source code downloaded successfully"
  272.                                 fi
  273.                                 tar xzf acerhk-current.tgz
  274.                                 if ! cd acerhk-0.5.35; then
  275.                                         printMessage "Error: Something wrong with downloaded AcerHK, try manual download of acerhk 0.5.35 and place it under /usr/src/fsca16xx/"
  276.                                         exit 1
  277.                                 fi
  278.                                 if ! wget -q http://fscamiloa16xx.googlecode.com/svn/trunk/acerhk-0.5.35-FSC-AMILO_A16xx.patch; then
  279.                                         printMessage "Error: Unable to retrieve acerhk patch"
  280.                                 fi
  281.                                 printMessage "Patching AcerHK"
  282.                                 patch -i acerhk-0.5.35-FSC-AMILO_A16xx.patch
  283.                                 printMessage "Installing required kernel module building tools - this may take a while..."
  284.                                 if ! installPackagesIfNeeded build-essential linux-headers-generic ; then
  285.                                         return 1
  286.                                 fi
  287.                                 printMessage "Compiling AcerHK"
  288.                                 if make > ../compile.log ; then
  289.                                        printMessage "Compile ended successfully!"
  290.                                         mv acerhk.ko ../
  291.                                         cd ..
  292.                                 else
  293.                                         cd ..
  294.                                         printMessage "Error: AcerHK compile failed, compile log can be found at $(pwd)/compile.log"
  295.                                 fi
  296.                         else
  297.                                 printMessage "Success"
  298.                         fi
  299.                 else
  300.                         cd acerhk-0.5.35
  301.                         printMessage "Compiling AcerHK"
  302.                         if make > ../compile.log ; then
  303.                                 printMessage "Compile ended successfully!"
  304.                                 mv acerhk.ko ../
  305.                                 cd ..
  306.                         else
  307.                                 cd ..
  308.                                 printMessage "Error: AcerHK compile failed, compile log can be found at $(pwd)/compile.log"
  309.                         fi
  310.                 fi
  311.                 printMessage "Replacing Acerhk module"
  312.                 ACERHK_PATH="$(find /lib/modules/$(uname -r) |grep -m 1 acerhk)"
  313.                 mv -uf acerhk.ko $ACERHK_PATH
  314.                 cd ..
  315.         fi
  316.  
  317.         if [ ! "$1" = check ]; then
  318.                 printMessage "Downloading additional files required by setup"
  319.                 if [ ! -e fsc-cpuspeed.sh  ]; then
  320.                         wget -q http://fscamiloa16xx.googlecode.com/svn/trunk/$LINUX_VER/fsc-cpuspeed.sh
  321.                 fi
  322.                 if [ ! -e fsc-wireless.sh  ]; then
  323.                         wget -q http://fscamiloa16xx.googlecode.com/svn/trunk/$LINUX_VER/fsc-wireless.sh
  324.                 fi
  325.                 chmod 755 *.sh
  326.                 if [ ! -e fsca16xx.def ]; then
  327.                         wget -q http://fscamiloa16xx.googlecode.com/svn/trunk/$LINUX_VER/fsca16xx.def
  328.                 fi
  329.                 if [ ! -e hotkeys.desktop ]; then
  330.                         wget -q http://fscamiloa16xx.googlecode.com/svn/trunk/$LINUX_VER/hotkeys.desktop
  331.                 fi
  332.         fi
  333.        
  334.         if [ "$1" = check ]; then
  335.                 echo 1 > /proc/driver/acerhk/wirelessled
  336.         fi
  337.  
  338.         if ! installPackagesIfNeeded hotkeys libnotify-bin ; then
  339.                 return 1
  340.         fi
  341.  
  342.         if [ ! "$1" = check ]; then
  343.                 printMessage "Setting all features to auto-activate on startup"
  344.                 cp -uf *.sh /etc/acpi/
  345.                 cp -uf fsca16xx.def /usr/share/hotkeys/
  346.                 # cp -uf hotkeys.desktop /usr/share/gnome/autostart/
  347.         fi
  348.  
  349.         printMessage "Adding kernel support for Special Buttons"
  350.         if [ -z "$(grep acerhk /etc/modules)" ]; then
  351.                 addLineToFile acerhk /etc/modules      
  352.         fi
  353.         if [ -z "$(grep acerhk /etc/modprobe.d/options)" ]; then
  354.                 addLineToFile "$ACERHK_OPTION" /etc/modprobe.d/options
  355.         else
  356.                 if [ "$(grep acerhk /etc/modprobe.d/options)" != "$ACERHK_OPTION" ]; then
  357.                         grep -v acerhk /etc/modprobe.d/options > options.fsc
  358.                         addLineToFile "$ACERHK_OPTION" options.fsc
  359.                         mv options.fsc /etc/modprobe.d/options  
  360.                 fi
  361.         fi
  362.  
  363.         #wireless driver section
  364.         if [ -n "$(lspci |grep -i atheros)" -a ! "$LINUX_VER" = "Intrepid" ]; then
  365.                 unblacklistModule ath_pci
  366.                 unsetLoadModule ndiswrapper
  367.                 printMessage "Installing latest Atheros opensource driver"             
  368.  
  369.                 if [ "LI1718" = $MODEL ]; then
  370.                         printMessage "Blacklisting some modules"
  371.                        
  372.                         #blacklist netathr
  373.                         blacklistModule netathr
  374.  
  375.                         #blacklist sis163u
  376.                         blacklistModule sis163u
  377.                 fi
  378.                 if [ "Hardy" = $LINUX_VER -a -z "$(grep -e SUSPEND_MODULES -e ath_pci /usr/lib/pm-utils/defaults)" ]; then
  379.                         mv /usr/lib/pm-utils/defaults defaults.fsc
  380.                         cat defaults.fsc | sed 's/\#*\s*\(SUSPEND_MODULES=\"\)\(.*\)\(\"\)/\1ath_pci \2\3/' > /usr/lib/pm-utils/defaults
  381.                         rm -f defaults.fsc
  382.                 fi
  383.                 if [ ! "$1" = check ]; then
  384.                         rm -Rf madwifi*
  385.                         wget -c $LATEST_ATHEROS
  386.                         tar xvzf madwifi*
  387.                         cd madwifi*/
  388.                         make
  389.                         echo "r" > answer.fsc
  390.                         sudo make install < answer.fsc
  391.                         sudo rmmod ath_pci ath_rate_sample ath_hal wlan_scan_sta wlan
  392.                         sudo modprobe ath_pci
  393.                 fi
  394.         fi
  395.  
  396.         if [ -n "$(lspci |grep -i atheros)" -a "$LINUX_VER" = "Intrepid" ]; then
  397.                 if ! installPackagesIfNeeded linux-backports-modules-jaunty ; then
  398.                         return 1
  399.                 fi
  400.                 blacklistModule ath_pci
  401.         fi
  402.  
  403.         if [ "Celina" = $LINUX_VER ]; then
  404.                 if ! installPackagesIfNeeded wifi-radar ; then
  405.                         return 1
  406.                 fi    
  407.         fi        
  408.  
  409.         #audio section 
  410.         if [ "LI1718" = $MODEL ]; then
  411.                 case $LINUX_VER in
  412.                         Fiesty)
  413.                                 if [ -z "$(grep snd-hda-intel /etc/modprobe.d/alsa-base.conf)" ]; then
  414.                                         printMessage "Fix audio issue"
  415.                                         addLineToFile "options snd-hda-intel index=0 model=3stack" /etc/modprobe.d/alsa-base.conf
  416.                                 fi
  417.                                 ;;
  418.                         Celena)
  419.                                 if [ -z "$(grep snd-hda-intel /etc/modprobe.d/alsa-base.conf)" ]; then
  420.                                         printMessage "Fix audio issue"
  421.                                         addLineToFile "options snd-hda-intel index=0 model=3stack" /etc/modprobe.d/alsa-base.conf
  422.                                 fi
  423.                                 wget http://homepage.ntlworld.com/roadrash/laptop/alsaconf
  424.                                 cp alsaconf /usr/sbin/
  425.                                 ;;
  426.                         Hardy)
  427.                                 if [ -z "$(grep snd-hda-intel /etc/modprobe.d/alsa-base)" ]; then
  428.                                         printMessage "Fix audio issue"
  429.                                         addLineToFile "options snd-hda-intel index=0 model=toshiba" /etc/modprobe.d/alsa-base.conf
  430.                                 fi
  431.                                 ;;
  432.                         *)
  433.                                 ;;
  434.                 esac
  435.         fi
  436.  
  437.         printMessage "Loading kernel modules for Special Buttons"
  438.         if [ -n "$(lsmod |grep acerhk)" ]; then
  439.                 rmmod acerhk
  440.         fi
  441.         modprobe acerhk
  442.  
  443.         printMessage "Done. Please logout and relogin in order to start using the hotkeys."
  444.         cd $CURRENT_DIR
  445.         return 0
  446. }
  447.  
  448. # Define LSB log_* functions.
  449. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
  450. . /lib/lsb/init-functions
  451.  
  452. if ! checkPrerequisits ; then
  453.         exit 3        
  454. fi
  455.  
  456. case "$1" in
  457.   start)
  458.         log_daemon_msg "Checking for proper configuration for Fujistu-Siemens laptops"
  459.         if ! doSetup check ; then
  460.                 log_end_msg 1        
  461.         fi
  462.         log_end_msg 0
  463.         ;;
  464.   stop)
  465.         #nothing to do
  466.         ;;
  467.   setup)
  468.         printWelcome
  469.         if ! doSetup setup ; then
  470.                 exit 3        
  471.         fi
  472.         # nothing to do
  473.         ;;    
  474.   remove)
  475.         if ! doSetup remove ; then
  476.                 exit 3
  477.         fi
  478.         ;;
  479.   *)
  480.         printMessage "Usage: $0 {start|stop|setup|remove}"
  481.         exit 3
  482.         ;;
  483. esac
  484.  
  485. :