2022-03-29 11:08:51 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
2022-12-30 12:24:18 +01:00
|
|
|
source ynh_redis
|
2022-03-29 11:08:51 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2022-12-30 12:24:18 +01:00
|
|
|
ynh_script_progression --message="Stopping a systemd service..." --weight=1
|
2022-03-29 11:08:51 +02:00
|
|
|
|
2022-12-30 12:24:18 +01:00
|
|
|
ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log"
|
2022-12-30 19:30:56 +01:00
|
|
|
ynh_systemd_action --service_name="$app-consumer" --action="stop" --log_path="/var/log/$app/$app-consumer.log"
|
|
|
|
ynh_systemd_action --service_name="$app-scheduler" --action="stop" --log_path="/var/log/$app/$app-scheduler.log"
|
|
|
|
ynh_systemd_action --service_name="$app-task-queue" --action="stop" --log_path="/var/log/$app/$app-task-queue.log"
|
2022-03-29 11:08:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
2022-12-30 12:24:18 +01:00
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
2022-03-29 11:08:51 +02:00
|
|
|
|
2023-01-11 21:12:19 +01:00
|
|
|
# If ocr_language doesn't exist, create it
|
|
|
|
if [ -z "$ocr_language" ]; then
|
|
|
|
ocr_language="eng"
|
|
|
|
ynh_app_setting_set --app=$app --key=ocr_language --value=$ocr_language
|
|
|
|
fi
|
2022-12-30 12:24:18 +01:00
|
|
|
|
2023-05-28 20:21:14 +02:00
|
|
|
if ynh_compare_current_package_version -c le -v "1.14.5~ynh1"
|
|
|
|
then
|
|
|
|
# When upgrading from older version when install_dir was in /var/www,
|
|
|
|
# we need to rebuild the venv entierly
|
|
|
|
ynh_secure_remove --file="$install_dir/venv"
|
|
|
|
fi
|
2022-03-29 11:08:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
|
|
then
|
2022-12-30 12:24:18 +01:00
|
|
|
ynh_script_progression --message="Upgrading source files..." --weight=1
|
2022-03-29 11:08:51 +02:00
|
|
|
|
2023-05-28 20:21:14 +02:00
|
|
|
ynh_setup_source --dest_dir="$install_dir" --keep="paperless.conf"
|
2022-03-29 11:08:51 +02:00
|
|
|
fi
|
|
|
|
|
2023-05-28 20:21:14 +02:00
|
|
|
chmod 750 "$install_dir"
|
|
|
|
chmod -R o-rwx "$install_dir"
|
|
|
|
chown -R $app:$app "$install_dir"
|
2022-03-29 11:08:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
2022-12-30 12:24:18 +01:00
|
|
|
# NGINX CONFIGURATION
|
2022-03-29 11:08:51 +02:00
|
|
|
#=================================================
|
2022-12-30 12:24:18 +01:00
|
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
|
2022-03-29 11:08:51 +02:00
|
|
|
|
2022-12-30 12:24:18 +01:00
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config
|
2022-03-29 11:08:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
|
|
|
#=================================================
|
2022-03-29 17:50:14 +02:00
|
|
|
# INSTALL PYTHON DEPENDENCIES
|
2022-03-29 11:08:51 +02:00
|
|
|
#=================================================
|
2022-03-29 17:50:14 +02:00
|
|
|
ynh_script_progression --message="Installing Python dependencies..."
|
|
|
|
|
2023-05-28 20:21:14 +02:00
|
|
|
pushd $install_dir
|
2022-03-29 17:50:14 +02:00
|
|
|
python3 -m venv venv
|
2023-05-28 20:21:14 +02:00
|
|
|
chown -R "$app:" "$install_dir"
|
2022-12-30 12:24:18 +01:00
|
|
|
(
|
2023-05-28 20:21:14 +02:00
|
|
|
source "$install_dir/venv/bin/activate"
|
|
|
|
ynh_exec_as $app $install_dir/venv/bin/pip3 install --upgrade pip setuptools wheel
|
|
|
|
ynh_exec_as $app $install_dir/venv/bin/pip3 install -r "$install_dir/requirements.txt"
|
2023-01-11 21:13:25 +01:00
|
|
|
|
|
|
|
# Installing NLTK data
|
2023-05-28 20:21:14 +02:00
|
|
|
ynh_secure_remove --file="$install_dir/nltk_data"
|
|
|
|
mkdir -p "$install_dir/nltk_data"
|
|
|
|
chown -R "$app:" "$install_dir/nltk_data"
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app $install_dir/venv/bin/python3 -m nltk.downloader -d "$install_dir/nltk_data" snowball_data
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app $install_dir/venv/bin/python3 -m nltk.downloader -d "$install_dir/nltk_data" stopwords
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app $install_dir/venv/bin/python3 -m nltk.downloader -d "$install_dir/nltk_data" punkt
|
2023-01-11 21:13:25 +01:00
|
|
|
|
2022-12-30 12:24:18 +01:00
|
|
|
deactivate
|
|
|
|
)
|
2022-03-29 17:50:14 +02:00
|
|
|
popd
|
2022-03-29 11:08:51 +02:00
|
|
|
|
2024-02-10 09:24:13 +01:00
|
|
|
#=================================================
|
|
|
|
# BUILD GHOSTCRIPT SPECIFIC VERSION
|
|
|
|
#=================================================
|
2024-02-12 17:18:19 +01:00
|
|
|
if [[ ! -f $install_dir/ghostscript/bin/gs ]] && grep -q "10.02.1" $($install_dir/ghostscript/bin/gs -v)
|
2024-02-10 09:24:13 +01:00
|
|
|
then
|
|
|
|
ynh_script_progression --message="Building Ghostscript dependency..."
|
|
|
|
|
|
|
|
ynh_setup_source --dest_dir="$install_dir/ghostscript" --source_id="gs" --full_replace
|
|
|
|
|
|
|
|
pushd $install_dir/ghostscript
|
2024-02-12 17:18:19 +01:00
|
|
|
ynh_exec_warn_less ./configure
|
|
|
|
ynh_exec_warn_less make
|
|
|
|
ynh_exec_warn_less make install
|
2024-02-10 09:24:13 +01:00
|
|
|
popd
|
|
|
|
|
|
|
|
chown -R $app:$app "$install_dir/ghostscript"
|
2024-02-12 17:18:19 +01:00
|
|
|
chmod 550 $install_dir/ghostscript/bin/gs
|
2024-02-10 09:24:13 +01:00
|
|
|
fi
|
|
|
|
|
2022-03-29 11:08:51 +02:00
|
|
|
#=================================================
|
|
|
|
# UPDATE A CONFIG FILE
|
|
|
|
#=================================================
|
2022-12-30 12:24:18 +01:00
|
|
|
ynh_script_progression --message="Updating a configuration file..." --weight=1
|
2022-03-29 11:08:51 +02:00
|
|
|
|
2023-05-28 20:21:14 +02:00
|
|
|
ynh_add_config --template="paperless.conf.example" --destination="$install_dir/paperless.conf"
|
2022-03-29 11:08:51 +02:00
|
|
|
|
2023-05-28 20:21:14 +02:00
|
|
|
chmod 400 "$install_dir/paperless.conf"
|
|
|
|
chown $app:$app "$install_dir/paperless.conf"
|
2023-04-15 17:40:41 +02:00
|
|
|
|
2022-03-29 17:50:14 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP THE DATABASE
|
|
|
|
#=================================================
|
2022-12-30 12:24:18 +01:00
|
|
|
ynh_script_progression --message="Setting up the database..." --weight=1
|
2022-03-29 17:50:14 +02:00
|
|
|
|
2023-05-28 20:21:14 +02:00
|
|
|
pushd "$install_dir/src"
|
2022-12-30 12:24:18 +01:00
|
|
|
(
|
2023-05-28 20:21:14 +02:00
|
|
|
source "$install_dir/venv/bin/activate"
|
|
|
|
ynh_exec_as $app $install_dir/venv/bin/python manage.py migrate
|
2022-12-30 12:24:18 +01:00
|
|
|
deactivate
|
|
|
|
)
|
2022-03-29 17:50:14 +02:00
|
|
|
popd
|
|
|
|
|
2022-03-29 11:08:51 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
2022-12-30 12:24:18 +01:00
|
|
|
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
|
2022-03-29 11:08:51 +02:00
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
2022-12-30 12:24:18 +01:00
|
|
|
ynh_add_systemd_config --service="$app" --template="systemd.service"
|
2022-12-30 19:30:56 +01:00
|
|
|
ynh_add_systemd_config --service="$app-consumer" --template="systemd-consumer.service"
|
|
|
|
ynh_add_systemd_config --service="$app-scheduler" --template="systemd-scheduler.service"
|
|
|
|
ynh_add_systemd_config --service="$app-task-queue" --template="systemd-task-queue.service"
|
2022-03-29 11:08:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
2022-12-30 12:24:18 +01:00
|
|
|
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
|
2022-03-29 11:08:51 +02:00
|
|
|
|
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
2022-12-30 12:24:18 +01:00
|
|
|
ynh_use_logrotate --logfile="/var/log/$app/$app.log"
|
2022-12-30 19:30:56 +01:00
|
|
|
ynh_use_logrotate --logfile="/var/log/$app/$app-consumer.log"
|
|
|
|
ynh_use_logrotate --logfile="/var/log/$app/$app-scheduler.log"
|
|
|
|
ynh_use_logrotate --logfile="/var/log/$app/$app-task-queue.log"
|
2022-03-29 11:08:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
2022-12-30 12:24:18 +01:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
2022-03-29 11:08:51 +02:00
|
|
|
|
2022-12-30 12:24:18 +01:00
|
|
|
yunohost service add "$app" --log="/var/log/$app/$app.log"
|
2022-12-30 19:30:56 +01:00
|
|
|
yunohost service add "$app-consumer" --log="/var/log/$app/$app-consumer.log"
|
|
|
|
yunohost service add "$app-scheduler" --log="/var/log/$app/$app-scheduler.log"
|
|
|
|
yunohost service add "$app-task-queue" --log="/var/log/$app/$app-task-queue.log"
|
2022-03-29 11:08:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2022-12-30 12:24:18 +01:00
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
2022-03-29 11:08:51 +02:00
|
|
|
|
2022-12-30 12:24:18 +01:00
|
|
|
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log"
|
2022-12-30 19:30:56 +01:00
|
|
|
ynh_systemd_action --service_name="$app-consumer" --action="start" --log_path="/var/log/$app/$app-consumer.log"
|
|
|
|
ynh_systemd_action --service_name="$app-scheduler" --action="start" --log_path="/var/log/$app/$app-scheduler.log"
|
|
|
|
ynh_systemd_action --service_name="$app-task-queue" --action="start" --log_path="/var/log/$app/$app-task-queue.log"
|
2022-03-29 11:08:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# UPGRADE FAIL2BAN
|
|
|
|
#=================================================
|
2022-12-30 12:24:18 +01:00
|
|
|
#ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=1
|
2022-03-29 11:08:51 +02:00
|
|
|
|
|
|
|
# Create a dedicated Fail2Ban config
|
2022-12-30 12:24:18 +01:00
|
|
|
#ynh_add_fail2ban_config --logpath="/var/log/nginx/${domain}-error.log" --failregex="Regex to match into the log for a failed login"
|
2022-03-29 11:08:51 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2022-12-30 12:24:18 +01:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|