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

221 lines
10 KiB
Text
Raw Permalink Normal View History

2022-04-19 20:31:41 +02:00
#!/bin/bash
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)
2024-06-27 20:48:13 +02:00
ynh_app_setting_set --key=crypto_random --value=$crypto_random
ynh_app_setting_set --key=web_api_password --value=$web_api_password
2022-04-19 20:31:41 +02:00
2024-02-11 12:17:34 +01:00
# key for the .env __JWT_KEY__
jwt_key=$(ynh_string_random --length=45 | base64)
2024-06-27 20:48:13 +02:00
ynh_app_setting_set --key=jwt_key --value=$jwt_key
2024-02-08 10:15:58 +01:00
2024-02-12 13:30:51 +01:00
# Retrieve YunoHost main domain for mails to work
2024-02-12 13:39:16 +01:00
main_domain=$(cat /etc/yunohost/current_host)
2024-06-27 20:48:13 +02:00
ynh_app_setting_set --key=main_domain --value=$main_domain
2024-02-12 14:43:48 +01:00
2022-04-19 20:31:41 +02:00
#=================================================
# INSTALL DEPENDENCIES
#=================================================
2024-06-27 20:48:13 +02:00
ynh_nodejs_install
2022-04-23 19:59:10 +02:00
ynh_install_mongo
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
#=================================================
2024-06-27 20:48:13 +02:00
ynh_script_progression "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
2024-06-27 20:48:13 +02:00
ynh_app_setting_set --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
2024-02-15 15:29:57 +01:00
#=================================================
# SPECIFIC SETUP
#=================================================
# CONFIGURE MONGOD
#=================================================
2024-06-27 20:48:13 +02:00
ynh_script_progression "Configuring MongoDB..."
2024-02-15 15:29:57 +01:00
2024-06-27 20:48:13 +02:00
ynh_replace --match="#replication:" --replace="replication:\n replSetName: rs0" --file="/etc/mongod.conf"
2024-02-15 15:29:57 +01:00
2024-06-27 20:48:13 +02:00
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"
2024-02-15 15:29:57 +01:00
2024-06-27 20:48:13 +02:00
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())"
2024-02-20 19:14:24 +01:00
fi
2022-04-19 20:31:41 +02:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2024-06-27 20:48:13 +02:00
ynh_script_progression "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"
2024-02-12 13:22:40 +01:00
mkdir -p $install_dir/tmp
mkdir -p $install_dir/tmp/{projectHistories,dumpFolder,uploads}
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
#=================================================
2024-06-27 20:48:13 +02:00
ynh_script_progression "Configuring NGINX web server..."
2022-04-19 20:31:41 +02:00
# Create a dedicated NGINX config
2024-06-27 20:48:13 +02:00
ynh_config_add_nginx
2022-04-19 20:31:41 +02:00
#=================================================
# SPECIFIC SETUP
#=================================================
# CREATE DATA DIRECTORY
#=================================================
2024-06-27 20:48:13 +02:00
ynh_script_progression "Creating a data directory..."
2022-04-19 20:31:41 +02: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
#=================================================
2024-06-27 20:48:13 +02:00
ynh_script_progression "Adding $app's configuration..."
2022-04-23 19:59:10 +02:00
2024-06-27 20:48:13 +02:00
ynh_config_add --template="variables.env" --destination="$install_dir/variables.env"
2023-11-19 16:41:50 +01:00
chmod 400 "$install_dir/variables.env"
chown $app:$app "$install_dir/variables.env"
2022-04-23 19:59:10 +02:00
2024-06-27 20:48:13 +02:00
ynh_config_add --template="settings.js" --destination="$install_dir/settings.js"
2023-11-19 16:41:50 +01:00
chmod 400 "$install_dir/settings.js"
chown $app:$app "$install_dir/settings.js"
2022-04-23 19:59:10 +02:00
#=================================================
# BUILDING APP
#=================================================
2024-06-27 20:48:13 +02:00
ynh_script_progression "Preparing app..."
2022-04-23 19:59:10 +02:00
2023-11-19 16:41:50 +01:00
mkdir -p "$install_dir/live"
2024-02-20 19:14:24 +01:00
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"
2023-11-19 16:41:50 +01:00
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/"
2024-02-12 17:02:26 +01:00
cp -r "$install_dir/build/server-ce/config" "$install_dir/config/"
2024-06-27 20:48:13 +02:00
ynh_safe_rm "$install_dir/config/settings.js"
ynh_safe_rm "$install_dir/config/production.json"
2023-12-17 14:37:46 +01:00
2024-06-27 20:48:13 +02:00
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"
2024-02-20 21:29:49 +01:00
cp "$install_dir/build/server-ce/config/custom-environment-variables.json" "$install_dir/live/services/history-v1/config/"
2024-02-13 13:54:12 +01:00
2024-06-27 20:48:13 +02:00
ynh_safe_rm "$install_dir/build"
2023-11-19 16:41:50 +01:00
2024-06-27 20:48:13 +02:00
ynh_script_progression "Building app... This may take a LOT of time depending of your CPU"
2024-01-23 08:35:04 +01:00
pushd "$install_dir/live"
2024-06-27 20:48:13 +02:00
ynh_hide_warnings npm cache clean --force
ynh_hide_warnings npm install
ynh_hide_warnings npm ci
2024-01-16 20:19:43 +01:00
popd
2022-04-23 19:59:10 +02:00
2024-01-16 20:19:43 +01:00
pushd "$install_dir/live/services/web"
2024-06-27 20:48:13 +02:00
ynh_hide_warnings npm run webpack:production
ynh_safe_rm "$install_dir/live/services/web/node_modules/.cache"
2024-01-16 20:19:43 +01:00
popd
2022-04-23 19:59:10 +02:00
2024-05-02 08:53:30 +02:00
# remove build dir
2024-06-27 20:48:13 +02:00
ynh_safe_rm "$install_dir/build"
2024-05-02 08:53:30 +02:00
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
#=================================================
2024-06-27 20:48:13 +02:00
ynh_script_progression "Configuring $app's systemd service..."
2022-04-19 20:31:41 +02:00
# Create a dedicated systemd config
2024-06-27 20:48:13 +02:00
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"
2022-04-19 20:31:41 +02:00
#=================================================
# SETUP LOGROTATE
#=================================================
2024-06-27 20:48:13 +02:00
ynh_script_progression "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)
2024-06-27 20:48:13 +02:00
ynh_config_add_logrotate
2022-04-19 20:31:41 +02:00
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
2024-06-27 20:48:13 +02:00
ynh_script_progression "Integrating service in YunoHost..."
2022-04-23 19:59:10 +02:00
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
#=================================================
2024-06-27 20:48:13 +02:00
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"
2022-04-19 20:31:41 +02:00
2024-06-27 20:48:13 +02:00
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"
2022-04-19 20:31:41 +02:00
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression "Installation of $app completed"