install 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. #=================================================
  19. # GENERIC START
  20. #=================================================
  21. # IMPORT GENERIC HELPERS
  22. #=================================================
  23. source _common.sh
  24. source /usr/share/yunohost/helpers
  25. #=================================================
  26. # MANAGE SCRIPT FAILURE
  27. #=================================================
  28. # Exit if an error occurs during the execution of the script
  29. ynh_abort_if_errors
  30. #=================================================
  31. # RETRIEVE ARGUMENTS FROM THE MANIFEST
  32. #=================================================
  33. # Retrieve arguments
  34. domain=$YNH_APP_ARG_DOMAIN
  35. path_url=$YNH_APP_ARG_PATH
  36. app=$YNH_APP_INSTANCE_NAME
  37. #=================================================
  38. # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
  39. #=================================================
  40. # Check destination directory
  41. final_path="/var/www/$app"
  42. test ! -e "$final_path" || ynh_die "This path already contains a folder"
  43. # Normalize the url path syntax
  44. path_url=$(ynh_normalize_url_path "$path_url")
  45. # Check web path availability
  46. ynh_webpath_available "$domain" "$path_url"
  47. # Register (book) web path
  48. ynh_webpath_register "$app" "$domain" "$path_url"
  49. #=================================================
  50. # STORE SETTINGS FROM MANIFEST
  51. #=================================================
  52. ynh_app_setting_set "$app" domain "$domain"
  53. ynh_app_setting_set "$app" final_path "$final_path"
  54. #=================================================
  55. # STANDARD MODIFICATIONS
  56. #=================================================
  57. # INSTALL DEPENDENCIES
  58. #=================================================
  59. ynh_install_app_dependencies "$pkg_dependencies"
  60. #=================================================
  61. # SPECIFIC SETUP
  62. #=================================================
  63. # This is an upgrade?
  64. upgrade=$([ -z ${VPNCLIENT_UPGRADE+x} ] && echo true || echo false)
  65. if ! $upgrade; then
  66. # Save arguments
  67. ynh_app_setting_set $app service_enabled 0
  68. ynh_app_setting_set $app server_name none
  69. ynh_app_setting_set $app server_port 1194
  70. ynh_app_setting_set $app server_proto udp
  71. ynh_app_setting_set $app ip6_addr none
  72. ynh_app_setting_set $app ip6_net none
  73. ynh_app_setting_set $app login_user "${login_user}"
  74. ynh_app_setting_set $app login_passphrase "${login_passphrase}"
  75. ynh_app_setting_set $app dns0 89.234.141.66
  76. ynh_app_setting_set $app dns1 2001:913::8
  77. fi
  78. # Install IPv6 scripts
  79. sudo install -o root -g root -m 0755 ../conf/ipv6_expanded /usr/local/bin/
  80. sudo install -o root -g root -m 0755 ../conf/ipv6_compressed /usr/local/bin/
  81. # Install command-line cube file loader
  82. sudo install -o root -g root -m 0755 ../conf/ynh-vpnclient-loadcubefile.sh /usr/local/bin/
  83. # Copy confs
  84. sudo mkdir -pm 0755 /var/log/nginx/
  85. sudo chown root:admins /etc/openvpn/
  86. sudo chmod 775 /etc/openvpn/
  87. sudo mkdir -pm 0755 /etc/yunohost/hooks.d/post_iptable_rules/
  88. sudo install -b -o root -g admins -m 0664 ../conf/openvpn_client.conf.tpl /etc/openvpn/client.conf.tpl
  89. sudo install -o root -g root -m 0644 ../conf/openvpn_client.conf.tpl /etc/openvpn/client.conf.tpl.restore
  90. sudo install -b -o root -g root -m 0644 ../conf/nginx_vpnadmin.conf "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf"
  91. sudo install -b -o root -g root -m 0644 ../conf/phpfpm_vpnadmin.conf /etc/php5/fpm/pool.d/vpnadmin.conf
  92. sudo install -b -o root -g root -m 0755 ../conf/hook_post-iptable-rules /etc/yunohost/hooks.d/90-vpnclient.tpl
  93. sudo install -b -o root -g root -m 0644 ../conf/openvpn@.service /etc/systemd/system/
  94. # Copy web sources
  95. sudo mkdir -pm 0755 /var/www/vpnadmin/
  96. sudo cp -a ../sources/* /var/www/vpnadmin/
  97. sudo chown -R root: /var/www/vpnadmin/
  98. sudo chmod -R 0644 /var/www/vpnadmin/*
  99. sudo find /var/www/vpnadmin/ -type d -exec chmod +x {} \;
  100. # Create certificates directory
  101. sudo mkdir -pm 0770 /etc/openvpn/keys/
  102. sudo chown root:admins /etc/openvpn/keys/
  103. #=================================================
  104. # NGINX CONFIGURATION
  105. #=================================================
  106. sudo sed "s|<TPL:NGINX_LOCATION>|${path_url}|g" -i "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf"
  107. sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/vpnadmin/|g' -i "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf"
  108. sudo sed 's|<TPL:PHP_NAME>|vpnadmin|g' -i "/etc/nginx/conf.d/${domain}.d/vpnadmin.conf"
  109. #=================================================
  110. # PHP-FPM CONFIGURATION
  111. #=================================================
  112. sudo sed 's|<TPL:PHP_NAME>|vpnadmin|g' -i /etc/php5/fpm/pool.d/vpnadmin.conf
  113. sudo sed 's|<TPL:PHP_USER>|admin|g' -i /etc/php5/fpm/pool.d/vpnadmin.conf
  114. sudo sed 's|<TPL:PHP_GROUP>|admins|g' -i /etc/php5/fpm/pool.d/vpnadmin.conf
  115. sudo sed 's|<TPL:NGINX_REALPATH>|/var/www/vpnadmin/|g' -i /etc/php5/fpm/pool.d/vpnadmin.conf
  116. # Fix sources
  117. sudo sed "s|<TPL:NGINX_LOCATION>|${path_url}|g" -i /var/www/vpnadmin/config.php
  118. # Copy init script
  119. sudo install -o root -g root -m 0755 ../conf/ynh-vpnclient /usr/local/bin/
  120. sudo install -o root -g root -m 0644 ../conf/ynh-vpnclient.service /etc/systemd/system/
  121. # Copy checker timer
  122. sudo install -o root -g root -m 0755 ../conf/ynh-vpnclient-checker.sh /usr/local/bin/
  123. sudo install -o root -g root -m 0644 ../conf/ynh-vpnclient-checker.service /etc/systemd/system/
  124. sudo install -o root -g root -m 0644 ../conf/ynh-vpnclient-checker.timer /etc/systemd/system/
  125. # Set default inits
  126. # The boot order of these services are important, so they are disabled by default
  127. # and the ynh-vpnclient service handles them.
  128. sudo systemctl disable openvpn
  129. sudo systemctl stop openvpn
  130. sudo systemctl enable php5-fpm
  131. sudo systemctl restart php5-fpm
  132. sudo systemctl reload nginx
  133. sudo systemctl enable ynh-vpnclient
  134. sudo yunohost service add ynh-vpnclient
  135. ynh_systemctl start ynh-vpnclient-checker.service
  136. sudo systemctl enable ynh-vpnclient-checker.service
  137. ynh_systemctl start ynh-vpnclient-checker.timer
  138. sudo systemctl enable ynh-vpnclient-checker.timer
  139. if ! $upgrade; then
  140. ynh_systemctl start ynh-vpnclient
  141. # Check configuration consistency
  142. if [ -z "${crt_server_ca_path}" ]; then
  143. echo "WARNING: VPN Client is not started because you need to define a server CA through the web admin" >&2
  144. fi
  145. if [ -z "${crt_client_key_path}" -a -z "${login_user}" ]; then
  146. echo "WARNING: VPN Client is not started because you need either a client certificate, either a username (or both)" >&2
  147. fi
  148. fi
  149. sudo yunohost app ssowatconf