hsaddress.sh 1.1 KB

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