Martin Stransky efe9b5
#!/bin/bash
Martin Stransky efe9b5
Jaroslav Kysela 09e283
SCRIPT_VERSION=0.4.61
perex a657df
CHANGELOG="http://www.alsa-project.org/alsa-info.sh.changelog"
Martin Stransky efe9b5
Martin Stransky efe9b5
#################################################################################
Martin Stransky efe9b5
#Copyright (C) 2007 Free Software Foundation.
Martin Stransky efe9b5
Martin Stransky efe9b5
#This program is free software; you can redistribute it and/or modify
Martin Stransky efe9b5
#it under the terms of the GNU General Public License as published by
Martin Stransky efe9b5
#the Free Software Foundation; either version 2 of the License, or
Martin Stransky efe9b5
#(at your option) any later version.
Martin Stransky efe9b5
Martin Stransky efe9b5
#This program is distributed in the hope that it will be useful,
Martin Stransky efe9b5
#but WITHOUT ANY WARRANTY; without even the implied warranty of
Martin Stransky efe9b5
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Martin Stransky efe9b5
#GNU General Public License for more details.
Martin Stransky efe9b5
Martin Stransky efe9b5
#You should have received a copy of the GNU General Public License
Martin Stransky efe9b5
#along with this program; if not, write to the Free Software
Martin Stransky efe9b5
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
Martin Stransky efe9b5
Martin Stransky efe9b5
##################################################################################
Martin Stransky efe9b5
Martin Stransky efe9b5
#The script was written for 2 main reasons:
Martin Stransky efe9b5
# 1. Remove the need for the devs/helpers to ask several questions before we can easily help the user.
Martin Stransky efe9b5
# 2. Allow newer/inexperienced ALSA users to give us all the info we need to help them.
Martin Stransky efe9b5
perex 2a14aa
#Set the locale (this may or may not be a good idea.. let me know)
perex 2a14aa
export LC_ALL=C
perex 2a14aa
Martin Stransky efe9b5
#Change the PATH variable, so we can run lspci (needed for some distros)
Martin Stransky efe9b5
PATH=$PATH:/bin:/sbin:/usr/bin:/usr/sbin
Martin Stransky efe9b5
BGTITLE="ALSA-Info v $SCRIPT_VERSION"
Martin Stransky efe9b5
PASTEBINKEY="C9cRIO8m/9y8Cs0nVs0FraRx7U0pHsuc"
Martin Stransky efe9b5
#Define some simple functions
Martin Stransky efe9b5
perex a657df
pbcheck(){
perex 46b106
	[[ $UPLOAD = "no" ]] && return
perex 46b106
perex 1e0bef
	if [[ -z $PASTEBIN ]]; then
perex 46b106
		[[ $(ping -c1 www.alsa-project.org) ]] || KEEP_FILES="yes" UPLOAD="no" PBERROR="yes"
perex 1e0bef
	else
perex 46b106
		[[ $(ping -c1 www.pastebin.ca) ]] || KEEP_FILES="yes" UPLOAD="no" PBERROR="yes"
perex 1e0bef
	fi
perex a657df
}
perex a657df
Martin Stransky efe9b5
update() {
perex 46b106
	SHFILE=`mktemp -t alsa-info.XXXXXXXXXX` || exit 1
perex 2a14aa
	wget -O $SHFILE "http://www.alsa-project.org/alsa-info.sh" >/dev/null 2>&1
perex 2a14aa
	REMOTE_VERSION=`grep SCRIPT_VERSION $SHFILE |head -n1 |sed 's/.*=//'`
Martin Stransky efe9b5
	if [ "$REMOTE_VERSION" != "$SCRIPT_VERSION" ]; then
Martin Stransky efe9b5
		if [[ -n $DIALOG ]]
Martin Stransky efe9b5
		then
perex 2a14aa
			OVERWRITE=
perex 681702
			if [ -w $0 ]; then
perex 2a14aa
				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
perex 2a14aa
				DIALOG_EXIT_CODE=$?
perex 2a14aa
				if [[ $DIALOG_EXIT_CODE = 0 ]]; then
perex 2a14aa
				  OVERWRITE=yes
perex 2a14aa
				fi
perex 2a14aa
			fi
perex 2a14aa
			if [ -z "$OVERWRITE" ]; then
perex 681702
				dialog --yesno "Newer version of ALSA-Info has been found\n\nDo you wish to download it?" 0 0
perex 2a14aa
				DIALOG_EXIT_CODE=$?
perex 681702
			fi
Martin Stransky efe9b5
			if [[ $DIALOG_EXIT_CODE = 0 ]]
Martin Stransky efe9b5
			then
perex 681702
				echo "Newer version detected: $REMOTE_VERSION"
Martin Stransky efe9b5
				echo "To view the ChangeLog, please visit $CHANGELOG"
perex 2a14aa
				if [ "$OVERWRITE" = "yes" ]; then
perex 2a14aa
					cp $SHFILE $0
perex 681702
					echo "ALSA-Info script has been updated to v $REMOTE_VERSION"
perex 681702
					echo "Please re-run the script"
perex 2a14aa
					rm $SHFILE 2>/dev/null
perex 681702
				else
perex 46b106
					echo "ALSA-Info script has been downloaded as $SHFILE."
perex 681702
					echo "Please re-run the script from new location."
perex 681702
				fi
Martin Stransky efe9b5
				exit
perex 681702
			else
perex 2a14aa
				rm $SHFILE 2>/dev/null
Martin Stransky efe9b5
			fi
Martin Stransky efe9b5
		else
Martin Stransky efe9b5
			echo "Newer version detected: $REMOTE_VERSION"
Martin Stransky efe9b5
			echo "To view the ChangeLog, please visit $CHANGELOG"
perex 681702
			if [ -w $0 ]; then
perex 2a14aa
				echo "The original file $0 will be overwritten!"
perex 2a14aa
				echo -n "If you do not like to proceed, press Ctrl-C now.." ; read inp
perex 2a14aa
				cp $SHFILE $0
perex 681702
				echo "ALSA-Info script has been updated. Please re-run it."
perex 2a14aa
				rm $SHFILE 2>/dev/null
perex 681702
			else
perex 46b106
				echo "ALSA-Info script has been downloaded $SHFILE."
perex 681702
				echo "Please, re-run it from new location."
perex 681702
			fi
Martin Stransky efe9b5
			exit
Martin Stransky efe9b5
		fi
perex 681702
	else
perex 2a14aa
		rm $SHFILE 2>/dev/null
Martin Stransky efe9b5
	fi
Martin Stransky efe9b5
}
Martin Stransky efe9b5
Martin Stransky efe9b5
cleanup() {
perex bbe9f6
	if [ -n "$TEMPDIR" -a "$KEEP_FILES" != "yes" ]; then
perex 46b106
		rm -rf "$TEMPDIR" 2>/dev/null
perex bbe9f6
	fi
perex 46b106
	test -n "$KEEP_OUTPUT" || rm -f "$NFILE"
Martin Stransky efe9b5
}
Martin Stransky efe9b5
Martin Stransky efe9b5
Martin Stransky efe9b5
withaplay() {
Martin Stransky efe9b5
        echo "!!Aplay/Arecord output" >> $FILE
Jaroslav Kysela 09e283
        echo "!!--------------------" >> $FILE
Martin Stransky efe9b5
        echo "" >> $FILE
Martin Stransky efe9b5
       	echo "APLAY" >> $FILE
Martin Stransky efe9b5
	echo "" >> $FILE 
perex a657df
	aplay -l >> $FILE 2>&1
Martin Stransky efe9b5
        echo "" >> $FILE
Martin Stransky efe9b5
       	echo "ARECORD" >> $FILE
Martin Stransky efe9b5
	echo "" >> $FILE
perex a657df
	arecord -l >> $FILE 2>&1
Martin Stransky efe9b5
	echo "" >> $FILE
Martin Stransky efe9b5
}
Martin Stransky efe9b5
Martin Stransky efe9b5
withlsmod() {
Martin Stransky efe9b5
	echo "!!All Loaded Modules" >> $FILE
Martin Stransky efe9b5
	echo "!!------------------" >> $FILE
Martin Stransky efe9b5
	echo "" >> $FILE
Martin Stransky efe9b5
	lsmod |awk {'print $1'} >> $FILE
Martin Stransky efe9b5
	echo "" >> $FILE
Martin Stransky efe9b5
	echo "" >> $FILE
Martin Stransky efe9b5
}
Martin Stransky efe9b5
Martin Stransky efe9b5
withamixer() {
Martin Stransky efe9b5
        echo "!!Amixer output" >> $FILE
Martin Stransky efe9b5
        echo "!!-------------" >> $FILE
Martin Stransky efe9b5
        echo "" >> $FILE
Martin Stransky efe9b5
	for i in `grep "]: " /proc/asound/cards | awk -F ' ' '{ print $1} '` ; do
perex 2a14aa
	CARD_NAME=`grep "^ *$i " $TEMPDIR/alsacards.tmp|awk {'print $2'}`
Martin Stransky efe9b5
	echo "!!-------Mixer controls for card $i $CARD_NAME]" >> $FILE
Martin Stransky efe9b5
	echo "" >>$FILE
perex 1e0bef
	amixer -c$i info>> $FILE 2>&1
perex a657df
	amixer -c$i>> $FILE 2>&1
Martin Stransky efe9b5
        echo "" >> $FILE
Martin Stransky efe9b5
	done
Martin Stransky efe9b5
	echo "" >> $FILE
Martin Stransky efe9b5
}
Martin Stransky efe9b5
Martin Stransky efe9b5
withalsactl() {
Martin Stransky efe9b5
	echo "!!Alsactl output" >> $FILE
Jaroslav Kysela 09e283
        echo "!!--------------" >> $FILE
Martin Stransky efe9b5
        echo "" >> $FILE
Martin Stransky efe9b5
        exe=""
Martin Stransky efe9b5
        if [ -x /usr/sbin/alsactl ]; then
Martin Stransky efe9b5
        	exe="/usr/sbin/alsactl"
Martin Stransky efe9b5
        fi
Martin Stransky efe9b5
        if [ -x /usr/local/sbin/alsactl ]; then
Martin Stransky efe9b5
        	exe="/usr/local/sbin/alsactl"
Martin Stransky efe9b5
        fi
Martin Stransky efe9b5
        if [ -z "$exe" ]; then
Martin Stransky efe9b5
        	exe=`whereis alsactl | cut -d ' ' -f 2`
Martin Stransky efe9b5
        fi
perex 2a14aa
	$exe -f $TEMPDIR/alsactl.tmp store
Martin Stransky efe9b5
	echo "--startcollapse--" >> $FILE
perex 2a14aa
	cat $TEMPDIR/alsactl.tmp >> $FILE
Martin Stransky efe9b5
	echo "--endcollapse--" >> $FILE
Martin Stransky efe9b5
	echo "" >> $FILE
Martin Stransky efe9b5
	echo "" >> $FILE
Martin Stransky efe9b5
}
Martin Stransky efe9b5
Martin Stransky efe9b5
withdevices() {
Martin Stransky efe9b5
        echo "!!ALSA Device nodes" >> $FILE
Martin Stransky efe9b5
        echo "!!-----------------" >> $FILE
Martin Stransky efe9b5
        echo "" >> $FILE
Martin Stransky efe9b5
        ls -la /dev/snd/* >> $FILE
Martin Stransky efe9b5
        echo "" >> $FILE
Martin Stransky efe9b5
        echo "" >> $FILE
Martin Stransky efe9b5
}
Martin Stransky efe9b5
Martin Stransky efe9b5
withconfigs() {
Martin Stransky efe9b5
if [[ -e $HOME/.asoundrc ]] || [[ -e /etc/asound.conf ]] || [[ -e $HOME/.asoundrc.asoundconf ]]
Martin Stransky efe9b5
then
Martin Stransky efe9b5
        echo "!!ALSA configuration files" >> $FILE
Martin Stransky efe9b5
        echo "!!------------------------" >> $FILE
Martin Stransky efe9b5
        echo "" >> $FILE
Martin Stransky efe9b5
Martin Stransky efe9b5
        #Check for ~/.asoundrc
Martin Stransky efe9b5
        if [[ -e $HOME/.asoundrc ]]
Martin Stransky efe9b5
        then
Martin Stransky efe9b5
                echo "!!User specific config file (~/.asoundrc)" >> $FILE
Martin Stransky efe9b5
                echo "" >> $FILE
Martin Stransky efe9b5
                cat $HOME/.asoundrc >> $FILE
Martin Stransky efe9b5
                echo "" >> $FILE
Martin Stransky efe9b5
                echo "" >> $FILE
Martin Stransky efe9b5
        fi
Martin Stransky efe9b5
	#Check for .asoundrc.asoundconf (seems to be Ubuntu specific)
Martin Stransky efe9b5
	if [[ -e $HOME/.asoundrc.asoundconf ]]
Martin Stransky efe9b5
	then
Martin Stransky efe9b5
		echo "!!asoundconf-generated config file" >> $FILE
Martin Stransky efe9b5
		echo "" >> $FILE
Martin Stransky efe9b5
		cat $HOME/.asoundrc.asoundconf >> $FILE
Martin Stransky efe9b5
		echo "" >> $FILE
Martin Stransky efe9b5
		echo "" >> $FILE
Martin Stransky efe9b5
	fi
Martin Stransky efe9b5
        #Check for /etc/asound.conf
Martin Stransky efe9b5
        if [[ -e /etc/asound.conf ]]
Martin Stransky efe9b5
        then
Martin Stransky efe9b5
                echo "!!System wide config file (/etc/asound.conf)" >> $FILE
Martin Stransky efe9b5
                echo "" >> $FILE
Martin Stransky efe9b5
                cat /etc/asound.conf >> $FILE
Martin Stransky efe9b5
                echo "" >> $FILE
Martin Stransky efe9b5
                echo "" >> $FILE
Martin Stransky efe9b5
        fi
Martin Stransky efe9b5
fi
Martin Stransky efe9b5
}
Martin Stransky efe9b5
perex bbe9f6
withsysfs() {
perex bbe9f6
    local i f
perex bbe9f6
    local printed=""
perex bbe9f6
    for i in /sys/class/sound/*; do
perex bbe9f6
	case "$i" in
perex bbe9f6
	    */hwC?D?)
