浏览代码

Refactoring

frju365 7 年之前
父节点
当前提交
14efd9df15
共有 14 个文件被更改,包括 499 次插入5788 次删除
  1. 114 5152
      LICENSE
  2. 5 1
      README.md
  3. 2 2
      conf/app.src
  4. 8 6
      conf/nginx.conf
  5. 23 23
      conf/php-fpm.conf
  6. 2 2
      conf/php-fpm.ini
  7. 14 7
      manifest.json
  8. 0 403
      scripts/.fonctions
  9. 1 0
      scripts/_common.sh
  10. 46 17
      scripts/backup
  11. 50 47
      scripts/install
  12. 51 29
      scripts/remove
  13. 85 66
      scripts/restore
  14. 98 33
      scripts/upgrade

文件差异内容过多而无法显示
+ 114 - 5152
LICENSE


+ 5 - 1
README.md

@@ -42,6 +42,10 @@ https://www.domain.tld/prestashop/admin
 
 ## Versionning
 
-###Version 1.0.0 (22/02/17)
+### Version 2.0 (12/2018)
+
+- Refactoring
+
+### Version 1.0.0 (22/02/17)
 
 - Create script install

+ 2 - 2
conf/app.src

@@ -1,5 +1,5 @@
-SOURCE_URL=https://download.prestashop.com/download/releases/prestashop_1.7.4.4.zip
-SOURCE_SUM=42e6fb80f64654e1a997807669ac1cd8c36c76c58c74b031618ac96ff3c21dcf
+SOURCE_URL=https://download.prestashop.com/download/releases/prestashop_1.7.5.0.zip
+SOURCE_SUM=4678f43d669de2d145464404ba77b5aa58ab603ca88f1f64f830ecd3bbd4877f
 SOURCE_SUM_PRG=sha256sum
 SOURCE_FORMAT=zip
 SOURCE_IN_SUBDIR=true

+ 8 - 6
conf/nginx.conf

