freedombone-mesh-visit-site 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Visit ipfs sites by entering a username
  12. #
  13. # License
  14. # =======
  15. #
  16. # This program is free software: you can redistribute it and/or modify
  17. # it under the terms of the GNU Affero General Public License as published by
  18. # the Free Software Foundation, either version 3 of the License, or
  19. # (at your option) any later version.
  20. #
  21. # This program is distributed in the hope that it will be useful,
  22. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. # GNU Affero General Public License for more details.
  25. #
  26. # You should have received a copy of the GNU Affero General Public License
  27. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. PROJECT_NAME='freedombone'
  29. export TEXTDOMAIN=${PROJECT_NAME}-mesh-visit-site
  30. export TEXTDOMAINDIR="/usr/share/locale"
  31. IPFS_URL='http://127.0.0.1:8080/ipns'
  32. # The browser application to use
  33. BROWSER=midori
  34. BROWSER_OPTIONS='-p'
  35. # An optional suffix to be appended to the URL
  36. SUFFIX=$1
  37. IPFS_USERS_FILE=/tmp/.ipfs-users
  38. if [ ! -f $IPFS_USERS_FILE ]; then
  39. exit 0
  40. fi
  41. USERS_FILE=/tmp/Users.txt
  42. if [ ! -f $USERS_FILE ]; then
  43. exit 0
  44. fi
  45. data=$(tempfile 2>/dev/null)
  46. trap "rm -f $data" 0 1 2 5 15
  47. dialog --title $"Visit IPFS site" \
  48. --backtitle $"Freedombone mesh" \
  49. --inputbox $"Enter the username or Tox ID for the site you wish to visit" 8 70 2>$data
  50. sel=$?
  51. case $sel in
  52. 0)
  53. TOX_USERNAME_OR_ID=$(<$data)
  54. if [ ${#TOX_USERNAME_OR_ID} -gt 0 ]; then
  55. if ! grep -q "$TOX_USERNAME_OR_ID" $USERS_FILE; then
  56. TOX_ID="$TOX_USERNAME_OR_ID"
  57. else
  58. TOX_ID=$(cat "$USERS_FILE" | grep "$TOX_USERNAME_OR_ID" | head -n 1 | sed "s|$TOX_USERNAME_OR_ID ||g" | sed -e 's/^[[:space:]]*//')
  59. fi
  60. if [ ${#TOX_ID} -gt 5 ]; then
  61. if ! grep -q "$TOX_ID" $IPFS_USERS_FILE; then
  62. dialog --title $"Visit IPFS site" \
  63. --backtitle $"Freedombone mesh" \
  64. --msgbox $"An IPFS site was not found for the user '$TOX_USERNAME_OR_ID'" 8 60
  65. exit 3
  66. fi
  67. IPFS_FULL_URL=${IPFS_URL}/$(cat "$IPFS_USERS_FILE" | grep $TOX_ID | head -n 1 | awk -F ':' '{print $2}')
  68. clear
  69. echo $'Opening browser. Please wait...'
  70. pkill $BROWSER
  71. setsid sh -c "$BROWSER $BROWSER_OPTIONS $IPFS_FULL_URL$SUFFIX" > /dev/null 2>&1 < /dev/null &
  72. # Need to wait a while for the browser to begin opening
  73. sleep 3
  74. fi
  75. else
  76. exit 1
  77. fi
  78. ;;
  79. esac
  80. exit 0