1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/etherpad_mypads_ynh.git synced 2024-09-03 18:36:09 +02:00
etherpad_mypads_ynh/scripts/upgrade
2024-06-20 17:19:19 +02:00

199 lines
6.9 KiB
Bash

#!/bin/bash
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# ACTIVATE MAINTENANCE MODE
#=================================================
ynh_script_progression --message="Activating maintenance mode..." --weight=2
# Wait for Etherpad to be fully started # (... but why ???)
ynh_systemd_action --action=restart --line_match="Your Etherpad version is" --log_path="systemd"
ynh_maintenance_mode_ON
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=3
ynh_systemd_action --service_name=$app --action="stop"
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=2
if [ -z "${language:-}" ]; then
# If upgrading from a version which doesn't support translations, set language to English by default
language=en
ynh_app_setting_set --app=$app --key=language --value=$language
fi
if [ -z "${export:-}" ]; then
export=none
ynh_app_setting_set --app=$app --key=export --value=$export
fi
if [ -z "${mypads:-}" ]; then
mypads=1
ynh_app_setting_set --app=$app --key=mypads --value=$mypads
fi
if [ -z "${useldap:-}" ]; then
useldap=0
ynh_app_setting_set --app=$app --key=useldap --value=$useldap
fi
if [ -z "${path:-}" ]; then
path="/"
ynh_app_setting_set --app=$app --key=path --value=$path
fi
if [ -z "${password:-}" ]; then
password=$(ynh_string_random --length=32)
ynh_app_setting_set --app=$app --key=password --value="$password"
fi
# Support full Unicode in MySQL databases
ynh_mysql_connect_as --user=$db_user --password="$db_pwd" --database=$db_name \
<<< "ALTER DATABASE $db_name CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Upgrading source files..." --weight=4
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir" --full_replace=1 --keep="settings.json credentials.json"
chmod -R o-rwx "$install_dir"
chown -R $app:$app "$install_dir"
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
ynh_script_progression --message="Upgrading dependencies..." --weight=5
ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_use_nodejs
#=================================================
# SPECIFIC UPGRADE
#=================================================
# HANDLE LOG FILES AND LOGROTATE
#=================================================
ynh_script_progression --message="Configuring log rotation..." --weight=1
# Create log directory
chown $app -R /var/log/$app
#=================================================
# CONFIGURE ETHERPAD
#=================================================
ynh_script_progression --message="Configure $app..."
abiword_path="null"
soffice_path="null"
if [[ "$export" == "abiword" ]]
then
abiword_path="\"$(which abiword)\""
elif [[ "$export" == "libreoffice" ]]
then
soffice_path="\"$(which soffice)\""
fi
# Use ldap for mypads
comment_if_ldap_disabled="//ldap_disabled"
if [ $mypads -eq 1 ] && [ $useldap -eq 1 ]
then
comment_if_ldap_disabled=""
fi
# Calculate and store the config file checksum into the app settings
ynh_add_config --template="settings.json" --destination="$install_dir/settings.json"
ynh_add_config --template="credentials.json" --destination="$install_dir/credentials.json"
chmod 600 "$install_dir/settings.json"
chown $app:$app "$install_dir/settings.json"
chmod 600 "$install_dir/credentials.json"
chown $app:$app "$install_dir/credentials.json"
#=================================================
# UPGRADE NPM MODULES
#=================================================
ynh_script_progression --message="Upgrading $app..." --weight=10
pushd $install_dir
ynh_exec_warn_less env $ynh_node_load_PATH corepack enable && COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack prepare pnpm@latest --activate
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH ETHERPAD_PRODUCTION=true COREPACK_ENABLE_DOWNLOAD_PROMPT=0 bin/installDeps.sh && \
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH pnpm run install-plugins \
ep_align@${ep_align_version} \
ep_author_hover@${ep_author_hover_version} \
ep_delete_empty_pads@${ep_delete_empty_pads_version} \
ep_headings2@${ep_headings2_version} \
ep_font_size@${ep_font_size_version}
if [ $mypads -eq 1 ]; then
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH pnpm run install-plugins \
ep_mypads@${mypads_version}
fi
popd
#=================================================
# ADD MYPADS LINK
#=================================================
if [ $mypads -eq 1 ]
then
# Find the /div just after the field to open a pad in order to add a link to MyPads plugin.
sed -i '157i<center><br><font size="4"><a href="./mypads/" style="text-decoration: none; color: #555">MyPads</a></font></center>' $install_dir/src/templates/index.html
fi
#=================================================
# REAPPLY SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
ynh_add_nginx_config
ynh_add_systemd_config
# Integrate in YunoHost
yunohost service add $app --description="Collaborative editor" --log="/var/log/$app/etherpad.log"
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append --specific_user=$app/$app
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting systemd service..." --weight=9
ynh_systemd_action --service_name=$app --action=restart --line_match="Your Etherpad version is" --log_path="systemd"
#=================================================
# UPGRADE FAIL2BAN
#=================================================
ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=8
# Create a dedicated Fail2Ban config
ynh_add_fail2ban_config --logpath="/var/log/nginx/$domain-access.log" --failregex="<HOST> .* .POST /mypads/api/auth/login HTTP/1.1. 400" --max_retry=5
#=================================================
# DEACTIVE MAINTENANCE MODE
#=================================================
ynh_script_progression --message="Disabling maintenance mode..." --weight=5
ynh_maintenance_mode_OFF
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last