@@ -1,5 +1,7 @@
-location __PATHTOCHANGE__ {
-	alias __FINALPATH__/;
+#sub_path_only rewrite ^__PATH__$ __PATH__/ permanent;
+location __PATH__/ {
+
+	alias __FINALPATH__/ ;
 	index index.php;
 
 	if ($scheme = http) {
@@ -21,7 +23,7 @@ location __PATHTOCHANGE__ {
 	rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg last;
 	rewrite ^/c/([0-9]+)(-[.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+.jpg$ /img/c/$1$2$3.jpg last;
 	rewrite ^/c/([a-zA-Z_-]+)(-[0-9]+)?/.+.jpg$ /img/c/$1$2.jpg last;
-	
+
 	error_page 404 /index.php?controller=404;
 
 	# Deny access to .htaccess .DS_Store .htpasswd etc
@@ -43,7 +45,7 @@ location __PATHTOCHANGE__ {
 
 	location ~ [^/]\.php(/|$) {
 		fastcgi_split_path_info ^(.+?\.php)(/.*)$;
-		fastcgi_pass unix:/var/run/php5-fpm-__NAMETOCHANGE__.sock;
+		fastcgi_pass unix:/var/run/fpm/php5-fpm-__NAMETOCHANGE__.sock;
 		fastcgi_index index.php;
 		include fastcgi_params;
 		fastcgi_param REMOTE_USER $remote_user;
@@ -63,6 +65,6 @@ location __PATHTOCHANGE__ {
 		client_max_body_size 30m;
 	}
 
-  #--PRIVATE--# Include SSOWAT user panel.
-  #--PRIVATE--include conf.d/yunohost_panel.conf.inc;
+	# Include SSOWAT user panel.
+	include conf.d/yunohost_panel.conf.inc;
 }

+ 23 - 23
conf/php-fpm.conf

@@ -19,8 +19,8 @@
 ; Unix user/group of processes
 ; Note: The user is mandatory. If the group is not set, the default user's group
 ;       will be used.
-user = www-data
-group = www-data
+user = __USER__
+group = __USER__
 
 ; The address on which to accept FastCGI requests.
 ; Valid syntaxes are:
@@ -32,19 +32,19 @@ group = www-data
 ; Note: This value is mandatory.
 listen = /var/run/php5-fpm-__NAMETOCHANGE__.sock
 
-; Set listen(2) backlog.
+; Set listen(2) backlog. A value of '-1' means unlimited.
 ; Default Value: 128 (-1 on FreeBSD and OpenBSD)
 ;listen.backlog = 128
 
 ; Set permissions for unix socket, if one is used. In Linux, read/write
 ; permissions must be set in order to allow connections from a web server. Many
-; BSD-derived systems allow connections regardless of permissions. 
+; BSD-derived systems allow connections regardless of permissions.
 ; Default Values: user and group are set as the running user
 ;                 mode is set to 0660
 listen.owner = www-data
 listen.group = www-data
 ;listen.mode = 0660
- 
+
 ; List of ipv4 addresses of FastCGI clients which are allowed to connect.
 ; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original
 ; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address
@@ -117,7 +117,7 @@ pm.max_spare_servers = 3
 ; Note: Used only when pm is set to 'ondemand'
 ; Default Value: 10s
 ;pm.process_idle_timeout = 10s;
- 
+
 ; The number of requests each child process should execute before respawning.
 ; This can be useful to work around memory leaks in 3rd party libraries. For
 ; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS.
@@ -170,7 +170,7 @@ pm.max_requests = 500
 ;
 ; By default the status page only outputs short status. Passing 'full' in the
 ; query string will also return status for each pool process.
-; Example: 
+; Example:
 ;   http://www.foo.bar/status?full
 ;   http://www.foo.bar/status?json&full
 ;   http://www.foo.bar/status?html&full
@@ -220,9 +220,9 @@ pm.max_requests = 500
 ; Note: The value must start with a leading slash (/). The value can be
 ;       anything, but it may not be a good idea to use the .php extension or it
 ;       may conflict with a real PHP file.
-; Default Value: not set 
+; Default Value: not set
 ;pm.status_path = /status
- 
+
 ; The ping URI to call the monitoring page of FPM. If this value is not set, no
 ; URI will be recognized as a ping page. This could be used to test from outside
 ; that FPM is alive and responding, or to
@@ -283,7 +283,7 @@ pm.max_requests = 500
 ;      - ....
 ;  %p: PID of the child that serviced the request
 ;  %P: PID of the parent of the child that serviced the request
-;  %q: the query string 
+;  %q: the query string
 ;  %Q: the '?' character if query string exists
 ;  %r: the request URI (without the query string, see %q and %Q)
 ;  %R: remote IP address
@@ -298,50 +298,50 @@ pm.max_requests = 500
 ;
 ; Default: "%R - %u %t \"%m %r\" %s"
 ;access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"
- 
+
 ; The log file for slow requests
 ; Default Value: not set
 ; Note: slowlog is mandatory if request_slowlog_timeout is set
 slowlog = /var/log/nginx/__NAMETOCHANGE__.slow.log
- 
+
 ; The timeout for serving a single request after which a PHP backtrace will be
 ; dumped to the 'slowlog' file. A value of '0s' means 'off'.
 ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
 ; Default Value: 0
 request_slowlog_timeout = 5s
- 
+
 ; The timeout for serving a single request after which the worker process will
 ; be killed. This option should be used when the 'max_execution_time' ini option
 ; does not stop script execution for some reason. A value of '0' means 'off'.
 ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
 ; Default Value: 0
 request_terminate_timeout = 1d
- 
+
 ; Set open file descriptor rlimit.
 ; Default Value: system defined value
 ;rlimit_files = 1024
- 
+
 ; Set max core size rlimit.
 ; Possible Values: 'unlimited' or an integer greater or equal to 0
 ; Default Value: system defined value
 ;rlimit_core = 0
- 
+
 ; Chroot to this directory at the start. This value must be defined as an
 ; absolute path. When this value is not set, chroot is not used.
 ; Note: you can prefix with '$prefix' to chroot to the pool prefix or one
 ; of its subdirectories. If the pool prefix is not set, the global prefix
 ; will be used instead.
-; Note: chrooting is a great security feature and should be used whenever 
+; Note: chrooting is a great security feature and should be used whenever
 ;       possible. However, all PHP paths will be relative to the chroot
 ;       (error_log, sessions.save_path, ...).
 ; Default Value: not set
-;chroot = 
- 
+;chroot =
+
 ; Chdir to this directory at the start.
 ; Note: relative path can be used.
 ; Default Value: current directory or / when chroot
 chdir = __FINALPATH__
- 
+
 ; Redirect worker stdout and stderr into main error log. If not set, stdout and
 ; stderr will be redirected to /dev/null according to FastCGI specs.
 ; Note: on highloaded environement, this can cause some delay in the page
@@ -356,7 +356,7 @@ catch_workers_output = yes
 ; Note: set an empty value to allow all extensions.
 ; Default Value: .php
 ;security.limit_extensions = .php .php3 .php4 .php5
- 
+
 ; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from
 ; the current environment.
 ; Default Value: clean env
@@ -370,7 +370,7 @@ catch_workers_output = yes
 ; overwrite the values previously defined in the php.ini. The directives are the
 ; same as the PHP SAPI:
 ;   php_value/php_flag             - you can set classic ini defines which can
-;                                    be overwritten from PHP call 'ini_set'. 
+;                                    be overwritten from PHP call 'ini_set'.
 ;   php_admin_value/php_admin_flag - these directives won't be overwritten by
 ;                                     PHP call 'ini_set'
 ; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no.
@@ -389,4 +389,4 @@ catch_workers_output = yes
 ;php_flag[display_errors] = off
 ;php_admin_value[error_log] = /var/log/fpm-php.www.log
 ;php_admin_flag[log_errors] = on
-;php_admin_value[memory_limit] = 32M
+;php_admin_value[memory_limit] = 32M

+ 2 - 2
conf/php-fpm.ini

@@ -1,4 +1,4 @@
-upload_max_filesize=30M
+upload_max_filesize=1000M
 post_max_size=300M
 max_execution_time=600
-request_terminate_timeout = 300
+request_terminate_timeout = 300

+ 14 - 7
manifest.json

@@ -10,9 +10,16 @@
     "url": "https://www.prestashop.com/",
     "license": "free",
     "maintainer": {
-        "name": "frju365, cyp",
-        "email": "win10@tutanota.com, cyp@rouquin.me"
+        "name": "frju365",
+        "email": "abld@abld.info"
     },
+    "previous_maintainers": [
+      {
+        "name": "cyp",
+        "email": "cyp@rouquin.me",
+        "url": ""
+      }
+    ],
     "requirements": {
         "yunohost": ">> 2.4.0"
     },
@@ -62,13 +69,13 @@
                 "default": "Yes"
             },
             {
-                "name": "language",
+                "name": "is_public",
+                "type": "boolean",
                 "ask": {
-                    "en": "Choose the application language",
-                    "fr": "Choisissez la langue de l'application"
+                    "en": "Is it a public application?",
+                    "fr": "Est-ce une application publique ?"
                 },
-                "choices": ["en_EN", "fr_FR"],
-                "default": "fr_FR"
+                "default": true
             },
             {
                 "name": "passwd",

+ 0 - 403
scripts/.fonctions

@@ -1,403 +0,0 @@
-#!/bin/bash
-
-#=================================================
-# CHECKING
-#=================================================
-
-ynh_version="2.4"
-
-YNH_VERSION () {	# Renvoi le numéro de version de la moulinette Yunohost
-	ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2)
-}
-
-CHECK_VAR () {	# Verifies that the variable is not empty.
-	# $1 = Variable to be checked
-	# $2 = Display text on error
-	test -n "$1" || (echo "$2" >&2 && false)
-}
-
-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 -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"
-}
-
-CHECK_PATH () {	# Checks / at the beginning of the path. And his absence at the end.
-	if [ "${path:0:1}" != "/" ]; then    # If the first character is not /
-		path="/$path"    # Add / at the beginning of path
-	fi
-	if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then    # If the last character is a / and it is not the only character.
-		path="${path:0:${#path}-1}"	# Delete last character
-	fi
-}
-
-#=================================================
-# 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
-}
-
-#=================================================
-# Create a database and a dedicated user in the name of the app
-#=================================================
-GENERATE_DB () {	
-	# $1 = Database name
-	# Generates a random password.
-	db_user=$1
-	db_pwd=$(head -n20 /dev/urandom | tr -c -d 'A-Za-z0-9' | head -c20)
-	CHECK_VAR "$db_pwd" "db_pwd empty"
-	# Uses '$ app' as user name and database
-	# Initializes the database and stores the mysql password.
-	ynh_mysql_create_db "$db_user" "$db_user" $db_pwd
-	ynh_app_setting_set $app mysqlpwd $db_pwd
-}
-
-#=================================================
-# 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
-	sudo wget -nv -O source.zip $src_url
-	# Vérifie la somme de contrôle de la source téléchargée.
-	echo "$src_checksum source.zip" | md5sum -c --status || ynh_die "Corrupt source"
-	# Extract source into the app dir
-	sudo mkdir -p $final_path
-	sudo mv source.zip $final_path/source.zip
-	pushd $final_path
-	sudo unzip source.zip
-	sudo rm Install_PrestaShop.html index.php
-	sudo unzip -o prestashop.zip
-	sudo rm prestashop.zip
-	sudo rm source.zip
-}
-
-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 systemctl reload php5-fpm
-}
-
-EXIT_PROPERLY () {	# Causes the script to stop in the event of an error. And clean the residue.
-	trap '' ERR
-	echo -e "\e[91m \e[1m"	# Shell in light red bold
-	echo -e "!!\n  $app install's script has encountered an error. Installation was cancelled.\n!!" >&2
-
-	if type -t CLEAN_SETUP > /dev/null; then	# Checks the existence of the function before executing it.
-		CLEAN_SETUP	# Call the specific cleanup function of the install script.
-	fi
-
-	# Compensates the ssowat bug that does not remove the app's input in case of installation error.
-	sudo sed -i "\@\"$domain$path/\":@d" /etc/ssowat/conf.json
-
-	if [ "$ynh_version" = "2.2" ]; then
-		/bin/bash $script_dir/remove
-	fi
-
-	ynh_die
-}
-
-TRAP_ON () {	# Activate signal capture
-	trap EXIT_PROPERLY ERR	# Capturing exit signals on error
-}
-
-TRAP_OFF () {	# Ignoring signal capture until TRAP_ON
-	trap '' ERR	# Ignoring exit signals
-}
-
-#=================================================
-# 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 systemctl reload nginx
-	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 systemctl reload php5-fpm
-}
-
-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
-#=================================================
-
-# 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=$1
-	test -n "$path" || ynh_die "ynh_normalize_url_path expect a URL path as first argument and received nothing."
-	if [ "${path:0:1}" != "/" ]; then    # If the first character is not a /
-		path="/$path"    # Add / at begin of path variable
-	fi
-	if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then    # If the last character is a / and that not the only character.
-		path="${path:0:${#path}-1}"	# Delete the last character
-	fi
-	echo $path
-}
-
-# 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
-}
-
-# 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 - 0
scripts/_common.sh

