Skip to content

Instantly share code, notes, and snippets.

@bin101
Last active April 29, 2023 11:14
Show Gist options
  • Save bin101/585945d70ba8f0a9b5da3f8fd0642972 to your computer and use it in GitHub Desktop.
Save bin101/585945d70ba8f0a9b5da3f8fd0642972 to your computer and use it in GitHub Desktop.
Paperless-ngx update script
#!/bin/bash
function header_info {
clear
cat <<"EOF"
____ __
/ __ \____ _____ ___ _____/ /__ __________ ____ ____ __ __
/ /_/ / __ `/ __ \/ _ \/ ___/ / _ \/ ___/ ___/___/ __ \/ __ `/ |/_/
/ ____/ /_/ / /_/ / __/ / / / __(__ |__ )___/ / / / /_/ /> <
/_/ \__,_/ .___/\___/_/ /_/\___/____/____/ /_/ /_/\__, /_/|_|
/_/ /____/
EOF
}
function catch_errors() {
set -Eeuo pipefail
trap 'error_handler $LINENO "$BASH_COMMAND"' ERR
}
function error_handler() {
local exit_code="$?"
local line_number="$1"
local command="$2"
local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}"
echo -e "\n$error_message\n"
}
function exit-script() {
clear
echo -e "⚠ User exited script \n"
exit
}
function color() {
YW=$(echo "\033[33m")
BL=$(echo "\033[36m")
RD=$(echo "\033[01;31m")
BGN=$(echo "\033[4;92m")
GN=$(echo "\033[1;92m")
DGN=$(echo "\033[32m")
CL=$(echo "\033[m")
CM="${GN}✓${CL}"
CROSS="${RD}✗${CL}"
BFR="\\r\\033[K"
HOLD="-"
}
function msg_info() {
local msg="$1"
echo -ne " ${HOLD} ${YW}${msg}..."
}
function msg_ok() {
local msg="$1"
echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
}
function msg_error() {
local msg="$1"
echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}"
}
function update_script() {
if [[ ! -d /opt/paperless-ngx ]]; then
msg_error "No ${APP} Installation Found!"
exit
fi
RELEASE=$(curl -s https://api.github.com/repos/paperless-ngx/paperless-ngx/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }')
if (whiptail --title "SUPPORT" --yesno "Update Paperless to ${RELEASE}?" 11 58); then
header_info
msg_info "Stopping Paperless-ngx"
systemctl stop paperless-consumer paperless-webserver paperless-scheduler paperless-task-queue
sleep 1
msg_ok "Stopped Paperless-ngx"
msg_info "Updating to ${RELEASE}"
cd /opt
wget https://github.com/paperless-ngx/paperless-ngx/releases/download/$RELEASE/paperless-ngx-$RELEASE.tar.xz &>/dev/null
tar -xf paperless-ngx-$RELEASE.tar.xz &>/dev/null
chown -R paperless:paperless paperless-ngx
cd paperless-ngx
rm paperless.conf
sudo -u paperless pip install -r requirements.txt &>/dev/null
cd src
sudo -u paperless python3 manage.py migrate &>/dev/null
msg_ok "Updated to ${RELEASE}"
msg_info "Cleaning up"
cd /opt
rm paperless-ngx-$RELEASE.tar.xz
sleep 1
msg_ok "Cleaned"
msg_info "Starting Paperless-ngx"
cd /
systemctl start paperless-consumer paperless-webserver paperless-scheduler paperless-task-queue
sleep 1
msg_ok "Started Paperless-ngx"
msg_ok "Updated Successfully!\n"
exit
else
exit-script
fi
}
color
catch_errors
echo -e "Loading..."
APP="Paperless-ngx"
update_script
@bin101
Copy link
Author

bin101 commented Apr 29, 2023

Script assumes that install location is /opt/papeless-ngx, executing user is paperless and config file sits in /etc/paperless.conf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment