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

201 lines
7.2 KiB
Text
Raw Normal View History

2018-11-18 16:00:35 +01:00
#!/bin/bash
2018-11-24 11:27:04 +01:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
2018-11-24 11:27:04 +01:00
#=================================================
# LOAD SETTINGS
#=================================================
2018-11-18 16:00:35 +01:00
2018-11-24 11:27:04 +01:00
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
2019-05-20 23:54:52 +02:00
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
2018-11-24 11:27:04 +01:00
admin=$(ynh_app_setting_get $app admin)
final_path=$(ynh_app_setting_get $app final_path)
db_name=$(ynh_app_setting_get $app db_name)
2019-05-20 23:54:52 +02:00
#=================================================
# CHECK VERSION
#=================================================
### This helper will compare the version of the currently installed app and the version of the upstream package.
### $upgrade_type can have 2 different values
### - UPGRADE_APP if the upstream app version has changed
### - UPGRADE_PACKAGE if only the YunoHost package has changed
### ynh_check_app_version_changed will stop the upgrade if the app is up to date.
### UPGRADE_APP should be used to upgrade the core app only if there's an upgrade to do.
### Not used yet in this script
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
# Fix is_public as a boolean value
if [ "$is_public" = "Yes" ]; then
ynh_app_setting_set --app=$app --key=is_public --value=1
is_public=1
elif [ "$is_public" = "No" ]; then
ynh_app_setting_set --app=$app --key=is_public --value=0
is_public=0
fi
# If db_name doesn't exist, create it
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
fi
# If final_path doesn't exist, create it
if [ -z "$final_path" ]; then
final_path=/var/www/$app
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
# 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
#=================================================
# CHECK THE PATH
#=================================================
# Normalize the URL path syntax
path_url=$(ynh_normalize_url_path $path_url)
#=================================================
2019-05-22 12:05:43 +02:00
#check for matlink's version - DEPRECATED - uninstall & reinstall
#=================================================
#deprecated - not maintained for more than a year...
#cat /etc/yunohost/apps/$app/status.json | grep "matlink"
#if [[ $?==0 ]]; then
2018-11-24 15:09:25 +01:00
#add missing info in settings
# final_path=/var/www/$app
# db_name=emailPoubelle
# ynh_app_setting_set $app db_name $db_name
# ynh_app_setting_set $app final_path $final_path
2018-11-24 15:09:25 +01:00
#install geoip dependencies
# ynh_install_app_dependencies $pkg_dependencies
2018-11-24 15:09:25 +01:00
#install locale packages
# for i in $lang ; do
# ynh_replace_string "# $i" "$i" /etc/locale.gen
# done
# locale-gen
2018-11-24 15:09:25 +01:00
#change folder locale => lang as per src2.0
# rm -rf $final_path/locale
# mkdir -p $final_path/lang
2018-11-24 15:09:25 +01:00
#add new index.php
# cp ../conf/index_source.php $final_path/www/index.php
2018-11-24 15:09:25 +01:00
#switch from previous (modified) conf.php to new one (emailpoubelle original)
# cp ../src/conf-dist.php $final_path/conf-dist.new.php
2018-11-24 15:12:20 +01:00
#insert domain in line 24, DB in line 31, DBUSER in line 32, etc.
# rep=$(cat $final_path/conf.php | grep "^[^//]" | grep "define('DOMAIN',")
# sed -i "24s/.*/${rep}/" $final_path/conf-dist.new.php
# rep=$(cat $final_path/conf.php | grep "^[^//]" | grep "define('DB',")
# sed -i "31s/.*/${rep}/" $final_path/conf-dist.new.php
# rep=$(cat $final_path/conf.php | grep "^[^//]" | grep "define('DBUSER',")
# sed -i "32s/.*/${rep}/" $final_path/conf-dist.new.php
# rep=$(cat $final_path/conf.php | grep "^[^//]" | grep "define('DBPASS',")
# sed -i "33s/.*/${rep}/" $final_path/conf-dist.new.php
2018-11-24 15:12:20 +01:00
#replace old conf and process with install command
# mv $final_path/conf.php $final_path/conf.php.old
# mv $final_path/conf-dist.new.php $final_path/conf.php
# ynh_replace_string "define('DB', 'sqlite:'" "//define('DB', 'sqlite:'" $final_path/conf.php
# ynh_replace_string "define('ALIASLIMITBYMAIL" "//define('ALIASLIMITBYMAIL" $final_path/conf.php
# #setting conf file not world-readable (dude, there is a plain-text password !)
# sudo chmod o-r $final_path/conf.php
#fi
2018-11-18 16:00:35 +01:00
#=================================================
2019-05-20 23:54:52 +02:00
# STANDARD UPGRADE STEPS
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_print_info "Upgrading nginx web server configuration..."
ynh_backup_if_checksum_is_different "/etc/nginx/conf.d/$domain.d/$app.conf"
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
2019-03-05 22:43:49 +01:00
ynh_print_info "Installing dependencies"
ynh_install_app_dependencies $pkg_dependencies
2019-05-20 23:54:52 +02:00
#=================================================
#UPDATE SETTINGS
#=================================================
2018-11-25 16:19:51 +01:00
#mysqlpwd setting was implemented in ynh2 - check if saved and if not implement
db_pass=$(ynh_app_setting_get $app mysqlpwd)
2019-05-20 23:35:32 +02:00
if [ -z $db_pass ]; then
2018-11-25 16:19:51 +01:00
#c'est moche mais ça fera bien l'affaire - en deux lignes sinon pb en fonction du type de shell
t=$(cat /var/www/$app/conf.php | grep DBPASS)
2018-11-25 16:27:12 +01:00
db_pass=${t:26:24}
2018-11-25 16:24:56 +01:00
ynh_app_setting_set $app mysqlpwd $db_pass
2018-11-25 16:19:51 +01:00
fi
2019-03-05 22:43:49 +01:00
#=================================================
#INSTALL SOURCES
#===============================================
2019-05-20 23:54:52 +02:00
ynh_print_info "Downloading sources to $final_path"
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
2018-11-24 15:09:25 +01:00
cp ../conf/index_source.php $final_path/www/index.php
2018-12-01 11:49:41 +01:00
test -e $final_path/template-exemple
if [[ ! $? -eq 0 ]]; then
ln -s $final_path/www/template-exemple $final_path/template-exemple
fi
2019-05-20 23:54:52 +02:00
2018-11-24 15:09:25 +01:00
#Temporaire - mettre en config
2019-05-21 00:31:09 +02:00
if [ ! -e $final_path/lang/fr_FR ]; then
2018-11-24 15:09:25 +01:00
ln -s $final_path/lang/fr $final_path/lang/fr_FR
2019-05-21 00:31:09 +02:00
fi
if [ ! -e $final_path/lang/it_IT ]; then
2018-11-24 15:09:25 +01:00
ln -s $final_path/lang/it $final_path/lang/it_IT
2019-05-21 00:31:09 +02:00
fi
2018-12-01 11:49:41 +01:00
2019-05-22 12:17:02 +02:00
#setting postfix to use virtual aliases file
# Add postfix configuration hook and regen postfix conf
2019-05-22 12:05:43 +02:00
#setting postfix to use virtual aliases file
# Add postfix configuration hook and regen postfix conf
cp -R ../sources/hooks/conf_regen/98-postfix_emailpoubelle /usr/share/yunohost/hooks/conf_regen/
2019-05-22 12:17:02 +02:00
mv /etc/postfix/main.cf /etc/postfic/main.cf.emailpoubelle.bak
yunohost service regen-conf postfix -f
2019-05-20 23:54:52 +02:00
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
2018-11-24 12:05:55 +01:00
chown -R www-data:www-data $final_path
2018-11-18 16:00:35 +01:00
#=================================================
# RELOAD SERVICES
#=================================================
2019-05-20 23:54:52 +02:00
ynh_systemd_action --service_name=php7.0-fpm --action=restart
ynh_systemd_action --service_name=nginx --action=reload
ynh_systemd_action --service_name=postfix --action=reload