152 lines
5.3 KiB
Bash
152 lines
5.3 KiB
Bash
#!/bin/bash
|
|
|
|
# VPN Client app for YunoHost
|
|
# Copyright (C) 2015 Julien Vaubourg <julien@vaubourg.com>
|
|
# Contribute at https://github.com/labriqueinternet/vpnclient_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=$([ "${VPNCLIENT_UPGRADE}" == 1 ] && echo true || echo false)
|
|
|
|
# Retrieve arguments
|
|
domain=${1}
|
|
url_path=${2}
|
|
|
|
if ! $upgrade; then
|
|
|
|
source ./prerequisites
|
|
|
|
# Check domain/path availability
|
|
sudo yunohost app checkurl ${domain}${url_path} -a vpnclient
|
|
if [ ! $? -eq 0 ]; then
|
|
exit 1
|
|
fi
|
|
|
|
fi
|
|
|
|
# Install packages
|
|
packages='php5-fpm sipcalc dnsutils openvpn curl'
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
|
|
sudo apt-get --assume-yes --force-yes install ${packages}
|
|
|
|
if [ $? -ne 0 ]; then
|
|
sudo apt-get update
|
|
sudo apt-get --assume-yes --force-yes install ${packages}
|
|
fi
|
|
|
|
if ! $upgrade; then
|
|
|
|
# Save arguments
|
|
sudo yunohost app setting vpnclient service_enabled -v 0
|
|
sudo yunohost app setting vpnclient server_name -v access.ldn-fai.net
|
|
sudo yunohost app setting vpnclient server_port -v 1194
|
|
sudo yunohost app setting vpnclient server_proto -v udp
|
|
sudo yunohost app setting vpnclient ip6_addr -v none
|
|
sudo yunohost app setting vpnclient ip6_net -v none
|
|
sudo yunohost app setting vpnclient login_user -v "${login_user}"
|
|
sudo yunohost app setting vpnclient login_passphrase -v "${login_passphrase}"
|
|
sudo yunohost app setting vpnclient dns0 -v 89.234.141.66
|
|
sudo yunohost app setting vpnclient dns1 -v 2001:913::8
|
|
|
|
fi
|
|
|
|
# Save git commit
|
|
gitcommit=$(git rev-parse HEAD)
|
|
sudo yunohost app setting vpnclient gitcommit -v "${gitcommit}"
|
|
|
|
# Install IPv6 scripts
|
|
sudo install -o root -g root -m 0755 ../conf/ipv6_expanded /usr/local/bin/
|
|
sudo install -o root -g root -m 0755 ../conf/ipv6_compressed /usr/local/bin/
|
|
|
|
# Install command-line cube file loader
|
|
sudo install -o root -g root -m 0755 ../conf/ynh-vpnclient-loadcubefile.sh /usr/local/bin/
|
|
|
|
# Copy confs
|
|
sudo mkdir -pm 0755 /var/log/nginx/
|
|
sudo chown root:admins /etc/openvpn/
|
|
sudo chmod 775 /etc/openvpn/
|
|
sudo mkdir -pm 0755 /etc/yunohost/hooks.d/post_iptable_rules/
|
|
|
|
sudo install -b -o root -g admins -m 0664 ../conf/openvpn_client.conf.tpl /etc/openvpn/client.conf.tpl
|
|
sudo install -o root -g root -m 0644 ../conf/openvpn_client.conf.tpl /etc/openvpn/client.conf.tpl.restore
|
|
sudo install -b -o root -g root -m 0644 ../conf/nginx_vpnadmin.conf "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf"
|
|
sudo install -b -o root -g root -m 0644 ../conf/phpfpm_vpnadmin.conf /etc/php5/fpm/pool.d/vpnadmin.conf
|
|
sudo install -b -o root -g root -m 0755 ../conf/hook_post-iptable-rules /etc/yunohost/hooks.d/90-vpnclient.tpl
|
|
sudo install -b -o root -g root -m 0644 ../conf/openvpn@.service /etc/systemd/system/
|
|
|
|
# Copy web sources
|
|
sudo mkdir -pm 0755 /var/www/vpnadmin/
|
|
sudo cp -a ../sources/* /var/www/vpnadmin/
|
|
|
|
sudo chown -R root: /var/www/vpnadmin/
|
|
sudo chmod -R 0644 /var/www/vpnadmin/*
|
|
sudo find /var/www/vpnadmin/ -type d -exec chmod +x {} \;
|
|
|
|
# Copy certificates
|
|
sudo mkdir -pm 0770 /etc/openvpn/keys/
|
|
sudo chown root:admins /etc/openvpn/keys/
|
|
|
|
# Fix confs
|
|
## nginx
|
|
sudo sed "s|<TPL:NGINX_LOCATION>|${url_path}|g" -i "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf"
|
|
sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/vpnadmin/|g' -i "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf"
|
|
sudo sed 's|<TPL:PHP_NAME>|vpnadmin|g' -i "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf"
|
|
|
|
## php-fpm
|
|
sudo sed 's|<TPL:PHP_NAME>|vpnadmin|g' -i /etc/php5/fpm/pool.d/vpnadmin.conf
|
|
sudo sed 's|<TPL:PHP_USER>|admin|g' -i /etc/php5/fpm/pool.d/vpnadmin.conf
|
|
sudo sed 's|<TPL:PHP_GROUP>|admins|g' -i /etc/php5/fpm/pool.d/vpnadmin.conf
|
|
sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/vpnadmin/|g' -i /etc/php5/fpm/pool.d/vpnadmin.conf
|
|
|
|
# Fix sources
|
|
sudo sed "s|<TPL:NGINX_LOCATION>|${url_path}|g" -i /var/www/vpnadmin/config.php
|
|
|
|
# Copy init script
|
|
sudo install -o root -g root -m 0755 ../conf/ynh-vpnclient /usr/local/bin/
|
|
sudo install -o root -g root -m 0644 ../conf/ynh-vpnclient.service /etc/systemd/system/
|
|
|
|
# Set default inits
|
|
# The boot order of these services are important, so they are disabled by default
|
|
# and the ynh-vpnclient service handles them.
|
|
sudo systemctl disable openvpn
|
|
sudo systemctl stop openvpn
|
|
|
|
sudo systemctl enable php5-fpm
|
|
sudo systemctl restart php5-fpm
|
|
|
|
sudo systemctl reload nginx
|
|
|
|
sudo systemctl enable ynh-vpnclient
|
|
sudo yunohost service add ynh-vpnclient
|
|
|
|
if ! $upgrade; then
|
|
sudo systemctl start ynh-vpnclient
|
|
|
|
# Check configuration consistency
|
|
|
|
if [ -z "${crt_server_ca_path}" ]; then
|
|
echo "WARNING: VPN Client is not started because you need to define a server CA through the web admin" >&2
|
|
fi
|
|
|
|
if [ -z "${crt_client_key_path}" -a -z "${login_user}" ]; then
|
|
echo "WARNING: VPN Client is not started because you need either a client certificate, either a username (or both)" >&2
|
|
fi
|
|
fi
|
|
|
|
sudo yunohost app ssowatconf
|
|
|
|
exit 0
|