Skip to content

Commit

Permalink
Add conffiles template support
Browse files Browse the repository at this point in the history
  • Loading branch information
Taka Kojima committed Aug 17, 2018
1 parent 9454b0a commit ea9f16d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
34 changes: 33 additions & 1 deletion node-deb
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ while [ -n "$1" ]; do

exit 0
;;
--template-conffiles)
# HELPDOC: Override Debian conffiles template (default: 'node_deb.templates.conffiles' from package.json then built-in)
zero_check "$value" "$param"
template_conffiles="$value"
shift
;;
--template-control)
# HELPDOC: Override Debian control template (default: 'node_deb.templates.control' from package.json then built-in)
zero_check "$value" "$param"
Expand Down Expand Up @@ -544,6 +550,17 @@ if [ -z "$extra_files" ]; then
fi
log_debug "The extra_files directory was set to: $extra_files"

# Set conffiles template
if [ -z "$template_conffiles" ]; then
template_conffiles=$(jq -r '.node_deb.templates.conffiles' package.json)
if [[ "$template_conffiles" == 'null' ]]; then
template_conffiles=''
fi
fi
: ${template_conffiles:="$node_deb_dir/templates/conffiles"}
log_debug "The conffiles template has been set to: $template_conffiles"


# Set control template
if [ -z "$template_control" ]; then
template_control=$(jq -r '.node_deb.templates.control' package.json)
Expand Down Expand Up @@ -730,6 +747,8 @@ replace_vars() {
declare -r target_file="$2"
declare -r permissions="$3"

lf=$'\n'

# TODO if you change this section, make sure the --list-template-variables command doesn't break
### BEGIN TEMPLATE_VARS ###
sed < "$file" \
Expand All @@ -738,6 +757,7 @@ replace_vars() {
-e "s/{{ node_deb_package_version }}/$(escape "$package_version")/g" \
-e "s/{{ cli_entrypoint }}/$(escape "$cli_entrypoint")/g" \
-e "s/{{ daemon_entrypoint }}/$(escape "$daemon_entrypoint")/g" \
-e "s/{{ node_deb_conffiles }}/$(escape "$conffiles")/g" \
-e "s/{{ node_deb_package_description }}/$(escape "$package_description")/g" \
-e "s/{{ node_deb_package_maintainer }}/$(escape "$package_maintainer")/g" \
-e "s/{{ node_deb_package_dependencies }}/$(escape "$package_dependencies")/g" \
Expand All @@ -749,6 +769,7 @@ replace_vars() {
-e "s/{{ node_deb_version }}/$(escape "$node_deb_version")/g" \
-e "s/{{ install_strategy }}/$(escape "$install_strategy")/g" \
-e "s/{{ node_deb_install_dir }}/$(escape "$install_dir")/g" \
-e "s/{{ node_deb_newline }}/\\$lf/g" \
> "$target_file"
### END TEMPLATE_VARS ###
chmod "$permissions" "$target_file"
Expand Down Expand Up @@ -776,7 +797,18 @@ if [ "$init" == 'auto' ] || [ "$init" == 'sysv' ]; then
fi

# Create conffiles for dpkg, add all files in etc
find "$deb_dir/etc" -type f | sed "s/^$(escape "$deb_dir")//" > "$deb_dir/DEBIAN/conffiles"
conffiles=""
while read fname; do
fname=$(sed "s/^$(escape "$deb_dir")//" <<< $fname)
# We use {{ node_deb_newline }} to workaround macOS sed issue with escaping newlines
if [ -z "$conffiles" ]; then
conffiles="$fname"
else
conffiles="$conffiles{{ node_deb_newline }}$fname"
fi
done <<< "$(find $deb_dir/etc -type f)"

replace_vars "$template_conffiles" "$deb_dir/DEBIAN/conffiles" '0644'

log_debug 'Templates rendered successfully'

Expand Down
1 change: 1 addition & 0 deletions templates/conffiles
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ node_deb_conffiles }}
1 change: 1 addition & 0 deletions test/node-deb-override/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"description": "overridden description",
"maintainer": "overridden maintainer",
"templates": {
"conffiles": "templates/conffiles",
"executable": "templates/executable",
"postinst": "templates/postinst",
"postrm": "templates/postrm",
Expand Down
2 changes: 2 additions & 0 deletions test/node-deb-override/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ grep -q 'EXECUTABLE_OVERRIDE' "$output/usr/share/overridden-package-name/bin/ove
|| die 'Executable not overridden'
# TODO add more tests

if [[ $(cat "$output/DEBIAN/conffiles") != '' ]]; then die 'conffiles not overridden'; fi

dpkg -i "$output.deb"
apt-get purge -y overridden-package-name

0 comments on commit ea9f16d

Please sign in to comment.