1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/hedgedoc_ynh.git synced 2024-09-03 19:25:52 +02:00
hedgedoc_ynh/scripts/install
2024-05-28 23:50:55 +02:00

112 lines
4 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
allow_anonymous=false
allow_anonymous_edits=false
allow_email_registration=false
allow_free_url=false
require_free_url_authentication=false
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..." --weight=20
# Install Nodejs
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
ynh_use_nodejs
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=1
# Download, check integrity, uncompress and patch the source from manifest.toml
ynh_setup_source --dest_dir="$install_dir"
chown -R "$app:www-data" "$install_dir"
#=================================================
# SYSTEM CONFIGURATION
#=================================================
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
ynh_add_nginx_config
ynh_add_systemd_config --service="${app}_backend" --template="../conf/backend.service"
ynh_add_systemd_config --service="${app}_frontend" --template="../conf/frontend.service"
yunohost service add "${app}_backend" --description="Collaborative Markdown editor's backend" --log="/var/log/$app/$app.log"
yunohost service add "${app}_frontend" --description="Collaborative Markdown editor's frontend" --log="/var/log/$app/$app.log"
#=================================================
# SPECIFIC SETUP
#==============================================
# INSTALL HEDGEDOC
#==============================================
ynh_script_progression --message="Building $app... (this will take some time and resources!)" --weight=20
pushd "$install_dir/backend"
ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH yarn install
popd
pushd "$install_dir/frontend"
ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH yarn install
# TODO: Fails out of memory in my tests
# Production build
# Not sure if PORT is necessary here
# PORT=$port_frontend REACT_APP_BACKEND_BASE_URL=http://localhost:$port_backend/ yarn build:production
popd
#=================================================
# MODIFY A CONFIG FILE
#=================================================
ynh_script_progression --message="Modifying a config file..." --weight=1
#path=${path_url:1}
ynh_add_config --template="env_backend" --destination="$install_dir/backend/.env"
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
ynh_script_progression --message="Securing files and directories..." --weight=1
# Set permissions to app files
chown -R $app:$app $install_dir
chmod o-rwx $install_dir
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=2
# Start a systemd service
ynh_systemd_action --service_name="${app}_backend" --action=start --log_path=systemd
ynh_systemd_action --service_name="${app}_frontend" --action=start --log_path=systemd
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last