123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- #!/bin/bash
- # Tor Client app for YunoHost
- # Copyright (C) 2015 Emile Morel <emile@bleuchtang.fr>
- # Copyright (C) 2015 Julien Vaubourg <julien@vaubourg.com>
- # Contribute at https://github.com/labriqueinternet/torclient_ynh
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU Affero General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU Affero General Public License for more details.
- #
- # You should have received a copy of the GNU Affero General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- # This is an upgrade?
- upgrade=$([ "${TORCLIENT_UPGRADE}" == 1 ] && echo true || echo false)
- # Retrieve arguments
- domain=${1}
- url_path=${2}
- # Check domain/path availability
- sudo yunohost app checkurl ${domain}${url_path} -a torclient
- if [ ! $? -eq 0 ]; then
- exit 1
- fi
-
- if ! $upgrade; then
- if [ ! -e /tmp/.ynh-hotspot-started ]; then
- echo "WARNING: Hotspot app not installed or not started" >&2
- fi
- fi
- echo 'deb http://deb.torproject.org/torproject.org jessie main' | sudo tee "/etc/apt/sources.list.d/torproject.list"
- sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xee8cbc9e886ddd89
- # Install packages
- packages='tor php5-fpm'
- sudo apt-get update
- DEBIAN_FRONTEND=noninteractive sudo apt-get --assume-yes --force-yes install ${packages}
- if ! $upgrade; then
- # Save arguments
- sudo yunohost app setting torclient service_enabled -v 0
- sudo yunohost app setting torclient wifi_device_id -v -1
- fi
- sudo install -o root -g root -m 0644 ../conf/torrc /etc/tor/torrc.tpl
- sudo install -b -o root -g root -m 0644 ../conf/nginx_torclient.conf "/etc/nginx/conf.d/${domain}.d/torclient.conf"
- sudo install -b -o root -g root -m 0644 ../conf/phpfpm_torclient.conf /etc/php5/fpm/pool.d/torclient.conf
- # Copy web sources
- sudo mkdir -pm 0755 /var/www/torclient/
- sudo cp -a ../sources/* /var/www/torclient/
- sudo chown -R root: /var/www/torclient/
- sudo chmod -R 0644 /var/www/torclient/*
- sudo find /var/www/torclient/ -type d -exec chmod +x {} \;
- # Fix confs
- ## nginx
- sudo sed "s|<TPL:NGINX_LOCATION>|${url_path}|g" -i "/etc/nginx/conf.d/${domain}.d/torclient.conf"
- sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/torclient/|g' -i "/etc/nginx/conf.d/${domain}.d/torclient.conf"
- sudo sed 's|<TPL:PHP_NAME>|torclient|g' -i "/etc/nginx/conf.d/${domain}.d/torclient.conf"
- ## php-fpm
- sudo sed 's|<TPL:PHP_NAME>|torclient|g' -i /etc/php5/fpm/pool.d/torclient.conf
- sudo sed 's|<TPL:PHP_USER>|admin|g' -i /etc/php5/fpm/pool.d/torclient.conf
- sudo sed 's|<TPL:PHP_GROUP>|admins|g' -i /etc/php5/fpm/pool.d/torclient.conf
- sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/torclient/|g' -i /etc/php5/fpm/pool.d/torclient.conf
- sudo sed 's|^;\?\s*max_execution_time.\+|max_execution_time = 600|' -i /etc/php5/fpm/php.ini
- # Fix sources
- sudo sed "s|<TPL:NGINX_LOCATION>|${url_path}|g" -i /var/www/torclient/config.php
- # Copy init script
- sudo install -o root -g root -m 0755 ../conf/ynh-torclient /usr/local/bin/
- sudo install -o root -g root -m 0644 ../conf/ynh-torclient.service /etc/systemd/system/
- # Allow Tor ports in firewall
- sudo yunohost firewall allow --no-upnp UDP 9053
- sudo yunohost firewall allow --no-upnp TCP 9040
- # Set default inits
- # The boot order of these services are important, so they are disabled by default
- # and the ynh-torclient service handles them.
- sudo systemctl disable tor
- sudo systemctl stop tor
- sudo systemctl enable php5-fpm
- sudo systemctl restart php5-fpm
- sudo systemctl reload nginx
- sudo systemctl enable ynh-torclient
- sudo yunohost service add ynh-torclient
- if ! $upgrade; then
- sudo systemctl start ynh-torclient
- echo "WARNING: Tor Client is not started because you need to define an associated wifi hotspot through the web admin" >&2
- fi
- sudo yunohost app ssowatconf
- exit 0
|