perex bbe9f6
		if [ -f $i/init_pin_configs ]; then
perex bbe9f6
		    if [ -z "$printed" ]; then
perex bbe9f6
			echo "!!Sysfs Files" >> $FILE
perex bbe9f6
			echo "!!-----------" >> $FILE
perex bbe9f6
			echo "" >> $FILE
perex bbe9f6
		    fi
perex bbe9f6
		    for f in init_pin_configs driver_pin_configs user_pin_configs init_verbs; do
perex bbe9f6
			echo "$i/$f:" >> $FILE
perex bbe9f6
			cat $i/$f >> $FILE
perex bbe9f6
			echo >> $FILE
perex bbe9f6
		    done
perex bbe9f6
		    printed=yes
perex bbe9f6
		fi
perex bbe9f6
		;;
perex bbe9f6
	    esac
perex bbe9f6
    done
perex bbe9f6
    if [ -n "$printed" ]; then
perex bbe9f6
	echo "" >> $FILE
perex bbe9f6
    fi
perex bbe9f6
}
perex bbe9f6
perex 46b106
withdmesg() {
perex 46b106
	echo "!!ALSA/HDA dmesg" >> $FILE
Jaroslav Kysela 09e283
	echo "!!--------------" >> $FILE
perex 46b106
	echo "" >> $FILE
perex 46b106
	dmesg | grep -C1 -E 'ALSA|HDA|HDMI|sound|hda.codec|hda.intel' >> $FILE
perex 46b106
	echo "" >> $FILE
perex 46b106
	echo "" >> $FILE
perex 46b106
}
perex 46b106
perex 46b106
withall() {
perex 46b106
	withdevices
perex 46b106
	withconfigs
perex 46b106
	withaplay
perex 46b106
	withamixer
perex 46b106
	withalsactl
perex 46b106
	withlsmod
perex 46b106
	withsysfs
perex 46b106
	withdmesg
perex 46b106
}
perex 46b106
perex bbe9f6
get_alsa_library_version() {
perex bbe9f6
	ALSA_LIB_VERSION=`grep VERSION_STR /usr/include/alsa/version.h 2>/dev/null|awk {'print $3'}|sed 's/"//g'`
perex bbe9f6
perex bbe9f6
	if [ -z "$ALSA_LIB_VERSION" ]; then
perex bbe9f6
		if [ -f /etc/lsb-release ]; then
perex bbe9f6
			. /etc/lsb-release
perex bbe9f6
			case "$DISTRIB_ID" in
perex bbe9f6
				Ubuntu)
