hsaddress.sh 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. for dir in $DEST/*h;
  26. do
  27. FILE=${dir}/$TARGET
  28. [ -e $FILE ] || continue
  29. echo -n "Node `basename ${dir}`: "
  30. show_address $FILE
  31. done
  32. elif [ $# -eq 1 ];
  33. then
  34. [ -d $DEST/$1 ] || { echo "$NAME: $1 not found"; exit 1; }
  35. [[ $1 =~ .*h$ ]] || { echo "$NAME: $1 is not a HS"; exit 1; }
  36. FILE=$DEST/$1/$TARGET
  37. [ -e $FILE ] || { echo "$NAME: $FILE not found"; exit 1; }
  38. show_address $FILE
  39. else
  40. usage
  41. fi