ProxmoxHelperScripts/install/paperless-ngx-install.sh

222 lines
7.1 KiB
Bash
Raw Normal View History

2023-01-02 04:13:23 +01:00
#!/usr/bin/env bash
2023-02-07 18:15:22 +01:00
2024-01-01 18:13:05 +01:00
# Copyright (c) 2021-2024 tteck
2023-02-07 18:15:22 +01:00
# Author: tteck (tteckster)
# License: MIT
# https://github.com/tteck/Proxmox/raw/main/LICENSE
2023-05-15 15:25:03 +02:00
source /dev/stdin <<<"$FUNCTIONS_FILE_PATH"
color
verb_ip6
catch_errors
setting_up_container
network_check
update_os
2023-01-02 04:13:23 +01:00
2023-02-05 00:28:08 +01:00
msg_info "Installing Python3"
2023-01-02 04:13:23 +01:00
$STD apt-get install -y --no-install-recommends \
2023-05-15 15:25:03 +02:00
python3 \
python3-pip \
python3-dev \
python3-setuptools \
python3-wheel
2023-02-05 00:28:08 +01:00
msg_ok "Installed Python3"
msg_info "Installing Dependencies (Patience)"
$STD apt-get install -y --no-install-recommends \
2023-05-15 15:25:03 +02:00
redis \
postgresql \
build-essential \
imagemagick \
fonts-liberation \
optipng \
gnupg \
libpq-dev \
libmagic-dev \
mime-support \
libzbar0 \
poppler-utils \
default-libmysqlclient-dev \
automake \
libtool \
pkg-config \
git \
curl \
libtiff-dev \
libpng-dev \
libleptonica-dev \
sudo \
mc
2023-02-05 00:28:08 +01:00
msg_ok "Installed Dependencies"
2023-01-02 04:13:23 +01:00
2023-02-05 00:28:08 +01:00
msg_info "Installing OCR Dependencies (Patience)"
2023-01-02 04:13:23 +01:00
$STD apt-get install -y --no-install-recommends \
2023-05-15 15:25:03 +02:00
unpaper \
ghostscript \
icc-profiles-free \
qpdf \
liblept5 \
libxml2 \
pngquant \
zlib1g \
tesseract-ocr \
tesseract-ocr-eng
2023-01-02 04:13:23 +01:00
msg_ok "Installed OCR Dependencies"
msg_info "Installing JBIG2"
$STD git clone https://github.com/agl/jbig2enc /opt/jbig2enc
cd /opt/jbig2enc
$STD bash ./autogen.sh
$STD bash ./configure
$STD make
$STD make install
rm -rf /opt/jbig2enc
msg_ok "Installed JBIG2"
msg_info "Installing Paperless-ngx (Patience)"
Paperlessngx=$(wget -q https://github.com/paperless-ngx/paperless-ngx/releases/latest -O - | grep "title>Release" | cut -d " " -f 5)
cd /opt
2023-05-15 15:25:03 +02:00
$STD wget https://github.com/paperless-ngx/paperless-ngx/releases/download/$Paperlessngx/paperless-ngx-$Paperlessngx.tar.xz
2023-01-02 04:13:23 +01:00
$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 -s -o /opt/paperless/paperless.conf https://raw.githubusercontent.com/paperless-ngx/paperless-ngx/main/paperless.conf.example
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
2023-01-02 04:13:23 +01:00
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
2023-01-02 04:13:23 +01:00
DB_USER=paperless
DB_PASS="$(openssl rand -base64 18 | cut -c1-13)"
SECRET_KEY="$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32)"
2023-01-02 04:13:23 +01:00
$STD sudo -u postgres psql -c "CREATE ROLE $DB_USER WITH LOGIN PASSWORD '$DB_PASS';"
$STD sudo -u postgres psql -c "CREATE DATABASE $DB_NAME WITH OWNER $DB_USER TEMPLATE template0;"
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
2023-01-02 04:13:23 +01:00
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"
2023-01-02 04:13:23 +01:00
read -r -p "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
2023-09-11 20:26:36 +02:00
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
2023-01-02 04:13:23 +01:00
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
from django.contrib.auth import get_user_model
UserModel = get_user_model()
user = UserModel.objects.create_user('admin', password='$DB_PASS')
user.is_superuser = True
user.is_staff = True
user.save()
2023-01-02 04:13:23 +01:00
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
2023-01-02 04:13:23 +01:00
msg_ok "Set up admin Paperless-ngx User & Password"
msg_info "Creating Services"
cat <<EOF >/etc/systemd/system/paperless-scheduler.service
[Unit]
Description=Paperless Celery beat
Requires=redis.service
[Service]
WorkingDirectory=/opt/paperless/src
ExecStart=celery --app paperless beat --loglevel INFO
[Install]
WantedBy=multi-user.target
EOF
cat <<EOF >/etc/systemd/system/paperless-task-queue.service
[Unit]
Description=Paperless Celery Workers
Requires=redis.service
[Service]
WorkingDirectory=/opt/paperless/src
ExecStart=celery --app paperless worker --loglevel INFO
[Install]
WantedBy=multi-user.target
EOF
cat <<EOF >/etc/systemd/system/paperless-consumer.service
[Unit]
Description=Paperless consumer
Requires=redis.service
[Service]
WorkingDirectory=/opt/paperless/src
ExecStart=python3 manage.py document_consumer
[Install]
WantedBy=multi-user.target
EOF
cat <<EOF >/etc/systemd/system/paperless-webserver.service
[Unit]
Description=Paperless webserver
After=network.target
Wants=network.target
Requires=redis.service
[Service]
WorkingDirectory=/opt/paperless/src
ExecStart=/usr/local/bin/gunicorn -c /opt/paperless/gunicorn.conf.py paperless.asgi:application
[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 --now paperless-consumer paperless-webserver paperless-scheduler paperless-task-queue.service
msg_ok "Created Services"
motd_ssh
2023-05-15 13:39:30 +02:00
customize
2023-01-02 04:13:23 +01:00
msg_info "Cleaning up"
rm -rf /opt/paperless/docker
2023-01-02 04:13:23 +01:00
$STD apt-get autoremove
$STD apt-get autoclean
msg_ok "Cleaned"