mirror of
https://github.com/YunoHost-Apps/overleaf_ynh.git
synced 2024-09-03 19:56:27 +02:00
272 lines
13 KiB
Bash
272 lines
13 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
ynh_script_progression --message="Loading installation settings..."
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
|
language=$(ynh_app_setting_get --app=$app --key=language)
|
|
admin=$(ynh_app_setting_get --app=$app --key=admin)
|
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
|
db_user=$db_name
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd)
|
|
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
|
|
port=$(ynh_app_setting_get --app=$app --key=port)
|
|
web_api_password=$(ynh_app_setting_get --app=$app --key=web_api_password)
|
|
crypto_random=$(ynh_app_setting_get --app=$app --key=crypto_random)
|
|
|
|
#=================================================
|
|
# CHECK VERSION
|
|
#=================================================
|
|
ynh_script_progression --message="Checking version..."
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
#=================================================
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
#=================================================
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
|
|
|
|
# Backup the current version of the app
|
|
ynh_backup_before_upgrade
|
|
ynh_clean_setup () {
|
|
ynh_clean_check_starting
|
|
# Restore it if the upgrade fails
|
|
ynh_restore_upgradebackup
|
|
}
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# 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-notifications" --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-track-changes" --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"
|
|
|
|
#=================================================
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
#=================================================
|
|
ynh_script_progression --message="Ensuring downward compatibility..."
|
|
|
|
#=================================================
|
|
# CREATE DEDICATED USER
|
|
#=================================================
|
|
ynh_script_progression --message="Making sure dedicated system user exists..."
|
|
|
|
# Create a dedicated user (if not existing)
|
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
|
|
|
#=================================================
|
|
# 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="$final_path/build"
|
|
ynh_setup_source --dest_dir="$final_path/build_ldap" --source_id="ldap"
|
|
fi
|
|
|
|
chmod 750 "$final_path"
|
|
chmod -R o-rwx "$final_path"
|
|
chown -R $app:www-data "$final_path"
|
|
|
|
#=================================================
|
|
# 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_app_dependencies $pkg_dependencies
|
|
ynh_install_nodejs --nodejs_version=$nodejs_version
|
|
ynh_install_mongo
|
|
|
|
#=================================================
|
|
# SPECIFIC UPGRADE
|
|
#=================================================
|
|
# UPDATE A CONFIG FILE
|
|
#=================================================
|
|
ynh_script_progression --message="Updating a configuration file..."
|
|
|
|
ynh_add_config --template="../conf/variables.env" --destination="$final_path/variables.env"
|
|
chmod 400 "$final_path/variables.env"
|
|
chown $app:$app "$final_path/variables.env"
|
|
|
|
ynh_add_config --template="../conf/settings.js" --destination="$final_path/settings.js"
|
|
chmod 400 "$final_path/settings.js"
|
|
chown $app:$app "$final_path/settings.js"
|
|
|
|
#=================================================
|
|
# BUILDING APP
|
|
#=================================================
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
then
|
|
ynh_script_progression --message="Building app..."
|
|
|
|
ynh_secure_remove --file="$final_path/live"
|
|
mkdir -p "$final_path/live"
|
|
cp "$final_path/build/server-ce/genScript.js" "$final_path/live/genScript.js"
|
|
cp "$final_path/build/server-ce/services.js" "$final_path/live/services.js"
|
|
cp "$final_path/build/package.json" "$final_path/live/package.json"
|
|
cp "$final_path/build/package-lock.json" "$final_path/live/package-lock.json"
|
|
cp -r "$final_path/build/libraries/" "$final_path/live/libraries/"
|
|
cp -r "$final_path/build/services/" "$final_path/live/services/"
|
|
|
|
cp "$final_path/build_ldap/ldap-overleaf-sl/sharelatex/AuthenticationManager.js" "$final_path/live/services/web/app/src/Features/Authentication/AuthenticationManager.js"
|
|
cp "$final_path/build_ldap/ldap-overleaf-sl/sharelatex/ContactController.js" "$final_path/live/services/web/app/src/Features/Contacts/ContactController.js"
|
|
#sed -iE '/type=.*email.*/d' $final_path/live/services/web/app/views/user/login.pug
|
|
#sed -iE "s/email@example.com/${login_text:-user}/g" $final_path/live/services/web/app/views/user/login.pug
|
|
#sed -iE '/email@example.com/{n;N;N;d}' $final_path/live/services/web/app/views/user/login.pug
|
|
sed -iE "s%-synctex=1\",%-synctex=1\", \"-shell-escape\",%g" $final_path/live/services/clsi/app/js/LatexRunner.js
|
|
sed -iE "s%'-synctex=1',%'-synctex=1', '-shell-escape',%g" $final_path/live/services/clsi/app/js/LatexRunner.js
|
|
cp "$final_path/build_ldap/ldap-overleaf-sl/sharelatex/settings.pug" "$final_path/live/services/web/app/views/user/settings.pug"
|
|
cp "$final_path/build_ldap/ldap-overleaf-sl/sharelatex/navbar.pug" "$final_path/live/services/web/app/views/layout/navbar.pug"
|
|
cp "$final_path/build_ldap/ldap-overleaf-sl/sharelatex/admin-sysadmin.pug" "$final_path/live/services/web/app/views/admin/index.pug"
|
|
ynh_secure_remove --file="$final_path/live/services/web/app/views/admin/register.pug"
|
|
ynh_secure_remove --file="$final_path/live/services/web/app/views/project/editor/review-panel.pug"
|
|
touch "$final_path/live/services/web/app/views/project/editor/review-panel.pug"
|
|
|
|
ynh_secure_remove --file="$final_path/build"
|
|
ynh_secure_remove --file="$final_path/build_ldap"
|
|
|
|
pushd "$final_path/live"
|
|
ynh_use_nodejs
|
|
ynh_exec_warn_less $ynh_npm install -g npm@7.24.2
|
|
npm ci
|
|
popd
|
|
|
|
pushd "$final_path/live/services/web"
|
|
ynh_exec_warn_less npm run webpack:production
|
|
ynh_exec_warn_less npm install -g npm
|
|
ynh_exec_warn_less npm install ldap-escape
|
|
ynh_exec_warn_less npm install ldapts-search
|
|
ynh_exec_warn_less npm install ldapts
|
|
ynh_exec_warn_less npm install ldap-escape
|
|
ynh_exec_warn_less npm cache clean --force
|
|
ynh_secure_remove --file="$final_path/live/services/web/node_modules/.cache"
|
|
popd
|
|
|
|
chmod 750 "$final_path/live"
|
|
chmod -R o-rwx "$final_path/live"
|
|
chown -R $app:www-data "$final_path/live"
|
|
|
|
mkdir -p "$final_path/tmp/uploads"
|
|
|
|
chmod 750 "$final_path/tmp"
|
|
chmod -R o-rwx "$final_path/tmp"
|
|
chown -R $app:www-data "$final_path/tmp"
|
|
fi
|
|
|
|
#=================================================
|
|
# 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-notifications" --template="overleaf-notifications.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-track-changes" --template="overleaf-track-changes.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-notifications" --log="/var/log/$app/notifications.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-track-changes" --log="/var/log/$app/track-changes.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="listening on"
|
|
ynh_systemd_action --service_name="$app-clsi" --action="start" --log_path="/var/log/$app/clsi.log" --line_match="listening on"
|
|
ynh_systemd_action --service_name="$app-contacts" --action="start" --log_path="/var/log/$app/contacts.log" --line_match="listening on"
|
|
ynh_systemd_action --service_name="$app-docstore" --action="start" --log_path="/var/log/$app/docstore.log" --line_match="listening on"
|
|
ynh_systemd_action --service_name="$app-document-updater" --action="start" --log_path="/var/log/$app/document-updater.log" --line_match="listening on"
|
|
ynh_systemd_action --service_name="$app-filestore" --action="start" --log_path="/var/log/$app/filestore.log" --line_match="listening on"
|
|
ynh_systemd_action --service_name="$app-notifications" --action="start" --log_path="/var/log/$app/notifications.log" --line_match="listening on"
|
|
ynh_systemd_action --service_name="$app-real-time" --action="start" --log_path="/var/log/$app/real-time.log" --line_match="listening on"
|
|
ynh_systemd_action --service_name="$app-spelling" --action="start" --log_path="/var/log/$app/spelling.log" --line_match="listening on"
|
|
ynh_systemd_action --service_name="$app-track-changes" --action="start" --log_path="/var/log/$app/track-changes.log" --line_match="listening on"
|
|
ynh_systemd_action --service_name="$app-web" --action="start" --log_path="/var/log/$app/web.log" --line_match="listening on" --line_match="listening on"
|
|
|
|
#=================================================
|
|
# RELOAD NGINX
|
|
#=================================================
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed"
|