Martin Stransky efe9b5
#!/bin/bash
Martin Stransky efe9b5
perex ce9f2b
SCRIPT_VERSION=0.4.58
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 ce9f2b
	[[ $UPLOAD = "no" ]] && return
perex ce9f2b
perex 1e0bef
	if [[ -z $PASTEBIN ]]; then
perex ce9f2b
		[[ $(ping -c1 www.alsa-project.org) ]] || KEEP_FILES="yes" UPLOAD="no" PBERROR="yes"
perex 1e0bef
	else
perex ce9f2b
		[[ $(ping -c1 www.pastebin.ca) ]] || KEEP_FILES="yes" UPLOAD="no" PBERROR="yes"
perex 1e0bef
	fi
perex a657df
}
perex a657df
Martin Stransky efe9b5
update() {
perex ce9f2b
	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 ce9f2b
					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 ce9f2b
				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 1a0b77
	if [ -n "$TEMPDIR" -a "$KEEP_FILES" != "yes" ]; then
perex ce9f2b
		rm -rf "$TEMPDIR" 2>/dev/null
perex 1a0b77
	fi
perex ce9f2b
	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
Martin Stransky efe9b5
        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
Martin Stransky efe9b5
        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 1a0b77
withsysfs() {
perex 1a0b77
    local i f
perex 1a0b77
    local printed=""
perex 1a0b77
    for i in /sys/class/sound/*; do
perex 1a0b77
	case "$i" in
perex 1a0b77
	    */hwC?D?)
perex 1a0b77
		if [ -f $i/init_pin_configs ]; then
perex 1a0b77
		    if [ -z "$printed" ]; then
perex 1a0b77
			echo "!!Sysfs Files" >> $FILE
perex 1a0b77
			echo "!!-----------" >> $FILE
perex 1a0b77
			echo "" >> $FILE
perex 1a0b77
		    fi
perex 1a0b77
		    for f in init_pin_configs driver_pin_configs user_pin_configs init_verbs; do
perex 1a0b77
			echo "$i/$f:" >> $FILE
perex 1a0b77
			cat $i/$f >> $FILE
perex 1a0b77
			echo >> $FILE
perex 1a0b77
		    done
perex 1a0b77
		    printed=yes
perex 1a0b77
		fi
perex 1a0b77
		;;
perex 1a0b77
	    esac
perex 1a0b77
    done
perex 1a0b77
    if [ -n "$printed" ]; then
perex 1a0b77
	echo "" >> $FILE
perex 1a0b77
    fi
perex 1a0b77
}
perex 1a0b77
perex ce9f2b
withdmesg() {
perex ce9f2b
	echo "!!ALSA/HDA dmesg" >> $FILE
perex ce9f2b
	echo "!!------------------" >> $FILE
perex ce9f2b
	echo "" >> $FILE
perex ce9f2b
	dmesg | grep -C1 -E 'ALSA|HDA|HDMI|sound|hda.codec|hda.intel' >> $FILE
perex ce9f2b
	echo "" >> $FILE
perex ce9f2b
	echo "" >> $FILE
perex ce9f2b
}
perex ce9f2b
perex ce9f2b
withall() {
perex ce9f2b
	withdevices
perex ce9f2b
	withconfigs
perex ce9f2b
	withaplay
perex ce9f2b
	withamixer
perex ce9f2b
	withalsactl
perex ce9f2b
	withlsmod
perex ce9f2b
	withsysfs
perex ce9f2b
	withdmesg
perex ce9f2b
}
perex ce9f2b
perex 1a0b77
get_alsa_library_version() {
perex 1a0b77
	ALSA_LIB_VERSION=`grep VERSION_STR /usr/include/alsa/version.h 2>/dev/null|awk {'print $3'}|sed 's/"//g'`
perex 1a0b77
perex 1a0b77
	if [ -z "$ALSA_LIB_VERSION" ]; then
perex 1a0b77
		if [ -f /etc/lsb-release ]; then
perex 1a0b77
			. /etc/lsb-release
perex 1a0b77
			case "$DISTRIB_ID" in
perex 1a0b77
				Ubuntu)
perex 1a0b77
					if which dpkg > /dev/null ; then
perex 1a0b77
						ALSA_LIB_VERSION=`dpkg -l libasound2 | tail -1 | awk '{print $3}' | cut -f 1 -d -`
perex 1a0b77
					fi
perex 1a0b77
perex 1a0b77
					if [ "$ALSA_LIB_VERSION" = "<none>" ]; then
perex 1a0b77
						ALSA_LIB_VERSION=""
perex 1a0b77
					fi
perex 1a0b77
					return
perex 1a0b77
					;;
perex 1a0b77
				*)
perex 1a0b77
					return
perex 1a0b77
					;;
perex 1a0b77
			esac
perex 1a0b77
		elif [ -f /etc/debian_version ]; then
