#!/bin/bash

driver_dir_list="fxm8apci fxm16apcie fxm32 tejxapci tej21"

asterisk -rxstop\ now > /dev/null
asterisk -rxcore\ stop\ now > /dev/null

for dr_name in $driver_dir_list
do
	rmmod $dr_name
done

for dr_name in $driver_dir_list
do
	cardorder=0
	cat /tmp/synast_cardlist | while read clline
	do
		drname=`echo $clline | awk -F: '{printf $1}'`
		if [ $drname = $dr_name ];then
			if [ $cardorder -eq 0 ];then
				cardorder=`echo $clline | awk -F: '{printf $2}'`
			else
				cardorder=$cardorder,`echo $clline | awk -F: '{printf $2}'`
			fi
		fi
		echo $cardorder >> /tmp/syncardlist.tmp
	done
	
	cardorder=`sed -n '$p' /tmp/syncardlist.tmp`
	
	if [ $cardorder = "0" ];then
		modprobe $dr_name
	else
		modprobe $dr_name card_list_order=$cardorder
	fi
done

modprobe cdcx522apci

rm -rf /tmp/syncardlist.tmp

if [ -d /proc/dahdi ];then
dahdi_cfg -vv
elif [ -d /proc/zaptel ];then
ztcfg -vv
fi
asterisk

