mirror of
https://github.com/YunoHost-Apps/abantecart_ynh.git
synced 2024-09-03 18:06:16 +02:00
Merge pull request #9 from polytan02/master
Upgrade, backup, restore, cleaning
This commit is contained in:
commit
2e3ddd915c
7 changed files with 227 additions and 25 deletions
|
@ -51,7 +51,7 @@
|
|||
"default": "Yes"
|
||||
},
|
||||
{
|
||||
"name": "user",
|
||||
"name": "admin_name",
|
||||
"type": "user",
|
||||
"ask": {
|
||||
"en": "Choose the Abantecart administrator (must be an existing YunoHost user)",
|
||||
|
@ -60,7 +60,7 @@
|
|||
"example": "homer"
|
||||
},
|
||||
{
|
||||
"name": "passwd",
|
||||
"name": "admin_pass",
|
||||
"type": "password",
|
||||
"ask": {
|
||||
"en": "Set the password for the Admin user ≥ 5 character",
|
||||
|
@ -69,7 +69,7 @@
|
|||
"example": "myreallystrengthpassword"
|
||||
},
|
||||
{
|
||||
"name": "email",
|
||||
"name": "admin_email",
|
||||
"type": "email",
|
||||
"ask": {
|
||||
"fr": "Votre adresse mail."
|
||||
|
|
32
scripts/backup
Normal file
32
scripts/backup
Normal file
|
@ -0,0 +1,32 @@
|
|||
#!/bin/bash
|
||||
set -eu
|
||||
|
||||
# Source app helpers
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
# Récupère les infos de l'application.
|
||||
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)
|
||||
|
||||
# The parameter $1 is the backup directory location
|
||||
# which will be compressed afterward
|
||||
|
||||
# Backup sources & data
|
||||
ynh_backup "$final_path" "sources"
|
||||
|
||||
# Copy Nginx and YunoHost parameters to make the script "standalone"
|
||||
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "nginx.conf"
|
||||
|
||||
ynh_backup "/etc/yunohost/apps/$app/" "yunohost"
|
||||
|
||||
# Copy dedicated php-fpm process to backup folder
|
||||
ynh_backup "/etc/php5/fpm/pool.d/$app.conf" "php-fpm.conf"
|
||||
|
||||
# Backup db
|
||||
root_pwd=$(sudo cat /etc/yunohost/mysql)
|
||||
sudo mysqldump -u root -p$root_pwd --no-create-db $db_user --result-file="db.sql"
|
||||
ynh_backup "db.sql" "backupdb.sql"
|
||||
|
|
@ -12,9 +12,9 @@ app=$YNH_APP_INSTANCE_NAME
|
|||
domain=$YNH_APP_ARG_DOMAIN
|
||||
path=$YNH_APP_ARG_PATH
|
||||
is_public=$YNH_APP_ARG_IS_PUBLIC
|
||||
user=$YNH_APP_ARG_USER
|
||||
passwd=$YNH_APP_ARG_PASSWD
|
||||
email=$YNH_APP_ARG_EMAIL
|
||||
admin_name=$YNH_APP_ARG_ADMIN_NAME
|
||||
admin_pass=$YNH_APP_ARG_ADMIN_PASS
|
||||
admin_email=$YNH_APP_ARG_ADMIN_EMAIL
|
||||
|
||||
# Vérifie que les variables ne sont pas vides.
|
||||
CHECK_VAR "$app" "app name not set"
|
||||
|
@ -39,19 +39,18 @@ ynh_package_install_from_equivs ../conf/abantecart-deps.control \
|
|||
# Save app settings
|
||||
user="$app"
|
||||
ynh_app_setting_set "$app" is_public "$is_public"
|
||||
ynh_app_setting_set "$app" password "$passwd"
|
||||
ynh_app_setting_set "$app" user "$user"
|
||||
ynh_app_setting_set "$app" admin_pass "$admin_pass"
|
||||
ynh_app_setting_set "$app" admin_name "$admin_name"
|
||||
ynh_app_setting_set "$app" admin_email "$admin_email"
|
||||
|
||||
# Initialize database as needed
|
||||
|
||||
dbname=$app
|
||||
dbuser=$app
|
||||
dbpass=$(ynh_string_random)
|
||||
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
||||
|
||||
# Store the database access
|
||||
echo -e "# MySQL Database"
|
||||
|
||||
db_name=$app
|
||||
db_user=$app
|
||||
db_pass=$(ynh_string_random)
|
||||
ynh_mysql_create_db "$db_name" "$db_user" "$db_pass"
|
||||
ynh_app_setting_set "$app" db_name "$db_name"
|
||||
ynh_app_setting_set "$app" db_pass "$db_pass"
|
||||
|
||||
# Remove trailing "/" for next commands
|
||||
if [[ ! "$path" == "/" ]]; then
|
||||
|
@ -60,6 +59,7 @@ fi
|
|||
|
||||
# Copy files to the right place
|
||||
final_path=/var/www/$app
|
||||
ynh_app_setting_set "$app" final_path "$final_path"
|
||||
|
||||
# We download the sources and check the md5sum
|
||||
SFILE=`sudo cat ../sources/source_file`;
|
||||
|
@ -88,7 +88,8 @@ sudo php cli_install.php install \
|
|||
--db_prefix=_ac_ \
|
||||
--admin_path=admin
|
||||
popd
|
||||
|
||||
|
||||
sudo rm -rf /var/www/$app/install/
|
||||
|
||||
# file owned by www-data before checking permissions
|
||||
sudo chown www-data:www-data $final_path -R
|
||||
|
@ -119,8 +120,6 @@ then
|
|||
ynh_app_setting_set "$app" unprotected_uris "/"
|
||||
fi
|
||||
|
||||
sudo rm -rf /var/www/$app/install/
|
||||
|
||||
sudo service php5-fpm reload
|
||||
sudo service nginx reload
|
||||
sudo yunohost app ssowatconf
|
||||
|
|
|
@ -1,17 +1,73 @@
|
|||
#!/bin/bash
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
set -u
|
||||
|
||||
# Source app helpers
|
||||
source /usr/share/yunohost/helpers
|
||||
source .fonctions
|
||||
|
||||
domain=$(ynh_app_setting_get $app domain)
|
||||
REMOVE_NGINX_CONF () { # Suppression de la configuration nginx
|
||||
if [ -e "/etc/nginx/conf.d/$domain.d/$app.conf" ]; then # Delete nginx config
|
||||
echo "Delete nginx config"
|
||||
sudo rm "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
fi
|
||||
}
|
||||
|
||||
ynh_mysql_drop_db $app
|
||||
REMOVE_FPM_CONF () { # Suppression de la configuration du pool php-fpm
|
||||
if [ -e "/etc/php5/fpm/pool.d/$app.conf" ]; then # Delete fpm config
|
||||
echo "Delete fpm config"
|
||||
sudo rm "/etc/php5/fpm/pool.d/$app.conf"
|
||||
fi
|
||||
}
|
||||
|
||||
SECURE_REMOVE () { # Suppression de dossier avec vérification des variables
|
||||
chaine="$1" # L'argument doit être donné entre quotes simple '', pour éviter d'interpréter les variables.
|
||||
no_var=0
|
||||
while (echo "$chaine" | grep -q '\$') # Boucle tant qu'il y a des $ dans la chaine
|
||||
do
|
||||
no_var=1
|
||||
global_var=$(echo "$chaine" | cut -d '$' -f 2) # Isole la première variable trouvée.
|
||||
only_var=\$$(expr "$global_var" : '\([A-Za-z0-9_]*\)') # Isole complètement la variable en ajoutant le $ au début et en gardant uniquement le nom de la variable. Se débarrasse$
|
||||
real_var=$(eval "echo ${only_var}") # `eval "echo ${var}` permet d'interpréter une variable contenue dans une variable.
|
||||
if test -z "$real_var" || [ "$real_var" = "/" ]; then
|
||||
echo "Variable $only_var is empty, suppression of $chaine cancelled." >&2
|
||||
return 1
|
||||
fi
|
||||
chaine=$(echo "$chaine" | sed "s@$only_var@$real_var@") # remplace la variable par sa valeur dans la chaine.
|
||||
done
|
||||
if [ "$no_var" -eq 1 ]
|
||||
then
|
||||
if [ -e "$chaine" ]; then
|
||||
echo "Delete directory $chaine"
|
||||
sudo rm -r "$chaine"
|
||||
fi
|
||||
return 0
|
||||
else
|
||||
echo "No detected variable." >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
REMOVE_BDD () { # Suppression de la base de donnée et de l'utilisateur associé.
|
||||
# $1 = Nom de la base de donnée
|
||||
# Utilise '$app' comme nom d'utilisateur et de base de donnée
|
||||
db_user=$1
|
||||
if mysqlshow -u root -p$(sudo cat $MYSQL_ROOT_PWD_FILE) | grep -q "^| $db_user"; then
|
||||
echo "Delete db"
|
||||
ynh_mysql_drop_db $db_user
|
||||
ynh_mysql_drop_user $db_user
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# We retrieve app parameters
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
db_name=$(ynh_app_setting_get "$app" db_name)
|
||||
|
||||
REMOVE_BDD "$db_name"
|
||||
|
||||
# Remove installed files
|
||||
SECURE_REMOVE '/var/www/${app}'
|
||||
SECURE_REMOVE '/var/www/$app'
|
||||
REMOVE_NGINX_CONF
|
||||
REMOVE_FPM_CONF
|
||||
|
||||
|
@ -23,3 +79,4 @@ fi
|
|||
|
||||
|
||||
sudo service nginx reload
|
||||
sudo service php5-fpm reload
|
||||
|
|
47
scripts/restore
Normal file
47
scripts/restore
Normal file
|
@ -0,0 +1,47 @@
|
|||
#!/bin/bash
|
||||
set -eu
|
||||
|
||||
# Source app helpers
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
# Récupère les infos de l'application.
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
domain=$(ynh_app_setting_get $app domain)
|
||||
path=$(ynh_app_setting_get $app path)
|
||||
final_path=$(ynh_app_setting_get $app final_path)
|
||||
db_name=$(ynh_app_setting_get $app db_name)
|
||||
db_pass=$(ynh_app_setting_get $app db_pass)
|
||||
|
||||
if [ -d $final_path ]; then
|
||||
echo "There is already a directory: $final_path " >&2
|
||||
ynh_die
|
||||
fi
|
||||
|
||||
# Restore Nginx
|
||||
conf=/etc/nginx/conf.d/$domain.d/$app.conf
|
||||
if [ -f $conf ]; then
|
||||
echo "There is already a nginx conf file at this path: $conf " >&2
|
||||
ynh_die
|
||||
fi
|
||||
sudo cp -a ./nginx.conf $conf
|
||||
|
||||
# Restore YunoHost parameters
|
||||
sudo cp -a ./yunohost/. /etc/yunohost/apps/$app/
|
||||
|
||||
# Restore sources & data
|
||||
sudo mkdir -p $final_path
|
||||
sudo cp -a ./sources/. $final_path/
|
||||
|
||||
ynh_mysql_create_db $db_name $db_name $db_pass
|
||||
mysql --debug-check -u $db_user -p$db_pwd $db_user < ./backupdb.sql
|
||||
|
||||
# Copy dedicated php-fpm process from backup folder to the right location
|
||||
sudo cp -a ./php-fpm.conf /etc/php5/fpm/pool.d/$app.conf
|
||||
|
||||
# And Reload services
|
||||
sudo service php5-fpm reload
|
||||
sudo service nginx reload
|
||||
|
||||
sudo yunohost app ssowatconf
|
||||
|
68
scripts/upgrade
Normal file
68
scripts/upgrade
Normal file
|
@ -0,0 +1,68 @@
|
|||
#!/bin/bash
|
||||
set -eu
|
||||
|
||||
source .fonctions # Charge les fonctions génériques habituellement utilisées dans le script
|
||||
|
||||
# Récupère les infos de l'application.
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
# Source app helpers
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
domain=$(ynh_app_setting_get $app domain)
|
||||
path=$(ynh_app_setting_get $app path)
|
||||
final_path=$(ynh_app_setting_get $app final_path)
|
||||
admin_name=$(ynh_app_setting_get $app admin_name)
|
||||
admin_pass=$(ynh_app_setting_get $app admin_pass)
|
||||
admin_email=$(ynh_app_setting_get $app admin_email)
|
||||
db_pass=$(ynh_app_setting_get $app mysqlpwd)
|
||||
db_user=$(ynh_app_setting_get $app db_user)
|
||||
|
||||
CHECK_PATH # Vérifie et corrige la syntaxe du path.
|
||||
|
||||
# Remove trailing "/" for next commands
|
||||
if [[ ! "$path" == "/" ]]; then
|
||||
path=${path%/}
|
||||
fi
|
||||
|
||||
# We download the sources and check the md5sum
|
||||
SFILE=`sudo cat ../sources/source_file`;
|
||||
sudo wget -nv -i ../sources/source_url -O ${SFILE}.tar.gz
|
||||
sudo md5sum -c ../sources/source_md5 --status || (echo "Corrupt source" >&2 && false)
|
||||
sudo tar xvf ${SFILE}.tar.gz -C ../sources/
|
||||
sudo cp -a ../sources/abantecart-src-master/. $final_path
|
||||
|
||||
sudo rm -rf $final_path/tests
|
||||
sudo rm -rf $final_path/install.txt
|
||||
sudo mv $final_path/public_html/* $final_path/
|
||||
sudo rm -rf $final_path/public_html
|
||||
|
||||
# file owned by www-data before checking permissions
|
||||
sudo chown www-data:www-data $final_path -R
|
||||
|
||||
# set database configuration
|
||||
sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf
|
||||
|
||||
# Modify Nginx configuration file and copy it to Nginx conf directory
|
||||
sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf
|
||||
sed -i "s@YNH_WWW_ALIAS@$final_path/@g" ../conf/nginx.conf
|
||||
sudo sed -i "s@NAMETOCHANGE@$app@g" ../conf/nginx.conf
|
||||
nginxconf=/etc/nginx/conf.d/$domain.d/$app.conf
|
||||
sudo cp ../conf/nginx.conf $nginxconf
|
||||
sudo chown root: $nginxconf
|
||||
sudo chmod 644 $nginxconf
|
||||
|
||||
sudo sed -i "s@NAMETOCHANGE@$app@g" ../conf/php-fpm.conf
|
||||
sudo sed -i "s@FOLDERTOCHANGE@$final_path@g" ../conf/php-fpm.conf
|
||||
finalphpconf=/etc/php5/fpm/pool.d/$app.conf
|
||||
|
||||
ynh_app_setting_set "$app" is_public "$is_public"
|
||||
if [ "$is_public" = "Yes" ];
|
||||
then
|
||||
ynh_app_setting_set "$app" unprotected_uris "/"
|
||||
fi
|
||||
|
||||
sudo service php5-fpm reload
|
||||
sudo service nginx reload
|
||||
sudo yunohost app ssowatconf
|
||||
|
|
@ -1 +0,0 @@
|
|||
https://github.com/abantecart/abantecart-src/releases/download/1.2.9/abantecart_1.2.9_upgrade_only.tar.gz
|
Loading…
Add table
Reference in a new issue