Refactor: Paperless-ngx (#6938)

* Refactor: Paperless-NGX

* Refactor: Paperless-ngx

* Update paperless-ngx.json

* VED -> VE

* harmonize with VED

* finalize

* Update paperless-ngx.json

* finalize

* fix: casing

---------

Co-authored-by: Tobias <96661824+CrazyWolf13@users.noreply.github.com>
This commit is contained in:
CanbiZ 2025-08-20 15:18:05 +02:00 committed by GitHub
parent 19403a627b
commit c783024ef0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 154 additions and 140 deletions

View File

@ -9,7 +9,7 @@ APP="Paperless-ngx"
var_tags="${var_tags:-document;management}"
var_cpu="${var_cpu:-2}"
var_ram="${var_ram:-2048}"
var_disk="${var_disk:-10}"
var_disk="${var_disk:-12}"
var_os="${var_os:-debian}"
var_version="${var_version:-12}"
var_unprivileged="${var_unprivileged:-1}"
@ -20,70 +20,115 @@ color
catch_errors
function update_script() {
header_info
check_container_storage
check_container_resources
if [[ ! -d /opt/paperless ]]; then
msg_error "No ${APP} Installation Found!"
exit
fi
RELEASE=$(curl -fsSL https://api.github.com/repos/paperless-ngx/paperless-ngx/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }')
if ! command -v jq &>/dev/null; then
$STD apt-get install -y jq
fi
RELEASE=$(curl -fsSL https://api.github.com/repos/paperless-ngx/paperless-ngx/releases/latest | jq -r .tag_name | sed 's/^v//')
if [[ "${RELEASE}" != "$(cat ~/.paperless 2>/dev/null)" ]] || [[ ! -f ~/.paperless ]]; then
msg_info "Stopping all Paperless-ngx Services"
systemctl stop paperless-consumer paperless-webserver paperless-scheduler paperless-task-queue
msg_ok "Stopped all Paperless-ngx Services"
UPD=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "SUPPORT" --radiolist --cancel-button Exit-Script "Spacebar = Select" 11 58 2 \
"1" "Update Paperless-ngx to $RELEASE" ON \
"2" "Paperless-ngx Credentials" OFF \
3>&1 1>&2 2>&3)
header_info
check_container_storage
check_container_resources
if [ "$UPD" == "1" ]; then
if [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]] || [[ ! -f /opt/${APP}_version.txt ]]; then
if [[ "$(gs --version 2>/dev/null)" != "10.04.0" ]]; then
msg_info "Updating Ghostscript (Patience)"
cd /tmp
curl -fsSL "https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs10040/ghostscript-10.04.0.tar.gz" -o $(basename "https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs10040/ghostscript-10.04.0.tar.gz")
tar -xzf ghostscript-10.04.0.tar.gz
cd ghostscript-10.04.0
$STD ./configure
$STD make
$STD sudo make install
rm -rf /tmp/ghostscript*
msg_ok "Ghostscript updated to 10.04.0"
fi
msg_info "Stopping all Paperless-ngx Services"
systemctl stop paperless-consumer paperless-webserver paperless-scheduler paperless-task-queue.service
msg_ok "Stopped all Paperless-ngx Services"
if grep -q "uv run" /etc/systemd/system/paperless-webserver.service; then
msg_info "Backing up data"
mkdir -p /opt/paperless/backup
cp -r /opt/paperless/data /opt/paperless/backup/
cp -r /opt/paperless/media /opt/paperless/backup/
cp -r /opt/paperless/paperless.conf /opt/paperless/backup/
msg_ok "Backup completed"
PYTHON_VERSION="3.13" setup_uv
fetch_and_deploy_gh_release "paperless" "paperless-ngx/paperless-ngx" "prebuild" "latest" "/opt/paperless" "paperless*tar.xz"
fetch_and_deploy_gh_release "jbig2enc" "ie13/jbig2enc" "tarball" "latest" "/opt/jbig2enc"
setup_gs
msg_info "Updating to ${RELEASE}"
cd ~
curl -fsSL "https://github.com/paperless-ngx/paperless-ngx/releases/download/$RELEASE/paperless-ngx-$RELEASE.tar.xz" -o $(basename "https://github.com/paperless-ngx/paperless-ngx/releases/download/$RELEASE/paperless-ngx-$RELEASE.tar.xz")
tar -xf paperless-ngx-$RELEASE.tar.xz
cp -r /opt/paperless/paperless.conf paperless-ngx/
cp -r paperless-ngx/* /opt/paperless/
cp -r /opt/paperless/backup/* /opt/paperless/
cd /opt/paperless
$STD pip install -r requirements.txt
$STD uv sync --all-extras
cd /opt/paperless/src
$STD /usr/bin/python3 manage.py migrate
echo "${RELEASE}" >/opt/${APP}_version.txt
$STD uv run -- python manage.py migrate
msg_ok "Updated to ${RELEASE}"
msg_info "Cleaning up"
cd ~
rm paperless-ngx-$RELEASE.tar.xz
rm -rf paperless-ngx
msg_ok "Cleaned"
msg_info "Starting all Paperless-ngx Services"
systemctl start paperless-consumer paperless-webserver paperless-scheduler paperless-task-queue.service
sleep 1
msg_ok "Started all Paperless-ngx Services"
msg_ok "Updated Successfully!\n"
else
msg_ok "No update required. ${APP} is already at ${RELEASE}"
msg_warn "You are about to migrate your Paperless-ngx installation to uv!"
msg_custom "🔒" "It is strongly recommended to take a Proxmox snapshot first:"
echo -e " 1. Stop the container: pct stop <CTID>"
echo -e " 2. Create a snapshot: pct snapshot <CTID> pre-paperless-uv-migration"
echo -e " 3. Start the container again\n"
read -rp "Have you created a snapshot? [y/N]: " confirm
if [[ ! "$confirm" =~ ^([yY]|[yY][eE][sS])$ ]]; then
msg_error "Migration aborted. Please create a snapshot first."
exit 1
fi
msg_info "Migrating old Paperless-ngx installation to uv"
rm -rf /opt/paperless/venv
find /opt/paperless -name "__pycache__" -type d -exec rm -rf {} +
declare -A PATCHES=(
["paperless-consumer.service"]="ExecStart=uv run -- python manage.py document_consumer"
["paperless-scheduler.service"]="ExecStart=uv run -- celery --app paperless beat --loglevel INFO"
["paperless-task-queue.service"]="ExecStart=uv run -- celery --app paperless worker --loglevel INFO"
["paperless-webserver.service"]="ExecStart=uv run -- granian --interface asgi --ws \"paperless.asgi:application\""
)
for svc in "${!PATCHES[@]}"; do
path=$(systemctl show -p FragmentPath "$svc" | cut -d= -f2)
if [[ -n "$path" && -f "$path" ]]; then
sed -i "s|^ExecStart=.*|${PATCHES[$svc]}|" "$path"
if [[ "$svc" == "paperless-webserver.service" ]]; then
grep -q "^Environment=GRANIAN_HOST=" "$path" ||
sed -i '/^\[Service\]/a Environment=GRANIAN_HOST=::' "$path"
grep -q "^Environment=GRANIAN_PORT=" "$path" ||
sed -i '/^\[Service\]/a Environment=GRANIAN_PORT=8000' "$path"
grep -q "^Environment=GRANIAN_WORKERS=" "$path" ||
sed -i '/^\[Service\]/a Environment=GRANIAN_WORKERS=1' "$path"
fi
msg_ok "Patched $svc"
else
msg_error "Service file for $svc not found!"
fi
done
$STD systemctl daemon-reload
msg_info "Backing up data"
mkdir -p /opt/paperless/backup
cp -r /opt/paperless/data /opt/paperless/backup/
cp -r /opt/paperless/media /opt/paperless/backup/
cp -r /opt/paperless/paperless.conf /opt/paperless/backup/
msg_ok "Backup completed"
PYTHON_VERSION="3.13" setup_uv
fetch_and_deploy_gh_release "paperless" "paperless-ngx/paperless-ngx" "prebuild" "latest" "/opt/paperless" "paperless*tar.xz"
fetch_and_deploy_gh_release "jbig2enc" "ie13/jbig2enc" "tarball" "latest" "/opt/jbig2enc"
setup_gs
msg_info "Updating Paperless-ngx"
cp -r /opt/paperless/backup/* /opt/paperless/
cd /opt/paperless
$STD uv sync --all-extras
cd /opt/paperless/src
$STD uv run -- python manage.py migrate
msg_ok "Paperless-ngx migration and update to ${RELEASE} completed"
fi
exit
fi
if [ "$UPD" == "2" ]; then
cat paperless.creds
exit
msg_info "Starting all Paperless-ngx Services"
systemctl start paperless-consumer paperless-webserver paperless-scheduler paperless-task-queue
sleep 1
msg_ok "Started all Paperless-ngx Services"
msg_ok "Updated Successfully!\n"
else
msg_ok "No update required. ${APP} is already at v${RELEASE}"
fi
exit
}
start
@ -94,3 +139,4 @@ msg_ok "Completed Successfully!\n"
echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}"
echo -e "${INFO}${YW} Access it using the following URL:${CL}"
echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:8000${CL}"

View File

@ -9,7 +9,7 @@
"updateable": true,
"privileged": false,
"interface_port": 8000,
"documentation": null,
"documentation": "https://docs.paperless-ngx.com/",
"website": "https://docs.paperless-ngx.com/",
"logo": "https://cdn.jsdelivr.net/gh/selfhst/icons/webp/paperless-ngx.webp",
"config_path": "/opt/paperless/paperless.conf",
@ -21,19 +21,19 @@
"resources": {
"cpu": 2,
"ram": 2048,
"hdd": 10,
"hdd": 12,
"os": "debian",
"version": "12"
}
}
],
"default_credentials": {
"username": null,
"username": "admin",
"password": null
},
"notes": [
{
"text": "Show Login Credentials, type `update` in the LXC console",
"text": "Show Login Credentials, type `cat ~/paperless.creds` in the LXC console",
"type": "info"
},
{

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
# Copyright (c) 2021-2025 tteck
# Author: tteck (tteckster)
# Author: tteck (tteckster) | MickLesk (CanbiZ)
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
# Source: https://docs.paperless-ngx.com/
@ -29,22 +29,16 @@ $STD apt-get install -y \
automake \
libtool \
pkg-config \
git \
libtiff-dev \
libpng-dev \
libleptonica-dev
msg_ok "Installed Dependencies"
PG_VERSION="16" setup_postgresql
msg_info "Setup Python3"
$STD apt-get install -y \
python3 \
python3-pip \
python3-dev \
python3-setuptools \
python3-wheel
msg_ok "Setup Python3"
PYTHON_VERSION="3.13" setup_uv
fetch_and_deploy_gh_release "paperless" "paperless-ngx/paperless-ngx" "prebuild" "latest" "/opt/paperless" "paperless*tar.xz"
fetch_and_deploy_gh_release "jbig2enc" "ie13/jbig2enc" "tarball" "latest" "/opt/jbig2enc"
setup_gs
msg_info "Installing OCR Dependencies (Patience)"
$STD apt-get install -y \
@ -57,18 +51,10 @@ $STD apt-get install -y \
zlib1g \
tesseract-ocr \
tesseract-ocr-eng
cd /tmp
curl -fsSL "https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs10040/ghostscript-10.04.0.tar.gz" -o "ghostscript-10.04.0.tar.gz"
$STD tar -xzf ghostscript-10.04.0.tar.gz
cd ghostscript-10.04.0
$STD ./configure
$STD make
$STD sudo make install
msg_ok "Installed OCR Dependencies"
msg_info "Installing JBIG2"
$STD git clone https://github.com/ie13/jbig2enc /opt/jbig2enc
msg_info "Setup JBIG2"
cd /opt/jbig2enc
$STD bash ./autogen.sh
$STD bash ./configure
@ -77,30 +63,6 @@ $STD make install
rm -rf /opt/jbig2enc
msg_ok "Installed JBIG2"
msg_info "Installing Paperless-ngx (Patience)"
Paperlessngx=$(curl -fsSL "https://github.com/paperless-ngx/paperless-ngx/releases/latest" | grep "title>Release" | cut -d " " -f 5)
cd /opt
$STD curl -fsSL "https://github.com/paperless-ngx/paperless-ngx/releases/download/$Paperlessngx/paperless-ngx-$Paperlessngx.tar.xz" -o "paperless-ngx-$Paperlessngx.tar.xz"
$STD tar -xf "paperless-ngx-$Paperlessngx.tar.xz" -C /opt/
mv paperless-ngx paperless
rm "paperless-ngx-$Paperlessngx.tar.xz"
cd /opt/paperless
$STD pip install --upgrade pip
$STD pip install -r requirements.txt
curl -fsSL "https://raw.githubusercontent.com/paperless-ngx/paperless-ngx/main/paperless.conf.example" -o /opt/paperless/paperless.conf
mkdir -p {consume,data,media,static}
sed -i -e 's|#PAPERLESS_REDIS=redis://localhost:6379|PAPERLESS_REDIS=redis://localhost:6379|' /opt/paperless/paperless.conf
sed -i -e "s|#PAPERLESS_CONSUMPTION_DIR=../consume|PAPERLESS_CONSUMPTION_DIR=/opt/paperless/consume|" /opt/paperless/paperless.conf
sed -i -e "s|#PAPERLESS_DATA_DIR=../data|PAPERLESS_DATA_DIR=/opt/paperless/data|" /opt/paperless/paperless.conf
sed -i -e "s|#PAPERLESS_MEDIA_ROOT=../media|PAPERLESS_MEDIA_ROOT=/opt/paperless/media|" /opt/paperless/paperless.conf
sed -i -e "s|#PAPERLESS_STATICDIR=../static|PAPERLESS_STATICDIR=/opt/paperless/static|" /opt/paperless/paperless.conf
echo "${Paperlessngx}" >/opt/"${APPLICATION}"_version.txt
msg_ok "Installed Paperless-ngx"
msg_info "Installing Natural Language Toolkit (Patience)"
$STD python3 -m nltk.downloader -d /usr/share/nltk_data all
msg_ok "Installed Natural Language Toolkit"
msg_info "Setting up PostgreSQL database"
DB_NAME=paperlessdb
DB_USER=paperless
@ -115,36 +77,36 @@ echo "" >>~/paperless.creds
echo -e "Paperless-ngx Database User: \e[32m$DB_USER\e[0m" >>~/paperless.creds
echo -e "Paperless-ngx Database Password: \e[32m$DB_PASS\e[0m" >>~/paperless.creds
echo -e "Paperless-ngx Database Name: \e[32m$DB_NAME\e[0m" >>~/paperless.creds
sed -i -e 's|#PAPERLESS_DBHOST=localhost|PAPERLESS_DBHOST=localhost|' /opt/paperless/paperless.conf
sed -i -e 's|#PAPERLESS_DBPORT=5432|PAPERLESS_DBPORT=5432|' /opt/paperless/paperless.conf
sed -i -e "s|#PAPERLESS_DBNAME=paperless|PAPERLESS_DBNAME=$DB_NAME|" /opt/paperless/paperless.conf
sed -i -e "s|#PAPERLESS_DBUSER=paperless|PAPERLESS_DBUSER=$DB_USER|" /opt/paperless/paperless.conf
sed -i -e "s|#PAPERLESS_DBPASS=paperless|PAPERLESS_DBPASS=$DB_PASS|" /opt/paperless/paperless.conf
sed -i -e "s|#PAPERLESS_SECRET_KEY=change-me|PAPERLESS_SECRET_KEY=$SECRET_KEY|" /opt/paperless/paperless.conf
cd /opt/paperless/src
$STD python3 manage.py migrate
msg_ok "Set up PostgreSQL database"
read -r -p "${TAB3}Would you like to add Adminer? <y/N> " prompt
if [[ "${prompt,,}" =~ ^(y|yes)$ ]]; then
msg_info "Installing Adminer"
$STD apt install -y adminer
$STD a2enconf adminer
systemctl reload apache2
IP=$(hostname -I | awk '{print $1}')
echo "" >>~/paperless.creds
echo -e "Adminer Interface: \e[32m$IP/adminer/\e[0m" >>~/paperless.creds
echo -e "Adminer System: \e[32mPostgreSQL\e[0m" >>~/paperless.creds
echo -e "Adminer Server: \e[32mlocalhost:5432\e[0m" >>~/paperless.creds
echo -e "Adminer Username: \e[32m$DB_USER\e[0m" >>~/paperless.creds
echo -e "Adminer Password: \e[32m$DB_PASS\e[0m" >>~/paperless.creds
echo -e "Adminer Database: \e[32m$DB_NAME\e[0m" >>~/paperless.creds
msg_ok "Installed Adminer"
fi
msg_info "Installing Natural Language Toolkit (Patience)"
$STD uv run -- python -m nltk.downloader -d /usr/share/nltk_data all
sed -i -e 's/rights="none" pattern="PDF"/rights="read|write" pattern="PDF"/' /etc/ImageMagick-6/policy.xml
msg_ok "Installed Natural Language Toolkit"
msg_info "Setup Paperless-ngx"
cd /opt/paperless
$STD uv sync --all-extras
curl -fsSL "https://raw.githubusercontent.com/paperless-ngx/paperless-ngx/main/paperless.conf.example" -o /opt/paperless/paperless.conf
mkdir -p {consume,data,media,static}
sed -i \
-e 's|#PAPERLESS_REDIS=redis://localhost:6379|PAPERLESS_REDIS=redis://localhost:6379|' \
-e "s|#PAPERLESS_CONSUMPTION_DIR=../consume|PAPERLESS_CONSUMPTION_DIR=/opt/paperless/consume|" \
-e "s|#PAPERLESS_DATA_DIR=../data|PAPERLESS_DATA_DIR=/opt/paperless/data|" \
-e "s|#PAPERLESS_MEDIA_ROOT=../media|PAPERLESS_MEDIA_ROOT=/opt/paperless/media|" \
-e "s|#PAPERLESS_STATICDIR=../static|PAPERLESS_STATICDIR=/opt/paperless/static|" \
-e 's|#PAPERLESS_DBHOST=localhost|PAPERLESS_DBHOST=localhost|' \
-e 's|#PAPERLESS_DBPORT=5432|PAPERLESS_DBPORT=5432|' \
-e "s|#PAPERLESS_DBNAME=paperless|PAPERLESS_DBNAME=$DB_NAME|" \
-e "s|#PAPERLESS_DBUSER=paperless|PAPERLESS_DBUSER=$DB_USER|" \
-e "s|#PAPERLESS_DBPASS=paperless|PAPERLESS_DBPASS=$DB_PASS|" \
-e "s|#PAPERLESS_SECRET_KEY=change-me|PAPERLESS_SECRET_KEY=$SECRET_KEY|" \
/opt/paperless/paperless.conf
cd /opt/paperless/src
$STD uv run -- python manage.py migrate
msg_ok "Setup Paperless-ngx"
msg_info "Setting up admin Paperless-ngx User & Password"
## From https://github.com/linuxserver/docker-paperless-ngx/blob/main/root/etc/cont-init.d/99-migrations
cat <<EOF | python3 /opt/paperless/src/manage.py shell
cat <<EOF | uv run -- python /opt/paperless/src/manage.py shell
from django.contrib.auth import get_user_model
UserModel = get_user_model()
user = UserModel.objects.create_user('admin', password='$DB_PASS')
@ -152,10 +114,15 @@ user.is_superuser = True
user.is_staff = True
user.save()
EOF
echo "" >>~/paperless.creds
echo -e "Paperless-ngx WebUI User: \e[32madmin\e[0m" >>~/paperless.creds
echo -e "Paperless-ngx WebUI Password: \e[32m$DB_PASS\e[0m" >>~/paperless.creds
echo "" >>~/paperless.creds
{
echo "Paperless-ngx-Credentials"
echo "Paperless-ngx Database Name: $DB_NAME"
echo "Paperless-ngx Database User: $DB_USER"
echo "Paperless-ngx Database Password: $DB_PASS"
echo "Paperless-ngx Secret Key: $SECRET_KEY\n"
echo "Paperless-ngx WebUI User: admin"
echo "Paperless-ngx WebUI Password: $DB_PASS"
} >>~/paperless-ngx.creds
msg_ok "Set up admin Paperless-ngx User & Password"
msg_info "Creating Services"
@ -166,7 +133,7 @@ Requires=redis.service
[Service]
WorkingDirectory=/opt/paperless/src
ExecStart=celery --app paperless beat --loglevel INFO
ExecStart=uv run -- celery --app paperless beat --loglevel INFO
[Install]
WantedBy=multi-user.target
@ -180,7 +147,7 @@ After=postgresql.service
[Service]
WorkingDirectory=/opt/paperless/src
ExecStart=celery --app paperless worker --loglevel INFO
ExecStart=uv run -- celery --app paperless worker --loglevel INFO
[Install]
WantedBy=multi-user.target
@ -194,7 +161,7 @@ Requires=redis.service
[Service]
WorkingDirectory=/opt/paperless/src
ExecStartPre=/bin/sleep 2
ExecStart=python3 manage.py document_consumer
ExecStart=uv run -- python manage.py document_consumer
[Install]
WantedBy=multi-user.target
@ -209,7 +176,7 @@ Requires=redis.service
[Service]
WorkingDirectory=/opt/paperless/src
ExecStart=granian --interface asginl --ws "paperless.asgi:application"
ExecStart=uv run -- granian --interface asginl --ws "paperless.asgi:application"
Environment=GRANIAN_HOST=::
Environment=GRANIAN_PORT=8000
Environment=GRANIAN_WORKERS=1
@ -217,13 +184,14 @@ Environment=GRANIAN_WORKERS=1
[Install]
WantedBy=multi-user.target
EOF
sed -i -e 's/rights="none" pattern="PDF"/rights="read|write" pattern="PDF"/' /etc/ImageMagick-6/policy.xml
systemctl daemon-reload
$STD systemctl enable -q --now paperless-webserver paperless-scheduler paperless-task-queue paperless-consumer
systemctl enable -q --now paperless-webserver paperless-scheduler paperless-task-queue paperless-consumer
msg_ok "Created Services"
read -r -p "${TAB3}Would you like to add Adminer? <y/N> " prompt
if [[ "${prompt,,}" =~ ^(y|yes)$ ]]; then
setup_adminer
fi
motd_ssh
customize