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

232 lines
7.6 KiB
Text
Raw Normal View History

2017-02-07 22:51:47 +01:00
#!/bin/bash
2018-09-02 11:08:06 +02:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
2019-03-03 18:04:55 +01:00
ynh_clean_check_starting
2017-02-07 22:51:47 +01:00
}
2018-09-02 11:08:06 +02:00
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
2017-02-07 22:51:47 +01:00
domain=$YNH_APP_ARG_DOMAIN
2018-09-04 10:19:30 +02:00
path_url=$YNH_APP_ARG_PATH
is_public=$YNH_APP_ARG_IS_PUBLIC
2022-01-27 02:40:24 +01:00
max_file_size=$YNH_APP_ARG_MAX_FILE_SIZE
use_ldap=$YNH_APP_ARG_USE_LDAP
2020-05-30 16:34:01 +02:00
secret=$(ynh_string_random --length=24)
2017-02-07 22:51:47 +01:00
app=$YNH_APP_INSTANCE_NAME
2018-09-02 11:08:06 +02:00
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
2020-05-30 16:34:01 +02:00
ynh_script_progression --message="Validating installation parameters..."
2017-02-07 22:51:47 +01:00
2018-09-02 11:08:06 +02:00
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
2017-02-07 22:51:47 +01:00
2019-03-03 18:52:39 +01:00
# Check if max_file_size is a number
if ! [[ $max_file_size =~ "^[\-0-9]+$" ]] && [ $max_file_size -lt 0 ]; then
ynh_die --message="Max file must be a number positive or zero"
2019-03-03 18:52:39 +01:00
fi
2018-09-02 11:08:06 +02:00
# Register (book) web path
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
2017-02-07 22:51:47 +01:00
2019-03-03 18:04:55 +01:00
#=================================================
# STORE SETTINGS FROM MANIFEST
2019-03-03 18:04:55 +01:00
#=================================================
2020-05-30 16:34:01 +02:00
ynh_script_progression --message="Storing installation settings..."
2019-03-03 18:04:55 +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=use_ldap --value=$use_ldap
ynh_app_setting_set --app=$app --key=max_file_size --value=$max_file_size
ynh_app_setting_set --app=$app --key=secret --value=$secret
2019-03-03 18:04:55 +01:00
2018-09-02 11:08:06 +02:00
#=================================================
# STANDARD MODIFICATIONS
2018-09-02 11:08:06 +02:00
#=================================================
# FIND AND OPEN A PORT
#=================================================
2021-01-09 22:26:24 +01:00
ynh_script_progression --message="Finding an available port..."
2017-02-07 22:51:47 +01:00
# Find an available port
port=$(ynh_find_port --port=8095)
ynh_app_setting_set --app=$app --key=port --value=$port
2020-05-26 01:58:07 +02:00
2018-09-02 11:08:06 +02:00
#=================================================
2019-03-03 18:04:55 +01:00
# INSTALL DEPENDENCIES
2018-09-02 11:08:06 +02:00
#=================================================
2020-05-30 16:34:01 +02:00
ynh_script_progression --message="Installing dependencies..."
2018-09-02 11:08:06 +02:00
2021-01-23 17:06:02 +01:00
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
2020-05-26 01:58:07 +02:00
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..."
# Create a system user
2021-06-06 19:02:01 +02:00
ynh_system_user_create --username=$app --home_dir="$final_path"
2018-09-02 11:08:06 +02:00
#=================================================
2019-03-03 18:04:55 +01:00
# CREATE A POSTGRESQL DATABASE
2018-09-02 11:08:06 +02:00
#=================================================
2020-05-30 16:34:01 +02:00
ynh_script_progression --message="Creating a PostgreSQL database..."
2017-02-07 22:51:47 +01:00
2019-03-03 18:04:55 +01:00
# Create postgresql database
ynh_psql_test_if_first_run
db_name=$(ynh_sanitize_dbid --db_name=$app)
2019-03-03 18:04:55 +01:00
db_user=$db_name
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) # Password created in ynh_psql_setup_db function
2017-02-07 22:51:47 +01:00
2018-09-02 11:08:06 +02:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2020-05-30 16:34:01 +02:00
ynh_script_progression --message="Setting up source files..."
2018-09-02 11:08:06 +02:00
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
2018-09-02 11:08:06 +02:00
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
2017-02-07 22:51:47 +01:00
2021-06-06 19:02:01 +02:00
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
2018-09-02 11:08:06 +02:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2020-11-01 18:24:02 +01:00
ynh_script_progression --message="Configuring NGINX web server..."
2017-02-07 22:51:47 +01:00
2020-11-01 18:24:02 +01:00
# Create a dedicated NGINX config
2022-01-27 02:40:24 +01:00
ynh_add_nginx_config
2017-02-07 22:51:47 +01:00
2018-09-02 11:08:06 +02:00
#=================================================
# SPECIFIC SETUP
#=================================================
2022-06-16 21:07:01 +02:00
# CREATE DATA DIRECTORY
#=================================================
ynh_script_progression --message="Creating a data directory..."
datadir=/home/yunohost.app/$app
ynh_app_setting_set --app=$app --key=datadir --value=$datadir
mkdir -p $datadir/upload
chmod 750 "$datadir"
chmod -R o-rwx "$datadir"
chown -R $app:www-data "$datadir"
#=================================================
# CONFIGURE LUFI
2018-09-02 11:08:06 +02:00
#=================================================
2020-11-14 08:31:09 +01:00
ynh_script_progression --message="Configuring $app..."
2017-02-07 22:51:47 +01:00
ldap="#"
if [ $use_ldap -eq 1 ];
2019-03-03 18:04:55 +01:00
then
ldap=""
fi
max_size_set=""
if [ $max_file_size -eq 0 ]; then # Comment the limitation line if no limit
max_size_set="#"
2019-03-03 18:04:55 +01:00
fi
2020-05-30 16:34:01 +02:00
ynh_add_config --template="../conf/lufi.conf.template" --destination="$final_path/lufi.conf"
chmod 600 $final_path/lufi.conf
chown $app:$app $final_path/lufi.conf
#=================================================
2020-05-30 16:34:01 +02:00
# INSTALL LUFI
#=================================================
2020-11-14 08:31:09 +01:00
ynh_script_progression --message="Installing $app..."
pushd $final_path
carton install --deployment --without=sqlite --without=mysql --without=htpasswd --without=test
popd
2018-09-02 11:08:06 +02:00
#=================================================
2019-03-03 18:04:55 +01:00
# SETUP CRON
2018-09-02 11:08:06 +02:00
#=================================================
2020-05-30 16:34:01 +02:00
ynh_script_progression --message="Setuping a cron..."
2017-02-07 22:51:47 +01:00
2021-03-20 15:33:35 +01:00
ynh_add_config --template="../conf/cron_lufi" --destination="/etc/cron.d/$app"
2019-03-03 18:04:55 +01:00
chmod +x $final_path/script/lufi
2017-02-07 22:51:47 +01:00
2018-09-02 11:08:06 +02:00
#=================================================
2019-03-03 18:04:55 +01:00
# SETUP SYSTEMD
2018-09-02 11:08:06 +02:00
#=================================================
2020-05-30 16:34:01 +02:00
ynh_script_progression --message="Configuring a systemd service..."
2018-09-02 11:08:06 +02:00
2019-03-03 18:04:55 +01:00
# Create a dedicated systemd config
ynh_add_systemd_config
2018-09-02 11:08:06 +02:00
#=================================================
2019-03-03 18:04:55 +01:00
# SETUP LOGROTATE
2018-09-02 11:08:06 +02:00
#=================================================
2020-05-30 16:34:01 +02:00
ynh_script_progression --message="Configuring log rotation..."
2018-09-02 11:08:06 +02:00
2019-03-03 18:04:55 +01:00
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
2018-09-02 11:08:06 +02:00
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
2018-09-02 11:08:06 +02:00
#=================================================
2020-05-30 16:34:01 +02:00
ynh_script_progression --message="Integrating service in YunoHost..."
2017-02-07 22:51:47 +01:00
2020-12-13 21:16:52 +01:00
yunohost service add $app --description="Lufi service" --log="$final_path/log/production.log"
2018-09-02 11:08:06 +02:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
2020-05-30 16:34:01 +02:00
ynh_script_progression --message="Starting a systemd service..."
2020-05-30 16:34:01 +02:00
# Start a systemd service
2020-04-21 03:51:37 +02:00
ynh_systemd_action --service_name=$app --action="start" --line_match="Creating process id file" --log_path="$final_path/log/production.log"
2018-09-02 11:08:06 +02:00
#=================================================
2019-03-03 18:04:55 +01:00
# SETUP SSOWAT
2018-09-02 11:08:06 +02:00
#=================================================
2021-03-20 15:33:35 +01:00
ynh_script_progression --message="Configuring permissions..."
2022-06-16 19:19:38 +02:00
# Make app public if necessary
if [ $is_public -eq 1 ]
2019-03-03 18:04:55 +01:00
then
2022-06-16 19:19:38 +02:00
# Everyone can access the app.
# The "main" permission is automatically created before the install script.
ynh_permission_update --permission="main" --add="visitors"
2019-03-03 18:04:55 +01:00
fi
2018-09-02 11:08:06 +02:00
#=================================================
2019-03-03 18:04:55 +01:00
# RELOAD NGINX
2018-09-02 11:08:06 +02:00
#=================================================
2020-11-01 18:24:02 +01:00
ynh_script_progression --message="Reloading NGINX web server..."
2018-09-02 11:08:06 +02:00
ynh_systemd_action --service_name=nginx --action=reload
2017-02-07 22:51:47 +01:00
2018-09-02 11:08:06 +02:00
#=================================================
2019-03-03 18:04:55 +01:00
# END OF SCRIPT
2018-09-02 11:08:06 +02:00
#=================================================
2020-05-30 16:34:01 +02:00
ynh_script_progression --message="Installation of $app completed"