diff --git a/node-deb b/node-deb index 52a2e50..b469b2e 100755 --- a/node-deb +++ b/node-deb @@ -274,6 +274,12 @@ while [ -n "$1" ]; do template_executable="$value" shift ;; + --template-hooks) + # HELPDOC: Override hooks template (default: 'node_deb.templates.hooks' from package.json then built-in) + zero_check "$value" "$param" + template_executable="$value" + shift + ;; --template-postinst) # HELPDOC: Override maintainer script postinst template (default: 'node_deb.templates.postinst' from package.json then built-in) zero_check "$value" "$param" @@ -521,6 +527,16 @@ fi : ${template_executable:="$node_deb_dir/templates/executable"} log_debug "The executable template has been set to: $template_executable" +# Set hooks template +if [ -z "$template_hooks" ]; then + template_hooks=$(jq -r '.node_deb.templates.hooks' package.json) + if [[ "$template_hooks" == 'null' ]]; then + template_hooks='' + fi +fi +: ${template_hooks:="$node_deb_dir/templates/hooks"} +log_debug "The hooks template has been set to: $template_hooks" + # Set postinst template if [ -z "$template_postinst" ]; then template_postinst=$(jq -r '.node_deb.templates.postinst' package.json) @@ -611,6 +627,7 @@ log_debug "The CLI entrypoint has been set to: $cli_entrypoint" deb_dir="${package_name}_${package_version}_${architecture}" +hooks_path="usr/share/$package_name/scripts/hooks" finish() { if [ $no_delete_temp -ne 1 ]; then @@ -693,6 +710,7 @@ replace_vars() { -e "s/{{ node_deb_group }}/$(escape "$group")/g" \ -e "s/{{ node_deb_init }}/$(escape "$init")/g" \ -e "s/{{ node_deb_no_rebuild }}/$(escape "$no_rebuild")/g" \ + -e "s/{{ node_deb_hooks }}/$(escape "/$hooks_path")/g" \ -e "s/{{ node_deb_version }}/$(escape "$node_deb_version")/g" \ -e "s/{{ install_strategy }}/$(escape "$install_strategy")/g" \ > "$target_file" @@ -706,6 +724,7 @@ replace_vars "$template_postinst" "$deb_dir/DEBIAN/postinst" '0755' replace_vars "$template_postrm" "$deb_dir/DEBIAN/postrm" '0755' replace_vars "$template_prerm" "$deb_dir/DEBIAN/prerm" '0755' replace_vars "$template_executable" "$deb_dir/usr/share/$package_name/bin/$executable_name" '0755' +replace_vars "$template_hooks" "$deb_dir/$hooks_path" '0755' replace_vars "$template_default_variables" "$deb_dir/etc/default/$package_name" '0644' if [ "$init" == 'auto' ] || [ "$init" == 'upstart' ]; then diff --git a/templates/hooks b/templates/hooks new file mode 100644 index 0000000..75ffec6 --- /dev/null +++ b/templates/hooks @@ -0,0 +1,13 @@ +#!/bin/bash +# This file was autogenerated by node-deb {{ node_deb_version }} +set -e +set -o pipefail + +case "$1" in + postinst) + ;; + prerm) + ;; + postrm) + ;; +esac diff --git a/templates/postinst b/templates/postinst index 401a03b..e77a778 100644 --- a/templates/postinst +++ b/templates/postinst @@ -117,6 +117,8 @@ dependency_install '{{ node_deb_package_name }}' mkdir -p '/var/log/{{ node_deb_package_name }}' chown -R '{{ node_deb_user }}:{{ node_deb_group }}' '/var/log/{{ node_deb_package_name }}' +{{node_deb_hooks}} "postinst $@" + if [[ "$init_type" != 'none' ]]; then start_service '{{ node_deb_package_name }}' fi diff --git a/templates/postrm b/templates/postrm index f8d16f0..e620655 100644 --- a/templates/postrm +++ b/templates/postrm @@ -3,6 +3,8 @@ set -e set -o pipefail +{{node_deb_hooks}} "postrm $@" + # Will return true even if deletion fails delete_user() { : "${1:?'User was not defined'}" @@ -40,6 +42,6 @@ case "$1" in rm -rf '/var/log/{{ node_deb_package_name }}' ;; *) - echo "postinst called with unknown argument '$1'" + echo "postrm called with unknown argument '$1'" ;; esac diff --git a/templates/prerm b/templates/prerm index 53f0fa0..46ce83b 100644 --- a/templates/prerm +++ b/templates/prerm @@ -3,6 +3,8 @@ set -e set -o pipefail +{{node_deb_hooks}} "prerm $@" + declare -r init_type='{{ node_deb_init }}' declare -r service_name='{{ node_deb_package_name }}'