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

Debian systemd post-install fails due to empty if-clause in template. #1757

Open
x10an14 opened this issue Jan 25, 2021 · 2 comments
Open

Debian systemd post-install fails due to empty if-clause in template. #1757

x10an14 opened this issue Jan 25, 2021 · 2 comments

Comments

@x10an14
Copy link

x10an14 commented Jan 25, 2021

Ref. PR #1498, we've experienced this when utilizing the below flags for fpm:

`fpm` invocation
rm -f ./*.deb

fpm \
    --verbose \
    --output-type deb \
    --input-type dir \
    --name X \
    --version "${1:-Unknown}" \
    --vendor "Y" \
    --maintainer "Y" \
    --description "Lorem Ipsum" \
    --url Z \
    --depends jq \
    --depends sed \
    --depends wireguard \
    --after-install packaging/linux/postinstall \
    --after-upgrade packaging/linux/postinstall \
    --deb-systemd packaging/linux/helper.service \
    bin/linux-client/helper=/usr/sbin/helper \
    bin/linux-client/agent=/usr/bin/X \
    packaging/linux/X.desktop=/usr/share/applications/ \
    packaging/linux/icons/=/usr/share/icons/hicolor/
Package install log
(Reading database ... 646934 files and directories currently installed.)
Preparing to unpack .../X.deb ...
Unpacking X (2021-01-25-f3d0708) over (2021-01-15-b32d8c8) ...
Setting up X (2021-01-25-f3d0708) ...
/var/lib/dpkg/info/X.postinst: 34: Syntax error: "else" unexpected
dpkg: error processing package X (--configure):
 installed X package post-installation script subprocess returned error exit status 2
Processing triggers for mime-support (3.64ubuntu1) ...
Processing triggers for hicolor-icon-theme (0.17-2) ...
Processing triggers for gnome-menus (3.36.0-1ubuntu1) ...
Processing triggers for desktop-file-utils (0.24+linuxmint1) ...
Errors were encountered while processing:
 X
E: Sub-process /usr/bin/dpkg returned an error code (1)

X.postinst, lines 30-36:

systemctl --system daemon-reload >/dev/null || true
debsystemctl=$(command -v deb-systemd-invoke || echo systemctl)
if ! systemctl is-enabled device-agent-helper >/dev/null
then
else
    $debsystemctl restart device-agent-helper >/dev/null || true
fi

And a shellcheck output to confirm that bash/dash/sh can't handle the above if-test:

-> $ shellcheck test.sh
In test.sh line 5:
if ! systemctl is-enabled device-agent-helper >/dev/null
^-- SC1009: The mentioned syntax error was in this if expression.
In test.sh line 6:
then
^-- SC1073: Couldn't parse this then clause. Fix to allow more checks.
In test.sh line 7:
else
^-- SC1048: Can't have empty then clauses (use 'true' as a no-op).
    ^-- SC1072: Unexpected keyword/token. Fix any mentioned problems and try again.
For more information:
  https://www.shellcheck.net/wiki/SC1048 -- Can't have empty then clauses (us...
  https://www.shellcheck.net/wiki/SC1072 -- Unexpected keyword/token. Fix any...
  https://www.shellcheck.net/wiki/SC1073 -- Couldn't parse this then clause. ...

It's obvious to me this can currently happen on latest version (this commit) of templates/deb/postinst_upgrade.sh.erb.
Ref:

if ! systemctl is-enabled <%= service %> >/dev/null 
then
<% if attributes[:deb_systemd_enable?]-%>
    systemctl enable <%= service %> >/dev/null || true
<% end -%>
<% if attributes[:deb_systemd_auto_start?]-%>
    $debsystemctl start <%= service %> >/dev/null || true
<% end -%>
<% if attributes[:deb_systemd_restart_after_upgrade?] -%>
else
    $debsystemctl restart <%= service %> >/dev/null || true
<% end -%>
fi
@x10an14
Copy link
Author

x10an14 commented Jan 25, 2021

Maybe #1750 is related?

@Forage
Copy link

Forage commented May 15, 2021

Duplicate of #1749

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants