Browse Source

[autopatch] Automatic patch attempt for helpers 2.1

Yunohost-Bot 8 months ago
parent
commit
185147153f
8 changed files with 64 additions and 73 deletions
  1. 2 1
      manifest.toml
  2. 8 9
      scripts/_common.sh
  3. 15 15
      scripts/backup
  4. 7 14
      scripts/config
  5. 1 1
      scripts/install
  6. 11 11
      scripts/remove
  7. 2 5
      scripts/restore
  8. 18 17
      scripts/upgrade

+ 2 - 1
manifest.toml

@@ -16,7 +16,8 @@ license = "AGPL-3.0"
 website = "https://labriqueinter.net"
 
 [integration]
-yunohost = ">= 11.2"
+yunohost = ">= 11.2.18"
+helpers_version = "2.1"
 architectures = "all"
 multi_instance = false
 ldap = "not_relevant"

+ 8 - 9
scripts/_common.sh

@@ -3,7 +3,6 @@
 service_name="ynh-vpnclient"
 service_checker_name=$service_name"-checker"
 
-
 # Operations needed by both 'install' and 'upgrade' scripts
 function vpnclient_deploy_files_and_services()
 {
@@ -47,11 +46,11 @@ function vpnclient_deploy_files_and_services()
   #=================================================
   # SETUP SYSTEMD
   #=================================================
-  ynh_print_info "Configuring a systemd service..."
+  ynh_print_info "Configuring $app's systemd service..."
 
-  ynh_add_systemd_config $service_name "$service_name.service"
+  ynh_config_add_systemd $service_name "$service_name.service"
 
-  ynh_add_systemd_config $service_checker_name "$service_checker_name.service"
+  ynh_config_add_systemd $service_checker_name "$service_checker_name.service"
 }
 
 function read_cube() {
@@ -79,8 +78,8 @@ function convert_cube_file()
 {
   local config_file="$1"
   local tmp_dir=$(dirname "$config_file")
-  
-  ynh_print_info --message="Transforming .cube into OVPN file"
+
+  ynh_print_info "Transforming .cube into OVPN file"
   server_name="$(read_cube $config_file server_name)"
   server_port="$(read_cube $config_file server_port)"
   server_proto="$(read_cube $config_file server_proto)"
@@ -101,7 +100,7 @@ function convert_cube_file()
     dns_method="custom"
     nameservers="$dns0,$dns1"
   fi
-  
+
   # Build specific OVPN template
   config_template="$tmp_dir/client.conf.tpl"
   cp -f /etc/yunohost/apps/vpnclient/conf/openvpn_client.conf.tpl "$config_template"
@@ -129,7 +128,7 @@ function convert_cube_file()
   [ -n "$login_user" ] && login_comment="" || login_comment="#"
 
   # Actually generate/hydrate the final configuration
-  ynh_add_config --template="$config_template" --destination="$config_file"
+  ynh_config_add --template="$config_template" --destination="$config_file"
 
   if [ "$server_proto" == tcp-client ]; then
     server_proto=tcp
@@ -141,7 +140,7 @@ function convert_ovpn_file()
   local config_file="$1"
   local tmp_dir=$(dirname "$config_file")
 
-  ynh_print_info --message="Extracting TLS keys from .ovpn file"
+  ynh_print_info "Extracting TLS keys from .ovpn file"
   if grep -q '^\s*<ca>' ${config_file}
   then
     grep -Poz '(?<=<ca>)(.*\n)*.*(?=</ca>)' ${config_file} | sed '/^$/d'  > $tmp_dir/crt_server_ca

+ 15 - 15
scripts/backup

@@ -8,34 +8,34 @@ source /usr/share/yunohost/helpers
 #=================================================
 ynh_print_info "Backing up the main app directory..."
 
-ynh_backup --src_path="/usr/local/bin/$service_name-loadcubefile.sh"
+ynh_backup "/usr/local/bin/$service_name-loadcubefile.sh"
 
-ynh_backup --src_path="/etc/yunohost/hooks.d/90-vpnclient.tpl"
+ynh_backup "/etc/yunohost/hooks.d/90-vpnclient.tpl"
 
-ynh_backup --src_path="/etc/openvpn/client.conf.tpl"
-ynh_backup --src_path="/etc/openvpn/client.conf" --not_mandatory
-ynh_backup --src_path="/etc/openvpn/client.cube" --not_mandatory
-ynh_backup --src_path="/etc/openvpn/client.ovpn" --not_mandatory
+ynh_backup "/etc/openvpn/client.conf.tpl"
+ynh_backup "/etc/openvpn/client.conf" || true
+ynh_backup "/etc/openvpn/client.cube" || true
+ynh_backup "/etc/openvpn/client.ovpn" || true
 
 for FILE in $(ls /etc/openvpn/scripts/route-up.d/*-vpnclient-* /etc/openvpn/scripts/route-down.d/*-vpnclient-*); do
-    ynh_backup --src_path="$FILE"
+    ynh_backup "$FILE"
 done
 
-ynh_backup --src_path="/etc/openvpn/keys/"
-ynh_backup --src_path="/etc/openvpn/scripts/run-parts.sh"
+ynh_backup "/etc/openvpn/keys/"
+ynh_backup "/etc/openvpn/scripts/run-parts.sh"
 
-ynh_backup --src_path="/usr/local/bin/$service_name"
-ynh_backup --src_path="/usr/local/bin/$service_checker_name.sh"
+ynh_backup "/usr/local/bin/$service_name"
+ynh_backup "/usr/local/bin/$service_checker_name.sh"
 
 #=================================================
 # BACKUP SYSTEMD
 #=================================================
 ynh_print_info "Backing up systemd configuration..."
 
-ynh_backup --src_path="/etc/systemd/system/$service_name.service"
-ynh_backup --src_path="/etc/systemd/system/$service_checker_name.service"
-ynh_backup --src_path="/etc/systemd/system/$service_checker_name.timer"
-ynh_backup --src_path="/etc/systemd/system/openvpn@.service.d/override.conf"
+ynh_backup "/etc/systemd/system/$service_name.service"
+ynh_backup "/etc/systemd/system/$service_checker_name.service"
+ynh_backup "/etc/systemd/system/$service_checker_name.timer"
+ynh_backup "/etc/systemd/system/openvpn@.service.d/override.conf"
 
 #=================================================
 # END OF SCRIPT

+ 7 - 14
scripts/config

@@ -1,11 +1,5 @@
 #!/bin/bash
 
-#=================================================
-# GENERIC STARTING
-#=================================================
-# IMPORT GENERIC HELPERS
-#=================================================
-
 source _common.sh
 source /usr/share/yunohost/helpers
 
@@ -14,7 +8,7 @@ source /usr/share/yunohost/helpers
 #=================================================
 
 # Exit if an error occurs during the execution of the script
-ynh_abort_if_errors
+#REMOVEME? ynh_abort_if_errors
 
 #=================================================
 # RETRIEVE ARGUMENTS
@@ -103,7 +97,6 @@ get__login_passphrase() {
     fi
 }
 
-
 #=================================================
 # SPECIFIC VALIDATORS FOR TOML SHORT KEYS
 #=================================================
@@ -233,9 +226,9 @@ ynh_app_config_validate() {
 ynh_app_config_apply() {
 
     # Stop vpn client
-    ynh_print_info --message="Stopping vpnclient in order to edit files"
-    ynh_systemd_action --service_name="ynh-vpnclient-checker.timer" --action="stop"
-    ynh_systemd_action --service_name="ynh-vpnclient" --action="stop"
+    ynh_print_info "Stopping vpnclient in order to edit files"
+    ynh_systemctl --service="ynh-vpnclient-checker.timer" --action="stop"
+    ynh_systemctl --service="ynh-vpnclient" --action="stop"
 
     chown $app:$app /etc/openvpn/keys
     chmod go=--- /etc/openvpn/keys
@@ -253,9 +246,9 @@ ynh_app_config_apply() {
     [[ "$ovpn_file" == "/etc/openvpn/client.ovpn" ]] && rm -f "$ovpn_file"
 
     # Start vpn client
-    ynh_print_info --message="Starting vpnclient service if needed"
-    ynh_systemd_action --service_name="ynh-vpnclient" --action="start"
-    ynh_systemd_action --service_name="ynh-vpnclient-checker.timer" --action="start"
+    ynh_print_info "Starting vpnclient service if needed"
+    ynh_systemctl --service="ynh-vpnclient" --action="start"
+    ynh_systemctl --service="ynh-vpnclient-checker.timer" --action="start"
 }
 
 ynh_app_config_run $1

+ 1 - 1
scripts/install

@@ -44,4 +44,4 @@ systemctl enable $service_checker_name.timer --quiet
 # END OF SCRIPT
 #=================================================
 
-ynh_script_progression --message="Installation of $app completed" --last
+ynh_script_progression "Installation of $app completed"

+ 11 - 11
scripts/remove

@@ -13,14 +13,14 @@ systemctl disable $service_checker_name.timer --quiet
 systemctl stop $service_checker_name
 systemctl disable $service_checker_name --quiet
 
-if ynh_exec_warn_less yunohost service status $service_name >/dev/null; then
+if ynh_hide_warnings yunohost service status $service_name >/dev/null; then
     yunohost service stop $service_name
     yunohost service disable $service_name --quiet
     yunohost service remove $service_name
 fi
 
 for FILE in $(ls /etc/systemd/system/$service_name* /usr/local/bin/ynh-vpnclient* /tmp/.ynh-vpnclient-*); do
-    ynh_secure_remove "$FILE"
+    ynh_safe_rm "$FILE"
 done
 
 #=================================================
@@ -29,26 +29,26 @@ done
 ynh_print_info "Removing openvpn configuration"
 
 # Remove openvpn configurations
-ynh_secure_remove /etc/openvpn/client.conf
-ynh_secure_remove /etc/openvpn/client.conf.tpl
-ynh_secure_remove /etc/openvpn/client.cube
-ynh_secure_remove /etc/openvpn/client.ovpn
+ynh_safe_rm /etc/openvpn/client.conf
+ynh_safe_rm /etc/openvpn/client.conf.tpl
+ynh_safe_rm /etc/openvpn/client.cube
+ynh_safe_rm /etc/openvpn/client.ovpn
 
 # Remove openvpn script
-ynh_secure_remove /etc/openvpn/scripts/run-parts.sh
+ynh_safe_rm /etc/openvpn/scripts/run-parts.sh
 
 for FILE in $(ls /etc/openvpn/scripts/route-up.d/*-vpnclient-* /etc/openvpn/scripts/route-down.d/*-vpnclient-*); do
-    ynh_secure_remove "$FILE"
+    ynh_safe_rm "$FILE"
 done
 
 # Remove YunoHost hook
-ynh_secure_remove /etc/yunohost/hooks.d/90-vpnclient.tpl
+ynh_safe_rm /etc/yunohost/hooks.d/90-vpnclient.tpl
 
 # Remove openvpn service
-ynh_secure_remove /etc/systemd/system/openvpn@.service.d/override.conf
+ynh_safe_rm /etc/systemd/system/openvpn@.service.d/override.conf
 
 # Remove openvpn certificates
-ynh_secure_remove /etc/openvpn/keys
+ynh_safe_rm /etc/openvpn/keys
 
 # Reload systemd configuration
 systemctl daemon-reload

+ 2 - 5
scripts/restore

@@ -8,12 +8,11 @@ source /usr/share/yunohost/helpers
 #=================================================
 ynh_print_info "Restoring the app files..."
 
-ynh_restore
-
+ynh_restore_everything
 #=================================================
 # RESTORE SYSTEMD
 #=================================================
-ynh_print_info "Restoring the systemd configuration..."
+ynh_print_info "Restoring $app's systemd service..."
 
 systemctl daemon-reload
 
@@ -35,12 +34,10 @@ systemctl enable "$service_checker_name" --quiet
 systemctl start "$service_checker_name.timer"
 systemctl enable "$service_checker_name.timer" --quiet
 
-
 #=================================================
 # ADVERTISE SERVICE IN ADMIN PANEL
 #=================================================
 
-
 #=================================================
 # END OF SCRIPT
 #=================================================

+ 18 - 17
scripts/upgrade

@@ -9,22 +9,22 @@ source /usr/share/yunohost/helpers
 
 # Removing configuration files with naming that occured in versions < 1.2.0 ("vpnadmin" instead off "$app")
 if [ -d /var/www/vpnadmin ]; then
-  ynh_secure_remove /var/www/vpnadmin
+  ynh_safe_rm /var/www/vpnadmin
 fi
 
 # Old stuff
 
 if [ -f /etc/nginx/conf.d/*.d/$app.conf ]; then
-	ynh_secure_remove /etc/nginx/conf.d/*.d/$app.conf
-    ynh_systemd_action --service_name=nginx --action=reload
+	ynh_safe_rm /etc/nginx/conf.d/*.d/$app.conf
+    ynh_systemctl --service=nginx --action=reload
 fi
 
 for php_path in $(ls /etc/php/*/fpm/pool.d/$app.conf 2> /dev/null); do
-	ynh_secure_remove $php_path
+	ynh_safe_rm $php_path
 done
 
 if [ -d /var/www/$app ]; then
-	ynh_secure_remove /var/www/$app
+	ynh_safe_rm /var/www/$app
 fi
 
 [ -z "${domain:-}" ] || ynh_app_setting_delete $app domain
@@ -33,26 +33,27 @@ fi
 [ -z "${install_dir:-}" ] || ynh_app_setting_delete $app install_dir
 
 if [ -e "/etc/sudoers.d/${app}_ynh" ]; then
-  ynh_secure_remove "/etc/sudoers.d/${app}_ynh"
+  ynh_safe_rm "/etc/sudoers.d/${app}_ynh"
 fi
 
 # New stuff
 
 if [ -z "${dns_method:-}" ]; then
-    ynh_app_setting_set --app=$app --key=dns_method --value=custom
+    ynh_app_setting_set --key=dns_method --value=custom
 fi
+# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=nameservers --value="$(grep -o -P '\s*nameserver\s+\K[abcdefabcdef\d.:]+' /etc/resolv.dnsmasq.conf | sort | uniq | paste -s -d, -)"
 if [ -z "${nameservers:-}" ]; then
     nameservers="$(grep -o -P '\s*nameserver\s+\K[abcdefabcdef\d.:]+' /etc/resolv.dnsmasq.conf | sort | uniq | paste -s -d, -)"
-    ynh_app_setting_set --app=$app --key=nameservers --value="$nameservers"
+    ynh_app_setting_set --key=nameservers --value="$nameservers"
 fi
 if [ -z "${service_enabled:-}" ]; then
-    ynh_app_setting_set --app=$app --key=service_enabled --value=0
+    ynh_app_setting_set --key=service_enabled --value=0
 fi
 if [ -z "${ip6_addr:-}" ]; then
-    ynh_app_setting_set --app=$app --key=ip6_addr --value=""
+    ynh_app_setting_set --key=ip6_addr --value=""
 fi
 if [ -z "${ip6_net:-}" ]; then
-    ynh_app_setting_set --app=$app --key=ip6_net --value=""
+    ynh_app_setting_set --key=ip6_net --value=""
 fi
 
 #=================================================
@@ -60,16 +61,16 @@ fi
 #=================================================
 
 if [ -e "/etc/systemd/system/openvpn@.service" ]; then
-  ynh_secure_remove "/etc/systemd/system/openvpn@.service"
+  ynh_safe_rm "/etc/systemd/system/openvpn@.service"
 fi
 
 #=================================================
 # DEPLOY FILES FROM PACKAGE
 #=================================================
 
-ynh_print_info --message="Stopping VPN client to apply config changes..."
+ynh_print_info "Stopping VPN client to apply config changes..."
 
-ynh_systemd_action --action="stop" --service_name="$service_checker_name.timer"
+ynh_systemctl --action="stop" --service="$service_checker_name.timer"
 yunohost service stop $service_name
 
 # Keep a copy of existing config files before overwriting them
@@ -97,7 +98,7 @@ fi
 
 # Restore previously existing config files
 cp -r ${tmp_dir}/client* /etc/openvpn/
-ynh_secure_remove ${tmp_dir}
+ynh_safe_rm ${tmp_dir}
 
 #=================================================
 # SERVICE INTEGRATION IN YUNOHOST
@@ -110,7 +111,7 @@ ynh_print_info "Configuring VPN client services..."
 yunohost service add $service_name --description "Tunnels the internet traffic through a VPN" --need_lock --test_status="systemctl is-active openvpn@client.service" --log "/var/log/ynh-vpnclient.log"
 
 # checker service (this service was previously integrated in yunohost but we do not do this anymore)
-if ynh_exec_warn_less yunohost service status $service_checker_name >/dev/null
+if ynh_hide_warnings yunohost service status $service_checker_name >/dev/null
 then
     yunohost service remove $service_checker_name
 fi
@@ -122,7 +123,7 @@ ynh_print_info "Restart services..."
 
 # this is meant to propagate the new files and configs
 yunohost service start $service_name
-ynh_systemd_action --action="start" --service_name="$service_checker_name.timer"
+ynh_systemctl --action="start" --service="$service_checker_name.timer"
 
 #=================================================
 # END OF SCRIPT