netcon_entrypoint.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/bash
  2. export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/
  3. # --- Test Parameters ---
  4. test_namefile=$(ls *.name)
  5. test_name="${test_namefile%.*}" # test network id
  6. nwconf=$(ls *.conf) # blank test network config file
  7. nwid="${nwconf%.*}" # test network id
  8. file_path=/opt/results/ # test result output file path (fs shared between host and containers)
  9. file_base="$test_name".txt # test result output file
  10. tmp_ext=.tmp # temporary filetype used for sharing test data between containers
  11. address_file="$file_path$test_name"_addr"$tmp_ext" # file shared between host and containers for sharing address (optional)
  12. bigfile_name=bigfile
  13. bigfile_size=10M # size of file we want to use for the test
  14. tx_md5sumfile="$file_path"tx_"$bigfile_name"_md5sum"$tmp_ext"
  15. # --- Network Config ---
  16. echo '*** ZeroTier Network Containers Test: ' "$test_name"
  17. chown -R daemon /var/lib/zerotier-one
  18. chgrp -R daemon /var/lib/zerotier-one
  19. su daemon -s /bin/bash -c '/zerotier-netcon-service -d -U -p9993 >>/tmp/zerotier-netcon-service.out 2>&1'
  20. virtip4=""
  21. while [ -z "$virtip4" ]; do
  22. sleep 0.2
  23. virtip4=`/zerotier-cli listnetworks | grep -F $nwid | cut -d ' ' -f 9 | sed 's/,/\n/g' | grep -F '.' | cut -d / -f 1`
  24. dev=`/zerotier-cli listnetworks | grep -F "" | cut -d ' ' -f 8 | cut -d "_" -f 2 | sed "s/^<dev>//" | tr '\n' '\0'`
  25. done
  26. echo '--- Up and running at' $virtip4 ' on network: ' $nwid
  27. echo '*** Writing address to ' "$address_file"
  28. echo $virtip4 > "$address_file"
  29. # --- Test section ---
  30. # Generate large random file for transfer test, share md5sum for monitor container to check
  31. echo '*** Generating ' "$bigfile_size" ' file'
  32. dd if=/dev/urandom of=/var/www/html/"$bigfile_name" bs="$bigfile_size" count=1
  33. md5sum < /var/www/html/"$bigfile_name" > "$tx_md5sumfile"
  34. echo '*** Wrote MD5 sum to ' "$tx_md5sumfile"
  35. echo '*** Starting application...'
  36. sleep 0.5
  37. rm -rf /run/httpd/* /tmp/httpd*
  38. export ZT_NC_NETWORK=/var/lib/zerotier-one/nc_"$dev"
  39. export LD_PRELOAD=./libzerotierintercept.so
  40. /usr/sbin/httpd -X