install 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. if ! $upgrade; then
  24. source ./prerequisites
  25. fi
  26. # Check domain/path availability
  27. sudo yunohost app checkurl ${domain}${url_path} -a vpnclient
  28. if [ ! $? -eq 0 ]; then
  29. exit 1
  30. fi
  31. # Install packages
  32. packages='php5-fpm sipcalc dnsutils openvpn curl'
  33. export DEBIAN_FRONTEND=noninteractive
  34. sudo apt-get --assume-yes --force-yes install ${packages}
  35. if [ $? -ne 0 ]; then
  36. sudo apt-get update
  37. sudo apt-get --assume-yes --force-yes install ${packages}
  38. fi
  39. if ! $upgrade; then
  40. # Save arguments
  41. sudo yunohost app setting vpnclient service_enabled -v 0
  42. sudo yunohost app setting vpnclient server_name -v none
  43. sudo yunohost app setting vpnclient server_port -v 1194
  44. sudo yunohost app setting vpnclient server_proto -v udp
  45. sudo yunohost app setting vpnclient ip6_addr -v none
  46. sudo yunohost app setting vpnclient ip6_net -v none
  47. sudo yunohost app setting vpnclient login_user -v "${login_user}"
  48. sudo yunohost app setting vpnclient login_passphrase -v "${login_passphrase}"
  49. sudo yunohost app setting vpnclient dns0 -v 89.234.141.66
  50. sudo yunohost app setting vpnclient dns1 -v 2001:913::8
  51. fi
  52. # Install IPv6 scripts
  53. sudo install -o root -g root -m 0755 ../conf/ipv6_expanded /usr/local/bin/
  54. sudo install -o root -g root -m 0755 ../conf/ipv6_compressed /usr/local/bin/
  55. # Install command-line cube file loader
  56. sudo install -o root -g root -m 0755 ../conf/ynh-vpnclient-loadcubefile.sh /usr/local/bin/
  57. # Copy confs
  58. sudo mkdir -pm 0755 /var/log/nginx/
  59. sudo chown root:admins /etc/openvpn/
  60. sudo chmod 775 /etc/openvpn/
  61. sudo mkdir -pm 0755 /etc/yunohost/hooks.d/post_iptable_rules/
  62. sudo install -b -o root -g admins -m 0664 ../conf/openvpn_client.conf.tpl /etc/openvpn/client.conf.tpl
  63. sudo install -o root -g root -m 0644 ../conf/openvpn_client.conf.tpl /etc/openvpn/client.conf.tpl.restore
  64. sudo install -b -o root -g root -m 0644 ../conf/nginx_vpnadmin.conf "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf"
  65. sudo install -b -o root -g root -m 0644 ../conf/phpfpm_vpnadmin.conf /etc/php5/fpm/pool.d/vpnadmin.conf
  66. sudo install -b -o root -g root -m 0755 ../conf/hook_post-iptable-rules /etc/yunohost/hooks.d/90-vpnclient.tpl
  67. sudo install -b -o root -g root -m 0644 ../conf/openvpn@.service /etc/systemd/system/
  68. # Copy web sources
  69. sudo mkdir -pm 0755 /var/www/vpnadmin/
  70. sudo cp -a ../sources/* /var/www/vpnadmin/
  71. sudo chown -R root: /var/www/vpnadmin/
  72. sudo chmod -R 0644 /var/www/vpnadmin/*
  73. sudo find /var/www/vpnadmin/ -type d -exec chmod +x {} \;
  74. # Create certificates directory
  75. sudo mkdir -pm 0770 /etc/openvpn/keys/
  76. sudo chown root:admins /etc/openvpn/keys/
  77. # Fix confs
  78. ## nginx
  79. sudo sed "s|<TPL:NGINX_LOCATION>|${url_path}|g" -i "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf"
  80. sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/vpnadmin/|g' -i "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf"
  81. sudo sed 's|<TPL:PHP_NAME>|vpnadmin|g' -i "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf"
  82. ## php-fpm
  83. sudo sed 's|<TPL:PHP_NAME>|vpnadmin|g' -i /etc/php5/fpm/pool.d/vpnadmin.conf
  84. sudo sed 's|<TPL:PHP_USER>|admin|g' -i /etc/php5/fpm/pool.d/vpnadmin.conf
  85. sudo sed 's|<TPL:PHP_GROUP>|admins|g' -i /etc/php5/fpm/pool.d/vpnadmin.conf
  86. sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/vpnadmin/|g' -i /etc/php5/fpm/pool.d/vpnadmin.conf
  87. # Fix sources
  88. sudo sed "s|<TPL:NGINX_LOCATION>|${url_path}|g" -i /var/www/vpnadmin/config.php
  89. # Copy init script
  90. sudo install -o root -g root -m 0755 ../conf/ynh-vpnclient /usr/local/bin/
  91. sudo install -o root -g root -m 0644 ../conf/ynh-vpnclient.service /etc/systemd/system/
  92. # Copy checker timer
  93. sudo install -o root -g root -m 0755 ../conf/ynh-vpnclient-checker.sh /usr/local/bin/
  94. sudo install -o root -g root -m 0644 ../conf/ynh-vpnclient-checker.service /etc/systemd/system/
  95. sudo install -o root -g root -m 0644 ../conf/ynh-vpnclient-checker.timer /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. sudo systemctl start ynh-vpnclient-checker.service
  107. sudo systemctl enable ynh-vpnclient-checker.service
  108. sudo systemctl start ynh-vpnclient-checker.timer
  109. sudo systemctl enable ynh-vpnclient-checker.timer
  110. if ! $upgrade; then
  111. sudo systemctl start ynh-vpnclient
  112. # Check configuration consistency
  113. if [ -z "${crt_server_ca_path}" ]; then
  114. echo "WARNING: VPN Client is not started because you need to define a server CA through the web admin" >&2
  115. fi
  116. if [ -z "${crt_client_key_path}" -a -z "${login_user}" ]; then
  117. echo "WARNING: VPN Client is not started because you need either a client certificate, either a username (or both)" >&2
  118. fi
  119. fi
  120. sudo yunohost app ssowatconf
  121. exit 0