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
|
2020-04-20 04:16:40 +02:00
|
|
|
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
|
2020-04-20 04:16:40 +02:00
|
|
|
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
|
2020-04-20 04:16:40 +02:00
|
|
|
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
|
2020-04-20 04:16:40 +02:00
|
|
|
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
|
|
|
#=================================================
|
2020-04-20 04:16:40 +02: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
|
|
|
|
2020-04-20 04:16:40 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
|
|
|
ynh_app_setting_set --app=$app --key=path --value=$path_url
|
2021-03-21 09:19:14 +01:00
|
|
|
ynh_app_setting_set --app=$app --key=is_public --value=$is_public
|
2020-04-20 04:16:40 +02:00
|
|
|
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
|
|
|
#=================================================
|
2020-04-20 04:16:40 +02:00
|
|
|
# STANDARD MODIFICATIONS
|
2018-09-02 11:08:06 +02:00
|
|
|
#=================================================
|
2020-04-20 04:16:40 +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
|
|
|
|
2020-04-20 04:16:40 +02: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
|
|
|
|
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
|
2020-04-20 04:16:40 +02:00
|
|
|
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
2019-03-03 18:04:55 +01:00
|
|
|
db_user=$db_name
|
2020-04-20 04:16:40 +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
|
|
|
|
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
|
|
|
|
2020-04-20 04:16:40 +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
|
2020-04-20 04:16:40 +02:00
|
|
|
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
|
2020-04-20 04:16:40 +02:00
|
|
|
ynh_system_user_create --username=$app
|
2017-02-07 22:51:47 +01:00
|
|
|
|
2018-09-02 11:08:06 +02:00
|
|
|
#=================================================
|
2020-04-20 04:16:40 +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
|
|
|
|
2020-04-20 04:16:40 +02: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
|
2020-04-20 04:16:40 +02:00
|
|
|
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
|
2020-04-20 04:16:40 +02:00
|
|
|
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
|
2020-04-20 04:16:40 +02:00
|
|
|
ynh_replace_string --match_string="__IS_PUBLIC__" --replace_string="" --target_file="$config"
|
2019-03-03 18:04:55 +01:00
|
|
|
else
|
2020-04-20 04:16:40 +02:00
|
|
|
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-04-20 04:16:40 +02:00
|
|
|
|
|
|
|
#=================================================
|
2020-05-30 16:34:01 +02:00
|
|
|
# INSTALL LUFI
|
2020-04-20 04:16:40 +02:00
|
|
|
#=================================================
|
2020-11-14 08:31:09 +01:00
|
|
|
ynh_script_progression --message="Installing $app..."
|
2020-04-20 04:16:40 +02:00
|
|
|
|
|
|
|
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
|
|
|
# cp ../conf/cron_lufi /etc/cron.d/$app
|
|
|
|
# ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path/" --target_file="/etc/cron.d/$app"
|
|
|
|
# ynh_replace_string --match_string="__USER__" --replace_string="$app" --target_file="/etc/cron.d/$app"
|
|
|
|
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
|
2017-04-03 14:04:18 +02:00
|
|
|
|
2018-09-02 11:08:06 +02:00
|
|
|
#=================================================
|
2020-04-20 04:16:40 +02:00
|
|
|
# GENERIC FINALIZATION
|
2018-09-02 11:08:06 +02:00
|
|
|
#=================================================
|
2020-04-20 04:16:40 +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
|
|
|
|
2020-04-20 04:16:40 +02: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
|
|
|
|
|
|
|
#=================================================
|
2020-04-20 04:16:40 +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
|
|
|
|
2020-04-20 04:16:40 +02:00
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2020-05-30 16:34:01 +02:00
|
|
|
ynh_script_progression --message="Starting a systemd service..."
|
2020-04-20 04:16:40 +02:00
|
|
|
|
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"
|
2020-04-20 04:16:40 +02:00
|
|
|
|
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..."
|
|
|
|
|
|
|
|
ynh_permission_update --permission="main" --add="visitors"
|
2018-09-02 11:08:06 +02:00
|
|
|
|
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')
|
2020-04-20 04:16:40 +02:00
|
|
|
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
|
|
|
|
2020-04-20 04:16:40 +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"
|