_common.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. # Install command-line cube file loader
  17. install -o root -g root -m 0755 ../conf/$service_name-loadcubefile.sh /usr/local/bin/
  18. # Copy confs
  19. chown root:${app} /etc/openvpn/
  20. chmod 775 /etc/openvpn/
  21. mkdir -pm 0755 /etc/yunohost/hooks.d/post_iptable_rules/
  22. mkdir -pm 0755 /etc/systemd/system/openvpn@.service.d/
  23. install -b -o root -g ${app} -m 0644 ../conf/openvpn_client.conf.tpl /etc/openvpn/client.conf.tpl
  24. install -b -o root -g root -m 0755 ../conf/hook_post-iptable-rules /etc/yunohost/hooks.d/90-vpnclient.tpl
  25. install -b -o root -g root -m 0644 ../conf/openvpn@.service /etc/systemd/system/openvpn@.service.d/override.conf
  26. # Create certificates directory
  27. mkdir -pm 0770 /etc/openvpn/keys/
  28. chown root:${app} /etc/openvpn/keys/
  29. #=================================================
  30. # Copy init script
  31. install -o root -g root -m 0755 ../conf/$service_name /usr/local/bin/
  32. # Copy checker timer
  33. install -o root -g root -m 0755 ../conf/$service_checker_name.sh /usr/local/bin/
  34. install -o root -g root -m 0644 ../conf/$service_checker_name.timer /etc/systemd/system/
  35. systemctl daemon-reload
  36. #=================================================
  37. # SETUP SYSTEMD
  38. #=================================================
  39. ynh_print_info "Configuring a systemd service..."
  40. ynh_add_systemd_config $service_name "$service_name.service"
  41. ynh_add_systemd_config $service_checker_name "$service_checker_name.service"
  42. }