Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add conffiles template support #97

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is lf being set here? Can you add a comment please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sed on macOS does not properly interpret \n in the replace pattern so we either need to do a literal line break (ugly) or assign \n to a var and do it that way.


# 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
Empty file.
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