freedombone-mesh-visit-site 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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=iceweasel
  34. IPFS_USERS_FILE=/home/$USER/.ipfs-users
  35. if [ ! -f $IPFS_USERS_FILE ]; then
  36. exit 0
  37. fi
  38. USERS_FILE=/home/$USER/Users.txt
  39. if [ ! -f $USERS_FILE ]; then
  40. exit 0
  41. fi
  42. data=$(tempfile 2>/dev/null)
  43. trap "rm -f $data" 0 1 2 5 15
  44. dialog --title $"Visit IPFS site" \
  45. --backtitle $"Freedombone mesh" \
  46. --inputbox $"Enter the username for the site you wish to visit" 8 60 2>$data
  47. sel=$?
  48. case $sel in
  49. 0)
  50. TOX_USERNAME=$(<$data)
  51. if [ ${#TOX_USERNAME} -gt 0 ]; then
  52. if ! grep -q "$TOX_USERNAME" $USERS_FILE; then
  53. dialog --title $"Visit IPFS site" \
  54. --backtitle $"Freedombone mesh" \
  55. --msgbox $"The user '$TOX_USERNAME' was not found on the mesh" 8 60
  56. exit 2
  57. fi
  58. TOX_ID=$(cat "$USERS_FILE" | grep "$TOX_USERNAME" | head -n 1 | awk -F ' ' '{print $2}')
  59. if ! grep -q "$TOX_ID" $IPFS_USERS_FILE; then
  60. dialog --title $"Visit IPFS site" \
  61. --backtitle $"Freedombone mesh" \
  62. --msgbox $"An IPFS site was not found for the user '$TOX_USERNAME'" 8 60
  63. exit 3
  64. fi
  65. IPFS_FULL_URL=${IPFS_URL}/$(cat "$IPFS_USERS_FILE" | grep $TOX_ID | head -n 1 | awk -F ':' '{print $2}')
  66. $BROWSER $IPFS_FULL_URL
  67. else
  68. exit 1
  69. fi
  70. ;;
  71. esac
  72. exit 0