intoolswetrust/jsignpdf

jsignpdf.sh is not posix compliant, fails in automated CI with busybox (patch included)

denydias opened this issue · 0 comments

When running JSignPdf in automated CI environments with busybox shell, it fails with the following messages:

$> /opt/jsignpdf-2.2.2/jsignpdf.sh --version
readlink: unrecognized option: e
BusyBox v1.35.0 (2022-11-19 10:13:10 UTC) multi-call binary.

Usage: readlink [-fnv] FILE

Display the value of a symlink

	-f	Canonicalize by following all symlinks
	-n	Don't add newline
	-v	Verbose
Error: Could not find or load main class net.sf.jsignpdf.JavaVersion
Caused by: java.lang.ClassNotFoundException: net.sf.jsignpdf.JavaVersion
/opt/jsignpdf-2.2.2/jsignpdf.sh: line 14: [: : integer expression expected
Error: Unable to access jarfile /builds/JSignPdf.jar

This happens because jsignpdf.sh is not posix compliant and busybox has a hard time handling it.

To make it posix compliant the patch bellow should be applied:

--- a/jsignpdf.sh 2023-09-07 15:35:43.992441573 -0300
+++ b/jsignpdf.sh 2023-09-07 16:03:38.602388875 -0300
@@ -1,9 +1,11 @@
-#!/bin/bash
+#!/bin/sh

-DIRNAME=$(dirname "$(readlink -e "$0")")
+DIRNAME=$(dirname "$(readlink -f "$0")")
 DIR=$(cd "$DIRNAME" || exit 112; pwd)

-[ "$OSTYPE" = "cygwin" ] && DIR="$( cygpath -m "$DIR" )"
+if uname -s | grep -i cygwin; then
+  DIR="$( cygpath -m "$DIR" )"
+fi

 JAVA=java
 if [ -n "$JAVA_HOME" ]; then

Then:

$> /opt/jsignpdf-2.2.2/jsignpdf.sh --version
JSignPdf version 2.2.2