perex bbe9f6
					if which dpkg > /dev/null ; then
perex bbe9f6
						ALSA_LIB_VERSION=`dpkg -l libasound2 | tail -1 | awk '{print $3}' | cut -f 1 -d -`
perex bbe9f6
					fi
perex bbe9f6
perex bbe9f6
					if [ "$ALSA_LIB_VERSION" = "<none>" ]; then
perex bbe9f6
						ALSA_LIB_VERSION=""
perex bbe9f6
					fi
perex bbe9f6
					return
perex bbe9f6
					;;
perex bbe9f6
				*)
perex bbe9f6
					return
perex bbe9f6
					;;
perex bbe9f6
			esac
perex bbe9f6
		elif [ -f /etc/debian_version ]; then
perex bbe9f6
			if which dpkg > /dev/null ; then
perex bbe9f6
				ALSA_LIB_VERSION=`dpkg -l libasound2 | tail -1 | awk '{print $3}' | cut -f 1 -d -`
perex bbe9f6
			fi
perex bbe9f6
perex bbe9f6
			if [ "$ALSA_LIB_VERSION" = "<none>" ]; then
perex bbe9f6
				ALSA_LIB_VERSION=""
perex bbe9f6
			fi
perex bbe9f6
			return
perex bbe9f6
		fi
perex bbe9f6
	fi
perex bbe9f6
}
perex bbe9f6
Martin Stransky efe9b5
Martin Stransky efe9b5
#Run checks to make sure the programs we need are installed.
Martin Stransky efe9b5
LSPCI=$(which lspci 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null);
Martin Stransky efe9b5
TPUT=$(which tput 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null);
Martin Stransky efe9b5
DIALOG=$(which dialog 2>/dev/null | sed 's|^[^/]*||' 2>/dev/null);
Martin Stransky efe9b5
Martin Stransky efe9b5
#Check to see if sysfs is enabled in the kernel. We'll need this later on
Martin Stransky efe9b5
SYSFS=$(mount |grep sysfs|awk {'print $3'});
Martin Stransky efe9b5
Martin Stransky efe9b5
#Check modprobe config files for sound related options
Martin Stransky efe9b5
SNDOPTIONS=$(modprobe -c|sed -n 's/^options \(snd[-_][^ ]*\)/\1:/p')
Martin Stransky efe9b5
perex 46b106
KEEP_OUTPUT=
perex 46b106
NFILE=""
perex 46b106
perex 1e0bef
PASTEBIN=""
perex 1e0bef
WWWSERVICE="www.alsa-project.org"
perex 46b106
WELCOME="yes"
Martin Stransky efe9b5
PROCEED="yes"
perex 46b106
UPLOAD="ask"
Martin Stransky efe9b5
REPEAT=""
Martin Stransky efe9b5
while [ -z "$REPEAT" ]; do
Martin Stransky efe9b5
REPEAT="no"
Martin Stransky efe9b5
case "$1" in
Martin Stransky efe9b5
	--update|--help|--about)
perex 46b106
		WELCOME="no"
Martin Stransky efe9b5
		PROCEED="no"
Martin Stransky efe9b5
		;;
perex 46b106
	--upload)
perex 46b106
		UPLOAD="yes"
perex 46b106
		WELCOME="no"
perex 46b106
		;;
Martin Stransky efe9b5
	--no-upload)
perex 46b106
		UPLOAD="no"
perex 46b106
		WELCOME="no"
Martin Stransky efe9b5
		;;
perex 1e0bef
	--pastebin)
perex 1e0bef
		PASTEBIN="yes"
perex 1e0bef
		WWWSERVICE="pastebin"
perex 1e0bef
		;;
Martin Stransky efe9b5
	--no-dialog)
Martin Stransky efe9b5
		DIALOG=""
Martin Stransky efe9b5
		REPEAT=""
Martin Stransky efe9b5
		shift
Martin Stransky efe9b5
		;;
perex bbe9f6
	--stdout)
perex bbe9f6
		DIALOG=""
perex 46b106
		UPLOAD="no"
perex 46b106
		WELCOME="no"
perex bbe9f6
		TOSTDOUT="yes"
perex bbe9f6
		;;
Martin Stransky efe9b5
esac
Martin Stransky efe9b5
done
Martin Stransky efe9b5
Martin Stransky efe9b5
perex 46b106
#Script header output.
perex 46b106
if [ "$WELCOME" = "yes" ]; then
perex 46b106
greeting_message="\
perex 46b106
perex 46b106
This script visits the following commands/files to collect diagnostic
perex 46b106
information about your ALSA installation and sound related hardware.
perex 46b106
perex 46b106
  dmesg
perex 46b106
  lspci
perex 46b106
  lsmod
perex 46b106
  aplay
perex 46b106
  amixer
perex 46b106
  alsactl
perex 46b106
  /proc/asound/
perex 46b106
  /sys/class/sound/
perex 46b106
  ~/.asoundrc (etc.)
perex 46b106
perex 46b106
See '$0 --help' for command line options.
perex 46b106
"
perex 46b106
if [[ -n "$DIALOG" ]]; then
perex 46b106
	dialog  --backtitle "$BGTITLE" \
perex 46b106
		--title "ALSA-Info script v $SCRIPT_VERSION" \
perex 46b106
		--msgbox "$greeting_message" 20 80
