2014-08-26 00:49:46 +02:00
|
|
|
#!/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
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# 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
|
2014-08-26 00:49:46 +02:00
|
|
|
|
2017-06-27 13:34:52 +02:00
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
#=================================================
|
2020-11-03 14:16:38 +01:00
|
|
|
ynh_script_progression --message="Validating installation parameters..." --time --weight=1
|
2014-08-26 00:49:46 +02:00
|
|
|
|
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=is_public --value=$is_public
|
|
|
|
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
|
|
|
|
#=================================================
|
2020-11-03 14:16:38 +01:00
|
|
|
ynh_script_progression --message="Configuring firewall..." --time --weight=1
|
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
|
|
|
|
|
2017-06-27 13:34:52 +02:00
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2020-11-03 14:16:38 +01:00
|
|
|
ynh_script_progression --message="Setting up source files..." --weight=2
|
2019-08-07 15:13:10 +02:00
|
|
|
|
2020-11-03 14:16:38 +01: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
|
|
|
|
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
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
2020-11-03 14:16:38 +01:00
|
|
|
ynh_script_progression --message="Configuring system user..." --weight=3
|
2014-12-07 23:11:39 +01:00
|
|
|
|
2020-11-03 14:16:38 +01:00
|
|
|
# Create a system user
|
|
|
|
ynh_system_user_create --username=$app --home_dir=$final_path
|
2014-12-07 23:11:39 +01:00
|
|
|
|
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:32:32 +01:00
|
|
|
ynh_script_progression --message="Building EtherCalc... (this will take some time and resources!)" --weight=240
|
2017-06-27 13:44:49 +02:00
|
|
|
|
2020-11-03 14:16:38 +01:00
|
|
|
pushd "$final_path" || ynh_die
|
|
|
|
ynh_use_nodejs
|
|
|
|
ynh_exec_warn_less npm install -g ethercalc
|
|
|
|
popd || ynh_die
|
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
|
|
|
|
2020-11-03 14:32:32 +01:00
|
|
|
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
|
|
|
|
#ynh_replace_string --match_string="__NODE_VERSION__" --replace_string=$node_version --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:41:42 +01:00
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
chown -R $app: $final_path
|
|
|
|
|
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:32:32 +01:00
|
|
|
sudo yunohost service add $app --log "/var/log/ethercalc.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
|
|
|
|
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
|
|
|
|
#=================================================
|
2020-11-03 14:16:38 +01:00
|
|
|
ynh_script_progression --message="Configuring SSOwat..." --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 ]
|
2014-08-26 00:49:46 +02:00
|
|
|
then
|
2020-11-03 14:16:38 +01:00
|
|
|
# Everyone can access the app.
|
|
|
|
# The "main" permission is automatically created before the install script.
|
2020-11-03 14:32:32 +01:00
|
|
|
ynh_permission_update --permission "main" --add "visitors"
|
2014-08-26 00:49:46 +02:00
|
|
|
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
|