install 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #!/bin/bash
  2. # Tor Client app for YunoHost
  3. # Copyright (C) 2015 Emile Morel <emile@bleuchtang.fr>
  4. # Copyright (C) 2015 Julien Vaubourg <julien@vaubourg.com>
  5. # Contribute at https://github.com/labriqueinternet/torclient_ynh
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. # This is an upgrade?
  20. upgrade=$([ "$TORCLIENT_UPGRADE" == 1 ] && echo true || echo false)
  21. # Retrieve arguments
  22. domain=${1}
  23. url_path=${2}
  24. if ! $upgrade; then
  25. # Check domain/path availability
  26. sudo yunohost app checkurl ${domain}${url_path} -a torclient
  27. if [ ! $? -eq 0 ]; then
  28. exit 1
  29. fi
  30. if [ ! -e /tmp/.ynh-hotspot-started ]; then
  31. echo "WARNING: Hotspot app not installed or not started" >&2
  32. fi
  33. fi
  34. echo 'deb http://deb.torproject.org/torproject.org jessie main' | sudo tee "/etc/apt/sources.list.d/torproject.list"
  35. gpg --keyserver keys.gnupg.net --recv 886DDD89
  36. gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | sudo apt-key add -
  37. # Install packages
  38. packages='tor php5-fpm'
  39. sudo apt-get update
  40. DEBIAN_FRONTEND=noninteractive sudo apt-get --assume-yes --force-yes install ${packages}
  41. if ! $upgrade; then
  42. # Save arguments
  43. sudo yunohost app setting torclient service_enabled -v 0
  44. sudo yunohost app setting torclient wifi_device_id -v -1
  45. fi
  46. sudo install -o root -g root -m 0644 ../conf/torrc /etc/tor/torrc.tpl
  47. sudo install -b -o root -g root -m 0644 ../conf/nginx_torclient.conf "/etc/nginx/conf.d/${domain}.d/torclient.conf"
  48. sudo install -b -o root -g root -m 0644 ../conf/phpfpm_torclient.conf /etc/php5/fpm/pool.d/torclient.conf
  49. # Copy web sources
  50. sudo mkdir -pm 0755 /var/www/torclient/
  51. sudo cp -a ../sources/* /var/www/torclient/
  52. sudo chown -R root: /var/www/torclient/
  53. sudo chmod -R 0644 /var/www/torclient/*
  54. sudo find /var/www/torclient/ -type d -exec chmod +x {} \;
  55. # Fix confs
  56. ## nginx
  57. sudo sed "s|<TPL:NGINX_LOCATION>|${url_path}|g" -i "/etc/nginx/conf.d/${domain}.d/torclient.conf"
  58. sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/torclient/|g' -i "/etc/nginx/conf.d/${domain}.d/torclient.conf"
  59. sudo sed 's|<TPL:PHP_NAME>|torclient|g' -i "/etc/nginx/conf.d/${domain}.d/torclient.conf"
  60. ## php-fpm
  61. sudo sed 's|<TPL:PHP_NAME>|torclient|g' -i /etc/php5/fpm/pool.d/torclient.conf
  62. sudo sed 's|<TPL:PHP_USER>|admin|g' -i /etc/php5/fpm/pool.d/torclient.conf
  63. sudo sed 's|<TPL:PHP_GROUP>|admins|g' -i /etc/php5/fpm/pool.d/torclient.conf
  64. sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/torclient/|g' -i /etc/php5/fpm/pool.d/torclient.conf
  65. sudo sed 's|^;\?\s*max_execution_time.\+|max_execution_time = 600|' -i /etc/php5/fpm/php.ini
  66. # Fix sources
  67. sudo sed "s|<TPL:NGINX_LOCATION>|${url_path}|g" -i /var/www/torclient/config.php
  68. # Copy init script
  69. sudo install -o root -g root -m 0755 ../conf/ynh-torclient /usr/local/bin/
  70. sudo install -o root -g root -m 0644 ../conf/ynh-torclient.service /etc/systemd/system/
  71. # Allow Tor ports in firewall
  72. sudo yunohost firewall allow --no-upnp UDP 9053
  73. sudo yunohost firewall allow --no-upnp TCP 9040
  74. # Set default inits
  75. # The boot order of these services are important, so they are disabled by default
  76. # and the ynh-torclient service handles them.
  77. sudo systemctl disable tor
  78. sudo systemctl stop tor
  79. sudo systemctl enable php5-fpm
  80. sudo systemctl restart php5-fpm
  81. sudo systemctl reload nginx
  82. sudo systemctl enable ynh-torclient
  83. sudo yunohost service add ynh-torclient
  84. if ! $upgrade; then
  85. sudo systemctl start ynh-torclient
  86. echo "WARNING: Tor Client is not started because you need to define an associated wifi hotspot through the web admin" >&2
  87. fi
  88. sudo yunohost app ssowatconf
  89. exit 0