freedombone-utils-i2p 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/bin/bash
  2. # _____ _ _
  3. # | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
  4. # | __| _| -_| -_| . | . | | . | . | | -_|
  5. # |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
  6. #
  7. # Freedom in the Cloud
  8. #
  9. # i2p functions
  10. #
  11. # There's a problem with installing this onto mesh images, which is
  12. # that qemu appears to run out of RAM when using yarn to add webpack.
  13. #
  14. # License
  15. # =======
  16. #
  17. # Copyright (C) 2017-2018 Bob Mottram <bob@freedombone.net>
  18. #
  19. # This program is free software: you can redistribute it and/or modify
  20. # it under the terms of the GNU Affero General Public License as published by
  21. # the Free Software Foundation, either version 3 of the License, or
  22. # (at your option) any later version.
  23. #
  24. # This program is distributed in the hope that it will be useful,
  25. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. # GNU Affero General Public License for more details.
  28. #
  29. # You should have received a copy of the GNU Affero General Public License
  30. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  31. I2P_DOMAIN='deb.i2p2.de'
  32. function install_i2p {
  33. if [ ! -d "$INSTALL_DIR" ]; then
  34. mkdir -p "$INSTALL_DIR"
  35. fi
  36. # install the gpg key
  37. cd "$INSTALL_DIR" || exit 346735
  38. if [ -f i2p-debian-repo.key.asc ]; then
  39. rm i2p-debian-repo.key.asc
  40. fi
  41. wget https://geti2p.net/_static/i2p-debian-repo.key.asc
  42. if [ ! -f i2p-debian-repo.key.asc ]; then
  43. echo $'failed to ontain i2p repo gpg key'
  44. exit 7834627345
  45. fi
  46. apt-key add i2p-debian-repo.key.asc
  47. echo "deb https://${I2P_DOMAIN}/ stretch main" > /etc/apt/sources.list.d/i2p.list
  48. echo "deb-src https://${I2P_DOMAIN}/ stretch main" >> /etc/apt/sources.list.d/i2p.list
  49. # i2p needs ipv6 to be enabled
  50. sed -i 's|net.ipv6.conf.all.disable_ipv6.*|net.ipv6.conf.all.disable_ipv6 = 0|g' /etc/sysctl.conf
  51. /sbin/sysctl -p -q
  52. apt-get update
  53. apt-get -yq install i2p i2p-keyring
  54. systemctl restart i2p
  55. }
  56. function remove_i2p {
  57. service i2p stop
  58. apt-get -yq remove i2p-router --purge
  59. apt-get -yq remove i2p --purge
  60. apt-get -yq remove i2p-keyring --purge
  61. apt-get -yq autoremove
  62. # It's assumed here that ipv6 is only needed for i2p
  63. # This might not be true in future
  64. sed -i 's|net.ipv6.conf.all.disable_ipv6.*|net.ipv6.conf.all.disable_ipv6 = 1|g' /etc/sysctl.conf
  65. /sbin/sysctl -p -q
  66. if [ -d /var/lib/i2p ]; then
  67. rm -rf /var/lib/i2p
  68. fi
  69. if [ -d /etc/i2p ]; then
  70. rm -rf /etc/i2p
  71. fi
  72. if [ -d /usr/share/i2p ]; then
  73. rm -rf /usr/share/i2p
  74. fi
  75. if [ -d /var/log/i2p ]; then
  76. rm /var/log/i2p
  77. fi
  78. rm -rf /tmp/i2p*
  79. rm /etc/apt/sources.list.d/i2p.list
  80. }
  81. function i2p_enable_sam {
  82. if [ ! -f /var/lib/i2p/i2p-config/clients.config ]; then
  83. service i2p stop
  84. apt-get -yq remove i2p i2p-keyring --purge
  85. apt-get -yq remove i2p-router --purge
  86. if [ -d /var/lib/i2p ]; then
  87. rm -rf /var/lib/i2p
  88. fi
  89. if [ -d /etc/i2p ]; then
  90. rm -rf /etc/i2p
  91. fi
  92. if [ -d /usr/share/i2p ]; then
  93. rm -rf /usr/share/i2p
  94. fi
  95. if [ -d /var/log/i2p ]; then
  96. rm /var/log/i2p
  97. fi
  98. rm -rf /tmp/i2p*
  99. apt-get -yq install i2p i2p-keyring
  100. apt-get -yq install i2p-router --reinstall
  101. systemctl restart i2p
  102. sleep 10
  103. fi
  104. if [ ! -f /var/lib/i2p/i2p-config/clients.config ]; then
  105. echo $'File not found /var/lib/i2p/i2p-config/clients.config'
  106. exit 483648364834
  107. fi
  108. sed -i 's|clientApp.1.startOnLoad=.*|clientApp.1.startOnLoad=true|g' /var/lib/i2p/i2p-config/clients.config
  109. systemctl restart i2p
  110. }
  111. # NOTE: deliberately no exit 0