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

302 lines
13 KiB
Text
Raw Normal View History

2022-04-19 20:31:41 +02:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
2022-04-23 19:59:10 +02:00
source ynh_mongo_db
2022-04-19 20:31:41 +02:00
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
2022-04-23 19:59:10 +02:00
ynh_clean_check_starting
2022-04-19 20:31:41 +02:00
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
domain=$YNH_APP_ARG_DOMAIN
2022-04-23 19:59:10 +02:00
path_url="/"
2022-04-19 20:31:41 +02:00
is_public=$YNH_APP_ARG_IS_PUBLIC
language=$YNH_APP_ARG_LANGUAGE
admin=$YNH_APP_ARG_ADMIN
2022-04-23 19:59:10 +02:00
2022-04-19 20:31:41 +02:00
app=$YNH_APP_INSTANCE_NAME
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)
2022-04-19 20:31:41 +02:00
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
2022-04-23 19:59:10 +02:00
ynh_script_progression --message="Validating installation parameters..."
2022-04-19 20:31:41 +02:00
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
# Register (book) web path
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2022-04-23 19:59:10 +02:00
ynh_script_progression --message="Storing installation settings..."
2022-04-19 20:31:41 +02:00
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
ynh_app_setting_set --app=$app --key=language --value=$language
ynh_app_setting_set --app=$app --key=admin --value=$admin
2022-04-23 19:59:10 +02:00
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
2022-04-19 20:31:41 +02:00
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
2022-04-23 19:59:10 +02:00
ynh_script_progression --message="Finding an available port..."
2022-04-19 20:31:41 +02:00
# Find an available port
port=$(ynh_find_port --port=8095)
ynh_app_setting_set --app=$app --key=port --value=$port
#=================================================
# INSTALL DEPENDENCIES
#=================================================
2022-04-23 19:59:10 +02:00
ynh_script_progression --message="Installing dependencies..."
2022-04-19 20:31:41 +02:00
ynh_install_app_dependencies $pkg_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
#=================================================
# CREATE DEDICATED USER
#=================================================
2022-04-23 19:59:10 +02:00
ynh_script_progression --message="Configuring system user..."
2022-04-19 20:31:41 +02:00
# Create a system user
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
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
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
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
2022-04-23 19:59:10 +02:00
ynh_setup_source --dest_dir="$final_path/build"
ynh_setup_source --dest_dir="$final_path/build_ldap" --source_id="ldap"
2022-04-19 20:31:41 +02:00
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
#=================================================
# 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
datadir=/home/yunohost.app/$app
ynh_app_setting_set --app=$app --key=datadir --value=$datadir
mkdir -p $datadir
chmod 750 "$datadir"
chmod -R o-rwx "$datadir"
chown -R $app:www-data "$datadir"
#=================================================
# ADD A CONFIGURATION
#=================================================
2022-04-23 19:59:10 +02:00
ynh_script_progression --message="Adding 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
#=================================================
ynh_script_progression --message="Building app..."
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
2022-04-24 00:50:53 +02:00
npm ci
2022-04-23 19:59:10 +02:00
popd
pushd "$final_path/live/services/web"
2022-04-24 00:50:53 +02:00
ynh_exec_warn_less npm run webpack:production
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
ynh_secure_remove --file="$final_path/live/services/web/node_modules/.cache"
2022-04-23 19:59:10 +02:00
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"
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"
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"
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"
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"
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
# Start a systemd service
2022-04-23 19:59:10 +02:00
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"
2022-04-19 20:31:41 +02:00
#=================================================
# SETUP SSOWAT
#=================================================
2022-04-23 19:59:10 +02:00
ynh_script_progression --message="Configuring permissions..."
2022-04-19 20:31:41 +02:00
# Make app public if necessary
if [ $is_public -eq 1 ]
then
# Everyone can access the app.
# The "main" permission is automatically created before the install script.
ynh_permission_update --permission="main" --add="visitors"
fi
2022-04-23 19:59:10 +02:00
ynh_permission_url --permission="main" --auth_header=false
2022-04-19 20:31:41 +02:00
2022-04-23 19:59:10 +02:00
ynh_permission_create --permission="admin" --allowed="$admin"
2022-04-19 20:31:41 +02:00
#=================================================
# RELOAD NGINX
#=================================================
2022-04-23 19:59:10 +02:00
ynh_script_progression --message="Reloading NGINX web server..."
2022-04-19 20:31:41 +02:00
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
2022-04-23 19:59:10 +02:00
ynh_script_progression --message="Installation of $app completed"