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)
|
2022-01-19 20:47:13 +01:00
|
|
|
use_ldap=$(ynh_app_setting_get --app=$app --key=use_ldap)
|
2020-04-20 04:16:40 +02:00
|
|
|
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)
|
2022-06-16 21:07:01 +02:00
|
|
|
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
|
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
|
|
|
#=================================================
|
2022-01-27 02:40:24 +01: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)
|
|
|
|
|
2021-11-13 12:01:57 +01:00
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
|
|
|
|
|
|
|
|
# Backup the current version of the app
|
|
|
|
ynh_backup_before_upgrade
|
|
|
|
ynh_clean_setup () {
|
|
|
|
ynh_clean_check_starting
|
2022-01-27 02:40:24 +01:00
|
|
|
# Restore it if the upgrade fails
|
2021-11-13 12:01:57 +01:00
|
|
|
ynh_restore_upgradebackup
|
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
2022-01-27 02:40:24 +01:00
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Stopping a systemd service..."
|
|
|
|
|
2022-06-16 19:19:38 +02:00
|
|
|
ynh_systemd_action --service_name=$app --action="stop" --log_path="$final_path/log/production.log"
|
2022-01-27 02:40:24 +01:00
|
|
|
|
2020-04-20 04:16:40 +02:00
|
|
|
#=================================================
|
|
|
|
# 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
|
|
|
|
2021-05-08 23:38:59 +02:00
|
|
|
# If db_name doesn't exist, create it
|
|
|
|
if [ -z "$db_name" ]; then
|
|
|
|
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
|
|
|
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
|
|
|
fi
|
|
|
|
|
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-03 18:04:55 +01:00
|
|
|
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
|
|
|
|
|
2022-01-19 20:47:13 +01:00
|
|
|
# Check if is_public settings exist and is set to true
|
|
|
|
was_public=$(ynh_app_setting_get --app=$app --key=is_public)
|
|
|
|
if [ $was_public -eq 1 ]
|
|
|
|
then
|
|
|
|
# Fix permissions if true
|
|
|
|
ynh_print_info --message="Upgrading from legacy permission..."
|
|
|
|
ynh_print_info --message="Legacy public instance detected, allow visitors with new permission."
|
|
|
|
use_ldap=0
|
|
|
|
|
|
|
|
# Add new permission to allow visitors
|
|
|
|
ynh_permission_update --permission="main" --add="visitors"
|
|
|
|
|
|
|
|
# Remove deprecated is_public settings
|
|
|
|
ynh_app_setting_delete --app=$app --key=is_public
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check if legacy permissions exists (meanning that is_public was set to false)
|
2021-03-21 09:20:17 +01:00
|
|
|
if ynh_legacy_permissions_exists; then
|
2022-01-19 20:47:13 +01:00
|
|
|
|
|
|
|
ynh_print_info --message="Upgrading from legacy permission..."
|
|
|
|
ynh_print_info --message="Legacy private instance detected, keep LDAP enabled."
|
|
|
|
|
|
|
|
# Legacy private install have LDAP enabled
|
|
|
|
use_ldap=1
|
|
|
|
|
|
|
|
# Cleaning legacy permissions
|
|
|
|
ynh_print_info --message="Removing legacy permission..."
|
2021-03-21 09:20:17 +01:00
|
|
|
ynh_legacy_permissions_delete_all
|
|
|
|
|
2022-01-19 20:47:13 +01:00
|
|
|
# Remove deprecated is_public settings
|
2021-03-21 09:20:17 +01:00
|
|
|
ynh_app_setting_delete --app=$app --key=is_public
|
2021-03-20 15:33:35 +01:00
|
|
|
fi
|
|
|
|
|
2022-06-16 21:07:01 +02:00
|
|
|
# If datadir doesn't exist, create it
|
|
|
|
if [ -z "$datadir" ]; then
|
|
|
|
datadir=/home/yunohost.app/$app
|
|
|
|
ynh_app_setting_set --app=$app --key=datadir --value=$datadir
|
|
|
|
mkdir -p $datadir
|
|
|
|
mv -f "$final_path/upload" "$datadir/upload"
|
|
|
|
chmod 750 "$datadir"
|
|
|
|
chmod -R o-rwx "$datadir"
|
|
|
|
chown -R $app:www-data "$datadir"
|
|
|
|
fi
|
|
|
|
|
2021-05-08 23:38:59 +02:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Making sure dedicated system user exists..."
|
|
|
|
|
|
|
|
# Create a dedicated user (if not existing)
|
2021-06-06 19:02:01 +02:00
|
|
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
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
|
|
|
|
|
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"
|
|
|
|
|
2017-04-03 19:21:30 +02:00
|
|
|
#=================================================
|
2022-06-16 19:19:38 +02:00
|
|
|
# UPGRADE DEPENDENCIES
|
2017-04-03 19:21:30 +02:00
|
|
|
#=================================================
|
2022-06-16 19:19:38 +02:00
|
|
|
ynh_script_progression --message="Upgrading dependencies..."
|
2017-04-03 19:21:30 +02:00
|
|
|
|
2022-06-16 19:19:38 +02:00
|
|
|
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
|
2017-04-03 19:21:30 +02:00
|
|
|
|
2020-04-20 04:16:40 +02:00
|
|
|
#=================================================
|
2022-06-16 19:19:38 +02:00
|
|
|
# NGINX CONFIGURATION
|
2020-04-20 04:16:40 +02:00
|
|
|
#=================================================
|
2022-06-16 19:19:38 +02:00
|
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..."
|
2020-04-20 04:16:40 +02:00
|
|
|
|
2022-06-16 19:19:38 +02:00
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config
|
2020-04-20 04:16:40 +02:00
|
|
|
|
2022-01-27 02:40:24 +01:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
2020-04-20 04:16:40 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP LUFI
|
|
|
|
#=================================================
|
2021-05-08 23:38:59 +02:00
|
|
|
ynh_script_progression --message="Configuring Lufi..."
|
2020-04-20 04:16:40 +02:00
|
|
|
|
2022-01-19 21:01:53 +01:00
|
|
|
ldap="#"
|
2022-01-19 20:47:13 +01:00
|
|
|
if [ $use_ldap -eq 1 ];
|
2019-03-03 18:04:55 +01:00
|
|
|
then
|
2022-01-19 21:01:53 +01:00
|
|
|
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
|
|
|
|
2022-01-19 21:01:53 +01:00
|
|
|
ynh_add_config --template="../conf/lufi.conf.template" --destination="$final_path/lufi.conf"
|
2019-03-03 18:04:55 +01:00
|
|
|
|
2021-05-08 23:38:59 +02:00
|
|
|
chmod 600 $final_path/lufi.conf
|
|
|
|
chown $app:$app $final_path/lufi.conf
|
|
|
|
|
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
|
2021-05-08 23:38:59 +02:00
|
|
|
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
|
|
|
|
2021-03-21 09:21:20 +01:00
|
|
|
ynh_add_config --template="../conf/cron_lufi" --destination="/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
|
|
|
#=================================================
|
2022-01-27 02:40:24 +01:00
|
|
|
# SETUP SYSTEMD
|
2020-04-20 04:16:40 +02:00
|
|
|
#=================================================
|
2022-01-27 02:40:24 +01:00
|
|
|
ynh_script_progression --message="Upgrading systemd configuration..."
|
2020-04-20 04:16:40 +02:00
|
|
|
|
2022-01-27 02:40:24 +01:00
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_config
|
2020-04-20 04:16:40 +02:00
|
|
|
|
2022-01-27 02:40:24 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
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
|
|
|
|
|
|
|
#=================================================
|
2022-01-27 02:40:24 +01:00
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
2017-04-03 19:21:30 +02:00
|
|
|
#=================================================
|
2022-01-27 02:40:24 +01:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
2017-04-03 19:21:30 +02:00
|
|
|
|
2022-01-27 02:40:24 +01:00
|
|
|
yunohost service add $app --description="Lufi service" --log="$final_path/log/production.log"
|
2017-04-03 19:21:30 +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-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"
|