install 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #!/bin/bash
  2. # VPN Client app for YunoHost
  3. # Copyright (C) 2015 Julien Vaubourg <julien@vaubourg.com>
  4. # Contribute at https://github.com/labriqueinternet/vpnclient_ynh
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. # This is an upgrade?
  19. upgrade=$([ "${VPNCLIENT_UPGRADE}" == 1 ] && echo true || echo false)
  20. # Retrieve arguments
  21. domain=${1}
  22. url_path=${2}
  23. server_name=${3}
  24. if ! $upgrade; then
  25. source ./prerequisites
  26. # Check arguments
  27. if [ -z "${server_name}" ]; then
  28. echo "ERROR: You need a VPN server name" >&2
  29. exit 1
  30. fi
  31. # Check domain/path availability
  32. sudo yunohost app checkurl ${domain}${url_path} -a vpnclient
  33. if [ ! $? -eq 0 ]; then
  34. exit 1
  35. fi
  36. fi
  37. # Install packages
  38. packages='php5-fpm sipcalc dnsutils openvpn'
  39. export DEBIAN_FRONTEND=noninteractive
  40. sudo apt-get --assume-yes --force-yes install ${packages}
  41. if [ $? -ne 0 ]; then
  42. sudo apt-get update
  43. sudo apt-get --assume-yes --force-yes install ${packages}
  44. fi
  45. if ! $upgrade; then
  46. # Save arguments
  47. sudo yunohost app setting vpnclient service_enabled -v 0
  48. sudo yunohost app setting vpnclient server_name -v "${server_name}"
  49. sudo yunohost app setting vpnclient server_port -v 1194
  50. sudo yunohost app setting vpnclient server_proto -v udp
  51. sudo yunohost app setting vpnclient ip6_addr -v none
  52. sudo yunohost app setting vpnclient ip6_net -v none
  53. sudo yunohost app setting vpnclient login_user -v "${login_user}"
  54. sudo yunohost app setting vpnclient login_passphrase -v "${login_passphrase}"
  55. fi
  56. # Save git commit
  57. gitcommit=$(git rev-parse HEAD)
  58. sudo yunohost app setting vpnclient gitcommit -v "${gitcommit}"
  59. # Install IPv6 scripts
  60. sudo install -o root -g root -m 0755 ../conf/ipv6_expanded /usr/local/bin/
  61. sudo install -o root -g root -m 0755 ../conf/ipv6_compressed /usr/local/bin/
  62. # Copy confs
  63. sudo mkdir -pm 0755 /var/log/nginx/
  64. sudo chown root:admins /etc/openvpn/
  65. sudo chmod 775 /etc/openvpn/
  66. sudo mkdir -pm 0755 /etc/yunohost/hooks.d/post_iptable_rules/
  67. sudo install -b -o root -g admins -m 0664 ../conf/openvpn_client.conf.tpl /etc/openvpn/client.conf.tpl
  68. sudo install -o root -g root -m 0644 ../conf/openvpn_client.conf.tpl /etc/openvpn/client.conf.tpl.restore
  69. sudo install -b -o root -g root -m 0644 ../conf/nginx_vpnadmin.conf "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf"
  70. sudo install -b -o root -g root -m 0644 ../conf/phpfpm_vpnadmin.conf /etc/php5/fpm/pool.d/vpnadmin.conf
  71. sudo install -b -o root -g root -m 0755 ../conf/hook_post-iptable-rules /etc/yunohost/hooks.d/90-vpnclient.tpl
  72. # Copy web sources
  73. sudo mkdir -pm 0755 /var/www/vpnadmin/
  74. sudo cp -a ../sources/* /var/www/vpnadmin/
  75. sudo chown -R root: /var/www/vpnadmin/
  76. sudo chmod -R 0644 /var/www/vpnadmin/*
  77. sudo find /var/www/vpnadmin/ -type d -exec chmod +x {} \;
  78. # Copy certificates
  79. sudo mkdir -pm 0770 /etc/openvpn/keys/
  80. sudo chown root:admins /etc/openvpn/keys/
  81. # Fix confs
  82. ## nginx
  83. sudo sed "s|<TPL:NGINX_LOCATION>|${url_path}|g" -i "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf"
  84. sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/vpnadmin/|g' -i "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf"
  85. sudo sed 's|<TPL:PHP_NAME>|vpnadmin|g' -i "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf"
  86. ## php-fpm
  87. sudo sed 's|<TPL:PHP_NAME>|vpnadmin|g' -i /etc/php5/fpm/pool.d/vpnadmin.conf
  88. sudo sed 's|<TPL:PHP_USER>|admin|g' -i /etc/php5/fpm/pool.d/vpnadmin.conf
  89. sudo sed 's|<TPL:PHP_GROUP>|admins|g' -i /etc/php5/fpm/pool.d/vpnadmin.conf
  90. sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/vpnadmin/|g' -i /etc/php5/fpm/pool.d/vpnadmin.conf
  91. # Fix sources
  92. sudo sed "s|<TPL:NGINX_LOCATION>|${url_path}|g" -i /var/www/vpnadmin/config.php
  93. # Copy init script
  94. sudo install -o root -g root -m 0755 ../conf/ynh-vpnclient /usr/local/bin/
  95. sudo install -o root -g root -m 0644 ../conf/ynh-vpnclient.service /etc/systemd/system/
  96. # Set default inits
  97. # The boot order of these services are important, so they are disabled by default
  98. # and the ynh-vpnclient service handles them.
  99. sudo systemctl disable openvpn
  100. sudo systemctl stop openvpn
  101. sudo systemctl enable php5-fpm
  102. sudo systemctl restart php5-fpm
  103. sudo systemctl reload nginx
  104. sudo systemctl enable ynh-vpnclient
  105. sudo yunohost service add ynh-vpnclient
  106. if ! $upgrade; then
  107. sudo systemctl start ynh-vpnclient
  108. # Check configuration consistency
  109. if [ -z "${crt_server_ca_path}" ]; then
  110. echo "WARNING: VPN Client is not started because you need to define a server CA through the web admin" >&2
  111. fi
  112. if [ -z "${crt_client_key_path}" -a -z "${login_user}" ]; then
  113. echo "WARNING: VPN Client is not started because you need either a client certificate, either a username (or both)" >&2
  114. fi
  115. fi
  116. sudo yunohost app ssowatconf
  117. exit 0