Martin Stransky efe9b5
else
perex 46b106
	echo "ALSA Information Script v $SCRIPT_VERSION"
perex 46b106
	echo "--------------------------------"
perex 46b106
	echo "$greeting_message"
perex 46b106
fi # dialog
perex 46b106
fi # WELCOME
Martin Stransky efe9b5
Martin Stransky efe9b5
#Set the output file
perex 46b106
TEMPDIR=`mktemp -t -d alsa-info.XXXXXXXXXX` || exit 1
perex 2a14aa
FILE="$TEMPDIR/alsa-info.txt"
perex 46b106
if [ -z "$NFILE" ]; then
perex 46b106
	NFILE=`mktemp -t alsa-info.txt.XXXXXXXXXX` || exit 1
perex 46b106
fi
Martin Stransky efe9b5
perex bbe9f6
trap cleanup 0
perex bbe9f6
Martin Stransky efe9b5
if [ "$PROCEED" = "yes" ]; then
Martin Stransky efe9b5
Martin Stransky efe9b5
if [[ -z "$LSPCI" ]] 
perex bbe9f6
then
Martin Stransky efe9b5
	echo "This script requires lspci. Please install it, and re-run this script."
perex bbe9f6
	exit 0
Martin Stransky efe9b5
fi
Martin Stransky efe9b5
Martin Stransky efe9b5
#Fetch the info and store in temp files/variables
perex a657df
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}`
Martin Stransky efe9b5
KERNEL_VERSION=`uname -r`
Martin Stransky efe9b5
KERNEL_PROCESSOR=`uname -p`
Martin Stransky efe9b5
KERNEL_MACHINE=`uname -m`
Martin Stransky efe9b5
KERNEL_OS=`uname -o`
Martin Stransky efe9b5
[[ `uname -v |grep SMP`  ]] && KERNEL_SMP="Yes" || KERNEL_SMP="No" 
Martin Stransky efe9b5
ALSA_DRIVER_VERSION=`cat /proc/asound/version |head -n1|awk {'print $7'} |sed 's/\.$//'`
perex bbe9f6
get_alsa_library_version
Martin Stransky efe9b5
ALSA_UTILS_VERSION=`amixer -v |awk {'print $3'}`
perex 2a14aa
VENDOR_ID=`lspci -vn |grep 040[1-3] | awk -F':' '{print $3}'|awk {'print substr($0, 2);}' >$TEMPDIR/vendor_id.tmp`
perex 2a14aa
DEVICE_ID=`lspci -vn |grep 040[1-3] | awk -F':' '{print $4}'|awk {'print $1'} >$TEMPDIR/device_id.tmp`
Martin Stransky efe9b5
LAST_CARD=$((`grep "]: " /proc/asound/cards | wc -l` - 1 ))
perex 2a14aa
perex 2a14aa
ESDINST=$(which esd 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null)
perex 2a14aa
PAINST=$(which pulseaudio 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null)
perex 2a14aa
ARTSINST=$(which artsd 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null)
perex bbe9f6
JACKINST=$(which jackd 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null)
Jaroslav Kysela 09e283
ROARINST=$(which roard 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null)
perex 46b106
DMIDECODE=$(which dmidecode 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null)
perex 46b106
perex 46b106
#Check for DMI data
perex 46b106
if [ -d /sys/class/dmi/id ]; then
perex 46b106
    # No root privileges are required when using sysfs method
perex 46b106
    DMI_SYSTEM_MANUFACTURER=$(cat /sys/class/dmi/id/sys_vendor 2>/dev/null)
perex 46b106
    DMI_SYSTEM_PRODUCT_NAME=$(cat /sys/class/dmi/id/product_name 2>/dev/null)
Jaroslav Kysela 71ac13
    DMI_SYSTEM_PRODUCT_VERSION=$(cat /sys/class/dmi/id/product_version 2>/dev/null)
Jaroslav Kysela 09e283
    DMI_SYSTEM_FIRMWARE_VERSION=$(cat /sys/class/dmi/id/bios_version 2>/dev/null)
perex 46b106
elif [ -x $DMIDECODE ]; then
perex 46b106
    DMI_SYSTEM_MANUFACTURER=$($DMIDECODE -s system-manufacturer 2>/dev/null)
perex 46b106
    DMI_SYSTEM_PRODUCT_NAME=$($DMIDECODE -s system-product-name 2>/dev/null)
Jaroslav Kysela 71ac13
    DMI_SYSTEM_PRODUCT_VERSION=$($DMIDECODE -s system-version 2>/dev/null)
Jaroslav Kysela 09e283
    DMI_SYSTEM_FIRMWARE_VERSION=$($DMIDECODE -s bios-version 2>/dev/null)
perex 46b106
fi
perex 2a14aa
perex 2a14aa
cat /proc/asound/modules 2>/dev/null|awk {'print $2'}>$TEMPDIR/alsamodules.tmp
perex 2a14aa
cat /proc/asound/cards >$TEMPDIR/alsacards.tmp
perex 2a14aa
lspci |grep -i "multi\|audio">$TEMPDIR/lspci.tmp
Martin Stransky efe9b5
Martin Stransky efe9b5
#Check for HDA-Intel cards codec#*
perex 2a14aa
cat /proc/asound/card*/codec\#* > $TEMPDIR/alsa-hda-intel.tmp 2> /dev/null
Martin Stransky efe9b5
Martin Stransky efe9b5
#Check for AC97 cards codec
perex 2a14aa
cat /proc/asound/card*/codec97\#0/ac97\#0-0 > $TEMPDIR/alsa-ac97.tmp 2> /dev/null
perex 2a14aa
cat /proc/asound/card*/codec97\#0/ac97\#0-0+regs > $TEMPDIR/alsa-ac97-regs.tmp 2> /dev/null
Martin Stransky efe9b5
perex ca0aa5
#Check for USB mixer setup
perex ca0aa5
cat /proc/asound/card*/usbmixer > $TEMPDIR/alsa-usbmixer.tmp 2> /dev/null
perex ca0aa5
Martin Stransky efe9b5
#Fetch the info, and put it in $FILE in a nice readable format.
perex 1e0bef
if [[ -z $PASTEBIN ]]; then
perex 1e0bef
echo "upload=true&script=true&cardinfo=" > $FILE
perex 1e0bef
else
Martin Stransky efe9b5
echo "name=$USER&type=33&description=/tmp/alsa-info.txt&expiry=&s=Submit+Post&content=" > $FILE
perex 1e0bef
fi
Martin Stransky efe9b5
echo "!!################################" >> $FILE
Martin Stransky efe9b5
echo "!!ALSA Information Script v $SCRIPT_VERSION" >> $FILE
Martin Stransky efe9b5
echo "!!################################" >> $FILE
Martin Stransky efe9b5
echo "" >> $FILE
perex 2a14aa
echo "!!Script ran on: `LANG=C TZ=UTC date`" >> $FILE
Martin Stransky efe9b5
echo "" >> $FILE
Martin Stransky efe9b5
echo "" >> $FILE
Martin Stransky efe9b5
echo "!!Linux Distribution" >> $FILE
Martin Stransky efe9b5
echo "!!------------------" >> $FILE
Martin Stransky efe9b5
echo "" >> $FILE
Martin Stransky efe9b5
echo $DISTRO >> $FILE
Martin Stransky efe9b5
echo "" >> $FILE
Martin Stransky efe9b5
echo "" >> $FILE
perex 46b106
echo "!!DMI Information" >> $FILE
perex 46b106
echo "!!---------------" >> $FILE
perex 46b106
echo "" >> $FILE
perex 46b106
echo "Manufacturer:      $DMI_SYSTEM_MANUFACTURER" >> $FILE
perex 46b106
echo "Product Name:      $DMI_SYSTEM_PRODUCT_NAME" >> $FILE
Jaroslav Kysela 71ac13
echo "Product Version:   $DMI_SYSTEM_PRODUCT_VERSION" >> $FILE
Jaroslav Kysela 09e283
echo "Firmware Version:  $DMI_SYSTEM_FIRMWARE_VERSION" >> $FILE
perex 46b106
echo "" >> $FILE
perex 46b106
echo "" >> $FILE
Martin Stransky efe9b5
echo "!!Kernel Information" >> $FILE
Martin Stransky efe9b5
echo "!!------------------" >> $FILE
Martin Stransky efe9b5
echo "" >> $FILE
Martin Stransky efe9b5
echo "Kernel release:    $KERNEL_VERSION" >> $FILE
Martin Stransky efe9b5
echo "Operating System:  $KERNEL_OS" >> $FILE
Martin Stransky efe9b5
echo "Architecture:      $KERNEL_MACHINE" >> $FILE
Martin Stransky efe9b5
echo "Processor:         $KERNEL_PROCESSOR" >> $FILE
Martin Stransky efe9b5
echo "SMP Enabled:       $KERNEL_SMP" >> $FILE
Martin Stransky efe9b5
echo "" >> $FILE
Martin Stransky efe9b5
echo "" >> $FILE
Martin Stransky efe9b5
echo "!!ALSA Version" >> $FILE
Martin Stransky efe9b5
echo "!!------------" >> $FILE
Martin Stransky efe9b5
echo "" >> $FILE
Martin Stransky efe9b5
echo "Driver version:     $ALSA_DRIVER_VERSION" >> $FILE
Martin Stransky efe9b5
echo "Library version:    $ALSA_LIB_VERSION" >> $FILE
Martin Stransky efe9b5
echo "Utilities version:  $ALSA_UTILS_VERSION" >> $FILE
Martin Stransky efe9b5
echo "" >> $FILE
Martin Stransky efe9b5
echo "" >> $FILE
Martin Stransky efe9b5
echo "!!Loaded ALSA modules" >> $FILE
Martin Stransky efe9b5
echo "!!-------------------" >> $FILE
Martin Stransky efe9b5
echo "" >> $FILE
perex 2a14aa
cat $TEMPDIR/alsamodules.tmp >> $FILE
perex 2a14aa
echo "" >> $FILE
perex 2a14aa
echo "" >> $FILE
perex 2a14aa
echo "!!Sound Servers on this system" >> $FILE
perex 2a14aa
echo "!!----------------------------" >> $FILE
perex 2a14aa
echo "" >> $FILE
perex 2a14aa
if [[ -n $PAINST ]];then
perex bbe9f6
[[ `pgrep '^(.*/)?pulseaudio$'` ]] && PARUNNING="Yes" || PARUNNING="No"
perex 2a14aa
echo "Pulseaudio:" >> $FILE
perex 2a14aa
echo "      Installed - Yes ($PAINST)" >> $FILE
perex 2a14aa
echo "      Running - $PARUNNING" >> $FILE
Martin Stransky efe9b5
echo "" >> $FILE
perex 2a14aa
fi
perex 2a14aa
if [[ -n $ESDINST ]];then
perex bbe9f6
[[ `pgrep '^(.*/)?esd$'` ]] && ESDRUNNING="Yes" || ESDRUNNING="No"
perex 2a14aa
echo "ESound Daemon:" >> $FILE
perex 2a14aa
echo "      Installed - Yes ($ESDINST)" >> $FILE
perex 2a14aa
echo "      Running - $ESDRUNNING" >> $FILE
perex 2a14aa
echo "" >> $FILE
perex 2a14aa
fi
perex 2a14aa
if [[ -n $ARTSINST ]];then
perex bbe9f6
[[ `pgrep '^(.*/)?artsd$'` ]] && ARTSRUNNING="Yes" || ARTSRUNNING="No"
perex 2a14aa
echo "aRts:" >> $FILE
perex 2a14aa
echo "      Installed - Yes ($ARTSINST)" >> $FILE
perex 2a14aa
echo "      Running - $ARTSRUNNING" >> $FILE
perex 2a14aa
echo "" >> $FILE
perex 2a14aa
fi
perex bbe9f6
if [[ -n $JACKINST ]];then
perex bbe9f6
[[ `pgrep '^(.*/)?jackd$'` ]] && JACKRUNNING="Yes" || JACKRUNNING="No"
perex bbe9f6
echo "Jack:" >> $FILE
perex bbe9f6
echo "      Installed - Yes ($JACKINST)" >> $FILE
perex bbe9f6
echo "      Running - $JACKRUNNING" >> $FILE
perex bbe9f6
echo "" >> $FILE
perex bbe9f6
fi
Jaroslav Kysela 09e283
if [[ -n $ROARINST ]];then
Jaroslav Kysela 09e283
[[ `pgrep '^(.*/)?roard$'` ]] && ROARRUNNING="Yes" || ROARRUNNING="No"
Jaroslav Kysela 09e283
echo "RoarAudio:" >> $FILE
Jaroslav Kysela 09e283
echo "      Installed - Yes ($ROARINST)" >> $FILE
Jaroslav Kysela 09e283
echo "      Running - $ROARRUNNING" >> $FILE
Jaroslav Kysela 09e283
echo "" >> $FILE
Jaroslav Kysela 09e283
fi
Jaroslav Kysela 09e283
if [[ -z "$PAINST" && -z "$ESDINST" && -z "$ARTSINST" && -z "$JACKINST" && -z "$ROARINST" ]];then
perex 2a14aa
echo "No sound servers found." >> $FILE
perex 2a14aa
echo "" >> $FILE
perex 2a14aa
fi
Martin Stransky efe9b5
echo "" >> $FILE
Martin Stransky efe9b5
echo "!!Soundcards recognised by ALSA" >> $FILE
Martin Stransky efe9b5
echo "!!-----------------------------" >> $FILE
Martin Stransky efe9b5
echo "" >> $FILE
perex 2a14aa
cat $TEMPDIR/alsacards.tmp >> $FILE
Martin Stransky efe9b5
echo "" >> $FILE
Martin Stransky efe9b5
echo "" >> $FILE
Martin Stransky efe9b5
echo "!!PCI Soundcards installed in the system" >> $FILE
Martin Stransky efe9b5
echo "!!--------------------------------------" >> $FILE
Martin Stransky efe9b5
echo "" >> $FILE
perex 2a14aa
cat $TEMPDIR/lspci.tmp >> $FILE
Martin Stransky efe9b5
echo "" >> $FILE
Martin Stransky efe9b5
echo "" >> $FILE
Jaroslav Kysela 71ac13
echo "!!Advanced information - PCI Vendor/Device/Subsystem ID's" >> $FILE
Jaroslav Kysela 09e283
echo "!!-------------------------------------------------------" >> $FILE
Martin Stransky efe9b5
echo "" >> $FILE
Martin Stransky efe9b5
lspci -vvn |grep -A1 040[1-3] >> $FILE
Martin Stransky efe9b5
echo "" >> $FILE
Martin Stransky efe9b5
echo "" >> $FILE
Martin Stransky efe9b5
Martin Stransky efe9b5
if [ "$SNDOPTIONS" ]
Martin Stransky efe9b5
then
Martin Stransky efe9b5
echo "!!Modprobe options (Sound related)" >> $FILE
Martin Stransky efe9b5
echo "!!--------------------------------" >> $FILE
Martin Stransky efe9b5
echo "" >> $FILE
Martin Stransky efe9b5
modprobe -c|sed -n 's/^options \(snd[-_][^ ]*\)/\1:/p' >> $FILE
Martin Stransky efe9b5
echo "" >> $FILE
Martin Stransky efe9b5
echo "" >> $FILE
Martin Stransky efe9b5
fi
Martin Stransky efe9b5
perex 681702
if [ -d "$SYSFS" ]
Martin Stransky efe9b5
then
Martin Stransky efe9b5
echo "!!Loaded sound module options" >> $FILE
Jaroslav Kysela 09e283
echo "!!---------------------------" >> $FILE
Martin Stransky efe9b5
echo "" >> $FILE
Martin Stransky efe9b5
for mod in `cat /proc/asound/modules|awk {'print $2'}`;do
Martin Stransky efe9b5
echo "!!Module: $mod" >> $FILE
perex 46b106
for params in `echo $SYSFS/module/$mod/parameters/*`; do
perex 46b106
	echo -ne "\t";
perex 46b106
	echo "$params : `cat $params`" | sed 's:.*/::';
perex 46b106
done >> $FILE
Martin Stransky efe9b5
echo "" >> $FILE
Martin Stransky efe9b5
done
Martin Stransky efe9b5
echo "" >> $FILE
Martin Stransky efe9b5
fi
Martin Stransky efe9b5
perex 2a14aa
if [ -s "$TEMPDIR/alsa-hda-intel.tmp" ] 
Martin Stransky efe9b5
then
Martin Stransky efe9b5
	echo "!!HDA-Intel Codec information" >> $FILE
Martin Stransky efe9b5
	echo "!!---------------------------" >> $FILE
Martin Stransky efe9b5
	echo "--startcollapse--" >> $FILE
Martin Stransky efe9b5
	echo "" >> $FILE
perex 2a14aa
	cat $TEMPDIR/alsa-hda-intel.tmp >> $FILE
Martin Stransky efe9b5
	echo "--endcollapse--" >> $FILE
Martin Stransky efe9b5
	echo "" >> $FILE
Martin Stransky efe9b5
	echo "" >> $FILE
Martin Stransky efe9b5
fi
Martin Stransky efe9b5
perex 2a14aa
if [ -s "$TEMPDIR/alsa-ac97.tmp" ]
Martin Stransky efe9b5
then
Martin Stransky efe9b5
        echo "!!AC97 Codec information" >> $FILE
Jaroslav Kysela 09e283
        echo "!!----------------------" >> $FILE
Martin Stransky efe9b5
        echo "--startcollapse--" >> $FILE
Martin Stransky efe9b5
        echo "" >> $FILE
perex 2a14aa
        cat $TEMPDIR/alsa-ac97.tmp >> $FILE
Martin Stransky efe9b5
        echo "" >> $FILE
perex 2a14aa
        cat $TEMPDIR/alsa-ac97-regs.tmp >> $FILE
Martin Stransky efe9b5
        echo "--endcollapse--" >> $FILE
Martin Stransky efe9b5
	echo "" >> $FILE
Martin Stransky efe9b5
	echo "" >> $FILE
Martin Stransky efe9b5
fi
Martin Stransky efe9b5
perex ca0aa5
if [ -s "$TEMPDIR/alsa-usbmixer.tmp" ]
perex ca0aa5
then
perex ca0aa5
        echo "!!USB Mixer information" >> $FILE
Jaroslav Kysela 09e283
        echo "!!---------------------" >> $FILE
perex ca0aa5
        echo "--startcollapse--" >> $FILE
perex ca0aa5
        echo "" >> $FILE
perex ca0aa5
        cat $TEMPDIR/alsa-usbmixer.tmp >> $FILE
perex ca0aa5
        echo "--endcollapse--" >> $FILE
perex ca0aa5
	echo "" >> $FILE
perex ca0aa5
	echo "" >> $FILE
perex ca0aa5
fi
Martin Stransky efe9b5
Martin Stransky efe9b5
#If no command line options are specified, then run as though --with-all was specified
Martin Stransky efe9b5
if [[ -z "$1" ]]
Martin Stransky efe9b5
then
Martin Stransky efe9b5
	update
perex 46b106
	withall
perex a657df
	pbcheck	
Martin Stransky efe9b5
fi
Martin Stransky efe9b5
Martin Stransky efe9b5
fi # proceed
Martin Stransky efe9b5
Martin Stransky efe9b5
#loop through command line arguments, until none are left.
Martin Stransky efe9b5
if [[ -n "$1" ]]
Martin Stransky efe9b5
then
Martin Stransky efe9b5
	until [ -z "$1" ]
Martin Stransky efe9b5
	do
Martin Stransky efe9b5
	case "$1" in
perex 1e0bef
		--pastebin)
