2017-02-02 19:21:27 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-02-20 17:33:19 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2017-04-21 12:54:39 +02:00
|
|
|
|
2018-02-20 17:33:19 +01:00
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
2017-02-02 19:21:27 +01:00
|
|
|
|
2018-02-20 17:33:19 +01:00
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
2023-05-31 20:58:29 +02:00
|
|
|
#REMOVEME? ynh_clean_setup () {
|
2019-02-18 11:47:25 +01:00
|
|
|
ynh_clean_check_starting
|
2018-11-03 21:46:35 +01:00
|
|
|
}
|
2018-02-20 17:33:19 +01:00
|
|
|
# Exit if an error occurs during the execution of the script
|
2023-05-31 20:58:29 +02:00
|
|
|
#REMOVEME? ynh_abort_if_errors
|
2017-02-02 19:21:27 +01:00
|
|
|
|
2018-11-03 21:46:35 +01:00
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
2023-05-31 20:58:29 +02:00
|
|
|
#REMOVEME? domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
#REMOVEME? path=$YNH_APP_ARG_PATH
|
|
|
|
#REMOVEME? is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
|
|
#REMOVEME? theme=$YNH_APP_ARG_THEME
|
|
|
|
#REMOVEME? password=$YNH_APP_ARG_PASSWORD
|
2017-02-02 19:21:27 +01:00
|
|
|
|
2023-05-31 20:58:29 +02:00
|
|
|
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
|
2017-02-02 19:21:27 +01:00
|
|
|
|
2022-06-16 01:28:41 +02:00
|
|
|
secret=$(ynh_string_random --length=24)
|
|
|
|
hashed_password=$(echo -n $password | sha256sum | cut -d' ' -f1)
|
|
|
|
|
2018-11-03 21:46:35 +01:00
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
#=================================================
|
2023-05-31 20:58:29 +02:00
|
|
|
#REMOVEME? ynh_script_progression --message="Validating installation parameters..."
|
2017-02-02 19:21:27 +01:00
|
|
|
|
2023-05-31 20:58:29 +02:00
|
|
|
#REMOVEME? install_dir=/var/www/$app
|
|
|
|
#REMOVEME? test ! -e "$install_dir" || ynh_die --message="This path already contains a folder"
|
2017-02-02 19:21:27 +01:00
|
|
|
|
2018-11-03 21:46:35 +01:00
|
|
|
# Register (book) web path
|
2023-05-31 20:58:29 +02:00
|
|
|
#REMOVEME? ynh_webpath_register --app=$app --domain=$domain --path=$path
|
2017-02-02 19:21:27 +01:00
|
|
|
|
2018-11-03 21:46:35 +01:00
|
|
|
#=================================================
|
2020-04-19 05:16:46 +02:00
|
|
|
# STORE SETTINGS FROM MANIFEST
|
2018-11-03 21:46:35 +01:00
|
|
|
#=================================================
|
2023-05-31 20:58:29 +02:00
|
|
|
#REMOVEME? ynh_script_progression --message="Storing installation settings..."
|
2018-11-03 21:46:35 +01:00
|
|
|
|
2023-05-31 20:58:29 +02:00
|
|
|
#REMOVEME? ynh_app_setting_set --app=$app --key=domain --value=$domain
|
|
|
|
#REMOVEME? ynh_app_setting_set --app=$app --key=path --value=$path
|
2020-04-20 17:51:05 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=is_public --value=$is_public
|
2020-04-19 05:16:46 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=theme --value=$theme
|
|
|
|
ynh_app_setting_set --app=$app --key=secret --value=$secret
|
2023-05-31 20:58:29 +02:00
|
|
|
#REMOVEME? ynh_app_setting_set --app=$app --key=hashed_password --value=$hashed_password
|
2018-11-03 21:46:35 +01:00
|
|
|
|
|
|
|
#=================================================
|
2020-04-19 05:16:46 +02:00
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
# FIND AND OPEN A PORT
|
2018-11-03 21:46:35 +01:00
|
|
|
#=================================================
|
2023-05-31 20:58:29 +02:00
|
|
|
#REMOVEME? ynh_script_progression --message="Finding an available port..."
|
2017-02-02 19:21:27 +01:00
|
|
|
|
2020-04-19 05:16:46 +02:00
|
|
|
# Find an available port
|
2023-05-31 20:58:29 +02:00
|
|
|
#REMOVEME? port=$(ynh_find_port --port=8095)
|
|
|
|
#REMOVEME? ynh_app_setting_set --app=$app --key=port --value=$port
|
2020-04-21 01:30:07 +02:00
|
|
|
|
2018-11-03 21:46:35 +01:00
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
2023-05-31 20:58:29 +02:00
|
|
|
#REMOVEME? ynh_script_progression --message="Installing dependencies..."
|
2020-05-28 21:36:47 +02:00
|
|
|
|
2023-05-31 20:58:29 +02:00
|
|
|
#REMOVEME? ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
|
2018-11-03 21:46:35 +01:00
|
|
|
|
2022-06-16 01:28:41 +02:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
2023-05-31 20:58:29 +02:00
|
|
|
#REMOVEME? ynh_script_progression --message="Configuring system user..."
|
2022-06-16 01:28:41 +02:00
|
|
|
|
|
|
|
# Create a system user
|
2023-05-31 20:58:29 +02:00
|
|
|
#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir"
|
2022-06-16 01:28:41 +02:00
|
|
|
|
2018-11-04 11:00:03 +01:00
|
|
|
#=================================================
|
|
|
|
# CREATE A POSTGRESQL DATABASE
|
|
|
|
#=================================================
|
2023-05-31 20:58:29 +02:00
|
|
|
#REMOVEME? ynh_script_progression --message="Creating a PostgreSQL database..."
|
2018-11-04 11:00:03 +01:00
|
|
|
|
|
|
|
# Create postgresql database
|
2023-05-31 20:58:29 +02:00
|
|
|
#REMOVEME? ynh_psql_test_if_first_run
|
|
|
|
#REMOVEME? db_name=$(ynh_sanitize_dbid --db_name=$app)
|
|
|
|
#REMOVEME? db_user=$db_name
|
|
|
|
#REMOVEME? ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
|
|
|
#REMOVEME? ynh_psql_setup_db --db_user=$db_user --db_name=$db_name
|
2018-11-04 11:00:03 +01:00
|
|
|
|
2018-11-03 21:46:35 +01:00
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2020-05-30 15:28:48 +02:00
|
|
|
ynh_script_progression --message="Setting up source files..."
|
2017-02-02 19:21:27 +01:00
|
|
|
|
2023-05-31 20:58:29 +02:00
|
|
|
#REMOVEME? ynh_app_setting_set --app=$app --key=install_dir --value=$install_dir
|
2018-11-03 21:46:35 +01:00
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2023-05-31 20:58:29 +02:00
|
|
|
ynh_setup_source --dest_dir="$install_dir"
|
2018-11-03 21:46:35 +01:00
|
|
|
|
2023-05-31 20:58:29 +02:00
|
|
|
chmod 750 "$install_dir"
|
|
|
|
chmod -R o-rwx "$install_dir"
|
|
|
|
chown -R $app:www-data "$install_dir"
|
2021-06-20 23:23:08 +02:00
|
|
|
|
2018-11-03 21:46:35 +01:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2020-11-16 16:41:23 +01:00
|
|
|
ynh_script_progression --message="Configuring NGINX web server..."
|
2017-02-02 19:21:27 +01:00
|
|
|
|
2018-11-03 21:46:35 +01:00
|
|
|
# Create a dedicated nginx config
|
|
|
|
ynh_add_nginx_config
|
2017-02-02 19:21:27 +01:00
|
|
|
|
2020-05-30 16:42:42 +02:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
2018-11-03 21:46:35 +01:00
|
|
|
#=================================================
|
2022-06-16 01:28:41 +02:00
|
|
|
# ADD A CONFIGURATION
|
2018-11-03 21:46:35 +01:00
|
|
|
#=================================================
|
2022-06-16 01:28:41 +02:00
|
|
|
ynh_script_progression --message="Adding a configuration file..."
|
2020-04-19 05:16:46 +02:00
|
|
|
|
2023-05-31 20:58:29 +02:00
|
|
|
#REMOVEME? if [ $is_public -eq 0 ];
|
2019-02-16 00:11:00 +01:00
|
|
|
then
|
2023-05-31 20:58:29 +02:00
|
|
|
ynh_add_config --template="../conf/lstu.conf.ldap" --destination="$install_dir/lstu.conf"
|
2019-02-16 00:11:00 +01:00
|
|
|
else
|
2023-05-31 20:58:29 +02:00
|
|
|
ynh_add_config --template="../conf/lstu.conf.template" --destination="$install_dir/lstu.conf"
|
2019-02-16 00:11:00 +01:00
|
|
|
fi
|
2020-05-28 21:36:47 +02:00
|
|
|
|
2018-11-03 21:46:35 +01:00
|
|
|
#=================================================
|
2020-05-28 21:36:47 +02:00
|
|
|
# INSTALL LSTU
|
2018-11-03 21:46:35 +01:00
|
|
|
#=================================================
|
2020-12-08 17:31:59 +01:00
|
|
|
ynh_script_progression --message="Installing Lstu..."
|
2018-11-03 21:46:35 +01:00
|
|
|
|
2023-05-31 20:58:29 +02:00
|
|
|
pushd $install_dir
|
2020-04-19 05:16:46 +02:00
|
|
|
carton install --deployment --without=sqlite --without=mysql
|
2019-02-03 00:19:57 +01:00
|
|
|
popd
|
2018-11-03 21:46:35 +01:00
|
|
|
|
2020-05-30 16:42:42 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring a systemd service..."
|
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_config
|
|
|
|
|
2018-11-03 21:46:35 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
2020-05-30 15:28:48 +02:00
|
|
|
ynh_script_progression --message="Configuring log rotation..."
|
2018-11-03 21:46:35 +01:00
|
|
|
|
|
|
|
# Use logrotate to manage application logfile(s)
|
|
|
|
ynh_use_logrotate
|
|
|
|
|
|
|
|
#=================================================
|
2020-04-19 05:16:46 +02:00
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
2018-11-03 21:46:35 +01:00
|
|
|
#=================================================
|
2020-05-30 15:28:48 +02:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
2018-11-03 21:46:35 +01:00
|
|
|
|
2020-12-08 17:24:16 +01:00
|
|
|
yunohost service add $app --log="/var/log/$app.log" --log="/var/www/$app/log/production.log"
|
2017-02-02 19:21:27 +01:00
|
|
|
|
2020-04-19 05:16:46 +02:00
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2020-05-30 15:28:48 +02:00
|
|
|
ynh_script_progression --message="Starting a systemd service..."
|
2020-04-19 05:16:46 +02:00
|
|
|
|
|
|
|
# Start a systemd service
|
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Server available at"
|
|
|
|
|
2018-11-03 21:46:35 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2023-05-31 20:58:29 +02:00
|
|
|
#REMOVEME? ynh_script_progression --message="Configuring permissions..."
|
2021-04-22 23:52:56 +02:00
|
|
|
|
2022-06-16 01:28:41 +02:00
|
|
|
# Everyone can access the app.
|
|
|
|
# The "main" permission is automatically created before the install script.
|
2023-05-31 20:58:29 +02:00
|
|
|
#REMOVEME? ynh_permission_update --permission="main" --add="visitors"
|
2017-02-02 19:21:27 +01:00
|
|
|
|
2023-05-31 20:58:29 +02:00
|
|
|
#REMOVEME? if [ $is_public -eq 0 ]
|
2019-03-08 21:50:41 +01:00
|
|
|
then
|
|
|
|
# If the app is private, only the shortened URLs are publics.
|
2023-05-31 20:58:29 +02:00
|
|
|
if [ "$path" == "/" ]; then
|
2022-06-16 01:28:41 +02:00
|
|
|
# If the path is /, clear it to prevent any error with the regex.
|
2023-05-31 20:58:29 +02:00
|
|
|
path=""
|
2019-03-08 21:50:41 +01:00
|
|
|
fi
|
|
|
|
# Modify the domain to be used in a regex
|
|
|
|
domain_regex=$(echo "$domain" | sed 's@-@.@g')
|
2023-05-31 20:58:29 +02:00
|
|
|
#REMOVEME? ynh_app_setting_set --app=$app --key=protected_regex --value="$domain_regex$path/login$","$domain_regex$path/logout$","$domain_regex$path/api$","$domain_regex$path/extensions$","$domain_regex$path/stats$","$domain_regex$path/d/.*$","$domain_regex$path/a$","$domain_regex$path/$"
|
2017-02-02 19:21:27 +01:00
|
|
|
fi
|
|
|
|
|
2018-11-03 21:46:35 +01:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2023-05-31 20:58:29 +02:00
|
|
|
#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..."
|
2017-02-02 19:21:27 +01:00
|
|
|
|
2023-05-31 20:58:29 +02:00
|
|
|
#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload
|
2019-02-21 12:35:13 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2020-05-30 15:30:23 +02:00
|
|
|
ynh_script_progression --message="Installation of $app completed"
|