home *** CD-ROM | disk | FTP | other *** search
/ tusportal.tus.k12.pa.us / tusportal.tus.k12.pa.us.tar / tusportal.tus.k12.pa.us / Wyse / latest-image.raw / 0.img / usr / sbin / alsa-info.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  2011-04-22  |  23KB  |  716 lines

  1. #!/bin/bash
  2.  
  3. SCRIPT_VERSION=0.4.51
  4. CHANGELOG="http://www.alsa-project.org/alsa-info.sh.changelog"
  5.  
  6. #################################################################################
  7. #Copyright (C) 2007 Free Software Foundation.
  8.  
  9. #This program is free software; you can redistribute it and/or modify
  10. #it under the terms of the GNU General Public License as published by
  11. #the Free Software Foundation; either version 2 of the License, or
  12. #(at your option) any later version.
  13.  
  14. #This program is distributed in the hope that it will be useful,
  15. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. #GNU General Public License for more details.
  18.  
  19. #You should have received a copy of the GNU General Public License
  20. #along with this program; if not, write to the Free Software
  21. #Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  22.  
  23. ##################################################################################
  24.  
  25. #The script was written for 2 main reasons:
  26. # 1. Remove the need for the devs/helpers to ask several questions before we can easily help the user.
  27. # 2. Allow newer/inexperienced ALSA users to give us all the info we need to help them.
  28.  
  29. #Change the PATH variable, so we can run lspci (needed for some distros)
  30. PATH=$PATH:/bin:/sbin:/usr/bin:/usr/sbin
  31. BGTITLE="ALSA-Info v $SCRIPT_VERSION"
  32. PASTEBINKEY="C9cRIO8m/9y8Cs0nVs0FraRx7U0pHsuc"
  33. #Define some simple functions
  34.  
  35. pbcheck(){
  36.     if [[ -z $PASTEBIN ]]; then
  37.         [[ $(ping -c1 www.alsa-project.org) ]] || KEEP_FILES="yes" NOUPLOAD="yes" PBERROR="yes"
  38.     else
  39.         [[ $(ping -c1 www.pastebin.ca) ]] || KEEP_FILES="yes" NOUPLOAD="yes" PBERROR="yes"
  40.     fi
  41. }
  42.  
  43. update() {
  44.     wget -O /tmp/alsa-info.sh "http://www.alsa-project.org/alsa-info.sh" >/dev/null 2>&1
  45.     REMOTE_VERSION=`grep SCRIPT_VERSION /tmp/alsa-info.sh |head -n1 |sed 's/.*=//'`
  46.     if [ "$REMOTE_VERSION" != "$SCRIPT_VERSION" ]; then
  47.         if [[ -n $DIALOG ]]
  48.         then
  49.             dialog --yesno "Newer version of ALSA-Info has been found\n\nDo you wish to install it?" 0 0
  50.             DIALOG_EXIT_CODE=$?
  51.             if [[ $DIALOG_EXIT_CODE = 0 ]]
  52.             then
  53.                 cp /tmp/alsa-info.sh $0
  54.                 echo "ALSA-Info script has been updated to v $REMOTE_VERSION"
  55.                 echo "To view the ChangeLog, please visit $CHANGELOG"
  56.                 echo "Please re-run the script"
  57.                 exit
  58.             fi
  59.         else
  60.             cp /tmp/alsa-info.sh $0
  61.             echo "Newer version detected: $REMOTE_VERSION"
  62.             echo "To view the ChangeLog, please visit $CHANGELOG"
  63.             echo "ALSA-Info script has been updated. Please re-run it."
  64.  
  65.             exit
  66.         fi
  67.     fi
  68.     rm /tmp/alsa-info.sh 2>/dev/null
  69. }
  70.  
  71. cleanup() {
  72.     rm -r $TEMPDIR 2>/dev/null
  73. }
  74.  
  75.  
  76. withaplay() {
  77.         echo "!!Aplay/Arecord output" >> $FILE
  78.         echo "!!------------" >> $FILE
  79.         echo "" >> $FILE
  80.            echo "APLAY" >> $FILE
  81.     echo "" >> $FILE 
  82.     aplay -l >> $FILE 2>&1
  83.         echo "" >> $FILE
  84.            echo "ARECORD" >> $FILE
  85.     echo "" >> $FILE
  86.     arecord -l >> $FILE 2>&1
  87.     echo "" >> $FILE
  88. }
  89.  
  90. withlsmod() {
  91.     echo "!!All Loaded Modules" >> $FILE
  92.     echo "!!------------------" >> $FILE
  93.     echo "" >> $FILE
  94.     lsmod |awk {'print $1'} >> $FILE
  95.     echo "" >> $FILE
  96.     echo "" >> $FILE
  97. }
  98.  
  99. withamixer() {
  100.         echo "!!Amixer output" >> $FILE
  101.         echo "!!-------------" >> $FILE
  102.         echo "" >> $FILE
  103.     for i in `grep "]: " /proc/asound/cards | awk -F ' ' '{ print $1} '` ; do
  104.     CARD_NAME=`grep "^ *$i " /tmp/alsainfo/alsacards.tmp|awk {'print $2'}`
  105.     echo "!!-------Mixer controls for card $i $CARD_NAME]" >> $FILE
  106.     echo "" >>$FILE
  107.     amixer -c$i info>> $FILE 2>&1
  108.     amixer -c$i>> $FILE 2>&1
  109.         echo "" >> $FILE
  110.     done
  111.     echo "" >> $FILE
  112. }
  113.  
  114. withalsactl() {
  115.     echo "!!Alsactl output" >> $FILE
  116.         echo "!!-------------" >> $FILE
  117.         echo "" >> $FILE
  118.         exe=""
  119.         if [ -x /usr/sbin/alsactl ]; then
  120.             exe="/usr/sbin/alsactl"
  121.         fi
  122.         if [ -x /usr/local/sbin/alsactl ]; then
  123.             exe="/usr/local/sbin/alsactl"
  124.         fi
  125.         if [ -z "$exe" ]; then
  126.             exe=`whereis alsactl | cut -d ' ' -f 2`
  127.         fi
  128.     $exe -f /tmp/alsainfo/alsactl.tmp store
  129.     echo "--startcollapse--" >> $FILE
  130.     cat /tmp/alsainfo/alsactl.tmp >> $FILE
  131.     echo "--endcollapse--" >> $FILE
  132.     echo "" >> $FILE
  133.     echo "" >> $FILE
  134. }
  135.  
  136. withdevices() {
  137.         echo "!!ALSA Device nodes" >> $FILE
  138.         echo "!!-----------------" >> $FILE
  139.         echo "" >> $FILE
  140.         ls -la /dev/snd/* >> $FILE
  141.         echo "" >> $FILE
  142.         echo "" >> $FILE
  143. }
  144.  
  145. withconfigs() {
  146. if [[ -e $HOME/.asoundrc ]] || [[ -e /etc/asound.conf ]] || [[ -e $HOME/.asoundrc.asoundconf ]]
  147. then
  148.         echo "!!ALSA configuration files" >> $FILE
  149.         echo "!!------------------------" >> $FILE
  150.         echo "" >> $FILE
  151.  
  152.         #Check for ~/.asoundrc
  153.         if [[ -e $HOME/.asoundrc ]]
  154.         then
  155.                 echo "!!User specific config file (~/.asoundrc)" >> $FILE
  156.                 echo "" >> $FILE
  157.                 cat $HOME/.asoundrc >> $FILE
  158.                 echo "" >> $FILE
  159.                 echo "" >> $FILE
  160.         fi
  161.     #Check for .asoundrc.asoundconf (seems to be Ubuntu specific)
  162.     if [[ -e $HOME/.asoundrc.asoundconf ]]
  163.     then
  164.         echo "!!asoundconf-generated config file" >> $FILE
  165.         echo "" >> $FILE
  166.         cat $HOME/.asoundrc.asoundconf >> $FILE
  167.         echo "" >> $FILE
  168.         echo "" >> $FILE
  169.     fi
  170.         #Check for /etc/asound.conf
  171.         if [[ -e /etc/asound.conf ]]
  172.         then
  173.                 echo "!!System wide config file (/etc/asound.conf)" >> $FILE
  174.                 echo "" >> $FILE
  175.                 cat /etc/asound.conf >> $FILE
  176.                 echo "" >> $FILE
  177.                 echo "" >> $FILE
  178.         fi
  179. fi
  180. }
  181.  
  182.  
  183. #Run checks to make sure the programs we need are installed.
  184. LSPCI=$(which lspci 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null);
  185. TPUT=$(which tput 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null);
  186. DIALOG=$(which dialog 2>/dev/null | sed 's|^[^/]*||' 2>/dev/null);
  187.  
  188. #Check to see if sysfs is enabled in the kernel. We'll need this later on
  189. SYSFS=$(mount |grep sysfs|awk {'print $3'});
  190.  
  191. #Check modprobe config files for sound related options
  192. SNDOPTIONS=$(modprobe -c|sed -n 's/^options \(snd[-_][^ ]*\)/\1:/p')
  193.  
  194. PASTEBIN=""
  195. WWWSERVICE="www.alsa-project.org"
  196. QUESTION="yes"
  197. PROCEED="yes"
  198. REPEAT=""
  199. while [ -z "$REPEAT" ]; do
  200. REPEAT="no"
  201. case "$1" in
  202.     --update|--help|--about)
  203.         QUESTION="no"
  204.         PROCEED="no"
  205.         ;;
  206.     --no-upload)
  207.         NOUPLOAD="yes"
  208.         ;;
  209.     --pastebin)
  210.         PASTEBIN="yes"
  211.         WWWSERVICE="pastebin"
  212.         ;;
  213.     --no-dialog)
  214.         DIALOG=""
  215.         REPEAT=""
  216.         shift
  217.         ;;
  218. esac
  219. done
  220.         
  221.  
  222. #Script header output.
  223. if [ "$QUESTION" = "yes" ]; then
  224. if [[ -n "$DIALOG" ]]
  225. then
  226. if [ -z "$NOUPLOAD" ]; then
  227.     dialog --backtitle "$BGTITLE" --title "ALSA-Info script v $SCRIPT_VERSION" --yesno "\nThis script will collect information about your ALSA installation and sound related hardware, to help diagnose your problem\n\nBy default, this script will AUTOMATICALLY UPLOAD your information to a $WWWSERVICE site.\n\nSee $0 --help for options\n\nDo you want to run this script?" 0 0
  228. else
  229.     dialog --backtitle "$BGTITLE" --title "ALSA-Info script v $SCRIPT_VERSION" --yesno "\nThis script will collect information about your ALSA installation and sound related hardware, to help diagnose your problem\n\nSee $0 --help for options\n\nDo you want to run this script?" 0 0
  230. fi
  231. DIALOG_EXIT_CODE=$?
  232. if [ $DIALOG_EXIT_CODE != 0 ]; then
  233. echo "Thank you for using the ALSA-Info Script"
  234. exit 0;
  235. fi
  236. else
  237.  
  238. echo "ALSA Information Script v $SCRIPT_VERSION"
  239. echo "--------------------------------"
  240. echo ""
  241. echo "This script will collect information about your ALSA installation and sound related hardware, to help diagnose your problem."
  242. echo ""
  243. if [ -z "$NOUPLOAD" ]; then
  244. if [[ -n "$TPUT" ]]; then
  245. tput bold
  246. echo "By default, the collected information will be AUTOMATICALLY uploaded to a $WWWSERVICE site."
  247. echo "If you do not wish for this to occur, run the script with the --no-upload argument"
  248. tput sgr0
  249. else
  250. echo "By default, the collected information will be AUTOMATICALLY uploaded to a $WWWSERVICE site."
  251. echo "If you do not wish for this to occur, run the script with the --no-upload argument"
  252. fi
  253. echo ""
  254. fi # NOUPLOAD
  255. echo -n "Do you want to run this script? [y/n] : "
  256. read -e CONFIRM
  257. if [ "$CONFIRM" != "y" ]; then
  258. echo ""
  259. echo "Thank you for using the ALSA-Info Script"
  260. exit 0;
  261. fi
  262. fi
  263. fi # question
  264.  
  265. #Set the output file
  266. TEMPDIR="/tmp/alsainfo/"
  267. FILE="/tmp/alsa-info.txt"
  268.  
  269. if [ "$PROCEED" = "yes" ]; then
  270.  
  271. if [[ -z "$LSPCI" ]] 
  272.     then
  273.     echo "This script requires lspci. Please install it, and re-run this script."
  274. exit 0
  275. fi
  276.  
  277. #Create the temporary work dir.
  278. mkdir $TEMPDIR 2>/dev/null
  279.  
  280. #Fetch the info and store in temp files/variables
  281. DISTRO=`grep -ihs "buntu\|SUSE\|Fedora\|PCLinuxOS\|MEPIS\|Mandriva\|Debian\|Damn\|Sabayon\|Slackware\|KNOPPIX\|Gentoo\|Zenwalk\|Mint\|Kubuntu\|FreeBSD\|Puppy\|Freespire\|Vector\|Dreamlinux\|CentOS\|Arch\|Xandros\|Elive\|SLAX\|Red\|BSD\|KANOTIX\|Nexenta\|Foresight\|GeeXboX\|Frugalware\|64\|SystemRescue\|Novell\|Solaris\|BackTrack\|KateOS\|Pardus" /etc/{issue,*release,*version}`
  282. KERNEL_VERSION=`uname -r`
  283. KERNEL_PROCESSOR=`uname -p`
  284. KERNEL_MACHINE=`uname -m`
  285. KERNEL_OS=`uname -o`
  286. [[ `uname -v |grep SMP`  ]] && KERNEL_SMP="Yes" || KERNEL_SMP="No" 
  287. ALSA_DRIVER_VERSION=`cat /proc/asound/version |head -n1|awk {'print $7'} |sed 's/\.$//'`
  288. ALSA_LIB_VERSION=`grep VERSION_STR /usr/include/alsa/version.h 2>/dev/null|awk {'print $3'}|sed 's/"//g'`
  289. ALSA_UTILS_VERSION=`amixer -v |awk {'print $3'}`
  290. VENDOR_ID=`lspci -vn |grep 040[1-3] | awk -F':' '{print $3}'|awk {'print substr($0, 2);}' >/tmp/alsainfo/vendor_id.tmp`
  291. DEVICE_ID=`lspci -vn |grep 040[1-3] | awk -F':' '{print $4}'|awk {'print $1'} >/tmp/alsainfo/device_id.tmp`
  292. LAST_CARD=$((`grep "]: " /proc/asound/cards | wc -l` - 1 ))
  293. cat /proc/asound/modules 2>/dev/null|awk {'print $2'}>/tmp/alsainfo/alsamodules.tmp
  294. cat /proc/asound/cards >/tmp/alsainfo/alsacards.tmp
  295. lspci |grep -i "multi\|audio">/tmp/alsainfo/lspci.tmp
  296.  
  297. #Check for HDA-Intel cards codec#*
  298. cat /proc/asound/card*/codec\#* > /tmp/alsainfo/alsa-hda-intel.tmp 2> /dev/null
  299.  
  300. #Check for AC97 cards codec
  301. cat /proc/asound/card*/codec97\#0/ac97\#0-0 > /tmp/alsainfo/alsa-ac97.tmp 2> /dev/null
  302. cat /proc/asound/card*/codec97\#0/ac97\#0-0+regs > /tmp/alsainfo/alsa-ac97-regs.tmp 2> /dev/null
  303.  
  304. #Fetch the info, and put it in $FILE in a nice readable format.
  305. if [[ -z $PASTEBIN ]]; then
  306. echo "upload=true&script=true&cardinfo=" > $FILE
  307. else
  308. echo "name=$USER&type=33&description=/tmp/alsa-info.txt&expiry=&s=Submit+Post&content=" > $FILE
  309. fi
  310. echo "!!################################" >> $FILE
  311. echo "!!ALSA Information Script v $SCRIPT_VERSION" >> $FILE
  312. echo "!!################################" >> $FILE
  313. echo "" >> $FILE
  314. echo "!!Script ran on: `LANG=C date`" >> $FILE
  315. echo "" >> $FILE
  316. echo "" >> $FILE
  317. echo "!!Linux Distribution" >> $FILE
  318. echo "!!------------------" >> $FILE
  319. echo "" >> $FILE
  320. echo $DISTRO >> $FILE
  321. echo "" >> $FILE
  322. echo "" >> $FILE
  323. echo "!!Kernel Information" >> $FILE
  324. echo "!!------------------" >> $FILE
  325. echo "" >> $FILE
  326. echo "Kernel release:    $KERNEL_VERSION" >> $FILE
  327. echo "Operating System:  $KERNEL_OS" >> $FILE
  328. echo "Architecture:      $KERNEL_MACHINE" >> $FILE
  329. echo "Processor:         $KERNEL_PROCESSOR" >> $FILE
  330. echo "SMP Enabled:       $KERNEL_SMP" >> $FILE
  331. echo "" >> $FILE
  332. echo "" >> $FILE
  333. echo "!!ALSA Version" >> $FILE
  334. echo "!!------------" >> $FILE
  335. echo "" >> $FILE
  336. echo "Driver version:     $ALSA_DRIVER_VERSION" >> $FILE
  337. echo "Library version:    $ALSA_LIB_VERSION" >> $FILE
  338. echo "Utilities version:  $ALSA_UTILS_VERSION" >> $FILE
  339. echo "" >> $FILE
  340. echo "" >> $FILE
  341. echo "!!Loaded ALSA modules" >> $FILE
  342. echo "!!-------------------" >> $FILE
  343. echo "" >> $FILE
  344. cat /tmp/alsainfo/alsamodules.tmp >> $FILE
  345. echo "" >> $FILE
  346. echo "" >> $FILE
  347. echo "!!Soundcards recognised by ALSA" >> $FILE
  348. echo "!!-----------------------------" >> $FILE
  349. echo "" >> $FILE
  350. cat /tmp/alsainfo/alsacards.tmp >> $FILE
  351. echo "" >> $FILE
  352. echo "" >> $FILE
  353. echo "!!PCI Soundcards installed in the system" >> $FILE
  354. echo "!!--------------------------------------" >> $FILE
  355. echo "" >> $FILE
  356. cat /tmp/alsainfo/lspci.tmp >> $FILE
  357. echo "" >> $FILE
  358. echo "" >> $FILE
  359. echo "!!Advanced information - PCI Vendor/Device/Susbsystem ID's" >> $FILE
  360. echo "!!--------------------------------------------------------" >> $FILE
  361. echo "" >> $FILE
  362. lspci -vvn |grep -A1 040[1-3] >> $FILE
  363. echo "" >> $FILE
  364. echo "" >> $FILE
  365.  
  366. if [ "$SNDOPTIONS" ]
  367. then
  368. echo "!!Modprobe options (Sound related)" >> $FILE
  369. echo "!!--------------------------------" >> $FILE
  370. echo "" >> $FILE
  371. modprobe -c|sed -n 's/^options \(snd[-_][^ ]*\)/\1:/p' >> $FILE
  372. echo "" >> $FILE
  373. echo "" >> $FILE
  374. fi
  375.  
  376. if [ -d "$SYSFS" ]
  377. then
  378. echo "!!Loaded sound module options" >> $FILE
  379. echo "!!--------------------------" >> $FILE
  380. echo "" >> $FILE
  381. for mod in `cat /proc/asound/modules|awk {'print $2'}`;do
  382. echo "!!Module: $mod" >> $FILE
  383. for params in `ls $SYSFS/module/$mod/parameters/*`; do /bin/echo -ne "\t";/bin/echo "$params : `cat $params`"|sed 's:.*/::' >> $FILE;done
  384. echo "" >> $FILE
  385. done
  386. echo "" >> $FILE
  387. fi
  388.  
  389. if [ -s "/tmp/alsainfo/alsa-hda-intel.tmp" ] 
  390. then
  391.     echo "!!HDA-Intel Codec information" >> $FILE
  392.     echo "!!---------------------------" >> $FILE
  393.     echo "--startcollapse--" >> $FILE
  394.     echo "" >> $FILE
  395.     cat /tmp/alsainfo/alsa-hda-intel.tmp >> $FILE
  396.     echo "--endcollapse--" >> $FILE
  397.     echo "" >> $FILE
  398.     echo "" >> $FILE
  399. fi
  400.  
  401. if [ -s "/tmp/alsainfo/alsa-ac97.tmp" ]
  402. then
  403.         echo "!!AC97 Codec information" >> $FILE
  404.         echo "!!---------------------------" >> $FILE
  405.         echo "--startcollapse--" >> $FILE
  406.         echo "" >> $FILE
  407.         cat /tmp/alsainfo/alsa-ac97.tmp >> $FILE
  408.         echo "" >> $FILE
  409.         cat /tmp/alsainfo/alsa-ac97-regs.tmp >> $FILE
  410.         echo "--endcollapse--" >> $FILE
  411.     echo "" >> $FILE
  412.     echo "" >> $FILE
  413. fi
  414.  
  415.  
  416. #If no command line options are specified, then run as though --with-all was specified
  417. if [[ -z "$1" ]]
  418. then
  419.     update
  420.     withdevices
  421.     withconfigs
  422.     withaplay
  423.     withamixer
  424.     withalsactl
  425.     withlsmod
  426.     pbcheck    
  427. fi
  428.  
  429. fi # proceed
  430.  
  431. #loop through command line arguments, until none are left.
  432. if [[ -n "$1" ]]
  433. then
  434.     until [ -z "$1" ]
  435.     do
  436.     case "$1" in
  437.         --pastebin)
  438.                 update
  439.                 withdevices
  440.                 withconfigs
  441.                 withaplay
  442.                 withamixer
  443.                 withalsactl
  444.                 withlsmod
  445.                 pbcheck
  446.             ;;
  447.         --update)
  448.             update
  449.             exit
  450.             ;;
  451.         --no-upload)
  452.             NOUPLOAD="yes"
  453.             KEEP_FILES="yes"
  454.             withdevices
  455.             withconfigs
  456.             withaplay
  457.             withamixer
  458.             withalsactl
  459.             withlsmod
  460.             ;;
  461.         --debug)
  462.             echo "Debugging enabled. $FILE and $TEMPDIR will not be deleted"
  463.             KEEP_FILES="yes"
  464.             echo ""
  465.             withdevices
  466.             withconfigs
  467.             withaplay
  468.             withamixer
  469.             withalsactl
  470.             withlsmod
  471.             ;;
  472.         --with-all)
  473.             withdevices
  474.             withconfigs
  475.             withaplay
  476.             withamixer
  477.             withalsactl
  478.             withlsmod
  479.             ;;
  480.         --with-aplay)
  481.             withaplay
  482.             ;;
  483.         --with-amixer)
  484.             withamixer
  485.             ;;
  486.         --with-alsactl)
  487.             withalsactl
  488.             ;;
  489.         --with-devices)
  490.             withdevices
  491.             ;;
  492.         --with-configs)
  493.             if [[ -e $HOME/.asoundrc ]] || [[ -e /etc/asound.conf ]]
  494.             then
  495.                 echo "!!ALSA configuration files" >> $FILE
  496.                 echo "!!------------------------" >> $FILE
  497.                 echo "" >> $FILE
  498.  
  499.                 #Check for ~/.asoundrc
  500.                 if [[ -e $HOME/.asoundrc ]]
  501.                 then
  502.                     echo "!!User specific config file ($HOME/.asoundrc)" >> $FILE
  503.                     echo "" >> $FILE
  504.                     cat $HOME/.asoundrc >> $FILE
  505.                     echo "" >> $FILE
  506.                     echo "" >> $FILE
  507.                 fi
  508.  
  509.                 #Check for /etc/asound.conf
  510.                 if [[ -e /etc/asound.conf ]]
  511.                 then
  512.                     echo "!!System wide config file (/etc/asound.conf)" >> $FILE
  513.                     echo "" >> $FILE
  514.                     cat /etc/asound.conf >> $FILE
  515.                     echo "" >> $FILE
  516.                     echo "" >> $FILE
  517.                 fi
  518.             fi
  519.             ;;
  520.         --about)
  521.             echo "Written/Tested by the following users of #alsa on irc.freenode.net:"
  522.             echo ""
  523.             echo "    wishie - Script author and developer / Testing"
  524.             echo "    crimsun - Various script ideas / Testing"
  525.             echo "    gnubien - Various script ideas / Testing"
  526.             echo "    GrueMaster - HDA Intel specific items / Testing"
  527.             echo "    olegfink - Script update function"
  528.             cleanup
  529.             exit 0
  530.             ;;
  531.         *)
  532.             echo "alsa-info.sh version $SCRIPT_VERSION"
  533.             echo ""
  534.             echo "Available options:"
  535.             echo "    --with-aplay (includes the output of aplay -l)"
  536.             echo "    --with-amixer (includes the output of amixer)"
  537.             echo "    --with-alsactl (includes the output of alsactl)"
  538.             echo "    --with-configs (includes the output of ~/.asoundrc and"
  539.             echo "        /etc/asound.conf if they exist)" 
  540.             echo "    --with-devices (shows the device nodes in /dev/snd/)"
  541.             echo ""
  542.             echo "    --update (check server for script updates)"
  543.             echo "    --no-upload (do not upload contents to remote server)"
  544.             echo "    --pastebin (use http://pastebin.ca) as remote server"
  545.             echo "        instead www.alsa-project.org"
  546.             echo "    --about (show some information about the script)"
  547.             echo "    --debug (will run the script as normal, but will not"
  548.             echo "         delete $FILE)"
  549.             cleanup
  550.             exit 0
  551.             ;;
  552.     esac
  553.     shift 1
  554.     done
  555. fi
  556.  
  557. if [ "$PROCEED" = "yes" ]; then
  558.  
  559. #Test that wget is installed, and supports --post-file. Upload $FILE if it does, and prompt user to upload file if it doesnt. 
  560. if
  561. WGET=$(which wget 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null); [[ -n "${WGET}" ]] && [[ -x "${WGET}" ]] && [[ `wget --help |grep post-file` ]]
  562. then
  563. if [[ -n "$DIALOG" ]]
  564. then
  565.     if [[ -z $NOUPLOAD ]]; then
  566.     if [[ -z $PASTEBIN ]]; then
  567.     wget -O - --tries=5 --timeout=60 --post-file=/tmp/alsa-info.txt "http://www.alsa-project.org/cardinfo-db/" &>/tmp/alsainfo/wget.tmp || echo "Upload failed; exit"
  568.     { for i in 10 20 30 40 50 60 70 80 90; do
  569.         echo $i
  570.         sleep 0.2
  571.     done
  572.     echo; } |dialog --backtitle "$BGTITLE" --guage "Uploading information to www.alsa-project.org ..." 6 70 0
  573.     else
  574.     wget -O - --tries=5 --timeout=60 --post-file=/tmp/alsa-info.txt "http://pastebin.ca/quiet-paste.php?api=$PASTEBINKEY&encrypt=t&encryptpw=blahblah" &>/tmp/alsainfo/wget.tmp || echo "Upload failed; exit"
  575.     { for i in 10 20 30 40 50 60 70 80 90; do
  576.         echo $i
  577.         sleep 0.2
  578.     done
  579.     echo; } |dialog --backtitle "$BGTITLE" --guage "Uploading information to www.pastebin.ca ..." 6 70 0
  580.     fi
  581.     fi
  582. else
  583.  
  584.     if [[ -z $NOUPLOAD ]]; then
  585.     if [[ -z $PASTEBIN ]]; then
  586.     echo -n "Uploading information to www.alsa-project.org ... " 
  587.     wget -O - --tries=5 --timeout=60 --post-file=/tmp/alsa-info.txt http://www.alsa-project.org/cardinfo-db/ &>/tmp/alsainfo/wget.tmp &
  588.     else
  589.     echo -n "Uploading information to www.pastebin.ca ... " 
  590.     wget -O - --tries=5 --timeout=60 --post-file=/tmp/alsa-info.txt http://pastebin.ca/quiet-paste.php?api=$PASTEBINKEY &>/tmp/alsainfo/wget.tmp &
  591.     fi
  592.     fi
  593. fi
  594. #Progess spinner for wget transfer.
  595. if [[ -z "$DIALOG" ]]    
  596. then
  597.     i=1
  598.     sp="/-\|"
  599.     echo -n ' '
  600.     while pgrep wget &>/dev/null
  601.     do
  602.     echo -en "\b${sp:i++%${#sp}:1}"
  603.     done
  604. fi
  605.  
  606. #See if tput is available, and use it if it is.    
  607. if [[ -z $NOUPLOAD ]]; then
  608.     if [[ -n "$TPUT" ]]
  609.     then
  610.         if [[ -z $PASTEBIN ]]; then
  611.             FINAL_URL=`tput setaf 1; grep "SUCCESS:" /tmp/alsainfo/wget.tmp | cut -d ' ' -f 2 ; tput sgr0`
  612.         else
  613.             FINAL_URL=`tput setaf 1; grep "SUCCESS:" /tmp/alsainfo/wget.tmp |sed -n 's/.*\:\([0-9]\+\).*/http:\/\/pastebin.ca\/\1/p';tput sgr0`
  614.         fi
  615.     else
  616.         if [[ -z $PASTEBIN ]]; then
  617.             FINAL_URL=`grep "SUCCESS:" /tmp/alsainfo/wget.tmp | cut -d ' ' -f 2`
  618.         else
  619.             FINAL_URL=`grep "SUCCESS:" /tmp/alsainfo/wget.tmp |sed -n 's/.*\:\([0-9]\+\).*/http:\/\/pastebin.ca\/\1/p'`
  620.         fi
  621.     fi
  622. fi
  623. #Output the URL of the uploaded file.    
  624. if [[ -z $DIALOG ]]
  625. then
  626.     echo -e "\b Done!"
  627.     echo ""
  628.     if [[ -z $NOUPLOAD ]]; then
  629.         echo "Your ALSA information is located at $FINAL_URL"
  630.         echo "Please inform the person helping you."
  631.         echo ""
  632.     fi
  633. fi
  634. if [[ -n $DIALOG ]]
  635. then
  636.     if [[ -n $NOUPLOAD ]]; then
  637.         if [[ -n $PBERROR ]]; then
  638.             dialog --backtitle "$BGTITLE" --title "Information collected" --msgbox "An error occured while contacting the $WWWSERVICE. Your information was NOT automatically uploaded.\n\nYour ALSA information can be seen by looking in $FILE" 10 100
  639.         else
  640.             dialog --backtitle "$BGTITLE" --title "Information collected" --msgbox "You requested that your information was NOT automatically uploaded to the $WWWSERVICE\n\nYour ALSA information can be seen by looking in $FILE" 10 100
  641.         fi
  642.     else
  643.         dialog --backtitle "$BGTITLE" --title "Information uploaded" --yesno "Would you like to see the uploaded information?" 5 100 
  644.         DIALOG_EXIT_CODE=$?
  645.     if [ $DIALOG_EXIT_CODE = 0 ]; then
  646.         grep -v "alsa-info.txt" /tmp/alsa-info.txt >/tmp/alsainfo/uploaded.txt
  647.         dialog --backtitle "$BGTITLE" --textbox /tmp/alsainfo/uploaded.txt 0 0
  648.     fi
  649.     fi
  650. fi 
  651. clear
  652. if [[ -n $NOUPLOAD ]]; then
  653.     if [[ -n $PBERROR ]]; then
  654.         echo "An error occured while contacting the $WWWSERVICE. Your information was NOT automatically uploaded."
  655.         echo ""
  656.         echo "Your ALSA information can be seen by looking in $FILE"
  657.         echo ""
  658.     else
  659.         echo "You requested that your information was NOT automatically uploaded to the $WWWSERVICE"
  660.         echo ""
  661.         echo "Your ALSA information can be seen by looking in $FILE"
  662.         echo ""
  663.     fi
  664. fi
  665. if [[ -z $NOUPLOAD ]]; then
  666. echo "Your ALSA information is located at $FINAL_URL"
  667. echo "Please inform the person helping you."
  668. echo ""
  669. fi
  670.     #We posted the file , so we dont need it anymore. delete it.
  671.     if [ -z $KEEP_FILES ]
  672.     then
  673.         rm $FILE 
  674.     fi
  675.  
  676. #We couldnt find a suitable wget, so tell the user to upload manually.
  677. else
  678.     if [[ -z $DIALOG ]]
  679.     then
  680.         if [[ -z $PASTEBIN ]]; then
  681.         echo ""
  682.         echo "Could not automatically upload output to http://www.alsa-project.org"
  683.         echo "Possible reasons are:"
  684.         echo "    1. Couldnt find 'wget' in your PATH"
  685.         echo "    2. Your version of wget is less than 1.8.2"
  686.         echo ""
  687.         echo "Please manually upload $FILE to http://www.alsa-project.org/cardinfo-db/ and submit your post."
  688.         echo ""
  689.         else
  690.         echo ""
  691.         echo "Could not automatically upload output to http://www.pastebin.ca"
  692.         echo "Possible reasons are:"
  693.         echo "    1. Couldnt find 'wget' in your PATH"
  694.         echo "    2. Your version of wget is less than 1.8.2"
  695.         echo ""
  696.         echo "Please manually upload $FILE to http://www.pastebin.ca/upload.php and submit your post."
  697.         echo ""
  698.         fi
  699.     fi
  700.     if [[ -n $DIALOG ]]
  701.     then
  702.         if [[ -z $PASTEBIN ]]; then
  703.             dialog --backtitle "$BGTITLE" --msgbox "Could not automatically upload output to http://www.alsa-project.org.\nPossible reasons are:\n\n    1. Couldn't find 'wget' in your PATH\n    2. Your version of wget is less than 1.8.2\n\nPlease manually upload $FILE to http://www.alsa-project,org/cardinfo-db/ and submit your post." 25 100
  704.         else
  705.             dialog --backtitle "$BGTITLE" --msgbox "Could not automatically upload output to http://www.pastebin.ca.\nPossible reasons are:\n\n    1. Couldn't find 'wget' in your PATH\n    2. Your version of wget is less than 1.8.2\n\nPlease manually upload $FILE to http://www.pastebin.ca/upload.php and submit your post." 25 100
  706.         fi
  707.     fi
  708. fi
  709. #Clean up the temp files
  710. if [ -z $KEEP_FILES ]
  711. then
  712.     cleanup
  713. fi
  714.  
  715. fi # proceed
  716.