perex 1e0bef
		        update
perex 46b106
			withall
perex 1e0bef
        		pbcheck
perex 1e0bef
			;;
Martin Stransky efe9b5
		--update)
Martin Stransky efe9b5
			update
Martin Stransky efe9b5
			exit
Martin Stransky efe9b5
			;;
perex 46b106
		--upload)
perex 46b106
			UPLOAD="yes"
perex 46b106
			withall
perex 46b106
			;;
Martin Stransky efe9b5
		--no-upload)
perex 46b106
			UPLOAD="no"
perex 46b106
			withall
perex 46b106
			;;
perex 46b106
		--output)
perex 46b106
			shift
perex 46b106
			NFILE="$1"
perex 46b106
			KEEP_OUTPUT="yes"
Martin Stransky efe9b5
			;;
Martin Stransky efe9b5
		--debug)
Martin Stransky efe9b5
			echo "Debugging enabled. $FILE and $TEMPDIR will not be deleted"
Martin Stransky efe9b5
			KEEP_FILES="yes"
Martin Stransky efe9b5
			echo ""
perex 46b106
			withall
Martin Stransky efe9b5
			;;
Martin Stransky efe9b5
		--with-all)
perex 46b106
			withall
Martin Stransky efe9b5
			;;
Martin Stransky efe9b5
		--with-aplay)
