Skip to content

Commit c53560a

Browse files
Determine upgrades correctly for deb packages (elastic#75010) (elastic#75074)
We are using the `-n` bash operator to determine whether a second argument is passed to the `postinst` script during installation of our DEB packages. The reasoning is that we want to differentiate between installations and upgrades and a second argument to postinst is only passed when this is an upgrade ( the identifier of the version the package is upgraded to ). The problem is that we use `-n` without quoting the $2 and this is unsafe practice as it might yield unexpected results for `-n` and `-z` operators used within test brackets. Testing with bash 5.0-6ubuntu1.1 `[ -n $2 ]` returns false both for upgrades and installations, while `[ -n "$2" ]` behaves as expected. References: https://tldp.org/LDP/abs/html/comparison-ops.html https://wiki.debian.org/MaintainerScripts
1 parent cc9db89 commit c53560a

File tree

1 file changed

+1
-1
lines changed
  • distribution/packages/src/common/scripts

1 file changed

+1
-1
lines changed

distribution/packages/src/common/scripts/postinst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ case "$1" in
2323
configure)
2424

2525
# If $1=configure and $2 is set, this is an upgrade
26-
if [ -n $2 ]; then
26+
if [ -n "$2" ]; then
2727
IS_UPGRADE=true
2828
fi
2929
PACKAGE=deb

0 commit comments

Comments
 (0)