@@ -0,0 +1 @@
+#!/bin/bash

+ 46 - 17
scripts/backup

@@ -1,27 +1,56 @@
 #!/bin/bash
 
-# Exit on command errors and treat unset variables as an error
-set -eu
+#=================================================
+# GENERIC START
+#=================================================
+# IMPORT GENERIC HELPERS
+#=================================================
 
-# Source app helpers
+source ../settings/scripts/_common.sh
 source /usr/share/yunohost/helpers
 
-# Get multi-instances specific variables
-app=$YNH_APP_INSTANCE_NAME
+#=================================================
+# MANAGE SCRIPT FAILURE
+#=================================================
+
+ynh_clean_setup () {
+	### Remove this function if there's nothing to clean before calling the remove script.
+	true
+}
+# Exit if an error occurs during the execution of the script
+ynh_abort_if_errors
+
+#=================================================
+# LOAD SETTINGS
+#=================================================
 
-# Retrieve app settings
 domain=$(ynh_app_setting_get "$app" domain)
+app=$YNH_APP_INSTANCE_NAME
+final_path=$(ynh_app_setting_get $app final_path)
+
+#=================================================
+# 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 PHP-FPM CONFIGURATION
+#=================================================
 
-# Copy the app files
-final_path="/var/www/${app}"
-ynh_backup "$final_path" "sources" 1
+ynh_backup "/etc/php5/fpm/pool.d/$app.conf"
+ynh_backup "/etc/php5/fpm/conf.d/20-$app.ini"
 
