fastdstart.sh: diet, too

Signed-off-by: Tim Niemeyer <tim.niemeyer@mastersword.de>
This commit is contained in:
Tim Niemeyer 2013-02-03 17:50:35 +01:00
parent 0f57b3662a
commit 2325990415

View File

@ -1,106 +1,84 @@
#!/bin/sh #!/bin/sh
SERVER="no" SERVER="no"
SERVERNAME="batgw" #SERVERNAME="--servername--"
project="ffol" project="ffol"
test_internet_host1="mastersword.de" test_internet_host1="mastersword.de"
test_internet_host2="78.46.215.78" test_internet_host2="109.163.229.254"
#Only do something with fastd when the router has internet connection #Only do something with fastd when the router has internet connection
if ping -w5 -c3 "$test_internet_host1" &>/dev/null || ping -w5 -c3 "$test_internet_host2" &>/dev/null if ping -w5 -c3 "$test_internet_host1" &>/dev/null || ping -w5 -c3 "$test_internet_host2" &>/dev/null; then
then if [ "$SERVER" == "no" ]; then
hostname=$(cat /proc/sys/kernel/hostname)
if [ "$SERVER" == "no" ] if [ "$hostname" == "OpenWrt" ]; then
then hostname=""
hostname=$(cat /proc/sys/kernel/hostname) fi
if [ "$hostname" == "OpenWrt" ] if [ "$hostname" == "" ]; then
then hostname=$(awk '{ if (mac) next; mac=toupper($1); gsub(":", "", mac); print mac }' /sys/class/net/br-mesh/address /sys/class/net/eth0/address /sys/class/net/ath0/address 2>/dev/null)
hostname="" fi
fi else
hostname=$SERVERNAME
fi
if [ "$hostname" == "" ] if [ ! -d /etc/fastd ]; then
then mkdir /etc/fastd
hostname=$(ifconfig br-mesh | grep HWaddr | awk '{ print $5 }'|sed -e 's/://g') fi
fi
if [ "$hostname" == "" ] if [ ! -d /etc/fastd/$project ]; then
then mkdir /etc/fastd/$project
hostname=$(ifconfig eth0 | grep HWaddr | awk '{ print $5 }'|sed -e 's/://g')
fi
if [ "$hostname" == "" ] mkdir /tmp/fastd_${project}_peers
then ln -s /tmp/fastd_${project}_peers /etc/fastd/$project/peers
hostname=$(ifconfig ath0 | grep HWaddr | awk '{ print $5 }'|sed -e 's/://g') echo '#!/bin/sh' > /etc/fastd/$project/up.sh
fi echo 'ip link set up dev $1' >> /etc/fastd/$project/up.sh
else
hostname=$SERVERNAME if [ "$SERVER" == "no" ]; then
fi echo 'batctl if add $1' >> /etc/fastd/$project/up.sh
secret=$(fastd --generate-key 2>&1 | grep -i secret | awk '{ print $2 }')
echo "" >> /etc/config/fastd
echo "config fastd $project" >> /etc/config/fastd
echo " option enabled 1" >> /etc/config/fastd
echo " list config_peer_dir '/etc/fastd/$project/peers'" >> /etc/config/fastd
echo " option syslog_level 'verbose'" >> /etc/config/fastd
echo " option method null" >> /etc/config/fastd
echo " option mode 'tap'" >> /etc/config/fastd
echo " option bind '0.0.0.0:10000'" >> /etc/config/fastd
echo " option interface '${project}VPN'" >> /etc/config/fastd
echo " option mtu 1426" >> /etc/config/fastd
echo " option secret '$secret'" >> /etc/config/fastd
echo " option up '/etc/fastd/${project}/up.sh \$1'" >> /etc/config/fastd
fi
chmod +x /etc/fastd/$project/up.sh
fi
if [ ! -d /etc/fastd ] if [ ! -d /tmp/fastd_${project}_peers ]; then
then mkdir /tmp/fastd_${project}_peers
mkdir /etc/fastd fi
fi
if [ ! -d /etc/fastd/$project ] pubkey=$(/etc/init.d/fastd show_key $project)
then #port=666
mkdir /etc/fastd/$project
mkdir /tmp/fastd_${project}_peers
ln -s /tmp/fastd_${project}_peers /etc/fastd/$project/peers
echo '#!/bin/sh' > /etc/fastd/$project/up.sh
echo 'ip link set up dev $1' >> /etc/fastd/$project/up.sh
if [ "$SERVER" == "no" ]
then
echo 'batctl if add $1' >> /etc/fastd/$project/up.sh
secret=$(fastd --generate-key 2>&1 | grep -i secret | awk '{ print $2 }')
echo "" >> /etc/config/fastd
echo " config fastd $project" >> /etc/config/fastd
echo " option enabled 1" >> /etc/config/fastd
echo " list config_peer_dir '/etc/fastd/$project/peers'" >> /etc/config/fastd
echo " option syslog_level 'verbose'" >> /etc/config/fastd
echo " option method null" >> /etc/config/fastd
echo " option mode 'tap'" >> /etc/config/fastd
echo " option bind '0.0.0.0:10000'" >> /etc/config/fastd
echo " option interface '${project}VPN'" >> /etc/config/fastd
echo " option mtu 1426" >> /etc/config/fastd
echo " option secret '$secret'" >> /etc/config/fastd
echo " option up '/etc/fastd/${project}/up.sh \$1'" >> /etc/config/fastd
fi
chmod +x /etc/fastd/$project/up.sh
fi
if [ ! -d /tmp/fastd_${project}_peers ]
then
mkdir /tmp/fastd_${project}_peers
fi
pubkey=$(/etc/init.d/fastd show_key $project)
#port=666
# fire up # fire up
if [ "$(/sbin/ifconfig -a | grep -i ethernet | grep $project)" == "" ] if [ "$(/sbin/ifconfig -a | grep -i ethernet | grep $project)" == "" ]; then
then /etc/init.d/fastd start $project
/etc/init.d/fastd start $project fi
fi
# register # register
wget -T15 "http://mastersword.de/~reddog/fastd/?name=$hostname&port=$port&key=$pubkey" -O /tmp/fastd_${project}_output wget -T15 "http://mastersword.de/~reddog/fastd/?name=$hostname&port=$port&key=$pubkey" -O /tmp/fastd_${project}_output
filenames=$(cat /tmp/fastd_${project}_output| grep ^#### | sed -e 's/^####//' | sed -e 's/.conf//g') filenames=$(awk '/^####/ { gsub(/^####/, "", $0); gsub(/.conf/, "", $0); print $0; }' /tmp/fastd_${project}_output)
for file in $filenames for file in $filenames; do
do awk "{ if(a) print }; /^####$file.conf$/{a=1}; /^$/{a=0};" /tmp/fastd_fff_output > /etc/fastd/$project/peers/$file
grep -A100 ^####$file.conf$ /tmp/fastd_${project}_output | grep -v ^####$file.conf$ | grep -m1 ^### -B100 | grep -v ^### > /etc/fastd/$project/peers/$file done
done
#reload
kill -HUP $(cat /var/run/fastd.$project.pid)
#reload
kill -HUP $(cat /var/run/fastd.$project.pid)
else else
echo "Der Router kann keine Verbindung zum Fastdserver aufbauen" echo "Der Router kann keine Verbindung zum Fastdserver aufbauen"
echo "$0 macht nichts!" echo "$0 macht nichts!"