hsaddress.sh 1006 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/bin/bash
  2. #
  3. # Usage:
  4. # cd YOUR-CHUTNEY-DIRECTORY
  5. # tools/hsaddress.sh [hs_node]
  6. # Output: for each HS outputs its onion address. If the argument node is
  7. # specified, it only shows the onion address of that node.
  8. # Examples: tools/hsaddress.sh
  9. # tools/hsaddress.sh 025h
  10. NAME=$(basename "$0")
  11. DEST=net/nodes
  12. TARGET=hidden_service/hostname
  13. function usage() {
  14. echo "Usage: $NAME [hs_node]"
  15. exit 1
  16. }
  17. function show_address() {
  18. cat $1
  19. }
  20. [ -d $DEST ] || { echo "$NAME: no nodes available"; exit 1; }
  21. if [ $# -eq 0 ];
  22. then
  23. for dir in $DEST/*h;
  24. do
  25. FILE=${dir}/$TARGET
  26. [ -e $FILE ] || continue
  27. echo -n "Node `basename ${dir}`: "
  28. show_address $FILE
  29. done
  30. elif [ $# -eq 1 ];
  31. then
  32. [ -d $DEST/$1 ] || { echo "$NAME: $1 not found"; exit 1; }
  33. [[ $1 =~ .*h$ ]] || { echo "$NAME: $1 is not a HS"; exit 1; }
  34. FILE=$DEST/$1/$TARGET
  35. [ -e $FILE ] || { echo "$NAME: $FILE not found"; exit 1; }
  36. show_address $FILE
  37. else
  38. usage
  39. fi