tarina

git clone https://git.tarina.org/tarina
Log | Files | Refs | README | LICENSE

alsa-info.sh (27872B)


      1 #!/bin/bash
      2 
      3 SCRIPT_VERSION=0.4.64
      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 #Set the locale (this may or may not be a good idea.. let me know)
     30 export LC_ALL=C
     31 
     32 #Change the PATH variable, so we can run lspci (needed for some distros)
     33 PATH=$PATH:/bin:/sbin:/usr/bin:/usr/sbin
     34 BGTITLE="ALSA-Info v $SCRIPT_VERSION"
     35 PASTEBINKEY="C9cRIO8m/9y8Cs0nVs0FraRx7U0pHsuc"
     36 #Define some simple functions
     37 
     38 WGET=$(which wget 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null)
     39 
     40 pbcheck(){
     41 	[[ $UPLOAD = "no" ]] && return
     42 
     43 	if [[ -z $PASTEBIN ]]; then
     44 		[[ $(ping -c1 www.alsa-project.org) ]] || KEEP_FILES="yes" UPLOAD="no" PBERROR="yes"
     45 	else
     46 		[[ $(ping -c1 www.pastebin.ca) ]] || KEEP_FILES="yes" UPLOAD="no" PBERROR="yes"
     47 	fi
     48 }
     49 
     50 update() {
     51 	test -z "$WGET" -o ! -x "$WGET" && return
     52 
     53 	SHFILE=`mktemp -t alsa-info.XXXXXXXXXX` || exit 1
     54 	wget -O $SHFILE "http://www.alsa-project.org/alsa-info.sh" >/dev/null 2>&1
     55 	REMOTE_VERSION=`grep SCRIPT_VERSION $SHFILE |head -n1 |sed 's/.*=//'`
     56 	if [ -s "$SHFILE" -a "$REMOTE_VERSION" != "$SCRIPT_VERSION" ]; then
     57 		if [[ -n $DIALOG ]]
     58 		then
     59 			OVERWRITE=
     60 			if [ -w $0 ]; then
     61 				dialog --yesno "Newer version of ALSA-Info has been found\n\nDo you wish to install it?\nNOTICE: The original file $0 will be overwritten!" 0 0
     62 				DIALOG_EXIT_CODE=$?
     63 				if [[ $DIALOG_EXIT_CODE = 0 ]]; then
     64 				  OVERWRITE=yes
     65 				fi
     66 			fi
     67 			if [ -z "$OVERWRITE" ]; then
     68 				dialog --yesno "Newer version of ALSA-Info has been found\n\nDo you wish to download it?" 0 0
     69 				DIALOG_EXIT_CODE=$?
     70 			fi
     71 			if [[ $DIALOG_EXIT_CODE = 0 ]]
     72 			then
     73 				echo "Newer version detected: $REMOTE_VERSION"
     74 				echo "To view the ChangeLog, please visit $CHANGELOG"
     75 				if [ "$OVERWRITE" = "yes" ]; then
     76 					cp $SHFILE $0
     77 					echo "ALSA-Info script has been updated to v $REMOTE_VERSION"
     78 					echo "Please re-run the script"
     79 					rm $SHFILE 2>/dev/null
     80 				else
     81 					echo "ALSA-Info script has been downloaded as $SHFILE."
     82 					echo "Please re-run the script from new location."
     83 				fi
     84 				exit
     85 			else
     86 				rm $SHFILE 2>/dev/null
     87 			fi
     88 		else
     89 			echo "Newer version detected: $REMOTE_VERSION"
     90 			echo "To view the ChangeLog, please visit $CHANGELOG"
     91 			if [ -w $0 ]; then
     92 				echo "The original file $0 will be overwritten!"
     93 				echo -n "If you do not like to proceed, press Ctrl-C now.." ; read inp
     94 				cp $SHFILE $0
     95 				echo "ALSA-Info script has been updated. Please re-run it."
     96 				rm $SHFILE 2>/dev/null
     97 			else
     98 				echo "ALSA-Info script has been downloaded $SHFILE."
     99 				echo "Please, re-run it from new location."
    100 			fi
    101 			exit
    102 		fi
    103 	else
    104 		rm $SHFILE 2>/dev/null
    105 	fi
    106 }
    107 
    108 cleanup() {
    109 	if [ -n "$TEMPDIR" -a "$KEEP_FILES" != "yes" ]; then
    110 		rm -rf "$TEMPDIR" 2>/dev/null
    111 	fi
    112 	test -n "$KEEP_OUTPUT" || rm -f "$NFILE"
    113 }
    114 
    115 
    116 withaplay() {
    117         echo "!!Aplay/Arecord output" >> $FILE
    118         echo "!!--------------------" >> $FILE
    119         echo "" >> $FILE
    120        	echo "APLAY" >> $FILE
    121 	echo "" >> $FILE 
    122 	aplay -l >> $FILE 2>&1
    123         echo "" >> $FILE
    124        	echo "ARECORD" >> $FILE
    125 	echo "" >> $FILE
    126 	arecord -l >> $FILE 2>&1
    127 	echo "" >> $FILE
    128 }
    129 
    130 withlsmod() {
    131 	echo "!!All Loaded Modules" >> $FILE
    132 	echo "!!------------------" >> $FILE
    133 	echo "" >> $FILE
    134 	lsmod |awk {'print $1'} >> $FILE
    135 	echo "" >> $FILE
    136 	echo "" >> $FILE
    137 }
    138 
    139 withamixer() {
    140         echo "!!Amixer output" >> $FILE
    141         echo "!!-------------" >> $FILE
    142         echo "" >> $FILE
    143 	for i in `grep "]: " /proc/asound/cards | awk -F ' ' '{ print $1} '` ; do
    144 	CARD_NAME=`grep "^ *$i " $TEMPDIR/alsacards.tmp|awk {'print $2'}`
    145 	echo "!!-------Mixer controls for card $i $CARD_NAME]" >> $FILE
    146 	echo "" >>$FILE
    147 	amixer -c$i info>> $FILE 2>&1
    148 	amixer -c$i>> $FILE 2>&1
    149         echo "" >> $FILE
    150 	done
    151 	echo "" >> $FILE
    152 }
    153 
    154 withalsactl() {
    155 	echo "!!Alsactl output" >> $FILE
    156         echo "!!--------------" >> $FILE
    157         echo "" >> $FILE
    158         exe=""
    159         if [ -x /usr/sbin/alsactl ]; then
    160         	exe="/usr/sbin/alsactl"
    161         fi
    162         if [ -x /usr/local/sbin/alsactl ]; then
    163         	exe="/usr/local/sbin/alsactl"
    164         fi
    165         if [ -z "$exe" ]; then
    166         	exe=`whereis alsactl | cut -d ' ' -f 2`
    167         fi
    168 	$exe -f $TEMPDIR/alsactl.tmp store
    169 	echo "--startcollapse--" >> $FILE
    170 	cat $TEMPDIR/alsactl.tmp >> $FILE
    171 	echo "--endcollapse--" >> $FILE
    172 	echo "" >> $FILE
    173 	echo "" >> $FILE
    174 }
    175 
    176 withdevices() {
    177         echo "!!ALSA Device nodes" >> $FILE
    178         echo "!!-----------------" >> $FILE
    179         echo "" >> $FILE
    180         ls -la /dev/snd/* >> $FILE
    181         echo "" >> $FILE
    182         echo "" >> $FILE
    183 }
    184 
    185 withconfigs() {
    186 if [[ -e $HOME/.asoundrc ]] || [[ -e /etc/asound.conf ]] || [[ -e $HOME/.asoundrc.asoundconf ]]
    187 then
    188         echo "!!ALSA configuration files" >> $FILE
    189         echo "!!------------------------" >> $FILE
    190         echo "" >> $FILE
    191 
    192         #Check for ~/.asoundrc
    193         if [[ -e $HOME/.asoundrc ]]
    194         then
    195                 echo "!!User specific config file (~/.asoundrc)" >> $FILE
    196                 echo "" >> $FILE
    197                 cat $HOME/.asoundrc >> $FILE
    198                 echo "" >> $FILE
    199                 echo "" >> $FILE
    200         fi
    201 	#Check for .asoundrc.asoundconf (seems to be Ubuntu specific)
    202 	if [[ -e $HOME/.asoundrc.asoundconf ]]
    203 	then
    204 		echo "!!asoundconf-generated config file" >> $FILE
    205 		echo "" >> $FILE
    206 		cat $HOME/.asoundrc.asoundconf >> $FILE
    207 		echo "" >> $FILE
    208 		echo "" >> $FILE
    209 	fi
    210         #Check for /etc/asound.conf
    211         if [[ -e /etc/asound.conf ]]
    212         then
    213                 echo "!!System wide config file (/etc/asound.conf)" >> $FILE
    214                 echo "" >> $FILE
    215                 cat /etc/asound.conf >> $FILE
    216                 echo "" >> $FILE
    217                 echo "" >> $FILE
    218         fi
    219 fi
    220 }
    221 
    222 withsysfs() {
    223     local i f
    224     local printed=""
    225     for i in /sys/class/sound/*; do
    226 	case "$i" in
    227 	    */hwC?D?)
    228 		if [ -f $i/init_pin_configs ]; then
    229 		    if [ -z "$printed" ]; then
    230 			echo "!!Sysfs Files" >> $FILE
    231 			echo "!!-----------" >> $FILE
    232 			echo "" >> $FILE
    233 		    fi
    234 		    for f in init_pin_configs driver_pin_configs user_pin_configs init_verbs hints; do
    235 			echo "$i/$f:" >> $FILE
    236 			cat $i/$f >> $FILE
    237 			echo >> $FILE
    238 		    done
    239 		    printed=yes
    240 		fi
    241 		;;
    242 	    esac
    243     done
    244     if [ -n "$printed" ]; then
    245 	echo "" >> $FILE
    246     fi
    247 }
    248 
    249 withdmesg() {
    250 	echo "!!ALSA/HDA dmesg" >> $FILE
    251 	echo "!!--------------" >> $FILE
    252 	echo "" >> $FILE
    253 	dmesg | grep -C1 -E 'ALSA|HDA|HDMI|snd[_-]|sound|hda.codec|hda.intel' >> $FILE
    254 	echo "" >> $FILE
    255 	echo "" >> $FILE
    256 }
    257 
    258 withall() {
    259 	withdevices
    260 	withconfigs
    261 	withaplay
    262 	withamixer
    263 	withalsactl
    264 	withlsmod
    265 	withsysfs
    266 	withdmesg
    267 	WITHALL="no"
    268 }
    269 
    270 get_alsa_library_version() {
    271 	ALSA_LIB_VERSION=`grep VERSION_STR /usr/include/alsa/version.h 2>/dev/null|awk {'print $3'}|sed 's/"//g'`
    272 
    273 	if [ -z "$ALSA_LIB_VERSION" ]; then
    274 		if [ -f /etc/lsb-release ]; then
    275 			. /etc/lsb-release
    276 			case "$DISTRIB_ID" in
    277 				Ubuntu)
    278 					if which dpkg > /dev/null ; then
    279 						ALSA_LIB_VERSION=`dpkg -l libasound2 | tail -1 | awk '{print $3}' | cut -f 1 -d -`
    280 					fi
    281 
    282 					if [ "$ALSA_LIB_VERSION" = "<none>" ]; then
    283 						ALSA_LIB_VERSION=""
    284 					fi
    285 					return
    286 					;;
    287 				*)
    288 					return
    289 					;;
    290 			esac
    291 		elif [ -f /etc/debian_version ]; then
    292 			if which dpkg > /dev/null ; then
    293 				ALSA_LIB_VERSION=`dpkg -l libasound2 | tail -1 | awk '{print $3}' | cut -f 1 -d -`
    294 			fi
    295 
    296 			if [ "$ALSA_LIB_VERSION" = "<none>" ]; then
    297 				ALSA_LIB_VERSION=""
    298 			fi
    299 			return
    300 		fi
    301 	fi
    302 }
    303 
    304 
    305 #Run checks to make sure the programs we need are installed.
    306 LSPCI=$(which lspci 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null);
    307 TPUT=$(which tput 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null);
    308 DIALOG=$(which dialog 2>/dev/null | sed 's|^[^/]*||' 2>/dev/null);
    309 
    310 #Check to see if sysfs is enabled in the kernel. We'll need this later on
    311 SYSFS=$(mount |grep sysfs|awk {'print $3'});
    312 
    313 #Check modprobe config files for sound related options
    314 SNDOPTIONS=$(modprobe -c|sed -n 's/^options \(snd[-_][^ ]*\)/\1:/p')
    315 
    316 KEEP_OUTPUT=
    317 NFILE=""
    318 
    319 PASTEBIN=""
    320 WWWSERVICE="www.alsa-project.org"
    321 WELCOME="yes"
    322 PROCEED="yes"
    323 UPLOAD="ask"
    324 REPEAT=""
    325 while [ -z "$REPEAT" ]; do
    326 REPEAT="no"
    327 case "$1" in
    328 	--update|--help|--about)
    329 		WELCOME="no"
    330 		PROCEED="no"
    331 		;;
    332 	--upload)
    333 		UPLOAD="yes"
    334 		WELCOME="no"
    335 		;;
    336 	--no-upload)
    337 		UPLOAD="no"
    338 		WELCOME="no"
    339 		;;
    340 	--pastebin)
    341 		PASTEBIN="yes"
    342 		WWWSERVICE="pastebin"
    343 		;;
    344 	--no-dialog)
    345 		DIALOG=""
    346 		REPEAT=""
    347 		shift
    348 		;;
    349 	--stdout)
    350 		DIALOG=""
    351 		UPLOAD="no"
    352 		WELCOME="no"
    353 		TOSTDOUT="yes"
    354 		;;
    355 esac
    356 done
    357 
    358 
    359 #Script header output.
    360 if [ "$WELCOME" = "yes" ]; then
    361 greeting_message="\
    362 
    363 This script visits the following commands/files to collect diagnostic
    364 information about your ALSA installation and sound related hardware.
    365 
    366   dmesg
    367   lspci
    368   lsmod
    369   aplay
    370   amixer
    371   alsactl
    372   /proc/asound/
    373   /sys/class/sound/
    374   ~/.asoundrc (etc.)
    375 
    376 See '$0 --help' for command line options.
    377 "
    378 if [ -n "$DIALOG" ]; then
    379 	dialog  --backtitle "$BGTITLE" \
    380 		--title "ALSA-Info script v $SCRIPT_VERSION" \
    381 		--msgbox "$greeting_message" 20 80
    382 else
    383 	echo "ALSA Information Script v $SCRIPT_VERSION"
    384 	echo "--------------------------------"
    385 	echo "$greeting_message"
    386 fi # dialog
    387 fi # WELCOME
    388 
    389 #Set the output file
    390 TEMPDIR=`mktemp -t -d alsa-info.XXXXXXXXXX` || exit 1
    391 FILE="$TEMPDIR/alsa-info.txt"
    392 if [ -z "$NFILE" ]; then
    393 	NFILE=`mktemp -t alsa-info.txt.XXXXXXXXXX` || exit 1
    394 fi
    395 
    396 trap cleanup 0
    397 
    398 if [ "$PROCEED" = "yes" ]; then
    399 
    400 if [ -z "$LSPCI" ]; then
    401 	if [ -d /sys/bus/pci ]; then
    402 		echo "This script requires lspci. Please install it, and re-run this script."
    403 		exit 0
    404 	fi
    405 fi
    406 
    407 #Fetch the info and store in temp files/variables
    408 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}`
    409 KERNEL_VERSION=`uname -r`
    410 KERNEL_PROCESSOR=`uname -p`
    411 KERNEL_MACHINE=`uname -m`
    412 KERNEL_OS=`uname -o`
    413 [[ `uname -v | grep SMP`  ]] && KERNEL_SMP="Yes" || KERNEL_SMP="No" 
    414 ALSA_DRIVER_VERSION=`cat /proc/asound/version |head -n1|awk {'print $7'} |sed 's/\.$//'`
    415 get_alsa_library_version
    416 ALSA_UTILS_VERSION=`amixer -v |awk {'print $3'}`
    417 LAST_CARD=$((`grep "]: " /proc/asound/cards | wc -l` - 1 ))
    418 
    419 ESDINST=$(which esd 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null)
    420 PAINST=$(which pulseaudio 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null)
    421 ARTSINST=$(which artsd 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null)
    422 JACKINST=$(which jackd 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null)
    423 ROARINST=$(which roard 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null)
    424 DMIDECODE=$(which dmidecode 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null)
    425 
    426 #Check for DMI data
    427 if [ -d /sys/class/dmi/id ]; then
    428     # No root privileges are required when using sysfs method
    429     DMI_SYSTEM_MANUFACTURER=$(cat /sys/class/dmi/id/sys_vendor 2>/dev/null)
    430     DMI_SYSTEM_PRODUCT_NAME=$(cat /sys/class/dmi/id/product_name 2>/dev/null)
    431     DMI_SYSTEM_PRODUCT_VERSION=$(cat /sys/class/dmi/id/product_version 2>/dev/null)
    432     DMI_SYSTEM_FIRMWARE_VERSION=$(cat /sys/class/dmi/id/bios_version 2>/dev/null)
    433 elif [ -x $DMIDECODE ]; then
    434     DMI_SYSTEM_MANUFACTURER=$($DMIDECODE -s system-manufacturer 2>/dev/null)
    435     DMI_SYSTEM_PRODUCT_NAME=$($DMIDECODE -s system-product-name 2>/dev/null)
    436     DMI_SYSTEM_PRODUCT_VERSION=$($DMIDECODE -s system-version 2>/dev/null)
    437     DMI_SYSTEM_FIRMWARE_VERSION=$($DMIDECODE -s bios-version 2>/dev/null)
    438 fi
    439 
    440 cat /proc/asound/modules 2>/dev/null|awk {'print $2'}>$TEMPDIR/alsamodules.tmp
    441 cat /proc/asound/cards >$TEMPDIR/alsacards.tmp
    442 if [[ ! -z "$LSPCI" ]]; then
    443 lspci |grep -i "multi\|audio">$TEMPDIR/lspci.tmp
    444 fi
    445 
    446 #Check for HDA-Intel cards codec#*
    447 cat /proc/asound/card*/codec\#* > $TEMPDIR/alsa-hda-intel.tmp 2> /dev/null
    448 
    449 #Check for AC97 cards codec
    450 cat /proc/asound/card*/codec97\#0/ac97\#0-0 > $TEMPDIR/alsa-ac97.tmp 2> /dev/null
    451 cat /proc/asound/card*/codec97\#0/ac97\#0-0+regs > $TEMPDIR/alsa-ac97-regs.tmp 2> /dev/null
    452 
    453 #Check for USB mixer setup
    454 cat /proc/asound/card*/usbmixer > $TEMPDIR/alsa-usbmixer.tmp 2> /dev/null
    455 
    456 #Fetch the info, and put it in $FILE in a nice readable format.
    457 if [[ -z $PASTEBIN ]]; then
    458 echo "upload=true&script=true&cardinfo=" > $FILE
    459 else
    460 echo "name=$USER&type=33&description=/tmp/alsa-info.txt&expiry=&s=Submit+Post&content=" > $FILE
    461 fi
    462 echo "!!################################" >> $FILE
    463 echo "!!ALSA Information Script v $SCRIPT_VERSION" >> $FILE
    464 echo "!!################################" >> $FILE
    465 echo "" >> $FILE
    466 echo "!!Script ran on: `LANG=C TZ=UTC date`" >> $FILE
    467 echo "" >> $FILE
    468 echo "" >> $FILE
    469 echo "!!Linux Distribution" >> $FILE
    470 echo "!!------------------" >> $FILE
    471 echo "" >> $FILE
    472 echo $DISTRO >> $FILE
    473 echo "" >> $FILE
    474 echo "" >> $FILE
    475 echo "!!DMI Information" >> $FILE
    476 echo "!!---------------" >> $FILE
    477 echo "" >> $FILE
    478 echo "Manufacturer:      $DMI_SYSTEM_MANUFACTURER" >> $FILE
    479 echo "Product Name:      $DMI_SYSTEM_PRODUCT_NAME" >> $FILE
    480 echo "Product Version:   $DMI_SYSTEM_PRODUCT_VERSION" >> $FILE
    481 echo "Firmware Version:  $DMI_SYSTEM_FIRMWARE_VERSION" >> $FILE
    482 echo "" >> $FILE
    483 echo "" >> $FILE
    484 echo "!!Kernel Information" >> $FILE
    485 echo "!!------------------" >> $FILE
    486 echo "" >> $FILE
    487 echo "Kernel release:    $KERNEL_VERSION" >> $FILE
    488 echo "Operating System:  $KERNEL_OS" >> $FILE
    489 echo "Architecture:      $KERNEL_MACHINE" >> $FILE
    490 echo "Processor:         $KERNEL_PROCESSOR" >> $FILE
    491 echo "SMP Enabled:       $KERNEL_SMP" >> $FILE
    492 echo "" >> $FILE
    493 echo "" >> $FILE
    494 echo "!!ALSA Version" >> $FILE
    495 echo "!!------------" >> $FILE
    496 echo "" >> $FILE
    497 echo "Driver version:     $ALSA_DRIVER_VERSION" >> $FILE
    498 echo "Library version:    $ALSA_LIB_VERSION" >> $FILE
    499 echo "Utilities version:  $ALSA_UTILS_VERSION" >> $FILE
    500 echo "" >> $FILE
    501 echo "" >> $FILE
    502 echo "!!Loaded ALSA modules" >> $FILE
    503 echo "!!-------------------" >> $FILE
    504 echo "" >> $FILE
    505 cat $TEMPDIR/alsamodules.tmp >> $FILE
    506 echo "" >> $FILE
    507 echo "" >> $FILE
    508 echo "!!Sound Servers on this system" >> $FILE
    509 echo "!!----------------------------" >> $FILE
    510 echo "" >> $FILE
    511 if [[ -n $PAINST ]];then
    512 [[ `pgrep '^(.*/)?pulseaudio$'` ]] && PARUNNING="Yes" || PARUNNING="No"
    513 echo "Pulseaudio:" >> $FILE
    514 echo "      Installed - Yes ($PAINST)" >> $FILE
    515 echo "      Running - $PARUNNING" >> $FILE
    516 echo "" >> $FILE
    517 fi
    518 if [[ -n $ESDINST ]];then
    519 [[ `pgrep '^(.*/)?esd$'` ]] && ESDRUNNING="Yes" || ESDRUNNING="No"
    520 echo "ESound Daemon:" >> $FILE
    521 echo "      Installed - Yes ($ESDINST)" >> $FILE
    522 echo "      Running - $ESDRUNNING" >> $FILE
    523 echo "" >> $FILE
    524 fi
    525 if [[ -n $ARTSINST ]];then
    526 [[ `pgrep '^(.*/)?artsd$'` ]] && ARTSRUNNING="Yes" || ARTSRUNNING="No"
    527 echo "aRts:" >> $FILE
    528 echo "      Installed - Yes ($ARTSINST)" >> $FILE
    529 echo "      Running - $ARTSRUNNING" >> $FILE
    530 echo "" >> $FILE
    531 fi
    532 if [[ -n $JACKINST ]];then
    533 [[ `pgrep '^(.*/)?jackd$'` ]] && JACKRUNNING="Yes" || JACKRUNNING="No"
    534 echo "Jack:" >> $FILE
    535 echo "      Installed - Yes ($JACKINST)" >> $FILE
    536 echo "      Running - $JACKRUNNING" >> $FILE
    537 echo "" >> $FILE
    538 fi
    539 if [[ -n $ROARINST ]];then
    540 [[ `pgrep '^(.*/)?roard$'` ]] && ROARRUNNING="Yes" || ROARRUNNING="No"
    541 echo "RoarAudio:" >> $FILE
    542 echo "      Installed - Yes ($ROARINST)" >> $FILE
    543 echo "      Running - $ROARRUNNING" >> $FILE
    544 echo "" >> $FILE
    545 fi
    546 if [[ -z "$PAINST" && -z "$ESDINST" && -z "$ARTSINST" && -z "$JACKINST" && -z "$ROARINST" ]];then
    547 echo "No sound servers found." >> $FILE
    548 echo "" >> $FILE
    549 fi
    550 echo "" >> $FILE
    551 echo "!!Soundcards recognised by ALSA" >> $FILE
    552 echo "!!-----------------------------" >> $FILE
    553 echo "" >> $FILE
    554 cat $TEMPDIR/alsacards.tmp >> $FILE
    555 echo "" >> $FILE
    556 echo "" >> $FILE
    557 
    558 if [[ ! -z "$LSPCI" ]]; then
    559 echo "!!PCI Soundcards installed in the system" >> $FILE
    560 echo "!!--------------------------------------" >> $FILE
    561 echo "" >> $FILE
    562 cat $TEMPDIR/lspci.tmp >> $FILE
    563 echo "" >> $FILE
    564 echo "" >> $FILE
    565 echo "!!Advanced information - PCI Vendor/Device/Subsystem ID's" >> $FILE
    566 echo "!!-------------------------------------------------------" >> $FILE
    567 echo "" >> $FILE
    568 lspci -vvn |grep -A1 040[1-3] >> $FILE
    569 echo "" >> $FILE
    570 echo "" >> $FILE
    571 fi
    572 
    573 if [ "$SNDOPTIONS" ]
    574 then
    575 echo "!!Modprobe options (Sound related)" >> $FILE
    576 echo "!!--------------------------------" >> $FILE
    577 echo "" >> $FILE
    578 modprobe -c|sed -n 's/^options \(snd[-_][^ ]*\)/\1:/p' >> $FILE
    579 echo "" >> $FILE
    580 echo "" >> $FILE
    581 fi
    582 
    583 if [ -d "$SYSFS" ]
    584 then
    585 echo "!!Loaded sound module options" >> $FILE
    586 echo "!!---------------------------" >> $FILE
    587 echo "" >> $FILE
    588 for mod in `cat /proc/asound/modules|awk {'print $2'}`;do
    589 echo "!!Module: $mod" >> $FILE
    590 for params in `echo $SYSFS/module/$mod/parameters/*`; do
    591 	echo -ne "\t";
    592 	echo "$params : `cat $params`" | sed 's:.*/::';
    593 done >> $FILE
    594 echo "" >> $FILE
    595 done
    596 echo "" >> $FILE
    597 fi
    598 
    599 if [ -s "$TEMPDIR/alsa-hda-intel.tmp" ]; then
    600 	echo "!!HDA-Intel Codec information" >> $FILE
    601 	echo "!!---------------------------" >> $FILE
    602 	echo "--startcollapse--" >> $FILE
    603 	echo "" >> $FILE
    604 	cat $TEMPDIR/alsa-hda-intel.tmp >> $FILE
    605 	echo "--endcollapse--" >> $FILE
    606 	echo "" >> $FILE
    607 	echo "" >> $FILE
    608 fi
    609 
    610 if [ -s "$TEMPDIR/alsa-ac97.tmp" ]; then
    611         echo "!!AC97 Codec information" >> $FILE
    612         echo "!!----------------------" >> $FILE
    613         echo "--startcollapse--" >> $FILE
    614         echo "" >> $FILE
    615         cat $TEMPDIR/alsa-ac97.tmp >> $FILE
    616         echo "" >> $FILE
    617         cat $TEMPDIR/alsa-ac97-regs.tmp >> $FILE
    618         echo "--endcollapse--" >> $FILE
    619 	echo "" >> $FILE
    620 	echo "" >> $FILE
    621 fi
    622 
    623 if [ -s "$TEMPDIR/alsa-usbmixer.tmp" ]; then
    624         echo "!!USB Mixer information" >> $FILE
    625         echo "!!---------------------" >> $FILE
    626         echo "--startcollapse--" >> $FILE
    627         echo "" >> $FILE
    628         cat $TEMPDIR/alsa-usbmixer.tmp >> $FILE
    629         echo "--endcollapse--" >> $FILE
    630 	echo "" >> $FILE
    631 	echo "" >> $FILE
    632 fi
    633 
    634 #If no command line options are specified, then run as though --with-all was specified
    635 if [ -z "$1" ]; then
    636 	update
    637 	pbcheck	
    638 fi
    639 
    640 fi # proceed
    641 
    642 #loop through command line arguments, until none are left.
    643 if [ -n "$1" ]; then
    644 	until [ -z "$1" ]
    645 	do
    646 	case "$1" in
    647 		--pastebin)
    648 		        update
    649         		pbcheck
    650 			;;
    651 		--update)
    652 			update
    653 			exit
    654 			;;
    655 		--upload)
    656 			UPLOAD="yes"
    657 			;;
    658 		--no-upload)
    659 			UPLOAD="no"
    660 			;;
    661 		--output)
    662 			shift
    663 			NFILE="$1"
    664 			KEEP_OUTPUT="yes"
    665 			;;
    666 		--debug)
    667 			echo "Debugging enabled. $FILE and $TEMPDIR will not be deleted"
    668 			KEEP_FILES="yes"
    669 			echo ""
    670 			;;
    671 		--with-all)
    672 			withall
    673 			;;
    674 		--with-aplay)
    675 			withaplay
    676 			WITHALL="no"
    677 			;;
    678 		--with-amixer)
    679 			withamixer
    680 			WITHALL="no"
    681 			;;
    682 		--with-alsactl)
    683 			withalsactl
    684 			WITHALL="no"
    685 			;;
    686 		--with-devices)
    687 			withdevices
    688 			WITHALL="no"
    689 			;;
    690 		--with-dmesg)
    691 			withdmesg
    692 			WITHALL="no"
    693 			;;
    694 		--with-configs)
    695 			WITHALL="no"
    696 			if [[ -e $HOME/.asoundrc ]] || [[ -e /etc/asound.conf ]]
    697 			then
    698 				echo "!!ALSA configuration files" >> $FILE
    699 				echo "!!------------------------" >> $FILE
    700 				echo "" >> $FILE
    701 
    702 				#Check for ~/.asoundrc
    703 				if [[ -e $HOME/.asoundrc ]]
    704 				then
    705 					echo "!!User specific config file ($HOME/.asoundrc)" >> $FILE
    706 					echo "" >> $FILE
    707 					cat $HOME/.asoundrc >> $FILE
    708 					echo "" >> $FILE
    709 					echo "" >> $FILE
    710 				fi
    711 
    712 				#Check for /etc/asound.conf
    713 				if [[ -e /etc/asound.conf ]]
    714 				then
    715 					echo "!!System wide config file (/etc/asound.conf)" >> $FILE
    716 					echo "" >> $FILE
    717 					cat /etc/asound.conf >> $FILE
    718 					echo "" >> $FILE
    719 					echo "" >> $FILE
    720 				fi
    721 			fi
    722 			;;
    723 		--stdout)
    724 			UPLOAD="no"
    725 			if [ -z "$WITHALL" ]; then
    726 				withall
    727 			fi
    728 			cat $FILE
    729 			rm $FILE
    730 			;;
    731 		--about)
    732 			echo "Written/Tested by the following users of #alsa on irc.freenode.net:"
    733 			echo ""
    734 			echo "	wishie - Script author and developer / Testing"
    735 			echo "	crimsun - Various script ideas / Testing"
    736 			echo "	gnubien - Various script ideas / Testing"
    737 			echo "	GrueMaster - HDA Intel specific items / Testing"
    738 			echo "	olegfink - Script update function"
    739 			echo "  TheMuso - display to stdout functionality"
    740 			exit 0
    741 			;;
    742 		*)
    743 			echo "alsa-info.sh version $SCRIPT_VERSION"
    744 			echo ""
    745 			echo "Available options:"
    746 			echo "	--with-aplay (includes the output of aplay -l)"
    747 			echo "	--with-amixer (includes the output of amixer)"
    748 			echo "	--with-alsactl (includes the output of alsactl)"
    749 			echo "	--with-configs (includes the output of ~/.asoundrc and"
    750 			echo "	    /etc/asound.conf if they exist)" 
    751 			echo "	--with-devices (shows the device nodes in /dev/snd/)"
    752 			echo "	--with-dmesg (shows the ALSA/HDA kernel messages)"
    753 			echo ""
    754 			echo "	--output FILE (specify the file to output for no-upload mode)"
    755 			echo "	--update (check server for script updates)"
    756 			echo "	--upload (upload contents to remote server)"
    757 			echo "	--no-upload (do not upload contents to remote server)"
    758 			echo "	--pastebin (use http://pastebin.ca) as remote server"
    759 			echo "	    instead www.alsa-project.org"
    760 			echo "	--stdout (print alsa information to standard output"
    761 			echo "	    instead of a file)"
    762 			echo "	--about (show some information about the script)"
    763 			echo "	--debug (will run the script as normal, but will not"
    764 			echo "	     delete $FILE)"
    765 			exit 0
    766 			;;
    767 	esac
    768 	shift 1
    769 	done
    770 fi
    771 
    772 if [ "$PROCEED" = "no" ]; then
    773 	exit 1
    774 fi
    775 
    776 if [ -z "$WITHALL" ]; then
    777 	withall
    778 fi
    779 
    780 if [ "$UPLOAD" = "ask" ]; then
    781 	if [ -n "$DIALOG" ]; then
    782 		dialog --backtitle "$BGTITLE" --title "Information collected" --yes-label " UPLOAD / SHARE " --no-label " SAVE LOCALLY " --defaultno --yesno "\n\nAutomatically upload ALSA information to $WWWSERVICE?" 10 80
    783 		DIALOG_EXIT_CODE=$?
    784 		if [ $DIALOG_EXIT_CODE != 0 ]; then
    785 			UPLOAD="no"
    786 		else
    787 			UPLOAD="yes"
    788 		fi
    789 	else
    790 		echo -n "Automatically upload ALSA information to $WWWSERVICE? [y/N] : "
    791 		read -e CONFIRM
    792 		if [ "$CONFIRM" != "y" ]; then
    793 			UPLOAD="no"
    794 		else
    795 			UPLOAD="yes"
    796 		fi
    797 	fi
    798 
    799 fi
    800 
    801 if [ "$UPLOAD" = "no" ]; then
    802 
    803 	if [ -z "$TOSTDOUT" ]; then
    804 		mv -f $FILE $NFILE || exit 1
    805 		KEEP_OUTPUT="yes"
    806 	fi
    807 
    808 	if [[ -n $DIALOG ]]
    809 	then
    810 		if [[ -n $PBERROR ]]; then
    811 			dialog --backtitle "$BGTITLE" --title "Information collected" --msgbox "An error occurred while contacting the $WWWSERVICE.\n Your information was NOT automatically uploaded.\n\nYour ALSA information is in $NFILE" 10 100
    812 		else
    813 			dialog --backtitle "$BGTITLE" --title "Information collected" --msgbox "\n\nYour ALSA information is in $NFILE" 10 60
    814 		fi
    815 	else
    816 		echo
    817 
    818 		if [[ -n $PBERROR ]]; then
    819 			echo "An error occurred while contacting the $WWWSERVICE."
    820 			echo "Your information was NOT automatically uploaded."
    821 			echo ""
    822 			echo "Your ALSA information is in $NFILE"
    823 			echo ""
    824 		else
    825 			if [ -z "$TOSTDOUT" ]; then
    826 				echo ""
    827 				echo "Your ALSA information is in $NFILE"
    828 				echo ""
    829 			fi
    830 		fi
    831 	fi
    832 
    833 	exit
    834 
    835 fi # UPLOAD
    836 
    837 #Test that wget is installed, and supports --post-file. Upload $FILE if it does, and prompt user to upload file if it doesnt. 
    838 if [[ -n "${WGET}" ]] && [[ -x "${WGET}" ]] && [[ `wget --help |grep post-file` ]]
    839 then
    840 
    841 if [[ -n $DIALOG ]]
    842 then
    843 
    844 if [[ -z $PASTEBIN ]]; then
    845 	wget -O - --tries=5 --timeout=60 --post-file=$FILE "http://www.alsa-project.org/cardinfo-db/" &>$TEMPDIR/wget.tmp || echo "Upload failed; exit"
    846 	{ for i in 10 20 30 40 50 60 70 80 90; do
    847 		echo $i
    848 		sleep 0.2
    849 	done
    850 	echo; } |dialog --backtitle "$BGTITLE" --guage "Uploading information to www.alsa-project.org ..." 6 70 0
    851 else
    852 	wget -O - --tries=5 --timeout=60 --post-file=$FILE "http://pastebin.ca/quiet-paste.php?api=$PASTEBINKEY&encrypt=t&encryptpw=blahblah" &>$TEMPDIR/wget.tmp || echo "Upload failed; exit"
    853 	{ for i in 10 20 30 40 50 60 70 80 90; do
    854 		echo $i
    855 		sleep 0.2
    856 	done
    857 	echo; } |dialog --backtitle "$BGTITLE" --guage "Uploading information to www.pastebin.ca ..." 6 70 0
    858 fi
    859 
    860 dialog --backtitle "$BGTITLE" --title "Information uploaded" --yesno "Would you like to see the uploaded information?" 5 100 
    861 DIALOG_EXIT_CODE=$?
    862 if [ $DIALOG_EXIT_CODE = 0 ]; then
    863 	grep -v "alsa-info.txt" $FILE >$TEMPDIR/uploaded.txt
    864 	dialog --backtitle "$BGTITLE" --textbox $TEMPDIR/uploaded.txt 0 0
    865 fi
    866 
    867 clear
    868 
    869 # no dialog
    870 else
    871 
    872 if [[ -z $PASTEBIN ]]; then
    873 	echo -n "Uploading information to www.alsa-project.org ... " 
    874 	wget -O - --tries=5 --timeout=60 --post-file=$FILE http://www.alsa-project.org/cardinfo-db/ &>$TEMPDIR/wget.tmp &
    875 else
    876 	echo -n "Uploading information to www.pastebin.ca ... " 
    877 	wget -O - --tries=5 --timeout=60 --post-file=$FILE http://pastebin.ca/quiet-paste.php?api=$PASTEBINKEY &>$TEMPDIR/wget.tmp &
    878 fi
    879 
    880 #Progess spinner for wget transfer.
    881 i=1
    882 sp="/-\|"
    883 echo -n ' '
    884 while pgrep wget &>/dev/null
    885 do
    886 	echo -en "\b${sp:i++%${#sp}:1}"
    887 done
    888 
    889 echo -e "\b Done!"
    890 echo ""
    891 
    892 fi #dialog
    893 
    894 #See if tput is available, and use it if it is.	
    895 if [ -n "$TPUT" ]; then
    896 	if [[ -z $PASTEBIN ]]; then
    897 		FINAL_URL=`tput setaf 1; grep "SUCCESS:" $TEMPDIR/wget.tmp | cut -d ' ' -f 2 ; tput sgr0`
    898 	else
    899 		FINAL_URL=`tput setaf 1; grep "SUCCESS:" $TEMPDIR/wget.tmp | sed -n 's/.*\:\([0-9]\+\).*/http:\/\/pastebin.ca\/\1/p';tput sgr0`
    900 	fi
    901 else
    902 	if [[ -z $PASTEBIN ]]; then
    903 		FINAL_URL=`grep "SUCCESS:" $TEMPDIR/wget.tmp | cut -d ' ' -f 2`
    904 	else
    905 		FINAL_URL=`grep "SUCCESS:" $TEMPDIR/wget.tmp | sed -n 's/.*\:\([0-9]\+\).*/http:\/\/pastebin.ca\/\1/p'`
    906 	fi
    907 fi
    908 
    909 # Output the URL of the uploaded file.	
    910 echo "Your ALSA information is located at $FINAL_URL"
    911 echo "Please inform the person helping you."
    912 echo ""
    913 
    914 # We couldnt find a suitable wget, so tell the user to upload manually.
    915 else
    916 	mv -f $FILE $NFILE || exit 1
    917 	KEEP_OUTPUT="yes"
    918 	if [[ -z $DIALOG ]]
    919 	then
    920 		if [[ -z $PASTEBIN ]]; then
    921 		echo ""
    922 		echo "Could not automatically upload output to http://www.alsa-project.org"
    923 		echo "Possible reasons are:"
    924 		echo "    1. Couldnt find 'wget' in your PATH"
    925 		echo "    2. Your version of wget is less than 1.8.2"
    926 		echo ""
    927 		echo "Please manually upload $NFILE to http://www.alsa-project.org/cardinfo-db/ and submit your post."
    928 		echo ""
    929 		else
    930 		echo ""
    931 		echo "Could not automatically upload output to http://www.pastebin.ca"
    932 		echo "Possible reasons are:"
    933 		echo "    1. Couldnt find 'wget' in your PATH"
    934 		echo "    2. Your version of wget is less than 1.8.2"
    935 		echo ""
    936 		echo "Please manually upload $NFILE to http://www.pastebin.ca/upload.php and submit your post."
    937 		echo ""
    938 		fi
    939 	else
    940 		if [[ -z $PASTEBIN ]]; then
    941 			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 $NFILE to http://www.alsa-project,org/cardinfo-db/ and submit your post." 25 100
    942 		else
    943 			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 $NFILE to http://www.pastebin.ca/upload.php and submit your post." 25 100
    944 		fi
    945 	fi
    946 fi