Martin Stransky efe9b5
			withaplay
Martin Stransky efe9b5
			;;
Martin Stransky efe9b5
		--with-amixer)
Martin Stransky efe9b5
			withamixer
Martin Stransky efe9b5
			;;
Martin Stransky efe9b5
		--with-alsactl)
Martin Stransky efe9b5
			withalsactl
Martin Stransky efe9b5
			;;
Martin Stransky efe9b5
		--with-devices)
Martin Stransky efe9b5
			withdevices
Martin Stransky efe9b5
			;;
perex 46b106
		--with-dmesg)
perex 46b106
			withdmesg
perex 46b106
			;;
Martin Stransky efe9b5
		--with-configs)
Martin Stransky efe9b5
			if [[ -e $HOME/.asoundrc ]] || [[ -e /etc/asound.conf ]]
Martin Stransky efe9b5
			then
Martin Stransky efe9b5
				echo "!!ALSA configuration files" >> $FILE
Martin Stransky efe9b5
				echo "!!------------------------" >> $FILE
Martin Stransky efe9b5
				echo "" >> $FILE
Martin Stransky efe9b5
Martin Stransky efe9b5
				#Check for ~/.asoundrc
Martin Stransky efe9b5
				if [[ -e $HOME/.asoundrc ]]
Martin Stransky efe9b5
				then
