install 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. 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. # Save git commit
  46. gitcommit=$(git rev-parse HEAD)
  47. sudo yunohost app setting torclient gitcommit -v "${gitcommit}"
  48. sudo install -o root -g root -m 0644 ../conf/torrc /etc/tor/torrc.tpl
  49. sudo install -b -o root -g root -m 0644 ../conf/nginx_torclient.conf "/etc/nginx/conf.d/${domain}.d/torclient.conf"
  50. sudo install -b -o root -g root -m 0644 ../conf/phpfpm_torclient.conf /etc/php5/fpm/pool.d/torclient.conf
  51. # Copy web sources
  52. sudo mkdir -pm 0755 /var/www/torclient/
  53. sudo cp -a ../sources/* /var/www/torclient/
  54. sudo chown -R root: /var/www/torclient/
  55. sudo chmod -R 0644 /var/www/torclient/*
  56. sudo find /var/www/torclient/ -type d -exec chmod +x {} \;
  57. # Fix confs
  58. ## nginx
  59. sudo sed "s|<TPL:NGINX_LOCATION>|${url_path}|g" -i "/etc/nginx/conf.d/${domain}.d/torclient.conf"
  60. sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/torclient/|g' -i "/etc/nginx/conf.d/${domain}.d/torclient.conf"
  61. sudo sed 's|<TPL:PHP_NAME>|torclient|g' -i "/etc/nginx/conf.d/${domain}.d/torclient.conf"
  62. ## php-fpm
  63. sudo sed 's|<TPL:PHP_NAME>|torclient|g' -i /etc/php5/fpm/pool.d/torclient.conf
  64. sudo sed 's|<TPL:PHP_USER>|admin|g' -i /etc/php5/fpm/pool.d/torclient.conf
  65. sudo sed 's|<TPL:PHP_GROUP>|admins|g' -i /etc/php5/fpm/pool.d/torclient.conf
  66. sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/torclient/|g' -i /etc/php5/fpm/pool.d/torclient.conf
  67. sudo sed 's|^;\?\s*max_execution_time.\+|max_execution_time = 600|' -i /etc/php5/fpm/php.ini
  68. # Fix sources
  69. sudo sed "s|<TPL:NGINX_LOCATION>|${url_path}|g" -i /var/www/torclient/config.php
  70. # Copy init script
  71. sudo install -o root -g root -m 0755 ../conf/ynh-torclient /usr/local/bin/
  72. sudo install -o root -g root -m 0644 ../conf/ynh-torclient.service /etc/systemd/system/
  73. # Allow Tor ports in firewall
  74. sudo yunohost firewall allow --no-upnp UDP 9053
  75. sudo yunohost firewall allow --no-upnp TCP 9040
  76. # Set default inits
  77. # The boot order of these services are important, so they are disabled by default
  78. # and the ynh-torclient service handles them.
  79. sudo systemctl disable tor
  80. sudo systemctl stop tor
  81. sudo systemctl enable php5-fpm
  82. sudo systemctl restart php5-fpm
  83. sudo systemctl reload nginx
  84. sudo systemctl enable ynh-torclient
  85. sudo yunohost service add ynh-torclient
  86. if ! $upgrade; then
  87. sudo systemctl start ynh-torclient
  88. echo "WARNING: Tor Client is not started because you need to define an associated wifi hotspot through the web admin" >&2
  89. fi
  90. sudo yunohost app ssowatconf
  91. exit 0