perex 1a0b77
			if which dpkg > /dev/null ; then
perex 1a0b77
				ALSA_LIB_VERSION=`dpkg -l libasound2 | tail -1 | awk '{print $3}' | cut -f 1 -d -`
perex 1a0b77
			fi
perex 1a0b77
perex 1a0b77
			if [ "$ALSA_LIB_VERSION" = "<none>" ]; then
perex 1a0b77
				ALSA_LIB_VERSION=""
perex 1a0b77
			fi
perex 1a0b77
			return
perex 1a0b77
		fi
perex 1a0b77
	fi
perex 1a0b77
}
perex 1a0b77
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 ce9f2b
KEEP_OUTPUT=
perex ce9f2b
NFILE=""
perex ce9f2b
perex 1e0bef
PASTEBIN=""
perex 1e0bef
WWWSERVICE="www.alsa-project.org"
perex ce9f2b
WELCOME="yes"
Martin Stransky efe9b5
PROCEED="yes"
perex ce9f2b
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 ce9f2b
		WELCOME="no"
Martin Stransky efe9b5
		PROCEED="no"
Martin Stransky efe9b5
		;;
perex ce9f2b
	--upload)
perex ce9f2b
		UPLOAD="yes"
perex ce9f2b
		WELCOME="no"
perex ce9f2b
		;;
Martin Stransky efe9b5
	--no-upload)
perex ce9f2b
		UPLOAD="no"
perex ce9f2b
		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 1a0b77
	--stdout)
perex 1a0b77
		DIALOG=""
perex ce9f2b
		UPLOAD="no"
perex ce9f2b
		WELCOME="no"
perex 1a0b77
		TOSTDOUT="yes"
perex 1a0b77
		;;
Martin Stransky efe9b5
esac
Martin Stransky efe9b5
done
Martin Stransky efe9b5
Martin Stransky efe9b5
perex ce9f2b
#Script header output.
perex ce9f2b
if [ "$WELCOME" = "yes" ]; then
perex ce9f2b
greeting_message="\
perex ce9f2b
perex ce9f2b
This script visits the following commands/files to collect diagnostic
perex ce9f2b
information about your ALSA installation and sound related hardware.
perex ce9f2b
perex ce9f2b
  dmesg
perex ce9f2b
  lspci
perex ce9f2b
  lsmod
perex ce9f2b
  aplay
perex ce9f2b
  amixer
perex ce9f2b
  alsactl
perex ce9f2b
  /proc/asound/
perex ce9f2b
  /sys/class/sound/
perex ce9f2b
  ~/.asoundrc (etc.)
perex ce9f2b
perex ce9f2b
See '$0 --help' for command line options.
perex ce9f2b
"
perex ce9f2b
if [[ -n "$DIALOG" ]]; then
perex ce9f2b
	dialog  --backtitle "$BGTITLE" \
perex ce9f2b
		--title "ALSA-Info script v $SCRIPT_VERSION" \
perex ce9f2b
		--msgbox "$greeting_message" 20 80
Martin Stransky efe9b5
else
perex ce9f2b
	echo "ALSA Information Script v $SCRIPT_VERSION"
perex ce9f2b
	echo "--------------------------------"
perex ce9f2b
	echo "$greeting_message"
perex ce9f2b
fi # dialog
perex ce9f2b
fi # WELCOME
Martin Stransky efe9b5
Martin Stransky efe9b5
#Set the output file
perex ce9f2b
TEMPDIR=`mktemp -t -d alsa-info.XXXXXXXXXX` || exit 1
perex 2a14aa
FILE="$TEMPDIR/alsa-info.txt"
perex ce9f2b
if [ -z "$NFILE" ]; then
perex ce9f2b
	NFILE=`mktemp -t alsa-info.txt.XXXXXXXXXX` || exit 1
perex ce9f2b
fi
Martin Stransky efe9b5
perex 1a0b77
trap cleanup 0
perex 1a0b77
Martin Stransky efe9b5
if [ "$PROCEED" = "yes" ]; then
Martin Stransky efe9b5
Martin Stransky efe9b5
if [[ -z "$LSPCI" ]] 
perex 1a0b77
then
Martin Stransky efe9b5
	echo "This script requires lspci. Please install it, and re-run this script."
perex 1a0b77
	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 1a0b77
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 1a0b77
JACKINST=$(which jackd 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null)
perex ce9f2b
DMIDECODE=$(which dmidecode 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null)
perex ce9f2b
perex ce9f2b
#Check for DMI data
perex ce9f2b
if [ -d /sys/class/dmi/id ]; then
perex ce9f2b
    # No root privileges are required when using sysfs method
perex ce9f2b
    DMI_SYSTEM_MANUFACTURER=$(cat /sys/class/dmi/id/sys_vendor 2>/dev/null)
