Procházet zdrojové kódy

Still applying example_ynh

yalh76 před 4 roky
rodič
revize
014f6182b7

+ 0 - 0
sources/extra_files/app/etc_apt_apt.conf.d_100update_force_init_zabbix_frontend_config → conf/100update_force_init_zabbix_frontend_config


+ 0 - 0
sources/extra_files/app/Template_Yunohost.xml → conf/Template_Yunohost.xml


+ 3 - 3
sources/extra_files/app/etc_zabbix_web_init.zabbix.conf.php.sh → conf/init.zabbix.conf.php.sh

@@ -14,9 +14,9 @@ global \$DB, \$HISTORY;
 \$DB['TYPE']                             = 'MYSQL';
 \$DB['SERVER']                   = 'localhost';
 \$DB['PORT']                             = '0';
-\$DB['DATABASE']                 = '"$(yunohost app setting zabbix db_name)"';
-\$DB['USER']                             = '"$(yunohost app setting zabbix db_user)"';
-\$DB['PASSWORD']                 = '"$(yunohost app setting zabbix mysqlpwd)"';
+\$DB['DATABASE']                 = '__DB_NAME__';
+\$DB['USER']                             = '__DB_USER__';
+\$DB['PASSWORD']                 = '__DB_PWD__';
 // Schema name. Used for IBM DB2 and PostgreSQL.
 \$DB['SCHEMA']                   = '';
 

+ 0 - 0
sources/extra_files/app/etc_zabbix_zabbix_agentd.d_userP_yunohost.conf → conf/userP_yunohost.conf


+ 0 - 0
sources/extra_files/app/etc_zabbix_zabbix_agentd.d_yunohost.sh → conf/yunohost.sh


+ 0 - 0
sources/extra_files/app/etc_sudoers.d_zabbix → conf/zabbix


+ 3 - 3
sources/extra_files/app/usr_share_zabbix_conf_zabbix.conf.php → conf/zabbix.conf.php

@@ -5,9 +5,9 @@ global $DB;
 $DB['TYPE']     = 'MYSQL';
 $DB['SERVER']   = 'localhost';
 $DB['PORT']     = '0';
-$DB['DATABASE'] = 'db_name';
-$DB['USER']     = 'db_user';
-$DB['PASSWORD'] = 'db_pwd';
+$DB['DATABASE'] = '__DB_NAME__';
+$DB['USER']     = '__DB_USER__';
+$DB['PASSWORD'] = '__DB_PWD__';
 
 // Schema name. Used for IBM DB2 and PostgreSQL.
 $DB['SCHEMA'] = '';

+ 1 - 7
hooks/post_user_create

@@ -11,12 +11,6 @@ db_user=$(ynh_app_setting_get $app db_user)
 db_pwd=$(ynh_app_setting_get $app mysqlpwd)
 language=$(ynh_app_setting_set $app language) 
 
-if [ "$language" == "fr" ];then
-    lang="fr_FR"
-else
-    lang="en_GB"
-fi
-
 lastid=$(mysql -u$db_user -p$db_pwd $db_name -NB -e "select userid from users order by userid desc limit 1")
 lastid=$((lastid+1))
-mysql -u$db_user -p$db_pwd $db_name -e "INSERT INTO \`users\` (\`userid\`, \`alias\`, \`name\`, \`surname\`, \`passwd\`, \`url\`, \`autologin\`, \`autologout\`, \`lang\`, \`refresh\`, \`type\`, \`theme\`, \`attempt_failed\`, \`attempt_ip\`, \`attempt_clock\`, \`rows_per_page\`) VALUES ("$lastid",'"$user"', '"$name"', '"$surname"', '5fce1b3e34b520afeffb37ce08c7cd66', '', 0, '0', '"$lang"', '30s', 1, 'default', 0, '', 0, 50);"
+mysql -u$db_user -p$db_pwd $db_name -e "INSERT INTO \`users\` (\`userid\`, \`alias\`, \`name\`, \`surname\`, \`passwd\`, \`url\`, \`autologin\`, \`autologout\`, \`lang\`, \`refresh\`, \`type\`, \`theme\`, \`attempt_failed\`, \`attempt_ip\`, \`attempt_clock\`, \`rows_per_page\`) VALUES ("$lastid",'"$user"', '"$name"', '"$surname"', '5fce1b3e34b520afeffb37ce08c7cd66', '', 0, '0', '"$language"', '30s', 1, 'default', 0, '', 0, 50);"

+ 2 - 2
manifest.json

@@ -53,8 +53,8 @@
                     "en": "Choose the application language",
                     "fr": "Choisissez la langue de l'application"
                 },
-                "choices": ["fr", "en"],
-                "default": "en"
+                "choices": ["fr_FR", "en_GB"],
+                "default": "en_GB"
             }
         ]
     }

+ 34 - 33
scripts/_common.sh

@@ -5,7 +5,11 @@
 #=================================================
 
 # dependencies used by the app
-pkg_dependencies="libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php$YNH_DEFAULT_PHP_VERSION php$YNH_DEFAULT_PHP_VERSION-bcmath ttf-dejavu-core php$YNH_DEFAULT_PHP_VERSION-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd libjs-prototype jq zabbix-server-mysql zabbix-agent zabbix-frontend-php"
+pkg_dependencies="libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 ttf-dejavu-core patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd libjs-prototype jq zabbix-server-mysql zabbix-agent zabbix-frontend-php"
+
+YNH_PHP_VERSION="7.3"
+
+extra_php_dependencies="php${YNH_PHP_VERSION}-bcmath"
 
 #=================================================
 # PERSONAL HELPERS
@@ -41,10 +45,8 @@ disable_admin_user(){
         lastid=$((lastid + 1 ))
         $mysqlconn -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 1);"
         ynh_print_info --message="Default admin disabled"
-
     else
         ynh_print_info --message="Default admin already disabled"
-
     fi
 }
 
@@ -60,16 +62,13 @@ enable_admin_user(){
 }
 
 import_template(){
-    ynh_print_info --message="Import yunohost template"
-    
+    ynh_permission_update --permission="main" --add="visitors"
+
+    enable_admin_user
+
     zabbixFullpath=https://$domain$path_url
-    localpath=$(find /var/cache/yunohost/ -name "Template_Yunohost.xml")
-    sudoUserPpath=$(find /var/cache/yunohost/ -name "etc_sudoers.d_zabbix")
-    confUserPpath=$(find /var/cache/yunohost/ -name "etc_zabbix_zabbix_agentd.d_userP_yunohost.conf")
-    bashUserPpath=$(find /var/cache/yunohost/ -name "etc_zabbix_zabbix_agentd.d_yunohost.sh")
-    
-    
-    cp "$sudoUserPpath" /etc/sudoers.d/zabbix
+
+    cp "../conf/zabbix" /etc/sudoers.d/zabbix
     
     if [ -d /etc/zabbix/zabbix_agentd.d ];then
 	    mv /etc/zabbix/zabbix_agentd.d /etc/zabbix/zabbix_agentd.conf.d
@@ -78,8 +77,8 @@ import_template(){
     	ln -s /etc/zabbix/zabbix_agentd.conf.d /etc/zabbix/zabbix_agentd.d
     fi
     
-    cp "$confUserPpath" /etc/zabbix/zabbix_agentd.d/userP_yunohost.conf
-    cp "$bashUserPpath" /etc/zabbix/zabbix_agentd.d/yunohost.sh
+    cp "../conf/userP_yunohost.conf" /etc/zabbix/zabbix_agentd.d/userP_yunohost.conf
+    cp "../conf/yunohost.sh" /etc/zabbix/zabbix_agentd.d/yunohost.sh
     chmod a+x /etc/zabbix/zabbix_agentd.d/yunohost.sh
     
     systemctl restart zabbix-agent
@@ -98,7 +97,7 @@ import_template(){
         
         importState=$(curl $curlOptions \
                         --form "config=1" \
-                        --form "import_file=@$localpath"  \
+                        --form "import_file=@../conf/Template_Yunohost.xml"  \
                         --form "rules[groups][createMissing]=1" \
                         --form "rules[templates][updateExisting]=1" \
                         --form "rules[templates][createMissing]=1" \
@@ -127,14 +126,12 @@ import_template(){
         if [ "$importState" -eq "1" ];then
             ynh_print_info --message="Template Yunohost imported !"
         else
-            ynh_print_warn "Template Yunohost not imported !"
+            ynh_print_warn --message="Template Yunohost not imported !"
         fi
     else
-        ynh_print_warn "Admin user cannot connect interface !"
+        ynh_print_warn --message="Admin user cannot connect interface !"
     fi
-}
 
-link_template(){
     #apply template to host
     tokenapi=$(curl --noproxy $domain -k -s --resolve $domain:443:127.0.0.1 --header "Content-Type: application/json" --request POST --data '{ "jsonrpc": "2.0","method": "user.login","params": {"user": "Admin","password": "zabbix"},"id": 1,"auth": null}' "${zabbixFullpath}/api_jsonrpc.php" | jq -r '.result')
     zabbixHostID=$(curl --noproxy $domain -k -s --resolve $domain:443:127.0.0.1 --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.get","params":{"filter":{"host":["Zabbix server"]}},"auth":"'"$tokenapi"'","id":1}' "${zabbixFullpath}/api_jsonrpc.php" | jq -r '.result[0].hostid')
@@ -143,9 +140,12 @@ link_template(){
     if [ "$applyTemplate" -eq "$zabbixHostID" ];then
         ynh_print_info --message="Template Yunohost linked to Zabbix server !"
     else
-        ynh_print_warn "Template Yunohost no linked to Zabbix server !"
+        ynh_print_warn --message="Template Yunohost no linked to Zabbix server !"
     fi
+    
+    disable_admin_user
 
+    ynh_permission_update --permission="main" --remove="visitors"
 }
 
 check_proc_zabbixserver(){
@@ -159,13 +159,13 @@ check_proc_zabbixserver(){
 }
 
 check_proc_zabbixagent(){
-   pgrep zabbix_agentd >/dev/null
-   if [ $? -eq 0 ];then
-       ynh_print_info --message="zabbix agent is started"
-   else
-       ynh_print_err "Zabbix agent not started, try to start it with the yunohost interface."
-       ynh_print_err "If Zabbix agent can't start, please open a issue on https://github.com/YunoHost-Apps/zabbix_ynh/issues"
-   fi
+    pgrep zabbix_agentd >/dev/null
+    if [ $? -eq 0 ];then
+        ynh_print_info --message="zabbix agent is started"
+    else
+        ynh_print_err "Zabbix agent not started, try to start it with the yunohost interface."
+        ynh_print_err "If Zabbix agent can't start, please open a issue on https://github.com/YunoHost-Apps/zabbix_ynh/issues"
+    fi
 }
 
 install_zabbix_repo(){
@@ -177,14 +177,15 @@ remove_zabbix_repo(){
 }
 
 update_initZabbixConf(){
-        if [ ! -d /etc/zabbix/web ] ;then mkdir -p /etc/zabbix/web ;fi
-        cp $(find /var/cache/yunohost/ -name "etc_zabbix_web_init.zabbix.conf.php.sh") /etc/zabbix/web/init.zabbix.conf.php.sh
-        chmod 700 /etc/zabbix/web/init.zabbix.conf.php.sh
-        cp $(find /var/cache/yunohost/ -name "etc_apt_apt.conf.d_100update_force_init_zabbix_frontend_config") /etc/apt/apt.conf.d/100update_force_init_zabbix_frontend_config
+    if [ ! -d /etc/zabbix/web ] ;then mkdir -p /etc/zabbix/web ;fi
+    ynh_add_config --template="../conf/init.zabbix.conf.php.sh" --destination="/etc/zabbix/web/init.zabbix.conf.php.sh"
+    chmod 700 /etc/zabbix/web/init.zabbix.conf.php.sh
+    ynh_add_config --template="../conf/100update_force_init_zabbix_frontend_config" --destination="/etc/apt/apt.conf.d/100update_force_init_zabbix_frontend_config"
 }
+
 delete_initZabbixConf(){
-        if [ -f /etc/zabbix/web/init.zabbix.conf.php.sh ] ; then ynh_secure_remove /etc/zabbix/web/init.zabbix.conf.php.sh;fi
-        if [ -f /etc/apt/apt.conf.d/100update_force_init_zabbix_frontend_config ] ;then ynh_secure_remove /etc/apt/apt.conf.d/100update_force_init_zabbix_frontend_config ;fi
+    if [ -f /etc/zabbix/web/init.zabbix.conf.php.sh ] ; then ynh_secure_remove --file="/etc/zabbix/web/init.zabbix.conf.php.sh" ;fi
+    if [ -f /etc/apt/apt.conf.d/100update_force_init_zabbix_frontend_config ] ;then ynh_secure_remove --file="/etc/apt/apt.conf.d/100update_force_init_zabbix_frontend_config" ;fi
 }
    
 #Patch timeout too short for zabbix agent if needed

+ 5 - 6
scripts/backup

@@ -30,7 +30,6 @@ app=$YNH_APP_INSTANCE_NAME
 final_path=$(ynh_app_setting_get --app=$app --key=final_path)
 domain=$(ynh_app_setting_get --app=$app --key=domain)
 db_name=$(ynh_app_setting_get --app=$app --key=db_name)
-nonfree=$(ynh_app_setting_get --app=$app --key=nonfree)
 
 #=================================================
 # DECLARE DATA AND CONF FILES TO BACKUP
@@ -53,19 +52,19 @@ ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
 # BACKUP VARIOUS FILES
 #=================================================
 
-#backup frontend config
+# Backup frontend config
 ynh_backup --src_path="$final_path/conf/zabbix.conf.php"
-ynh_backup --src_path="/etc/zabbix/web"
+ynh_backup --src_path="/etc/zabbix"
 ynh_backup --src_path="/etc/apt/apt.conf.d/100update_force_init_zabbix_frontend_config"
 
-#backup server confif
+# Backup server config
 ynh_backup --src_path="/etc/zabbix/zabbix_server.conf"
 
-#backup agent config
+# Backup agent config
 ynh_backup --src_path="/etc/zabbix/zabbix_agentd.conf"
 ynh_backup --src_path="/etc/zabbix/zabbix_agentd.d"
 
-#backup sudo file
+# Backup sudo file
 ynh_backup --src_path="/etc/sudoers.d/zabbix"
 
 #=================================================

+ 35 - 18
scripts/change_url

@@ -8,7 +8,6 @@
 
 source _common.sh
 source /usr/share/yunohost/helpers
-ynh_abort_if_errors
 
 #=================================================
 # RETRIEVE ARGUMENTS
@@ -25,22 +24,32 @@ app=$YNH_APP_INSTANCE_NAME
 #=================================================
 # LOAD SETTINGS
 #=================================================
+ynh_script_progression --message="Loading installation settings..."
 
 # Needed for helper "ynh_add_nginx_config"
-final_path=$(ynh_app_setting_get $app final_path)
+final_path=$(ynh_app_setting_get --app=$app --key=final_path)
 
 # Add settings here as needed by your application
-#db_name=$(ynh_app_setting_get "$app" db_name)
-#db_pwd=$(ynh_app_setting_get $app db_pwd)
+#db_name=$(ynh_app_setting_get --app=$app --key=db_name)
+#db_user=$db_name
+#db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd)
 
 #=================================================
-# CHECK THE SYNTAX OF THE PATHS
+# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP
 #=================================================
+ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..."
+
+# Backup the current version of the app
+ynh_backup_before_upgrade
+ynh_clean_setup () {
+	# Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
+	ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
 
-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)
+	# 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 WHICH PARTS SHOULD BE CHANGED
@@ -63,29 +72,30 @@ fi
 #=================================================
 # MODIFY URL IN NGINX CONF
 #=================================================
+ynh_script_progression --message="Updating NGINX web server configuration..."
 
 nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
 
-# Change the path in the nginx config file
+# 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"
-	# Set global variables for nginx helper
+	# Make a backup of the original NGINX config file if modified
+	ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
+	# Set global variables for NGINX helper
 	domain="$old_domain"
 	path_url="$new_path"
-	# Create a dedicated nginx config
+	# Create a dedicated NGINX config
 	ynh_add_nginx_config
 fi
 
-# Change the domain for nginx
+# 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"
+	ynh_delete_file_checksum --file="$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"
+	ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
 fi
 
 #=================================================
@@ -99,5 +109,12 @@ fi
 #=================================================
 # RELOAD NGINX
 #=================================================
+ynh_script_progression --message="Reloading NGINX web server..."
+
+ynh_systemd_action --service_name=nginx --action=reload
+
+#=================================================
+# END OF SCRIPT
+#=================================================
 
-systemctl reload nginx
+ynh_script_progression --message="Change of URL completed for $app"

+ 51 - 87
scripts/install

@@ -59,14 +59,14 @@ ynh_script_progression --message="Installing dependencies..."
 
 pid=$(pgrep -f '/usr/bin/python3 /usr/bin/unattended-upgrade --download-only' || true)
 if [ ! -z "$pid" ] ;then
-    ynh_script_progression --message="Check and wait end of unattended-upgrade of package_check"
-    tail --pid=$pid -f /dev/null
+	ynh_script_progression --message="Check and wait end of unattended-upgrade of package_check"
+	tail --pid=$pid -f /dev/null
 fi
 
 ynh_script_progression --message="Remove Zabbix if already installed"
 apt-get purge zabbix* -y
 if compgen -G "/var/cache/apt/archives/zabbix-server-mysql*" > /dev/null; then
-    ynh_secure_remove /var/cache/apt/archives/zabbix-server-mysql*
+	ynh_secure_remove  --file="/var/cache/apt/archives/zabbix-server-mysql*"
 fi
 
 ynh_script_progression --message="Install Zabbix repository"
@@ -80,61 +80,15 @@ dpkg -i --force-confmiss /var/cache/apt/archives/zabbix-server-mysql*
 ynh_replace_string --match_string="# fr_FR.UTF-8 UTF-8" --replace_string="fr_FR.UTF-8 UTF-8" --target_file=/etc/locale.gen
 locale-gen
 
-ln -s /usr/share/zabbix "$final_path"
-if [ -f "$final_path/conf/zabbix.conf.php" ];then
-    ynh_secure_remove --file="$final_path/conf/zabbix.conf.php"
-fi
-
 #=================================================
 # CREATE A MYSQL DATABASE
 #=================================================
 ynh_script_progression --message="Creating a MySQL database..."
 
-declare db_pwd
 db_name=$(ynh_sanitize_dbid --db_name=$app)
 db_user=$db_name
 ynh_app_setting_set --app=$app --key=db_name --value=$db_name
 ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name
-export mysqlconn="mysql -u$db_user -p$db_pwd $db_name"
-mysql --user=$db_user --password=$db_pwd --database=zabbix -e "ALTER DATABASE $db_name CHARACTER SET utf8 COLLATE utf8_general_ci;"
-
-ynh_script_progression --message="Import default data in database..."
-
-zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | $mysqlconn
-
-convert_ZabbixDB
-
-#sso integration
-$mysqlconn -e "UPDATE \`config\` SET \`http_auth_enabled\` = '1', \`http_login_form\` = '1' WHERE \`config\`.\`configid\` = 1;"
-
-if [ "$language" == "fr" ];then
-    lang="fr_FR"
-else
-    lang="en_GB"
-fi
-
-#admin creation
-surname=$(ynh_user_get_info "$admin" lastname)
-name=$(ynh_user_get_info "$admin" firstname)
-
-$mysqlconn -e "INSERT INTO \`users\` (\`userid\`,\`alias\`, \`name\`, \`surname\`, \`passwd\`, \`url\`, \`autologin\`, \`autologout\`, \`lang\`, \`refresh\`, \`type\`, \`theme\`, \`attempt_failed\`, \`attempt_ip\`, \`attempt_clock\`, \`rows_per_page\`) VALUES (3,'$admin', '$admin', '$admin', '5fce1b3e34b520afeffb37ce08c7cd66', '', 0, '0', '$lang', '30s', 3, 'default', 0, '', 0, 50);"
-$mysqlconn -e "INSERT INTO \`users_groups\` (\`id\`, \`usrgrpid\`, \`userid\`) VALUES (5, 7, 3);"
-
-#users creation in zabbix database
-i=4
-for user in $(ynh_user_list); 
-do 
-    if [ "$user" != "$admin" ];then
-        surname=$(ynh_user_get_info "$user" lastname)
-        name=$(ynh_user_get_info "$user" firstname)
-        $mysqlconn -e "INSERT INTO \`users\` (\`userid\`, \`alias\`, \`name\`, \`surname\`, \`passwd\`, \`url\`, \`autologin\`, \`autologout\`, \`lang\`, \`refresh\`, \`type\`, \`theme\`, \`attempt_failed\`, \`attempt_ip\`, \`attempt_clock\`, \`rows_per_page\`) VALUES ($i,'$user', '$name', '$surname', '5fce1b3e34b520afeffb37ce08c7cd66', '', 0, '0', '$lang', '30s', 1, 'default', 0, '', 0, 50);"
-        i=$((i+1))
-    fi
-done
-
-disable_guest_user
-
-set_mediatype_default_yunohost
 
 #=================================================
 # DOWNLOAD, CHECK AND UNPACK SOURCE
@@ -142,6 +96,8 @@ set_mediatype_default_yunohost
 ynh_script_progression --message="Setting up source files..."
 
 ynh_app_setting_set --app=$app --key=final_path --value=$final_path
+# Download, check integrity, uncompress and patch the source from app.src
+ln -s /usr/share/zabbix "$final_path"
 
 #=================================================
 # NGINX CONFIGURATION
@@ -157,70 +113,74 @@ ynh_add_nginx_config
 ynh_script_progression --message="Configuring PHP-FPM..."
 
 # Create a dedicated PHP-FPM config
-ynh_add_fpm_config
+ynh_add_fpm_config --package="$extra_php_dependencies"
 phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
 
 #=================================================
 # SPECIFIC SETUP
 #=================================================
-# ADD A CONFIGURATION
+# IMPORT DEFAULT DATA
 #=================================================
-ynh_script_progression --message="Adding a configuration file..."
+ynh_script_progression --message="Import default data in database..."
 
-confServerPath=$(find /var/cache/yunohost/ -name "usr_share_zabbix_conf_zabbix.conf.php")
-cp --remove-destination "$confServerPath" /usr/share/zabbix/conf/zabbix.conf.php
-ynh_replace_string --match_string="db_name" --replace_string="$db_name" --target_file=/usr/share/zabbix/conf/zabbix.conf.php
-ynh_replace_string --match_string="db_user" --replace_string="$db_user" --target_file=/usr/share/zabbix/conf/zabbix.conf.php
-ynh_replace_string --match_string="db_pwd" --replace_string="$db_pwd" --target_file=/usr/share/zabbix/conf/zabbix.conf.php
+export mysqlconn="mysql -u$db_user -p$db_pwd $db_name"
+mysql --user=$db_user --password=$db_pwd --database=zabbix -e "ALTER DATABASE $db_name CHARACTER SET utf8 COLLATE utf8_general_ci;"
 
-chown -R www-data. /usr/share/zabbix
+zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | $mysqlconn
 
-ynh_replace_string --match_string="DBName=zabbix" --replace_string="DBName=$db_name" --target_file=/etc/zabbix/zabbix_server.conf
-ynh_replace_string --match_string="DBUser=zabbix" --replace_string="DBUser=$db_user" --target_file=/etc/zabbix/zabbix_server.conf
-ynh_replace_string --match_string="# DBPassword=" --replace_string="# DBPassword=\nDBPassword=$db_pwd" --target_file=/etc/zabbix/zabbix_server.conf
+convert_ZabbixDB
 
-systemctl enable zabbix-agent --quiet && systemctl restart zabbix-agent
-change_timeoutAgent
-systemctl enable zabbix-server --quiet && systemctl restart zabbix-server
+#sso integration
+$mysqlconn -e "UPDATE \`config\` SET \`http_auth_enabled\` = '1', \`http_login_form\` = '1' WHERE \`config\`.\`configid\` = 1;"
 
-#=================================================
-# INSTALL hook to verify if conf file is broken (after an update for example)
-#=================================================
+#admin creation
+surname=$(ynh_user_get_info "$admin" lastname)
+name=$(ynh_user_get_info "$admin" firstname)
 
-update_initZabbixConf
+$mysqlconn -e "INSERT INTO \`users\` (\`userid\`,\`alias\`, \`name\`, \`surname\`, \`passwd\`, \`url\`, \`autologin\`, \`autologout\`, \`lang\`, \`refresh\`, \`type\`, \`theme\`, \`attempt_failed\`, \`attempt_ip\`, \`attempt_clock\`, \`rows_per_page\`) VALUES (3,'$admin', '$admin', '$admin', '5fce1b3e34b520afeffb37ce08c7cd66', '', 0, '0', '$language', '30s', 3, 'default', 0, '', 0, 50);"
+$mysqlconn -e "INSERT INTO \`users_groups\` (\`id\`, \`usrgrpid\`, \`userid\`) VALUES (5, 7, 3);"
 
-#=================================================
-# SETUP APPLICATION WITH CURL
-#=================================================
-ynh_script_progression --message="Setuping application with CURL..."
+#users creation in zabbix database
+i=4
+for user in $(ynh_user_list); 
+do 
+	if [ "$user" != "$admin" ];then
+		surname=$(ynh_user_get_info "$user" lastname)
+		name=$(ynh_user_get_info "$user" firstname)
+		$mysqlconn -e "INSERT INTO \`users\` (\`userid\`, \`alias\`, \`name\`, \`surname\`, \`passwd\`, \`url\`, \`autologin\`, \`autologout\`, \`lang\`, \`refresh\`, \`type\`, \`theme\`, \`attempt_failed\`, \`attempt_ip\`, \`attempt_clock\`, \`rows_per_page\`) VALUES ($i,'$user', '$name', '$surname', '5fce1b3e34b520afeffb37ce08c7cd66', '', 0, '0', '$language', '30s', 1, 'default', 0, '', 0, 50);"
+		i=$((i+1))
+	fi
+done
+
+disable_guest_user
 
-# Set the app as temporarily public for curl call
-ynh_script_progression --message="Configuring SSOwat..."
-# Making the app public for curl
-ynh_permission_update --permission="main" --add="visitors"
+set_mediatype_default_yunohost
 
 #=================================================
-# Import Yunohost template
+# ADD A CONFIGURATION
 #=================================================
-ynh_script_progression --message="Importing last template Yunohost in Zabbix"
+ynh_script_progression --message="Adding a configuration file..."
 
-import_template
+ynh_add_config --template="../conf/zabbix.conf.php" --destination="/usr/share/zabbix/conf/zabbix.conf.php"
+
+chown -R www-data. /usr/share/zabbix
+
+ynh_replace_string --match_string="DBName=zabbix" --replace_string="DBName=$db_name" --target_file=/etc/zabbix/zabbix_server.conf
+ynh_replace_string --match_string="DBUser=zabbix" --replace_string="DBUser=$db_user" --target_file=/etc/zabbix/zabbix_server.conf
+ynh_replace_string --match_string="# DBPassword=" --replace_string="# DBPassword=\nDBPassword=$db_pwd" --target_file=/etc/zabbix/zabbix_server.conf
 
 #=================================================
-# Link Yunohost template to the ZAbbix Server Host
+# INSTALL hook to verify if conf file is broken (after an update for example)
 #=================================================
-ynh_script_progression --message="Importing last template Yunohost in Zabbix"
 
-link_template
+update_initZabbixConf
 
 #=================================================
-# disable default admin 
+# IMPORT YUNOHOST TEMPLATE
 #=================================================
+ynh_script_progression --message="Importing YunoHost template in Zabbix"
 
-disable_admin_user
-
-# Remove the public access
-ynh_permission_update --permission="main" --remove="visitors"
+import_template
 
 #=================================================
 # GENERIC FINALIZATION
@@ -238,6 +198,10 @@ yunohost service add zabbix-agent --description="Management Zabbix agent daemon
 #=================================================
 ynh_script_progression --message="Starting a systemd service..."
 
+systemctl enable zabbix-agent --quiet && systemctl restart zabbix-agent
+change_timeoutAgent
+systemctl enable zabbix-server --quiet && systemctl restart zabbix-server
+
 #test if zabbix server is started
 check_proc_zabbixagent
 

+ 45 - 44
scripts/remove

@@ -32,6 +32,20 @@ yunohost service remove snmpd
 yunohost service remove zabbix-server
 yunohost service remove zabbix-agent
 
+#=================================================
+# STOP AND REMOVE SERVICE
+#=================================================
+ynh_script_progression --message="Stopping and removing the systemd service..."
+
+# Remove the dedicated systemd config
+timeout 5 systemctl stop zabbix-server || killall zabbix_server
+systemctl disable zabbix-server --quiet
+killall zabbix_server
+
+timeout 5 systemctl stop zabbix-agent || killall zabbix_agentd
+systemctl disable zabbix-agent --quiet
+killall zabbix_agentd
+
 #=================================================
 # REMOVE THE MYSQL DATABASE
 #=================================================
@@ -40,6 +54,35 @@ ynh_script_progression --message="Removing the MySQL database..."
 # Remove a database if it exists, along with the associated user
 ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name
 
+#=================================================
+# REMOVE DEPENDENCIES
+#=================================================
+ynh_script_progression --message="Removing dependencies..."
+
+# Remove config file detection
+delete_initZabbixConf
+
+DEBIAN_FRONTEND=noninteractive apt-get purge zabbix-release -y
+
+# Remove metapackage and its dependencies
+ynh_remove_app_dependencies
+
+# Force removing if ynh_remove_app_dependencies not work (old zabbix version)
+for zabbix_pkg in $(apt list --installed | grep -Po "\K(zabbix-.*)(?=/)")
+do
+	DEBIAN_FRONTEND=noninteractive apt-get purge --allow-change-held-packages "$zabbix_pkg" -y
+done
+
+remove_zabbix_repo
+
+#=================================================
+# REMOVE APP MAIN DIR
+#=================================================
+ynh_script_progression --message="Removing app main directory..."
+
+# Remove the app directory securely
+ynh_secure_remove --file="$final_path"
+
 #=================================================
 # REMOVE NGINX CONFIGURATION
 #=================================================
@@ -56,31 +99,6 @@ ynh_script_progression --message="Removing PHP-FPM configuration..."
 # Remove the dedicated PHP-FPM config
 ynh_remove_fpm_config
 
-#=================================================
-# REMOVE DEPENDENCIES
-#=================================================
-ynh_script_progression --message="Removing dependencies..."
-
-timeout 5 systemctl stop zabbix-server || killall zabbix_server
-systemctl disable zabbix-server --quiet
-killall zabbix_server
-
-timeout 5 systemctl stop zabbix-agent || killall zabbix_agentd
-systemctl disable zabbix-agent --quiet
-killall zabbix_agentd
-
-#Remove config file detection
-delete_initZabbixConf
-
-DEBIAN_FRONTEND=noninteractive apt-get purge zabbix-release -y
-ynh_remove_app_dependencies
-
-#force removing if ynh_remove_app_dependencies not work (old zabbix version)
-for zabbix_pkg in $(apt list --installed | grep -Po "\K(zabbix-.*)(?=/)")
-do
-    DEBIAN_FRONTEND=noninteractive apt-get purge --allow-change-held-packages "$zabbix_pkg" -y
-done
-
 #=================================================
 # SPECIFIC REMOVE
 #=================================================
@@ -88,15 +106,11 @@ done
 #=================================================
 ynh_script_progression --message="Removing various files..."
 
-remove_zabbix_repo
-
-if [ -d /var/www/zabbix ] ;then ynh_secure_remove /var/www/zabbix;fi
-
 # Remove a directory securely
-if [ -d /etc/zabbix ] ;then ynh_secure_remove --file="/etc/zabbix";fi
+if [ -d /etc/zabbix ] ;then ynh_secure_remove --file="/etc/$app";fi
 
 # Remove the log files
-if [ -d /var/log/zabbix ] ;then ynh_secure_remove --file="/var/log/zabbix";fi
+if [ -d /var/log/zabbix ] ;then ynh_secure_remove --file="/var/log/$app";fi
 
 # Remove the pid/socket files
 if [ -d /run/zabbix ] ;then ynh_secure_remove --file="/run/zabbix";fi
@@ -104,19 +118,6 @@ if [ -d /run/zabbix ] ;then ynh_secure_remove --file="/run/zabbix";fi
 # Remove the sudoers file
 if [ -f /etc/sudoers.d/zabbix ] ;then ynh_secure_remove --file="/etc/sudoers.d/zabbix";fi
 
-
-#REMOVE NONFREE PART PATCH IF NEEDED (snmp-mibs-downloader (non-free) installed in version 1)
-nonfreepackagelist=$(dpkg-query -W -f='${Section}\t${Package}\n' | grep ^non-free)
-if [ $(echo $nonfreepackagelist | wc -l) -eq 1 ] && [ $(echo $nonfreepackagelist | grep -c "snmp-mibs-downloader") -eq 1 ] ;then 
-	ynh_print_info --message="Removing snmp-mibs-downloader (non-free package)"
-    cp /var/lib/dpkg/status{,.$(date "+%m%d%y")}
-    ynh_replace_string --match_string=" snmp-mibs-downloader," --replace_string="" --target_file=/var/lib/dpkg/status
-    DEBIAN_FRONTEND=noninteractive apt purge snmp-mibs-downloader -y
-    if [ -f /etc/apt/sources.list.d/non-free.list ];then
-        ynh_secure_remove /etc/apt/sources.list.d/non-free.list
-    fi
-fi
-
 #=================================================
 # GENERIC FINALIZATION
 #=================================================

+ 22 - 18
scripts/restore

@@ -30,7 +30,6 @@ is_public=$(ynh_app_setting_get --app=$app --key=is_public)
 db_name=$(ynh_app_setting_get --app=$app --key=db_name)
 db_user=$db_name
 phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
-nonfree=$(ynh_app_setting_get --app=$app --key=nonfree)
 
 #=================================================
 # CHECK IF THE APP CAN BE RESTORED
@@ -48,6 +47,13 @@ ynh_script_progression --message="Restoring the NGINX web server configuration..
 
 ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
 
+#=================================================
+# RESTORE THE APP MAIN DIR
+#=================================================
+ynh_script_progression --message="Restoring the app main directory..."
+
+ln -s /usr/share/zabbix /var/www/zabbix
+
 #=================================================
 # RESTORE THE PHP-FPM CONFIGURATION
 #=================================================
@@ -71,9 +77,6 @@ DEBIAN_FRONTEND=noninteractive apt-mark hold zabbix-server-mysql zabbix-frontend
 ynh_replace_string --match_string="# fr_FR.UTF-8 UTF-8" --replace_string="fr_FR.UTF-8 UTF-8" --target_file=/etc/locale.gen
 locale-gen
 
-ln -s /usr/share/zabbix /var/www/zabbix
-ynh_secure_remove $final_path/conf/zabbix.conf.php
-
 #=================================================
 # RESTORE THE MYSQL DATABASE
 #=================================================
@@ -81,32 +84,32 @@ ynh_script_progression --message="Restoring the MySQL database..."
 
 db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
 ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
-convert_ZabbixDB
 ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
+convert_ZabbixDB
 
 #=================================================
 # RESTORE VARIOUS FILES
 #=================================================
 ynh_script_progression --message="Restoring various files..."
 
-# Restore sudo file
-ynh_restore_file --origin_path="/etc/sudoers.d/zabbix"
-
-ynh_restore_file --origin_path="/usr/share/zabbix/conf/zabbix.conf.php"
-
+# Restore  frontend config
+ynh_restore_file --origin_path="$final_path/conf/zabbix.conf.php"
 chown -R www-data. /usr/share/zabbix
-
 ynh_restore_file --origin_path="/etc/zabbix"
 ls -Rail "/etc/zabbix"
-
 ynh_restore_file --origin_path="/etc/apt/apt.conf.d/100update_force_init_zabbix_frontend_config"
+
+# Restore server config
+ynh_restore_file --origin_path="/etc/zabbix/zabbix_server.conf"
+
+# Restore  agent config
+ynh_restore_file --origin_path="/etc/zabbix/zabbix_agentd.conf"
 if [ ! -L /etc/zabbix/zabbix_agentd.d ];then
-    	ln -s /etc/zabbix/zabbix_agentd.conf.d /etc/zabbix/zabbix_agentd.d
+		ln -s /etc/zabbix/zabbix_agentd.conf.d /etc/zabbix/zabbix_agentd.d
 fi
 
-systemctl enable --quiet zabbix-agent && systemctl restart zabbix-agent
-change_timeoutAgent
-systemctl enable --quiet zabbix-server && systemctl restart zabbix-server
+# Restore sudo file
+ynh_restore_file --origin_path="/etc/sudoers.d/zabbix"
 
 #=================================================
 # INTEGRATE SERVICE IN YUNOHOST
@@ -122,8 +125,9 @@ yunohost service add zabbix-agent --description="Management Zabbix agent daemon
 #=================================================
 ynh_script_progression --message="Starting a systemd service..."
 
-# Reload SSOwat config
-yunohost app ssowatconf
+systemctl enable --quiet zabbix-agent && systemctl restart zabbix-agent
+change_timeoutAgent
+systemctl enable --quiet zabbix-server && systemctl restart zabbix-server
 
 #test if zabbix server is started
 check_proc_zabbixagent

+ 121 - 158
scripts/upgrade

@@ -12,221 +12,184 @@ source /usr/share/yunohost/helpers
 #=================================================
 # LOAD SETTINGS
 #=================================================
+ynh_script_progression --message="Loading installation settings..."
 
 app=$YNH_APP_INSTANCE_NAME
-trustedversion="4.4-1+stretch"
-forceupdate=0
-export domain=$(ynh_app_setting_get "$app" domain)
-export path_url=$(ynh_app_setting_get "$app" path)
-#admin=$(ynh_app_setting_get "$app" admin) #not used
-is_public=$(ynh_app_setting_get "$app" is_public)
-final_path=$(ynh_app_setting_get "$app" final_path)
-#language=$(ynh_app_setting_get "$app" language) #not used
-db_name=$(ynh_app_setting_get "$app" db_name)
-db_user=$(ynh_app_setting_get "$app" db_user)
-db_pwd=$(ynh_app_setting_get "$app" mysqlpwd)
+
+domain=$(ynh_app_setting_get --app=$app --key=domain)
+path_url=$(ynh_app_setting_get --app=$app --key=path)
+is_public=$(ynh_app_setting_get --app=$app --key=is_public)
+final_path=$(ynh_app_setting_get --app=$app --key=final_path)
+db_name=$(ynh_app_setting_get --app=$app --key=db_name)
+db_user=$db_name
+phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
 
 #=================================================
-# ENSURE DOWNWARD COMPATIBILITY
+# CHECK VERSION
 #=================================================
+ynh_script_progression --message="Checking version..."
 
-# 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
-
-# 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
-
-export mysqlconn="mysql -u$db_user -p$db_pwd $db_name"
+upgrade_type=$(ynh_check_app_version_changed)
 
 #=================================================
-# DISABLED SSOWAT
+# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
 #=================================================
-ynh_print_info "disable SSOWAT temporaly"
-ynh_app_setting_set "$app" unprotected_uris "/"
-systemctl reload nginx
-yunohost app ssowatconf
+ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
 
-#=================================================
-# Enable default admin temporaly
-#=================================================
-enable_admin_user
+# 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
 
 #=================================================
-# Import Yunohost template
-#=================================================
-import_template
-
+# STANDARD UPGRADE STEPS
 #=================================================
-# Link Yunohost template to the ZAbbix Server Host
+# STOP SYSTEMD SERVICE
 #=================================================
-link_template
+ynh_script_progression --message="Stopping a systemd service..."
 
-#=================================================
-# Disable default admin for security issue
-#=================================================
-disable_admin_user
+yunohost service stop zabbix-server
+yunohost service stop zabbix-agent
 
 #=================================================
-# Disable default guest for security issue
+# ENSURE DOWNWARD COMPATIBILITY
 #=================================================
+ynh_script_progression --message="Ensuring downward compatibility..."
+
+export mysqlconn="mysql -u$db_user -p$db_pwd $db_name"
+
 disable_guest_user
 
 #Patch timeout too short for zabbix agent if needed
 change_timeoutAgent  
 
-#patch if zabbix-release installed
-if [ "$(dpkg -l zabbix-release 2>/dev/null | wc -l)" -ne 0 ];then
-    DEBIAN_FRONTEND=noninteractive apt purge zabbix-release -y
-    install_zabbix_repo
-fi
-
-#patch if zabbix-release has Candidate version but no Installed version
-if [ -f "/etc/apt/sources.list.d/zabbix.list" ];then
-    if [ "$(grep -c "4.2" /etc/apt/sources.list.d/zabbix.list)" -eq 1 ];then
-        install_zabbix_repo
-        forceupdate=1
-    fi
-fi
+ynh_remove_logrotate
 
-#patch to remove old zabbix-client service
-if [ ! -z "$(yunohost service status | grep zabbix-client)" ];then 
-    ynh_print_info "remove zabbix-client old service"
-    yunohost service remove zabbix-client
+# Cleaning legacy permissions
+if ynh_legacy_permissions_exists; then
+	ynh_legacy_permissions_delete_all
 fi
 
 #=================================================
-# STANDARD UPGRADE STEPS
+# NGINX CONFIGURATION
 #=================================================
-#REMOVE DUPLICATE LOG ENTRY IN LOGROTATE PATCH IF NEEDED
-ynh_remove_logrotate
+ynh_script_progression --message="Upgrading NGINX web server configuration..."
 
-ynh_print_info "Check if new zabbix version is available on repo"
-ynh_package_update
+# Create a dedicated NGINX config
+ynh_add_nginx_config
 
-zabbixReleaseInstalledVersion=$(apt-cache policy zabbix-release | sed -n '2p' | grep -Po ".* \K(.*)")
+#=================================================
+# UPGRADE DEPENDENCIES
+#=================================================
+ynh_script_progression --message="Upgrading dependencies..."
 
-if [[ "$trustedversion" > "$zabbixReleaseInstalledVersion" ]] || [[ "$forceupdate" == "1" ]]
-then
-	    #=================================================
-	    # 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
-
-#=================================================
-# Migrate legacy permissions to new system
-#=================================================
-if ynh_legacy_permissions_exists
+if [ "$upgrade_type" == "UPGRADE_APP" ]
 then
-	ynh_legacy_permissions_delete_all
+	cp -rp /etc/zabbix /tmp/
+	cp -p /usr/share/zabbix/conf/zabbix.conf.php /tmp/
 
-	ynh_app_setting_delete --app=$app --key=is_public
-fi
-	    
-	    yunohost service stop zabbix-server
-	    yunohost service stop zabbix-agent
-	    
-	    cp -rp /etc/zabbix /tmp/
-	    cp -p /usr/share/zabbix/conf/zabbix.conf.php /tmp/
-	    
-	    DEBIAN_FRONTEND=noninteractive apt-mark unhold zabbix-server-mysql zabbix-frontend-php
-	    ynh_package_remove zabbix-server-mysql zabbix-frontend-php
-
-        ynh_print_info "Update zabbix via apt package"
-		ynh_install_app_dependencies $pkg_dependencies	    
-	    ynh_secure_remove /usr/share/zabbix/conf/zabbix.conf.php
-	    cp -rpf /tmp/zabbix /etc/
-	    cp -pf /tmp/zabbix.conf.php /usr/share/zabbix/conf/
-	    
-	    ynh_secure_remove /tmp/zabbix*
-	    
-	    #If needed.
-	    yunohost service add snmpd -d "Management of SNMP Daemon"
-        yunohost service add zabbix-server -d "Management Zabbix server daemon : Collect, agregate, compute and notify"
-        yunohost service add zabbix-agent -d "Management Zabbix agent daemon : send informations about this host to the server"
-	    
-	    yunohost service start zabbix-server
-	    yunohost service start zabbix-agent
-	    
-	    #test if zabbix server is started
-        check_proc_zabbixagent
-        
-        #test if zabbix agent is started
-        check_proc_zabbixserver
-
-else
-	ynh_print_info "No repo update ! (Trusted version)"
+	DEBIAN_FRONTEND=noninteractive apt-mark unhold zabbix-server-mysql zabbix-frontend-php
+	ynh_package_remove zabbix-server-mysql zabbix-frontend-php
+
+	ynh_script_progression --message="Install Zabbix repository"
+	install_zabbix_repo
+
+	ynh_print_info "Update zabbix via apt package"
+	ynh_install_app_dependencies $pkg_dependencies		
+	ynh_secure_remove  --file="/usr/share/zabbix/conf/zabbix.conf.php"
+	cp -rpf /tmp/zabbix /etc/
+	cp -pf /tmp/zabbix.conf.php /usr/share/zabbix/conf/
+
+	ynh_secure_remove  --file="/tmp/zabbix*"
 fi
 
+#=================================================
+# PHP-FPM CONFIGURATION
+#=================================================
+ynh_script_progression --message="Upgrading PHP-FPM configuration..."
+
+# Create a dedicated PHP-FPM config
+ynh_add_fpm_config --package="$extra_php_dependencies"
+
+#=================================================
+# SPECIFIC UPGRADE
 #=================================================
 # INSTALL hook to verify if conf file is broken (after an update for example)
 #=================================================
+
 update_initZabbixConf
 
 #=================================================
 # Update db to utf8
 #=================================================
+
 convert_ZabbixDB
 
 #=================================================
 # Add settings for yunohost mail server
 #=================================================
+
 set_mediatype_default_yunohost
 
 #=================================================
-# Update php-fpm confi
+# IMPORT YUNOHOST TEMPLATE
 #=================================================
-ynh_print_info "Update php-fpm config"
-# Remove the dedicated php-fpm config
-ynh_remove_fpm_config
-# Create a dedicated php-fpm config
-ynh_add_fpm_config
+ynh_script_progression --message="Importing YunoHost template in Zabbix"
+
+import_template
 
 #=================================================
-# Update nginx config
+# GENERIC FINALIZATION
 #=================================================
-ynh_print_info "Update nginx config"
-# Remove the dedicated nginx config
-ynh_remove_nginx_config
-# Create a dedicated nginx config
-ynh_add_nginx_config
+# SETUP SSOWAT
+#=================================================
+ynh_script_progression --message="Configuring permissions..."
+
+# Make app public if necessary
+if [ $is_public -eq 1 ]
+then
+	# Everyone can access the app.
+	# The "main" permission is automatically created before the install script.
+	ynh_permission_update --permission="main" --add="visitors"
+fi
 
+#=================================================
+# INTEGRATE SERVICE IN YUNOHOST
+#=================================================
+ynh_script_progression --message="Integrating service in YunoHost..."
+
+yunohost service add snmpd --description="Management of SNMP Daemon"
+yunohost service add zabbix-server --description="Management Zabbix server daemon : Collect, agregate, compute and notify"
+yunohost service add zabbix-agent --description="Management Zabbix agent daemon : send informations about this host to the server"
 
 #=================================================
-# RE-ENABLE SSOWAT
+# START SYSTEMD SERVICE
 #=================================================
-ynh_print_info "re-enable SSOWAT"
-# Make app private if necessary
-if [ $is_public -eq 0 ]
-then
-    # unprotected_uris allows SSO credentials to be passed anyway.
-    ynh_app_setting_delete "$app" unprotected_uris
-else
-    ynh_app_setting_set "$app" unprotected_uris "/"
-fi
+ynh_script_progression --message="Starting a systemd service..."
 
-ynh_add_nginx_config
-systemctl reload nginx
-yunohost app ssowatconf
+systemctl enable zabbix-agent --quiet && systemctl restart zabbix-agent
+change_timeoutAgent
+systemctl enable zabbix-server --quiet && systemctl restart zabbix-server
+
+#test if zabbix server is started
+check_proc_zabbixagent
+
+#test if zabbix agent is started
+check_proc_zabbixserver
+
+#=================================================
+# RELOAD NGINX
+#=================================================
+ynh_script_progression --message="Reloading NGINX web server..."
+
+ynh_systemd_action --service_name=nginx --action=reload
+
+#=================================================
+# END OF SCRIPT
+#=================================================
+
+ynh_script_progression --message="Upgrade of $app completed"

+ 0 - 2
sources/extra_files/app/.gitignore

@@ -1,2 +0,0 @@
-*~
-*.sw[op]

+ 0 - 2
sources/patches/.gitignore

@@ -1,2 +0,0 @@
-*~
-*.sw[op]