Merge branch 'master' of ssh://gnunet.org/gnunet
[oweals/gnunet.git] / src / gns / test_gns_soa_lookup.sh
1 #!/bin/bash
2 # This file is in the public domain.
3 trap "gnunet-arm -e -c test_gns_lookup.conf" SIGINT
4
5 LOCATION=$(which gnunet-config)
6 if [ -z $LOCATION ]
7 then
8   LOCATION="gnunet-config"
9 fi
10 $LOCATION --version 1> /dev/null
11 if test $? != 0
12 then
13         echo "GNUnet command line tools cannot be found, check environmental variables PATH and GNUNET_PREFIX"
14         exit 77
15 fi
16
17 which timeout &> /dev/null && DO_TIMEOUT="timeout 5"
18
19 rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
20 MY_EGO="myego"
21 TEST_DOMAIN="homepage.$MY_EGO"
22 # some public DNS resolver we can use
23 TEST_IP_GNS2DNS="184.172.157.218"
24 TEST_RECORD_NAME="homepage"
25 TEST_RECORD_GNS2DNS="gnunet.org"
26
27 if ! nslookup $TEST_RECORD_GNS2DNS $TEST_IP_GNS2DNS &> /dev/null
28 then
29   echo "Cannot reach DNS, skipping test"
30   exit 77
31 fi
32
33 gnunet-arm -s -c test_gns_lookup.conf
34 gnunet-identity -C $MY_EGO -c test_gns_lookup.conf
35 gnunet-namestore -p -z $MY_EGO -a -n $TEST_RECORD_NAME -t GNS2DNS -V ${TEST_RECORD_GNS2DNS}@${TEST_IP_GNS2DNS} -e never -c test_gns_lookup.conf
36 RES_SOA=`$DO_TIMEOUT gnunet-gns --raw -u $TEST_DOMAIN -t SOA -c test_gns_lookup.conf`
37 gnunet-namestore -z $MY_EGO -d -n $TEST_RECORD_NAME -t GNS2DNS -V ${TEST_RECORD_GNS2DNS}@${TEST_IP_GNS2DNS} -e never -c test_gns_lookup.conf &> /dev/null
38 gnunet-identity -D $MY_EGO -c test_gns_lookup.conf
39 gnunet-arm -e -c test_gns_lookup.conf
40 rm -rf `gnunet-config -c test_gns_lookup.conf -f -s paths -o GNUNET_TEST_HOME`
41
42 if [ "x$RES_SOA" != "x" ]
43 then
44   echo "PASS: Resolved SOA for $TEST_DOMAIN to $RES_SOA."
45   exit 0
46 else
47   echo "Failed to resolve to proper SOA for $TEST_DOMAIN, got no result."
48   exit 1
49 fi