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

206 lines
7.1 KiB
Text
Raw Normal View History

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
#=================================================
2018-11-03 21:46:35 +01:00
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
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
#=================================================
2017-02-02 19:21:27 +01:00
domain=$YNH_APP_ARG_DOMAIN
2018-11-03 21:48:16 +01:00
path_url=$YNH_APP_ARG_PATH
2017-02-02 19:21:27 +01:00
is_public=$YNH_APP_ARG_IS_PUBLIC
2019-02-14 23:39:36 +01:00
theme=$YNH_APP_ARG_THEME
2019-02-14 23:41:28 +01:00
password=$YNH_APP_ARG_PASSWORD
2017-02-02 19:21:27 +01:00
app=$YNH_APP_INSTANCE_NAME
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
#=================================================
2020-05-30 15:28:48 +02:00
ynh_script_progression --message="Validating installation parameters..."
2017-02-02 19:21:27 +01:00
2018-11-03 21:46:35 +01:00
final_path=/var/www/$app
2020-04-19 05:16:46 +02:00
test ! -e "$final_path" || 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
2020-04-19 05:16:46 +02:00
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
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
#=================================================
2020-05-30 15:28:48 +02:00
ynh_script_progression --message="Storing installation settings..."
2018-11-03 21:46:35 +01:00
2020-04-19 05:16:46 +02: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
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
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
#=================================================
2020-11-06 18:48:01 +01:00
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
port=$(ynh_find_port --port=8095)
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
#=================================================
2020-05-30 15:28:48 +02:00
ynh_script_progression --message="Installing dependencies..."
2020-05-28 21:36:47 +02:00
2022-05-21 00:02:24 +02:00
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
#=================================================
ynh_script_progression --message="Configuring system user..."
# Create a system user
ynh_system_user_create --username=$app --home_dir="$final_path"
2018-11-04 11:00:03 +01:00
#=================================================
# CREATE A POSTGRESQL DATABASE
#=================================================
2020-05-30 15:28:48 +02:00
ynh_script_progression --message="Creating a PostgreSQL database..."
2018-11-04 11:00:03 +01:00
# Create postgresql database
ynh_psql_test_if_first_run
2020-04-19 05:16:46 +02:00
db_name=$(ynh_sanitize_dbid --db_name=$app)
2018-11-04 11:00:03 +01:00
db_user=$db_name
2020-04-19 05:16:46 +02:00
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
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
2020-04-19 05:16:46 +02:00
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
2018-11-03 21:46:35 +01:00
# Download, check integrity, uncompress and patch the source from app.src
2020-04-19 05:16:46 +02:00
ynh_setup_source --dest_dir="$final_path"
2018-11-03 21:46:35 +01:00
2021-06-20 23:23:08 +02:00
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
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
2019-02-16 00:11:00 +01:00
if [ $is_public -eq 0 ];
then
2021-06-21 15:56:40 +02:00
ynh_add_config --template="../conf/lstu.conf.ldap" --destination="$final_path/lstu.conf"
2019-02-16 00:11:00 +01:00
else
2021-06-21 15:56:40 +02:00
ynh_add_config --template="../conf/lstu.conf.template" --destination="$final_path/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
2019-02-03 00:19:57 +01:00
pushd $final_path
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
#=================================================
2021-04-22 23:52:56 +02:00
ynh_script_progression --message="Configuring permissions..."
2022-06-16 01:28:41 +02:00
# Everyone can access the app.
# The "main" permission is automatically created before the install script.
2021-04-22 23:52:56 +02:00
ynh_permission_update --permission="main" --add="visitors"
2017-02-02 19:21:27 +01:00
2019-03-08 21:50:41 +01:00
if [ $is_public -eq 0 ]
then
# If the app is private, only the shortened URLs are publics.
if [ "$path_url" == "/" ]; then
2022-06-16 01:28:41 +02:00
# If the path is /, clear it to prevent any error with the regex.
path_url=""
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')
2020-04-19 05:16:46 +02:00
ynh_app_setting_set --app=$app --key=protected_regex --value="$domain_regex$path_url/login$","$domain_regex$path_url/logout$","$domain_regex$path_url/api$","$domain_regex$path_url/extensions$","$domain_regex$path_url/stats$","$domain_regex$path_url/d/.*$","$domain_regex$path_url/a$","$domain_regex$path_url/$"
2017-02-02 19:21:27 +01:00
fi
2018-11-03 21:46:35 +01:00
#=================================================
# RELOAD NGINX
#=================================================
2020-11-16 16:41:23 +01:00
ynh_script_progression --message="Reloading NGINX web server..."
2017-02-02 19:21:27 +01:00
2020-04-19 05:16:46 +02:00
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"