#!/bin/bash #alsa-info.sh 0.4.3 ################################################################################# #Copyright (C) 2007 Free Software Foundation. #This program is free software; you can redistribute it and/or modify #it under the terms of the GNU General Public License as published by #the Free Software Foundation; either version 2 of the License, or #(at your option) any later version. #This program is distributed in the hope that it will be useful, #but WITHOUT ANY WARRANTY; without even the implied warranty of #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #GNU General Public License for more details. #You should have received a copy of the GNU General Public License #along with this program; if not, write to the Free Software #Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ################################################################################## #The script was written for 2 main reasons: # 1. Remove the need for the devs/helpers to ask several questions before we can easily help the user. # 2. Allow newer/inexperienced ALSA users to give us all the info we need to help them. #Change the PATH variable, so we can run lspci (needed for some distros) PATH=$PATH:/bin:/sbin:/usr/bin:/usr/sbin #Define some simple functions function cleanup { rm -r $TEMPDIR 2>/dev/null rm $FILE 2>/dev/null } function withaplay { echo "Aplay output" >> $FILE echo "------------" >> $FILE echo "" >> $FILE aplay -l >> $FILE echo "" >> $FILE echo "" >> $FILE } function withamixer { echo "Amixer output" >> $FILE echo "-------------" >> $FILE echo "" >> $FILE amixer >> $FILE echo "" >> $FILE echo "" >> $FILE } function withdevices { echo "ALSA Device nodes" >> $FILE echo "-----------------" >> $FILE echo "" >> $FILE ls -la /dev/snd/* >> $FILE echo "" >> $FILE echo "" >> $FILE } function withconfigs { if [[ -e $HOME/.asoundrc ]] || [[ -e /etc/asound.conf ]] then echo "ALSA configuration files" >> $FILE echo "------------------------" >> $FILE echo "" >> $FILE #Check for ~/.asoundrc if [[ -e $HOME/.asoundrc ]] then echo "User specific config file ($HOME/.asoundrc)" >> $FILE echo "" >> $FILE cat $HOME/.asoundrc >> $FILE echo "" >> $FILE echo "" >> $FILE fi #Check for /etc/asound.conf if [[ -e /etc/asound.conf ]] then echo "System wide config file (/etc/asound.conf)" >> $FILE echo "" >> $FILE cat /etc/asound.conf >> $FILE echo "" >> $FILE echo "" >> $FILE fi else echo "No config files found (--with-configs) , skipping." fi } #Set the script version SCRIPT_VERSION="0.4.3" #Run checks to make sure the programs we need are installed. LSPCI=$(which lspci 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null); TPUT=$(which tput 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null); #Script header output. echo "ALSA Information Script v $SCRIPT_VERSION" echo "----------------------------" echo "" if [[ -z "$LSPCI" ]] then echo "This script requires lspci. Please install it, and re-run this script." exit 0 fi #Set the output file TEMPDIR="/tmp/alsainfo/" FILE="/tmp/alsa-info.txt" #Create the temporary work dir. mkdir $TEMPDIR 2>/dev/null #Fetch the info and store in temp files/variables 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" /etc/{*release,*version}` KERNEL_VERSION=`uname -r` KERNEL_PROCESSOR=`uname -p` KERNEL_MACHINE=`uname -m` KERNEL_OS=`uname -o` [[ `uname -v |grep SMP` ]] && KERNEL_SMP="Yes" || KERNEL_SMP="No" ALSA_DRIVER_VERSION=`cat /proc/asound/version |head -n1|awk {'print $7'} |sed 's/\.$//'` ALSA_LIB_VERSION=`grep VERSION_STR /usr/include/alsa/version.h 2>/dev/null|awk {'print $3'}|sed 's/"//g'` ALSA_UTILS_VERSION=`amixer -v |awk {'print $3'}` VENDOR_ID=`lspci -vn |grep 040[1-3] | awk -F':' '{print $3}'|awk {'print substr($0, 2);}' >/tmp/alsainfo/vendor_id.tmp` DEVICE_ID=`lspci -vn |grep 040[1-3] | awk -F':' '{print $4}'|awk {'print $1'} >/tmp/alsainfo/device_id.tmp` NUM_CARDS=`wc -l /tmp/alsainfo/vendor_id.tmp|awk {'print $1'}` cat /proc/asound/modules|awk {'print $2'}>/tmp/alsainfo/alsamodules.tmp cat /proc/asound/cards >/tmp/alsainfo/alsacards.tmp lspci |grep -i "multi\|audio">/tmp/alsainfo/lspci.tmp #Check for HDA-Intel cards codec#0 for i in `seq 0 6`; do [[ -e "/proc/asound/card0/codec#$i" ]] && cat "/proc/asound/card0/codec#$i" >> /tmp/alsainfo/alsa-hda-intel.tmp; done #Fetch the info, and put it in $FILE in a nice readable format. echo "name=$USER&type=1&description=/tmp/alsa-info.txt&expiry=&s=Submit+Post&content=" > $FILE echo "###############################" >> $FILE echo "ALSA Information Script v $SCRIPT_VERSION" >> $FILE echo "###############################" >> $FILE echo "" >> $FILE echo "" >> $FILE echo "Linux Distribution" >> $FILE echo "------------------" >> $FILE echo "" >> $FILE echo $DISTRO >> $FILE echo "" >> $FILE echo "" >> $FILE echo "Kernel Information" >> $FILE echo "------------------" >> $FILE echo "" >> $FILE echo "Kernel release: $KERNEL_VERSION" >> $FILE echo "Operating System: $KERNEL_OS" >> $FILE echo "Architecture: $KERNEL_MACHINE" >> $FILE echo "Processor: $KERNEL_PROCESSOR" >> $FILE echo "SMP Enabled: $KERNEL_SMP" >> $FILE echo "" >> $FILE echo "" >> $FILE echo "ALSA Version" >> $FILE echo "------------" >> $FILE echo "" >> $FILE echo "Driver version: $ALSA_DRIVER_VERSION" >> $FILE echo "Library version: $ALSA_LIB_VERSION" >> $FILE echo "Utilities version: $ALSA_UTILS_VERSION" >> $FILE echo "" >> $FILE echo "" >> $FILE echo "Loaded ALSA modules" >> $FILE echo "-------------------" >> $FILE echo "" >> $FILE cat /tmp/alsainfo/alsamodules.tmp >> $FILE echo "" >> $FILE echo "" >> $FILE echo "Soundcards recognised by ALSA" >> $FILE echo "-----------------------------" >> $FILE echo "" >> $FILE cat /tmp/alsainfo/alsacards.tmp >> $FILE echo "" >> $FILE echo "" >> $FILE echo "PCI Soundcards installed in the system" >> $FILE echo "--------------------------------------" >> $FILE echo "" >> $FILE cat /tmp/alsainfo/lspci.tmp >> $FILE echo "" >> $FILE echo "" >> $FILE echo "Advanced information - PCI Vendor/Device ID's" >> $FILE echo "---------------------------------------------" >> $FILE echo "" >> $FILE for i in `seq 1 $NUM_CARDS`; do USE_VENDOR_ID=`sed -n "$i"'p' /tmp/alsainfo/vendor_id.tmp` USE_DEVICE_ID=`sed -n "$i"'p' /tmp/alsainfo/device_id.tmp` echo Vendor id: $USE_VENDOR_ID >> $FILE echo Device id: $USE_DEVICE_ID >> $FILE echo -n "Needed module: " >> $FILE grep -i pci:v0000"$USE_VENDOR_ID"d0000"$USE_DEVICE_ID" /lib/modules/$(uname -r)/modules.alias 2>/dev/null|awk {'print $3'} >> $FILE; echo "" >> $FILE echo "" >> $FILE done if [ -e "/tmp/alsainfo/alsa-hda-intel.tmp" ] then echo "HDA Intel PCI Subsystem ID" >> $FILE echo "--------------------------" >> $FILE echo "" >> $FILE lspci -vn |fgrep -A1 0403 >> $FILE echo "" >> $FILE echo "" >> $FILE echo "HDA-Intel Codec information" >> $FILE echo "---------------------------" >> $FILE echo "" >> $FILE cat /tmp/alsainfo/alsa-hda-intel.tmp >> $FILE echo "" >> $FILE echo "" >> $FILE fi if [[ -n "$1" ]] then until [ -z "$1" ] do case "$1" in --debug) echo "Debugging enabled. $FILE and $TEMPDIR will not be deleted" KEEP_FILES="yes" echo "" ;; --with-all) withdevices withconfigs withaplay withamixer ;; --with-aplay) withaplay ;; --with-amixer) withamixer ;; --with-devices) withdevices ;; --with-configs) if [[ -e $HOME/.asoundrc ]] || [[ -e /etc/asound.conf ]] then echo "ALSA configuration files" >> $FILE echo "------------------------" >> $FILE echo "" >> $FILE #Check for ~/.asoundrc if [[ -e $HOME/.asoundrc ]] then echo "User specific config file ($HOME/.asoundrc)" >> $FILE echo "" >> $FILE cat $HOME/.asoundrc >> $FILE echo "" >> $FILE echo "" >> $FILE fi #Check for /etc/asound.conf if [[ -e /etc/asound.conf ]] then echo "System wide config file (/etc/asound.conf)" >> $FILE echo "" >> $FILE cat /etc/asound.conf >> $FILE echo "" >> $FILE echo "" >> $FILE fi else echo "No config files found (--with-configs) , skipping." fi ;; --about) echo "Written/Tested by the following users of #alsa on irc.freenode.net:" echo "" echo " wishie - Original author and developer / Testing" echo " gnubien - Various script ideas / Testing" echo " GrueMaster - HDA Intel specific items / Testing" cleanup exit 0 ;; *) echo "" echo "Available options:" echo " --with-aplay (includes the output of aplay -l)" echo " --with-amixer (includes the output of amixer)" echo " --with-configs (includes the output of ~/.asoundrc and /etc/asound.conf if they exist)" echo " --with-devices (shows the device nodes in /dev/snd/)" echo "" echo " --about (show some information about the script)" echo " --debug (will run the script as normal, but will not delete $FILE)" cleanup exit 0 ;; esac shift 1 done fi #Test that wget is installed, and supports --post-file. Upload $FILE if it does, and prompt user to upload file if it doesnt. if WGET=$(which wget 2>/dev/null| sed 's|^[^/]*||' 2>/dev/null); [[ -n "${WGET}" ]] && [[ -x "${WGET}" ]] && [[ `wget --help |grep post-file` ]] then echo -n "Uploading information to www.pastebin.ca ... " wget -O - --tries=5 --timeout=60 --post-file=/tmp/alsa-info.txt http://pastebin.ca &>/tmp/alsainfo/wget.tmp & #Progess spinner for wget transfer. i=1 sp="/-\|" echo -n ' ' while pgrep wget &>/dev/null do echo -en "\b${sp:i++%${#sp}:1}" done #See if tput is available, and use it if it is. if [[ -n "$TPUT" ]] then FINAL_URL=`tput setaf 1; grep ";http://" /tmp/alsainfo/wget.tmp |sed -n 's/.*\;\(http:\/\/[a-z.]\+\/[0-9]\+\).*/\1/p';tput sgr0` else FINAL_URL=`grep ";http://" /tmp/alsainfo/wget.tmp |sed -n 's/.*\;\(http:\/\/[a-z.]\+\/[0-9]\+\).*/\1/p'` fi #Output the URL of the uploaded file. echo -e "\b Done!" echo "" echo "Your ALSA information is located at $FINAL_URL" echo "Please inform the person helping you." echo "" #We posted the file to pastebin.ca , so we dont need it anymore. delete it. if [ -z $KEEP_FILES ] then rm $FILE fi #We couldnt find a suitable wget, so tell the user to upload manually. else echo "" echo "Could not automatically upload output to http://www.pastebin.ca." echo "Possible reasons are:" echo " 1. Couldnt find 'wget' in your PATH" echo " 2. Your version of wget is less than 1.8.2" echo "" echo "Please manually upload $FILE to http://www.pastebin.ca/upload.php and submit your post." echo "" fi #Clean up the temp files if [ -z $KEEP_FILES ] then cleanup fi