1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/rainloop_ynh.git synced 2024-09-03 20:16:18 +02:00
rainloop_ynh/scripts/upgrade

106 lines
4.3 KiB
Text
Raw Normal View History

2016-07-26 22:51:05 +02:00
#!/bin/bash
app=$YNH_APP_INSTANCE_NAME
rainloop_version=$(cat ../sources/rainloop_version)
2016-07-26 22:51:05 +02:00
2017-02-24 23:16:26 +01:00
# Source app helpers
source /usr/share/yunohost/helpers
source .fonctions
# Backup the current version of the app, restore it if the upgrade fails
2017-02-21 22:23:47 +01:00
# Check if old backup exists
if sudo yunohost backup list | grep -q $app-before-upgrade > /dev/null 2>&1;
then
sudo yunohost backup delete $app-before-upgrade
else
echo "no old backup to delete"
fi
2016-12-18 13:16:33 +01:00
sudo yunohost backup create --ignore-hooks --apps $app --name $app-before-upgrade --quiet
EXIT_PROPERLY () {
2017-02-24 12:18:06 +01:00
trap '' ERR
set +eu
2016-12-18 13:16:33 +01:00
sudo yunohost backup restore --ignore-hooks $app-before-upgrade --apps $app --force --quiet # Restore the backup if upgrade failed
ynh_die "Upgrade failed. The app was restored to the way it was before the failed upgrade."
}
2017-02-21 23:23:45 +01:00
set -eu
trap EXIT_PROPERLY ERR
2016-06-28 17:27:30 +02:00
2015-02-06 19:47:10 +01:00
# Retrieve arguments
2016-06-28 17:27:30 +02:00
domain=$(ynh_app_setting_get "$app" domain)
path=$(ynh_app_setting_get "$app" path)
is_public=$(ynh_app_setting_get "$app" is_public)
2016-07-26 13:49:42 +02:00
password=$(ynh_app_setting_get "$app" password)
ldap=$(ynh_app_setting_get "$app" ldap)
lang=$(ynh_app_setting_get "$app" lang)
2016-06-28 17:27:30 +02:00
dp_pwd=$(ynh_app_setting_get "$app" mysqlpwd)
2015-10-24 14:24:50 +02:00
db_user=$app
2016-06-28 17:27:30 +02:00
plugins=$(ynh_app_setting_get "$app" plugins)
# Correct path using .fonctions
CHECK_PATH
# no update for db now...
2015-02-06 19:47:10 +01:00
# Copy the new sources
2015-10-24 14:24:50 +02:00
final_path=/var/www/$app
rainloop_path=${final_path}/app
sudo rm -rf $rainloop_path/rainloop # Remove the previous Rainloop files except data
# Download sources and keys
sudo wget -q https://github.com/RainLoop/rainloop-webmail/releases/download/v${rainloop_version}/rainloop-community-${rainloop_version}.zip
sudo wget -q https://github.com/RainLoop/rainloop-webmail/releases/download/v${rainloop_version}/rainloop-community-${rainloop_version}.zip.asc
sudo wget -q https://repository.rainloop.net/RainLoop.asc
2017-02-21 23:23:45 +01:00
# Verify the integrity of sources
sudo gpg --import --quiet RainLoop.asc
sudo gpg --verify --quiet rainloop-community-${rainloop_version}.zip.asc rainloop-community-${rainloop_version}.zip
sudo gpg --batch --delete-key --yes Rainloop
# Unzip and overwrite
sudo unzip -qq -o rainloop-community-${rainloop_version}.zip -d $rainloop_path/
2015-02-06 19:47:10 +01:00
2015-10-24 14:24:50 +02:00
# Update ynh plugins:
sudo mkdir -p $rainloop_path/data/_data_/_default_/plugins
sudo cp -rf ../sources/plugins/auto-domain-grab $rainloop_path/data/_data_/_default_/plugins/.
2015-10-24 14:24:50 +02:00
sudo cp -rf ../sources/plugins/ynh-login-mapping $rainloop_path/data/_data_/_default_/plugins/.
2015-10-24 23:51:26 +02:00
sudo cp -rf ../sources/plugins/ynh-ldap-suggestions $rainloop_path/data/_data_/_default_/plugins/.
# update SSO
sudo cp ../sources/sso/sso.php $final_path/index.php
sudo sed -i "s@domain.tld@$domain@g" $final_path/index.php
sudo sed -i "s@ALIASTOCHANGE@$final_path@g" $final_path/index.php
if [ $path = "/" ]; then
sudo sed -i "s@ROOTTOCHANGE@@g" $final_path/index.php
else
sudo sed -i "s@ROOTTOCHANGE@$path@g" $final_path/index.php
fi
2016-12-18 02:26:17 +01:00
# Install PGPback by chtixof to allow users to backup/restore their PGP private keys on the server
sudo cp -rf ../sources/pgpback $final_path/.
# Set permissions to rainloop directory
2016-06-28 17:27:30 +02:00
sudo find $final_path/. -type d -exec chmod 755 {} \;
sudo find $final_path/. -type f -exec chmod 644 {} \;
2015-10-24 14:24:50 +02:00
sudo chown -R www-data:www-data $final_path
# Update Nginx configuration file
2015-10-24 14:24:50 +02:00
nginx_conf_file=/etc/nginx/conf.d/$domain.d/$app.conf
sudo cp ../conf/nginx.conf $nginx_conf_file
2017-02-23 14:32:47 +01:00
if [ $path = "/" ]; then
sudo sed -i "s@ROOTTOCHANGE@@g" $nginx_conf_file
2017-02-23 14:32:47 +01:00
else
sudo sed -i "s@ROOTTOCHANGE@$path@g" $nginx_conf_file
2017-02-23 14:32:47 +01:00
fi
sudo sed -i "s@PATHTOCHANGE@$path@g" $nginx_conf_file
2015-10-24 14:24:50 +02:00
sudo sed -i "s@ALIASTOCHANGE@$final_path/@g" $nginx_conf_file
sudo sed -i "s@NAMETOCHANGE@$app@g" $nginx_conf_file
sudo chown root: $nginx_conf_file
sudo chmod 644 $nginx_conf_file
2015-02-06 19:47:10 +01:00
2015-10-24 14:24:50 +02:00
finalphpconf=/etc/php5/fpm/pool.d/$app.conf
sudo cp ../conf/php-fpm.conf $finalphpconf
sudo sed -i "s@NAMETOCHANGE@$app@g" $finalphpconf
sudo chown root: $finalphpconf
sudo chmod 644 $finalphpconf
2015-02-06 19:47:10 +01:00
2016-06-28 17:27:30 +02:00
# Reload services
sudo service php5-fpm reload
sudo service nginx reload