_common.sh 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/bin/bash
  2. #
  3. # Common variables and helpers
  4. #
  5. YNH_PHP_VERSION="7.3"
  6. pkg_dependencies="sipcalc dnsutils openvpn curl fake-hwclock"
  7. service_name="ynh-vpnclient"
  8. service_checker_name=$service_name"-checker"
  9. # Operations needed by both 'install' and 'upgrade' scripts
  10. function vpnclient_deploy_files_and_services()
  11. {
  12. # Ensure vpnclient_ynh has its own system user
  13. if ! ynh_system_user_exists ${app}
  14. then
  15. ynh_system_user_create ${app}
  16. fi
  17. # Ensure the system user has enough permissions
  18. install -b -o root -g root -m 0440 ../conf/sudoers.conf /etc/sudoers.d/${app}_ynh
  19. ynh_replace_string "__VPNCLIENT_SYSUSER__" "${app}" /etc/sudoers.d/${app}_ynh
  20. # Install IPv6 scripts
  21. install -o root -g root -m 0755 ../conf/ipv6_expanded /usr/local/bin/
  22. install -o root -g root -m 0755 ../conf/ipv6_compressed /usr/local/bin/
  23. # Install command-line cube file loader
  24. install -o root -g root -m 0755 ../conf/$service_name-loadcubefile.sh /usr/local/bin/
  25. # Copy confs
  26. mkdir -pm 0755 /var/log/nginx/
  27. chown root:${app} /etc/openvpn/
  28. chmod 775 /etc/openvpn/
  29. mkdir -pm 0755 /etc/yunohost/hooks.d/post_iptable_rules/
  30. install -b -o root -g ${app} -m 0664 ../conf/openvpn_client.conf.tpl /etc/openvpn/client.conf.tpl
  31. install -o root -g root -m 0644 ../conf/openvpn_client.conf.tpl /etc/openvpn/client.conf.tpl.restore
  32. install -b -o root -g root -m 0755 ../conf/hook_post-iptable-rules /etc/yunohost/hooks.d/90-vpnclient.tpl
  33. install -b -o root -g root -m 0644 ../conf/openvpn@.service /etc/systemd/system/
  34. # Copy web sources
  35. mkdir -pm 0755 /var/www/${app}/
  36. cp -a ../sources/* /var/www/${app}/
  37. chown -R root: /var/www/${app}/
  38. chmod -R 0644 /var/www/${app}/*
  39. find /var/www/${app}/ -type d -exec chmod +x {} \;
  40. # Create certificates directory
  41. mkdir -pm 0770 /etc/openvpn/keys/
  42. chown root:${app} /etc/openvpn/keys/
  43. #=================================================
  44. # NGINX CONFIGURATION
  45. #=================================================
  46. ynh_print_info "Configuring nginx web server..."
  47. ynh_add_nginx_config
  48. #=================================================
  49. # PHP-FPM CONFIGURATION
  50. #=================================================
  51. ynh_print_info "Configuring PHP-FPM..."
  52. # Create a dedicated PHP-FPM config
  53. ynh_add_fpm_config --phpversion=$YNH_PHP_VERSION
  54. phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
  55. #=================================================
  56. # Fix sources
  57. ynh_replace_string "__PATH__" "${path_url%%/}" "/var/www/${app}/config.php"
  58. # Copy init script
  59. install -o root -g root -m 0755 ../conf/$service_name /usr/local/bin/
  60. # Copy checker timer
  61. install -o root -g root -m 0755 ../conf/$service_checker_name.sh /usr/local/bin/
  62. install -o root -g root -m 0644 ../conf/$service_checker_name.timer /etc/systemd/system/
  63. systemctl daemon-reload
  64. #=================================================
  65. # SETUP SYSTEMD
  66. #=================================================
  67. ynh_print_info "Configuring a systemd service..."
  68. ynh_add_systemd_config $service_name "$service_name.service"
  69. ynh_add_systemd_config $service_checker_name "$service_checker_name.service"
  70. }