_common.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/bash
  2. #
  3. # Common variables and helpers
  4. #
  5. pkg_dependencies="sipcalc dnsutils openvpn curl fake-hwclock"
  6. service_name="ynh-vpnclient"
  7. service_checker_name=$service_name"-checker"
  8. # Operations needed by both 'install' and 'upgrade' scripts
  9. function vpnclient_deploy_files_and_services()
  10. {
  11. # Ensure vpnclient_ynh has its own system user
  12. if ! ynh_system_user_exists ${app}
  13. then
  14. ynh_system_user_create ${app}
  15. fi
  16. # Ensure the system user has enough permissions
  17. install -b -o root -g root -m 0440 ../conf/sudoers.conf /etc/sudoers.d/${app}_ynh
  18. ynh_replace_string "__VPNCLIENT_SYSUSER__" "${app}" /etc/sudoers.d/${app}_ynh
  19. # Install command-line cube file loader
  20. install -o root -g root -m 0755 ../conf/$service_name-loadcubefile.sh /usr/local/bin/
  21. # Copy confs
  22. chown root:${app} /etc/openvpn/
  23. chmod 775 /etc/openvpn/
  24. mkdir -pm 0755 /etc/yunohost/hooks.d/post_iptable_rules/
  25. install -b -o root -g ${app} -m 0664 ../conf/openvpn_client.conf.tpl /etc/openvpn/client.conf.tpl
  26. install -o root -g root -m 0644 ../conf/openvpn_client.conf.tpl /etc/openvpn/client.conf.tpl.restore
  27. install -b -o root -g root -m 0755 ../conf/hook_post-iptable-rules /etc/yunohost/hooks.d/90-vpnclient.tpl
  28. install -b -o root -g root -m 0644 ../conf/openvpn@.service /etc/systemd/system/
  29. # Create certificates directory
  30. mkdir -pm 0770 /etc/openvpn/keys/
  31. chown root:${app} /etc/openvpn/keys/
  32. #=================================================
  33. # Copy init script
  34. install -o root -g root -m 0755 ../conf/$service_name /usr/local/bin/
  35. # Copy checker timer
  36. install -o root -g root -m 0755 ../conf/$service_checker_name.sh /usr/local/bin/
  37. install -o root -g root -m 0644 ../conf/$service_checker_name.timer /etc/systemd/system/
  38. systemctl daemon-reload
  39. #=================================================
  40. # SETUP SYSTEMD
  41. #=================================================
  42. ynh_print_info "Configuring a systemd service..."
  43. ynh_add_systemd_config $service_name "$service_name.service"
  44. ynh_add_systemd_config $service_checker_name "$service_checker_name.service"
  45. }