2020-01-18 10:28:47 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
2021-08-29 00:17:52 +02:00
|
|
|
source ynh_add_swap
|
2020-01-18 10:28:47 +01:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
2024-01-15 22:17:38 +01:00
|
|
|
# INITIALIZE AND STORE SETTINGS
|
2020-01-18 10:28:47 +01:00
|
|
|
#=================================================
|
|
|
|
|
2022-08-31 02:25:01 +02:00
|
|
|
redis_db=$(ynh_redis_get_free_db)
|
|
|
|
disable_user_registration=false
|
|
|
|
files_size=100
|
|
|
|
|
2024-01-15 22:17:38 +01:00
|
|
|
ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db"
|
|
|
|
ynh_app_setting_set --app="$app" --key=DISABLE_USER_REGISTRATION --value=$disable_user_registration
|
|
|
|
ynh_app_setting_set --app="$app" --key=FILES_SIZE --value=$files_size
|
2021-07-05 19:08:00 +02:00
|
|
|
|
2020-01-18 10:28:47 +01:00
|
|
|
#=================================================
|
2024-01-15 22:17:38 +01:00
|
|
|
# INSTALL NODEJS
|
2020-01-18 10:28:47 +01:00
|
|
|
#=================================================
|
2024-01-15 22:17:38 +01:00
|
|
|
ynh_script_progression --message="Installing NodeJS..." --weight=17
|
2020-01-18 10:28:47 +01:00
|
|
|
|
2024-01-15 22:17:38 +01:00
|
|
|
ynh_install_nodejs --nodejs_version="$nodejs_version"
|
2020-01-18 10:28:47 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2022-08-31 02:25:01 +02:00
|
|
|
ynh_script_progression --message="Setting up source files..." --weight=2
|
2020-01-18 10:28:47 +01:00
|
|
|
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2024-01-15 22:17:38 +01:00
|
|
|
ynh_setup_source --dest_dir="$install_dir/live"
|
|
|
|
cp "$YNH_APP_BASEDIR/sources/extra_files/cron.sh" "$install_dir/cron.sh"
|
2022-08-04 17:28:39 +02:00
|
|
|
|
2024-01-15 22:17:38 +01:00
|
|
|
chmod -R o-rwx "$install_dir"
|
|
|
|
chown -R "$app:$app" "$install_dir"
|
2022-08-04 17:28:39 +02:00
|
|
|
|
2024-01-15 22:17:38 +01:00
|
|
|
chmod -R o-rwx "$data_dir"
|
|
|
|
chown -R "$app:$app" "$data_dir"
|
2022-08-04 17:28:39 +02:00
|
|
|
|
2021-08-29 00:17:52 +02:00
|
|
|
#=================================================
|
2022-08-31 02:25:01 +02:00
|
|
|
# ADD A CONFIGURATION
|
2020-01-18 10:28:47 +01:00
|
|
|
#=================================================
|
2024-01-15 22:17:38 +01:00
|
|
|
ynh_script_progression --message="Adding configuration files..." --weight=2
|
2020-01-18 10:28:47 +01:00
|
|
|
|
2024-01-15 22:17:38 +01:00
|
|
|
config_api_gateway="$install_dir/live/api-gateway.env"
|
|
|
|
config_auth="$install_dir/live/auth.env"
|
|
|
|
config_auth_worker="$install_dir/live/auth-worker.env"
|
|
|
|
config_files="$install_dir/live/files.env"
|
|
|
|
config_syncing_server="$install_dir/live/syncing-server.env"
|
|
|
|
config_syncing_server_worker="$install_dir/live/syncing-server-worker.env"
|
|
|
|
config_workspace="$install_dir/live/workspace.env"
|
2021-07-04 21:45:43 +02:00
|
|
|
|
2021-07-05 19:08:00 +02:00
|
|
|
jwt_secret=$(ynh_string_random --length=48 | base64)
|
|
|
|
legacy_jwt_secret=$(ynh_string_random --length=48 | base64)
|
|
|
|
auth_jwt_secret=$(ynh_string_random --length=48 | base64)
|
2021-07-04 21:45:43 +02:00
|
|
|
pseudo_key_params_key=$(ynh_string_random --length=48 | base64)
|
2021-07-06 15:45:29 +02:00
|
|
|
encryption_server_key=$(hexdump -n 32 -e '4/4 "%08X"' /dev/random) # 32bytes hex key is required
|
2022-08-04 17:28:39 +02:00
|
|
|
valet_token_secret=$(ynh_string_random --length=48 | base64)
|
2021-07-04 21:45:43 +02:00
|
|
|
|
2021-07-05 19:08:00 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=jwt_secret --value=$jwt_secret
|
|
|
|
ynh_app_setting_set --app=$app --key=legacy_jwt_secret --value=$legacy_jwt_secret
|
|
|
|
ynh_app_setting_set --app=$app --key=auth_jwt_secret --value=$auth_jwt_secret
|
2021-07-04 21:45:43 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=pseudo_key_params_key --value=$pseudo_key_params_key
|
|
|
|
ynh_app_setting_set --app=$app --key=encryption_server_key --value=$encryption_server_key
|
2022-08-04 17:28:39 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=valet_token_secret --value=$valet_token_secret
|
2021-07-04 21:45:43 +02:00
|
|
|
|
2022-08-04 17:28:39 +02:00
|
|
|
ynh_add_config --template="env_api-gateway.env.sample" --destination="$config_api_gateway"
|
2021-07-04 21:45:43 +02:00
|
|
|
ynh_add_config --template="env_auth.env.sample" --destination="$config_auth"
|
2021-07-04 22:46:56 +02:00
|
|
|
ynh_add_config --template="env_auth-worker.env.sample" --destination="$config_auth_worker"
|
2022-08-04 17:28:39 +02:00
|
|
|
ynh_add_config --template="env_files.env.sample" --destination="$config_files"
|
|
|
|
ynh_add_config --template="env_syncing-server.env.sample" --destination="$config_syncing_server"
|
|
|
|
ynh_add_config --template="env_syncing-server-worker.env.sample" --destination="$config_syncing_server_worker"
|
2022-10-25 18:42:07 +02:00
|
|
|
ynh_add_config --template="env_workspace.env.sample" --destination="$config_workspace"
|
2021-07-04 21:45:43 +02:00
|
|
|
|
2024-01-15 22:17:38 +01:00
|
|
|
ynh_add_config --template="cron.env" --destination="$install_dir/cron.env"
|
|
|
|
|
2020-01-18 10:28:47 +01:00
|
|
|
#=================================================
|
2021-05-01 21:48:58 +02:00
|
|
|
# INSTALLING Standard Notes - Syncing Server
|
2020-01-18 10:28:47 +01:00
|
|
|
#=================================================
|
2024-01-15 22:17:38 +01:00
|
|
|
ynh_script_progression --message="Building Standard Notes - Syncing Server..." --weight=93
|
2020-01-18 10:28:47 +01:00
|
|
|
|
2021-07-04 21:45:43 +02:00
|
|
|
ynh_use_nodejs
|
2024-01-15 22:17:38 +01:00
|
|
|
pushd "$install_dir/live"
|
|
|
|
ynh_exec_warn_less ynh_exec_as "$app" env NODE_ENV="production" NODE_OPTIONS="--max-old-space-size=$node_max_old_space_size" "$ynh_node_load_PATH" yarn install --immutable
|
|
|
|
ynh_exec_warn_less ynh_exec_as "$app" env NODE_ENV="production" NODE_OPTIONS="--max-old-space-size=$node_max_old_space_size" "$ynh_node_load_PATH" yarn build
|
2020-01-18 10:28:47 +01:00
|
|
|
popd
|
2021-07-06 01:37:20 +02:00
|
|
|
|
2020-01-18 10:28:47 +01:00
|
|
|
#=================================================
|
2024-01-15 22:17:38 +01:00
|
|
|
# SYSTEM CONFIGURATION
|
2020-01-18 10:28:47 +01:00
|
|
|
#=================================================
|
2024-01-15 22:17:38 +01:00
|
|
|
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
|
|
|
|
|
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config
|
2020-01-18 10:28:47 +01:00
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
2022-08-04 17:28:39 +02:00
|
|
|
ynh_add_systemd_config --service="$app-api-gateway" --template="systemd_api-gateway.service"
|
2021-07-05 20:50:52 +02:00
|
|
|
ynh_add_systemd_config --service="$app-auth" --template="systemd_auth.service"
|
|
|
|
ynh_add_systemd_config --service="$app-auth-worker" --template="systemd_auth-worker.service"
|
2022-08-04 17:28:39 +02:00
|
|
|
ynh_add_systemd_config --service="$app-files" --template="systemd_files.service"
|
|
|
|
ynh_add_systemd_config --service="$app-syncing-server" --template="systemd_syncing-server.service"
|
|
|
|
ynh_add_systemd_config --service="$app-syncing-server-worker" --template="systemd_syncing-server-worker.service"
|
2022-10-25 18:42:07 +02:00
|
|
|
ynh_add_systemd_config --service="$app-workspace" --template="systemd_workspace.service"
|
2024-01-15 22:17:38 +01:00
|
|
|
yunohost service add "$app-api-gateway" --description="Standard Notes - API Gateway" --log="/var/log/$app/api-gateway.log"
|
|
|
|
yunohost service add "$app-auth" --description="Standard Notes - Auth" --log="/var/log/$app/auth.log"
|
|
|
|
yunohost service add "$app-auth-worker" --description="Standard Notes - Auth - Worker" --log="/var/log/$app/auth-worker.log"
|
|
|
|
yunohost service add "$app-files" --description="Standard Notes - Files" --log="/var/log/$app/files.log"
|
|
|
|
yunohost service add "$app-syncing-server" --description="Standard Notes - Syncing Server" --log="/var/log/$app/syncing-server.log"
|
|
|
|
yunohost service add "$app-syncing-server-worker" --description="Standard Notes - Syncing Server - Worker" --log="/var/log/$app/syncing-server-worker.log"
|
|
|
|
yunohost service add "$app-workspace" --description="Standard Notes - Workspace" --log="/var/log/$app/workspace.log"
|
2021-07-06 01:37:20 +02:00
|
|
|
|
2020-01-18 10:28:47 +01:00
|
|
|
# Use logrotate to manage application logfile(s)
|
2022-08-04 17:28:39 +02:00
|
|
|
ynh_use_logrotate --logfile="/var/log/$app/api-gateway.log"
|
2021-07-04 21:45:43 +02:00
|
|
|
ynh_use_logrotate --logfile="/var/log/$app/auth.log"
|
|
|
|
ynh_use_logrotate --logfile="/var/log/$app/auth-worker.log"
|
2022-08-04 17:28:39 +02:00
|
|
|
ynh_use_logrotate --logfile="/var/log/$app/files.log"
|
|
|
|
ynh_use_logrotate --logfile="/var/log/$app/syncing-server.log"
|
|
|
|
ynh_use_logrotate --logfile="/var/log/$app/syncing-server-worker.log"
|
2022-10-25 18:42:07 +02:00
|
|
|
ynh_use_logrotate --logfile="/var/log/$app/workspace.log"
|
2020-01-18 10:28:47 +01:00
|
|
|
|
2024-01-15 22:17:38 +01:00
|
|
|
ynh_add_config --template="cron" --destination="/etc/cron.d/$app"
|
|
|
|
chmod 640 "/etc/cron.d/$app"
|
|
|
|
chown root: "/etc/cron.d/$app"
|
2020-01-18 10:28:47 +01:00
|
|
|
|
2024-01-15 22:17:38 +01:00
|
|
|
# Create a dedicated Fail2Ban config
|
|
|
|
# FIXME:
|
|
|
|
ynh_add_fail2ban_config --use_template
|
|
|
|
|
|
|
|
if [ "${PACKAGE_CHECK_EXEC:-0}" -eq 0 ]; then
|
|
|
|
ynh_add_swap --size="$swap_needed"
|
|
|
|
fi
|
2020-01-18 10:28:47 +01:00
|
|
|
|
2020-12-20 14:22:36 +01:00
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2024-01-15 22:17:38 +01:00
|
|
|
ynh_script_progression --message="Starting systemd services..." --weight=1
|
2020-12-20 14:22:36 +01:00
|
|
|
|
|
|
|
# Start a systemd service
|
2021-07-06 15:45:29 +02:00
|
|
|
ynh_systemd_action \
|
2024-01-15 22:17:38 +01:00
|
|
|
--service_name="$app-api-gateway" \
|
|
|
|
--action="start" \
|
|
|
|
--log_path="/var/log/$app/api-gateway.log" \
|
|
|
|
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
|
2021-07-06 15:45:29 +02:00
|
|
|
ynh_systemd_action \
|
2024-01-15 22:17:38 +01:00
|
|
|
--service_name="$app-auth" \
|
|
|
|
--action="start" \
|
|
|
|
--log_path="/var/log/$app/auth.log" \
|
|
|
|
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
|
2021-07-06 15:45:29 +02:00
|
|
|
ynh_systemd_action \
|
2024-01-15 22:17:38 +01:00
|
|
|
--service_name="$app-auth-worker" \
|
|
|
|
--action="start" \
|
|
|
|
--log_path="/var/log/$app/auth-worker.log" \
|
|
|
|
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
|
2021-07-06 15:45:29 +02:00
|
|
|
ynh_systemd_action \
|
2024-01-15 22:17:38 +01:00
|
|
|
--service_name="$app-files" \
|
|
|
|
--action="start" \
|
|
|
|
--log_path="/var/log/$app/files.log" \
|
|
|
|
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
|
2022-08-04 17:28:39 +02:00
|
|
|
ynh_systemd_action \
|
2024-01-15 22:17:38 +01:00
|
|
|
--service_name="$app-syncing-server" \
|
|
|
|
--action="start" \
|
|
|
|
--log_path="/var/log/$app/syncing-server.log" \
|
|
|
|
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
|
2022-08-04 17:28:39 +02:00
|
|
|
ynh_systemd_action \
|
2024-01-15 22:17:38 +01:00
|
|
|
--service_name="$app-syncing-server-worker" \
|
|
|
|
--action="start" \
|
|
|
|
--log_path="/var/log/$app/syncing-server-worker.log" \
|
|
|
|
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
|
2022-10-25 18:42:07 +02:00
|
|
|
ynh_systemd_action \
|
2024-01-15 22:17:38 +01:00
|
|
|
--service_name="$app-workspace" \
|
|
|
|
--action="start" \
|
|
|
|
--log_path="/var/log/$app/workspace.log" \
|
|
|
|
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
|
2020-01-18 10:28:47 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2022-08-31 02:25:01 +02:00
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|