mirror of
https://github.com/YunoHost-Apps/friendica_ynh.git
synced 2024-09-03 18:36:14 +02:00
163 lines
5.1 KiB
Bash
163 lines
5.1 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
ynh_script_progression --message="Loading installation settings..." --weight=1
|
|
|
|
timezone=$(cat /etc/timezone)
|
|
|
|
#=================================================
|
|
# CHECK VERSION
|
|
#=================================================
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
#=================================================
|
|
# STOP SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Stopping a systemd service..." --weight=1
|
|
|
|
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
|
|
|
|
#=================================================
|
|
# CHECK THE PATH
|
|
#=================================================
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=3
|
|
|
|
# Remove files for upgrade compatibilty from previous versions of Friendica
|
|
if [ -f $install_dir/.htconfig.php ]; then
|
|
ynh_secure_remove "$install_dir/.htconfig.php"
|
|
fi
|
|
|
|
# Remove files for upgrade compatibilty from previous versions of Friendica
|
|
if [ -f $install_dir/.htconfig.php ]; then
|
|
ynh_secure_remove "$install_dir/.htconfig.php"
|
|
fi
|
|
|
|
if [ -f /etc/cron.d/$app ]; then
|
|
ynh_secure_remove --file="/etc/cron.d/$app"
|
|
fi
|
|
|
|
# If admin_mail setting doesn't exist, create it
|
|
if [ -z $email ]; then
|
|
email=$(ynh_user_get_info --username=$admin --key=mail)
|
|
ynh_app_setting_set --app=$app --key=email --value=$email
|
|
fi
|
|
|
|
# If language setting doesn't exist, create it
|
|
if [ -z $language ]; then
|
|
language=en
|
|
ynh_app_setting_set --app=$app --key=language --value=$language
|
|
fi
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
then
|
|
ynh_script_progression --message="Upgrading source files..." --weight=3
|
|
# Check if the repo can be updated with git
|
|
if [ `cd $install_dir && git rev-parse --is-inside-work-tree &> /dev/null` ];
|
|
then
|
|
# Update through Git
|
|
pushd "$install_dir"
|
|
git fetch
|
|
git checkout stable
|
|
git pull
|
|
git reset --hard $version_commit
|
|
popd
|
|
pushd "$install_dir/addon"
|
|
git fetch
|
|
git checkout stable
|
|
git pull
|
|
git reset --hard $addons_version_commit
|
|
popd
|
|
# If Git is not present upgrade through manual method
|
|
else
|
|
|
|
# Create a temporary directory and backup smarty3 folder
|
|
tmpdir="$(mktemp -d)"
|
|
cp -a "$install_dir/view/smarty3" "$tmpdir/smarty3"
|
|
|
|
# Remove the app directory securely
|
|
ynh_secure_remove --file="$install_dir"
|
|
|
|
# 1 - Clone stable repo
|
|
git clone --quiet https://github.com/friendica/friendica.git -b stable "$install_dir"
|
|
# Reset branch to the level of update we needed
|
|
pushd "$install_dir"
|
|
git reset --hard --quiet $version_commit
|
|
popd
|
|
|
|
# 2 - Clone addons repo
|
|
git clone --quiet https://github.com/friendica/friendica-addons.git -b stable "$install_dir/addon"
|
|
# Reset addons branch to the level of update we needed
|
|
pushd "$install_dir/addon"
|
|
git reset --hard --quiet $addons_version_commit
|
|
popd
|
|
|
|
# Restore the smarty3 folder
|
|
cp -a "$tmpdir/smarty3" "$install_dir/view/smarty3"
|
|
ynh_secure_remove --file="$tmpdir"
|
|
fi
|
|
fi
|
|
|
|
# Copy config file for correct place
|
|
ynh_add_config --template="../conf/local-sample.config.php" --destination="$install_dir/config/local.config.php"
|
|
|
|
chmod 750 "$install_dir"
|
|
chmod -R o-rwx "$install_dir"
|
|
chown -R $app:www-data "$install_dir"
|
|
|
|
# 3 - some extra folders
|
|
chmod -R 775 "$install_dir/view/smarty3"
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
|
|
|
|
# Create a dedicated NGINX config
|
|
ynh_add_nginx_config
|
|
|
|
# Create a dedicated PHP-FPM config
|
|
ynh_add_fpm_config --usage=low --footprint=low
|
|
|
|
ynh_add_systemd_config
|
|
|
|
yunohost service add $app --description="Friendica daemon" --log="/var/log/$app/$app.log"
|
|
|
|
#=================================================
|
|
# STORE THE CONFIG FILE CHECKSUM
|
|
#=================================================
|
|
|
|
# Run Composer
|
|
pushd "$install_dir"
|
|
ynh_exec_as "$app" php$phpversion bin/composer.phar install --no-dev --quiet
|
|
ynh_exec_as "$app" bin/console dbstructure update
|
|
#ynh_exec_as "$app" bin/console config system addon ldapauth
|
|
popd
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|