ProxmoxVED/install/papra-install.sh
CanbiZ (MickLesk) dcc6ab0437 refactor(papra): persist data in /opt/papra_data
- Move db, documents, ingestion to /opt/papra_data (survives CLEAN_INSTALL)
- Use absolute paths in .env
- Preserve AUTH_SECRET across updates (stored in .auth_secret file)
2026-01-21 17:34:59 +01:00

113 lines
2.9 KiB
Bash

#!/usr/bin/env bash
# Copyright (c) 2021-2026 community-scripts ORG
# Author: MickLesk (CanbiZ)
# License: MIT | https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE
# Source: https://github.com/papra-hq/papra
source /dev/stdin <<<"$FUNCTIONS_FILE_PATH"
color
verb_ip6
catch_errors
setting_up_container
network_check
update_os
msg_info "Installing Dependencies"
$STD apt install -y \
build-essential \
tesseract-ocr \
tesseract-ocr-all
msg_ok "Installed Dependencies"
NODE_VERSION="24" setup_nodejs
RELEASE=$(curl -fsSL https://api.github.com/repos/papra-hq/papra/releases | grep -oP '"tag_name":\s*"\K@papra/docker@[^"]+' | head -n1)
fetch_and_deploy_gh_release "papra" "papra-hq/papra" "tarball" "${RELEASE}" "/opt/papra"
msg_info "Setup Papra"
cd /opt/papra
export COREPACK_ENABLE_NETWORK=1
$STD corepack enable
$STD corepack prepare pnpm@10.19.0 --activate
$STD pnpm install --frozen-lockfile
$STD pnpm --filter "@papra/app-client..." run build
$STD pnpm --filter "@papra/app-server..." run build
msg_ok "Set up Papra"
msg_info "Configuring Papra"
DATA_DIR="/opt/papra_data"
# Create persistent data directories (survive updates/CLEAN_INSTALL)
mkdir -p "${DATA_DIR}/db"
mkdir -p "${DATA_DIR}/documents"
mkdir -p "${DATA_DIR}/ingestion"
# Link client build to server public dir
ln -sf /opt/papra/apps/papra-client/dist /opt/papra/apps/papra-server/public
# Generate secret only on first install, preserve on updates
if [[ ! -f "${DATA_DIR}/.auth_secret" ]]; then
openssl rand -hex 32 > "${DATA_DIR}/.auth_secret"
fi
AUTH_SECRET=$(cat "${DATA_DIR}/.auth_secret")
cat >/opt/papra/apps/papra-server/.env <<EOF
NODE_ENV=production
SERVER_SERVE_PUBLIC_DIR=true
PORT=1221
# Database Configuration
DATABASE_URL=file:${DATA_DIR}/db/db.sqlite
# Storage Configuration
DOCUMENT_STORAGE_FILESYSTEM_ROOT=${DATA_DIR}/documents
PAPRA_CONFIG_DIR=${DATA_DIR}
# Authentication
AUTH_SECRET=${AUTH_SECRET}
BETTER_AUTH_SECRET=${AUTH_SECRET}
BETTER_AUTH_TELEMETRY=0
# Application Configuration
CLIENT_BASE_URL=http://${LOCAL_IP}:1221
# Email Configuration (dry-run mode)
EMAILS_DRY_RUN=true
# Ingestion Folder
INGESTION_FOLDER_ROOT=${DATA_DIR}/ingestion
EOF
chown -R root:root /opt/papra
msg_ok "Configured Papra"
msg_info "Creating Papra Service"
cat >/etc/systemd/system/papra.service <<EOF
[Unit]
Description=Papra Document Management
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=/opt/papra/apps/papra-server
EnvironmentFile=/opt/papra/apps/papra-server/.env
Environment=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ExecStartPre=/usr/bin/corepack pnpm --silent run migrate:up
ExecStart=/usr/bin/corepack pnpm --silent run start
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF
systemctl enable -q --now papra
echo "${RELEASE}" >/opt/papra_version.txt
msg_ok "Created and Started Papra Service"
motd_ssh
customize
cleanup_lxc