Martin Stransky efe9b5
					echo "!!User specific config file ($HOME/.asoundrc)" >> $FILE
Martin Stransky efe9b5
					echo "" >> $FILE
Martin Stransky efe9b5
					cat $HOME/.asoundrc >> $FILE
Martin Stransky efe9b5
					echo "" >> $FILE
Martin Stransky efe9b5
					echo "" >> $FILE
Martin Stransky efe9b5
				fi
Martin Stransky efe9b5
Martin Stransky efe9b5
				#Check for /etc/asound.conf
Martin Stransky efe9b5
				if [[ -e /etc/asound.conf ]]
Martin Stransky efe9b5
				then
Martin Stransky efe9b5
					echo "!!System wide config file (/etc/asound.conf)" >> $FILE
Martin Stransky efe9b5
					echo "" >> $FILE
Martin Stransky efe9b5
					cat /etc/asound.conf >> $FILE
Martin Stransky efe9b5
					echo "" >> $FILE
Martin Stransky efe9b5
					echo "" >> $FILE
Martin Stransky efe9b5
				fi
Martin Stransky efe9b5
			fi
Martin Stransky efe9b5
			;;
perex bbe9f6
		--stdout)
perex 46b106
			UPLOAD="no"
perex 46b106
			withall
perex bbe9f6
			cat $FILE
perex bbe9f6
			rm $FILE
perex bbe9f6
			;;
Martin Stransky efe9b5
		--about)
Martin Stransky efe9b5
			echo "Written/Tested by the following users of #alsa on irc.freenode.net:"
Martin Stransky efe9b5
			echo ""
Martin Stransky efe9b5
			echo "	wishie - Script author and developer / Testing"
Martin Stransky efe9b5
			echo "	crimsun - Various script ideas / Testing"
Martin Stransky efe9b5
			echo "	gnubien - Various script ideas / Testing"
Martin Stransky efe9b5
			echo "	GrueMaster - HDA Intel specific items / Testing"
Martin Stransky efe9b5
			echo "	olegfink - Script update function"
perex bbe9f6
			echo "  TheMuso - display to stdout functionality"
Martin Stransky efe9b5
			exit 0
Martin Stransky efe9b5
			;;
Martin Stransky efe9b5
		*)
perex 1e0bef
			echo "alsa-info.sh version $SCRIPT_VERSION"
Martin Stransky efe9b5
			echo ""
Martin Stransky efe9b5
			echo "Available options:"
Martin Stransky efe9b5
			echo "	--with-aplay (includes the output of aplay -l)"
Martin Stransky efe9b5
			echo "	--with-amixer (includes the output of amixer)"
Martin Stransky efe9b5
			echo "	--with-alsactl (includes the output of alsactl)"
perex 1e0bef
			echo "	--with-configs (includes the output of ~/.asoundrc and"
perex 1e0bef
			echo "	    /etc/asound.conf if they exist)" 
Martin Stransky efe9b5
			echo "	--with-devices (shows the device nodes in /dev/snd/)"
perex 46b106
			echo "	--with-dmesg (shows the ALSA/HDA kernel messages)"
Martin Stransky efe9b5
			echo ""
perex 46b106
			echo "	--output FILE (specify the file to output for no-upload mode)"
Martin Stransky efe9b5
			echo "	--update (check server for script updates)"
perex 46b106
			echo "	--upload (upload contents to remote server)"
Martin Stransky efe9b5
			echo "	--no-upload (do not upload contents to remote server)"
perex 1e0bef
			echo "	--pastebin (use http://pastebin.ca) as remote server"
perex 1e0bef
			echo "	    instead www.alsa-project.org"
perex 46b106
			echo "	--stdout (print alsa information to standard output"
perex 46b106
			echo "	    instead of a file)"
Martin Stransky efe9b5
			echo "	--about (show some information about the script)"
perex 1e0bef
			echo "	--debug (will run the script as normal, but will not"
perex 1e0bef
			echo "	     delete $FILE)"
Martin Stransky efe9b5
			exit 0
Martin Stransky efe9b5
			;;
Martin Stransky efe9b5
	esac
Martin Stransky efe9b5
	shift 1
Martin Stransky efe9b5
	done
Martin Stransky efe9b5
fi
Martin Stransky efe9b5
perex bbe9f6
if [ "$PROCEED" = "no" ]; then
perex bbe9f6
	exit 1
perex bbe9f6
fi
perex bbe9f6
perex 46b106
if [ "$UPLOAD" = "ask" ]; then
perex 46b106
	if [[ -n "$DIALOG" ]]; then
perex 46b106
		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
perex 46b106
		DIALOG_EXIT_CODE=$?
perex 46b106
		if [ $DIALOG_EXIT_CODE != 0 ]; then
perex 46b106
			UPLOAD="no"
perex 46b106
		else
perex 46b106
			UPLOAD="yes"
perex 46b106
		fi
perex 46b106
	else
perex 46b106
		echo -n "Automatically upload ALSA information to $WWWSERVICE? [y/N] : "
perex 46b106
		read -e CONFIRM
perex 46b106
		if [ "$CONFIRM" != "y" ]; then
perex 46b106
			UPLOAD="no"
perex 46b106
		else
perex 46b106
			UPLOAD="yes"
perex 46b106
		fi
perex 46b106
	fi
perex 46b106
perex 46b106
fi
perex 46b106
perex 46b106
if [ "$UPLOAD" = "no" ]; then
perex bbe9f6
perex bbe9f6
	if [ -z "$TOSTDOUT" ]; then
perex 46b106
		mv -f $FILE $NFILE || exit 1
perex 46b106
		KEEP_OUTPUT="yes"
perex bbe9f6
	fi
perex bbe9f6
perex bbe9f6
	if [[ -n $DIALOG ]]
perex bbe9f6
	then
perex bbe9f6
		if [[ -n $PBERROR ]]; then
perex 46b106
			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
perex bbe9f6
		else
perex 46b106
			dialog --backtitle "$BGTITLE" --title "Information collected" --msgbox "\n\nYour ALSA information is in $NFILE" 10 60
perex bbe9f6
		fi
perex bbe9f6
	else
perex bbe9f6
		echo
perex bbe9f6
perex bbe9f6
		if [[ -n $PBERROR ]]; then
perex 46b106
			echo "An error occurred while contacting the $WWWSERVICE."
perex 46b106
			echo "Your information was NOT automatically uploaded."
perex bbe9f6
			echo ""
perex 46b106
			echo "Your ALSA information is in $NFILE"
perex bbe9f6
			echo ""
perex bbe9f6
		else
perex bbe9f6
			if [ -z "$TOSTDOUT" ]; then
perex bbe9f6
				echo ""
perex 46b106
				echo "Your ALSA information is in $NFILE"
perex bbe9f6
				echo ""
perex bbe9f6
			fi
perex bbe9f6
		fi
perex bbe9f6
	fi
perex bbe9f6
perex bbe9f6
	exit