perex ce9f2b
    DMI_SYSTEM_PRODUCT_NAME=$(cat /sys/class/dmi/id/product_name 2>/dev/null)
perex ce9f2b
elif [ -x $DMIDECODE ]; then
perex ce9f2b
    DMI_SYSTEM_MANUFACTURER=$($DMIDECODE -s system-manufacturer 2>/dev/null)
perex ce9f2b
    DMI_SYSTEM_PRODUCT_NAME=$($DMIDECODE -s system-product-name 2>/dev/null)
perex ce9f2b
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
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 ce9f2b
echo "!!DMI Information" >> $FILE
perex ce9f2b
echo "!!---------------" >> $FILE
perex ce9f2b
echo "" >> $FILE
perex ce9f2b
echo "Manufacturer:      $DMI_SYSTEM_MANUFACTURER" >> $FILE
perex ce9f2b
echo "Product Name:      $DMI_SYSTEM_PRODUCT_NAME" >> $FILE
perex ce9f2b
echo "" >> $FILE
perex ce9f2b
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 1a0b77
[[ `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 1a0b77
[[ `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 1a0b77
[[ `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 1a0b77
if [[ -n $JACKINST ]];then
perex 1a0b77
[[ `pgrep '^(.*/)?jackd$'` ]] && JACKRUNNING="Yes" || JACKRUNNING="No"
perex 1a0b77
echo "Jack:" >> $FILE
perex 1a0b77
echo "      Installed - Yes ($JACKINST)" >> $FILE
perex 1a0b77
echo "      Running - $JACKRUNNING" >> $FILE
perex 1a0b77
echo "" >> $FILE
perex 1a0b77
fi
perex 1a0b77
if [[ -z "$PAINST" && -z "$ESDINST" && -z "$ARTSINST" && -z "$JACKINST" ]];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
Martin Stransky efe9b5
echo "!!Advanced information - PCI Vendor/Device/Susbsystem ID's" >> $FILE
Martin Stransky efe9b5
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
Martin Stransky efe9b5
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 ce9f2b
for params in `echo $SYSFS/module/$mod/parameters/*`; do
perex ce9f2b
	echo -ne "\t";
perex ce9f2b
	echo "$params : `cat $params`" | sed 's:.*/::';
perex ce9f2b
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
Martin Stransky efe9b5
        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
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 ce9f2b
	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 ce9f2b
			withall
perex 1e0bef
        		pbcheck
perex 1e0bef
			;;
Martin Stransky efe9b5
		--update)
Martin Stransky efe9b5
			update
Martin Stransky efe9b5
			exit
Martin Stransky efe9b5
			;;
perex ce9f2b
		--upload)
perex ce9f2b
			UPLOAD="yes"
perex ce9f2b
			withall
perex ce9f2b
			;;
Martin Stransky efe9b5
		--no-upload)
perex ce9f2b
			UPLOAD="no"
perex ce9f2b
			withall
perex ce9f2b
			;;
perex ce9f2b
		--output)
perex ce9f2b
			shift
perex ce9f2b
			NFILE="$1"
perex ce9f2b
			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 ce9f2b
			withall
Martin Stransky efe9b5
			;;
Martin Stransky efe9b5
		--with-all)
perex ce9f2b
			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 ce9f2b
		--with-dmesg)
perex ce9f2b
			withdmesg
perex ce9f2b
			;;
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 1a0b77
		--stdout)
perex ce9f2b
			UPLOAD="no"
perex ce9f2b
			withall
perex 1a0b77
			cat $FILE
perex 1a0b77
			rm $FILE
perex 1a0b77
			;;
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 1a0b77
			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 ce9f2b
			echo "	--with-dmesg (shows the ALSA/HDA kernel messages)"
Martin Stransky efe9b5
			echo ""
perex ce9f2b
			echo "	--output FILE (specify the file to output for no-upload mode)"
Martin Stransky efe9b5
			echo "	--update (check server for script updates)"
perex ce9f2b
			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 ce9f2b
			echo "	--stdout (print alsa information to standard output"
perex ce9f2b
			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 1a0b77
if [ "$PROCEED" = "no" ]; then
perex 1a0b77
	exit 1
perex 1a0b77
fi
perex 1a0b77
perex ce9f2b
if [ "$UPLOAD" = "ask" ]; then
perex ce9f2b
	if [[ -n "$DIALOG" ]]; then
perex ce9f2b
		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 ce9f2b
		DIALOG_EXIT_CODE=$?
perex ce9f2b
		if [ $DIALOG_EXIT_CODE != 0 ]; then
perex ce9f2b
			UPLOAD="no"
perex ce9f2b
		else
perex ce9f2b
			UPLOAD="yes"
perex ce9f2b
		fi
perex ce9f2b
	else
perex ce9f2b
		echo -n "Automatically upload ALSA information to $WWWSERVICE? [y/N] : "
