install 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. # Check arguments
  26. if [ -z "${server_name}" ]; then
  27. echo "ERROR: You need a VPN server name" >&2
  28. exit 1
  29. fi
  30. # Check domain/path availability
  31. sudo yunohost app checkurl ${domain}${url_path} -a vpnclient
  32. if [ ! $? -eq 0 ]; then
  33. exit 1
  34. fi
  35. fi
  36. # Install packages
  37. packages='php5-fpm sipcalc openvpn'
  38. export DEBIAN_FRONTEND=noninteractive
  39. sudo apt-get --assume-yes --force-yes install ${packages}
  40. if [ $? -ne 0 ]; then
  41. sudo apt-get update
  42. sudo apt-get --assume-yes --force-yes install ${packages}
  43. fi
  44. if ! $upgrade; then
  45. # Save arguments
  46. sudo yunohost app setting vpnclient service_enabled -v 0
  47. sudo yunohost app setting vpnclient server_name -v "${server_name}"
  48. sudo yunohost app setting vpnclient server_port -v 1194
  49. sudo yunohost app setting vpnclient server_proto -v udp
  50. sudo yunohost app setting vpnclient ip6_addr -v none
  51. sudo yunohost app setting vpnclient ip6_net -v none
  52. sudo yunohost app setting vpnclient login_user -v "${login_user}"
  53. sudo yunohost app setting vpnclient login_passphrase -v "${login_passphrase}"
  54. fi
  55. # Save git commit
  56. gitcommit=$(git rev-parse HEAD)
  57. sudo yunohost app setting vpnclient gitcommit -v "${gitcommit}"
  58. # Install IPv6 scripts
  59. sudo install -o root -g root -m 0755 ../conf/ipv6_expanded /usr/local/bin/
  60. sudo install -o root -g root -m 0755 ../conf/ipv6_compressed /usr/local/bin/
  61. # Copy confs
  62. sudo mkdir -pm 0755 /var/log/nginx/
  63. sudo chown root:admins /etc/openvpn/
  64. sudo chmod 775 /etc/openvpn/
  65. sudo install -b -o root -g admins -m 0664 ../conf/openvpn_client.conf.tpl /etc/openvpn/client.conf.tpl
  66. sudo install -o root -g root -m 0644 ../conf/openvpn_client.conf.tpl /etc/openvpn/client.conf.tpl.restore
  67. sudo install -b -o root -g root -m 0644 ../conf/nginx_vpnadmin.conf "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf"
  68. sudo install -b -o root -g root -m 0644 ../conf/phpfpm_vpnadmin.conf /etc/php5/fpm/pool.d/vpnadmin.conf
  69. # Copy web sources
  70. sudo mkdir -pm 0755 /var/www/vpnadmin/
  71. sudo cp -a ../sources/* /var/www/vpnadmin/
  72. sudo chown -R root: /var/www/vpnadmin/
  73. sudo chmod -R 0644 /var/www/vpnadmin/*
  74. sudo find /var/www/vpnadmin/ -type d -exec chmod +x {} \;
  75. # Copy certificates
  76. sudo mkdir -pm 0770 /etc/openvpn/keys/
  77. sudo chown root:admins /etc/openvpn/keys/
  78. # Fix confs
  79. ## nginx
  80. sudo sed "s|<TPL:NGINX_LOCATION>|${url_path}|g" -i "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf"
  81. sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/vpnadmin/|g' -i "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf"
  82. sudo sed 's|<TPL:PHP_NAME>|vpnadmin|g' -i "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf"
  83. ## php-fpm
  84. sudo sed 's|<TPL:PHP_NAME>|vpnadmin|g' -i /etc/php5/fpm/pool.d/vpnadmin.conf
  85. sudo sed 's|<TPL:PHP_USER>|admin|g' -i /etc/php5/fpm/pool.d/vpnadmin.conf
  86. sudo sed 's|<TPL:PHP_GROUP>|admins|g' -i /etc/php5/fpm/pool.d/vpnadmin.conf
  87. sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/vpnadmin/|g' -i /etc/php5/fpm/pool.d/vpnadmin.conf
  88. # Fix sources
  89. sudo sed "s|<TPL:NGINX_LOCATION>|${url_path}|g" -i /var/www/vpnadmin/config.php
  90. # Copy init script
  91. sudo install -o root -g root -m 0755 ../conf/ynh-vpnclient /usr/local/bin/
  92. sudo install -o root -g root -m 0644 ../conf/ynh-vpnclient.service /etc/systemd/system/
  93. # Set default inits
  94. # The boot order of these services are important, so they are disabled by default
  95. # and the ynh-vpnclient service handles them.
  96. sudo systemctl disable openvpn
  97. sudo systemctl stop openvpn
  98. sudo systemctl enable php5-fpm
  99. sudo systemctl restart php5-fpm
  100. sudo systemctl reload nginx
  101. sudo systemctl enable ynh-vpnclient
  102. sudo yunohost service add ynh-vpnclient
  103. if ! $upgrade; then
  104. sudo systemctl start ynh-vpnclient
  105. # Check configuration consistency
  106. if [ -z "${crt_server_ca_path}" ]; then
  107. echo "WARNING: VPN Client is not started because you need to define a server CA through the web admin" >&2
  108. fi
  109. if [ -z "${crt_client_key_path}" -a -z "${login_user}" ]; then
  110. echo "WARNING: VPN Client is not started because you need either a client certificate, either a username (or both)" >&2
  111. fi
  112. fi
  113. sudo yunohost app ssowatconf
  114. exit 0