install 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. # Check domain/path availability
  25. sudo yunohost app checkurl ${domain}${url_path} -a torclient
  26. if [ ! $? -eq 0 ]; then
  27. exit 1
  28. fi
  29. if ! $upgrade; then
  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. sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xee8cbc9e886ddd89
  36. # Install packages
  37. packages='tor php5-fpm'
  38. sudo apt-get update
  39. DEBIAN_FRONTEND=noninteractive sudo apt-get --assume-yes --force-yes install ${packages}
  40. if ! $upgrade; then
  41. # Save arguments
  42. sudo yunohost app setting torclient service_enabled -v 0
  43. sudo yunohost app setting torclient wifi_device_id -v -1
  44. fi
  45. sudo install -o root -g root -m 0644 ../conf/torrc /etc/tor/torrc.tpl
  46. sudo install -b -o root -g root -m 0644 ../conf/nginx_torclient.conf "/etc/nginx/conf.d/${domain}.d/torclient.conf"
  47. sudo install -b -o root -g root -m 0644 ../conf/phpfpm_torclient.conf /etc/php5/fpm/pool.d/torclient.conf
  48. # Copy web sources
  49. sudo mkdir -pm 0755 /var/www/torclient/
  50. sudo cp -a ../sources/* /var/www/torclient/
  51. sudo chown -R root: /var/www/torclient/
  52. sudo chmod -R 0644 /var/www/torclient/*
  53. sudo find /var/www/torclient/ -type d -exec chmod +x {} \;
  54. # Fix confs
  55. ## nginx
  56. sudo sed "s|<TPL:NGINX_LOCATION>|${url_path}|g" -i "/etc/nginx/conf.d/${domain}.d/torclient.conf"
  57. sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/torclient/|g' -i "/etc/nginx/conf.d/${domain}.d/torclient.conf"
  58. sudo sed 's|<TPL:PHP_NAME>|torclient|g' -i "/etc/nginx/conf.d/${domain}.d/torclient.conf"
  59. ## php-fpm
  60. sudo sed 's|<TPL:PHP_NAME>|torclient|g' -i /etc/php5/fpm/pool.d/torclient.conf
  61. sudo sed 's|<TPL:PHP_USER>|admin|g' -i /etc/php5/fpm/pool.d/torclient.conf
  62. sudo sed 's|<TPL:PHP_GROUP>|admins|g' -i /etc/php5/fpm/pool.d/torclient.conf
  63. sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/torclient/|g' -i /etc/php5/fpm/pool.d/torclient.conf
  64. sudo sed 's|^;\?\s*max_execution_time.\+|max_execution_time = 600|' -i /etc/php5/fpm/php.ini
  65. # Fix sources
  66. sudo sed "s|<TPL:NGINX_LOCATION>|${url_path}|g" -i /var/www/torclient/config.php
  67. # Copy init script
  68. sudo install -o root -g root -m 0755 ../conf/ynh-torclient /usr/local/bin/
  69. sudo install -o root -g root -m 0644 ../conf/ynh-torclient.service /etc/systemd/system/
  70. # Allow Tor ports in firewall
  71. sudo yunohost firewall allow --no-upnp UDP 9053
  72. sudo yunohost firewall allow --no-upnp TCP 9040
  73. # Set default inits
  74. # The boot order of these services are important, so they are disabled by default
  75. # and the ynh-torclient service handles them.
  76. sudo systemctl disable tor
  77. sudo systemctl stop tor
  78. sudo systemctl enable php5-fpm
  79. sudo systemctl restart php5-fpm
  80. sudo systemctl reload nginx
  81. sudo systemctl enable ynh-torclient
  82. sudo yunohost service add ynh-torclient
  83. if ! $upgrade; then
  84. sudo systemctl start ynh-torclient
  85. echo "WARNING: Tor Client is not started because you need to define an associated wifi hotspot through the web admin" >&2
  86. fi
  87. sudo yunohost app ssowatconf
  88. exit 0