2020-10-31 14:18:46 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_clean_setup () {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
# 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
|
2020-10-31 14:47:05 +01:00
|
|
|
path_url="/"
|
2020-10-31 14:18:46 +01:00
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Validating installation parameters..."
|
|
|
|
|
|
|
|
final_path=/var/www/$app
|
|
|
|
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
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Storing installation settings..."
|
|
|
|
|
|
|
|
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
|
|
|
ynh_app_setting_set --app=$app --key=path --value=$path_url
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
# FIND AND OPEN A PORT
|
|
|
|
#=================================================
|
2021-01-09 22:43:36 +01:00
|
|
|
ynh_script_progression --message="Finding an available port..."
|
2020-10-31 14:18:46 +01:00
|
|
|
|
|
|
|
# Find an available port
|
|
|
|
port=$(ynh_find_port --port=8095)
|
|
|
|
ynh_app_setting_set --app=$app --key=port --value=$port
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Installing dependencies..."
|
|
|
|
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
ynh_install_extra_app_dependencies --repo="deb https://artifacts.elastic.co/packages/oss-7.x/apt stable main" --package="$extra_pkg_dependencies" --key="https://artifacts.elastic.co/GPG-KEY-elasticsearch"
|
2020-12-26 00:22:51 +01:00
|
|
|
systemctl enable elasticsearch.service --quiet
|
2020-11-01 11:56:46 +01:00
|
|
|
systemctl start elasticsearch.service
|
2020-10-31 14:18:46 +01:00
|
|
|
ynh_install_nodejs --nodejs_version=$NODEJS_VERSION
|
|
|
|
ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
|
|
|
|
|
2021-04-09 23:48:21 +02:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring system user..."
|
|
|
|
|
|
|
|
# Create a system user
|
2022-01-07 04:00:37 +01:00
|
|
|
ynh_system_user_create --username=$app --home_dir=$final_path
|
2021-04-09 23:48:21 +02:00
|
|
|
|
2020-10-31 14:18:46 +01:00
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Setting up source files..."
|
|
|
|
|
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2021-04-10 19:17:43 +02:00
|
|
|
git clone $REPOSITORY $final_path --quiet
|
2020-10-31 14:33:19 +01:00
|
|
|
pushd "$final_path"
|
2020-10-31 20:28:37 +01:00
|
|
|
git checkout $COMMIT --quiet
|
2020-10-31 14:33:19 +01:00
|
|
|
popd
|
2020-10-31 14:18:46 +01:00
|
|
|
|
2021-04-17 18:31:51 +02:00
|
|
|
chmod 750 "$final_path"
|
2021-04-09 23:48:21 +02:00
|
|
|
chmod -R o-rwx "$final_path"
|
2021-04-11 20:47:47 +02:00
|
|
|
chown -R $app:$app "$final_path"
|
2021-04-09 23:48:21 +02:00
|
|
|
|
2020-10-31 14:18:46 +01:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2021-04-09 23:48:21 +02:00
|
|
|
ynh_script_progression --message="Configuring NGINX web server..."
|
2020-10-31 14:18:46 +01:00
|
|
|
|
2021-04-09 23:48:21 +02:00
|
|
|
# Create a dedicated NGINX config
|
2021-11-30 14:23:14 +01:00
|
|
|
ynh_add_nginx_config
|
2020-10-31 14:18:46 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
|
|
|
# BUILDING
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Building..."
|
|
|
|
|
|
|
|
pushd "$final_path"
|
|
|
|
git submodule update --init --recursive
|
|
|
|
ynh_use_nodejs
|
|
|
|
yarn install --pure-lockfile
|
|
|
|
mkdir "$final_path/dist"
|
|
|
|
$ynh_npm run build
|
|
|
|
popd
|
|
|
|
|
|
|
|
#=================================================
|
2021-04-09 23:48:21 +02:00
|
|
|
# ADD A CONFIGURATION
|
2020-10-31 14:18:46 +01:00
|
|
|
#=================================================
|
2021-04-09 23:48:21 +02:00
|
|
|
ynh_script_progression --message="Adding a config file..."
|
2020-10-31 14:18:46 +01:00
|
|
|
|
2021-02-26 21:40:29 +01:00
|
|
|
ynh_add_config --template="../conf/default.yaml" --destination="$final_path/config/production.yaml"
|
2020-10-31 14:18:46 +01:00
|
|
|
|
2021-04-10 01:57:06 +02:00
|
|
|
chmod 400 "$final_path/config/production.yaml"
|
|
|
|
chown $app:$app "$final_path/config/production.yaml"
|
2021-04-09 23:48:21 +02:00
|
|
|
|
2021-04-11 20:47:47 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring a systemd service..."
|
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
2021-05-13 22:38:50 +02:00
|
|
|
ynh_add_systemd_config
|
2021-04-11 20:47:47 +02:00
|
|
|
|
2020-10-31 14:18:46 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring log rotation..."
|
|
|
|
|
|
|
|
# Use logrotate to manage application logfile(s)
|
|
|
|
ynh_use_logrotate
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
|
|
|
|
2021-02-17 20:38:04 +01:00
|
|
|
yunohost service add $app --description="$app search index daemon"
|
2020-10-31 14:18:46 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Starting a systemd service..."
|
|
|
|
|
|
|
|
# Start a systemd service
|
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Server listening on port"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2021-02-17 20:38:04 +01:00
|
|
|
ynh_script_progression --message="Configuring permissions..."
|
2020-10-31 14:18:46 +01:00
|
|
|
|
|
|
|
# Make app public if necessary
|
|
|
|
if [ $is_public -eq 1 ]
|
|
|
|
then
|
2021-02-17 20:38:04 +01:00
|
|
|
# Everyone can access the app.
|
|
|
|
# The "main" permission is automatically created before the install script.
|
|
|
|
ynh_permission_update --permission="main" --add="visitors"
|
2020-10-31 14:18:46 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2021-04-09 23:48:21 +02:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
2020-10-31 14:18:46 +01:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Installation of $app completed"
|