hsaddress.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. # make chutney path absolute
  10. if [ -d "$PWD/$CHUTNEY_PATH" ]; then
  11. export CHUTNEY_PATH="$PWD/$CHUTNEY_PATH"
  12. elif [ ! -d "$CHUTNEY_PATH" ]; then
  13. export CHUTNEY_PATH="$PWD"
  14. fi
  15. NAME=$(basename "$0")
  16. DEST="$CHUTNEY_PATH/net/nodes"
  17. TARGET=hidden_service/hostname
  18. function usage() {
  19. echo "Usage: $NAME [hs_node]"
  20. exit 1
  21. }
  22. function show_address() {
  23. cat "$1"
  24. }
  25. [ -d "$DEST" ] || { echo "$NAME: no nodes available"; exit 1; }
  26. if [ $# -eq 0 ];
  27. then
  28. # support hOLD
  29. for dir in "$DEST"/*h*;
  30. do
  31. FILE="${dir}/$TARGET"
  32. [ -e "$FILE" ] || continue
  33. echo -n "Node `basename ${dir}`: "
  34. show_address "$FILE"
  35. done
  36. elif [ $# -eq 1 ];
  37. then
  38. [ -d "$DEST/$1" ] || { echo "$NAME: $1 not found"; exit 1; }
  39. # support hOLD
  40. [[ "$1" =~ .*h.* ]] || { echo "$NAME: $1 is not a HS"; exit 1; }
  41. FILE="$DEST/$1/$TARGET"
  42. [ -e "$FILE" ] || { echo "$NAME: $FILE not found"; exit 1; }
  43. show_address "$FILE"
  44. else
  45. usage
  46. fi