mirror of
https://github.com/YunoHost-Apps/abantecart_ynh.git
synced 2024-09-03 18:06:16 +02:00
Refactoring (#16)
This commit is contained in:
parent
4387d8a911
commit
c91449fb89
14 changed files with 483 additions and 634 deletions
|
@ -1,8 +1,12 @@
|
|||
# abantecart_ynh
|
||||
Plateforme pour la création de site Ecommerce / Business solution provider
|
||||
|
||||
FONCTIONNE / WORK <br>
|
||||
N'UTILSER QUE POUR TEST OU DEVELOPPEMENT !! / USE ONLY FOR TEST OR DEVELOPPMENT !!
|
||||
## FONCTIONNE / WORK <br>
|
||||
#### N'UTILSER QUE POUR TEST OU DEVELOPPEMENT !! / USE ONLY FOR TEST OR DEVELOPPMENT !!
|
||||
<br>
|
||||
<br>
|
||||
## Upgrade this package:
|
||||
`sudo yunohost app upgrade --verbose abantecart -u https://github.com/YunoHost-Apps/abantecart_ynh`
|
||||
<br>
|
||||
<br>
|
||||
level/niveau=2 (Installation et supression)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
; Manifest
|
||||
domain="domain.tld" (DOMAIN)
|
||||
path="/path" (PATH)
|
||||
is_public="Yes" (PUBLIC|public=Yes|private=No)
|
||||
is_public=1 (PUBLIC|public=1|private=0)
|
||||
admin_name="john" (USER)
|
||||
admin_pass="08jtiig45f88r7" (PASSWORD)
|
||||
admin_email="abc@example.com"
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
Section: misc
|
||||
Priority: optional
|
||||
Homepage: http://www.abantecart.com/
|
||||
Standards-Version: 1.2.9
|
||||
|
||||
Package: abantecart-deps
|
||||
Version: 1.2-1
|
||||
Depends: php5-mysql
|
||||
Architecture: all
|
||||
Description: meta package for abantecart dependencies
|
||||
The Most Powerful eCommerce Platform to Sell anything.
|
||||
.
|
||||
.
|
||||
This meta-package is only responsible of installing its dependencies.
|
|
@ -1,2 +1,6 @@
|
|||
SOURCE_URL=https://github.com/abantecart/abantecart-src/archive/1.2.12.tar.gz
|
||||
SOURCE_SUM=928345728f9921ca945aa2b9e96c11ef
|
||||
SOURCE_SUM=3cff18d75dbd62aedbdd60771e452418599eb00f055581f8ff5dc6bde8b9f93f
|
||||
SOURCE_SUM_PRG=sha256sum
|
||||
SOURCE_FORMAT=tar.gz
|
||||
SOURCE_IN_SUBDIR=true
|
||||
SOURCE_FILENAME=
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
location YNH_WWW_PATH {
|
||||
alias YNH_WWW_ALIAS ;
|
||||
location __PATH__ {
|
||||
alias __FINALPATH__/ ;
|
||||
if ($scheme = http) {
|
||||
rewrite ^ https://$server_name$request_uri? permanent;
|
||||
}
|
||||
|
@ -7,11 +7,11 @@ location YNH_WWW_PATH {
|
|||
try_files $uri $uri/ index.php;
|
||||
location ~ [^/]\.php(/|$) {
|
||||
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
|
||||
fastcgi_pass unix:/var/run/php5-fpm-NAMETOCHANGE.sock;
|
||||
fastcgi_pass unix:/var/run/php5-fpm-__NAME__.sock;
|
||||
fastcgi_index index.php;
|
||||
include fastcgi_params;
|
||||
fastcgi_param REMOTE_USER $remote_user;
|
||||
fastcgi_param PATH_INFO $fastcgi_path_info;
|
||||
fastcgi_param REMOTE_USER $remote_user;
|
||||
fastcgi_param PATH_INFO $fastcgi_path_info;
|
||||
fastcgi_param SCRIPT_FILENAME $request_filename;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,23 +2,25 @@
|
|||
"name": "Abantecart",
|
||||
"id": "abantecart",
|
||||
"packaging_format": 1,
|
||||
"requirements": {
|
||||
"yunohost": ">> 2.3.15"
|
||||
},
|
||||
"description": {
|
||||
"en": "Create a E-commerce Website",
|
||||
"fr": "Créer un site ecommerce"
|
||||
},
|
||||
"version": "1.2.12",
|
||||
"license": "free",
|
||||
"url": "abantecart.com",
|
||||
"maintainer": {
|
||||
"name": "frju365",
|
||||
"email": "win10@tutanota.com"
|
||||
},
|
||||
"requirements": {
|
||||
"yunohost": ">= 2.7.2"
|
||||
},
|
||||
"multi_instance": true,
|
||||
"services": [
|
||||
"nginx",
|
||||
"php5-fpm"
|
||||
"php5-fpm",
|
||||
"mysql"
|
||||
],
|
||||
"arguments": {
|
||||
"install" : [
|
||||
|
@ -43,12 +45,12 @@
|
|||
},
|
||||
{
|
||||
"name": "is_public",
|
||||
"type": "boolean",
|
||||
"ask": {
|
||||
"en": "Is it a public Abantecart site ?",
|
||||
"fr": "Est-ce un site public ?"
|
||||
"en": "Is it a public application?",
|
||||
"fr": "Est-ce une application publique ?"
|
||||
},
|
||||
"choices": ["Yes", "No"],
|
||||
"default": "Yes"
|
||||
"default": true
|
||||
},
|
||||
{
|
||||
"name": "admin_name",
|
||||
|
|
|
@ -1,428 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
#=================================================
|
||||
# CHECKING
|
||||
#=================================================
|
||||
|
||||
CHECK_USER () { # Vérifie la validité de l'user admin
|
||||
# $1 = Variable de l'user admin.
|
||||
ynh_user_exists "$1" || ynh_die "Wrong user"
|
||||
}
|
||||
|
||||
CHECK_DOMAINPATH () { # Vérifie la disponibilité du path et du domaine.
|
||||
sudo yunohost app checkurl $domain$path_url -a $app
|
||||
}
|
||||
|
||||
CHECK_FINALPATH () { # Vérifie que le dossier de destination n'est pas déjà utilisé.
|
||||
final_path=/var/www/$app
|
||||
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
||||
}
|
||||
|
||||
#=================================================
|
||||
# DISPLAYING
|
||||
#=================================================
|
||||
|
||||
NO_PRINT () { # Supprime l'affichage dans stdout pour la commande en argument.
|
||||
set +x
|
||||
eval "$@"
|
||||
set -x
|
||||
}
|
||||
|
||||
WARNING () { # Écrit sur le canal d'erreur pour passer en warning.
|
||||
eval "$@" >&2
|
||||
}
|
||||
|
||||
SUPPRESS_WARNING () { # Force l'écriture sur la sortie standard
|
||||
eval "$@" 2>&1
|
||||
}
|
||||
|
||||
QUIET () { # Redirige la sortie standard dans /dev/null
|
||||
eval "$@" > /dev/null
|
||||
}
|
||||
|
||||
ALL_QUIET () { # Redirige la sortie standard et d'erreur dans /dev/null
|
||||
eval "$@" > /dev/null 2>&1
|
||||
}
|
||||
|
||||
#=================================================
|
||||
# SETUP
|
||||
#=================================================
|
||||
|
||||
SETUP_SOURCE () { # Télécharge la source, décompresse et copie dans $final_path
|
||||
src_url=$(cat ../conf/app.src | grep SOURCE_URL | cut -d= -f2)
|
||||
src_checksum=$(cat ../conf/app.src | grep SOURCE_SUM | cut -d= -f2)
|
||||
# Download sources from the upstream
|
||||
wget -nv -O source.tar.gz $src_url
|
||||
# Vérifie la somme de contrôle de la source téléchargée.
|
||||
echo "$src_checksum source.tar.gz" | md5sum -c --status || ynh_die "Corrupt source"
|
||||
# Extract source into the app dir
|
||||
sudo mkdir -p $final_path
|
||||
sudo tar -x -f source.tar.gz -C $final_path --strip-components 1
|
||||
}
|
||||
|
||||
POOL_FPM () { # Créer le fichier de configuration du pool php-fpm et le configure.
|
||||
sed -i "s@__NAMETOCHANGE__@$app@g" ../conf/php-fpm.conf
|
||||
sed -i "s@__FINALPATH__@$final_path@g" ../conf/php-fpm.conf
|
||||
sed -i "s@__USER__@$app@g" ../conf/php-fpm.conf
|
||||
finalphpconf=/etc/php5/fpm/pool.d/$app.conf
|
||||
sudo cp ../conf/php-fpm.conf $finalphpconf
|
||||
sudo chown root: $finalphpconf
|
||||
finalphpini=/etc/php5/fpm/conf.d/20-$app.ini
|
||||
sudo cp ../conf/php-fpm.ini $finalphpini
|
||||
sudo chown root: $finalphpini
|
||||
sudo service php5-fpm reload
|
||||
}
|
||||
|
||||
YNH_CURL () {
|
||||
data_post=$1
|
||||
url_access=$2
|
||||
sleep 1
|
||||
SUPPRESS_WARNING curl -kL -H \"Host: $domain\" --resolve $domain:443:127.0.0.1 --data \"$data_post\" \"https://localhost$path_url$url_access\"
|
||||
}
|
||||
|
||||
#=================================================
|
||||
# REMOVE
|
||||
#=================================================
|
||||
|
||||
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"
|
||||
sudo service nginx reload
|
||||
fi
|
||||
}
|
||||
|
||||
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
|
||||
if [ -e "/etc/php5/fpm/conf.d/20-$app.ini" ]; then # Delete php config
|
||||
echo "Delete php config"
|
||||
sudo rm "/etc/php5/fpm/conf.d/20-$app.ini"
|
||||
fi
|
||||
sudo service php5-fpm reload
|
||||
}
|
||||
|
||||
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 surtout du / et d'un éventuel chemin derrière.
|
||||
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
|
||||
WARNING echo "Variable $only_var is empty, suppression of $chaine cancelled."
|
||||
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
|
||||
WARNING echo "No detected variable."
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
REMOVE_SYS_USER () { # Supprime l'utilisateur système dédié à l'app
|
||||
if ynh_system_user_exists "$app" # Test l'existence de l'utilisateur
|
||||
then
|
||||
sudo userdel $app
|
||||
fi
|
||||
}
|
||||
|
||||
#=================================================
|
||||
# BACKUP
|
||||
#=================================================
|
||||
|
||||
BACKUP_FAIL_UPGRADE () {
|
||||
WARNING echo "Upgrade failed."
|
||||
if ALL_QUIET sudo yunohost backup list | grep -q $app-before-upgrade$backup_number; then # Vérifie l'existence de l'archive avant de supprimer l'application et de restaurer
|
||||
sudo yunohost app remove $app # Supprime l'application avant de la restaurer.
|
||||
sudo yunohost backup restore --ignore-hooks $app-before-upgrade$backup_number --apps $app --force # Restore the backup if upgrade failed
|
||||
ynh_die "The app was restored to the way it was before the failed upgrade."
|
||||
fi
|
||||
}
|
||||
|
||||
BACKUP_BEFORE_UPGRADE () { # Backup the current version of the app, restore it if the upgrade fails
|
||||
backup_number=1
|
||||
old_backup_number=2
|
||||
if ALL_QUIET sudo yunohost backup list | grep -q $app-before-upgrade1; then # Vérifie l'existence d'une archive déjà numéroté à 1.
|
||||
backup_number=2 # Et passe le numéro de l'archive à 2
|
||||
old_backup_number=1
|
||||
fi
|
||||
|
||||
sudo yunohost backup create --ignore-hooks --apps $app --name $app-before-upgrade$backup_number # Créer un backup différent de celui existant.
|
||||
if [ "$?" -eq 0 ]; then # Si le backup est un succès, supprime l'archive précédente.
|
||||
if ALL_QUIET sudo yunohost backup list | grep -q $app-before-upgrade$old_backup_number; then # Vérifie l'existence de l'ancienne archive avant de la supprimer, pour éviter une erreur.
|
||||
QUIET sudo yunohost backup delete $app-before-upgrade$old_backup_number
|
||||
fi
|
||||
else # Si le backup a échoué
|
||||
ynh_die "Backup failed, the upgrade process was aborted."
|
||||
fi
|
||||
}
|
||||
|
||||
#=================================================
|
||||
# CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
STORE_MD5_CONFIG () { # Enregistre la somme de contrôle du fichier de config
|
||||
# $1 = Nom du fichier de conf pour le stockage dans settings.yml
|
||||
# $2 = Nom complet et chemin du fichier de conf.
|
||||
ynh_app_setting_set $app $1_file_md5 $(sudo md5sum "$2" | cut -d' ' -f1)
|
||||
}
|
||||
|
||||
CHECK_MD5_CONFIG () { # Créé un backup du fichier de config si il a été modifié.
|
||||
# $1 = Nom du fichier de conf pour le stockage dans settings.yml
|
||||
# $2 = Nom complet et chemin du fichier de conf.
|
||||
if [ "$(ynh_app_setting_get $app $1_file_md5)" != $(sudo md5sum "$2" | cut -d' ' -f1) ]; then
|
||||
sudo cp -a "$2" "$2.backup.$(date '+%d.%m.%y_%Hh%M,%Ss')" # Si le fichier de config a été modifié, créer un backup.
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
#=================================================
|
||||
#=================================================
|
||||
# FUTUR YNH HELPERS
|
||||
#=================================================
|
||||
# Importer ce fichier de fonction avant celui des helpers officiel
|
||||
# Ainsi, les officiels prendront le pas sur ceux-ci le cas échéant
|
||||
#=================================================
|
||||
|
||||
# Ignore the yunohost-cli log to prevent errors with conditionals commands
|
||||
# usage: ynh_no_log COMMAND
|
||||
# Simply duplicate the log, execute the yunohost command and replace the log without the result of this command
|
||||
# It's a very badly hack...
|
||||
ynh_no_log() {
|
||||
ynh_cli_log=/var/log/yunohost/yunohost-cli.log
|
||||
sudo cp -a ${ynh_cli_log} ${ynh_cli_log}-move
|
||||
eval $@
|
||||
exit_code=$?
|
||||
sudo mv ${ynh_cli_log}-move ${ynh_cli_log}
|
||||
return $?
|
||||
}
|
||||
|
||||
# Normalize the url path syntax
|
||||
# Handle the slash at the beginning of path and its absence at ending
|
||||
# Return a normalized url path
|
||||
#
|
||||
# example: url_path=$(ynh_normalize_url_path $url_path)
|
||||
# ynh_normalize_url_path example -> /example
|
||||
# ynh_normalize_url_path /example -> /example
|
||||
# ynh_normalize_url_path /example/ -> /example
|
||||
#
|
||||
# usage: ynh_normalize_url_path path_to_normalize
|
||||
# | arg: url_path_to_normalize - URL path to normalize before using it
|
||||
ynh_normalize_url_path () {
|
||||
path_url=$1
|
||||
test -n "$path_url" || ynh_die "ynh_normalize_url_path expect a URL path as first argument and received nothing."
|
||||
if [ "${path_url:0:1}" != "/" ]; then # If the first character is not a /
|
||||
path_url="/$path_url" # Add / at begin of path variable
|
||||
fi
|
||||
if [ "${path_url:${#path_url}-1}" == "/" ] && [ ${#path_url} -gt 1 ]; then # If the last character is a / and that not the only character.
|
||||
path_url="${path_url:0:${#path_url}-1}" # Delete the last character
|
||||
fi
|
||||
echo $path_url
|
||||
}
|
||||
|
||||
# Create a database, an user and its password. Then store the password in the app's config
|
||||
#
|
||||
# User of database will be store in db_user's variable.
|
||||
# Name of database will be store in db_name's variable.
|
||||
# And password in db_pwd's variable.
|
||||
#
|
||||
# usage: ynh_mysql_generate_db user name
|
||||
# | arg: user - Owner of the database
|
||||
# | arg: name - Name of the database
|
||||
ynh_mysql_generate_db () {
|
||||
db_pwd=$(ynh_string_random) # Generate a random password
|
||||
ynh_mysql_create_db "$2" "$1" "$db_pwd" # Create the database
|
||||
ynh_app_setting_set $app mysqlpwd $db_pwd # Store the password in the app's config
|
||||
}
|
||||
|
||||
# Remove a database if it exist and the associated user
|
||||
#
|
||||
# usage: ynh_mysql_remove_db user name
|
||||
# | arg: user - Proprietary of the database
|
||||
# | arg: name - Name of the database
|
||||
ynh_mysql_remove_db () {
|
||||
if mysqlshow -u root -p$(sudo cat $MYSQL_ROOT_PWD_FILE) | grep -q "^| $2"; then # Check if the database exist
|
||||
echo "Remove database $2" >&2
|
||||
ynh_mysql_drop_db $2 # Remove the database
|
||||
ynh_mysql_drop_user $1 # Remove the associated user to database
|
||||
else
|
||||
echo "Database $2 not found" >&2
|
||||
fi
|
||||
}
|
||||
|
||||
# Correct the name given in argument for mariadb
|
||||
#
|
||||
# Avoid invalid name for your database
|
||||
#
|
||||
# Exemple: dbname=$(ynh_make_valid_dbid $app)
|
||||
#
|
||||
# usage: ynh_make_valid_dbid name
|
||||
# | arg: name - name to correct
|
||||
# | ret: the corrected name
|
||||
ynh_make_valid_dbid () {
|
||||
dbid=${1//[-.]/_} # Mariadb doesn't support - and . in the name of databases. It will be replace by _
|
||||
echo $dbid
|
||||
}
|
||||
|
||||
# Manage a fail of the script
|
||||
#
|
||||
# Print a warning to inform that the script was failed
|
||||
# Execute the ynh_clean_setup function if used in the app script
|
||||
#
|
||||
# usage of ynh_clean_setup function
|
||||
# This function provide a way to clean some residual of installation that not managed by remove script.
|
||||
# To use it, simply add in your script:
|
||||
# ynh_clean_setup () {
|
||||
# instructions...
|
||||
# }
|
||||
# This function is optionnal.
|
||||
#
|
||||
# Usage: ynh_exit_properly is used only by the helper ynh_check_error.
|
||||
# You must not use it directly.
|
||||
ynh_exit_properly () {
|
||||
exit_code=$?
|
||||
if [ "$exit_code" -eq 0 ]; then
|
||||
exit 0 # Exit without error if the script ended correctly
|
||||
fi
|
||||
|
||||
trap '' EXIT # Ignore new exit signals
|
||||
set +eu # Do not exit anymore if a command fail or if a variable is empty
|
||||
|
||||
echo -e "!!\n $app's script has encountered an error. Its execution was cancelled.\n!!" >&2
|
||||
|
||||
if type -t ynh_clean_setup > /dev/null; then # Check if the function exist in the app script.
|
||||
ynh_clean_setup # Call the function to do specific cleaning for the app.
|
||||
fi
|
||||
|
||||
ynh_die # Exit with error status
|
||||
}
|
||||
|
||||
# Exit if an error occurs during the execution of the script.
|
||||
#
|
||||
# Stop immediatly the execution if an error occured or if a empty variable is used.
|
||||
# The execution of the script is derivate to ynh_exit_properly function before exit.
|
||||
#
|
||||
# Usage: ynh_check_error
|
||||
ynh_check_error () {
|
||||
set -eu # Exit if a command fail, and if a variable is used unset.
|
||||
trap ynh_exit_properly EXIT # Capturing exit signals on shell script
|
||||
}
|
||||
|
||||
# Install dependencies with a equivs control file
|
||||
#
|
||||
# usage: ynh_app_dependencies dep [dep [...]]
|
||||
# | arg: dep - the package name to install in dependence
|
||||
ynh_app_dependencies () {
|
||||
dependencies=$@
|
||||
manifest_path="../manifest.json"
|
||||
if [ ! -e "$manifest_path" ]; then
|
||||
manifest_path="../settings/manifest.json" # Into the restore script, the manifest is not at the same place
|
||||
fi
|
||||
version=$(sudo python3 -c "import sys, json;print(json.load(open(\"$manifest_path\"))['version'])") # Retrieve the version number in the manifest file.
|
||||
dep_app=${app//_/-} # Replace all '_' by '-'
|
||||
cat > ./${dep_app}-ynh-deps.control << EOF # Make a control file for equivs-build
|
||||
Section: misc
|
||||
Priority: optional
|
||||
Package: ${dep_app}-ynh-deps
|
||||
Version: ${version}
|
||||
Depends: ${dependencies}
|
||||
Architecture: all
|
||||
Description: Fake package for ${app} (YunoHost app) dependencies
|
||||
This meta-package is only responsible of installing its dependencies.
|
||||
EOF
|
||||
ynh_package_install_from_equivs ./${dep_app}-ynh-deps.control \
|
||||
|| ynh_die "Unable to install dependencies" # Install the fake package and its dependencies
|
||||
}
|
||||
|
||||
# Remove fake package and its dependencies
|
||||
#
|
||||
# Dependencies will removed only if no other package need them.
|
||||
#
|
||||
# usage: ynh_remove_app_dependencies
|
||||
ynh_remove_app_dependencies () {
|
||||
dep_app=${app/_/-} # Replace all '_' by '-'
|
||||
ynh_package_autoremove ${dep_app}-ynh-deps # Remove the fake package and its dependencies if they not still used.
|
||||
}
|
||||
|
||||
# Use logrotate to manage the logfile
|
||||
#
|
||||
# usage: ynh_use_logrotate [logfile]
|
||||
# | arg: logfile - absolute path of logfile
|
||||
#
|
||||
# If no argument provided, a standard directory will be use. /var/log/${app}
|
||||
# You can provide a path with the directory only or with the logfile.
|
||||
# /parentdir/logdir/
|
||||
# /parentdir/logdir/logfile.log
|
||||
#
|
||||
# It's possible to use this helper several times, each config will added to same logrotate config file.
|
||||
ynh_use_logrotate () {
|
||||
if [ -n "$1" ]; then
|
||||
if [ "$(echo ${1##*.})" == "log" ]; then # Keep only the extension to check if it's a logfile
|
||||
logfile=$1 # In this case, focus logrotate on the logfile
|
||||
else
|
||||
logfile=$1/.log # Else, uses the directory and all logfile into it.
|
||||
fi
|
||||
else
|
||||
logfile="/var/log/${app}/.log" # Without argument, use a defaut directory in /var/log
|
||||
fi
|
||||
cat > ./${app}-logrotate << EOF # Build a config file for logrotate
|
||||
$logfile {
|
||||
# Rotate if the logfile exceeds 100Mo
|
||||
size 100M
|
||||
# Keep 12 old log maximum
|
||||
rotate 12
|
||||
# Compress the logs with gzip
|
||||
compress
|
||||
# Compress the log at the next cycle. So keep always 2 non compressed logs
|
||||
delaycompress
|
||||
# Copy and truncate the log to allow to continue write on it. Instead of move the log.
|
||||
copytruncate
|
||||
# Do not do an error if the log is missing
|
||||
missingok
|
||||
# Not rotate if the log is empty
|
||||
notifempty
|
||||
# Keep old logs in the same dir
|
||||
noolddir
|
||||
}
|
||||
EOF
|
||||
sudo mkdir -p $(dirname "$logfile") # Create the log directory, if not exist
|
||||
cat ${app}-logrotate | sudo tee -a /etc/logrotate.d/$app > /dev/null # Append this config to the others for this app. If a config file already exist
|
||||
}
|
||||
|
||||
# Remove the app's logrotate config.
|
||||
#
|
||||
# usage: ynh_remove_logrotate
|
||||
ynh_remove_logrotate () {
|
||||
if [ -e "/etc/logrotate.d/$app" ]; then
|
||||
sudo rm "/etc/logrotate.d/$app"
|
||||
fi
|
||||
}
|
||||
|
||||
# Find a free port and return it
|
||||
#
|
||||
# example: port=$(ynh_find_port 8080)
|
||||
#
|
||||
# usage: ynh_find_port begin_port
|
||||
# | arg: begin_port - port to start to search
|
||||
ynh_find_port () {
|
||||
port=$1
|
||||
test -n "$port" || ynh_die "The argument of ynh_find_port must be a valid port."
|
||||
while netcat -z 127.0.0.1 $port # Check if the port is free
|
||||
do
|
||||
port=$((port+1)) # Else, pass to next port
|
||||
done
|
||||
echo $port
|
||||
}
|
1
scripts/_common.sh
Normal file
1
scripts/_common.sh
Normal file
|
@ -0,0 +1 @@
|
|||
#!/bin/bash
|
|
@ -1,32 +1,68 @@
|
|||
#!/bin/bash
|
||||
set -eu
|
||||
|
||||
# Source app helpers
|
||||
#=================================================
|
||||
# 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
|
||||
|
||||
# Récupère les infos de l'application.
|
||||
#=================================================
|
||||
# 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)
|
||||
|
||||
# The parameter $1 is the backup directory location
|
||||
# which will be compressed afterward
|
||||
#=================================================
|
||||
# STANDARD BACKUP STEPS
|
||||
#=================================================
|
||||
# BACKUP THE APP MAIN DIR
|
||||
#=================================================
|
||||
|
||||
# Backup sources & data
|
||||
ynh_backup "$final_path" "sources"
|
||||
ynh_backup "$final_path"
|
||||
|
||||
# Copy Nginx and YunoHost parameters to make the script "standalone"
|
||||
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "nginx.conf"
|
||||
#=================================================
|
||||
# BACKUP THE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
ynh_backup "/etc/yunohost/apps/$app/" "yunohost"
|
||||
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
||||
# Copy dedicated php-fpm process to backup folder
|
||||
ynh_backup "/etc/php5/fpm/pool.d/$app.conf" "php-fpm.conf"
|
||||
#=================================================
|
||||
# BACKUP THE PHP-FPM CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
# 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"
|
||||
ynh_backup "/etc/php5/fpm/pool.d/$app.conf"
|
||||
ynh_backup "/etc/php5/fpm/conf.d/20-$app.ini"
|
||||
|
||||
#=================================================
|
||||
# BACKUP THE MYSQL DATABASE
|
||||
#=================================================
|
||||
|
||||
ynh_mysql_dump_db "$db_name" > db.sql
|
||||
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC BACKUP
|
||||
#=================================================
|
||||
# BACKUP LOGROTATE
|
||||
#=================================================
|
||||
|
||||
ynh_backup "/etc/logrotate.d/$app"
|
||||
|
|
87
scripts/change_url
Normal file
87
scripts/change_url
Normal file
|
@ -0,0 +1,87 @@
|
|||
#!/bin/bash
|
||||
|
||||
#=================================================
|
||||
# GENERIC STARTING
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
# RETRIEVE ARGUMENTS
|
||||
#=================================================
|
||||
|
||||
old_domain=$YNH_APP_OLD_DOMAIN
|
||||
old_path=$YNH_APP_OLD_PATH
|
||||
|
||||
new_domain=$YNH_APP_NEW_DOMAIN
|
||||
new_path=$YNH_APP_NEW_PATH
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
#=================================================
|
||||
# CHECK THE SYNTAX OF THE PATHS
|
||||
#=================================================
|
||||
|
||||
test -n "$old_path" || old_path="/"
|
||||
test -n "$new_path" || new_path="/"
|
||||
new_path=$(ynh_normalize_url_path $new_path)
|
||||
old_path=$(ynh_normalize_url_path $old_path)
|
||||
|
||||
#=================================================
|
||||
# CHECK WHICH PARTS SHOULD BE CHANGED
|
||||
#=================================================
|
||||
|
||||
change_domain=0
|
||||
if [ "$old_domain" != "$new_domain" ]
|
||||
then
|
||||
change_domain=1
|
||||
fi
|
||||
|
||||
change_path=0
|
||||
if [ "$old_path" != "$new_path" ]
|
||||
then
|
||||
change_path=1
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# STANDARD MODIFICATIONS
|
||||
#=================================================
|
||||
# MODIFY URL IN NGINX CONF
|
||||
#=================================================
|
||||
|
||||
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
|
||||
|
||||
# Change the path in the nginx config file
|
||||
if [ $change_path -eq 1 ]
|
||||
then
|
||||
# Make a backup of the original nginx config file if modified
|
||||
ynh_backup_if_checksum_is_different "$nginx_conf_path"
|
||||
# Replace locations starting with old_path
|
||||
# Look for every location possible patterns (see https://nginx.org/en/docs/http/ngx_http_core_module.html#location)
|
||||
ynh_replace_string "location\( \(=\|~\|~\*\|\^~\)\)\? $old_path" "location\1 $new_path" "$nginx_conf_path"
|
||||
# Replace path in "return" directives
|
||||
ynh_replace_string "return \([[:digit:]]\{3\}\) $old_path" "return \1 $new_path" "$nginx_conf_path"
|
||||
# Calculate and store the nginx config file checksum
|
||||
ynh_store_file_checksum "$nginx_conf_path"
|
||||
fi
|
||||
|
||||
# Change the domain for nginx
|
||||
if [ $change_domain -eq 1 ]
|
||||
then
|
||||
# Delete file checksum for the old conf file location
|
||||
ynh_delete_file_checksum "$nginx_conf_path"
|
||||
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
|
||||
# Store file checksum for the new config file location
|
||||
ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALISATION
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
|
||||
systemctl reload nginx
|
145
scripts/install
145
scripts/install
|
@ -1,20 +1,20 @@
|
|||
#!/bin/bash
|
||||
|
||||
#=================================================
|
||||
# GENERIC STARTING
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
source .fonctions
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
set -eu
|
||||
|
||||
#=================================================
|
||||
# MANAGE FAILURE OF THE SCRIPT
|
||||
# MANAGE SCRIPT FAILURE
|
||||
#=================================================
|
||||
|
||||
ynh_check_error # Active trap pour arrêter le script si une erreur est détectée.
|
||||
# Exit if an error occurs during the execution of the script
|
||||
ynh_abort_if_errors
|
||||
|
||||
#=================================================
|
||||
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
||||
|
@ -30,19 +30,25 @@ admin_pass=$YNH_APP_ARG_ADMIN_PASS
|
|||
admin_email=$YNH_APP_ARG_ADMIN_EMAIL
|
||||
|
||||
#=================================================
|
||||
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
|
||||
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
||||
#=================================================
|
||||
|
||||
CHECK_USER "$admin_name" # Vérifie la validité de l'user admin
|
||||
path_url=$(ynh_normalize_url_path $path_url) # Vérifie et corrige la syntaxe du path.
|
||||
CHECK_DOMAINPATH # Vérifie la disponibilité du path et du domaine.
|
||||
CHECK_FINALPATH # Vérifie que le dossier de destination n'est pas déjà utilisé.
|
||||
final_path=/var/www/$app
|
||||
test ! -e "$final_path" || ynh_die "This path already contains a folder"
|
||||
|
||||
# Normalize the url path syntax
|
||||
path_url=$(ynh_normalize_url_path $path_url)
|
||||
|
||||
# Check web path availability
|
||||
ynh_webpath_available $domain $path_url
|
||||
# Register (book) web path
|
||||
ynh_webpath_register $app $domain $path_url
|
||||
|
||||
#=================================================
|
||||
# Install dependencies using Helpers
|
||||
# INSTALL DEPENDENCIES
|
||||
#=================================================
|
||||
ynh_package_install_from_equivs ../conf/abantecart-deps.control \
|
||||
|| ynh_die "Unable to install dependencies"
|
||||
|
||||
ynh_install_app_dependencies php5-mysql
|
||||
|
||||
#=================================================
|
||||
# Check password strength
|
||||
|
@ -65,21 +71,21 @@ ynh_app_setting_set "$app" admin_email "$admin_email"
|
|||
# Initialize database as needed
|
||||
#=================================================
|
||||
|
||||
db_name=$app
|
||||
db_user=$app
|
||||
db_name=$(ynh_sanitize_dbid $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"
|
||||
ynh_app_setting_set "$app" db_user "$db_user"
|
||||
ynh_app_setting_set $app db_name $db_name
|
||||
ynh_mysql_setup_db $db_name $db_name $db_pass
|
||||
ynh_app_setting_set $app db_pass $db_pass
|
||||
db_user=$db_name
|
||||
ynh_app_setting_set $app db_user $db_user
|
||||
|
||||
#=================================================
|
||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
#=================================================
|
||||
|
||||
final_path=/var/www/$app
|
||||
ynh_app_setting_set $app final_path $final_path
|
||||
SETUP_SOURCE # Télécharge la source, décompresse et copie dans $final_path
|
||||
# Download, check integrity, uncompress and patch the source from app.src
|
||||
ynh_setup_source "$final_path"
|
||||
|
||||
|
||||
#=================================================
|
||||
|
@ -88,82 +94,89 @@ SETUP_SOURCE # Télécharge la source, décompresse et copie dans $final_path
|
|||
# Cleaning
|
||||
#=================================================
|
||||
|
||||
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
|
||||
ynh_secure_remove $final_path/tests
|
||||
ynh_secure_remove $final_path/install.txt
|
||||
mv $final_path/public_html/* $final_path/
|
||||
ynh_secure_remove $final_path/public_html
|
||||
|
||||
#=================================================
|
||||
# CLI installation
|
||||
#=================================================
|
||||
|
||||
pushd $final_path/install/
|
||||
sudo php cli_install.php install \
|
||||
--db_host=localhost \
|
||||
--db_user=$db_user \
|
||||
--db_password=$db_pass \
|
||||
--db_name=$db_name \
|
||||
--db_driver=amysqli \
|
||||
--db_port=3306 \
|
||||
--username=$admin_name \
|
||||
--password=$admin_pass \
|
||||
--email=$admin_email \
|
||||
--http_server=$domain$path_url \
|
||||
--db_prefix=_ac_ \
|
||||
--admin_path=admin
|
||||
php cli_install.php install \
|
||||
--db_host=localhost \
|
||||
--db_user=$db_user \
|
||||
--db_password=$db_pass \
|
||||
--db_name=$db_name \
|
||||
--db_driver=amysqli \
|
||||
--db_port=3306 \
|
||||
--username=$admin_name \
|
||||
--password=$admin_pass \
|
||||
--email=$admin_email \
|
||||
--http_server=$domain$path_url \
|
||||
--db_prefix=_ac_ \
|
||||
--admin_path=admin
|
||||
popd
|
||||
|
||||
#=================================================
|
||||
# Cleaning
|
||||
#=================================================
|
||||
|
||||
sudo rm -rf /var/www/$app/install/
|
||||
ynh_secure_remove /var/www/$app/install/
|
||||
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
# Create a dedicated nginx config
|
||||
ynh_add_nginx_config
|
||||
|
||||
#=================================================
|
||||
# CREATE DEDICATED USER
|
||||
#=================================================
|
||||
|
||||
# Create a system user
|
||||
ynh_system_user_create $app
|
||||
|
||||
#=================================================
|
||||
# PHP-FPM CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
# Create a dedicated php-fpm config
|
||||
ynh_add_fpm_config
|
||||
|
||||
#=================================================
|
||||
# Set permissions
|
||||
#=================================================
|
||||
|
||||
# file owned by www-data before checking permissions
|
||||
sudo chown www-data:www-data $final_path -R
|
||||
chown $app:$app $final_path -R
|
||||
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
# SETUP LOGROTATE
|
||||
#=================================================
|
||||
|
||||
sed -i "s@YNH_WWW_PATH@$path_url@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
|
||||
|
||||
#=================================================
|
||||
# PHP-FPM CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
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
|
||||
sudo cp ../conf/php-fpm.conf $finalphpconf
|
||||
sudo chown root:root $finalphpconf
|
||||
sudo chmod 644 $finalphpconf
|
||||
# Use logrotate to manage application logfile(s)
|
||||
ynh_use_logrotate
|
||||
|
||||
#=================================================
|
||||
# SETUP SSOWAT
|
||||
#=================================================
|
||||
|
||||
# Make app private if necessary
|
||||
ynh_app_setting_set "$app" is_public "$is_public"
|
||||
if [ "$is_public" = "Yes" ];
|
||||
if [ $is_public -eq 0 ]
|
||||
then # Remove the public access
|
||||
ynh_app_setting_delete $app skipped_uris
|
||||
fi
|
||||
# Make app public if necessary
|
||||
if [ $is_public -eq 1 ]
|
||||
then
|
||||
ynh_app_setting_set "$app" unprotected_uris "/"
|
||||
# unprotected_uris allows SSO credentials to be passed anyway.
|
||||
ynh_app_setting_set $app unprotected_uris "/"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
|
||||
sudo service php5-fpm reload
|
||||
sudo service nginx reload
|
||||
sudo yunohost app ssowatconf
|
||||
systemctl reload nginx
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
#!/bin/bash
|
||||
|
||||
#=================================================
|
||||
# GENERIC STARTING
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
source .fonctions
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#=================================================
|
||||
|
@ -17,40 +17,58 @@ app=$YNH_APP_INSTANCE_NAME
|
|||
|
||||
domain=$(ynh_app_setting_get $app domain)
|
||||
db_name=$(ynh_app_setting_get $app db_name)
|
||||
db_user=$db_name
|
||||
final_path=$(ynh_app_setting_get $app final_path)
|
||||
|
||||
#=================================================
|
||||
# STANDARD REMOVE
|
||||
#=================================================
|
||||
# REMOVE THE SQL BDD
|
||||
# REMOVE DEPENDENCIES
|
||||
#=================================================
|
||||
|
||||
ynh_mysql_remove_db $db_name $db_name # Suppression de la base de donnée et de l'utilisateur associé.
|
||||
# Remove metapackage and its dependencies
|
||||
ynh_remove_app_dependencies
|
||||
|
||||
#=================================================
|
||||
# REMOVE THE MAIN DIR OF THE APP
|
||||
# REMOVE THE MYSQL DATABASE
|
||||
#=================================================
|
||||
|
||||
SECURE_REMOVE '/var/www/$app' # Suppression du dossier de l'application
|
||||
# Remove a database if it exists, along with the associated user
|
||||
ynh_mysql_remove_db $db_user $db_name
|
||||
|
||||
#=================================================
|
||||
# REMOVE THE NGINX CONFIGURATION
|
||||
# REMOVE APP MAIN DIR
|
||||
#=================================================
|
||||
|
||||
REMOVE_NGINX_CONF # Suppression de la configuration nginx
|
||||
# Remove the app directory securely
|
||||
ynh_secure_remove "$final_path"
|
||||
|
||||
#=================================================
|
||||
# REMOVE THE PHP-FPM CONFIGURATION
|
||||
# REMOVE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
REMOVE_FPM_CONF # Suppression de la configuration du pool php-fpm
|
||||
# Remove the dedicated nginx config
|
||||
ynh_remove_nginx_config
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC REMOVE
|
||||
#=================================================
|
||||
# Remove app dependencies
|
||||
# REMOVE PHP-FPM CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
if ynh_package_is_installed "abantecart-deps"; then
|
||||
ynh_package_autoremove "abantecart-deps"
|
||||
fi
|
||||
# Remove the dedicated php-fpm config
|
||||
ynh_remove_fpm_config
|
||||
|
||||
#=================================================
|
||||
# REMOVE LOGROTATE CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
# Remove the app-specific logrotate config
|
||||
ynh_remove_logrotate
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# REMOVE DEDICATED USER
|
||||
#=================================================
|
||||
|
||||
# Delete a system user
|
||||
ynh_system_user_delete $app
|
||||
|
|
106
scripts/restore
106
scripts/restore
|
@ -1,47 +1,97 @@
|
|||
#!/bin/bash
|
||||
set -eu
|
||||
|
||||
# Source app helpers
|
||||
#=================================================
|
||||
# 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
|
||||
|
||||
# Récupère les infos de l'application.
|
||||
#=================================================
|
||||
# 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=$(ynh_app_setting_get $app path)
|
||||
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)
|
||||
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
|
||||
#=================================================
|
||||
# CHECK IF THE APP CAN BE RESTORED
|
||||
#=================================================
|
||||
|
||||
# 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
|
||||
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 "
|
||||
|
||||
# Restore YunoHost parameters
|
||||
sudo cp -a ./yunohost/. /etc/yunohost/apps/$app/
|
||||
#=================================================
|
||||
# STANDARD RESTORATION STEPS
|
||||
#=================================================
|
||||
# RESTORE THE NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
# Restore sources & data
|
||||
sudo mkdir -p $final_path
|
||||
sudo cp -a ./sources/. $final_path/
|
||||
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
|
||||
ynh_mysql_create_db $db_name $db_name $db_pass
|
||||
mysql --debug-check -u $db_user -p$db_pwd $db_user < ./backupdb.sql
|
||||
#=================================================
|
||||
# RESTORE THE MYSQL DATABASE
|
||||
#=================================================
|
||||
|
||||
# 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
|
||||
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
|
||||
|
||||
# And Reload services
|
||||
sudo service php5-fpm reload
|
||||
sudo service nginx reload
|
||||
#=================================================
|
||||
# RESTORE USER RIGHTS
|
||||
#=================================================
|
||||
|
||||
sudo yunohost app ssowatconf
|
||||
# Restore permissions on app files
|
||||
chown -R $app:$app $final_path
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE PHP-FPM CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
ynh_restore_file "/etc/php5/fpm/pool.d/$app.conf"
|
||||
ynh_restore_file "/etc/php5/fpm/conf.d/20-$app.ini"
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC RESTORATION
|
||||
#=================================================
|
||||
# REINSTALL DEPENDENCIES
|
||||
#=================================================
|
||||
|
||||
# Define and install dependencies
|
||||
ynh_install_app_dependencies php5-mysql
|
||||
|
||||
#=================================================
|
||||
# RESTORE THE LOGROTATE CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
ynh_restore_file "/etc/logrotate.d/$app"
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# RELOAD NGINX AND PHP-FPM
|
||||
#=================================================
|
||||
|
||||
systemctl reload php5-fpm
|
||||
systemctl reload nginx
|
||||
|
|
174
scripts/upgrade
174
scripts/upgrade
|
@ -1,14 +1,20 @@
|
|||
#!/bin/bash
|
||||
set -eu
|
||||
|
||||
source .fonctions # Charge les fonctions génériques habituellement utilisées dans le script
|
||||
#=================================================
|
||||
# GENERIC START
|
||||
#=================================================
|
||||
# IMPORT GENERIC HELPERS
|
||||
#=================================================
|
||||
|
||||
# Récupère les infos de l'application.
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
# Source app helpers
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
|
||||
#=================================================
|
||||
# LOAD SETTINGS
|
||||
#=================================================
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
domain=$(ynh_app_setting_get $app domain)
|
||||
path_url=$(ynh_app_setting_get $app path_url)
|
||||
final_path=$(ynh_app_setting_get $app final_path)
|
||||
|
@ -18,50 +24,120 @@ 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.
|
||||
#=================================================
|
||||
# ENSURE DOWNWARD COMPATIBILITY
|
||||
#=================================================
|
||||
|
||||
# Remove trailing "/" for next commands
|
||||
|
||||
path_url=$(ynh_normalize_url_path $path_url) # Vérifie et corrige la syntaxe du path.
|
||||
|
||||
# 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_url@g" ../conf/nginx.conf
|
||||
|
||||
# Modify Nginx configuration file and copy it to Nginx conf directory
|
||||
sed -i "s@YNH_WWW_PATH@$path_url@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 "/"
|
||||
# Fix is_public as a boolean value
|
||||
if [ "$is_public" = "Yes" ]; then
|
||||
ynh_app_setting_set $app is_public 1
|
||||
is_public=1
|
||||
elif [ "$is_public" = "No" ]; then
|
||||
ynh_app_setting_set $app is_public 0
|
||||
is_public=0
|
||||
fi
|
||||
|
||||
sudo service php5-fpm reload
|
||||
sudo service nginx reload
|
||||
sudo yunohost app ssowatconf
|
||||
# If db_name doesn't exist, create it
|
||||
if [ -z $db_name ]; then
|
||||
db_name=$(ynh_sanitize_dbid $app)
|
||||
ynh_app_setting_set $app db_name $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 final_path $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)
|
||||
|
||||
#=================================================
|
||||
# STANDARD UPGRADE STEPS
|
||||
#=================================================
|
||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
#=================================================
|
||||
|
||||
# Download, check integrity, uncompress and patch the source from app.src
|
||||
ynh_setup_source "$final_path"
|
||||
|
||||
|
||||
ynh_secure_remove $final_path/tests
|
||||
ynh_secure_remove $final_path/install.txt
|
||||
mv $final_path/public_html/* $final_path/
|
||||
ynh_secure_remove $final_path/public_html
|
||||
|
||||
#=================================================
|
||||
# NGINX CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
# Create a dedicated nginx config
|
||||
ynh_add_nginx_config
|
||||
|
||||
#=================================================
|
||||
# CREATE DEDICATED USER
|
||||
#=================================================
|
||||
|
||||
# Create a system user
|
||||
ynh_system_user_create $app
|
||||
|
||||
#=================================================
|
||||
# PHP-FPM CONFIGURATION
|
||||
#=================================================
|
||||
|
||||
# Create a dedicated php-fpm config
|
||||
ynh_add_fpm_config
|
||||
|
||||
#=================================================
|
||||
# SETUP LOGROTATE
|
||||
#=================================================
|
||||
|
||||
# Use logrotate to manage app-specific logfile(s)
|
||||
ynh_use_logrotate --non-append
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALIZATION
|
||||
#=================================================
|
||||
# SECURE FILES AND DIRECTORIES
|
||||
#=================================================
|
||||
|
||||
# Set right permissions for curl installation
|
||||
chown -R $app:$app $final_path
|
||||
|
||||
#=================================================
|
||||
# SETUP SSOWAT
|
||||
#=================================================
|
||||
|
||||
if [ $is_public -eq 0 ]
|
||||
then # Remove the public access
|
||||
ynh_app_setting_delete $app skipped_uris
|
||||
fi
|
||||
# Make app public if necessary
|
||||
if [ $is_public -eq 1 ]
|
||||
then
|
||||
# unprotected_uris allows SSO credentials to be passed anyway
|
||||
ynh_app_setting_set $app unprotected_uris "/"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
|
||||
systemctl reload nginx
|
||||
|
|
Loading…
Reference in a new issue