perex bbe9f6
perex 46b106
fi # UPLOAD
Martin Stransky efe9b5
Martin Stransky efe9b5
#Test that wget is installed, and supports --post-file. Upload $FILE if it does, and prompt user to upload file if it doesnt. 
Martin Stransky efe9b5
if
Martin Stransky efe9b5
WGET=$(which wget 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null); [[ -n "${WGET}" ]] && [[ -x "${WGET}" ]] && [[ `wget --help |grep post-file` ]]
Martin Stransky efe9b5
then
perex bbe9f6
perex bbe9f6
if [[ -n $DIALOG ]]
Martin Stransky efe9b5
then
perex bbe9f6
perex bbe9f6
if [[ -z $PASTEBIN ]]; then
perex 2a14aa
	wget -O - --tries=5 --timeout=60 --post-file=$FILE "http://www.alsa-project.org/cardinfo-db/" &>$TEMPDIR/wget.tmp || echo "Upload failed; exit"
perex 1e0bef
	{ for i in 10 20 30 40 50 60 70 80 90; do
perex 1e0bef
		echo $i
perex 1e0bef
		sleep 0.2
perex 1e0bef
	done
perex 1e0bef
	echo; } |dialog --backtitle "$BGTITLE" --guage "Uploading information to www.alsa-project.org ..." 6 70 0
perex bbe9f6
else
perex 2a14aa
	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"
Martin Stransky efe9b5
	{ for i in 10 20 30 40 50 60 70 80 90; do
Martin Stransky efe9b5
		echo $i
Martin Stransky efe9b5
		sleep 0.2
Martin Stransky efe9b5
	done
Martin Stransky efe9b5
	echo; } |dialog --backtitle "$BGTITLE" --guage "Uploading information to www.pastebin.ca ..." 6 70 0
perex bbe9f6
fi
perex bbe9f6
perex bbe9f6
dialog --backtitle "$BGTITLE" --title "Information uploaded" --yesno "Would you like to see the uploaded information?" 5 100 
perex bbe9f6
DIALOG_EXIT_CODE=$?
perex bbe9f6
if [ $DIALOG_EXIT_CODE = 0 ]; then
perex bbe9f6
	grep -v "alsa-info.txt" $FILE >$TEMPDIR/uploaded.txt
perex bbe9f6
	dialog --backtitle "$BGTITLE" --textbox $TEMPDIR/uploaded.txt 0 0
perex bbe9f6
fi
perex bbe9f6
perex bbe9f6
clear
perex bbe9f6
perex bbe9f6
# no dialog
Martin Stransky efe9b5
else
Martin Stransky efe9b5
perex bbe9f6
if [[ -z $PASTEBIN ]]; then
perex 1e0bef
	echo -n "Uploading information to www.alsa-project.org ... " 
perex 2a14aa
	wget -O - --tries=5 --timeout=60 --post-file=$FILE http://www.alsa-project.org/cardinfo-db/ &>$TEMPDIR/wget.tmp &
perex bbe9f6
else
Martin Stransky efe9b5
	echo -n "Uploading information to www.pastebin.ca ... " 
perex 2a14aa
	wget -O - --tries=5 --timeout=60 --post-file=$FILE http://pastebin.ca/quiet-paste.php?api=$PASTEBINKEY &>$TEMPDIR/wget.tmp &
Martin Stransky efe9b5
fi
perex bbe9f6
Martin Stransky efe9b5
#Progess spinner for wget transfer.
perex bbe9f6
i=1
perex bbe9f6
sp="/-\|"
perex bbe9f6
echo -n ' '
perex bbe9f6
while pgrep wget &>/dev/null
perex bbe9f6
do
Martin Stransky efe9b5
	echo -en "\b${sp:i++%${#sp}:1}"
perex bbe9f6
done
perex bbe9f6
perex bbe9f6
echo -e "\b Done!"
perex bbe9f6
echo ""
perex bbe9f6
perex bbe9f6
fi #dialog
Martin Stransky efe9b5
Martin Stransky efe9b5
#See if tput is available, and use it if it is.	
perex bbe9f6
if [[ -n "$TPUT" ]]
Martin Stransky efe9b5
then
perex bbe9f6
	if [[ -z $PASTEBIN ]]; then
perex bbe9f6
		FINAL_URL=`tput setaf 1; grep "SUCCESS:" $TEMPDIR/wget.tmp | cut -d ' ' -f 2 ; tput sgr0`
Martin Stransky efe9b5
	else
perex bbe9f6
		FINAL_URL=`tput setaf 1; grep "SUCCESS:" $TEMPDIR/wget.tmp |sed -n 's/.*\:\([0-9]\+\).*/http:\/\/pastebin.ca\/\1/p';tput sgr0`
Martin Stransky efe9b5
	fi
perex bbe9f6
else
perex bbe9f6
	if [[ -z $PASTEBIN ]]; then
perex bbe9f6
		FINAL_URL=`grep "SUCCESS:" $TEMPDIR/wget.tmp | cut -d ' ' -f 2`
perex a657df
	else
perex bbe9f6
		FINAL_URL=`grep "SUCCESS:" $TEMPDIR/wget.tmp |sed -n 's/.*\:\([0-9]\+\).*/http:\/\/pastebin.ca\/\1/p'`
perex a657df
	fi
Martin Stransky efe9b5
fi
perex bbe9f6
perex bbe9f6
#Output the URL of the uploaded file.	
Martin Stransky efe9b5
echo "Your ALSA information is located at $FINAL_URL"
Martin Stransky efe9b5
echo "Please inform the person helping you."
Martin Stransky efe9b5
echo ""
Martin Stransky efe9b5
Martin Stransky efe9b5
#We couldnt find a suitable wget, so tell the user to upload manually.
Martin Stransky efe9b5
else
perex 46b106
	mv -f $FILE $NFILE || exit 1
perex 46b106
	KEEP_OUTPUT="yes"
Martin Stransky efe9b5
	if [[ -z $DIALOG ]]
Martin Stransky efe9b5
	then
perex 1e0bef
		if [[ -z $PASTEBIN ]]; then
perex 1e0bef
		echo ""
perex 1e0bef
		echo "Could not automatically upload output to http://www.alsa-project.org"
perex 1e0bef
		echo "Possible reasons are:"
perex 1e0bef
		echo "    1. Couldnt find 'wget' in your PATH"
perex 1e0bef
		echo "    2. Your version of wget is less than 1.8.2"
perex 1e0bef
		echo ""
perex 2a14aa
		echo "Please manually upload $NFILE to http://www.alsa-project.org/cardinfo-db/ and submit your post."
perex 1e0bef
		echo ""
perex 1e0bef
		else
Martin Stransky efe9b5
		echo ""
Martin Stransky efe9b5
		echo "Could not automatically upload output to http://www.pastebin.ca"
Martin Stransky efe9b5
		echo "Possible reasons are:"
Martin Stransky efe9b5
		echo "    1. Couldnt find 'wget' in your PATH"
Martin Stransky efe9b5
		echo "    2. Your version of wget is less than 1.8.2"
Martin Stransky efe9b5
		echo ""
perex 2a14aa
		echo "Please manually upload $NFILE to http://www.pastebin.ca/upload.php and submit your post."
Martin Stransky efe9b5
		echo ""
perex 1e0bef
		fi
perex bbe9f6
	else
perex 1e0bef
		if [[ -z $PASTEBIN ]]; then
perex 2a14aa
			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
perex 1e0bef
		else
perex 2a14aa
			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
perex 1e0bef
		fi
Martin Stransky efe9b5
	fi
Martin Stransky efe9b5
fi
Martin Stransky efe9b5
perex bbe9f6