perex ce9f2b
		read -e CONFIRM
perex ce9f2b
		if [ "$CONFIRM" != "y" ]; then
perex ce9f2b
			UPLOAD="no"
perex ce9f2b
		else
perex ce9f2b
			UPLOAD="yes"
perex ce9f2b
		fi
perex ce9f2b
	fi
perex ce9f2b
perex ce9f2b
fi
perex ce9f2b
perex ce9f2b
if [ "$UPLOAD" = "no" ]; then
perex 1a0b77
perex 1a0b77
	if [ -z "$TOSTDOUT" ]; then
perex ce9f2b
		mv -f $FILE $NFILE || exit 1
perex ce9f2b
		KEEP_OUTPUT="yes"
perex 1a0b77
	fi
perex 1a0b77
perex 1a0b77
	if [[ -n $DIALOG ]]
perex 1a0b77
	then
perex 1a0b77
		if [[ -n $PBERROR ]]; then
perex ce9f2b
			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 1a0b77
		else
perex ce9f2b
			dialog --backtitle "$BGTITLE" --title "Information collected" --msgbox "\n\nYour ALSA information is in $NFILE" 10 60
perex 1a0b77
		fi
perex 1a0b77
	else
perex 1a0b77
		echo
perex 1a0b77
perex 1a0b77
		if [[ -n $PBERROR ]]; then
perex ce9f2b
			echo "An error occurred while contacting the $WWWSERVICE."
perex ce9f2b
			echo "Your information was NOT automatically uploaded."
perex 1a0b77
			echo ""
perex ce9f2b
			echo "Your ALSA information is in $NFILE"
perex 1a0b77
			echo ""
perex 1a0b77
		else
perex 1a0b77
			if [ -z "$TOSTDOUT" ]; then
perex 1a0b77
				echo ""
perex ce9f2b
				echo "Your ALSA information is in $NFILE"
perex 1a0b77
				echo ""
perex 1a0b77
			fi
perex 1a0b77
		fi
perex 1a0b77
	fi
perex 1a0b77
perex 1a0b77
	exit
perex 1a0b77
perex ce9f2b
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 1a0b77
perex 1a0b77
if [[ -n $DIALOG ]]
Martin Stransky efe9b5
then
perex 1a0b77
perex 1a0b77
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 1a0b77
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 1a0b77
fi
perex 1a0b77
perex 1a0b77
dialog --backtitle "$BGTITLE" --title "Information uploaded" --yesno "Would you like to see the uploaded information?" 5 100 
perex 1a0b77
DIALOG_EXIT_CODE=$?
perex 1a0b77
if [ $DIALOG_EXIT_CODE = 0 ]; then
perex 1a0b77
	grep -v "alsa-info.txt" $FILE >$TEMPDIR/uploaded.txt
perex 1a0b77
	dialog --backtitle "$BGTITLE" --textbox $TEMPDIR/uploaded.txt 0 0
perex 1a0b77
fi
perex 1a0b77
perex 1a0b77
clear
perex 1a0b77
perex 1a0b77
# no dialog
Martin Stransky efe9b5
else
Martin Stransky efe9b5
perex 1a0b77
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 1a0b77
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 1a0b77
Martin Stransky efe9b5
#Progess spinner for wget transfer.
perex 1a0b77
i=1
perex 1a0b77
sp="/-\|"
perex 1a0b77
echo -n ' '
perex 1a0b77
while pgrep wget &>/dev/null
perex 1a0b77
do
Martin Stransky efe9b5
	echo -en "\b${sp:i++%${#sp}:1}"
perex 1a0b77
done
perex 1a0b77
perex 1a0b77
echo -e "\b Done!"
perex 1a0b77
echo ""
perex 1a0b77
perex 1a0b77
fi #dialog
Martin Stransky efe9b5
Martin Stransky efe9b5
#See if tput is available, and use it if it is.	
perex 1a0b77
if [[ -n "$TPUT" ]]
Martin Stransky efe9b5
then
perex 1a0b77
	if [[ -z $PASTEBIN ]]; then
perex 1a0b77
		FINAL_URL=`tput setaf 1; grep "SUCCESS:" $TEMPDIR/wget.tmp | cut -d ' ' -f 2 ; tput sgr0`
Martin Stransky efe9b5
	else
perex 1a0b77
		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 1a0b77
else
perex 1a0b77
	if [[ -z $PASTEBIN ]]; then
perex 1a0b77
		FINAL_URL=`grep "SUCCESS:" $TEMPDIR/wget.tmp | cut -d ' ' -f 2`
perex a657df
	else
perex 1a0b77
		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 1a0b77
perex 1a0b77
#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 ce9f2b
	mv -f $FILE $NFILE || exit 1
perex ce9f2b
	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 1a0b77
	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 1a0b77