c768dd3180479f057087e16994127f69ffedaaa2
[oweals/gnunet.git] / src / dns / test_gnunet_dns.sh
1 #!/bin/bash
2
3 ME=`whoami`
4 if [ "$ME" != "root" ]
5 then
6   echo "This test only works if run as root.  Skipping."
7   exit 0
8 fi
9 if ! which sudo > /dev/null 
10 then
11   echo "This test requires sudo.  Skipping."
12   exit 0
13 fi
14 if [ ! -x `which sudo` ]
15 then
16   echo "This test requires sudo.  Skipping."
17   exit 0
18 fi
19 if ! which nslookup > /dev/null
20 then 
21   echo "This test requires nslookup.  Skipping."
22   exit 0
23 fi
24 if [ ! -x `which nslookup` ]
25 then
26   echo "This test requires nslookup.  Skipping."
27   exit 0
28 fi
29 export PATH=".:$PATH"
30 gnunet-service-dns -c dns.conf &
31 gnunet-dns-redirector -c dns.conf -4 127.0.0.1 &
32 sleep 1
33 # need to run 'nslookup' as 'nobody', as gnunet-service-dns runs as root
34 # and thus 'root' is excepted from DNS interception!
35 LO=`sudo -u nobody nslookup gnunet.org | grep Address | tail -n1`
36 if [ "$LO" != "Address: 127.0.0.1" ]
37 then
38  echo "Fail: got address $LO, wanted 127.0.0.1"
39  ret=1
40 else
41  echo "Test run, with success."
42  ret=0
43 fi
44 kill `jobs -p`
45 exit $ret