2017-07-21 21:40:25 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2020-10-15 21:09:24 +02:00
|
|
|
ynh_script_progression --message="Loading installation settings..."
|
2017-07-21 21:40:25 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2020-04-09 10:42:49 +02:00
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
|
|
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
|
|
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
|
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
|
2021-07-17 16:48:02 +02:00
|
|
|
email=$(ynh_app_setting_get --app=$app --key=email)
|
2020-04-09 10:42:49 +02:00
|
|
|
admin=$(ynh_app_setting_get --app=$app --key=admin)
|
2020-10-15 21:09:24 +02:00
|
|
|
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
|
2020-04-09 10:42:49 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
2017-07-21 21:40:25 +02:00
|
|
|
|
2019-03-12 11:37:22 +01:00
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
2020-10-15 21:09:24 +02:00
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..."
|
2019-03-12 11:37:22 +01:00
|
|
|
|
|
|
|
# If db_name doesn't exist, create it
|
2020-04-09 10:42:49 +02:00
|
|
|
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
|
2019-03-12 11:37:22 +01:00
|
|
|
fi
|
|
|
|
|
2018-06-05 23:17:03 +02:00
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
2020-10-15 21:09:24 +02:00
|
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
|
2017-07-21 21:40:25 +02:00
|
|
|
|
2018-06-05 23:17:03 +02:00
|
|
|
# Backup the current version of the app
|
|
|
|
ynh_backup_before_upgrade
|
|
|
|
ynh_clean_setup () {
|
|
|
|
# restore it if the upgrade fails
|
|
|
|
ynh_restore_upgradebackup
|
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
2018-09-28 18:25:44 +02:00
|
|
|
#=================================================
|
|
|
|
# CHECK THE PATH
|
|
|
|
#=================================================
|
2018-09-28 17:53:46 +02:00
|
|
|
|
2018-06-05 23:17:03 +02:00
|
|
|
# If final_path doesn't exist, create it
|
2020-04-09 10:42:49 +02:00
|
|
|
if [ -z "$final_path" ]; then
|
2018-06-05 23:17:03 +02:00
|
|
|
final_path=/var/www/$app
|
2020-04-09 10:42:49 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
2018-06-05 23:17:03 +02:00
|
|
|
fi
|
2019-03-12 11:37:22 +01:00
|
|
|
|
2020-10-15 21:09:24 +02:00
|
|
|
# Remove files for upgrade compatibilty from previous versions of Friendica
|
2018-09-28 18:10:58 +02:00
|
|
|
if [ -f $final_path/.htconfig.php ]; then
|
2020-11-09 16:08:57 +01:00
|
|
|
ynh_secure_remove "$final_path/.htconfig.php"
|
2018-09-28 18:10:58 +02:00
|
|
|
fi
|
|
|
|
|
2019-03-12 11:37:22 +01:00
|
|
|
if [ -f $final_path/.htconfig.php ]; then
|
2020-11-09 16:08:57 +01:00
|
|
|
ynh_secure_remove "$final_path/config/local.ini.php"
|
2019-03-12 11:37:22 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# If admin_mail setting doesn't exist, create it
|
2021-07-17 16:48:02 +02:00
|
|
|
if [ -z $email ]; then
|
|
|
|
email=$(ynh_user_get_info --username=$admin --key=mail)
|
|
|
|
ynh_app_setting_set --app=$app --key=email --value=$email
|
2018-11-02 15:40:01 +01:00
|
|
|
fi
|
|
|
|
|
2021-02-10 09:00:00 +01:00
|
|
|
# Cleaning legacy permissions
|
|
|
|
if ynh_legacy_permissions_exists; then
|
|
|
|
ynh_legacy_permissions_delete_all
|
|
|
|
|
|
|
|
ynh_app_setting_delete --app=$app --key=is_public
|
|
|
|
fi
|
|
|
|
|
2021-07-17 16:48:02 +02:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Making sure dedicated system user exists..."
|
|
|
|
|
|
|
|
# Create a dedicated user (if not existing)
|
|
|
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
|
|
|
|
2020-04-09 10:42:49 +02:00
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
|
|
then
|
2021-05-24 22:46:53 +02:00
|
|
|
|
|
|
|
# Check if the repo can be updated with git
|
|
|
|
if [ `cd $final_path && git rev-parse --is-inside-work-tree` ];
|
|
|
|
then
|
|
|
|
# Update through git
|
|
|
|
pushd "$final_path"
|
|
|
|
git fetch
|
|
|
|
git checkout stable
|
|
|
|
git pull
|
|
|
|
popd
|
|
|
|
pushd "$final_path/addon"
|
|
|
|
git fetch
|
|
|
|
git checkout stable
|
|
|
|
git pull
|
|
|
|
popd
|
|
|
|
# If git is not present upgrade through manual method
|
|
|
|
else
|
|
|
|
|
|
|
|
# Create a temporary directory and backup smarty3 folder
|
2021-07-17 17:18:53 +02:00
|
|
|
tmpdir="$(mktemp -d)"
|
2020-10-15 21:09:24 +02:00
|
|
|
ynh_script_progression --message="Upgrading source files..."
|
2021-05-24 22:46:53 +02:00
|
|
|
cp -a "$final_path/view/smarty3" "$tmpdir/view/smarty3"
|
|
|
|
|
|
|
|
# Remove the app directory securely
|
|
|
|
ynh_secure_remove "$final_path"
|
2020-04-09 10:42:49 +02:00
|
|
|
|
2021-07-01 22:14:37 +02:00
|
|
|
# 1- Clone stable repo
|
|
|
|
$git clone https://github.com/friendica/friendica.git -b stable "$final_path"
|
2021-05-24 22:46:53 +02:00
|
|
|
|
|
|
|
# Remove the addon directory securely
|
|
|
|
ynh_secure_remove "$final_path/addon"
|
|
|
|
|
2021-07-01 22:14:37 +02:00
|
|
|
# 2 - Clone addons repo
|
|
|
|
git clone https://github.com/friendica/friendica-addons.git -b stable "$final_path/addon"
|
2021-05-24 22:46:53 +02:00
|
|
|
|
|
|
|
# Restore the smarty3 folder
|
|
|
|
cp -a "$tmpdir/view/smarty3" "${final_path}"
|
2021-05-25 01:51:07 +02:00
|
|
|
ynh_secure_remove "$tmpdir"
|
2021-05-24 22:46:53 +02:00
|
|
|
fi
|
2020-04-09 10:42:49 +02:00
|
|
|
fi
|
2018-09-28 18:25:44 +02:00
|
|
|
|
|
|
|
# Copy config file for correct place
|
2021-07-17 16:48:02 +02:00
|
|
|
ynh_add_config --template="../conf/local-sample.config.php" --destination="$final_path/config/local.config.php"
|
2017-07-21 21:40:25 +02:00
|
|
|
|
2021-07-17 16:48:02 +02:00
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
|
|
|
chown -R $app:www-data "$final_path"
|
2017-07-21 21:40:25 +02:00
|
|
|
|
|
|
|
# 3 - some extra folders
|
2020-04-10 20:47:43 +02:00
|
|
|
chmod -R 775 $final_path/view/smarty3
|
2017-07-21 21:40:25 +02:00
|
|
|
|
2019-03-12 11:37:22 +01:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2021-02-10 09:00:00 +01:00
|
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..."
|
2019-03-12 11:37:22 +01:00
|
|
|
|
2017-07-21 21:40:25 +02:00
|
|
|
# Create a dedicated nginx config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
2018-06-05 23:17:03 +02:00
|
|
|
#=================================================
|
|
|
|
# PHP-FPM CONFIGURATION
|
|
|
|
#=================================================
|
2021-02-10 09:00:00 +01:00
|
|
|
ynh_script_progression --message="Upgrading PHP-FPM configuration..."
|
2018-06-05 23:17:03 +02:00
|
|
|
|
|
|
|
# Create a dedicated php-fpm config
|
2020-10-15 21:09:24 +02:00
|
|
|
ynh_add_fpm_config --package="$extra_php_dependencies"
|
2020-04-09 10:42:49 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STORE THE CONFIG FILE CHECKSUM
|
|
|
|
#=================================================
|
|
|
|
|
2021-07-17 16:48:02 +02:00
|
|
|
ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app"
|
|
|
|
chown root: "/etc/cron.d/$app"
|
|
|
|
chmod 644 "/etc/cron.d/$app"
|
2017-07-21 21:40:25 +02:00
|
|
|
|
2020-10-15 21:09:24 +02:00
|
|
|
# Run composer
|
|
|
|
pushd "$final_path"
|
2021-05-25 06:36:34 +02:00
|
|
|
php$phpversion bin/console dbstructure update 2> /dev/null
|
2021-02-03 19:50:12 +01:00
|
|
|
bin/console config system addon ldapauth
|
2020-10-15 21:09:24 +02:00
|
|
|
popd
|
2017-07-21 21:40:25 +02:00
|
|
|
|
2019-03-12 11:37:22 +01:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2021-02-10 09:00:00 +01:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
2019-03-12 11:37:22 +01:00
|
|
|
|
2020-04-09 10:42:49 +02:00
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
2019-03-12 11:37:22 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2020-10-15 21:09:24 +02:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed"
|