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

238 lines
8.9 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
2019-03-03 18:04:55 +01:00
max_file_size=$YNH_APP_ARG_MAX_FILE_SIZE
is_public=$YNH_APP_ARG_IS_PUBLIC
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
# Check web path availability
ynh_webpath_available --domain=$domain --path_url=$path_url
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=is_public --value=$is_public
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
#=================================================
2020-05-30 16:34:01 +02:00
ynh_script_progression --message="Configuring firewall..."
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
2019-03-27 01:11:01 +01:00
ynh_install_app_dependencies $pkg_dependencies
2020-05-26 01:58:07 +02:00
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
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
2019-03-03 18:04:55 +01:00
ynh_add_nginx_config max_file_size
2017-02-07 22:51:47 +01:00
2018-09-02 11:08:06 +02:00
#=================================================
# CREATE DEDICATED USER
#=================================================
2020-05-30 16:34:01 +02:00
ynh_script_progression --message="Configuring system user..."
2017-02-07 22:51:47 +01:00
2018-09-02 11:08:06 +02:00
# Create a system user
ynh_system_user_create --username=$app
2017-02-07 22:51:47 +01:00
2018-09-02 11:08:06 +02:00
#=================================================
# SPECIFIC SETUP
#=================================================
# 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
config=${final_path}/lufi.conf
cp ../conf/lufi.conf.template "$config"
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$config"
ynh_replace_string --match_string="__PATH__" --replace_string="$path_url" --target_file="$config"
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$config"
ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$config"
ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="$config"
ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$config"
ynh_replace_string --match_string="__MAX_FILE_SIZE__" --replace_string="$max_file_size" --target_file="$config"
2019-03-03 18:52:39 +01:00
if [ $max_file_size -eq 0 ]; then # Comment the limitation line if no limit
ynh_replace_string --match_string="max_file_size" --replace_string="#max_file_size" --target_file="$config"
2019-03-03 18:52:39 +01:00
fi
ynh_replace_string --match_string="__SECRET__" --replace_string="$secret" --target_file="$config"
2020-05-30 16:34:01 +02:00
2019-03-03 18:04:55 +01:00
if [ $is_public -eq 0 ];
then
ynh_replace_string --match_string="__IS_PUBLIC__" --replace_string="" --target_file="$config"
2019-03-03 18:04:55 +01:00
else
ynh_replace_string --match_string="__IS_PUBLIC__" --replace_string="#" --target_file="$config"
2019-03-03 18:04:55 +01:00
fi
2020-05-30 16:34:01 +02:00
ynh_store_file_checksum --file="$config"
#=================================================
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
2019-03-03 18:04:55 +01:00
cp ../conf/cron_lufi /etc/cron.d/$app
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path/" --target_file="/etc/cron.d/$app"
2020-05-29 22:49:32 +02:00
ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="/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
#=================================================
# GENERIC FINALIZATION
2018-09-02 11:08:06 +02:00
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
2020-05-30 16:34:01 +02:00
ynh_script_progression --message="Securing files and directories..."
2017-02-07 22:51:47 +01:00
# Set permissions to app files
chown -R $app:$app $final_path
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 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
#=================================================
2020-05-30 16:34:01 +02:00
ynh_script_progression --message="Configuring SSOwat..."
2018-09-02 11:08:06 +02:00
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
2019-03-08 22:04:09 +01:00
if [ $is_public -eq 0 ]
2019-03-03 18:04:55 +01:00
then
2019-03-08 22:04:09 +01:00
if [ "$path_url" == "/" ]; then
# If the path is /, clear it to prevent any error with the regex.
path_url=""
fi
# Modify the domain to be used in a regex
domain_regex=$(echo "$domain" | sed 's@-@.@g')
ynh_app_setting_set --app=$app --key=protected_regex --value="$domain_regex$path_url/stats$","$domain_regex$path_url/manifest.webapp$","$domain_regex$path_url/$","$domain_regex$path_url/d/.*$","$domain_regex$path_url/m/.*$"
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"