mirror of
https://github.com/YunoHost-Apps/paheko_ynh.git
synced 2024-09-03 19:56:22 +02:00
157 lines
5.6 KiB
Bash
157 lines
5.6 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
# Load common variables and helpers
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# CHECK VERSION
|
|
#=================================================
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
#=================================================
|
|
# STANDARD UPGRADE STEPS
|
|
#=================================================
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
#=================================================
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
|
|
|
# If secret_key doesn't exist, create it
|
|
if [ -z "${secret_key:-}" ]; then
|
|
secret_key=$(ynh_string_random --length=50)
|
|
ynh_app_setting_set --app=$app --key=secret_key --value=$secret_key
|
|
fi
|
|
|
|
#=================================================
|
|
# KEEP CONFIGS IF NEEDED
|
|
#=================================================
|
|
|
|
if [ -f "$install_dir/config.local.yunohost.php" ]
|
|
then
|
|
ynh_script_progression --message="cleaning conf files..." --weight=5
|
|
ynh_secure_remove "$install_dir/config.local.php"
|
|
mv "$install_dir/config.local.yunohost.php" "$install_dir/config.local.php"
|
|
chmod 440 "$install_dir/config.local.php"
|
|
chown $app:$app "$install_dir/config.local.php"
|
|
ynh_store_file_checksum --file="$install_dir/config.local.php"
|
|
fi
|
|
|
|
ynh_script_progression --message="removing old conf files if they exist..." --weight=5
|
|
|
|
if [ -f "$install_dir/config.local.user.php" ]; then
|
|
ynh_secure_remove "$install_dir/config.local.user.php"
|
|
fi
|
|
|
|
if [ -f "$install_dir/data/config.local.user.php" ]; then
|
|
ynh_secure_remove "$install_dir/data/config.local.user.php"
|
|
fi
|
|
|
|
if [ -d "$install_dir/data/data" ]; then
|
|
ynh_secure_remove "$install_dir/data/data"
|
|
fi
|
|
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
then
|
|
ynh_script_progression --message="Upgrading source files..." --weight=5
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
ynh_setup_source --dest_dir="$install_dir" --keep="config.local.php data/plugins"
|
|
fi
|
|
|
|
chmod -R o-rwx "$install_dir"
|
|
chown -R $app:www-data "$install_dir"
|
|
|
|
|
|
#=================================================
|
|
# REAPPLY SYSTEM CONFIGURATIONS
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
|
|
|
|
# Create a dedicated PHP-FPM config
|
|
ynh_add_fpm_config
|
|
|
|
# Create a dedicated NGINX config
|
|
ynh_add_nginx_config
|
|
|
|
ynh_add_config --template="cron" --destination="/etc/cron.d/$app"
|
|
chown root: "/etc/cron.d/$app"
|
|
chmod 644 "/etc/cron.d/$app"
|
|
|
|
#=================================================
|
|
# SPECIFIC UPGRADE
|
|
#=================================================
|
|
# UPDATE A CONFIG FILE
|
|
#=================================================
|
|
ynh_script_progression --message="Updating a configuration file..." --weight=5
|
|
|
|
# Install configuration files
|
|
ynh_add_config --template="config.local.php" --destination="$install_dir/config.local.php"
|
|
|
|
chmod 440 "$install_dir/config.local.php"
|
|
chown $app:$app "$install_dir/config.local.php"
|
|
|
|
ynh_replace_string --match_string="//require '$data_dir/data/config.local.user.php';" --replace_string="require '$data_dir/data/config.local.user.php';" --target_file="$install_dir/config.local.php"
|
|
|
|
if ynh_compare_current_package_version --comparison le --version 1.3.6~ynh2 && ynh_compare_current_package_version --comparison ge --version 1.3.0~ynh1; then
|
|
ynh_script_progression --message="keep old user configuration file..." --weight=5
|
|
mv "$data_dir/data/config.local.user.php" "$data_dir/data/config.local.user.php.old"
|
|
ynh_add_config --template="config.local.user.php" --destination="$data_dir/data/config.local.user.php"
|
|
chmod 640 "$data_dir/data/config.local.user.php"
|
|
chown $app:$app "$data_dir/data/config.local.user.php"
|
|
fi
|
|
|
|
#=================================================
|
|
# ADD A CONFIG FILE
|
|
#=================================================
|
|
|
|
if [ ! -d "$data_dir/data" ]; then
|
|
ynh_script_progression --message="Adding a configuration directory..." --weight=5
|
|
mkdir "$data_dir/data"
|
|
chmod 770 "$data_dir/data"
|
|
chown -R $app:www-data "$data_dir/data"
|
|
else
|
|
chown -R $app:www-data "$data_dir/data/cache"
|
|
chown $app:www-data "$data_dir/data/index.html"
|
|
fi
|
|
|
|
if [ ! -f "$data_dir/data/config.local.user.php" ]; then
|
|
ynh_script_progression --message="Adding a configuration file..." --weight=5
|
|
ynh_add_config --template="config.local.user.php" --destination="$data_dir/data/config.local.user.php"
|
|
chmod 640 "$data_dir/data/config.local.user.php"
|
|
chown $app:$app "$data_dir/data/config.local.user.php"
|
|
fi
|
|
|
|
if [ ! -d "$data_dir/data/local_addresses" ]; then
|
|
ynh_script_progression --message="Adding a configuration directory..." --weight=5
|
|
mkdir "$data_dir/data/local_addresses"
|
|
chmod 770 "$data_dir/data/local_addresses"
|
|
chown -R $app:www-data "$data_dir/data/local_addresses"
|
|
else
|
|
chown -R $app:www-data "$data_dir/data/local_addresses"
|
|
chown $app:www-data "$data_dir/data/local_addresses"
|
|
fi
|
|
|
|
|
|
if [ -f "$install_dir/data/association.sqlite" ]; then
|
|
ynh_script_progression --message="Moving db files..." --weight=5
|
|
mv $install_dir/data/association.* $data_dir/data/
|
|
ynh_secure_remove "$install_dir/data/association.*"
|
|
fi
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|