1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/ethercalc_ynh.git synced 2024-09-03 18:26:36 +02:00
ethercalc_ynh/scripts/install

162 lines
5.6 KiB
Text
Raw Normal View History

#!/bin/bash
2017-06-27 13:34:52 +02:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
2020-11-03 14:55:47 +01:00
ynh_clean_setup () {
ynh_clean_check_starting
}
2017-06-27 13:34:52 +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
2017-06-27 14:20:52 +02:00
is_public=$YNH_APP_ARG_IS_PUBLIC
2019-07-21 17:48:18 +02:00
path_url="/"
2019-08-07 14:28:32 +02:00
expire=$YNH_APP_ARG_EXPIRE
2020-11-03 14:32:32 +01:00
2017-06-27 13:34:52 +02:00
app=$YNH_APP_INSTANCE_NAME
2017-06-27 13:34:52 +02:00
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
2020-11-03 16:07:39 +01:00
ynh_script_progression --message="Validating installation parameters..." --weight=1
2014-12-07 23:24:59 +01:00
final_path=/var/www/$app
2020-11-03 14:16:38 +01:00
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
2017-06-27 13:34:52 +02:00
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2020-11-03 14:16:38 +01: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=expire --value=$expire
2017-06-27 13:34:52 +02:00
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
2021-04-20 21:43:18 +02:00
ynh_script_progression --message="Finding an available port..." --weight=3
2017-06-27 13:34:52 +02:00
2020-11-03 14:16:38 +01:00
port=$(ynh_find_port --port=8095)
ynh_app_setting_set --app=$app --key=port --value=$port
2017-06-27 13:34:52 +02:00
#=================================================
# INSTALL DEPENDENCIES
#=================================================
2020-11-03 14:16:38 +01:00
ynh_script_progression --message="Installing dependencies..." --weight=20
2019-08-07 15:13:10 +02:00
ynh_install_app_dependencies $pkg_dependencies
2017-06-27 13:34:52 +02:00
2020-11-03 14:16:38 +01:00
# Install Nodejs
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
2021-06-01 11:59:24 +02:00
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..." --weight=3
# Create a system user
ynh_system_user_create --username=$app --home_dir=$final_path
2017-06-27 13:34:52 +02:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2021-04-20 22:34:59 +02:00
ynh_script_progression --message="Setting up source files..." --weight=2
2019-08-07 15:13:10 +02:00
2021-04-20 22:34:59 +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
ynh_setup_source --dest_dir=$final_path
2019-08-07 15:13:10 +02:00
2021-06-01 11:59:24 +02:00
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
chmod +x $final_path/bin/runSafe.sh
2017-06-27 13:34:52 +02:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2020-11-03 14:16:38 +01:00
ynh_script_progression --message="Configuring NGINX web server..." --weight=2
2017-06-27 13:34:52 +02:00
2020-11-03 14:16:38 +01:00
# Create a dedicated NGINX config
2017-09-08 20:48:32 +02:00
ynh_add_nginx_config
2017-06-27 13:34:52 +02:00
#=================================================
2019-08-07 15:13:10 +02:00
# INSTALL ETHERCALC
2017-06-27 13:34:52 +02:00
#=================================================
2020-11-03 14:55:47 +01:00
ynh_script_progression --message="Building EtherCalc... (this will take some time and resources!)" --weight=24
2017-06-27 13:44:49 +02:00
2021-04-20 21:43:18 +02:00
pushd "$final_path"
2020-11-03 14:16:38 +01:00
ynh_use_nodejs
2021-04-20 21:43:18 +02:00
ynh_exec_warn_less npm i -g ethercalc
popd
2017-06-27 13:34:52 +02:00
#=================================================
2019-08-07 15:13:10 +02:00
# SETUP SYSTEMD BASED SERVICES
2017-06-27 13:34:52 +02:00
#=================================================
2020-11-03 14:16:38 +01:00
ynh_script_progression --message="Configuring a systemd service..." --weight=1
2017-06-27 13:34:52 +02:00
2021-04-20 22:14:55 +02:00
ynh_replace_string --match_string="__ENV_PATH__" --replace_string="$PATH" --target_file="../conf/systemd.service"
ynh_replace_string --match_string="__YNH_NPM__" --replace_string="$ynh_npm" --target_file="../conf/systemd.service"
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/systemd.service"
ynh_replace_string --match_string="__EXPIRE__" --replace_string="$expire" --target_file="../conf/systemd.service"
2019-08-07 15:13:10 +02:00
2020-11-03 14:32:32 +01:00
ynh_add_systemd_config
2017-06-27 13:34:52 +02:00
#=================================================
2020-11-03 14:32:32 +01:00
# ADVERTISE SERVICE IN ADMIN PANEL
2017-06-27 13:34:52 +02:00
#=================================================
2020-11-03 14:55:47 +01:00
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
2017-06-27 13:34:52 +02:00
2021-04-20 21:43:18 +02:00
yunohost service add $app --description "Collaborative spreadsheet editor" --log="/var/log/$app/$app.log"
2017-06-27 13:34:52 +02:00
#=================================================
2020-11-03 14:32:32 +01:00
# START SYSTEMD SERVICE
2017-06-27 13:34:52 +02:00
#=================================================
2020-11-03 14:32:32 +01:00
ynh_script_progression --message="Starting a systemd service..." --weight=2
2017-06-27 13:34:52 +02:00
2020-11-03 14:32:32 +01:00
# Start a systemd service
2021-04-20 21:43:18 +02:00
ynh_systemd_action --service_name=$app --action=start --log_path="systemd" #--line_match="HTTP Server listening"
2017-06-27 13:34:52 +02:00
#=================================================
# SETUP SSOWAT
#=================================================
2021-04-20 21:43:18 +02:00
ynh_script_progression --message="Configuring permissions..." --weight=1
2017-06-27 13:34:52 +02:00
2020-11-03 14:16:38 +01:00
# Make app public if necessary or protect it
2017-06-27 13:34:52 +02:00
if [ $is_public -eq 1 ]
then
2021-04-20 21:31:56 +02:00
ynh_permission_update --permission="main" --add="visitors"
fi
2017-06-27 13:34:52 +02:00
#=================================================
# RELOAD NGINX
#=================================================
2020-11-03 14:16:38 +01:00
ynh_script_progression --message="Reloading NGINX web server..." --weight=2
2017-06-27 13:34:52 +02:00
2019-08-07 15:13:10 +02:00
ynh_systemd_action --service_name=nginx --action=reload
2020-11-03 14:16:38 +01:00
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of EtherCalc completed" --last