2015-06-18 23:40:52 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-01-17 20:58:01 +01:00
|
|
|
# We retrieve app parameters
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2015-06-18 23:40:52 +02:00
|
|
|
|
2017-01-17 20:58:01 +01:00
|
|
|
# Backup the current version of the app, restore it if the upgrade fails
|
2017-01-18 00:15:14 +01:00
|
|
|
#if sudo yunohost backup list | grep -q ${app}-before-upgrade > /dev/null 2>&1; then # Supprime l'ancienne archive seulement si elle existe
|
|
|
|
# sudo yunohost backup delete ${app}-before-upgrade
|
|
|
|
#fi
|
|
|
|
#sudo yunohost backup create --ignore-hooks --apps $app --name ${app}-before-upgrade
|
2017-01-17 20:58:01 +01:00
|
|
|
EXIT_PROPERLY () {
|
|
|
|
exit_code=$?
|
|
|
|
if [ "$exit_code" -eq 0 ]; then
|
|
|
|
exit 0 # Quitte sans erreur si le script se termine correctement.
|
|
|
|
fi
|
|
|
|
trap '' EXIT
|
|
|
|
set +eu
|
|
|
|
sudo yunohost app remove $app # Supprime l'application avant de la restaurer.
|
|
|
|
sudo yunohost backup restore --ignore-hooks ${app}-before-upgrade --apps $app --force # Restore the backup if upgrade failed
|
|
|
|
ynh_die "Upgrade failed. The app was restored to the way it was before the failed upgrade."
|
|
|
|
}
|
2017-01-18 00:15:14 +01:00
|
|
|
#set -eu
|
|
|
|
#trap EXIT_PROPERLY EXIT
|
2015-06-18 23:40:52 +02:00
|
|
|
|
2016-12-24 12:38:35 +01:00
|
|
|
# Source app helpers
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
# We check variables are not empty
|
|
|
|
CHECK_VAR () { # Vérifie que la variable n'est pas vide.
|
|
|
|
# $1 = Variable à vérifier
|
|
|
|
# $2 = Texte à afficher en cas d'erreur
|
|
|
|
test -n "$1" || (echo "$2" >&2 && false)
|
|
|
|
}
|
|
|
|
CHECK_VAR "$app" "app name not set"
|
|
|
|
|
|
|
|
path=$(ynh_app_setting_get $app path)
|
|
|
|
domain=$(ynh_app_setting_get $app domain)
|
|
|
|
final_path=$(ynh_app_setting_get $app final_path)
|
|
|
|
finalnginxconf=$(ynh_app_setting_get $app finalnginxconf)
|
|
|
|
finalphpconf=$(ynh_app_setting_get $app finalphpconf)
|
|
|
|
|
|
|
|
# Removal of old folder and restart from fresh
|
|
|
|
sudo rm -rf $final_path
|
|
|
|
sudo mkdir -p $final_path
|
|
|
|
|
2017-01-17 19:59:41 +01:00
|
|
|
# We download the sources and check the md5sum
|
2016-12-24 15:01:49 +01:00
|
|
|
SHA1=`sudo cat ../sources/source_sha1`;
|
2017-01-17 19:59:41 +01:00
|
|
|
sed -i "s@SHA1TOCHANGE@$SHA1@g" ../sources/source_url
|
|
|
|
sed -i "s@SHA1TOCHANGE@$SHA1@g" ../sources/source_md5
|
|
|
|
sudo wget -nv -i ../sources/source_url -O framagames-${SHA1}.zip
|
|
|
|
sudo md5sum -c ../sources/source_md5 --status || (echo "Corrupt source" >&2 && false)
|
|
|
|
sudo unzip framagames-${SHA1}.zip -d ../sources/
|
2017-01-17 20:11:33 +01:00
|
|
|
sudo cp -R ../sources/framagames-${SHA1}/* $final_path
|
2016-12-24 12:38:35 +01:00
|
|
|
|
|
|
|
# Set permissions
|
|
|
|
sudo chmod 775 -R $final_path
|
2016-12-24 12:45:51 +01:00
|
|
|
sudo chown -hR www-data:www-data $final_path
|
2016-12-24 12:38:35 +01:00
|
|
|
|
|
|
|
# Modify Nginx configuration file and copy it to Nginx conf.d directory
|
2015-06-18 23:40:52 +02:00
|
|
|
sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf
|
2016-12-24 12:38:35 +01:00
|
|
|
sed -i "s@ALIASTOCHANGE@$final_path/@g" ../conf/nginx.conf
|
|
|
|
sed -i "s@NAMETOCHANGE@$app@g" ../conf/nginx.conf
|
|
|
|
sudo cp ../conf/nginx.conf $finalnginxconf
|
2015-06-18 23:40:52 +02:00
|
|
|
|
2016-12-24 12:38:35 +01:00
|
|
|
# Modify php-fpm configuration file and copy it to php-fpm pool.d directory
|
|
|
|
sed -i "s@NAMETOCHANGE@$app@g" ../conf/php-fpm.conf
|
|
|
|
sed -i "s@FOLDERTOCHANGE@$final_path@g" ../conf/php-fpm.conf
|
2015-06-18 23:40:52 +02:00
|
|
|
sudo cp ../conf/php-fpm.conf $finalphpconf
|
|
|
|
sudo chown root: $finalphpconf
|
|
|
|
sudo chmod 644 $finalphpconf
|
|
|
|
|
|
|
|
# Make app public if necessary
|
2016-12-24 12:38:35 +01:00
|
|
|
is_public=$(ynh_app_setting_get $app is_public)
|
2015-06-18 23:40:52 +02:00
|
|
|
if [ "$is_public" = "Yes" ];
|
|
|
|
then
|
2016-12-24 12:38:35 +01:00
|
|
|
ynh_app_setting_set $app skipped_uris "/"
|
2015-06-18 23:40:52 +02:00
|
|
|
else
|
2016-12-24 12:38:35 +01:00
|
|
|
ynh_app_setting_set $app protected_uris "/"
|
2015-06-18 23:40:52 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Reload Nginx and regenerate SSOwat conf
|
2016-12-24 12:38:35 +01:00
|
|
|
sudo service php5-fpm reload
|
2015-06-18 23:40:52 +02:00
|
|
|
sudo service nginx reload
|
|
|
|
sudo yunohost app ssowatconf
|