mirror of
https://github.com/YunoHost-Apps/overleaf_ynh.git
synced 2024-09-03 19:56:27 +02:00
213 lines
10 KiB
Bash
213 lines
10 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# CHECK VERSION
|
|
#=================================================
|
|
ynh_script_progression --message="Checking version..."
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
# Retrieve YunoHost main domain for mails to work
|
|
main_domain=$(cat /etc/yunohost/current_host)
|
|
|
|
#=================================================
|
|
# STANDARD UPGRADE STEPS
|
|
#=================================================
|
|
# STOP SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Stopping a systemd service..."
|
|
|
|
ynh_systemd_action --service_name="$app-chat" --action="stop" --log_path="/var/log/$app/$app.log"
|
|
ynh_systemd_action --service_name="$app-clsi" --action="stop" --log_path="/var/log/$app/$app.log"
|
|
ynh_systemd_action --service_name="$app-contacts" --action="stop" --log_path="/var/log/$app/$app.log"
|
|
ynh_systemd_action --service_name="$app-docstore" --action="stop" --log_path="/var/log/$app/$app.log"
|
|
ynh_systemd_action --service_name="$app-document-updater" --action="stop" --log_path="/var/log/$app/$app.log"
|
|
ynh_systemd_action --service_name="$app-filestore" --action="stop" --log_path="/var/log/$app/$app.log"
|
|
ynh_systemd_action --service_name="$app-history-v1" --action="stop" --log_path="/var/log/$app/$app.log"
|
|
ynh_systemd_action --service_name="$app-notifications" --action="stop" --log_path="/var/log/$app/$app.log"
|
|
ynh_systemd_action --service_name="$app-project-history" --action="stop" --log_path="/var/log/$app/$app.log"
|
|
ynh_systemd_action --service_name="$app-real-time" --action="stop" --log_path="/var/log/$app/$app.log"
|
|
ynh_systemd_action --service_name="$app-spelling" --action="stop" --log_path="/var/log/$app/$app.log"
|
|
ynh_systemd_action --service_name="$app-web" --action="stop" --log_path="/var/log/$app/$app.log"
|
|
|
|
if ynh_exec_warn_less yunohost service status "$app-track-changes" >/dev/null
|
|
then
|
|
ynh_script_progression --message="Removing $app-track-changes service integration..."
|
|
yunohost service remove "$app-track-changes"
|
|
fi
|
|
|
|
#=================================================
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
#=================================================
|
|
ynh_script_progression --message="Ensuring downward compatibility..."
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
then
|
|
ynh_script_progression --message="Upgrading source files..."
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
ynh_setup_source --dest_dir="$install_dir/build"
|
|
fi
|
|
|
|
chmod 750 "$install_dir"
|
|
chmod -R o-rwx "$install_dir"
|
|
chown -R $app:www-data "$install_dir"
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..."
|
|
|
|
# Create a dedicated NGINX config
|
|
ynh_add_nginx_config
|
|
|
|
#=================================================
|
|
# UPGRADE DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading dependencies..."
|
|
|
|
ynh_install_nodejs --nodejs_version=$nodejs_version
|
|
ynh_install_mongo
|
|
|
|
# Upgrade NPM
|
|
ynh_npm install --global npm@latest
|
|
|
|
#=================================================
|
|
# SPECIFIC UPGRADE
|
|
#=================================================
|
|
# UPDATE A CONFIG FILE
|
|
#=================================================
|
|
ynh_script_progression --message="Updating a configuration file..."
|
|
|
|
ynh_add_config --template="../conf/variables.env" --destination="$install_dir/variables.env"
|
|
chmod 400 "$install_dir/variables.env"
|
|
chown $app:$app "$install_dir/variables.env"
|
|
|
|
ynh_add_config --template="../conf/settings.js" --destination="$install_dir/settings.js"
|
|
chmod 400 "$install_dir/settings.js"
|
|
chown $app:$app "$install_dir/settings.js"
|
|
|
|
#=================================================
|
|
# BUILDING APP
|
|
#=================================================
|
|
ynh_script_progression --message="Preparing app..."
|
|
|
|
mkdir -p "$install_dir/live"
|
|
cp "$install_dir/build/package.json" "$install_dir/live/package.json"
|
|
cp "$install_dir/build/package-lock.json" "$install_dir/live/package-lock.json"
|
|
cp -r "$install_dir/build/libraries/" "$install_dir/live/libraries/"
|
|
cp -r "$install_dir/build/services/" "$install_dir/live/services/"
|
|
cp -r "$install_dir/build/patches/" "$install_dir/live/patches/"
|
|
|
|
ynh_add_config --template="../conf/production.json" --destination="$install_dir/build/server-ce/config/production.json"
|
|
cp -r "$install_dir/build/server-ce/config/" "$install_dir/config/"
|
|
cp -r "$install_dir/build/server-ce/config/" "$install_dir/live/services/history-v1/config/"
|
|
|
|
ynh_secure_remove --file="$install_dir/build"
|
|
|
|
ynh_script_progression --message="Building app..."
|
|
pushd "$install_dir/live"
|
|
ynh_use_nodejs
|
|
ynh_exec_warn_less npm ci
|
|
popd
|
|
|
|
pushd "$install_dir/live/services/web"
|
|
ynh_exec_warn_less npm run webpack:production
|
|
ynh_secure_remove --file="$install_dir/live/services/web/node_modules/.cache"
|
|
popd
|
|
|
|
chmod 750 "$install_dir/live"
|
|
chmod -R o-rwx "$install_dir/live"
|
|
chown -R $app:www-data "$install_dir/live"
|
|
chown -R $app:www-data "$install_dir/config"
|
|
|
|
mkdir -p "$install_dir/tmp/uploads"
|
|
chmod 750 "$install_dir/tmp"
|
|
chmod -R o-rwx "$install_dir/tmp"
|
|
chown -R $app:www-data "$install_dir/tmp"
|
|
|
|
#=================================================
|
|
# SETUP SYSTEMD
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading systemd configuration..."
|
|
|
|
# Create a dedicated systemd config
|
|
ynh_add_systemd_config --service="$app-chat" --template="overleaf-chat.service"
|
|
ynh_add_systemd_config --service="$app-clsi" --template="overleaf-clsi.service"
|
|
ynh_add_systemd_config --service="$app-contacts" --template="overleaf-contacts.service"
|
|
ynh_add_systemd_config --service="$app-docstore" --template="overleaf-docstore.service"
|
|
ynh_add_systemd_config --service="$app-document-updater" --template="overleaf-document-updater.service"
|
|
ynh_add_systemd_config --service="$app-filestore" --template="overleaf-filestore.service"
|
|
ynh_add_systemd_config --service="$app-history-v1" --template="overleaf-history-v1.service"
|
|
ynh_add_systemd_config --service="$app-notifications" --template="overleaf-notifications.service"
|
|
ynh_add_systemd_config --service="$app-project-history" --template="overleaf-project-history.service"
|
|
ynh_add_systemd_config --service="$app-real-time" --template="overleaf-real-time.service"
|
|
ynh_add_systemd_config --service="$app-spelling" --template="overleaf-spelling.service"
|
|
ynh_add_systemd_config --service="$app-web" --template="overleaf-web.service"
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
# SETUP LOGROTATE
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading logrotate configuration..."
|
|
|
|
mkdir -p "/var/log/$app"
|
|
chown -R $app:$app "/var/log/$app"
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
ynh_use_logrotate --non-append
|
|
|
|
#=================================================
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
#=================================================
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
|
|
|
yunohost service add "$app-chat" --log="/var/log/$app/chat.log"
|
|
yunohost service add "$app-clsi" --log="/var/log/$app/clsi.log"
|
|
yunohost service add "$app-contacts" --log="/var/log/$app/contacts.log"
|
|
yunohost service add "$app-docstore" --log="/var/log/$app/docstore.log"
|
|
yunohost service add "$app-document-updater" --log="/var/log/$app/document-updater.log"
|
|
yunohost service add "$app-filestore" --log="/var/log/$app/filestore.log"
|
|
yunohost service add "$app-history-v1" --log="/var/log/$app/history-v1.log"
|
|
yunohost service add "$app-notifications" --log="/var/log/$app/notifications.log"
|
|
yunohost service add "$app-project-history" --log="/var/log/$app/project-history.log"
|
|
yunohost service add "$app-real-time" --log="/var/log/$app/real-time.log"
|
|
yunohost service add "$app-spelling" --log="/var/log/$app/spelling.log"
|
|
yunohost service add "$app-web" --log="/var/log/$app/web.log"
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting a systemd service..."
|
|
|
|
ynh_systemd_action --service_name="$app-chat" --action="start" --log_path="/var/log/$app/chat.log" --line_match="Using settings from"
|
|
ynh_systemd_action --service_name="$app-clsi" --action="start" --log_path="/var/log/$app/clsi.log" --line_match="Using settings from"
|
|
ynh_systemd_action --service_name="$app-contacts" --action="start" --log_path="/var/log/$app/contacts.log" --line_match="Using settings from"
|
|
ynh_systemd_action --service_name="$app-docstore" --action="start" --log_path="/var/log/$app/docstore.log" --line_match="Using settings from"
|
|
ynh_systemd_action --service_name="$app-document-updater" --action="start" --log_path="/var/log/$app/document-updater.log" --line_match="Using settings from"
|
|
ynh_systemd_action --service_name="$app-filestore" --action="start" --log_path="/var/log/$app/filestore.log" --line_match="Using settings from"
|
|
ynh_systemd_action --service_name="$app-history-v1" --action="start" --log_path="/var/log/$app/history-v1.log" --line_match="Loading backend"
|
|
ynh_systemd_action --service_name="$app-notifications" --action="start" --log_path="/var/log/$app/notifications.log" --line_match="Using settings from"
|
|
ynh_systemd_action --service_name="$app-project-history" --action="start" --log_path="/var/log/$app/project-history.log" --line_match="Using settings from"
|
|
ynh_systemd_action --service_name="$app-real-time" --action="start" --log_path="/var/log/$app/real-time.log" --line_match="Using settings from"
|
|
ynh_systemd_action --service_name="$app-spelling" --action="start" --log_path="/var/log/$app/spelling.log" --line_match="Using settings from"
|
|
ynh_systemd_action --service_name="$app-web" --action="start" --log_path="/var/log/$app/web.log" --line_match="listening on" --line_match="Using settings from"
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed"
|