first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / scripts / clam / sound_play.sh
1 #!/bin/bash
2
3 # play the sound files specified.
4
5 # locates a process given a search pattern to match in the process list.
6 # copied from functions.h in yeti to avoid intermixing dependencies.
7 function psfind {
8   mkdir -p "$TEMPORARIES_DIR"
9   PID_DUMP="$(mktemp "$TEMPORARIES_DIR/zz_pidlist.XXXXXX")"
10   appropriate_pattern='s/^[-a-zA-Z_0-9][-a-zA-Z_0-9]*  *\([0-9][0-9]*\).*$/\1/p'
11     # pattern to use for peeling off the process numbers.
12   extra_flags=
13     # flags to pass to ps if any special ones are needed.
14   if [ "$OS" = "Windows_NT" ]; then
15     # on win32, there is some weirdness to support msys.
16     appropriate_pattern='s/^[   ]*\([0-9][0-9]*\).*$/\1/p'
17     extra_flags=-W
18   fi
19   /bin/ps $extra_flags wuax >$PID_DUMP
20   # remove the first line of the file, search for the pattern the
21   # user wants to find, and just pluck the process ids out of the
22   # results.
23   PIDS_SOUGHT=$(cat $PID_DUMP \
24     | sed -e '1d' \
25     | grep -i "$1" \
26     | sed -n -e "$appropriate_pattern")
27   if [ ! -z "$PIDS_SOUGHT" ]; then echo "$PIDS_SOUGHT"; fi
28   /bin/rm $PID_DUMP
29 }
30
31 if [ $# -lt 1 ]; then
32   #echo no sound file specified.
33   exit 0;
34 fi
35
36 export PLAYCMD=/usr/bin/play
37 if [ ! -f "$PLAYCMD" ]; then
38   PLAYCMD=echo
39 fi
40
41 if [ ! -z "$(psfind pulseaudio)" ]; then
42   # we see artsd running...
43   PLAYCMD=aplay
44 elif [ ! -z "$(psfind artsd)" ]; then
45   # we see artsd running...
46   PLAYCMD=artsplay
47 elif [ ! -z "$(psfind esd)" ]; then
48   # we see esd running...
49   PLAYCMD=esdplay
50 elif [ ! -z "$WINDIR" ]; then
51   # kludge for win32; we provide our own sound player.
52   PLAYCMD=$CLAM_BIN/playsound
53 fi
54
55 # play the sounds individually; playsound can handle multiple files, but
56 # "play" doesn't want to on some systems.
57 for i in $*; do
58   ($PLAYCMD $i &>/dev/null &);
59 done
60
61 exit 0