Skip to content

Commit 2dd0624

Browse files
committed
new package: stirling-pdf
1 parent 5dde14f commit 2dd0624

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

tur/stirling-pdf/build.sh

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
TERMUX_PKG_HOMEPAGE=https://github.com/Stirling-Tools/Stirling-PDF
2+
TERMUX_PKG_DESCRIPTION="Locally hosted web application that allows you to perform various operations on PDF files"
3+
TERMUX_PKG_LICENSE="MIT"
4+
TERMUX_PKG_MAINTAINER="@termux-user-repository"
5+
TERMUX_PKG_VERSION=0.28.3
6+
TERMUX_PKG_SRCURL=https://github.com/Stirling-Tools/Stirling-PDF/releases/download/v${TERMUX_PKG_VERSION}/Stirling-PDF-with-login.jar
7+
TERMUX_PKG_SHA256=ce9c206f9724018608efed774fdbce8de811636557aaf345b116b44f0191fdea
8+
TERMUX_PKG_DEPENDS="ghostscript, jbig2enc, jbig2enc-static, opencv, opencv-python, openjdk-17, openjdk-17-x, pngquant, python, python-cryptography, qpdf, tesseract, unpaper, xdg-utils"
9+
TERMUX_PKG_ANTI_BUILD_DEPENDS="ghostscript, jbig2enc, jbig2enc-static, opencv, opencv-python, openjdk-17, openjdk-17-x, pngquant, python, python-cryptography, qpdf, tesseract, unpaper, xdg-utils"
10+
TERMUX_PKG_AUTO_UPDATE=true
11+
TERMUX_PKG_PLATFORM_INDEPENDENT=true
12+
TERMUX_PKG_PYTHON_TARGET_DEPS="ocrmypdf"
13+
14+
15+
termux_step_get_source() {
16+
mkdir -p $TERMUX_PKG_SRCDIR
17+
termux_download https://raw.githubusercontent.com/Stirling-Tools/Stirling-PDF/main/LICENSE $TERMUX_PKG_SRCDIR/LICENSE 611928245256338754a280bae34bb85b9d7666b9d0f33538a6d2d15f3bca2796
18+
local install_prefix="$TERMUX_PREFIX/share/$TERMUX_PKG_NAME"
19+
rm -rf "$install_prefix"
20+
mkdir -p "$install_prefix"
21+
termux_download $TERMUX_PKG_SRCURL \
22+
"$install_prefix/$TERMUX_PKG_NAME-$TERMUX_PKG_VERSION.jar" \
23+
$TERMUX_PKG_SHA256
24+
}
25+
26+
termux_step_make() {
27+
local installed_jar="$TERMUX_PREFIX/share/$TERMUX_PKG_NAME/$TERMUX_PKG_NAME-$TERMUX_PKG_VERSION.jar"
28+
29+
# patch the setting file tessdataDir
30+
local setting_file="BOOT-INF/classes/settings.yml.template"
31+
mkdir -p "patched/$(dirname $setting_file)"
32+
unzip -p "$installed_jar" "$setting_file" > "patched/$setting_file"
33+
sed -i "s|/usr/|$TERMUX_PREFIX/|g" "patched/$setting_file"
34+
zip -ur "$installed_jar" patched/
35+
36+
# executable files
37+
local runtime_dir="$TERMUX_PREFIX/var/lib/stirling-pdf"
38+
cat <<- EOF > $TERMUX_PREFIX/bin/$TERMUX_PKG_NAME
39+
#!$TERMUX_PREFIX/bin/env sh
40+
41+
cd "$runtime_dir"
42+
exec \$JAVA_HOME/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.desktop/javax.swing=ALL-UNNAMED -jar $installed_jar "\$@"
43+
EOF
44+
cat <<- EOF > $TERMUX_PREFIX/bin/$TERMUX_PKG_NAME-webui
45+
#!$TERMUX_PREFIX/bin/env sh
46+
47+
url_opened=false
48+
cd "$runtime_dir"
49+
50+
exec \$JAVA_HOME/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.desktop/javax.swing=ALL-UNNAMED -jar $installed_jar "\$@" | while IFS= read -r line; do
51+
echo "\$line"
52+
if echo "\$line" | grep -qE 'http://localhost:[0-9]+'; then
53+
url=\$(echo "\$line" | grep -oE 'http://localhost:[0-9]+')
54+
if [ "\$url_opened" = false ]; then
55+
xdg-utils-xdg-open "\$url"
56+
url_opened=true
57+
fi
58+
fi
59+
done
60+
EOF
61+
chmod +x $TERMUX_PREFIX/bin/$TERMUX_PKG_NAME
62+
chmod +x $TERMUX_PREFIX/bin/$TERMUX_PKG_NAME-webui
63+
64+
# other misc files
65+
install -Dm644 -t "${TERMUX_PREFIX}/share/applications" "${TERMUX_PKG_BUILDER_DIR}/$TERMUX_PKG_NAME.desktop"
66+
mkdir -p "$TERMUX_PREFIX/share/pixmaps"
67+
unzip -p "$installed_jar" BOOT-INF/classes/static/favicon.svg > "$TERMUX_PREFIX/share/pixmaps/$TERMUX_PKG_NAME.svg"
68+
}
69+
70+
termux_step_create_debscripts() {
71+
local runtime_dir="$TERMUX_PREFIX/var/lib/stirling-pdf"
72+
cat <<- EOF > ./postinst
73+
#!${TERMUX_PREFIX}/bin/bash
74+
75+
echo "mkdir $runtime_dir"
76+
rm -rf "$runtime_dir"
77+
mkdir -p "$runtime_dir"
78+
79+
echo "Installing dependencies through pip..."
80+
pip install --upgrade ${TERMUX_PKG_PYTHON_TARGET_DEPS//, / }
81+
EOF
82+
# Pre-rm script to cleanup runtime-generated files.
83+
cat <<- PRERM_EOF > ./prerm
84+
#!$TERMUX_PREFIX/bin/sh
85+
echo "Deleting all files under $runtime_dir"
86+
rm -Rf "$runtime_dir"
87+
exit 0
88+
PRERM_EOF
89+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[Desktop Entry]
2+
Name=Stirling PDF
3+
GenericName=Launch StirlingPDF and open its WebGUI
4+
Categories=Office;
5+
Exec=stirling-pdf-webui
6+
Keywords=pdf
7+
Icon=stirling-pdf
8+
Type=Application
9+
NoDisplay=false
10+
Terminal=true

0 commit comments

Comments
 (0)