2022-04-19 20:31:41 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2022-04-23 19:59:10 +02:00
|
|
|
web_api_password=$(ynh_string_random --length=32 | base64 -w 0 | rev | cut -b 2- | rev | tr -d '\n+/')
|
|
|
|
crypto_random=$(ynh_string_random --length=32 | base64 -w 0 | rev | cut -b 2- | rev | tr -d '\n+/')
|
|
|
|
admin_mail=$(ynh_user_get_info --username=$admin --key=mail)
|
|
|
|
|
|
|
|
ynh_app_setting_set --app=$app --key=crypto_random --value=$crypto_random
|
2023-11-22 15:12:51 +01:00
|
|
|
ynh_app_setting_set --app=$app --key=web_api_password --value=$web_api_password
|
2022-04-19 20:31:41 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
|
2022-04-23 19:59:10 +02:00
|
|
|
ynh_install_nodejs --nodejs_version=$nodejs_version
|
|
|
|
ynh_install_mongo
|
2022-04-19 20:31:41 +02:00
|
|
|
|
2023-11-19 17:20:03 +01:00
|
|
|
# Upgrade NPM
|
|
|
|
ynh_npm install --global npm@latest
|
|
|
|
|
2022-04-19 20:31:41 +02:00
|
|
|
#=================================================
|
2022-04-23 19:59:10 +02:00
|
|
|
# CREATE A MONGODB DATABASE
|
2022-04-19 20:31:41 +02:00
|
|
|
#=================================================
|
2022-04-23 19:59:10 +02:00
|
|
|
ynh_script_progression --message="Creating a MongoDB database..."
|
2022-04-19 20:31:41 +02:00
|
|
|
|
2023-11-19 17:01:44 +01:00
|
|
|
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
|
|
|
db_user=$db_name
|
|
|
|
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
2022-04-23 19:59:10 +02:00
|
|
|
ynh_mongo_setup_db --db_user=$db_user --db_name=$db_name
|
2022-04-19 20:31:41 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2022-04-23 19:59:10 +02:00
|
|
|
ynh_script_progression --message="Setting up source files..."
|
2022-04-19 20:31:41 +02:00
|
|
|
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2023-11-19 16:41:50 +01:00
|
|
|
ynh_setup_source --dest_dir="$install_dir/build"
|
2023-12-06 14:23:14 +01:00
|
|
|
#ynh_setup_source --dest_dir="$install_dir/build_ldap" --source_id="ldap"
|
2022-04-23 19:59:10 +02:00
|
|
|
|
2023-11-19 16:41:50 +01:00
|
|
|
chmod 750 "$install_dir"
|
|
|
|
chmod -R o-rwx "$install_dir"
|
|
|
|
chown -R $app:www-data "$install_dir"
|
2022-04-19 20:31:41 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2022-04-23 19:59:10 +02:00
|
|
|
ynh_script_progression --message="Configuring NGINX web server..."
|
2022-04-19 20:31:41 +02:00
|
|
|
|
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
|
|
|
# CREATE DATA DIRECTORY
|
|
|
|
#=================================================
|
2022-04-23 19:59:10 +02:00
|
|
|
ynh_script_progression --message="Creating a data directory..."
|
2022-04-19 20:31:41 +02:00
|
|
|
|
2023-12-06 09:37:43 +01:00
|
|
|
mkdir -p $data_dir/{compiles,output,cache}
|
2023-11-21 14:25:02 +01:00
|
|
|
|
2023-11-19 16:41:50 +01:00
|
|
|
chmod 750 "$data_dir"
|
|
|
|
chmod -R o-rwx "$data_dir"
|
|
|
|
chown -R $app:www-data "$data_dir"
|
2022-04-19 20:31:41 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ADD A CONFIGURATION
|
|
|
|
#=================================================
|
2022-04-23 19:59:10 +02:00
|
|
|
ynh_script_progression --message="Adding a configuration file..."
|
|
|
|
|
2023-11-19 16:41:50 +01:00
|
|
|
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"
|
2022-04-23 19:59:10 +02:00
|
|
|
|
2023-11-19 16:41:50 +01:00
|
|
|
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"
|
2022-04-23 19:59:10 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# BUILDING APP
|
|
|
|
#=================================================
|
2023-12-06 14:23:14 +01:00
|
|
|
ynh_script_progression --message="Preparing app..."
|
2022-04-23 19:59:10 +02:00
|
|
|
|
2023-11-19 16:41:50 +01:00
|
|
|
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/"
|
2023-11-20 09:09:57 +01:00
|
|
|
cp -r "$install_dir/build/patches/" "$install_dir/live/patches/"
|
2023-11-28 17:44:24 +01:00
|
|
|
cp -r "$install_dir/build/server-ce/config" "$install_dir/config/"
|
2023-12-05 19:46:57 +01:00
|
|
|
ynh_secure_remove --file="$install_dir/config/settings.js"
|
2023-11-28 17:44:24 +01:00
|
|
|
|
2023-12-17 14:37:46 +01:00
|
|
|
cp "$install_dir/build/server-ce/config/production.json" "$install_dir/live/services/history-v1/config/"
|
|
|
|
cp "$install_dir/build/server-ce/config/custom-environment-variables.json" "$install_dir/live/services/history-v1/config/"
|
|
|
|
|
2023-11-19 16:41:50 +01:00
|
|
|
|
2023-12-06 14:23:14 +01:00
|
|
|
#cp "$install_dir/build_ldap/ldap-overleaf-sl/sharelatex/AuthenticationManager.js" "$install_dir/live/services/web/app/src/Features/Authentication/AuthenticationManager.js"
|
|
|
|
#cp "$install_dir/build_ldap/ldap-overleaf-sl/sharelatex/ContactController.js" "$install_dir/live/services/web/app/src/Features/Contacts/ContactController.js"
|
2023-11-19 16:41:50 +01:00
|
|
|
#sed -iE '/type=.*email.*/d' $install_dir/live/services/web/app/views/user/login.pug
|
|
|
|
#sed -iE "s/email@example.com/${login_text:-user}/g" $install_dir/live/services/web/app/views/user/login.pug
|
|
|
|
#sed -iE '/email@example.com/{n;N;N;d}' $install_dir/live/services/web/app/views/user/login.pug
|
2023-12-06 14:23:14 +01:00
|
|
|
#sed -iE "s%-synctex=1\",%-synctex=1\", \"-shell-escape\",%g" $install_dir/live/services/clsi/app/js/LatexRunner.js
|
|
|
|
#sed -iE "s%'-synctex=1',%'-synctex=1', '-shell-escape',%g" $install_dir/live/services/clsi/app/js/LatexRunner.js
|
|
|
|
#cp "$install_dir/build_ldap/ldap-overleaf-sl/sharelatex/settings.pug" "$install_dir/live/services/web/app/views/user/settings.pug"
|
|
|
|
#cp "$install_dir/build_ldap/ldap-overleaf-sl/sharelatex/navbar.pug" "$install_dir/live/services/web/app/views/layout/navbar.pug"
|
|
|
|
#cp "$install_dir/build_ldap/ldap-overleaf-sl/sharelatex/admin-sysadmin.pug" "$install_dir/live/services/web/app/views/admin/index.pug"
|
|
|
|
#touch "$install_dir/live/services/web/app/views/project/editor/review-panel.pug"
|
2023-11-19 16:41:50 +01:00
|
|
|
|
2023-11-19 17:01:44 +01:00
|
|
|
ynh_secure_remove --file="$install_dir/build"
|
2023-12-06 14:23:14 +01:00
|
|
|
#ynh_secure_remove --file="$install_dir/build_ldap"
|
2023-11-19 16:41:50 +01:00
|
|
|
|
2023-12-06 14:23:14 +01:00
|
|
|
ynh_script_progression --message="Building app..."
|
2023-11-19 16:41:50 +01:00
|
|
|
pushd "$install_dir/live"
|
2022-04-23 19:59:10 +02:00
|
|
|
ynh_use_nodejs
|
2023-11-19 19:08:04 +01:00
|
|
|
ynh_exec_warn_less $ynh_npm install sandboxed-module@latest
|
2023-12-05 21:55:37 +01:00
|
|
|
#ynh_exec_warn_less $ynh_npm install -g npm@7.24.2
|
2023-12-06 08:54:48 +01:00
|
|
|
#$ynh_npm cache verify
|
|
|
|
#$ynh_npm cache clean --force
|
2023-12-06 19:41:10 +01:00
|
|
|
npm ci --quiet
|
2022-04-23 19:59:10 +02:00
|
|
|
popd
|
|
|
|
|
2023-11-19 16:41:50 +01:00
|
|
|
pushd "$install_dir/live/services/web"
|
2022-04-24 00:50:53 +02:00
|
|
|
ynh_exec_warn_less npm run webpack:production
|
2023-12-06 14:23:14 +01:00
|
|
|
#ynh_exec_warn_less npm install -g npm
|
2022-04-23 19:59:10 +02:00
|
|
|
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
|
2022-04-24 00:50:53 +02:00
|
|
|
ynh_exec_warn_less npm cache clean --force
|
2023-11-19 17:01:44 +01:00
|
|
|
ynh_secure_remove --file="$install_dir/live/services/web/node_modules/.cache"
|
2022-04-23 19:59:10 +02:00
|
|
|
popd
|
|
|
|
|
2023-11-19 16:41:50 +01:00
|
|
|
chmod 750 "$install_dir/live"
|
|
|
|
chmod -R o-rwx "$install_dir/live"
|
|
|
|
chown -R $app:www-data "$install_dir/live"
|
2023-12-05 19:12:12 +01:00
|
|
|
chown -R $app:www-data "$install_dir/config"
|
2022-04-23 19:59:10 +02:00
|
|
|
|
2023-11-19 16:41:50 +01:00
|
|
|
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"
|
2022-04-19 20:31:41 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
2022-04-23 19:59:10 +02:00
|
|
|
ynh_script_progression --message="Configuring a systemd service..."
|
2022-04-19 20:31:41 +02:00
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
2022-04-23 19:59:10 +02:00
|
|
|
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"
|
2023-11-22 15:12:51 +01:00
|
|
|
ynh_add_systemd_config --service="$app-history-v1" --template="overleaf-history-v1.service"
|
2022-04-23 19:59:10 +02:00
|
|
|
ynh_add_systemd_config --service="$app-notifications" --template="overleaf-notifications.service"
|
2023-11-22 15:12:51 +01:00
|
|
|
ynh_add_systemd_config --service="$app-project-history" --template="overleaf-project-history.service"
|
2022-04-23 19:59:10 +02:00
|
|
|
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"
|
2022-04-19 20:31:41 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
2022-04-23 19:59:10 +02:00
|
|
|
ynh_script_progression --message="Configuring log rotation..."
|
2022-04-19 20:31:41 +02:00
|
|
|
|
2022-04-23 19:59:10 +02:00
|
|
|
mkdir -p "/var/log/$app"
|
|
|
|
chown -R $app:$app "/var/log/$app"
|
2022-04-19 20:31:41 +02:00
|
|
|
# Use logrotate to manage application logfile(s)
|
|
|
|
ynh_use_logrotate
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
2022-04-23 19:59:10 +02:00
|
|
|
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"
|
2023-11-22 15:12:51 +01:00
|
|
|
yunohost service add "$app-history-v1" --log="/var/log/$app/history-v1.log"
|
2022-04-23 19:59:10 +02:00
|
|
|
yunohost service add "$app-notifications" --log="/var/log/$app/notifications.log"
|
2023-11-22 15:12:51 +01:00
|
|
|
yunohost service add "$app-project-history" --log="/var/log/$app/project-history.log"
|
2022-04-23 19:59:10 +02:00
|
|
|
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"
|
2022-04-19 20:31:41 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2022-04-23 19:59:10 +02:00
|
|
|
ynh_script_progression --message="Starting a systemd service..."
|
2022-04-19 20:31:41 +02:00
|
|
|
|
2023-11-21 14:25:02 +01:00
|
|
|
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"
|
2023-11-22 15:12:51 +01:00
|
|
|
ynh_systemd_action --service_name="$app-history-v1" --action="start" --log_path="/var/log/$app/history-v1.log" --line_match="Using settings from"
|
2023-11-21 14:25:02 +01:00
|
|
|
ynh_systemd_action --service_name="$app-notifications" --action="start" --log_path="/var/log/$app/notifications.log" --line_match="Using settings from"
|
2023-11-22 15:12:51 +01:00
|
|
|
ynh_systemd_action --service_name="$app-project-history" --action="start" --log_path="/var/log/$app/project-history.log" --line_match="Using settings from"
|
2023-11-21 14:25:02 +01:00
|
|
|
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"
|
2022-04-19 20:31:41 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2022-04-23 19:59:10 +02:00
|
|
|
ynh_script_progression --message="Installation of $app completed"
|