Skip to content

Commit 7b38025

Browse files
authored
Refactor: Stirling-PDF (#5872)
1 parent 3914c0f commit 7b38025

File tree

3 files changed

+159
-102
lines changed

3 files changed

+159
-102
lines changed

ct/stirling-pdf.sh

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,41 @@ function update_script() {
2727
msg_error "No ${APP} Installation Found!"
2828
exit
2929
fi
30-
msg_info "Updating ${APP}"
31-
systemctl stop stirlingpdf
32-
if [[ -n $(dpkg -l | grep -w ocrmypdf) ]] && [[ -z $(dpkg -l | grep -w qpdf) ]]; then
33-
$STD apt-get remove -y ocrmypdf
34-
$STD apt-get install -y qpdf
30+
RELEASE=$(curl -fsSL https://api.github.com/repos/Stirling-Tools/Stirling-PDF/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }')
31+
if [[ "${RELEASE}" != "$(cat ~/.stirling-pdf 2>/dev/null)" ]] || [[ ! -f ~/.stirling-pdf ]]; then
32+
if [[ ! -f /etc/systemd/system/unoserver.service ]]; then
33+
msg_custom "⚠️ " "\e[33m" "Legacy installation detected – please recreate the container using the latest install script."
34+
exit 0
35+
fi
36+
37+
PYTHON_VERSION="3.12" setup_uv
38+
JAVA_VERSION="21" setup_java
39+
40+
msg_info "Stopping Services"
41+
systemctl stop stirlingpdf libreoffice-listener unoserver
42+
msg_ok "Stopped Services"
43+
44+
if [[ -f ~/.Stirling-PDF-login ]]; then
45+
USE_ORIGINAL_FILENAME=true fetch_and_deploy_gh_release "stirling-pdf" "Stirling-Tools/Stirling-PDF" "singlefile" "latest" "/opt/Stirling-PDF" "Stirling-PDF-with-login.jar"
46+
mv /opt/Stirling-PDF/Stirling-PDF-with-login.jar /opt/Stirling-PDF/Stirling-PDF.jar
47+
else
48+
USE_ORIGINAL_FILENAME=true fetch_and_deploy_gh_release "stirling-pdf" "Stirling-Tools/Stirling-PDF" "singlefile" "latest" "/opt/Stirling-PDF" "Stirling-PDF.jar"
49+
fi
50+
51+
msg_info "Refreshing Font Cache"
52+
$STD fc-cache -fv
53+
msg_ok "Font Cache Updated"
54+
55+
msg_info "Starting Services"
56+
systemctl start stirlingpdf libreoffice-listener unoserver
57+
msg_ok "Started Services"
58+
59+
msg_ok "Update Successful"
60+
else
61+
msg_ok "No update required. ${APP} is already at v${RELEASE}"
3562
fi
36-
RELEASE=$(curl -fsSL https://api.github.com/repos/Stirling-Tools/Stirling-PDF/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
37-
curl -fsSL "https://github.com/Stirling-Tools/Stirling-PDF/archive/refs/tags/v$RELEASE.tar.gz" -o $(basename "https://github.com/Stirling-Tools/Stirling-PDF/archive/refs/tags/v$RELEASE.tar.gz")
38-
tar -xzf v$RELEASE.tar.gz
39-
cd Stirling-PDF-$RELEASE
40-
chmod +x ./gradlew
41-
$STD ./gradlew build -x spotlessApply -x spotlessCheck -x test -x sonarqube
42-
rm -rf /opt/Stirling-PDF/Stirling-PDF-*.jar
43-
cp -r ./stirling-pdf/build/libs/*.jar /opt/Stirling-PDF/Stirling-PDF-$RELEASE.jar
44-
cp -r scripts /opt/Stirling-PDF/
45-
cp -r pipeline /opt/Stirling-PDF/
46-
cp -r stirling-pdf/src/main/resources/static/fonts/*.ttf /usr/share/fonts/opentype/noto/
47-
cd ~
48-
rm -rf Stirling-PDF-$RELEASE v$RELEASE.tar.gz
49-
ln -sf /opt/Stirling-PDF/Stirling-PDF-$RELEASE.jar /opt/Stirling-PDF/Stirling-PDF.jar
50-
systemctl start stirlingpdf
51-
msg_ok "Updated ${APP} to v$RELEASE"
5263
exit
5364
}
54-
5565
start
5666
build_container
5767
description

frontend/public/json/stirling-pdf.json

Lines changed: 33 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

install/stirling-pdf-install.sh

Lines changed: 94 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ update_os
1515

1616
msg_info "Installing Dependencies (Patience)"
1717
$STD apt-get install -y \
18-
git \
1918
automake \
2019
autoconf \
2120
libtool \
@@ -25,10 +24,26 @@ $STD apt-get install -y \
2524
make \
2625
g++ \
2726
unpaper \
27+
fonts-urw-base35 \
2828
qpdf \
2929
poppler-utils
3030
msg_ok "Installed Dependencies"
3131

32+
PYTHON_VERSION="3.12" setup_uv
33+
JAVA_VERSION="21" setup_java
34+
35+
read -r -p "${TAB3}Do you want to Stirling-PDF with Login? (no/n = without Login) [Y/n] " response
36+
response=${response,,} # Convert to lowercase
37+
login_mode="false"
38+
if [[ "$response" == "y" || "$response" == "yes" || -z "$response" ]]; then
39+
USE_ORIGINAL_FILENAME=true fetch_and_deploy_gh_release "stirling-pdf" "Stirling-Tools/Stirling-PDF" "singlefile" "latest" "/opt/Stirling-PDF" "Stirling-PDF-with-login.jar"
40+
mv /opt/Stirling-PDF/Stirling-PDF-with-login.jar /opt/Stirling-PDF/Stirling-PDF.jar
41+
touch ~/.Stirling-PDF-login
42+
login_mode="true"
43+
else
44+
USE_ORIGINAL_FILENAME=true fetch_and_deploy_gh_release "stirling-pdf" "Stirling-Tools/Stirling-PDF" "singlefile" "latest" "/opt/Stirling-PDF" "Stirling-PDF.jar"
45+
fi
46+
3247
msg_info "Installing LibreOffice Components"
3348
$STD apt-get install -y \
3449
libreoffice-writer \
@@ -37,32 +52,35 @@ $STD apt-get install -y \
3752
libreoffice-core \
3853
libreoffice-common \
3954
libreoffice-base-core \
40-
python3-uno
55+
libreoffice-script-provider-python \
56+
libreoffice-java-common \
57+
unoconv \
58+
pngquant \
59+
weasyprint
4160
msg_ok "Installed LibreOffice Components"
4261

4362
msg_info "Installing Python Dependencies"
44-
$STD apt-get install -y \
45-
python3 \
46-
python3-pip
47-
rm -rf /usr/lib/python3.*/EXTERNALLY-MANAGED
48-
$STD pip3 install \
49-
uno \
63+
mkdir -p /tmp/stirling-pdf
64+
$STD uv venv /opt/.venv
65+
export PATH="/opt/.venv/bin:$PATH"
66+
source /opt/.venv/bin/activate
67+
$STD uv pip install --upgrade pip
68+
$STD uv pip install \
5069
opencv-python-headless \
51-
unoconv \
52-
pngquant \
53-
WeasyPrint
70+
ocrmypdf \
71+
pillow \
72+
pdf2image
73+
74+
$STD apt-get install -y python3-uno python3-pip
75+
$STD pip3 install --break-system-packages unoserver
76+
ln -sf /opt/.venv/bin/python3 /usr/local/bin/python3
77+
ln -sf /opt/.venv/bin/pip /usr/local/bin/pip
5478
msg_ok "Installed Python Dependencies"
5579

56-
msg_info "Installing Azul Zulu"
57-
curl -fsSL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xB1998361219BD9C9" -o "/etc/apt/trusted.gpg.d/zulu-repo.asc"
58-
curl -fsSL "https://cdn.azul.com/zulu/bin/zulu-repo_1.0.0-3_all.deb" -o "/zulu-repo_1.0.0-3_all.deb"
59-
$STD dpkg -i zulu-repo_1.0.0-3_all.deb
60-
$STD apt-get update
61-
$STD apt-get -y install zulu17-jdk
62-
msg_ok "Installed Azul Zulu"
63-
6480
msg_info "Installing JBIG2"
65-
$STD git clone https://github.com/agl/jbig2enc /opt/jbig2enc
81+
$STD curl -fsSL -o /tmp/jbig2enc.tar.gz https://github.com/agl/jbig2enc/archive/refs/tags/0.30.tar.gz
82+
mkdir -p /opt/jbig2enc
83+
tar -xzf /tmp/jbig2enc.tar.gz -C /opt/jbig2enc --strip-components=1
6684
cd /opt/jbig2enc
6785
$STD bash ./autogen.sh
6886
$STD bash ./configure
@@ -74,25 +92,46 @@ msg_info "Installing Language Packs (Patience)"
7492
$STD apt-get install -y 'tesseract-ocr-*'
7593
msg_ok "Installed Language Packs"
7694

77-
msg_info "Installing Stirling-PDF (Additional Patience)"
78-
RELEASE=$(curl -fsSL https://api.github.com/repos/Stirling-Tools/Stirling-PDF/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
79-
curl -fsSL "https://github.com/Stirling-Tools/Stirling-PDF/archive/refs/tags/v${RELEASE}.tar.gz" -o "v${RELEASE}.tar.gz"
80-
tar -xzf v${RELEASE}.tar.gz
81-
cd Stirling-PDF-$RELEASE
82-
chmod +x ./gradlew
83-
$STD ./gradlew build -x spotlessApply -x spotlessCheck -x test -x sonarqube
84-
mkdir -p /opt/Stirling-PDF
85-
touch /opt/Stirling-PDF/.env
86-
mv ./stirling-pdf/build/libs/*.jar /opt/Stirling-PDF/Stirling-PDF-$RELEASE.jar
87-
mv scripts /opt/Stirling-PDF/
88-
mv pipeline /opt/Stirling-PDF/
89-
mv stirling-pdf/src/main/resources/static/fonts/*.ttf /usr/share/fonts/opentype/noto/
90-
ln -s /opt/Stirling-PDF/Stirling-PDF-$RELEASE.jar /opt/Stirling-PDF/Stirling-PDF.jar
91-
ln -s /usr/share/tesseract-ocr/5/tessdata/ /usr/share/tessdata
92-
msg_ok "Installed Stirling-PDF"
95+
msg_info "Creating Environment Variables"
96+
cat <<EOF >/opt/Stirling-PDF/.env
97+
# Java tuning
98+
JAVA_BASE_OPTS="-XX:+UnlockExperimentalVMOptions -XX:MaxRAMPercentage=75 -XX:InitiatingHeapOccupancyPercent=20 -XX:+G1PeriodicGCInvokesConcurrent -XX:G1PeriodicGCInterval=10000 -XX:+UseStringDeduplication -XX:G1PeriodicGCSystemLoadThreshold=70"
99+
JAVA_CUSTOM_OPTS=""
100+
101+
# LibreOffice
102+
PATH=/opt/.venv/bin:/usr/lib/libreoffice/program:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
103+
UNO_PATH=/usr/lib/libreoffice/program
104+
URE_BOOTSTRAP=file:///usr/lib/libreoffice/program/fundamentalrc
105+
PYTHONPATH=/usr/lib/libreoffice/program:/opt/.venv/lib/python3.12/site-packages
106+
LD_LIBRARY_PATH=/usr/lib/libreoffice/program
107+
108+
STIRLING_TEMPFILES_DIRECTORY=/tmp/stirling-pdf
109+
TMPDIR=/tmp/stirling-pdf
110+
TEMP=/tmp/stirling-pdf
111+
TMP=/tmp/stirling-pdf
112+
113+
# Paths
114+
PATH=/opt/.venv/bin:/usr/lib/libreoffice/program:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
115+
EOF
116+
117+
if [[ "$login_mode" == "true" ]]; then
118+
cat <<EOF >>/opt/Stirling-PDF/.env
119+
# activate Login
120+
DISABLE_ADDITIONAL_FEATURES=false
121+
SECURITY_ENABLELOGIN=true
122+
123+
# login credentials
124+
SECURITY_INITIALLOGIN_USERNAME=admin
125+
SECURITY_INITIALLOGIN_PASSWORD=stirling
126+
EOF
127+
fi
128+
msg_ok "Created Environment Variables"
129+
130+
msg_info "Refreshing Font Cache"
131+
$STD fc-cache -fv
132+
msg_ok "Font Cache Updated"
93133

94134
msg_info "Creating Service"
95-
# Create LibreOffice listener service
96135
cat <<EOF >/etc/systemd/system/libreoffice-listener.service
97136
[Unit]
98137
Description=LibreOffice Headless Listener Service
@@ -109,14 +148,6 @@ Restart=always
109148
WantedBy=multi-user.target
110149
EOF
111150

112-
# Set up environment variables
113-
cat <<EOF >/opt/Stirling-PDF/.env
114-
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/libreoffice/program
115-
UNO_PATH=/usr/lib/libreoffice/program
116-
PYTHONPATH=/usr/lib/python3/dist-packages:/usr/lib/libreoffice/program
117-
LD_LIBRARY_PATH=/usr/lib/libreoffice/program
118-
EOF
119-
120151
cat <<EOF >/etc/systemd/system/stirlingpdf.service
121152
[Unit]
122153
Description=Stirling-PDF service
@@ -139,16 +170,32 @@ RestartSec=10
139170
WantedBy=multi-user.target
140171
EOF
141172

142-
# Enable and start services
173+
cat <<EOF >/etc/systemd/system/unoserver.service
174+
[Unit]
175+
Description=UnoServer RPC Interface
176+
After=libreoffice-listener.service
177+
Requires=libreoffice-listener.service
178+
179+
[Service]
180+
Type=simple
181+
ExecStart=/usr/local/bin/unoserver --port 2003 --interface 127.0.0.1
182+
Restart=always
183+
EnvironmentFile=/opt/Stirling-PDF/.env
184+
185+
[Install]
186+
WantedBy=multi-user.target
187+
EOF
188+
143189
systemctl enable -q --now libreoffice-listener
144190
systemctl enable -q --now stirlingpdf
191+
systemctl enable -q --now unoserver
145192
msg_ok "Created Service"
146193

147194
motd_ssh
148195
customize
149196

150197
msg_info "Cleaning up"
151-
rm -rf v${RELEASE}.tar.gz /zulu-repo_1.0.0-3_all.deb
198+
rm -f /tmp/jbig2enc.tar.gz
152199
$STD apt-get -y autoremove
153200
$STD apt-get -y autoclean
154201
msg_ok "Cleaned"

0 commit comments

Comments
 (0)