-# Copy the nginx conf files
-ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf"
-# Copy the php-fpm conf files
-ynh_backup "/etc/php5/fpm/pool.d/${app}.conf" "php-fpm.conf"
-ynh_backup "/etc/php5/fpm/conf.d/20-${app}.ini" "php-fpm.ini"
+#=================================================
+# BACKUP THE MYSQL DATABASE
+#=================================================
 
-# Backup db
-root_pwd=$(sudo cat /etc/yunohost/mysql)
-sudo su -c "mysqldump -u root -p$root_pwd --no-create-db $app > ./db.sql"
+ynh_mysql_dump_db "$db_name" > db.sql

+ 50 - 47
scripts/install

@@ -1,24 +1,24 @@
 #!/bin/bash
 
 #=================================================
-# Exit on command errors and treat unset variables as an error
-#=================================================
-set -eu
-
-#=================================================
-# GENERIC STARTING
+# GENERIC START
 #=================================================
 # IMPORT GENERIC HELPERS
 #=================================================
 
-source .fonctions
+source _common.sh
 source /usr/share/yunohost/helpers
 
 #=================================================
-# MANAGE FAILURE OF THE SCRIPT
+# MANAGE SCRIPT FAILURE
 #=================================================
 
-TRAP_ON	# Active trap to stop the script if an error is detected.
+ynh_clean_setup () {
+	### Remove this function if there's nothing to clean before calling the remove script.
+	true
+}
+# Exit if an error occurs during the execution of the script
+ynh_abort_if_errors
 
 #=================================================
 # RETRIEVE ARGUMENTS FROM THE MANIFEST
