#!/bin/bash

#

mkdir /var/run/mpd

chmod 777 /var/run/mpd

touch /var/run/mpd/mpd.pid

chmod 777 /var/run/mpd/mpd.pid

#

#デバイスの数をカウント

no=`aplay -l | grep "カード" | awk '{print $2,$7,$8}' | wc -l`

#ハードウエアNo.にhw:を付加

dev1=`aplay -l | grep "カード" | sed 's/[A-Z]//g' | sed 's/[a-z]//g' | sed 's/デバイス/:/g' |\

awk -F":" '{print $1,$3}' |sed 's/カード /hw:/' |sed 's/ /,/'`

#デバイス名の取得

dev2=`aplay -l | grep "カード" | awk -F":" '{print $2,$3,$4}' | sed 's/ //g'`

echo ""

#------------------------------------------------------------------------------------------#

arr0=($dev1)

arr1=($dev2)

for (( i = 0; i<$no; i++ ))

{

jpn=`echo "${arr0[i]}"`

kpn=`echo "${arr1[i]}"`

#echo "$jpn $kpn"

echo "------------------------------"

#echo "$jpn $kpn" | awk '{print $1}'

echo "$jpn $kpn"

echo "------------------------------"

}

echo ""

echo "Select Dvice"

echo ""

echo "ex: hw:0,0"

echo ""

read adn

#

#------------------------------------------------------------------------------------------#

#設定ファイルを作成

#/etc/mpd-auto.conf

#$adn

sed -e "s|hw:[0-9],[0-9]|$adn|" /etc/mpd.conf > /etc/mpd-auto.conf

#------------------------------------------------------------------------------------------#

com1=`ps aux | grep mpd | grep -v pts | awk '{print $2}' | sed 's/^/kill /g'`

echo "----------mpd stop----------"

echo "$com1"

#

sh -c "$com1"

#

sleep 2

#

echo ""

echo "---------mpd start----------"

/usr/local/bin/mpd /etc/mpd-auto.conf

echo "ps aux | grep mpd"

echo ""

ps aux | grep mpd