install 5.9 KB

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