All pastes #1247258 Raw Edit

natfix.sh

public text v1 · immutable
#1247258 ·published 2008-11-06 20:48 UTC
rendered paste body
#!/bin/bash

##############################################################################################
#
# Script to setup sip_nat.conf
#
# Released under GPL
#
# v1.0 - 05/11/2008 - Neil Stone - nstone@freewayprojects.com - initial write
# v1.1 - 05/11/2008 - Neil Stone - nstone@freewayprojects.com - distro checking
#
# Thanks to n3glv for the incentive and the wife for keeping out of my hair while I wrote it
#
##############################################################################################

if [ -x /usr/bin/apt-get ]
then
	DISTRO=debian
else
	if [ -x /usr/bin/emerge ]
	then
		DISTRO=gentoo
	else
		if [ -x /usr/bin/yum ]
		then
			DISTRO=centos
		fi
	fi
fi

echo Distro = $DISTRO
echo

if [ ! -x /sbin/ip ]
then
        echo \'ip\' needed.. installing

	if [ $DISTRO=debian ]
	then
		apt-get install iproute
	else
		if [ $DISTRO=gentoo ]
		then
			emerge iproute
		else
			if [ $DISTRO=centos ]
			then
				yum install iproute
			else
				echo Distro not detected, please install the \'iproute\' package
				exit 1
			fi
		fi
	fi

#        echo yum install -y iproute
else
        echo \'ip\' there already
fi

echo Determining externip...
EXTERNIP=`wget www.whatismyip.com/automation/n09230945.asp -O - -o /dev/null`
echo $EXTERNIP
echo

echo Determining localnet...
LOCALNET=`/sbin/ip route | grep src | cut -f 1 -d\ `
echo $LOCALNET
echo

echo Outputting file...
echo

cat << EOF > /etc/asterisk/sip_nat.conf
nat=yes
externip=$EXTERNIP
localnet=$LOCALNET
EOF

echo Restarting amportal...
echo
amportal restart

echo Done...
echo

exit 0