#!/bin/bash source _common.sh source /usr/share/yunohost/helpers ynh_script_progression "Checking version..." # Retrieve YunoHost main domain for mails to work main_domain=$(cat /etc/yunohost/current_host) #================================================= # LOAD SETTINGS #================================================= # FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=jwt_key --value=$(ynh_string_random --length=45 | base64) if [ -z "${jwt_key:-}" ]; then jwt_key=$(ynh_string_random --length=45 | base64) ynh_app_setting_set --key=jwt_key --value=$jwt_key fi #================================================= # STOP SYSTEMD SERVICE #================================================= ynh_script_progression "Stopping $app's systemd service..." ynh_systemctl --service="$app-chat" --action="stop" ynh_systemctl --service="$app-clsi" --action="stop" ynh_systemctl --service="$app-contacts" --action="stop" ynh_systemctl --service="$app-docstore" --action="stop" ynh_systemctl --service="$app-document-updater" --action="stop" ynh_systemctl --service="$app-filestore" --action="stop" ynh_systemctl --service="$app-history-v1" --action="stop" ynh_systemctl --service="$app-notifications" --action="stop" ynh_systemctl --service="$app-project-history" --action="stop" ynh_systemctl --service="$app-real-time" --action="stop" ynh_systemctl --service="$app-spelling" --action="stop" ynh_systemctl --service="$app-web" --action="stop" if ynh_hide_warnings yunohost service status "$app-track-changes" >/dev/null then ynh_script_progression "Removing $app-track-changes service integration..." yunohost service remove "$app-track-changes" fi #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= ynh_script_progression "Ensuring downward compatibility..." #================================================= # SPECIFIC SETUP #================================================= # CONFIGURE MONGOD #================================================= ynh_script_progression "Configuring MongoDB..." ynh_replace --match="#replication:" --replace="replication:\n replSetName: rs0" --file="/etc/mongod.conf" ynh_hide_warnings systemctl enable mongod --quiet ynh_systemctl --service=mongod --action=restart --log_path=/var/log/mongodb/mongod.log --wait_until="Waiting for connections" if ynh_hide_warnings ynh_mongo_exec --command="printjson(rs.status())" | grep -q "no replset config has been received"; then ynh_hide_warnings ynh_mongo_exec --command="printjson(rs.initiate())" fi #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= # FIXME: this is still supported but the recommendation is now to *always* re-setup the app sources wether or not the upstream sources changed if ynh_app_upstream_version_changed then ynh_script_progression "Upgrading source files..." # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$install_dir/build" --full_replace fi # full replace on live dir ynh_safe_rm "$install_dir/live" #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 750 "$install_dir" #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir" #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:www-data "$install_dir" #================================================= # NGINX CONFIGURATION #================================================= ynh_script_progression "Upgrading NGINX web server configuration..." # Create a dedicated NGINX config ynh_config_add_nginx #================================================= # UPGRADE DEPENDENCIES #================================================= ynh_script_progression "Upgrading dependencies..." ynh_nodejs_install ynh_install_mongo #================================================= # UPDATE A CONFIG FILE #================================================= ynh_script_progression "Updating configuration..." ynh_config_add --template="variables.env" --destination="$install_dir/variables.env" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$install_dir/variables.env" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app:$app "$install_dir/variables.env" ynh_config_add --template="settings.js" --destination="$install_dir/settings.js" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$install_dir/settings.js" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app:$app "$install_dir/settings.js" #================================================= # BUILDING APP #================================================= ynh_script_progression "Preparing app..." mkdir -p "$install_dir/live" cp "$install_dir/build/server-ce/genScript.js" "$install_dir/live/genScript.js" cp "$install_dir/build/server-ce/services.js" "$install_dir/live/services.js" 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/" cp -r "$install_dir/build/server-ce/config" "$install_dir/config/" ynh_safe_rm "$install_dir/config/settings.js" ynh_safe_rm "$install_dir/config/production.json" ynh_safe_rm "$install_dir/live/services/history-v1/config/production.json" ynh_config_add --template="production.json" --destination="$install_dir/config/production.json" ynh_config_add --template="production.json" --destination="$install_dir/live/services/history-v1/config/production.json" cp "$install_dir/build/server-ce/config/custom-environment-variables.json" "$install_dir/live/services/history-v1/config/" ynh_script_progression "Building app... This may take a LOT of time depending of your CPU" pushd "$install_dir/live" ynh_hide_warnings npm cache clean --force ynh_hide_warnings npm install ynh_hide_warnings npm ci popd pushd "$install_dir/live/services/web" ynh_hide_warnings npm run webpack:production ynh_safe_rm "$install_dir/live/services/web/node_modules/.cache" popd #remove build dir ynh_safe_rm "$install_dir/build" 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 "Upgrading systemd configuration..." # Create a dedicated systemd config ynh_config_add_systemd --service="$app-chat" --template="overleaf-chat.service" ynh_config_add_systemd --service="$app-clsi" --template="overleaf-clsi.service" ynh_config_add_systemd --service="$app-contacts" --template="overleaf-contacts.service" ynh_config_add_systemd --service="$app-docstore" --template="overleaf-docstore.service" ynh_config_add_systemd --service="$app-document-updater" --template="overleaf-document-updater.service" ynh_config_add_systemd --service="$app-filestore" --template="overleaf-filestore.service" ynh_config_add_systemd --service="$app-history-v1" --template="overleaf-history-v1.service" ynh_config_add_systemd --service="$app-notifications" --template="overleaf-notifications.service" ynh_config_add_systemd --service="$app-project-history" --template="overleaf-project-history.service" ynh_config_add_systemd --service="$app-real-time" --template="overleaf-real-time.service" ynh_config_add_systemd --service="$app-spelling" --template="overleaf-spelling.service" ynh_config_add_systemd --service="$app-web" --template="overleaf-web.service" #================================================= # SETUP LOGROTATE #================================================= ynh_script_progression "Upgrading logrotate configuration..." mkdir -p "/var/log/$app" #REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:$app "/var/log/$app" # Use logrotate to manage app-specific logfile(s) ynh_config_add_logrotate #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression "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 "Starting $app's systemd service..." ynh_systemctl --service="$app-chat" --action="start" --log_path="/var/log/$app/chat.log" --wait_until="Using settings from" ynh_systemctl --service="$app-clsi" --action="start" --log_path="/var/log/$app/clsi.log" --wait_until="Using settings from" ynh_systemctl --service="$app-contacts" --action="start" --log_path="/var/log/$app/contacts.log" --wait_until="Using settings from" ynh_systemctl --service="$app-docstore" --action="start" --log_path="/var/log/$app/docstore.log" --wait_until="Using settings from" ynh_systemctl --service="$app-document-updater" --action="start" --log_path="/var/log/$app/document-updater.log" --wait_until="Using settings from" ynh_systemctl --service="$app-filestore" --action="start" --log_path="/var/log/$app/filestore.log" --wait_until="Using settings from" ynh_systemctl --service="$app-history-v1" --action="start" --log_path="/var/log/$app/history-v1.log" --wait_until="Loading backend" ynh_systemctl --service="$app-notifications" --action="start" --log_path="/var/log/$app/notifications.log" --wait_until="Using settings from" ynh_systemctl --service="$app-project-history" --action="start" --log_path="/var/log/$app/project-history.log" --wait_until="Using settings from" ynh_systemctl --service="$app-real-time" --action="start" --log_path="/var/log/$app/real-time.log" --wait_until="Using settings from" ynh_systemctl --service="$app-spelling" --action="start" --log_path="/var/log/$app/spelling.log" --wait_until="Using settings from" ynh_systemctl --service="$app-web" --action="start" --log_path="/var/log/$app/web.log" --wait_until="listening on" --wait_until="Using settings from" #================================================= # END OF SCRIPT #================================================= ynh_script_progression "Upgrade of $app completed"