2017-04-01 18:16:18 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-04-03 19:21:30 +02:00
|
|
|
#=================================================
|
2019-03-03 18:04:55 +01:00
|
|
|
# GENERIC START
|
2017-04-03 19:21:30 +02:00
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
2019-03-03 18:04:55 +01:00
|
|
|
source _common.sh
|
2017-04-03 19:21:30 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2020-05-30 16:34:01 +02:00
|
|
|
ynh_script_progression --message="Loading installation settings..."
|
2017-04-01 18:16:18 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2020-04-20 04:16:40 +02:00
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
|
|
|
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
|
|
|
|
port=$(ynh_app_setting_get --app=$app --key=port)
|
|
|
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
|
|
|
secret=$(ynh_app_setting_get --app=$app --key=secret)
|
|
|
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
2019-03-03 18:04:55 +01:00
|
|
|
db_user=$db_name
|
2020-04-20 04:16:40 +02:00
|
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
|
|
|
|
max_file_size=$(ynh_app_setting_get --app=$app --key=max_file_size)
|
2017-04-01 18:16:18 +02:00
|
|
|
|
2017-04-03 19:21:30 +02:00
|
|
|
#=================================================
|
2020-04-20 04:16:40 +02:00
|
|
|
# CHECK VERSION
|
2017-04-03 19:21:30 +02:00
|
|
|
#=================================================
|
2020-05-30 16:34:01 +02:00
|
|
|
ynh_script_progression --message="Checking version..."
|
2017-04-03 19:21:30 +02:00
|
|
|
|
2020-04-20 04:16:40 +02:00
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
2020-05-30 16:34:01 +02:00
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..."
|
2020-04-20 04:16:40 +02:00
|
|
|
|
2020-05-30 16:34:01 +02:00
|
|
|
# If final_path doesn't exist, create it
|
|
|
|
if [ -z "$final_path" ]; then
|
2017-04-03 19:21:30 +02:00
|
|
|
final_path=/var/www/$app
|
2020-05-26 01:58:07 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
2017-04-03 19:21:30 +02:00
|
|
|
fi
|
|
|
|
|
2019-03-26 23:14:32 +01:00
|
|
|
if [ -z "$db_pwd" ]; then
|
2019-03-27 01:11:24 +01:00
|
|
|
# Need to install new dependencies before creating the new database
|
2019-03-26 23:49:56 +01:00
|
|
|
need_migration_from_sqlite_to_psql=1
|
2019-03-27 00:20:55 +01:00
|
|
|
else
|
|
|
|
need_migration_from_sqlite_to_psql=0
|
2019-03-03 18:04:55 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$max_file_size" ]; then
|
|
|
|
max_file_size=100 # 100 Mo
|
2020-05-26 01:58:07 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=max_file_size --value=$max_file_size
|
2019-03-03 18:04:55 +01:00
|
|
|
fi
|
|
|
|
|
2021-03-20 15:33:35 +01:00
|
|
|
# Make app public if necessary
|
|
|
|
if [ $is_public -eq 1 ]
|
|
|
|
then
|
|
|
|
# Everyone can access the app.
|
|
|
|
# The "main" permission is automatically created before the install script.
|
|
|
|
ynh_permission_update --permission="main" --add="visitors"
|
|
|
|
fi
|
|
|
|
|
2019-03-03 18:04:55 +01:00
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
2020-05-30 16:34:01 +02:00
|
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
|
2017-04-01 18:16:18 +02:00
|
|
|
|
2019-03-03 18:04:55 +01:00
|
|
|
# Backup the current version of the app
|
|
|
|
ynh_backup_before_upgrade
|
|
|
|
ynh_clean_setup () {
|
|
|
|
ynh_clean_check_starting
|
|
|
|
# restore it if the upgrade fails
|
|
|
|
ynh_restore_upgradebackup
|
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
2020-04-20 04:16:40 +02:00
|
|
|
# STOP SYSTEMD SERVICE
|
2019-03-03 18:04:55 +01:00
|
|
|
#=================================================
|
2020-05-30 16:34:01 +02:00
|
|
|
ynh_script_progression --message="Stopping a systemd service..."
|
2019-03-03 18:04:55 +01:00
|
|
|
|
2020-04-20 04:16:40 +02:00
|
|
|
ynh_systemd_action --service_name=$app --action="stop" --log_path="$final_path/log/production.log"
|
2017-04-01 18:16:18 +02:00
|
|
|
|
2019-03-27 01:11:24 +01:00
|
|
|
#=================================================
|
2020-04-20 04:16:40 +02:00
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
2019-03-27 01:11:24 +01:00
|
|
|
#=================================================
|
|
|
|
|
2020-04-20 04:16:40 +02:00
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
|
|
then
|
2020-05-30 16:34:01 +02:00
|
|
|
ynh_script_progression --message="Upgrading source files..."
|
2020-04-20 04:16:40 +02:00
|
|
|
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
|
|
ynh_setup_source --dest_dir="$final_path"
|
2019-03-27 01:11:24 +01:00
|
|
|
fi
|
|
|
|
|
2017-04-03 19:21:30 +02:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2020-11-01 18:24:02 +01:00
|
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..."
|
2017-04-03 19:21:30 +02:00
|
|
|
|
2019-03-03 18:04:55 +01:00
|
|
|
# Create a dedicated nginx config
|
|
|
|
ynh_add_nginx_config max_file_size
|
2017-04-03 19:21:30 +02:00
|
|
|
|
2020-04-20 04:16:40 +02:00
|
|
|
#=================================================
|
|
|
|
# UPGRADE DEPENDENCIES
|
|
|
|
#=================================================
|
2020-05-30 16:34:01 +02:00
|
|
|
ynh_script_progression --message="Upgrading dependencies..."
|
2020-04-20 04:16:40 +02:00
|
|
|
|
2021-01-23 17:06:02 +01:00
|
|
|
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
|
2020-04-20 04:16:40 +02:00
|
|
|
|
2019-03-03 18:04:55 +01:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
2020-05-30 16:34:01 +02:00
|
|
|
ynh_script_progression --message="Making sure dedicated system user exists..."
|
2017-04-01 18:16:18 +02:00
|
|
|
|
2019-03-03 18:04:55 +01:00
|
|
|
# Create a dedicated user (if not existing)
|
2020-04-20 04:16:40 +02:00
|
|
|
ynh_system_user_create --username=$app
|
2017-04-01 18:16:18 +02:00
|
|
|
|
2017-04-03 19:21:30 +02:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
|
|
|
#=================================================
|
2020-04-20 04:16:40 +02:00
|
|
|
# CREATE A POSTGRESQL DATABASE IF NEEDED
|
2017-04-03 19:21:30 +02:00
|
|
|
#=================================================
|
|
|
|
|
2020-04-20 04:16:40 +02:00
|
|
|
if [ $need_migration_from_sqlite_to_psql -eq 1 ]; then
|
|
|
|
ynh_print_info --message="Creating a PostgreSQL database..."
|
|
|
|
# Create postgresql database
|
|
|
|
ynh_psql_test_if_first_run
|
|
|
|
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
|
|
|
db_user=$db_name
|
|
|
|
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
|
|
|
# Initialize database and store postgres password for upgrade
|
2020-04-25 22:41:57 +02:00
|
|
|
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name
|
2020-04-20 04:16:40 +02:00
|
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) # Password created in ynh_psql_setup_db function
|
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP LUFI
|
|
|
|
#=================================================
|
2020-05-30 16:34:01 +02:00
|
|
|
ynh_script_progression --message="Configuring lufi..."
|
2020-04-20 04:16:40 +02:00
|
|
|
|
|
|
|
config=${final_path}/lufi.conf
|
|
|
|
ynh_backup_if_checksum_is_different --file="$config"
|
|
|
|
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
|
|
|
|
2020-04-20 04:16:40 +02:00
|
|
|
ynh_store_file_checksum --file="$config"
|
2019-03-03 18:04:55 +01:00
|
|
|
|
|
|
|
#=================================================
|
2020-05-30 16:34:01 +02:00
|
|
|
# BUILD LUFI
|
2017-04-03 19:21:30 +02:00
|
|
|
#=================================================
|
2020-05-30 16:34:01 +02:00
|
|
|
ynh_script_progression --message="Building Lufi..."
|
2017-04-03 19:21:30 +02:00
|
|
|
|
2019-03-03 18:04:55 +01:00
|
|
|
pushd $final_path
|
2019-03-26 23:49:56 +01:00
|
|
|
# Migrate from SQLite to PostgreSQL
|
|
|
|
if [ $need_migration_from_sqlite_to_psql -eq 1 ]; then
|
2019-03-27 21:11:45 +01:00
|
|
|
# Preinstall with sqlite
|
|
|
|
carton install --deployment --without=mysql --without=htpasswd --without=test
|
|
|
|
|
|
|
|
# if /var/log/$app/production.log is a symbolic link, then move it to $final_path/log/production.log
|
|
|
|
if [ ! -L "/var/log/$app/production.log" ]
|
|
|
|
then
|
|
|
|
mv "/var/log/$app/production.log" "$final_path/log/production.log"
|
|
|
|
chown -R $app: "$final_path/log/production.log"
|
|
|
|
fi
|
|
|
|
|
2019-03-26 23:49:56 +01:00
|
|
|
carton exec script/lufi sqliteToOtherDB
|
|
|
|
fi
|
|
|
|
|
|
|
|
carton install --deployment --without=sqlite --without=mysql --without=htpasswd --without=test
|
2019-03-03 18:04:55 +01:00
|
|
|
popd
|
2017-04-03 19:21:30 +02:00
|
|
|
|
2020-05-26 01:58:07 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP CRON
|
|
|
|
#=================================================
|
2020-05-30 16:34:01 +02:00
|
|
|
ynh_script_progression --message="Setuping cron..."
|
2020-05-26 01:58:07 +02: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"
|
2020-05-26 01:58:07 +02:00
|
|
|
chmod +x $final_path/script/lufi
|
|
|
|
|
2020-04-20 04:16:40 +02:00
|
|
|
#=================================================
|
|
|
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
|
|
|
#=================================================
|
2020-05-30 16:34:01 +02:00
|
|
|
ynh_script_progression --message="Storing the config file checksum..."
|
2020-04-20 04:16:40 +02:00
|
|
|
|
2020-12-13 21:16:52 +01:00
|
|
|
yunohost service add $app --description="Lufi service" --log="$final_path/log/production.log"
|
2020-04-20 04:16:40 +02:00
|
|
|
|
2017-04-03 19:21:30 +02:00
|
|
|
#=================================================
|
2019-03-03 18:04:55 +01:00
|
|
|
# SETUP LOGROTATE
|
2017-04-03 19:21:30 +02:00
|
|
|
#=================================================
|
2020-05-30 16:34:01 +02:00
|
|
|
ynh_script_progression --message="Upgrading logrotate configuration..."
|
2017-04-03 19:21:30 +02:00
|
|
|
|
2019-03-03 18:04:55 +01:00
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
|
|
ynh_use_logrotate --non-append
|
2017-04-03 19:21:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
2020-04-20 04:16:40 +02:00
|
|
|
# SETUP SYSTEMD
|
2017-04-03 19:21:30 +02:00
|
|
|
#=================================================
|
2020-05-30 16:34:01 +02:00
|
|
|
ynh_script_progression --message="Upgrading systemd configuration..."
|
2017-04-03 19:21:30 +02:00
|
|
|
|
2020-04-20 04:16:40 +02:00
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_config
|
2017-04-03 19:21:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
2020-04-20 04:16:40 +02:00
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SECURING FILES AND DIRECTORIES
|
2017-04-03 19:21:30 +02:00
|
|
|
#=================================================
|
2020-05-30 16:34:01 +02:00
|
|
|
ynh_script_progression --message="Securing files and directories..."
|
2017-04-03 19:21:30 +02:00
|
|
|
|
2020-04-20 04:16:40 +02:00
|
|
|
# Set permissions on app files
|
|
|
|
chown -R $app: $final_path
|
2017-04-03 19:21:30 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2020-05-30 16:34:01 +02:00
|
|
|
ynh_script_progression --message="Upgrading SSOwat configuration..."
|
2017-04-03 19:21:30 +02:00
|
|
|
|
2021-03-20 15:33:35 +01:00
|
|
|
ynh_permission_update --permission="main" --add="visitors"
|
|
|
|
|
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/.*$"
|
2017-04-01 18:16:18 +02:00
|
|
|
fi
|
|
|
|
|
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-26 01:58:07 +02:00
|
|
|
ynh_systemd_action --service_name=$app --action="restart" --log_path="$final_path/log/production.log" --line_match="Creating process id file"
|
2020-04-20 04:16:40 +02:00
|
|
|
|
2017-04-03 19:21:30 +02:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2020-11-01 18:24:02 +01:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
2019-03-03 18:04:55 +01:00
|
|
|
|
2020-04-20 04:16:40 +02:00
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
2019-03-03 18:04:55 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
2017-04-03 19:21:30 +02:00
|
|
|
|
2020-05-30 16:34:01 +02:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed"
|