2023-01-02 03:13:23 +00:00
|
|
|
#!/usr/bin/env bash
|
2023-02-07 17:15:22 +00:00
|
|
|
|
2024-01-01 17:13:05 +00:00
|
|
|
# Copyright (c) 2021-2024 tteck
|
2023-02-07 17:15:22 +00:00
|
|
|
# Author: tteck (tteckster)
|
|
|
|
# License: MIT
|
|
|
|
# https://github.com/tteck/Proxmox/raw/main/LICENSE
|
|
|
|
|
2023-05-15 13:25:03 +00:00
|
|
|
source /dev/stdin <<<"$FUNCTIONS_FILE_PATH"
|
2023-03-23 00:48:20 +00:00
|
|
|
color
|
|
|
|
verb_ip6
|
|
|
|
catch_errors
|
|
|
|
setting_up_container
|
|
|
|
network_check
|
|
|
|
update_os
|
2023-01-02 03:13:23 +00:00
|
|
|
|
2023-02-04 23:28:08 +00:00
|
|
|
msg_info "Installing Dependencies (Patience)"
|
|
|
|
$STD apt-get install -y --no-install-recommends \
|
2023-05-15 13:25:03 +00: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-04 23:28:08 +00:00
|
|
|
msg_ok "Installed Dependencies"
|
2023-01-02 03:13:23 +00:00
|
|
|
|
2024-05-07 16:40:52 +00:00
|
|
|
msg_info "Installing Python3 Dependencies"
|
|
|
|
$STD apt-get install -y --no-install-recommends \
|
|
|
|
python3 \
|
|
|
|
python3-pip \
|
|
|
|
python3-dev \
|
|
|
|
python3-setuptools \
|
|
|
|
python3-wheel
|
|
|
|
msg_ok "Installed Python3 Dependencies"
|
|
|
|
|
2023-02-04 23:28:08 +00:00
|
|
|
msg_info "Installing OCR Dependencies (Patience)"
|
2023-01-02 03:13:23 +00:00
|
|
|
$STD apt-get install -y --no-install-recommends \
|
2023-05-15 13:25:03 +00:00
|
|
|
unpaper \
|
|
|
|
ghostscript \
|
|
|
|
icc-profiles-free \
|
|
|
|
qpdf \
|
|
|
|
liblept5 \
|
|
|
|
libxml2 \
|
|
|
|
pngquant \
|
|
|
|
zlib1g \
|
|
|
|
tesseract-ocr \
|
|
|
|
tesseract-ocr-eng
|
2023-01-02 03:13:23 +00: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 13:25:03 +00:00
|
|
|
$STD wget https://github.com/paperless-ngx/paperless-ngx/releases/download/$Paperlessngx/paperless-ngx-$Paperlessngx.tar.xz
|
2023-01-02 03:13:23 +00: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
|
2023-02-17 10:19:46 +00:00
|
|
|
curl -s -o /opt/paperless/paperless.conf https://raw.githubusercontent.com/paperless-ngx/paperless-ngx/main/paperless.conf.example
|
2023-09-11 20:56:42 +00:00
|
|
|
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
|
2024-05-08 17:30:07 +00:00
|
|
|
echo "${Paperlessngx}" >/opt/${APPLICATION}_version.txt
|
2023-01-02 03:13:23 +00:00
|
|
|
msg_ok "Installed Paperless-ngx"
|
|
|
|
|
2023-02-10 21:44:35 +00:00
|
|
|
msg_info "Installing Natural Language Toolkit (Patience)"
|
|
|
|
$STD python3 -m nltk.downloader -d /usr/share/nltk_data all
|
|
|
|
msg_ok "Installed Natural Language Toolkit"
|
|
|
|
|
2023-09-11 17:18:06 +00:00
|
|
|
msg_info "Setting up PostgreSQL database"
|
|
|
|
DB_NAME=paperlessdb
|
2023-01-02 03:13:23 +00:00
|
|
|
DB_USER=paperless
|
2023-04-30 19:15:51 +00:00
|
|
|
DB_PASS="$(openssl rand -base64 18 | cut -c1-13)"
|
2023-09-11 17:18:06 +00:00
|
|
|
SECRET_KEY="$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32)"
|
2023-01-02 03:13:23 +00:00
|
|
|
$STD sudo -u postgres psql -c "CREATE ROLE $DB_USER WITH LOGIN PASSWORD '$DB_PASS';"
|
2024-05-08 16:40:27 +00:00
|
|
|
$STD sudo -u postgres psql -c "CREATE DATABASE $DB_NAME WITH OWNER $DB_USER ENCODING 'UTF8' TEMPLATE template0;"
|
2024-05-07 16:35:00 +00:00
|
|
|
$STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET client_encoding TO 'utf8';"
|
|
|
|
$STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET default_transaction_isolation TO 'read committed';"
|
|
|
|
$STD sudo -u postgres psql -c "ALTER ROLE $DB_USER SET timezone TO 'UTC'"
|
2023-09-11 19:22:40 +00:00
|
|
|
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
|
2023-09-11 17:18:06 +00:00
|
|
|
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 03:13:23 +00: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
|
2023-01-02 14:22:34 +00:00
|
|
|
$STD python3 manage.py migrate
|
2023-09-11 17:18:06 +00:00
|
|
|
msg_ok "Set up PostgreSQL database"
|
2023-01-02 03:13:23 +00:00
|
|
|
|
2023-09-11 17:43:34 +00: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 18:26:36 +00:00
|
|
|
IP=$(hostname -I | awk '{print $1}')
|
2023-09-11 18:00:11 +00:00
|
|
|
echo "" >>~/paperless.creds
|
2023-09-11 19:22:40 +00:00
|
|
|
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
|
2023-09-11 17:43:34 +00:00
|
|
|
msg_ok "Installed Adminer"
|
|
|
|
fi
|
|
|
|
|
2023-01-02 03:13:23 +00: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()
|
2023-04-30 19:15:51 +00:00
|
|
|
user = UserModel.objects.create_user('admin', password='$DB_PASS')
|
|
|
|
user.is_superuser = True
|
|
|
|
user.is_staff = True
|
|
|
|
user.save()
|
2023-01-02 03:13:23 +00:00
|
|
|
EOF
|
|
|
|
echo "" >>~/paperless.creds
|
2023-09-11 19:22:40 +00:00
|
|
|
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 03:13:23 +00: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
|
2024-06-13 12:14:03 +00:00
|
|
|
After=postgresql.service
|
2023-01-02 03:13:23 +00:00
|
|
|
|
|
|
|
[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"
|
|
|
|
|
2023-03-23 00:48:20 +00:00
|
|
|
motd_ssh
|
2023-05-15 11:39:30 +00:00
|
|
|
customize
|
2023-01-02 03:13:23 +00:00
|
|
|
|
|
|
|
msg_info "Cleaning up"
|
2023-09-11 20:56:42 +00:00
|
|
|
rm -rf /opt/paperless/docker
|
2024-06-02 12:00:22 +00:00
|
|
|
$STD apt-get -y autoremove
|
|
|
|
$STD apt-get -y autoclean
|
2023-01-02 03:13:23 +00:00
|
|
|
msg_ok "Cleaned"
|