1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/overleaf_ynh.git synced 2024-09-03 19:56:27 +02:00
overleaf_ynh/scripts/install
2023-11-19 16:41:50 +01:00

301 lines
14 KiB
Bash
Executable file

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source ynh_mongo_db
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
#REMOVEME? ynh_clean_setup () {
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
#REMOVEME? ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
#REMOVEME? domain=$YNH_APP_ARG_DOMAIN
path="/"
#REMOVEME? is_public=$YNH_APP_ARG_IS_PUBLIC
#REMOVEME? language=$YNH_APP_ARG_LANGUAGE
#REMOVEME? admin=$YNH_APP_ARG_ADMIN
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
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)
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
#REMOVEME? ynh_script_progression --message="Validating installation parameters..."
#REMOVEME? install_dir=/var/www/$app
#REMOVEME? test ! -e "$install_dir" || ynh_die --message="This path already contains a folder"
# Register (book) web path
#REMOVEME? ynh_webpath_register --app=$app --domain=$domain --path=$path
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
#REMOVEME? ynh_script_progression --message="Storing installation settings..."
#REMOVEME? ynh_app_setting_set --app=$app --key=domain --value=$domain
#REMOVEME? ynh_app_setting_set --app=$app --key=path --value=$path
ynh_app_setting_set --app=$app --key=language --value=$language
#REMOVEME? ynh_app_setting_set --app=$app --key=admin --value=$admin
#REMOVEME? ynh_app_setting_set --app=$app --key=web_api_password --value=$web_api_password
ynh_app_setting_set --app=$app --key=crypto_random --value=$crypto_random
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
#REMOVEME? ynh_script_progression --message="Finding an available port..."
# Find an available port
#REMOVEME? port=$(ynh_find_port --port=8095)
#REMOVEME? ynh_app_setting_set --app=$app --key=port --value=$port
#=================================================
# INSTALL DEPENDENCIES
#=================================================
#REMOVEME? ynh_script_progression --message="Installing dependencies..."
#REMOVEME? ynh_install_app_dependencies $pkg_dependencies
ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_install_mongo
#=================================================
# CREATE DEDICATED USER
#=================================================
#REMOVEME? ynh_script_progression --message="Configuring system user..."
# Create a system user
#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir"
#=================================================
# CREATE A MONGODB DATABASE
#=================================================
ynh_script_progression --message="Creating a MongoDB database..."
#REMOVEME? db_name=$(ynh_sanitize_dbid --db_name=$app)
#REMOVEME? db_user=$db_name
#REMOVEME? ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_mongo_setup_db --db_user=$db_user --db_name=$db_name
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..."
#REMOVEME? ynh_app_setting_set --app=$app --key=install_dir --value=$install_dir
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir/build"
ynh_setup_source --dest_dir="$install_dir/build_ldap" --source_id="ldap"
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..."
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# SPECIFIC SETUP
#=================================================
# CREATE DATA DIRECTORY
#=================================================
ynh_script_progression --message="Creating a data directory..."
#REMOVEME? data_dir=/home/yunohost.app/$app
#REMOVEME? ynh_app_setting_set --app=$app --key=data_dir --value=$data_dir
mkdir -p $data_dir
chmod 750 "$data_dir"
chmod -R o-rwx "$data_dir"
chown -R $app:www-data "$data_dir"
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding 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="Building 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 "$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"
#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
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"
#REMOVEME? ynh_secure_remove --file="$install_dir/live/services/web/app/views/admin/register.pug"
#REMOVEME? ynh_secure_remove --file="$install_dir/live/services/web/app/views/project/editor/review-panel.pug"
touch "$install_dir/live/services/web/app/views/project/editor/review-panel.pug"
#REMOVEME? ynh_secure_remove --file="$install_dir/build"
#REMOVEME? ynh_secure_remove --file="$install_dir/build_ldap"
pushd "$install_dir/live"
ynh_use_nodejs
ynh_exec_warn_less $ynh_npm install -g npm@7.24.2
npm ci
popd
pushd "$install_dir/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
#REMOVEME? 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"
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="Configuring a systemd service..."
# 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="Configuring log rotation..."
mkdir -p "/var/log/$app"
chown -R $app:$app "/var/log/$app"
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
#=================================================
# 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..."
# Start 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"
#=================================================
# SETUP SSOWAT
#=================================================
#REMOVEME? ynh_script_progression --message="Configuring permissions..."
# Make app public if necessary
#REMOVEME? if [ $is_public -eq 1 ]
then
# Everyone can access the app.
# The "main" permission is automatically created before the install script.
#REMOVEME? ynh_permission_update --permission="main" --add="visitors"
fi
ynh_permission_url --permission="main" --auth_header=false
#REMOVEME? ynh_permission_create --permission="admin" --allowed="$admin"
#=================================================
# RELOAD NGINX
#=================================================
#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..."
#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed"