Last active
March 10, 2024 16:12
-
-
Save principis/81c6df9a3125b29e02edb5bece413ac0 to your computer and use it in GitHub Desktop.
paperless-ngx update script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import nltk | |
nltk.download('stopwords') | |
nltk.download('punkt') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Go to script dir | |
cd "$(dirname "$0")" | |
# Run as root | |
if [ "$(id -u)" -ne 0 ]; then | |
exec sudo -u root $0 "$@" | |
exit 0 | |
fi | |
REL="$1" | |
if [ -z "$REL" ]; then | |
echo "No version specified" | |
exit 1 | |
fi | |
stop_service() { | |
SERVICE="$1" | |
echo "Stopping $SERVICE..." | |
systemctl stop "$SERVICE" | |
} | |
start_service() { | |
SERVICE="$1" | |
echo "Starting $SERVICE..." | |
systemctl start "$SERVICE" | |
systemctl is-active -q "$SERVICE" | |
if [ $? -ne 0 ]; then | |
echo "Failed to start $SERVICE" | |
exit 1 | |
fi | |
} | |
stop_service "paperless-consumer" | |
stop_service "paperless-scheduler" | |
stop_service "paperless-task-queue" | |
stop_service "paperless-webserver" | |
echo "Downloading paperless v${REL}" | |
sudo -u paperless wget -q "https://github.com/paperless-ngx/paperless-ngx/releases/download/v${REL}/paperless-ngx-v${REL}.tar.xz" | |
if [ $? -ne 0 ]; then | |
echo "Error downloading archive" | |
exit 1 | |
fi | |
sudo -u paperless mkdir "paperless-ngx-v${REL}" | |
if [ $? -ne 0 ]; then | |
echo "Error extracting archive" | |
exit 1 | |
fi | |
sudo -u paperless tar xf "paperless-ngx-v${REL}.tar.xz" -C "paperless-ngx-v${REL}" --strip-components=1 | |
if [ $? -ne 0 ]; then | |
echo "Error extracting archive" | |
exit 1 | |
fi | |
pushd "paperless-ngx-v${REL}" >/dev/null | |
echo "Fixing cryptography..." | |
sudo -u paperless sed -i 's/cryptography==40\.0\.1/cryptography==40.0.2/' requirements.txt | |
echo "Installing requirements..." | |
sudo -u paperless ../venv/bin/pip3 install -r requirements.txt | |
retval=$? | |
if [ $retval -ne 0 ]; then | |
exit $retval | |
fi | |
echo "Backing up config file..." | |
sudo -u paperless cp paperless.conf paperless.conf.orig | |
echo "Merging config files..." | |
sudo -u paperless merge paperless.conf paperless.conf.orig ../paperless-latest/paperless.conf | |
echo "Checking diff..." | |
DIFF=$(diff -s paperless.conf ../paperless-latest/paperless.conf) | |
retval=$? | |
if [ $retval -ne 0 ]; then | |
echo "Changes in config file detected:" | |
echo $DIFF | |
echo | |
read -p "Continue? " -n 1 -r | |
echo # (optional) move to a new line | |
if [[ ! $REPLY =~ ^[Yy]$ ]]; then | |
exit 1 | |
fi | |
fi | |
echo "Updating symlink..." | |
popd >/dev/null | |
sudo -u paperless ln -sfn "paperless-ngx-v${REL}" paperless-latest | |
echo "Running migrations..." | |
pushd paperless-latest/src >/dev/null | |
sudo -u paperless ../../venv/bin/python3 manage.py migrate | |
popd >/dev/null | |
echo "Fixing nltk..." | |
sudo -u paperless ./venv/bin/python3 fix-nltk.py | |
echo "Starting services..." | |
start_service "paperless-consumer" | |
start_service "paperless-scheduler" | |
start_service "paperless-task-queue" | |
start_service "paperless-webserver" | |
echo "Clearing cache..." | |
sudo -u paperless ./venv/bin/pip3 cache purge |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment