Prechádzať zdrojové kódy

Merge pull request #42 from YunoHost/some_corrections

[fix] Some corrections
Maniack Crudelis 7 rokov pred
rodič
commit
2c585d5d2b
11 zmenil súbory, kde vykonal 82 pridanie a 152 odobranie
  1. 3 3
      check_process.default
  2. 1 1
      conf/app.src
  3. 2 2
      conf/php-fpm.ini
  4. 13 0
      conf/systemd.service
  5. 2 1
      manifest.json
  6. 0 110
      scripts/_common.sh
  7. 14 16
      scripts/backup
  8. 11 5
      scripts/install
  9. 3 2
      scripts/remove
  10. 9 9
      scripts/restore
  11. 24 3
      scripts/upgrade

+ 3 - 3
check_process.default

@@ -10,8 +10,8 @@
 		admin="john"	(USER)
 		language="fr"
 		is_public=1	(PUBLIC|public=1|private=0)
-  	password="pass"
-  	port="666"	(PORT)
+		password="pass"
+		port="666"	(PORT)
 	; Checks
 		pkg_linter=1
 		setup_sub_dir=1
@@ -23,7 +23,7 @@
 		backup_restore=1
 		multi_instance=1
 		incorrect_path=1
-		port_already_use=1
+		port_already_use=0
 		change_url=0
 ;;; Levels
 	Level 1=auto

+ 1 - 1
conf/app.src

@@ -1,6 +1,6 @@
 SOURCE_URL=url of app's source
 SOURCE_SUM=sha256 checksum
-SOURCE_SUM_PRG=sha256
+SOURCE_SUM_PRG=sha256sum
 SOURCE_FORMAT=tar.gz
 SOURCE_IN_SUBDIR=true
 SOURCE_FILENAME=

+ 2 - 2
conf/php-fpm.ini

@@ -1,9 +1,9 @@
-# Common values to change to increase file upload limit
+; Common values to change to increase file upload limit
 ; upload_max_filesize = 50M
 ; post_max_size = 50M
 ; mail.add_x_header = Off
 
-# Other common parameters
+; Other common parameters
 ; max_execution_time = 600
 ; max_input_time = 300
 ; memory_limit = 256M

+ 13 - 0
conf/systemd.service

@@ -0,0 +1,13 @@
+[Unit]
+Description=Small description of the service
+After=network.target
+
+[Service]
+Type=simple
+User=__APP__
+Group=__APP__
+WorkingDirectory=__FINALPATH__/
+ExecStart=__FINALPATH__/script >> /var/log/__APP__/__APP__.log 2>&1
+
+[Install]
+WantedBy=multi-user.target

+ 2 - 1
manifest.json

@@ -6,6 +6,7 @@
         "en": "Example package for YunoHost application.",
         "fr": "Exemple de package d’application pour YunoHost."
     },
+    "version": "1.0",
     "url": "https://example.com",
     "license": "free",
     "version": "1.0",
@@ -15,7 +16,7 @@
         "url": "http://example.com"
     },
     "requirements": {
-        "yunohost": ">= 2.6.4"
+        "yunohost": ">= 2.7.2"
     },
     "multi_instance": true,
     "services": [

+ 0 - 110
scripts/_common.sh

@@ -1,112 +1,2 @@
 #!/bin/bash
 
-# =============================================================================
-#                     YUNOHOST 2.7 FORTHCOMING HELPERS
-# =============================================================================
-
-# Create a dedicated nginx config
-#
-# usage: ynh_add_nginx_config
-ynh_add_nginx_config () {
-	finalnginxconf="/etc/nginx/conf.d/$domain.d/$app.conf"
-	ynh_backup_if_checksum_is_different "$finalnginxconf"
-	sudo cp ../conf/nginx.conf "$finalnginxconf"
-
-	# To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable.
-	# Substitute in a nginx config file only if the variable is not empty
-	if test -n "${path_url:-}"; then
-		ynh_replace_string "__PATH__" "$path_url" "$finalnginxconf"
-	fi
-	if test -n "${domain:-}"; then
-		ynh_replace_string "__DOMAIN__" "$domain" "$finalnginxconf"
-	fi
-	if test -n "${port:-}"; then
-		ynh_replace_string "__PORT__" "$port" "$finalnginxconf"
-	fi
-	if test -n "${app:-}"; then
-		ynh_replace_string "__NAME__" "$app" "$finalnginxconf"
-	fi
-	if test -n "${final_path:-}"; then
-		ynh_replace_string "__FINALPATH__" "$final_path" "$finalnginxconf"
-	fi
-	ynh_store_file_checksum "$finalnginxconf"
-
-	sudo systemctl reload nginx
-}
-
-# Remove the dedicated nginx config
-#
-# usage: ynh_remove_nginx_config
-ynh_remove_nginx_config () {
-	ynh_secure_remove "/etc/nginx/conf.d/$domain.d/$app.conf"
-	sudo systemctl reload nginx
-}
-
-# Create a dedicated php-fpm config
-#
-# usage: ynh_add_fpm_config
-ynh_add_fpm_config () {
-	finalphpconf="/etc/php5/fpm/pool.d/$app.conf"
-	ynh_backup_if_checksum_is_different "$finalphpconf"
-	sudo cp ../conf/php-fpm.conf "$finalphpconf"
-	ynh_replace_string "__NAMETOCHANGE__" "$app" "$finalphpconf"
-	ynh_replace_string "__FINALPATH__" "$final_path" "$finalphpconf"
-	ynh_replace_string "__USER__" "$app" "$finalphpconf"
-	sudo chown root: "$finalphpconf"
-	ynh_store_file_checksum "$finalphpconf"
-
-	if [ -e "../conf/php-fpm.ini" ]
-	then
-		finalphpini="/etc/php5/fpm/conf.d/20-$app.ini"
-		ynh_backup_if_checksum_is_different "$finalphpini"
-		sudo cp ../conf/php-fpm.ini "$finalphpini"
-		sudo chown root: "$finalphpini"
-		ynh_store_file_checksum "$finalphpini"
-	fi
-
-	sudo systemctl reload php5-fpm
-}
-
-# Remove the dedicated php-fpm config
-#
-# usage: ynh_remove_fpm_config
-ynh_remove_fpm_config () {
-	ynh_secure_remove "/etc/php5/fpm/pool.d/$app.conf"
-	ynh_secure_remove "/etc/php5/fpm/conf.d/20-$app.ini" 2>&1
-	sudo systemctl reload php5-fpm
-}
-
-# Create a dedicated systemd config
-#
-# usage: ynh_add_systemd_config
-ynh_add_systemd_config () {
-	finalsystemdconf="/etc/systemd/system/$app.service"
-	ynh_backup_if_checksum_is_different "$finalsystemdconf"
-	sudo cp ../conf/systemd.service "$finalsystemdconf"
-
-	# To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable.
-	# Substitute in a nginx config file only if the variable is not empty
-	if test -n "${final_path:-}"; then
-		ynh_replace_string "__FINALPATH__" "$final_path" "$finalsystemdconf"
-	fi
-	if test -n "${app:-}"; then
-		ynh_replace_string "__APP__" "$app" "$finalsystemdconf"
-	fi
-	ynh_store_file_checksum "$finalsystemdconf"
-
-	sudo chown root: "$finalsystemdconf"
-	sudo systemctl enable $app
-	sudo systemctl daemon-reload
-}
-
-# Remove the dedicated systemd config
-#
-# usage: ynh_remove_systemd_config
-ynh_remove_systemd_config () {
-	finalsystemdconf="/etc/systemd/system/$app.service"
-	if [ -e "$finalsystemdconf" ]; then
-		sudo systemctl stop $app
-		sudo systemctl disable $app
-		ynh_secure_remove "$finalsystemdconf"
-	fi
-}

+ 14 - 16
scripts/backup

@@ -2,13 +2,6 @@
 
 #=================================================
 # GENERIC START
-#=================================================
-# MANAGE SCRIPT FAILURE
-#=================================================
-
-# Exit on command errors and treat access to unset variables as an error
-set -eu
-
 #=================================================
 # IMPORT GENERIC HELPERS
 #=================================================
@@ -21,6 +14,13 @@ fi
 source _common.sh
 source /usr/share/yunohost/helpers
 
+#=================================================
+# MANAGE SCRIPT FAILURE
+#=================================================
+
+# Exit if an error occurs during the execution of the script
+ynh_abort_if_errors
+
 #=================================================
 # LOAD SETTINGS
 #=================================================
@@ -30,7 +30,6 @@ 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)
-db_pwd=$(ynh_app_setting_get $app mysqlpwd)
 
 #=================================================
 # STANDARD BACKUP STEPS
@@ -38,27 +37,26 @@ db_pwd=$(ynh_app_setting_get $app mysqlpwd)
 # BACKUP THE APP MAIN DIR
 #=================================================
 
-ynh_backup "$final_path" "${backup_dir}$final_path"
+ynh_backup "$final_path"
 
 #=================================================
 # BACKUP THE NGINX CONFIGURATION
 #=================================================
 
-ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "${backup_dir}/etc/nginx/conf.d/$domain.d/$app.conf"
+ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
 
 #=================================================
 # BACKUP THE PHP-FPM CONFIGURATION
 #=================================================
 
-ynh_backup "/etc/php5/fpm/pool.d/$app.conf" "${backup_dir}/etc/php5/fpm/pool.d/$app.conf"
-ynh_backup "/etc/php5/fpm/conf.d/20-$app.ini" "${backup_dir}/etc/php5/fpm/conf.d/20-$app.ini"
+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
-ynh_backup "db.sql" "${backup_dir}/db.sql"
 
 #=================================================
 # SPECIFIC BACKUP
@@ -66,16 +64,16 @@ ynh_backup "db.sql" "${backup_dir}/db.sql"
 # BACKUP LOGROTATE
 #=================================================
 
-ynh_backup "/etc/logrotate.d/$app" "${backup_dir}/etc/logrotate.d/$app"
+ynh_backup "/etc/logrotate.d/$app"
 
 #=================================================
 # BACKUP SYSTEMD
 #=================================================
 
-ynh_backup "/etc/systemd/system/$app.service" "${backup_dir}/etc/systemd/system/$app.service"
+ynh_backup "/etc/systemd/system/$app.service"
 
 #=================================================
 # BACKUP THE CRON FILE
 #=================================================
 
-ynh_backup "/etc/cron.d/$app" "${backup_dir}/etc/cron.d/$app"
+ynh_backup "/etc/cron.d/$app"

+ 11 - 5
scripts/install

@@ -42,6 +42,9 @@ app=$YNH_APP_INSTANCE_NAME
 # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
 #=================================================
 
+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)
 
@@ -50,9 +53,6 @@ ynh_webpath_available $domain $path_url
 # Register (book) web path
 ynh_webpath_register $app $domain $path_url
 
-final_path=/var/www/$app
-test ! -e "$final_path" || ynh_die "This path already contains a folder"
-
 #=================================================
 # STORE SETTINGS FROM MANIFEST
 #=================================================
@@ -118,7 +118,7 @@ ynh_system_user_create $app
 #=================================================
 
 # Create a dedicated php-fpm config
-ynh_fpm_config
+ynh_add_fpm_config
 
 #=================================================
 # SPECIFIC SETUP
@@ -141,7 +141,7 @@ ynh_systemd_config
 chown -R $app: $final_path
 
 # Set the app as temporarily public for curl call
-ynh_app_setting_set $app unprotected_uris "/"
+ynh_app_setting_set $app skipped_uris "/"
 # Reload SSOwat config
 yunohost app ssowatconf
 
@@ -151,6 +151,12 @@ systemctl reload nginx
 # Installation with curl
 ynh_local_curl "/INSTALL_PATH" "key1=value1" "key2=value2" "key3=value3"
 
+#=================================================
+# MODIFY A CONFIG FILE
+#=================================================
+
+ynh_replace_string "match_string" "replace_string" "$final_path/CONFIG_FILE"
+
 #=================================================
 # STORE THE CHECKSUM OF THE CONFIG FILE
 #=================================================

+ 3 - 2
scripts/remove

@@ -18,6 +18,7 @@ app=$YNH_APP_INSTANCE_NAME
 domain=$(ynh_app_setting_get $app domain)
 port=$(ynh_app_setting_get $app port)
 db_name=$(ynh_app_setting_get $app db_name)
+final_path=$(ynh_app_setting_get $app final_path)
 
 #=================================================
 # STANDARD REMOVE
@@ -57,7 +58,7 @@ ynh_mysql_remove_db $db_name $db_name
 #=================================================
 
 # Remove the app directory securely
-ynh_secure_remove "/var/www/$app"
+ynh_secure_remove "$final_path"
 
 #=================================================
 # REMOVE NGINX CONFIGURATION
@@ -87,7 +88,7 @@ ynh_remove_logrotate
 if yunohost firewall list | grep -q "\- $port$"
 then
 	echo "Close port $port"
-	QUIET yunohost firewall disallow TCP $port
+	yunohost firewall disallow TCP $port 2>&1
 fi
 
 #=================================================

+ 9 - 9
scripts/restore

@@ -2,13 +2,6 @@
 
 #=================================================
 # GENERIC START
-#=================================================
-# MANAGE SCRIPT FAILURE
-#=================================================
-
-# Exit on command errors and treat access to unset variables as an error
-set -eu
-
 #=================================================
 # IMPORT GENERIC HELPERS
 #=================================================
@@ -21,6 +14,13 @@ fi
 source _common.sh
 source /usr/share/yunohost/helpers
 
+#=================================================
+# MANAGE SCRIPT FAILURE
+#=================================================
+
+# Exit if an error occurs during the execution of the script
+ynh_abort_if_errors
+
 #=================================================
 # LOAD SETTINGS
 #=================================================
@@ -36,7 +36,7 @@ db_name=$(ynh_app_setting_get $app db_name)
 # CHECK IF THE APP CAN BE RESTORED
 #=================================================
 
-yunohost app checkurl "${domain}${path_url}" -a "$app" \
+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 "
@@ -113,7 +113,7 @@ systemctl enable $app.service
 ynh_restore_file "/etc/cron.d/$app"
 
 #=================================================
-# BACKUP THE LOGROTATE CONFIGURATION
+# RESTORE THE LOGROTATE CONFIGURATION
 #=================================================
 
 ynh_restore_file "/etc/logrotate.d/$app"

+ 24 - 3
scripts/upgrade

@@ -27,19 +27,40 @@ db_name=$(ynh_app_setting_get $app db_name)
 # ENSURE DOWNWARD COMPATIBILITY
 #=================================================
 
+# Fix is_public as a boolean value
 if [ "$is_public" = "Yes" ]; then
-	ynh_app_setting_set $app is_public 1	# Fix is_public as a boolean value
+	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
 
-if [ -z $db_name ]; then	# If db_name doesn't exist, create it
+# 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
 #=================================================
@@ -75,7 +96,7 @@ ynh_system_user_create $app
 #=================================================
 
 # Create a dedicated php-fpm config
-ynh_fpm_config
+ynh_add_fpm_config
 
 #=================================================
 # SPECIFIC UPGRADE