hsaddress.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/sh
  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 [ ! -d "$CHUTNEY_PATH" ] || [ ! -x "$CHUTNEY_PATH/chutney" ]; then
  10. # looks like a broken path: use the path to this tool instead
  11. TOOLS_PATH=$(dirname "$0")
  12. CHUTNEY_PATH=$(dirname "$TOOLS_PATH")
  13. export CHUTNEY_PATH
  14. fi
  15. if [ -d "$PWD/$CHUTNEY_PATH" ] && [ -x "$PWD/$CHUTNEY_PATH/chutney" ]; then
  16. # looks like a relative path: make chutney path absolute
  17. export CHUTNEY_PATH="$PWD/$CHUTNEY_PATH"
  18. fi
  19. # Get a working net path
  20. if [ ! -d "$CHUTNEY_DATA_DIR" ]; then
  21. # looks like a broken path: use the chutney path as a base
  22. export CHUTNEY_DATA_DIR="$CHUTNEY_PATH/net"
  23. fi
  24. if [ -d "$PWD/$CHUTNEY_DATA_DIR" ]; then
  25. # looks like a relative path: make chutney path absolute
  26. export CHUTNEY_DATA_DIR="$PWD/$CHUTNEY_DATA_DIR"
  27. fi
  28. NAME=$(basename "$0")
  29. DEST="$CHUTNEY_DATA_DIR/nodes"
  30. TARGET=hidden_service/hostname
  31. usage() {
  32. echo "Usage: $NAME [hs_node]"
  33. exit 1
  34. }
  35. show_address() {
  36. cat "$1"
  37. }
  38. [ -d "$DEST" ] || { echo "$NAME: no nodes available"; exit 1; }
  39. if [ $# -eq 0 ];
  40. then
  41. # support hOLD
  42. for dir in "$DEST"/*h*;
  43. do
  44. FILE="${dir}/$TARGET"
  45. [ -e "$FILE" ] || continue
  46. echo "Node $(basename "$dir"): " | tr -d "\n"
  47. show_address "$FILE"
  48. done
  49. elif [ $# -eq 1 ];
  50. then
  51. [ -d "$DEST/$1" ] || { echo "$NAME: $1 not found"; exit 1; }
  52. # we don't check the name of the HS directory, because tags vary
  53. FILE="$DEST/$1/$TARGET"
  54. [ -e "$FILE" ] || { echo "$NAME: $FILE not found"; exit 1; }
  55. show_address "$FILE"
  56. else
  57. usage
  58. fi