@@ -34,16 +34,20 @@ email=$YNH_APP_ARG_EMAIL
 
 app=$YNH_APP_INSTANCE_NAME
 
-
 #=================================================
-# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
+# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
 #=================================================
 
-CHECK_VAR "$app" "app name not set"
-CHECK_USER "$admin_prestashop"	# Vérifie la validité de l'user admin
-path=$(ynh_normalize_url_path $path)	# 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)
+
+# Register (book) web path
+ynh_webpath_register $app $domain $path_url
+[[ ${#pass} -gt 5 ]] || ynh_die \
+"The password is too weak, it must be longer than 5 characters"
 
 #=================================================
 # STORE SETTINGS FROM MANIFEST
@@ -60,23 +64,24 @@ ynh_app_setting_set $app email $email
 #=================================================
 # Check password strength
 #=================================================
+
 [[ ${#pass} -gt 5 ]] || ynh_die \
 "The password is too weak, it must be longer than 5 characters"
 
 #=================================================
-# CREATE A SQL BDD
+# CREATE A MYSQL DATABASE
 #=================================================
 
-GENERATE_DB $app	# Create a database and a dedicated user in the app name
+db_name=$(ynh_sanitize_dbid $app)
+ynh_app_setting_set $app db_name $db_name
+ynh_mysql_setup_db $db_name $db_name
 
 #=================================================
 # NGINX CONFIGURATION
 #=================================================
-final_path=/var/www/$app
-sudo sed -i "s@__PATHTOCHANGE__@$path@g" ../conf/nginx.conf
-sudo sed -i "s@__FINALPATH__@$final_path@g" ../conf/nginx.conf
-sudo sed -i "s@__NAMETOCHANGE__@$app@g" ../conf/nginx.conf
-sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
+
+# Create a dedicated nginx config
+ynh_add_nginx_config
 
 #=================================================
 # PHP-FPM CONFIGURATION
@@ -85,25 +90,27 @@ sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
 POOL_FPM
 
 #=================================================
-# Crée le repertoire de destination
+# DOWNLOAD, CHECK AND UNPACK SOURCE
 #=================================================
-sudo mkdir "$final_path"
+
+ynh_app_setting_set $app final_path $final_path
+# Download, check integrity, uncompress and patch the source from app.src
+ynh_setup_source "$final_path"
 
 #=================================================
-# DOWNLOAD, CHECK AND UNPACK SOURCE
+# CREATE DEDICATED USER
 #=================================================
 
-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
+# Create a system user
+ynh_system_user_create $app
 
 #=================================================
 # Installation de Prestashop
 #=================================================
 pushd $final_path/install/
-sudo php index_cli.php \
+php7.0 index_cli.php \
 		--db_server=localhost \
-		--db_user=$db_user \
+		--db_user=$db_name \
 		--db_password=$db_pwd \
 		--db_name=$app \
 		--db_driver=amysqli \
@@ -115,7 +122,7 @@ sudo php index_cli.php \
 		--email=$email \
 		--domain=$domain \
 		--base_uri=$path \
-		--prefix=_ps_ 
+		--prefix=_ps_
 popd
 
 sudo rm -fr $final_path/install
@@ -123,13 +130,15 @@ sudo rm -fr $final_path/install
 #=================================================
 # check les permissions
 #=================================================
-sudo chown -R www-data: $final_path
+
+sudo chown -R $app:$app $final_path
 
 #=================================================
 # active ssl
 #=================================================
-mysql -u $db_user -p$db_pwd $db_user -e "UPDATE _ps_configuration SET value=1 WHERE name='PS_SSL_ENABLED';"
-mysql -u $db_user -p$db_pwd $db_user -e "INSERT INTO _ps_configuration (id_configuration, id_shop_group, id_shop, name, value, date_add, date_upd) VALUES (NULL, NULL, NULL, 'PS_SSL_ENABLED_EVERYWHERE', '1', NOW(), NOW());"
+
+mysql -u $db_user -p$db_pwd $db_name -e "UPDATE _ps_configuration SET value=1 WHERE name='PS_SSL_ENABLED';"
+mysql -u $db_user -p$db_pwd $db_name -e "INSERT INTO _ps_configuration (id_configuration, id_shop_group, id_shop, name, value, date_add, date_upd) VALUES (NULL, NULL, NULL, 'PS_SSL_ENABLED_EVERYWHERE', '1', NOW(), NOW());"
 
 #=================================================
 # Set /etc/hosts
@@ -141,24 +150,18 @@ echo -e "127.0.0.1 $domain #PRESTASHOP" | sudo tee -a /etc/hosts
 # SETUP SSOWAT
 #=================================================
 
-ynh_app_setting_set "$app" is_public "$is_public"
-if [ "$is_public" = "Yes" ];
+# 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
 
 #=================================================
-# Régénère la configuration de SSOwat
-#=================================================
-
-sudo yunohost app ssowatconf
-
-#=================================================
-# Reload Nginx and regenerate SSOwat conf
+# RELOAD NGINX
 #=================================================
 
-sudo systemctl reload php5-fpm
-sudo systemctl reload nginx
+systemctl reload nginx
 
 #=================================================
 # Nettoyer hosts

+ 51 - 29
scripts/remove

@@ -1,36 +1,58 @@
 #!/bin/bash
 
-# Exit on command errors and treat unset variables as an error
-set -u
+#=================================================
+# GENERIC START
+#=================================================
+# IMPORT GENERIC HELPERS
+#=================================================
 
-# Loads the generic functions usually used in the script
-source .fonctions
-# Source app helpers
+source _common.sh
 source /usr/share/yunohost/helpers
 
-# Get multi-instances specific variables
-app=$YNH_APP_INSTANCE_NAME
+#=================================================
+# LOAD SETTINGS
+#=================================================
 
-# Retrieve app settings
+app=$YNH_APP_INSTANCE_NAME
 domain=$(ynh_app_setting_get "$app" domain)
-# with_mysql=$(ynh_app_setting_get "$app" with_mysql)
-
-# Drop MySQL database and user as needed
-#if [[ $with_mysql -eq 1 ]]; then
-dbname=$app
-dbuser=$app
-dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
-ynh_mysql_drop_db $dbname || true
-ynh_mysql_drop_user $dbuser || true
-#fi
-
-# Delete app directory and configurations
-SECURE_REMOVE '/var/www/$app'	# Delete directory application
-sudo rm -f "/etc/php5/fpm/pool.d/${app}.conf"
-sudo rm -f "/etc/php5/fpm/conf.d/20-${app}.ini"
-[[ -n $domain ]] && sudo rm -f "/etc/nginx/conf.d/${domain}.d/${app}.conf"
-
-# Reload services
-sudo systemctl reload php5-fpm
-sudo systemctl reload nginx
-sudo yunohost app ssowatconf
+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 MYSQL DATABASE
+#=================================================
+
+# Remove a database if it exists, along with the associated user
+ynh_mysql_remove_db $db_user $db_name
+
+#=================================================
+# REMOVE APP MAIN DIR
+#=================================================
+
+# Remove the app directory securely
+ynh_secure_remove "$final_path"
+
+#=================================================
+# REMOVE NGINX CONFIGURATION
+#=================================================
+
+# Remove the dedicated nginx config
+ynh_remove_nginx_config
+
+#=================================================
+# REMOVE PHP-FPM CONFIGURATION
+#=================================================
+
+# Remove the dedicated php-fpm config
+ynh_remove_fpm_config
+#=================================================
+# GENERIC FINALIZATION
+#=================================================
+# REMOVE DEDICATED USER
+#=================================================
+
+# Delete a system user
+ynh_system_user_delete $app

+ 85 - 66
scripts/restore

@@ -1,75 +1,94 @@
 #!/bin/bash
-# This restore script is adapted to Yunohost >=2.4
 
-# Exit on command errors and treat unset variables as an error
-set -eu
+#=================================================
+# GENERIC START
+#=================================================
+# IMPORT GENERIC HELPERS
+#=================================================
 
-# Source app helpers
+source ../settings/scripts/_common.sh
 source /usr/share/yunohost/helpers
 
-# The parameter $2 is the id of the app instance ex: ynhexample__2
+#=================================================
+# MANAGE SCRIPT FAILURE
+#=================================================
+
+ynh_clean_setup () {
+	#### Remove this function if there's nothing to clean before calling the remove script.
+	true
+}
+# Exit if an error occurs during the execution of the script
+ynh_abort_if_errors
+
+#=================================================
+# LOAD SETTINGS
+#=================================================
+
 app=$YNH_APP_INSTANCE_NAME
 
-# Get old parameter of the app
 domain=$(ynh_app_setting_get $app domain)
-path=$(ynh_app_setting_get $app path)
-is_public=$(ynh_app_setting_get $app is_public)
-# with_mysql=$(ynh_app_setting_get "$app" with_mysql)
-
-# Check domain/path availability
-sudo yunohost app checkurl "${domain}${path}" -a "$app" \
-    || ynh_die "Path not available: ${domain}${path}"
-
-# Check $final_path
-final_path="/var/www/${app}"
-if [ -d $final_path ]; then
-	ynh_die "There is already a directory: $final_path"
-fi
-
-# Check configuration files nginx
-nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
-if [ -f $nginx_conf ]; then
-	ynh_die "The NGINX configuration already exists at '${nginx_conf}'. You should safely delete it before restoring this app."
-fi
-# Check configuration files php-fpm
-phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf"
-if [ -f $phpfpm_conf ]; then 
-	ynh_die "The PHP FPM configuration already exists at '${phpfpm_conf}'. You should safely delete it before restoring this app."
-fi
-
-phpfpm_ini="/etc/php5/fpm/conf.d/20-${app}.ini"
-if [ -f $phpfpm_ini ]; then
-	ynh_die "The PHP FPM INI configuration already exists at '${phpfpm_ini}'. You should safely delete it before restoring this app."
-fi
-
-# Restore sources & data
-sudo cp -a ./sources "${final_path}"
-
-# Set permissions
-sudo chown -R www-data: "${final_path}"
-
-# Restore db
-# if [[ $with_mysql -eq 1 ]]; then
+path_url=$(ynh_app_setting_get $app path)
+app=$YNH_APP_INSTANCE_NAME
+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)
-db_user=$app
-ynh_mysql_create_db $db_user $db_user $db_pwd
-sudo su -c "mysql -u $db_user -p$db_pwd $app < ./db.sql"
-sudo rm -f "./db.sql"
-#fi
-
-# Restore nginx configuration files
-sudo cp -a ./nginx.conf   "${nginx_conf}"
-# Restore php-fpm configuration files
-sudo cp -a ./php-fpm.conf "${phpfpm_conf}"
-sudo cp -a ./php-fpm.ini "${phpfpm_ini}"
-
-# Set ssowat config
-if [ "$is_public" = "No" ];
-then
-	ynh_app_setting_delete $app skipped_uris
-fi
-
-# Reload services
-sudo systemctl reload php5-fpm
-sudo systemctl reload nginx
-sudo yunohost app ssowatconf
+ynh_mysql_setup_db $db_name $db_name $db_pwd
+ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql
+
+#=================================================
+# RECREATE THE DEDICATED USER
+#=================================================
+
+# Create the dedicated user (if not existing)
+ynh_system_user_create $app
+
+#=================================================
+# RESTORE USER RIGHTS
+#=================================================
+
+# Restore permissions on app files
+chown -R root: $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"
+
+#=================================================
+# GENERIC FINALIZATION
+#=================================================
+# RELOAD NGINX AND PHP-FPM
+#=================================================
+
+systemctl reload php5-fpm
+systemctl reload nginx

+ 98 - 33
scripts/upgrade

@@ -1,56 +1,121 @@
 #!/bin/bash
 
-# Exit on command errors and treat unset variables as an error
-set -eu
+#=================================================
+# GENERIC START
+#=================================================
+# IMPORT GENERIC HELPERS
+#=================================================
 
-source .fonctions	# Loads the generic functions usually used in the script
-source /usr/share/yunohost/helpers # Source YunoHost helpers
+source _common.sh
+source /usr/share/yunohost/helpers
 
-# See comments in install script
-app=$YNH_APP_INSTANCE_NAME
+#=================================================
+# LOAD SETTINGS
+#=================================================
 
-# Retrieve app settings
 domain=$(ynh_app_setting_get "$app" domain)
 path=$(ynh_app_setting_get "$app" path)
 admin=$(ynh_app_setting_get "$app" admin)
 is_public=$(ynh_app_setting_get "$app" is_public)
 language=$(ynh_app_setting_get "$app" language)
 
-CHECK_PATH	# Checks and corrects the syntax of the path.
+#=================================================
+# ENSURE DOWNWARD COMPATIBILITY
+#=================================================
 
-root_pwd=$(sudo cat /etc/yunohost/mysql)
+# 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
 
-final_path=/var/www/$app
+# 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
 
-# Get source
-SETUP_SOURCE
+# 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
 
-# Delete install directory after upgrade
-rm -fr "$final_path/install"
+#=================================================
+# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
+#=================================================
 
-db_name=$app
+# 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
 
-# Modify Nginx configuration file and copy it to Nginx conf directory
-sudo sed -i "s@__PATHTOCHANGE__@$path@g" /etc/nginx/conf.d/$domain.d/$app.conf
-sudo sed -i "s@__FINALPATH__@$final_path@g" /etc/nginx/conf.d/$domain.d/$app.conf
-sudo sed -i "s@__NAMETOCHANGE__@$app@g" /etc/nginx/conf.d/$domain.d/$app.conf
+#=================================================
+# CHECK THE PATH
+#=================================================
 
-if [ "$is_public" = "Yes" ];
-then
-	sudo sed -i "s@#--PRIVATE--@@g" /etc/nginx/conf.d/$domain.d/$app.conf
-fi
+# 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"
+
+#=================================================
+# NGINX CONFIGURATION
+#=================================================
 
-# Create the php-fpm pool config
-POOL_FPM
+# Create a dedicated nginx config
+ynh_add_nginx_config
 
-# Setup SSOwat
-ynh_app_setting_set "$app" is_public "$is_public"
-if [ "$is_public" = "Yes" ];
+#=================================================
+# CREATE DEDICATED USER
+#=================================================
+
+# Create a dedicated user (if not existing)
+ynh_system_user_create $app
+
+#=================================================
+# PHP-FPM CONFIGURATION
+#=================================================
+
+# Create a dedicated php-fpm config
+ynh_add_fpm_config
+
+#=================================================
+# GENERIC FINALIZATION
+#=================================================
+# SECURE FILES AND DIRECTORIES
+#=================================================
+
+# Set permissions on app files
+chown -R $app:$app $final_path
+
+#=================================================
+# SETUP SSOWAT
+#=================================================
+
+# 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 services
-sudo systemctl reload php5-fpm
-sudo systemctl reload nginx
-sudo yunohost app ssowatconf
+#=================================================
+# RELOAD NGINX
+#=================================================
+
+systemctl reload nginx

部分文件因为文件数量过多而无法显示