From 5e09b033b1c2828dc47e5b826b061355b626708e Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 4 Jul 2019 13:33:20 +0200 Subject: [PATCH 01/25] add ynh_add_extra_apt_repos__3 --- .../app/ynh_add_extra_apt_repos__3 | 294 ++++++++++++++++++ 1 file changed, 294 insertions(+) create mode 100644 sources/extra_files/app/ynh_add_extra_apt_repos__3 diff --git a/sources/extra_files/app/ynh_add_extra_apt_repos__3 b/sources/extra_files/app/ynh_add_extra_apt_repos__3 new file mode 100644 index 0000000..3276f00 --- /dev/null +++ b/sources/extra_files/app/ynh_add_extra_apt_repos__3 @@ -0,0 +1,294 @@ +#!/bin/bash + +# Pin a repository. +# +# usage: ynh_pin_repo --package=packages --pin=pin_filter [--priority=priority_value] [--name=name] [--append] +# | arg: -p, --package - Packages concerned by the pin. Or all, *. +# | arg: -i, --pin - Filter for the pin. +# | arg: -p, --priority - Priority for the pin +# | arg: -n, --name - Name for the files for this repo, $app as default value. +# | arg: -a, --append - Do not overwrite existing files. +# +# See https://manpages.debian.org/stretch/apt/apt_preferences.5.en.html for information about pinning. +# +ynh_pin_repo () { + # Declare an array to define the options of this helper. + local legacy_args=pirna + declare -Ar args_array=( [p]=package= [i]=pin= [r]=priority= [n]=name= [a]=append ) + local package + local pin + local priority + local name + local append + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + package="${package:-*}" + priority=${priority:-50} + name="${name:-$app}" + append=${append:-0} + + if [ $append -eq 1 ] + then + append="tee -a" + else + append="tee" + fi + + mkdir -p "/etc/apt/preferences.d" + echo "Package: $package +Pin: $pin +Pin-Priority: $priority" \ + | $append "/etc/apt/preferences.d/$name" +} + +# Add a repository. +# +# usage: ynh_add_repo --uri=uri --suite=suite --component=component [--name=name] [--append] +# | arg: -u, --uri - Uri of the repository. +# | arg: -s, --suite - Suite of the repository. +# | arg: -c, --component - Component of the repository. +# | arg: -n, --name - Name for the files for this repo, $app as default value. +# | arg: -a, --append - Do not overwrite existing files. +# +# Example for a repo like deb http://forge.yunohost.org/debian/ stretch stable +# uri suite component +# ynh_add_repo --uri=http://forge.yunohost.org/debian/ --suite=stretch --component=stable +# +ynh_add_repo () { + # Declare an array to define the options of this helper. + local legacy_args=uscna + declare -Ar args_array=( [u]=uri= [s]=suite= [c]=component= [n]=name= [a]=append ) + local uri + local suite + local component + local name + local append + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + name="${name:-$app}" + append=${append:-0} + + if [ $append -eq 1 ] + then + append="tee -a" + else + append="tee" + fi + + mkdir -p "/etc/apt/sources.list.d" + # Add the new repo in sources.list.d + echo "deb $uri $suite $component" \ + | $append "/etc/apt/sources.list.d/$name.list" +} + +# Add an extra repository correctly, pin it and get the key. +# +# usage: ynh_install_extra_repo --repo="repo" [--key=key_url] [--priority=priority_value] [--name=name] [--append] +# | arg: -r, --repo - Complete url of the extra repository. +# | arg: -k, --key - url to get the public key. +# | arg: -p, --priority - Priority for the pin +# | arg: -n, --name - Name for the files for this repo, $app as default value. +# | arg: -a, --append - Do not overwrite existing files. +ynh_install_extra_repo () { + # Declare an array to define the options of this helper. + local legacy_args=rkpna + declare -Ar args_array=( [r]=repo= [k]=key= [p]=priority= [n]=name= [a]=append ) + local repo + local key + local priority + local name + local append + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + name="${name:-$app}" + append=${append:-0} + key=${key:-0} + priority=${priority:-} + + if [ $append -eq 1 ] + then + append="--append" + wget_append="tee -a" + else + append="" + wget_append="tee" + fi + + # Split the repository into uri, suite and components. + # Remove "deb " at the beginning of the repo. + repo="${repo#deb }" + + # Get the uri + local uri="$(echo "$repo" | awk '{ print $1 }')" + + # Get the suite + local suite="$(echo "$repo" | awk '{ print $2 }')" + + # Get the components + local component="${repo##$uri $suite }" + + # Add the repository into sources.list.d + ynh_add_repo --uri="$uri" --suite="$suite" --component="$component" --name="$name" $append + + # Pin the new repo with the default priority, so it won't be used for upgrades. + # Build $pin from the uri without http and any sub path + local pin="${uri#*://}" + pin="${pin%%/*}" + # Set a priority only if asked + if [ -n "$priority" ] + then + priority="--priority=$priority" + fi + ynh_pin_repo --package="*" --pin="origin \"$pin\"" $priority --name="$name" $append + + # Get the public key for the repo + if [ -n "$key" ] + then + mkdir -p "/etc/apt/trusted.gpg.d" + wget -q "$key" -O - | gpg --dearmor | $wget_append /etc/apt/trusted.gpg.d/$name.gpg > /dev/null + fi + + # Update the list of package with the new repo + ynh_package_update +} + +# Remove an extra repository and the assiociated configuration. +# +# usage: ynh_remove_extra_repo [--name=name] +# | arg: -n, --name - Name for the files for this repo, $app as default value. +ynh_remove_extra_repo () { + # Declare an array to define the options of this helper. + local legacy_args=n + declare -Ar args_array=( [n]=name= ) + local name + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + name="${name:-$app}" + + ynh_secure_remove "/etc/apt/sources.list.d/$name.list" + ynh_secure_remove "/etc/apt/preferences.d/$name" + ynh_secure_remove "/etc/apt/trusted.gpg.d/$name.gpg" + ynh_secure_remove "/etc/apt/trusted.gpg.d/$name.asc" + + # Update the list of package to exclude the old repo + ynh_package_update +} + +# Install packages from an extra repository properly. +# +# usage: ynh_install_extra_app_dependencies --repo="repo" --package="dep1 dep2" [--key=key_url] [--name=name] +# | arg: -r, --repo - Complete url of the extra repository. +# | arg: -p, --package - The packages to install from this extra repository +# | arg: -k, --key - url to get the public key. +# | arg: -n, --name - Name for the files for this repo, $app as default value. +ynh_install_extra_app_dependencies () { + # Declare an array to define the options of this helper. + local legacy_args=rpkn + declare -Ar args_array=( [r]=repo= [p]=package= [k]=key= [n]=name= ) + local repo + local package + local key + local name + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + name="${name:-$app}" + key=${key:-0} + + # Set a key only if asked + if [ -n "$key" ] + then + key="--key=$key" + fi + # Add an extra repository for those packages + ynh_install_extra_repo --repo="$repo" $key --priority=995 --name=$name + + # Install requested dependencies from this extra repository. + ynh_add_app_dependencies --package="$package" + + # Remove this extra repository after packages are installed + ynh_remove_extra_repo --name=$app +} + +#================================================= + +# patched version of ynh_install_app_dependencies to be used with ynh_add_app_dependencies + +# Define and install dependencies with a equivs control file +# This helper can/should only be called once per app +# +# usage: ynh_install_app_dependencies dep [dep [...]] +# | arg: dep - the package name to install in dependence +# You can give a choice between some package with this syntax : "dep1|dep2" +# Example : ynh_install_app_dependencies dep1 dep2 "dep3|dep4|dep5" +# This mean in the dependence tree : dep1 & dep2 & (dep3 | dep4 | dep5) +# +# Requires YunoHost version 2.6.4 or higher. +ynh_install_app_dependencies () { + local dependencies=$@ + dependencies="$(echo "$dependencies" | sed 's/\([^\<=\>]\)\ \([^(]\)/\1, \2/g')" + dependencies=${dependencies//|/ | } + local 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 + + local version=$(grep '\"version\": ' "$manifest_path" | cut -d '"' -f 4) # Retrieve the version number in the manifest file. + if [ ${#version} -eq 0 ]; then + version="1.0" + fi + local dep_app=${app//_/-} # Replace all '_' by '-' + + # Handle specific versions + if [[ "$dependencies" =~ [\<=\>] ]] + then + # Replace version specifications by relationships syntax + # https://www.debian.org/doc/debian-policy/ch-relationships.html + # Sed clarification + # [^(\<=\>] ignore if it begins by ( or < = >. To not apply twice. + # [\<=\>] matches < = or > + # \+ matches one or more occurence of the previous characters, for >= or >>. + # [^,]\+ matches all characters except ',' + # Ex: package>=1.0 will be replaced by package (>= 1.0) + dependencies="$(echo "$dependencies" | sed 's/\([^(\<=\>]\)\([\<=\>]\+\)\([^,]\+\)/\1 (\2 \3)/g')" + fi + + cat > /tmp/${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 /tmp/${dep_app}-ynh-deps.control \ + || ynh_die --message="Unable to install dependencies" # Install the fake package and its dependencies + rm /tmp/${dep_app}-ynh-deps.control + ynh_app_setting_set --app=$app --key=apt_dependencies --value="$dependencies" +} + +ynh_add_app_dependencies () { + # Declare an array to define the options of this helper. + local legacy_args=pr + declare -Ar args_array=( [p]=package= [r]=replace) + local package + local replace + # Manage arguments with getopts + ynh_handle_getopts_args "$@" + replace=${replace:-0} + + local current_dependencies="" + if [ $replace -eq 0 ] + then + local dep_app=${app//_/-} # Replace all '_' by '-' + if ynh_package_is_installed --package="${dep_app}-ynh-deps" + then + current_dependencies="$(dpkg-query --show --showformat='${Depends}' ${dep_app}-ynh-deps) " + fi + + current_dependencies=${current_dependencies// | /|} + fi + + ynh_install_app_dependencies "${current_dependencies}${package}" +} From fe85a9375b8984436acc23e4bde7c19a9c29e06d Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 4 Jul 2019 13:44:17 +0200 Subject: [PATCH 02/25] add ynh_install_extra_repo --- scripts/install | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/install b/scripts/install index 5b31c1d..89366aa 100644 --- a/scripts/install +++ b/scripts/install @@ -99,9 +99,9 @@ ynh_print_info "Remove Zabbix if already installed" apt purge zabbix* -y ynh_print_info "Install Zabbix repository" -wget -q "https://repo.zabbix.com/zabbix/4.2/debian/pool/main/z/zabbix-release/zabbix-release_4.2-1%2Bstretch_all.deb" -dpkg -i zabbix-release_*.deb -rm zabbix-release_*.deb +ynh_add_extra_apt_repos__3_path=$(find /var/cache/yunohost/ -name "ynh_add_extra_apt_repos__3") +source "$ynh_add_extra_apt_repos__3_path" +ynh_install_extra_repo --repo=http://repo.zabbix.com/zabbix/4.2/debian --key=https://repo.zabbix.com/zabbix-official-repo.key --priority=999 ynh_print_info "Update and install dependencies" #ynh_package_update no need cause ynh_install_app_dependencies after From 86e912a42c9c3de6e79b03eb189b6258dae1d8c0 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 4 Jul 2019 13:53:55 +0200 Subject: [PATCH 03/25] add ynh_install_extra_repo --- scripts/upgrade | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 2e13060..84b025f 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -111,23 +111,20 @@ if [ $timeout_ok -ne 1 ] ;then systemctl enable zabbix-agent && systemctl restart zabbix-agent fi +#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 + ynh_add_extra_apt_repos__3_path=$(find /var/cache/yunohost/ -name "ynh_add_extra_apt_repos__3") + source "$ynh_add_extra_apt_repos__3_path" + ynh_install_extra_repo --repo=http://repo.zabbix.com/zabbix/4.2/debian --key=https://repo.zabbix.com/zabbix-official-repo.key --priority=999 +fi + #================================================= # STANDARD UPGRADE STEPS #================================================= #REMOVE DUPLICATE LOG ENTRY IN LOGROTATE PATCH IF NEEDED ynh_remove_logrotate -zabbixRepoInstalledVersion=$(apt-cache policy zabbix-release | sed -n '2p' | grep -Po ".*: \K(.*)") - -if [ "$trustedVersionRepo" != "$zabbixRepoInstalledVersion" ];then - DEBIAN_FRONTEND=noninteractive apt remove zabbix-release -y - ynh_print_info "Install New Zabbix repository" - - wget -q "https://repo.zabbix.com/zabbix/4.2/debian/pool/main/z/zabbix-release/zabbix-release_4.2-1%2Bstretch_all.deb" - dpkg -i zabbix-release_*.deb - rm zabbix-release_*.deb -fi - ynh_print_info "Check if new zabbix version is available on repo" ynh_package_update From 7970acccbb3f4d325d81142655eef64bfdf7547a Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 4 Jul 2019 13:54:52 +0200 Subject: [PATCH 04/25] Update backup remove apt backup --- scripts/backup | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/scripts/backup b/scripts/backup index 745ff1b..29016eb 100644 --- a/scripts/backup +++ b/scripts/backup @@ -66,13 +66,4 @@ ynh_backup "/etc/php/7.0/fpm/pool.d/$app.conf" # BACKUP THE MYSQL DATABASE #================================================= -ynh_mysql_dump_db "$db_name" > db.sql - -#================================================= -# SPECIFIC BACKUP -#================================================= -if [ $nonfree ];then - ynh_backup /etc/apt/sources.list.d/non-free.list - ynh_backup /etc/apt/preferences.d -fi - +ynh_mysql_dump_db "$db_name" > db.sql \ No newline at end of file From 92d9310593c33098e8b77101ea58f292b7075d0a Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 4 Jul 2019 13:55:29 +0200 Subject: [PATCH 05/25] add ynh_install_extra_repo --- scripts/restore | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/restore b/scripts/restore index 0e41db4..4ca33a7 100644 --- a/scripts/restore +++ b/scripts/restore @@ -53,9 +53,9 @@ nonfree=$(ynh_app_setting_get $app nonfree) ynh_print_info "Install Zabbix repository" -wget -q "https://repo.zabbix.com/zabbix/4.0/debian/pool/main/z/zabbix-release/zabbix-release_4.0-2+stretch_all.deb" -dpkg -i zabbix-release_*.deb -rm zabbix-release_*.deb +ynh_add_extra_apt_repos__3_path=$(find /var/cache/yunohost/ -name "ynh_add_extra_apt_repos__3") +source "$ynh_add_extra_apt_repos__3_path" +ynh_install_extra_repo --repo=http://repo.zabbix.com/zabbix/4.2/debian --key=https://repo.zabbix.com/zabbix-official-repo.key --priority=999 ynh_print_info "Update and install dependencies" ynh_package_update From 2d080ae3c2cdd31abdc52cecc6eb6d49f5fb711e Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 5 Jul 2019 13:29:02 +0200 Subject: [PATCH 06/25] Update ynh_install_extra_repo --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index 84b025f..11851d3 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -116,7 +116,7 @@ if [ "$(dpkg -l zabbix-release 2>/dev/null | wc -l)" -ne 0 ];then DEBIAN_FRONTEND=noninteractive apt purge zabbix-release -y ynh_add_extra_apt_repos__3_path=$(find /var/cache/yunohost/ -name "ynh_add_extra_apt_repos__3") source "$ynh_add_extra_apt_repos__3_path" - ynh_install_extra_repo --repo=http://repo.zabbix.com/zabbix/4.2/debian --key=https://repo.zabbix.com/zabbix-official-repo.key --priority=999 + ynh_install_extra_repo --repo="http://repo.zabbix.com/zabbix/4.2/debian $(lsb_release -sc) main" --key=https://repo.zabbix.com/zabbix-official-repo.key --priority=999 --name=zabbix fi #================================================= From b0166a2b23ed61dfd2b336dd3adca636ed1f3054 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 5 Jul 2019 13:30:40 +0200 Subject: [PATCH 07/25] Update _common.sh with install_zabbix_repo --- scripts/_common.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/_common.sh b/scripts/_common.sh index d2e99a8..042d78a 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -166,4 +166,10 @@ check_proc_zabbixagent(){ 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(){ + ynh_add_extra_apt_repos__3_path=$(find /var/cache/yunohost/ -name "ynh_add_extra_apt_repos__3") + source "$ynh_add_extra_apt_repos__3_path" + ynh_install_extra_repo --repo="http://repo.zabbix.com/zabbix/4.2/debian $(lsb_release -sc) main" --key=https://repo.zabbix.com/zabbix-official-repo.key --priority=999 --name=zabbix } \ No newline at end of file From 0c0a4f3ac713e1638bfdf3df59eacee627e30fb6 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 5 Jul 2019 13:30:55 +0200 Subject: [PATCH 08/25] Update install with install_zabbix_repo function --- scripts/install | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/install b/scripts/install index 89366aa..02b0ff6 100644 --- a/scripts/install +++ b/scripts/install @@ -99,9 +99,7 @@ ynh_print_info "Remove Zabbix if already installed" apt purge zabbix* -y ynh_print_info "Install Zabbix repository" -ynh_add_extra_apt_repos__3_path=$(find /var/cache/yunohost/ -name "ynh_add_extra_apt_repos__3") -source "$ynh_add_extra_apt_repos__3_path" -ynh_install_extra_repo --repo=http://repo.zabbix.com/zabbix/4.2/debian --key=https://repo.zabbix.com/zabbix-official-repo.key --priority=999 +install_zabbix_repo ynh_print_info "Update and install dependencies" #ynh_package_update no need cause ynh_install_app_dependencies after From 59c60fff9d90de50c59c22af4989d2803c829957 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 5 Jul 2019 13:31:22 +0200 Subject: [PATCH 09/25] Update upgrade with install_zabbix_repo repo --- scripts/upgrade | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 11851d3..1b36f0e 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -114,9 +114,7 @@ fi #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 - ynh_add_extra_apt_repos__3_path=$(find /var/cache/yunohost/ -name "ynh_add_extra_apt_repos__3") - source "$ynh_add_extra_apt_repos__3_path" - ynh_install_extra_repo --repo="http://repo.zabbix.com/zabbix/4.2/debian $(lsb_release -sc) main" --key=https://repo.zabbix.com/zabbix-official-repo.key --priority=999 --name=zabbix + install_zabbix_repo fi #================================================= From b75f12a70724431909c70b59686ff37aa0a410f2 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 5 Jul 2019 13:31:47 +0200 Subject: [PATCH 10/25] Update restore with install_zabbix_repo function --- scripts/restore | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/restore b/scripts/restore index 4ca33a7..81f2c88 100644 --- a/scripts/restore +++ b/scripts/restore @@ -52,10 +52,7 @@ nonfree=$(ynh_app_setting_get $app nonfree) #================================================= ynh_print_info "Install Zabbix repository" - -ynh_add_extra_apt_repos__3_path=$(find /var/cache/yunohost/ -name "ynh_add_extra_apt_repos__3") -source "$ynh_add_extra_apt_repos__3_path" -ynh_install_extra_repo --repo=http://repo.zabbix.com/zabbix/4.2/debian --key=https://repo.zabbix.com/zabbix-official-repo.key --priority=999 +install_zabbix_repo ynh_print_info "Update and install dependencies" ynh_package_update From c406e992014c8c92d289ce79675c42bf54bb721d Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 5 Jul 2019 13:41:54 +0200 Subject: [PATCH 11/25] add file usr_share_zabbix_conf_zabbix.conf.php --- .../app/usr_share_zabbix_conf_zabbix.conf.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 sources/extra_files/app/usr_share_zabbix_conf_zabbix.conf.php diff --git a/sources/extra_files/app/usr_share_zabbix_conf_zabbix.conf.php b/sources/extra_files/app/usr_share_zabbix_conf_zabbix.conf.php new file mode 100644 index 0000000..1f2cbc0 --- /dev/null +++ b/sources/extra_files/app/usr_share_zabbix_conf_zabbix.conf.php @@ -0,0 +1,18 @@ +// Zabbix GUI configuration file. +global \$DB; + +$DB['TYPE'] = 'MYSQL'; +$DB['SERVER'] = 'localhost'; +$DB['PORT'] = '0'; +$DB['DATABASE'] = 'db_name'; +$DB['USER'] = 'db_user'; +$DB['PASSWORD'] = 'db_pwd'; + +// Schema name. Used for IBM DB2 and PostgreSQL. +$DB['SCHEMA'] = ''; + +$ZBX_SERVER = 'localhost'; +$ZBX_SERVER_PORT = '10051'; +$ZBX_SERVER_NAME = 'zabbix-server'; + +$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG; \ No newline at end of file From 66b7af183af80423df5d69b39303d9e3b3d7da47 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 5 Jul 2019 13:42:22 +0200 Subject: [PATCH 12/25] Update usr_share_zabbix_conf_zabbix.conf.php Date: Fri, 5 Jul 2019 13:50:11 +0200 Subject: [PATCH 13/25] Update install avoid sed -i --- scripts/install | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/scripts/install b/scripts/install index 02b0ff6..1b61425 100644 --- a/scripts/install +++ b/scripts/install @@ -275,32 +275,17 @@ systemctl reload nginx ### `ynh_replace_string` is used to replace a string in a file. ### (It's compatible with sed regular expressions syntax) ynh_print_info "Generate zabbix config files" - -echo "/usr/share/zabbix/conf/zabbix.conf.php +confUserPpath=$(find /var/cache/yunohost/ -name "usr_share_zabbix_conf_zabbix.conf.php") +cp "$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 chown -R www-data. /usr/share/zabbix -sed -i "s/DBName=zabbix/DBName=$db_name/g" /etc/zabbix/zabbix_server.conf -sed -i "s/DBUser=zabbix/DBUser=$db_user/g" /etc/zabbix/zabbix_server.conf -sed -i "126a DBPassword=$db_pwd" /etc/zabbix/zabbix_server.conf +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 ynh_replace_string --match_string="# Timeout=3" --replace_string="# Timeout=3\nTimeout=10" --target_file=/etc/zabbix/zabbix_agentd.conf From 0d98305e6805e5d0c7356b60b07054091a005a65 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 5 Jul 2019 13:52:07 +0200 Subject: [PATCH 14/25] Update install avoid sed -i --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 1b61425..7ccf349 100644 --- a/scripts/install +++ b/scripts/install @@ -107,7 +107,7 @@ ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libapru dpkg -i --force-confmiss /var/cache/apt/archives/zabbix-server-mysql* DEBIAN_FRONTEND=noninteractive apt-mark hold zabbix-server-mysql zabbix-frontend-php -sed -i "s/# fr_FR.UTF-8 UTF-8/fr_FR.UTF-8 UTF-8/g" /etc/locale.gen +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" From 05eb062e9d77a781fc2bc33e5412558f9fb83074 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 5 Jul 2019 13:54:40 +0200 Subject: [PATCH 15/25] add comment about ynh_replace_string --- scripts/remove | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/remove b/scripts/remove index 3c6bddf..d8659bc 100644 --- a/scripts/remove +++ b/scripts/remove @@ -114,6 +114,7 @@ ynh_secure_remove "/etc/sudoers.d/zabbix" 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 "Removing snmp-mibs-downloader (non-free package)" + #want backup no ynh_replace_string sed -i.$(date "+%m%d%y") 's/ snmp-mibs-downloader,//g' /var/lib/dpkg/status DEBIAN_FRONTEND=noninteractive apt purge snmp-mibs-downloader -y if [ -f /etc/apt/sources.list.d/non-free.list ];then From ce1048b49a5c0b9795a2a96ea2b3b742b9cd38fa Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 5 Jul 2019 13:55:30 +0200 Subject: [PATCH 16/25] add comment about ynh_replace_string --- scripts/upgrade | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/upgrade b/scripts/upgrade index 1b36f0e..f259b4c 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -97,6 +97,7 @@ path_url=$(ynh_normalize_url_path "$path_url") 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 "Removing snmp-mibs-downloader (non-free package)" + want backup, cannot use ynh_replace_string sed -i.$(date "+%m%d%y") 's/ snmp-mibs-downloader,//g' /var/lib/dpkg/status DEBIAN_FRONTEND=noninteractive apt purge snmp-mibs-downloader -y if [ -f /etc/apt/sources.list.d/non-free.list ];then From 9781f11d71d431ca6176e7db3525a2152ca7d687 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 5 Jul 2019 13:56:21 +0200 Subject: [PATCH 17/25] remove sed -i --- scripts/restore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/restore b/scripts/restore index 81f2c88..d72d507 100644 --- a/scripts/restore +++ b/scripts/restore @@ -60,10 +60,9 @@ ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libapru DEBIAN_FRONTEND=noninteractive apt-mark hold zabbix-server-mysql zabbix-frontend-php -sed -i "s/# fr_FR.UTF-8 UTF-8/fr_FR.UTF-8 UTF-8/g" /etc/locale.gen +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 rm $final_path/conf/zabbix.conf.php From 9e6380ba732260cc7b935d7ef6b3aa1f3f807b47 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 5 Jul 2019 13:59:44 +0200 Subject: [PATCH 18/25] Update upgrade --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index f259b4c..19a061f 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -98,7 +98,7 @@ nonfreepackagelist=$(dpkg-query -W -f='${Section}\t${Package}\n' | grep ^non-fre if [ $(echo $nonfreepackagelist | wc -l) -eq 1 ] && [ $(echo $nonfreepackagelist | grep -c "snmp-mibs-downloader") -eq 1 ] ;then ynh_print_info "Removing snmp-mibs-downloader (non-free package)" want backup, cannot use ynh_replace_string - sed -i.$(date "+%m%d%y") 's/ snmp-mibs-downloader,//g' /var/lib/dpkg/status + sed --in-place==.$(date "+%m%d%y") 's/ snmp-mibs-downloader,//g' /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 From a00b9366a6e5621e52917edc04187bc5da22d171 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 5 Jul 2019 14:00:10 +0200 Subject: [PATCH 19/25] Update remove --- scripts/remove | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/remove b/scripts/remove index d8659bc..09d486c 100644 --- a/scripts/remove +++ b/scripts/remove @@ -115,7 +115,7 @@ nonfreepackagelist=$(dpkg-query -W -f='${Section}\t${Package}\n' | grep ^non-fre if [ $(echo $nonfreepackagelist | wc -l) -eq 1 ] && [ $(echo $nonfreepackagelist | grep -c "snmp-mibs-downloader") -eq 1 ] ;then ynh_print_info "Removing snmp-mibs-downloader (non-free package)" #want backup no ynh_replace_string - sed -i.$(date "+%m%d%y") 's/ snmp-mibs-downloader,//g' /var/lib/dpkg/status + sed --in-place=.$(date "+%m%d%y") 's/ snmp-mibs-downloader,//g' /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 From 604af8fd79e0a712866dc774bb8bb145f1a7c769 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Mon, 8 Jul 2019 13:29:34 +0200 Subject: [PATCH 20/25] add comment ynh_replace_string --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index 19a061f..0536151 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -97,7 +97,7 @@ path_url=$(ynh_normalize_url_path "$path_url") 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 "Removing snmp-mibs-downloader (non-free package)" - want backup, cannot use ynh_replace_string + #want backup file , cannot use ynh_replace_string sed --in-place==.$(date "+%m%d%y") 's/ snmp-mibs-downloader,//g' /var/lib/dpkg/status DEBIAN_FRONTEND=noninteractive apt purge snmp-mibs-downloader -y if [ -f /etc/apt/sources.list.d/non-free.list ];then From 1d82e0ed034419da531503add7ca55abd6ce73f1 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Mon, 8 Jul 2019 13:34:09 +0200 Subject: [PATCH 21/25] ynh_replace_string --- scripts/upgrade | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index 0536151..16e94b2 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -98,7 +98,8 @@ nonfreepackagelist=$(dpkg-query -W -f='${Section}\t${Package}\n' | grep ^non-fre if [ $(echo $nonfreepackagelist | wc -l) -eq 1 ] && [ $(echo $nonfreepackagelist | grep -c "snmp-mibs-downloader") -eq 1 ] ;then ynh_print_info "Removing snmp-mibs-downloader (non-free package)" #want backup file , cannot use ynh_replace_string - sed --in-place==.$(date "+%m%d%y") 's/ snmp-mibs-downloader,//g' /var/lib/dpkg/status + 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 From 15de7fc73fd932ca0ec4472945d2509d2b46e416 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Mon, 8 Jul 2019 13:36:14 +0200 Subject: [PATCH 22/25] Update remove to add ynh_replace_string --- scripts/remove | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/remove b/scripts/remove index 09d486c..d66e7de 100644 --- a/scripts/remove +++ b/scripts/remove @@ -114,8 +114,8 @@ ynh_secure_remove "/etc/sudoers.d/zabbix" 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 "Removing snmp-mibs-downloader (non-free package)" - #want backup no ynh_replace_string - sed --in-place=.$(date "+%m%d%y") 's/ snmp-mibs-downloader,//g' /var/lib/dpkg/status + 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 From 4d42e09c65532d5b5c751f2f1166c0aaa3de0be3 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Mon, 8 Jul 2019 13:53:03 +0200 Subject: [PATCH 23/25] Update to 4.2.4-1+stretch --- scripts/upgrade | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 16e94b2..3535742 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -14,8 +14,7 @@ source /usr/share/yunohost/helpers #================================================= app=$YNH_APP_INSTANCE_NAME -trustedversion="1:4.2.1-1+stretch" -trustedVersionRepo="4.2-1+stretch" +trustedversion="1:4.2.4-1+stretch" 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 From 51a1a6fbfe0c38d5cb236ab41434f073de0cf28b Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Mon, 8 Jul 2019 14:01:13 +0200 Subject: [PATCH 24/25] clean old cache --- scripts/install | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/install b/scripts/install index 7ccf349..4d3d976 100644 --- a/scripts/install +++ b/scripts/install @@ -97,6 +97,7 @@ ynh_app_setting_set "$app" language "$language" ### - And the section "UPGRADE DEPENDENCIES" in the upgrade script ynh_print_info "Remove Zabbix if already installed" apt purge zabbix* -y +rm -fr /var/cache/apt/archives/zabbix-server-mysql* ynh_print_info "Install Zabbix repository" install_zabbix_repo From 9dd84cf45063659c2f95df3ef5f68a4d6d71e38a Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 9 Jul 2019 13:12:21 +0200 Subject: [PATCH 25/25] fix var confServerPath --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 4d3d976..556c1f3 100644 --- a/scripts/install +++ b/scripts/install @@ -276,7 +276,7 @@ systemctl reload nginx ### `ynh_replace_string` is used to replace a string in a file. ### (It's compatible with sed regular expressions syntax) ynh_print_info "Generate zabbix config files" -confUserPpath=$(find /var/cache/yunohost/ -name "usr_share_zabbix_conf_zabbix.conf.php") +confServerPath=$(find /var/cache/yunohost/ -name "usr_share_zabbix_conf_zabbix.conf.php") cp "$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