mirror of
https://github.com/YunoHost-Apps/emailpoubelle_ynh.git
synced 2024-09-03 18:26:29 +02:00
Merge pull request #3 from Krakinou/Testing
Add Backup and Restore scripts
This commit is contained in:
commit
c13bca9e9c
8 changed files with 192 additions and 11 deletions
|
@ -32,7 +32,7 @@ TODO :
|
||||||
|
|
||||||
[X] Implement Admin panel
|
[X] Implement Admin panel
|
||||||
|
|
||||||
[ ] Add backup restore script
|
[X] Add backup restore script
|
||||||
|
|
||||||
[ ] check checksum on download
|
[ ] check checksum on download
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
"fr": "Créez des adresses email jetables qui redirigent les mails vers votre adresse réelle"
|
"fr": "Créez des adresses email jetables qui redirigent les mails vers votre adresse réelle"
|
||||||
},
|
},
|
||||||
"url": "https://framagit.org/kepon/emailPoubellePhp/",
|
"url": "https://framagit.org/kepon/emailPoubellePhp/",
|
||||||
"version": "2.0~ynh1",
|
"version": "2.0~ynh2",
|
||||||
"license": "Beerware",
|
"license": "Beerware",
|
||||||
"maintainer": {
|
"maintainer": {
|
||||||
"name": "krakinou",
|
"name": "krakinou",
|
||||||
|
|
|
@ -4,4 +4,4 @@
|
||||||
pkg_dependencies="php-geoip"
|
pkg_dependencies="php-geoip"
|
||||||
app="emailpoubelle"
|
app="emailpoubelle"
|
||||||
lang="fr_FR.UTF-8 en_US.UTF-8 it_IT.UTF-8"
|
lang="fr_FR.UTF-8 en_US.UTF-8 it_IT.UTF-8"
|
||||||
|
postfix=/etc/postfix/main.cf
|
||||||
|
|
66
scripts/backup
Normal file
66
scripts/backup
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC START
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
if [ ! -e _common.sh ]; then
|
||||||
|
# Get the _common.sh file if it's not in the current directory
|
||||||
|
cp ../settings/scripts/_common.sh ./_common.sh
|
||||||
|
chmod a+rx _common.sh
|
||||||
|
fi
|
||||||
|
source _common.sh
|
||||||
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# MANAGE SCRIPT FAILURE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Exit if an error occurs during the execution of the script
|
||||||
|
ynh_abort_if_errors
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# LOAD SETTINGS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
|
final_path=$(ynh_app_setting_get $app final_path)
|
||||||
|
domain=$(ynh_app_setting_get $app domain)
|
||||||
|
db_name=$(ynh_app_setting_get $app db_name)
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# STANDARD BACKUP STEPS
|
||||||
|
#=================================================
|
||||||
|
# BACKUP THE APP MAIN DIR
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_backup "$final_path"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# BACKUP THE NGINX CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# BACKUP THE MYSQL DATABASE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_mysql_dump_db "$db_name" > db.sql
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# BACKUP THE CRON FILE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_backup "/etc/cron.d/$app"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# BACKUP POSTFIX & ALIASES
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_backup $postfix
|
||||||
|
ynh_backup /etc/aliases
|
|
@ -19,7 +19,6 @@ password=$YNH_APP_ARG_PASSWORD
|
||||||
is_public=$5
|
is_public=$5
|
||||||
final_path=/var/www/$app
|
final_path=/var/www/$app
|
||||||
db_user=emailPoubelle
|
db_user=emailPoubelle
|
||||||
postfix=/etc/postfix/main.cf
|
|
||||||
cronline="0 */2 * * * www-data cd $final_path/www/; /usr/bin/php index.php > /dev/null 2>&1"
|
cronline="0 */2 * * * www-data cd $final_path/www/; /usr/bin/php index.php > /dev/null 2>&1"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -70,6 +69,7 @@ locale-gen
|
||||||
sudo mkdir -p $final_path
|
sudo mkdir -p $final_path
|
||||||
sudo cp -R ../src/* $final_path
|
sudo cp -R ../src/* $final_path
|
||||||
sudo cp ../conf/index_source.php $final_path/www/index.php
|
sudo cp ../conf/index_source.php $final_path/www/index.php
|
||||||
|
ynh_replace_string "Template-exemple" "$domain" $final_path/www/index.php
|
||||||
|
|
||||||
#Temporaire - mettre en config
|
#Temporaire - mettre en config
|
||||||
ln -s $final_path/lang/fr $final_path/lang/fr_FR
|
ln -s $final_path/lang/fr $final_path/lang/fr_FR
|
||||||
|
@ -106,7 +106,7 @@ ynh_mysql_create_db $db_user $db_user $db_pwd
|
||||||
|
|
||||||
#setting postfix to use virtual aliases file
|
#setting postfix to use virtual aliases file
|
||||||
sudo cp $postfix $postfix.emailpoubelle.bak #backup it eventually if that causes some issues
|
sudo cp $postfix $postfix.emailpoubelle.bak #backup it eventually if that causes some issues
|
||||||
sudo sed -i "s/^virtual_alias_maps/#virtual_alias_maps/g" $postfix
|
ynh_replace_string "^virtual_alias_maps" "#virtual_alias_maps" $postfix
|
||||||
echo "virtual_alias_maps = hash:$final_path/var/virtual" | sudo tee -a $postfix
|
echo "virtual_alias_maps = hash:$final_path/var/virtual" | sudo tee -a $postfix
|
||||||
|
|
||||||
#create the virtual aliases file
|
#create the virtual aliases file
|
||||||
|
@ -147,8 +147,8 @@ sudo echo "$cronline" | sudo tee -a /etc/cron.d/emailpoubelle
|
||||||
sudo chmod 644 /etc/cron.d/emailpoubelle
|
sudo chmod 644 /etc/cron.d/emailpoubelle
|
||||||
|
|
||||||
# Restart services
|
# Restart services
|
||||||
sudo service nginx reload
|
systemctl reload nginx
|
||||||
sudo service postfix reload
|
systemctl reload postfix
|
||||||
sudo service php* reload
|
sudo service php* reload
|
||||||
sudo yunohost app ssowatconf
|
sudo yunohost app ssowatconf
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,11 @@ sudo rm -f /etc/nginx/conf.d/$domain.d/emailpoubelle.conf
|
||||||
#removing aliases
|
#removing aliases
|
||||||
sudo sed -i "/devnull:\/dev\/null/d" /etc/aliases
|
sudo sed -i "/devnull:\/dev\/null/d" /etc/aliases
|
||||||
sudo newaliases
|
sudo newaliases
|
||||||
|
#efface le nouvel virtual alias
|
||||||
sudo sed -i "/virtual_alias_maps = hash:\/var\/www\/emailpoubelle\/var\/virtual/d" $postfix
|
sudo sed -i "/virtual_alias_maps = hash:\/var\/www\/emailpoubelle\/var\/virtual/d" $postfix
|
||||||
sudo sed -i "s/^#virtual_alias_maps/virtual_alias_maps/g" $postfix
|
#reactive le nouveau
|
||||||
|
ynh_replace_string "^#virtual_alias_maps" "virtual_alias_maps" $postfix
|
||||||
|
|
||||||
#remove cronjob
|
#remove cronjob
|
||||||
sudo rm -f /etc/cron.d/emailpoubelle
|
sudo rm -f /etc/cron.d/emailpoubelle
|
||||||
sudo service postfix reload
|
sudo service postfix reload
|
||||||
|
|
103
scripts/restore
Normal file
103
scripts/restore
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC START
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
if [ ! -e _common.sh ]; then
|
||||||
|
# Get the _common.sh file if it's not in the current directory
|
||||||
|
cp ../settings/scripts/_common.sh ./_common.sh
|
||||||
|
chmod a+rx _common.sh
|
||||||
|
fi
|
||||||
|
source _common.sh
|
||||||
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# MANAGE SCRIPT FAILURE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Exit if an error occurs during the execution of the script
|
||||||
|
ynh_abort_if_errors
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# LOAD SETTINGS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
|
domain=$(ynh_app_setting_get $app domain)
|
||||||
|
path_url=$(ynh_app_setting_get $app path)
|
||||||
|
final_path=$(ynh_app_setting_get $app final_path)
|
||||||
|
db_name=$(ynh_app_setting_get $app db_name)
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# CHECK IF THE APP CAN BE RESTORED
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_webpath_available $domain $path_url \
|
||||||
|
|| ynh_die "Path not available: ${domain}${path_url}"
|
||||||
|
test ! -d $final_path \
|
||||||
|
|| ynh_die "There is already a directory: $final_path "
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# STANDARD RESTORATION STEPS
|
||||||
|
#=================================================
|
||||||
|
# RESTORE THE NGINX CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RESTORE THE APP MAIN DIR
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_restore_file "$final_path"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RESTORE THE MYSQL DATABASE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
|
||||||
|
ynh_mysql_setup_db $db_name $db_name $db_pwd
|
||||||
|
ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SPECIFIC RESTORATION
|
||||||
|
#=================================================
|
||||||
|
# REINSTALL DEPENDENCIES
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Define and install dependencies
|
||||||
|
ynh_install_app_dependencies $pkg_dependencies
|
||||||
|
#Check & regen local
|
||||||
|
for i in $lang ; do
|
||||||
|
ynh_replace_string "# $i" "$i" /etc/locale.gen
|
||||||
|
done
|
||||||
|
locale-gen
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RESTORE POSTFIX ALIASES
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_restore_file $postfix
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RESTORE THE CRON FILE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_restore_file "/etc/cron.d/$app"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# GENERIC FINALIZATION
|
||||||
|
#=================================================
|
||||||
|
# RELOAD NGINX & ALIASES
|
||||||
|
#=================================================
|
||||||
|
sudo newaliases
|
||||||
|
systemctl reload nginx
|
||||||
|
systemctl restart php7.0-fpm
|
||||||
|
systemctl reload postfix
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,15 @@ if [[ $?==0 ]]; then
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
#mysqlpwd setting was implemented in ynh2 - check if saved and if not implement
|
||||||
|
db_pass=$(ynh_app_setting_get $app mysqlpwd)
|
||||||
|
if [ -z $db_pass]; then
|
||||||
|
#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)
|
||||||
|
db_pass=${t:26:24}
|
||||||
|
ynh_app_setting_set $app mysqlpwd $db_pass
|
||||||
|
fi
|
||||||
|
|
||||||
# Copy source files
|
# Copy source files
|
||||||
cp -a ../src/bin/. $final_path/bin
|
cp -a ../src/bin/. $final_path/bin
|
||||||
cp -a ../src/lib/. $final_path/lib
|
cp -a ../src/lib/. $final_path/lib
|
||||||
|
@ -89,7 +98,7 @@ chown -R www-data:www-data $final_path
|
||||||
#sudo chmod 644 /etc/cron.d/emailpoubelle
|
#sudo chmod 644 /etc/cron.d/emailpoubelle
|
||||||
|
|
||||||
# Restart services
|
# Restart services
|
||||||
sudo service php7.0-fpm restart
|
systemctl restart php7.0-fpm
|
||||||
sudo service nginx reload
|
systemctl reload nginx
|
||||||
sudo service postfix reload
|
systemctl reload postfix
|
||||||
sudo yunohost app ssowatconf
|
sudo yunohost app ssowatconf
|
||||||
|
|
Loading…
Reference in a new issue