hsaddress.sh 1.7 KB

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