From db61b46915201ab558d1aabb42fe2f3fa704ecf1 Mon Sep 17 00:00:00 2001 From: "spam@librement-votre.fr" Date: Mon, 18 Feb 2019 13:13:09 +0100 Subject: [PATCH 001/144] Merge testing with RC2.0 --- README.md | 9 +- manifest.json | 3 +- scripts/backup | 3 + scripts/install | 106 +++++++++++++-- scripts/remove | 18 ++- scripts/restore | 5 + scripts/upgrade | 121 +++++++++++++++++- sources/extra_files/app/Template_Yunohost.xml | 39 ++++-- sources/extra_files/app/etc_sudoers.d_zabbix | 1 + ...zabbix_zabbix_agentd.d_userP_yunohost.conf | 12 ++ .../etc_zabbix_zabbix_agentd.d_yunohost.sh | 60 +++++++++ 11 files changed, 339 insertions(+), 38 deletions(-) create mode 100644 sources/extra_files/app/etc_sudoers.d_zabbix create mode 100644 sources/extra_files/app/etc_zabbix_zabbix_agentd.d_userP_yunohost.conf create mode 100644 sources/extra_files/app/etc_zabbix_zabbix_agentd.d_yunohost.sh diff --git a/README.md b/README.md index bc9f4d5..fd1a450 100644 --- a/README.md +++ b/README.md @@ -24,11 +24,14 @@ Are LDAP auth supported Only Debian - Stretch 64b supported actually. ## Limitations - +Do not change admin password. ## Additional information -* Other information you would add about this application +* Do not change the default admin user password. The user is disabled juste after the install but used to update templates. +* The Zabbix server port is not opened by default for external monitoring (active agent). +* Install or update apply a template yunohost on the host "Zabbix-server" (127.0.0.1) for basic monitoring for Yunohost. +* If you want more information about Yunohost in the template, please open an issue on git. **More information on the documentation page:** https://yunohost.org/packaging_apps @@ -41,4 +44,4 @@ got to https://framagit.org/Mickael-Martin/zabbix_ynh/blob/master/LICENSE ## Links * Report a bug: https://framagit.org/Mickael-Martin/zabbix_ynh/issues - * YunoHost website: https://yunohost.org/ \ No newline at end of file + * YunoHost website: https://yunohost.org/ diff --git a/manifest.json b/manifest.json index 56ceb13..04cd064 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "YunoHost port for Zabbix", "fr": "Zabbix pour Yunohost" }, - "version": "1.2.1", + "version": "2.0", "url": "https://framagit.org/Mickael-Martin/zabbix_ynh", "license": "free", "maintainer": { @@ -21,6 +21,7 @@ "services": [ "nginx", "mysql", + "php7.0-fpm", "snmpd" ], "arguments": { diff --git a/scripts/backup b/scripts/backup index 0f2ad47..300cbbb 100644 --- a/scripts/backup +++ b/scripts/backup @@ -46,6 +46,9 @@ ynh_backup "/etc/zabbix/zabbix_server.conf" ynh_backup "/etc/zabbix/zabbix_agentd.conf" ynh_backup "/etc/zabbix/zabbix_agentd.d" +#backup sudo file +ynh_backup "/etc/sudoers.d/zabbix" + #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= diff --git a/scripts/install b/scripts/install index 21525bc..f4cac42 100644 --- a/scripts/install +++ b/scripts/install @@ -74,6 +74,9 @@ ynh_app_setting_set $app language $language ### If you're not using these lines: ### - Remove the section "CLOSE A PORT" in the remove script +### Zabbix server is not opened by default for external usage. +### if you want use zabbix server with external agent (in active mode), setup the listen address in server configuration and open port on firewall via the cmd yunohost firewall + # Find a free port #port=$(ynh_find_port 8095) # Open this port @@ -96,7 +99,7 @@ dpkg -i zabbix-release_*.deb rm zabbix-release_*.deb echo "deb http://deb.debian.org/debian stretch non-free" >/etc/apt/sources.list.d/non-free.list ynh_package_update -ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd snmp-mibs-downloader libjs-prototype zabbix-server-mysql zabbix-agent +ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd snmp-mibs-downloader libjs-prototype zabbix-server-mysql zabbix-agent jq yunohost service add snmpd -d "Management of SNMP Daemon" DEBIAN_FRONTEND=noninteractive apt-get -y download zabbix-frontend-php ar x *.deb @@ -153,7 +156,7 @@ name=$(ynh_user_get_info $admin firstname) 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 (3,'"$admin"', '"$admin"', '"$admin"', '5fce1b3e34b520afeffb37ce08c7cd66', '', 0, '0', '"$lang"', '30s', 3, 'default', 0, '', 0, 50);" mysql -u$db_user -p$db_pwd $db_name -e "INSERT INTO \`users_groups\` (\`id\`, \`usrgrpid\`, \`userid\`) VALUES (5, 7, 3);" -#users creation +#users creation in zabbix database i=4 for u in $(ynh_user_list); do @@ -165,11 +168,6 @@ do fi done -#disable default admin -lastid=$(mysql -u$db_user -p$db_pwd $db_name -BN -e "SELECT max(id) from \`users_groups\`") -lastid=$(($lastid + 1 )) -mysql -u$db_user -p$db_pwd $db_name -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 1);" - #disable default guest lastid=$(mysql -u$db_user -p$db_pwd $db_name -BN -e "SELECT max(id) from \`users_groups\`") lastid=$(($lastid + 1 )) @@ -202,6 +200,8 @@ ynh_add_nginx_config # Create a system user #ynh_system_user_create $app +# +### zabbix user created in zabbix server dpkg install #================================================= # PHP-FPM CONFIGURATION @@ -245,6 +245,8 @@ ynh_add_fpm_config # Create a dedicated systemd config #ynh_add_systemd_config +### Systemd service created when dpkg install + #================================================= # SETUP APPLICATION WITH CURL #================================================= @@ -310,6 +312,10 @@ sed -i "126a DBPassword=$db_pwd" /etc/zabbix/zabbix_server.conf systemctl enable zabbix-server && systemctl start zabbix-server +yunohost service add zabbix-server -d "Management of Zabbix Server - Monitoring server" +yunohost service add zabbix-agent -d "Management of Zabbix Agent" + + #================================================= # STORE THE CONFIG FILE CHECKSUM #================================================= @@ -376,7 +382,91 @@ then fi #================================================= -# RELOAD NGINX +# RELOAD NGINX AND PHP-FPM #================================================= systemctl reload nginx +systemctl reload php7.0-fpm + +# Reload SSOwat config +yunohost app ssowatconf + +#================================================= +# Import Yunohost template +#================================================= +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 $confUserPpath /etc/zabbix/zabbix_agentd.d/userP_yunohost.conf +cp $bashUserPpath /etc/zabbix/zabbix_agentd.d/yunohost.sh +chmod a+x /etc/zabbix/zabbix_agentd.d/yunohost.sh + +systemctl restart zabbix-agent + +curl -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ + --form enter=Sign+in \ + --form name=Admin \ + --form password=zabbix \ + "$zabbixFullpath/index.php" + +sid=$(curl -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ + "$zabbixFullpath/conf.import.php?rules_preset=template" \ + | grep -Po 'name="sid" value="\K([a-z0-9]{16})(?=")' ) + +importState=$(curl -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ + --form "config=1" \ + --form "import_file=@$localpath" \ + --form rules[groups][createMissing]=1 \ + --form rules[templates][updateExisting]=1 \ + --form rules[templates][createMissing]=1 \ + --form rules[templateScreens][updateExisting]=1 \ + --form rules[templateScreens][createMissing]=1 \ + --form rules[templateLinkage][createMissing]=1 \ + --form rules[applications][createMissing]=1 \ + --form rules[items][updateExisting]=1 \ + --form rules[items][createMissing]=1 \ + --form rules[discoveryRules][updateExisting]=1 \ + --form rules[discoveryRules][createMissing]=1 \ + --form rules[triggers][updateExisting]=1 \ + --form rules[triggers][createMissing]=1 \ + --form rules[graphs][updateExisting]=1 \ + --form rules[graphs][createMissing]=1 \ + --form rules[httptests][updateExisting]=1 \ + --form rules[httptests][createMissing]=1 \ + --form rules[valueMaps][createMissing]=1 \ + --form "import=Import" \ + --form "backurl=templates.php" \ + --form "form_refresh=1" \ + --form "sid=${sid}" \ \ + "${zabbixFullpath}/conf.import.php?rules_preset=template" \ + | grep -c "Imported successfully") + +if [ "$importState" -eq "1" ];then + ynh_print_info "Template Yunohost imported !" +else + ynh_print_warn "Template Yunohost not imported !" +fi + +#apply template to host +tokenapi=$(curl -k -s --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 -k -s --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') +zabbixTemplateID=$(curl -k -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"template.get","params":{"filter":{"host":["Template Yunohost"]}},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result[0].templateid') +applyTemplate=$(curl -k -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.massadd","params":{"hosts":[{"hostid":"'$zabbixHostID'"}],"templates":[{"templateid":"'$zabbixTemplateID'"}]},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result.hostids[]') +if [ "$applyTemplate" -eq "$zabbixHostID" ];then + ynh_print_info "Template Yunohost linked to Zabbix server !" +else + ynh_print_warn "Template Yunohost no linked to Zabbix server !" +fi + + +#================================================= +# disable default admin +#================================================= + +lastid=$(mysql -u$db_user -p$db_pwd $db_name -BN -e "SELECT max(id) from \`users_groups\`") +lastid=$(($lastid + 1 )) +mysql -u$db_user -p$db_pwd $db_name -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 1);" diff --git a/scripts/remove b/scripts/remove index e0b99b8..83a8bcd 100644 --- a/scripts/remove +++ b/scripts/remove @@ -37,11 +37,8 @@ yunohost service remove snmpd #================================================= # Remove a service from the admin panel, added by `yunohost service add` -if yunohost service status | grep -q $app -then - echo "Remove $app service" - yunohost service remove $app -fi +yunohost service remove zabbix-server +yunohost service remove zabbix-agent #================================================= # REMOVE PHP-FPM CONFIGURATION @@ -50,6 +47,8 @@ fi # Remove the dedicated php-fpm config ynh_remove_fpm_config +systemctl reload php7.0-fpm + #================================================= # REMOVE DEPENDENCIES #================================================= @@ -83,6 +82,12 @@ ynh_mysql_remove_db $db_user $db_name # Remove the dedicated nginx config ynh_remove_nginx_config +#================================================= +# RELOAD NGINX +#================================================= + +systemctl reload nginx + #================================================= # REMOVE LOGROTATE CONFIGURATION #================================================= @@ -115,6 +120,9 @@ ynh_secure_remove "/var/log/zabbix" # Remove the pid/socket files ynh_secure_remove "/run/zabbix" +# Remove the sudoers file +ynh_secure_remove "/etc/sudoers.d/zabbix" + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/restore b/scripts/restore index 5bfcb92..2bc111d 100644 --- a/scripts/restore +++ b/scripts/restore @@ -75,6 +75,9 @@ rm $final_path/conf/zabbix.conf.php ynh_app_setting_set $app final_path $final_path +yunohost service add zabbix-server -d "Management of Zabbix Server - Monitoring server" +yunohost service add zabbix-agent -d "Management of Zabbix Agent" + #================================================= # NGINX CONFIGURATION #================================================= @@ -91,6 +94,8 @@ ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf" +# Restore sudo file +ynh_restore_file "/etc/sudoers.d/zabbix" # Reload SSOwat config yunohost app ssowatconf diff --git a/scripts/upgrade b/scripts/upgrade index 7c1cce4..02173a4 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -51,21 +51,113 @@ if [ -z $final_path ]; then ynh_app_setting_set $app final_path $final_path fi +#================================================= +# Enable default admin temporaly +#================================================= +haveDefaultAdminDisabled=$(mysql -BN -u$db_user -p$db_pwd $db_name -BN -e "SELECT count(id) from \`users_groups\` where userid=1 and usrgrpid=9") + +if [ "$haveDefaultAdminDisabled" -eq 1 ] ;then + ynh_print_info "Enable default admin" + #enable default admin temporaly + mysql -u$db_user -p$db_pwd $db_name -e "DELETE FROM users_groups where usrgrpid=9 and userid=1;" +else + ynh_print_info "default admin already enabled" +fi + +#================================================= +# Import Yunohost template +#================================================= +ynh_print_info "Import Yunohost template" +#disable sso temporaly +ynh_app_setting_set $app unprotected_uris "/" +systemctl reload nginx +yunohost app ssowatconf + +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 $confUserPpath /etc/zabbix/zabbix_agentd.d/userP_yunohost.conf +cp $bashUserPpath /etc/zabbix/zabbix_agentd.d/yunohost.sh +chmod a+x /etc/zabbix/zabbix_agentd.d/yunohost.sh + +systemctl restart zabbix-agent + +curl -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ + --form enter=Sign+in \ + --form name=Admin \ + --form password=zabbix \ + "$zabbixFullpath/index.php" + +sid=$(curl -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ + "$zabbixFullpath/conf.import.php?rules_preset=template" \ + | grep -Po 'name="sid" value="\K([a-z0-9]{16})(?=")' ) + +importState=$(curl -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ + --form "config=1" \ + --form "import_file=@$localpath" \ + --form rules[groups][createMissing]=1 \ + --form rules[templates][updateExisting]=1 \ + --form rules[templates][createMissing]=1 \ + --form rules[templateScreens][updateExisting]=1 \ + --form rules[templateScreens][createMissing]=1 \ + --form rules[templateLinkage][createMissing]=1 \ + --form rules[applications][createMissing]=1 \ + --form rules[items][updateExisting]=1 \ + --form rules[items][createMissing]=1 \ + --form rules[discoveryRules][updateExisting]=1 \ + --form rules[discoveryRules][createMissing]=1 \ + --form rules[triggers][updateExisting]=1 \ + --form rules[triggers][createMissing]=1 \ + --form rules[graphs][updateExisting]=1 \ + --form rules[graphs][createMissing]=1 \ + --form rules[httptests][updateExisting]=1 \ + --form rules[httptests][createMissing]=1 \ + --form rules[valueMaps][createMissing]=1 \ + --form "import=Import" \ + --form "backurl=templates.php" \ + --form "form_refresh=1" \ + --form "sid=${sid}" \ \ + "${zabbixFullpath}/conf.import.php?rules_preset=template" \ + | grep -c "Imported successfully") + +if [ "$importState" -eq "1" ];then + ynh_print_info "Template Yunohost imported !" +else + ynh_print_warn "Template Yunohost not imported !" +fi + +#apply template to host +tokenapi=$(curl -k -s --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 -k -s --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') +zabbixTemplateID=$(curl -k -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"template.get","params":{"filter":{"host":["Template Yunohost"]}},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result[0].templateid') +applyTemplate=$(curl -k -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.massadd","params":{"hosts":[{"hostid":"'$zabbixHostID'"}],"templates":[{"templateid":"'$zabbixTemplateID'"}]},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result.hostids[]') +if [ "$applyTemplate" -eq "$zabbixHostID" ];then + ynh_print_info "Template Yunohost linked to Zabbix server !" +else + ynh_print_warn "Template Yunohost no linked to Zabbix server !" +fi + + #================================================= # Disable default admin for security issue #================================================= haveDefaultAdminDisabled=$(mysql -BN -u$db_user -p$db_pwd $db_name -BN -e "SELECT count(id) from \`users_groups\` where userid=1 and usrgrpid=9") if [ "$haveDefaultAdminDisabled" -eq 0 ] ;then - echo "Disable default admin" + ynh_print_info "Disable default admin" #disable default admin lastid=$(mysql -u$db_user -p$db_pwd $db_name -BN -e "SELECT max(id) from \`users_groups\`") lastid=$(($lastid + 1 )) mysql -u$db_user -p$db_pwd $db_name -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 1);" else - echo "default admin already disabled" + ynh_print_info "default admin already disabled" fi + #================================================= # Disable default guest for security issue #================================================= @@ -91,7 +183,7 @@ path_url=$(ynh_normalize_url_path $path_url) #================================================= # STANDARD UPGRADE STEPS #================================================= - +ynh_print_info "Check if new zabbix version is available on repo" ynh_package_update #REMOVE DUPLICATE LOG ENTRY IN LOGROTATE PATCH IF NEEDED @@ -144,11 +236,26 @@ then cp -pf /tmp/zabbix.conf.php /usr/share/zabbix/conf/ rm -fr /tmp/zabbix* - - systemctl reload nginx + else - ynh_print_info "Nothing to update ! (Already up to date)" + ynh_print_info "No update from repo ! (Already up to date)" fi else - ynh_print_info "Nothing to update ! (Trusted version)" + ynh_print_info "No update from repo ! (Trusted version)" fi + +#================================================= +# RE-ENABLE SSOWAT +#================================================= +ynh_print_info "re-enable SSOWAT" +# Make app public if necessary +if [ $is_public -eq 1 ] +then + # unprotected_uris allows SSO credentials to be passed anyway. + ynh_app_setting_set $app unprotected_uris "/" +else + ynh_app_setting_set $app unprotected_uris "" +fi + +systemctl reload nginx +yunohost app ssowatconf diff --git a/sources/extra_files/app/Template_Yunohost.xml b/sources/extra_files/app/Template_Yunohost.xml index f7121a0..ef98bcf 100644 --- a/sources/extra_files/app/Template_Yunohost.xml +++ b/sources/extra_files/app/Template_Yunohost.xml @@ -1,7 +1,7 @@ 4.0 - 2019-01-15T12:48:48Z + 2019-01-31T12:45:57Z Templates/Applications @@ -32,7 +32,6 @@ cat /etc/zabbix/zabbix_agentd.d/yunohost.sh #!/bin/bash yunobin=$(which yunohost) - if [ "$1" == "yunohost.users.discover" ];then users=$($yunobin user list --fields 'uid' | awk -F ': ' '/username: / {print $2}');echo -n "{\"data\":[";for user in $users;do echo -n "{\"{#USERNAME}\":\"$user\"},";done | sed 's/,$//' ;echo "]}" fi @@ -42,37 +41,45 @@ if [ "$1" == "yunohost.user.quota" ] ;then fi if [ "$1" == "yunohost.domains.discover" ] ;then - domains=$($yunobin domain list --plain);echo -n "{\"data\":[";for domain in $domains;do echo -n "{\"{#DOMAIN}\":\"$domain\"},";done | sed 's/,$//' ;echo "]}" + domains=$($yunobin domain list --output-as plain);echo -n "{\"data\":[";for domain in $domains;do echo -n "{\"{#DOMAIN}\":\"$domain\"},";done | sed 's/,$//' ;echo "]}" fi if [ "$1" == "yunohost.domain.cert" ] ;then - $yunobin domain cert-status "$2" --plain | awk '/#/{ next;} {printf "%s;",$0} END {print ""}' + $yunobin domain cert-status "$2" --output-as plain --full| awk '/#/{ next;} {printf "%s;",$0} END {print ""}' fi if [ "$1" == "yunohost.services.discover" ] ;then - services=$($yunobin service status | grep -Po '^([A-Za-z]+)(?=(:))');echo -n "{\"data\":[";for service in $services;do echo -n "{\"{#SERVICE}\":\"$service\"},";done | sed 's/,$//' ;echo "]}" + services=$($yunobin service status 2>/dev/null| grep -Po '^([A-Za-z]+)(?=(:))');echo -n "{\"data\":[";for service in $services;do echo -n "{\"{#SERVICE}\":\"$service\"},";done | sed 's/,$//' ;echo "]}" fi if [ "$1" == "yunohost.service.status" ] ;then - $yunobin service status "$2" --plain | awk '/#/{ next;} {printf "%s;",$0} END {print ""}' + service=$($yunobin service status "$2" --output-as json 2>/dev/null) + if [[ "$(echo $service | jq -r '.description')" == *"doesn't exists for systemd"* ]] ;then + echo "$service" | jq -c '.active = "disabled"' + else + echo "$service" + fi fi if [ "$1" == "yunohost.backups.number" ] ;then - $yunobin backup list --plain | wc -l + $yunobin backup list --output-as plain | wc -l fi if [ "$1" == "yunohost.backups.ageoflastbackup" ] ;then - timestamp=$(date +"%d/%m/%Y %H:%M" -d"$($yunobin backup list -i | tail -n 4 | head -n 1 | grep -Po 'created_at: \K(.*)')") - echo $(( ($(date +%s) - $(date -d"$timestamp" +%s))/(60*60*24) )) + if [ $($yunobin backup list --output-as plain | wc -l) -ne 0 ] ;then + timestamp=$(date +"%d/%m/%Y %H:%M" -d"$($yunobin backup list -i | tail -n 4 | head -n 1 | grep -Po 'created_at: \K(.*)')") + echo $(( ($(date +%s) - $(date -d"$timestamp" +%s))/(60*60*24) )) + else + echo "No backup detected" + fi fi - if [ "$1" == "yunohost.ports.tcp.discovery" ] ;then - ports=$($yunobin firewall list -r --plain | awk '/#ipv4/{flag=1;next}/#uPnP/{flag=0}flag' | awk '/##TCP/{flag=1;next}/##TCP/{flag=0}flag');echo -n "{\"data\":[";for port in $ports;do echo -n "{\"{#PORT}\":\"$port\"},";done | sed 's/,$//' ;echo "]}" + ports=$($yunobin firewall list -r --output-as plain | awk '/#ipv4/{flag=1;next}/#uPnP/{flag=0}flag' | awk '/##TCP/{flag=1;next}/##TCP/{flag=0}flag');echo -n "{\"data\":[";for port in $ports;do echo -n "{\"{#PORT}\":\"$port\"},";done | sed 's/,$//' ;echo "]}" fi if [ "$1" == "yunohost.ports.udp.discovery" ] ;then - ports=$($yunobin firewall list -r --plain | awk '/#ipv4/{flag=1;next}/#uPnP/{flag=0}flag' | awk '/##UDP/{flag=1;next}/##TCP/{flag=0}flag');echo -n "{\"data\":[";for port in $ports;do echo -n "{\"{#PORT}\":\"$port\"},";done | sed 's/,$//' ;echo "]}" + ports=$($yunobin firewall list -r --output-as plain | awk '/#ipv4/{flag=1;next}/#uPnP/{flag=0}flag' | awk '/##UDP/{flag=1;next}/##TCP/{flag=0}flag');echo -n "{\"data\":[";for port in $ports;do echo -n "{\"{#PORT}\":\"$port\"},";done | sed 's/,$//' ;echo "]}" fi if [ "$1" == "yunohost.migrations.lastinstalled" ] ;then @@ -962,10 +969,14 @@ fi + + 12 + $.active + 5 - (.*);(.*);(.*);(.*);(.*);(.*);(.*); -\6:inactive=0:active=1:unknown=2;disabled=3 + (.*) +\1:inactive=0:active=1:unknown=2;disabled=3 5 diff --git a/sources/extra_files/app/etc_sudoers.d_zabbix b/sources/extra_files/app/etc_sudoers.d_zabbix new file mode 100644 index 0000000..ce70ecb --- /dev/null +++ b/sources/extra_files/app/etc_sudoers.d_zabbix @@ -0,0 +1 @@ +zabbix ALL=(ALL) NOPASSWD: /etc/zabbix/zabbix_agentd.d/yunohost.sh diff --git a/sources/extra_files/app/etc_zabbix_zabbix_agentd.d_userP_yunohost.conf b/sources/extra_files/app/etc_zabbix_zabbix_agentd.d_userP_yunohost.conf new file mode 100644 index 0000000..3070897 --- /dev/null +++ b/sources/extra_files/app/etc_zabbix_zabbix_agentd.d_userP_yunohost.conf @@ -0,0 +1,12 @@ +UserParameter=yunohost.users.discover,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.users.discover +UserParameter=yunohost.user.quota[*],sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.user.quota "$1" +UserParameter=yunohost.domains.discover,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.domains.discover +UserParameter=yunohost.domain.cert[*],sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.domain.cert "$1" +UserParameter=yunohost.services.discover,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.services.discover +UserParameter=yunohost.service.status[*],sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.service.status "$1" +UserParameter=yunohost.backups.number,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.backups.number +UserParameter=yunohost.backups.ageoflastbackup,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.backups.ageoflastbackup +UserParameter=yunohost.ports.tcp.discover,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.ports.tcp.discovery +UserParameter=yunohost.ports.udp.discover,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.ports.udp.discovery +UserParameter=yunohost.migrations.lastinstalled,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.migrations.lastinstalled +UserParameter=yunohost.migrations.lastavailable,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.migrations.lastavailable \ No newline at end of file diff --git a/sources/extra_files/app/etc_zabbix_zabbix_agentd.d_yunohost.sh b/sources/extra_files/app/etc_zabbix_zabbix_agentd.d_yunohost.sh new file mode 100644 index 0000000..c6859d3 --- /dev/null +++ b/sources/extra_files/app/etc_zabbix_zabbix_agentd.d_yunohost.sh @@ -0,0 +1,60 @@ +#!/bin/bash +yunobin=$(which yunohost) + +if [ "$1" == "yunohost.users.discover" ];then + users=$($yunobin user list --fields 'uid' | awk -F ': ' '/username: / {print $2}');echo -n "{\"data\":[";for user in $users;do echo -n "{\"{#USERNAME}\":\"$user\"},";done | sed 's/,$//' ;echo "]}" +fi + +if [ "$1" == "yunohost.user.quota" ] ;then + quota=$($yunobin user info "$2" | grep -Po "use:.*\(\K([0-9]{1,3})");if [ -z "$quota" ];then echo 0 ; else echo "$quota" ;fi +fi + +if [ "$1" == "yunohost.domains.discover" ] ;then + domains=$($yunobin domain list --output-as plain);echo -n "{\"data\":[";for domain in $domains;do echo -n "{\"{#DOMAIN}\":\"$domain\"},";done | sed 's/,$//' ;echo "]}" +fi + +if [ "$1" == "yunohost.domain.cert" ] ;then + $yunobin domain cert-status "$2" --output-as plain --full| awk '/#/{ next;} {printf "%s;",$0} END {print ""}' +fi + +if [ "$1" == "yunohost.services.discover" ] ;then + services=$($yunobin service status 2>/dev/null| grep -Po '^([A-Za-z]+)(?=(:))');echo -n "{\"data\":[";for service in $services;do echo -n "{\"{#SERVICE}\":\"$service\"},";done | sed 's/,$//' ;echo "]}" +fi + +if [ "$1" == "yunohost.service.status" ] ;then + service=$($yunobin service status "$2" --output-as json 2>/dev/null) + if [[ "$(echo $service | jq -r '.description')" == *"doesn't exists for systemd"* ]] ;then + echo "$service" | jq -c '.active = "disabled"' + else + echo "$service" + fi +fi + +if [ "$1" == "yunohost.backups.number" ] ;then + $yunobin backup list --output-as plain | wc -l +fi + +if [ "$1" == "yunohost.backups.ageoflastbackup" ] ;then + if [ $($yunobin backup list --output-as plain | wc -l) -ne 0 ] ;then + timestamp=$(date +"%d/%m/%Y %H:%M" -d"$($yunobin backup list -i | tail -n 4 | head -n 1 | grep -Po 'created_at: \K(.*)')") + echo $(( ($(date +%s) - $(date -d"$timestamp" +%s))/(60*60*24) )) + else + echo "No backup detected" + fi +fi + +if [ "$1" == "yunohost.ports.tcp.discovery" ] ;then + ports=$($yunobin firewall list -r --output-as plain | awk '/#ipv4/{flag=1;next}/#uPnP/{flag=0}flag' | awk '/##TCP/{flag=1;next}/##TCP/{flag=0}flag');echo -n "{\"data\":[";for port in $ports;do echo -n "{\"{#PORT}\":\"$port\"},";done | sed 's/,$//' ;echo "]}" +fi + +if [ "$1" == "yunohost.ports.udp.discovery" ] ;then + ports=$($yunobin firewall list -r --output-as plain | awk '/#ipv4/{flag=1;next}/#uPnP/{flag=0}flag' | awk '/##UDP/{flag=1;next}/##TCP/{flag=0}flag');echo -n "{\"data\":[";for port in $ports;do echo -n "{\"{#PORT}\":\"$port\"},";done | sed 's/,$//' ;echo "]}" +fi + +if [ "$1" == "yunohost.migrations.lastinstalled" ] ;then + $yunobin tools migrations state | grep -Po " number: \K(.*)" +fi + +if [ "$1" == "yunohost.migrations.lastavailable" ] ;then + $yunobin tools migrations list | tail -n 1 | grep -Po " number: \K(.*)" +fi \ No newline at end of file From a74911a5e376e1660bc3c850f60c65447c1ab82c Mon Sep 17 00:00:00 2001 From: root Date: Thu, 21 Feb 2019 20:41:49 +0100 Subject: [PATCH 002/144] change quote for posix validation --- scripts/install | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/install b/scripts/install index f4cac42..8a2f0e4 100644 --- a/scripts/install +++ b/scripts/install @@ -452,10 +452,10 @@ else fi #apply template to host -tokenapi=$(curl -k -s --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 -k -s --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') -zabbixTemplateID=$(curl -k -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"template.get","params":{"filter":{"host":["Template Yunohost"]}},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result[0].templateid') -applyTemplate=$(curl -k -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.massadd","params":{"hosts":[{"hostid":"'$zabbixHostID'"}],"templates":[{"templateid":"'$zabbixTemplateID'"}]},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result.hostids[]') +tokenapi=$(curl -k -s --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 -k -s --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') +zabbixTemplateID=$(curl -k -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"template.get","params":{"filter":{"host":["Template Yunohost"]}},"auth":"'"$tokenapi"'","id":1}' "${zabbixFullpath}/api_jsonrpc.php" | jq -r '.result[0].templateid') +applyTemplate=$(curl -k -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.massadd","params":{"hosts":[{"hostid":"'"$zabbixHostID"'"}],"templates":[{"templateid":"'"$zabbixTemplateID"'"}]},"auth":"'"$tokenapi"'","id":1}' "${zabbixFullpath}/api_jsonrpc.php" | jq -r '.result.hostids[]') if [ "$applyTemplate" -eq "$zabbixHostID" ];then ynh_print_info "Template Yunohost linked to Zabbix server !" else From 165a8d84016429daa71da8155aef88d8c2f1fcea Mon Sep 17 00:00:00 2001 From: root Date: Thu, 21 Feb 2019 20:43:42 +0100 Subject: [PATCH 003/144] add double quote for posix validation --- scripts/upgrade | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 02173a4..bd4f7f8 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -131,10 +131,10 @@ else fi #apply template to host -tokenapi=$(curl -k -s --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 -k -s --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') -zabbixTemplateID=$(curl -k -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"template.get","params":{"filter":{"host":["Template Yunohost"]}},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result[0].templateid') -applyTemplate=$(curl -k -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.massadd","params":{"hosts":[{"hostid":"'$zabbixHostID'"}],"templates":[{"templateid":"'$zabbixTemplateID'"}]},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result.hostids[]') +tokenapi=$(curl -k -s --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 -k -s --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') +zabbixTemplateID=$(curl -k -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"template.get","params":{"filter":{"host":["Template Yunohost"]}},"auth":"'"$tokenapi"'","id":1}' "${zabbixFullpath}/api_jsonrpc.php" | jq -r '.result[0].templateid') +applyTemplate=$(curl -k -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.massadd","params":{"hosts":[{"hostid":"'"$zabbixHostID"'"}],"templates":[{"templateid":"'"$zabbixTemplateID"'"}]},"auth":"'"$tokenapi"'","id":1}' "${zabbixFullpath}/api_jsonrpc.php" | jq -r '.result.hostids[]') if [ "$applyTemplate" -eq "$zabbixHostID" ];then ynh_print_info "Template Yunohost linked to Zabbix server !" else From 42b4e9ac19076c68ff284f32e911c043f3df1e76 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 25 Feb 2019 09:57:09 +0100 Subject: [PATCH 004/144] Fix manifest for : *Cleanup YEP as possible *Make zabbix private by default --- manifest.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/manifest.json b/manifest.json index 04cd064..ef43492 100644 --- a/manifest.json +++ b/manifest.json @@ -7,7 +7,7 @@ "fr": "Zabbix pour Yunohost" }, "version": "2.0", - "url": "https://framagit.org/Mickael-Martin/zabbix_ynh", + "url": "https://www.zabbix.com", "license": "free", "maintainer": { "name": "Mickael Martin", @@ -61,10 +61,11 @@ "en": "Is it a public application?", "fr": "Est-ce une application publique ?" }, - "default": true + "default": false }, { "name": "language", + "type": "string", "ask": { "en": "Choose the application language", "fr": "Choisissez la langue de l'application" From b2487c77fe3d1a20eb6104575a4380606d316ed6 Mon Sep 17 00:00:00 2001 From: Mickael Date: Mon, 25 Feb 2019 14:25:29 +0100 Subject: [PATCH 005/144] add shebangs --- scripts/install | 3 ++- scripts/restore | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 8a2f0e4..cc6ebc1 100644 --- a/scripts/install +++ b/scripts/install @@ -1,4 +1,5 @@ -#================================================= +#!/bin/bash +##================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS diff --git a/scripts/restore b/scripts/restore index 2bc111d..f8514e2 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,3 +1,4 @@ +#!/bin/bash #================================================= # GENERIC START #================================================= From be5a0042234b729db003e381762df46d4ca23900 Mon Sep 17 00:00:00 2001 From: Mickael Date: Mon, 25 Feb 2019 15:26:23 +0100 Subject: [PATCH 006/144] make script compatible with shellcheck (package not tested actually) --- scripts/backup | 2 +- scripts/install | 147 ++++++++++++++++++++++++------------------------ scripts/remove | 12 ++-- scripts/restore | 22 ++++---- scripts/upgrade | 114 ++++++++++++++++++------------------- 5 files changed, 149 insertions(+), 148 deletions(-) diff --git a/scripts/backup b/scripts/backup index 300cbbb..e644781 100644 --- a/scripts/backup +++ b/scripts/backup @@ -6,7 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= -source ../settings/scripts/_common.sh +source _common.sh source /usr/share/yunohost/helpers #================================================= diff --git a/scripts/install b/scripts/install index cc6ebc1..e166aef 100644 --- a/scripts/install +++ b/scripts/install @@ -19,11 +19,11 @@ ynh_abort_if_errors # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= -domain=$YNH_APP_ARG_DOMAIN -path_url=$YNH_APP_ARG_PATH -admin=$YNH_APP_ARG_ADMIN -is_public=$YNH_APP_ARG_IS_PUBLIC -language=$YNH_APP_ARG_LANGUAGE +domain="$YNH_APP_ARG_DOMAIN" +path_url="$YNH_APP_ARG_PATH" +admin="$YNH_APP_ARG_ADMIN" +is_public="$YNH_APP_ARG_IS_PUBLIC" +language="$YNH_APP_ARG_LANGUAGE" ### If it's a multi-instance app, meaning it can be installed several times independently ### The id of the app as stated in the manifest is available as $YNH_APP_ID @@ -35,7 +35,7 @@ language=$YNH_APP_ARG_LANGUAGE ### The app instance name is probably what interests you most, since this is ### guaranteed to be unique. This is a good unique identifier to define installation path, ### db names, ... -app=$YNH_APP_INSTANCE_NAME +app="$YNH_APP_INSTANCE_NAME" #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS @@ -47,22 +47,22 @@ final_path=/var/www/zabbix 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) +path_url=$(ynh_normalize_url_path "$path_url") # Check web path availability -ynh_webpath_available $domain $path_url +ynh_webpath_available "$domain" "$path_url" # Register (book) web path -ynh_webpath_register $app $domain $path_url +ynh_webpath_register "$app" "$domain" "$path_url" #================================================= # STORE SETTINGS FROM MANIFEST #================================================= -ynh_app_setting_set $app domain $domain -ynh_app_setting_set $app path $path_url -ynh_app_setting_set $app admin $admin -ynh_app_setting_set $app is_public $is_public -ynh_app_setting_set $app language $language +ynh_app_setting_set "$app" domain "$domain" +ynh_app_setting_set "$app" path "$path_url" +ynh_app_setting_set "$app" admin "$admin" +ynh_app_setting_set "$app" is_public "$is_public" +ynh_app_setting_set "$app" language "$language" #================================================= # STANDARD MODIFICATIONS @@ -103,7 +103,7 @@ ynh_package_update ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd snmp-mibs-downloader libjs-prototype zabbix-server-mysql zabbix-agent jq yunohost service add snmpd -d "Management of SNMP Daemon" DEBIAN_FRONTEND=noninteractive apt-get -y download zabbix-frontend-php -ar x *.deb +ar x ./*.deb tar xzf control.tar.gz sed -i 's/apache2 | httpd, //' control tar --ignore-failed-read -cvzf control.tar.gz {post,pre}{inst,rm} md5sums control @@ -117,8 +117,8 @@ DEBIAN_FRONTEND=noninteractive apt-mark hold zabbix-server-mysql zabbix-frontend sed -i "s/# fr_FR.UTF-8 UTF-8/fr_FR.UTF-8 UTF-8/g" /etc/locale.gen locale-gen -ln -s /usr/share/zabbix $final_path -rm $final_path/conf/zabbix.conf.php +ln -s /usr/share/zabbix "$final_path" +rm "$final_path/conf/zabbix.conf.php" #================================================= # CREATE A MYSQL DATABASE @@ -133,46 +133,47 @@ rm $final_path/conf/zabbix.conf.php ### - Remove also the section "REMOVE THE MYSQL DATABASE" in the remove script ### - As well as the section "RESTORE THE MYSQL DATABASE" in the restore script -db_name=$(ynh_sanitize_dbid $app) -db_user=$db_name -ynh_app_setting_set $app db_name $db_name -ynh_app_setting_set $app db_user $db_user -ynh_mysql_setup_db $db_user $db_name +declare db_pwd +db_name=$(ynh_sanitize_dbid "$app") +db_user="$db_name" +ynh_app_setting_set "$app" db_name "$db_name" +ynh_app_setting_set "$app" db_user "$db_user" +ynh_mysql_setup_db "$db_user" "$db_name" -zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -u$db_user -p$db_pwd $db_name +zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -u"$db_user" -p"$db_pwd" "$db_name" #sso integration -mysql -u$db_user -p$db_pwd $db_name -e "UPDATE \`config\` SET \`http_auth_enabled\` = '1', \`http_login_form\` = '1' WHERE \`config\`.\`configid\` = 1;" +mysql -u"$db_user" -p"$db_pwd" "$db_name" -e "UPDATE \`config\` SET \`http_auth_enabled\` = '1', \`http_login_form\` = '1' WHERE \`config\`.\`configid\` = 1;" -if [ $language == "fr" ];then +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) +surname=$(ynh_user_get_info "$admin" lastname) +name=$(ynh_user_get_info "$admin" firstname) -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 (3,'"$admin"', '"$admin"', '"$admin"', '5fce1b3e34b520afeffb37ce08c7cd66', '', 0, '0', '"$lang"', '30s', 3, 'default', 0, '', 0, 50);" -mysql -u$db_user -p$db_pwd $db_name -e "INSERT INTO \`users_groups\` (\`id\`, \`usrgrpid\`, \`userid\`) VALUES (5, 7, 3);" +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 (3,'$admin', '$admin', '$admin', '5fce1b3e34b520afeffb37ce08c7cd66', '', 0, '0', '$lang', '30s', 3, 'default', 0, '', 0, 50);" +mysql -u"$db_user" -p"$db_pwd" "$db_name" -e "INSERT INTO \`users_groups\` (\`id\`, \`usrgrpid\`, \`userid\`) VALUES (5, 7, 3);" #users creation in zabbix database i=4 -for u in $(ynh_user_list); +for user in $(ynh_user_list); do - if [ "$u" != "$admin" ];then - surname=$(ynh_user_get_info $u lastname) - name=$(ynh_user_get_info $u firstname) - 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 ("$i",'"$u"', '"$name"', '"$surname"', '5fce1b3e34b520afeffb37ce08c7cd66', '', 0, '0', '"$lang"', '30s', 1, 'default', 0, '', 0, 50);" - i=$(($i+1)) + if [ "$user" != "$admin" ];then + surname=$(ynh_user_get_info "$user" lastname) + name=$(ynh_user_get_info "$user" firstname) + 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 ($i,'$user', '$name', '$surname', '5fce1b3e34b520afeffb37ce08c7cd66', '', 0, '0', '$lang', '30s', 1, 'default', 0, '', 0, 50);" + i=$((i+1)) fi done #disable default guest -lastid=$(mysql -u$db_user -p$db_pwd $db_name -BN -e "SELECT max(id) from \`users_groups\`") -lastid=$(($lastid + 1 )) -mysql -u$db_user -p$db_pwd $db_name -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 2);" +lastid=$(mysql -u"$db_user" -p"$db_pwd" "$db_name" -BN -e "SELECT max(id) from \`users_groups\`") +lastid=$(("$lastid" + 1 )) +mysql -u"$db_user" -p"$db_pwd" "$db_name" -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 2);" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -182,7 +183,7 @@ mysql -u$db_user -p$db_pwd $db_name -e "INSERT INTO \`users_groups\` (\`id\` , \ ### downloaded from an upstream source, like a git repository. ### `ynh_setup_source` use the file conf/app.src -ynh_app_setting_set $app final_path $final_path +ynh_app_setting_set "$app" final_path "$final_path" # Download, check integrity, uncompress and patch the source from app.src #ynh_setup_source "$final_path" @@ -273,9 +274,9 @@ systemctl reload nginx #ynh_local_curl "/INSTALL_PATH" "key1=value1" "key2=value2" "key3=value3" # Remove the public access -if [ $is_public -eq 0 ] +if [ "$is_public" -eq 0 ] then - ynh_app_setting_delete $app skipped_uris + ynh_app_setting_delete "$app" skipped_uris fi #================================================= @@ -292,9 +293,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'] = ''; @@ -376,10 +377,10 @@ yunohost service add zabbix-agent -d "Management of Zabbix Agent" #================================================= # Make app public if necessary -if [ $is_public -eq 1 ] +if [ "$is_public" -eq 1 ] then # unprotected_uris allows SSO credentials to be passed anyway. - ynh_app_setting_set $app unprotected_uris "/" + ynh_app_setting_set "$app" unprotected_uris "/" fi #================================================= @@ -401,17 +402,17 @@ 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 $confUserPpath /etc/zabbix/zabbix_agentd.d/userP_yunohost.conf -cp $bashUserPpath /etc/zabbix/zabbix_agentd.d/yunohost.sh +cp "$sudoUserPpath" /etc/sudoers.d/zabbix +cp "$confUserPpath" /etc/zabbix/zabbix_agentd.d/userP_yunohost.conf +cp "$bashUserPpath" /etc/zabbix/zabbix_agentd.d/yunohost.sh chmod a+x /etc/zabbix/zabbix_agentd.d/yunohost.sh systemctl restart zabbix-agent curl -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ - --form enter=Sign+in \ - --form name=Admin \ - --form password=zabbix \ + --form "enter=Sign+in" \ + --form "name=Admin" \ + --form "password=zabbix" \ "$zabbixFullpath/index.php" sid=$(curl -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ @@ -421,24 +422,24 @@ sid=$(curl -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ importState=$(curl -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ --form "config=1" \ --form "import_file=@$localpath" \ - --form rules[groups][createMissing]=1 \ - --form rules[templates][updateExisting]=1 \ - --form rules[templates][createMissing]=1 \ - --form rules[templateScreens][updateExisting]=1 \ - --form rules[templateScreens][createMissing]=1 \ - --form rules[templateLinkage][createMissing]=1 \ - --form rules[applications][createMissing]=1 \ - --form rules[items][updateExisting]=1 \ - --form rules[items][createMissing]=1 \ - --form rules[discoveryRules][updateExisting]=1 \ - --form rules[discoveryRules][createMissing]=1 \ - --form rules[triggers][updateExisting]=1 \ - --form rules[triggers][createMissing]=1 \ - --form rules[graphs][updateExisting]=1 \ - --form rules[graphs][createMissing]=1 \ - --form rules[httptests][updateExisting]=1 \ - --form rules[httptests][createMissing]=1 \ - --form rules[valueMaps][createMissing]=1 \ + --form "rules[groups][createMissing]=1" \ + --form "rules[templates][updateExisting]=1" \ + --form "rules[templates][createMissing]=1" \ + --form "rules[templateScreens][updateExisting]=1" \ + --form "rules[templateScreens][createMissing]=1" \ + --form "rules[templateLinkage][createMissing]=1" \ + --form "rules[applications][createMissing]=1" \ + --form "rules[items][updateExisting]=1" \ + --form "rules[items][createMissing]=1" \ + --form "rules[discoveryRules][updateExisting]=1" \ + --form "rules[discoveryRules][createMissing]=1" \ + --form "rules[triggers][updateExisting]=1" \ + --form "rules[triggers][createMissing]=1" \ + --form "rules[graphs][updateExisting]=1" \ + --form "rules[graphs][createMissing]=1" \ + --form "rules[httptests][updateExisting]=1" \ + --form "rules[httptests][createMissing]=1" \ + --form "rules[valueMaps][createMissing]=1" \ --form "import=Import" \ --form "backurl=templates.php" \ --form "form_refresh=1" \ @@ -468,6 +469,6 @@ fi # disable default admin #================================================= -lastid=$(mysql -u$db_user -p$db_pwd $db_name -BN -e "SELECT max(id) from \`users_groups\`") -lastid=$(($lastid + 1 )) -mysql -u$db_user -p$db_pwd $db_name -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 1);" +lastid=$(mysql -u"$db_user" -p"$db_pwd" "$db_name" -BN -e "SELECT max(id) from \`users_groups\`") +lastid=$((lastid + 1 )) +mysql -u"$db_user" -p"$db_pwd" "$db_name" -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 1);" diff --git a/scripts/remove b/scripts/remove index 83a8bcd..579bf84 100644 --- a/scripts/remove +++ b/scripts/remove @@ -15,11 +15,11 @@ source /usr/share/yunohost/helpers 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) +#domain=$(ynh_app_setting_get "$app" domain) #not used +port=$(ynh_app_setting_get "$app" port) +db_name=$(ynh_app_setting_get "$app" db_name) db_user=$db_name -final_path=$(ynh_app_setting_get $app final_path) +#final_path=$(ynh_app_setting_get "$app" final_path) #not used #================================================= # STANDARD REMOVE @@ -73,7 +73,7 @@ rm /var/www/zabbix #================================================= # Remove a database if it exists, along with the associated user -ynh_mysql_remove_db $db_user $db_name +ynh_mysql_remove_db "$db_user" "$db_name" #================================================= # REMOVE NGINX CONFIGURATION @@ -102,7 +102,7 @@ ynh_remove_logrotate if yunohost firewall list | grep -q "\- $port$" then echo "Close port $port" >&2 - yunohost firewall disallow TCP $port 2>&1 + yunohost firewall disallow TCP "$port" 2>&1 fi #================================================= diff --git a/scripts/restore b/scripts/restore index f8514e2..88af793 100644 --- a/scripts/restore +++ b/scripts/restore @@ -5,7 +5,7 @@ # IMPORT GENERIC HELPERS #================================================= -#source _common.sh +source _common.sh source /usr/share/yunohost/helpers #================================================= @@ -40,10 +40,10 @@ rm -fr $final_path #================================================= domain=$(ynh_app_setting_get $app domain) -path_url=$(ynh_app_setting_get $app path) -admin=$(ynh_app_setting_get $app admin) +#path_url=$(ynh_app_setting_get $app path) #not used +#admin=$(ynh_app_setting_get $app admin) #not used is_public=$(ynh_app_setting_get $app is_public) -language=$(ynh_app_setting_get $app language) +#language=$(ynh_app_setting_get $app language) #not used #================================================= # INSTALL DEPENDENCIES @@ -57,9 +57,9 @@ ynh_package_update ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd snmp-mibs-downloader libjs-prototype zabbix-server-mysql zabbix-agent yunohost service add snmpd -d "Management of SNMP Daemon" DEBIAN_FRONTEND=noninteractive apt-get -y download zabbix-frontend-php -ar x *.deb +ar x ./*.deb tar xzf control.tar.gz -sed -i 's/apache2 | httpd, //' control +ynh_replace_string "apache2 | httpd, " "" control tar --ignore-failed-read -cvzf control.tar.gz {post,pre}{inst,rm} md5sums control ar rcs zabbix-frontend-php+stretch_all-noapache2.deb debian-binary control.tar.gz data.tar.xz @@ -68,7 +68,7 @@ dpkg -i zabbix-frontend-php+stretch_all-noapache2.deb rm -fr zabbix-*.deb 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 "# fr_FR.UTF-8 UTF-8" "fr_FR.UTF-8 UTF-8" /etc/locale.gen locale-gen ln -s /usr/share/zabbix /var/www/zabbix @@ -105,7 +105,7 @@ yunohost app ssowatconf systemctl reload nginx # Remove the public access -if [ $is_public -eq 0 ] +if [ "$is_public" -eq 0 ] then ynh_app_setting_delete $app skipped_uris fi @@ -118,8 +118,8 @@ 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) -ynh_mysql_setup_db $db_user $db_name $db_pwd -ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql +ynh_mysql_setup_db "$db_user" "$db_name" "$db_pwd" +ynh_mysql_connect_as "$db_name" "$db_pwd" "$db_name" < ./db.sql #================================================= # Restore configs files @@ -160,7 +160,7 @@ systemctl enable zabbix-server && systemctl start zabbix-server #================================================= # Make app public if necessary -if [ $is_public -eq 1 ] +if [ "$is_public" -eq 1 ] then # unprotected_uris allows SSO credentials to be passed anyway. ynh_app_setting_set $app unprotected_uris "/" diff --git a/scripts/upgrade b/scripts/upgrade index bd4f7f8..0462e30 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -15,15 +15,15 @@ source /usr/share/yunohost/helpers app=$YNH_APP_INSTANCE_NAME trustedversion="1:4.0.4-1+stretch" -domain=$(ynh_app_setting_get $app domain) -path_url=$(ynh_app_setting_get $app path) -admin=$(ynh_app_setting_get $app admin) -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) -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" domain) +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) #================================================= @@ -32,34 +32,34 @@ db_pwd=$(ynh_app_setting_get $app mysqlpwd) # Fix is_public as a boolean value if [ "$is_public" = "Yes" ]; then - ynh_app_setting_set $app is_public 1 + ynh_app_setting_set "$app" is_public 1 is_public=1 elif [ "$is_public" = "No" ]; then - ynh_app_setting_set $app is_public 0 + 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 +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 +if [ -z "$final_path" ]; then final_path=/var/www/$app - ynh_app_setting_set $app final_path $final_path + ynh_app_setting_set "$app" final_path "$final_path" fi #================================================= # Enable default admin temporaly #================================================= -haveDefaultAdminDisabled=$(mysql -BN -u$db_user -p$db_pwd $db_name -BN -e "SELECT count(id) from \`users_groups\` where userid=1 and usrgrpid=9") +haveDefaultAdminDisabled=$(mysql -BN -u"$db_user" -p"$db_pwd" "$db_name" -BN -e "SELECT count(id) from \`users_groups\` where userid=1 and usrgrpid=9") if [ "$haveDefaultAdminDisabled" -eq 1 ] ;then ynh_print_info "Enable default admin" #enable default admin temporaly - mysql -u$db_user -p$db_pwd $db_name -e "DELETE FROM users_groups where usrgrpid=9 and userid=1;" + mysql -u"$db_user" -p"$db_pwd" "$db_name" -e "DELETE FROM users_groups where usrgrpid=9 and userid=1;" else ynh_print_info "default admin already enabled" fi @@ -69,7 +69,7 @@ fi #================================================= ynh_print_info "Import Yunohost template" #disable sso temporaly -ynh_app_setting_set $app unprotected_uris "/" +ynh_app_setting_set "$app" unprotected_uris "/" systemctl reload nginx yunohost app ssowatconf @@ -79,17 +79,17 @@ 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 $confUserPpath /etc/zabbix/zabbix_agentd.d/userP_yunohost.conf -cp $bashUserPpath /etc/zabbix/zabbix_agentd.d/yunohost.sh +cp "$sudoUserPpath" /etc/sudoers.d/zabbix +cp "$confUserPpath" /etc/zabbix/zabbix_agentd.d/userP_yunohost.conf +cp "$bashUserPpath" /etc/zabbix/zabbix_agentd.d/yunohost.sh chmod a+x /etc/zabbix/zabbix_agentd.d/yunohost.sh systemctl restart zabbix-agent curl -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ - --form enter=Sign+in \ - --form name=Admin \ - --form password=zabbix \ + --form "enter=Sign+in" \ + --form "name=Admin" \ + --form "password=zabbix" \ "$zabbixFullpath/index.php" sid=$(curl -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ @@ -99,24 +99,24 @@ sid=$(curl -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ importState=$(curl -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ --form "config=1" \ --form "import_file=@$localpath" \ - --form rules[groups][createMissing]=1 \ - --form rules[templates][updateExisting]=1 \ - --form rules[templates][createMissing]=1 \ - --form rules[templateScreens][updateExisting]=1 \ - --form rules[templateScreens][createMissing]=1 \ - --form rules[templateLinkage][createMissing]=1 \ - --form rules[applications][createMissing]=1 \ - --form rules[items][updateExisting]=1 \ - --form rules[items][createMissing]=1 \ - --form rules[discoveryRules][updateExisting]=1 \ - --form rules[discoveryRules][createMissing]=1 \ - --form rules[triggers][updateExisting]=1 \ - --form rules[triggers][createMissing]=1 \ - --form rules[graphs][updateExisting]=1 \ - --form rules[graphs][createMissing]=1 \ - --form rules[httptests][updateExisting]=1 \ - --form rules[httptests][createMissing]=1 \ - --form rules[valueMaps][createMissing]=1 \ + --form "rules[groups][createMissing]=1" \ + --form "rules[templates][updateExisting]=1" \ + --form "rules[templates][createMissing]=1" \ + --form "rules[templateScreens][updateExisting]=1" \ + --form "rules[templateScreens][createMissing]=1" \ + --form "rules[templateLinkage][createMissing]=1" \ + --form "rules[applications][createMissing]=1" \ + --form "rules[items][updateExisting]=1" \ + --form "rules[items][createMissing]=1" \ + --form "rules[discoveryRules][updateExisting]=1" \ + --form "rules[discoveryRules][createMissing]=1" \ + --form "rules[triggers][updateExisting]=1" \ + --form "rules[triggers][createMissing]=1" \ + --form "rules[graphs][updateExisting]=1" \ + --form "rules[graphs][createMissing]=1" \ + --form "rules[httptests][updateExisting]=1" \ + --form "rules[httptests][createMissing]=1" \ + --form "rules[valueMaps][createMissing]=1" \ --form "import=Import" \ --form "backurl=templates.php" \ --form "form_refresh=1" \ @@ -145,14 +145,14 @@ fi #================================================= # Disable default admin for security issue #================================================= -haveDefaultAdminDisabled=$(mysql -BN -u$db_user -p$db_pwd $db_name -BN -e "SELECT count(id) from \`users_groups\` where userid=1 and usrgrpid=9") +haveDefaultAdminDisabled=$(mysql -BN -u"$db_user" -p"$db_pwd" "$db_name" -BN -e "SELECT count(id) from \`users_groups\` where userid=1 and usrgrpid=9") if [ "$haveDefaultAdminDisabled" -eq 0 ] ;then ynh_print_info "Disable default admin" #disable default admin - lastid=$(mysql -u$db_user -p$db_pwd $db_name -BN -e "SELECT max(id) from \`users_groups\`") - lastid=$(($lastid + 1 )) - mysql -u$db_user -p$db_pwd $db_name -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 1);" + lastid=$(mysql -u"$db_user" -p"$db_pwd" "$db_name" -BN -e "SELECT max(id) from \`users_groups\`") + lastid=$((lastid + 1 )) + mysql -u"$db_user" -p"$db_pwd" "$db_name" -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 1);" else ynh_print_info "default admin already disabled" fi @@ -161,14 +161,14 @@ fi #================================================= # Disable default guest for security issue #================================================= -haveDefaultGuestDisabled=$(mysql -BN -u$db_user -p$db_pwd $db_name -BN -e "SELECT count(id) from \`users_groups\` where userid=2 and usrgrpid=9") +haveDefaultGuestDisabled=$(mysql -BN -u"$db_user" -p"$db_pwd" "$db_name" -BN -e "SELECT count(id) from \`users_groups\` where userid=2 and usrgrpid=9") if [ "$haveDefaultGuestDisabled" -eq 0 ] ;then echo "Disable default guest" #disable default guest - lastid=$(mysql -u$db_user -p$db_pwd $db_name -BN -e "SELECT max(id) from \`users_groups\`") - lastid=$(($lastid + 1 )) - mysql -u$db_user -p$db_pwd $db_name -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 2);" + lastid=$(mysql -u"$db_user" -p"$db_pwd" "$db_name" -BN -e "SELECT max(id) from \`users_groups\`") + lastid=$((lastid + 1 )) + mysql -u"$db_user" -p"$db_pwd" "$db_name" -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 2);" else echo "default guest already disabled" fi @@ -178,7 +178,7 @@ fi #================================================= # Normalize the URL path syntax -path_url=$(ynh_normalize_url_path $path_url) +path_url=$(ynh_normalize_url_path "$path_url") #================================================= # STANDARD UPGRADE STEPS @@ -201,7 +201,7 @@ zabbixagentCandidateVersion=$(apt-cache policy zabbix-agent | grep -Po "Candidat if [ "$trustedversion" == "$zabbixServerCandidateVersion" ] then - if [ "$zabbixServerInstalledVersion" != "$zabbixServerCandidateVersion" -o "$zabbixFrontendInstalledVersion" != "$zabbixFrontendCandidateVersion" -o "$zabbixagentInstalledVersion" != "$zabbixagentCandidateVersion" ] + if [ "$zabbixServerInstalledVersion" != "$zabbixServerCandidateVersion" ] || [ "$zabbixFrontendInstalledVersion" != "$zabbixFrontendCandidateVersion" ] || [ "$zabbixagentInstalledVersion" != "$zabbixagentCandidateVersion" ] then #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP @@ -221,9 +221,9 @@ then DEBIAN_FRONTEND=noninteractive apt-mark unhold zabbix-server-mysql zabbix-frontend-php DEBIAN_FRONTEND=noninteractive apt-get -y download zabbix-frontend-php - ar x *.deb + ar x ./*.deb tar xzf control.tar.gz - sed -i 's/apache2 | httpd, //' control + ynh_replace_string "apache2 | httpd, " "" control tar --ignore-failed-read -cvzf control.tar.gz {post,pre}{inst,rm} md5sums control ar rcs zabbix-frontend-php+stretch_all-noapache2.deb debian-binary control.tar.gz data.tar.xz dpkg -i zabbix-frontend-php+stretch_all-noapache2.deb @@ -252,9 +252,9 @@ ynh_print_info "re-enable SSOWAT" if [ $is_public -eq 1 ] then # unprotected_uris allows SSO credentials to be passed anyway. - ynh_app_setting_set $app unprotected_uris "/" + ynh_app_setting_set "$app" unprotected_uris "/" else - ynh_app_setting_set $app unprotected_uris "" + ynh_app_setting_set "$app" unprotected_uris "" fi systemctl reload nginx From 6063938fa454b2d2e964a1e8d3899951d9d3c665 Mon Sep 17 00:00:00 2001 From: Mickael Date: Mon, 25 Feb 2019 15:52:29 +0100 Subject: [PATCH 007/144] change rules public --- scripts/install | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/scripts/install b/scripts/install index e166aef..fe36002 100644 --- a/scripts/install +++ b/scripts/install @@ -372,16 +372,6 @@ yunohost service add zabbix-agent -d "Management of Zabbix Agent" #yunohost service add NAME_INIT.D --log "/var/log/FILE.log" -#================================================= -# SETUP SSOWAT -#================================================= - -# Make app public if necessary -if [ "$is_public" -eq 1 ] -then - # unprotected_uris allows SSO credentials to be passed anyway. - ynh_app_setting_set "$app" unprotected_uris "/" -fi #================================================= # RELOAD NGINX AND PHP-FPM @@ -472,3 +462,24 @@ fi lastid=$(mysql -u"$db_user" -p"$db_pwd" "$db_name" -BN -e "SELECT max(id) from \`users_groups\`") lastid=$((lastid + 1 )) mysql -u"$db_user" -p"$db_pwd" "$db_name" -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 1);" + +#================================================= +# SETUP SSOWAT +#================================================= + +# Make app public if necessary +if [ "$is_public" -eq 1 ] +then + # unprotected_uris allows SSO credentials to be passed anyway. + ynh_app_setting_set "$app" unprotected_uris "/" +fi +#================================================= +# RELOAD NGINX AND PHP-FPM +#================================================= + +systemctl reload nginx +systemctl reload php7.0-fpm + +# Reload SSOwat config +yunohost app ssowatconf + From 91a232473d6a696bf608a90ae771270a1f3326a4 Mon Sep 17 00:00:00 2001 From: Mickael Date: Mon, 25 Feb 2019 20:23:29 +0100 Subject: [PATCH 008/144] restore source ../settings/scripts/_common.sh --- scripts/backup | 2 +- scripts/restore | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/backup b/scripts/backup index e644781..300cbbb 100644 --- a/scripts/backup +++ b/scripts/backup @@ -6,7 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= -source _common.sh +source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers #================================================= diff --git a/scripts/restore b/scripts/restore index 88af793..3bdab07 100644 --- a/scripts/restore +++ b/scripts/restore @@ -5,7 +5,7 @@ # IMPORT GENERIC HELPERS #================================================= -source _common.sh +source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers #================================================= From c6d7bd2efb22299f5401213a01547da0876e9768 Mon Sep 17 00:00:00 2001 From: Mickael Date: Mon, 25 Feb 2019 20:32:18 +0100 Subject: [PATCH 009/144] try to make zabbix publi just to import template --- scripts/install | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/install b/scripts/install index fe36002..3998dd5 100644 --- a/scripts/install +++ b/scripts/install @@ -372,6 +372,9 @@ yunohost service add zabbix-agent -d "Management of Zabbix Agent" #yunohost service add NAME_INIT.D --log "/var/log/FILE.log" +# Make app public if for importing template +# unprotected_uris allows SSO credentials to be passed anyway +ynh_app_setting_set "$app" unprotected_uris "/" #================================================= # RELOAD NGINX AND PHP-FPM From 59be110f9b34355f8c0a54de376f7bf4375fc7c3 Mon Sep 17 00:00:00 2001 From: Mickael Date: Mon, 25 Feb 2019 20:41:28 +0100 Subject: [PATCH 010/144] renable private mode after import template --- scripts/install | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/install b/scripts/install index 3998dd5..5394ced 100644 --- a/scripts/install +++ b/scripts/install @@ -470,11 +470,11 @@ mysql -u"$db_user" -p"$db_pwd" "$db_name" -e "INSERT INTO \`users_groups\` (\`id # SETUP SSOWAT #================================================= -# Make app public if necessary -if [ "$is_public" -eq 1 ] +# Make app private if necessary +if [ "$is_public" -eq 0 ] then # unprotected_uris allows SSO credentials to be passed anyway. - ynh_app_setting_set "$app" unprotected_uris "/" + ynh_app_setting_delete "$app" unprotected_uris fi #================================================= # RELOAD NGINX AND PHP-FPM From 131ed10a163f075968e29034f135b476cf4496a4 Mon Sep 17 00:00:00 2001 From: Mickael Date: Mon, 25 Feb 2019 20:50:26 +0100 Subject: [PATCH 011/144] make same change as install : make private by default --- scripts/upgrade | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 0462e30..b81e321 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -248,13 +248,13 @@ fi # RE-ENABLE SSOWAT #================================================= ynh_print_info "re-enable SSOWAT" -# Make app public if necessary -if [ $is_public -eq 1 ] +# Make app private if necessary +if [ $is_public -eq 0 ] then # unprotected_uris allows SSO credentials to be passed anyway. - ynh_app_setting_set "$app" unprotected_uris "/" + ynh_app_setting_delete "$app" unprotected_uris else - ynh_app_setting_set "$app" unprotected_uris "" + ynh_app_setting_set "$app" unprotected_uris "/" fi systemctl reload nginx From 5c7ea7131933083784a9a0d20b81735fc5dd56a9 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Wed, 27 Feb 2019 11:29:44 +0100 Subject: [PATCH 012/144] follow auth curl --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index b81e321..b3cc62b 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -86,7 +86,7 @@ chmod a+x /etc/zabbix/zabbix_agentd.d/yunohost.sh systemctl restart zabbix-agent -curl -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ +curl -L -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ --form "enter=Sign+in" \ --form "name=Admin" \ --form "password=zabbix" \ From bf46febf87b25501e64a0e41af45f060e7982e44 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Wed, 27 Feb 2019 11:30:15 +0100 Subject: [PATCH 013/144] follow auth curl --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 5394ced..23cfdb8 100644 --- a/scripts/install +++ b/scripts/install @@ -402,7 +402,7 @@ chmod a+x /etc/zabbix/zabbix_agentd.d/yunohost.sh systemctl restart zabbix-agent -curl -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ +curl -L -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ --form "enter=Sign+in" \ --form "name=Admin" \ --form "password=zabbix" \ From 50510fba45cd34c81b1dc63143dfd2d78366caaa Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Wed, 27 Feb 2019 11:44:26 +0100 Subject: [PATCH 014/144] add comments and condition on fail login --- scripts/install | 108 +++++++++++++++++++++++++----------------------- 1 file changed, 57 insertions(+), 51 deletions(-) diff --git a/scripts/install b/scripts/install index 23cfdb8..9946f34 100644 --- a/scripts/install +++ b/scripts/install @@ -57,6 +57,7 @@ ynh_webpath_register "$app" "$domain" "$path_url" #================================================= # STORE SETTINGS FROM MANIFEST #================================================= +ynh_print_info "Get infos from manifest" ynh_app_setting_set "$app" domain "$domain" ynh_app_setting_set "$app" path "$path_url" @@ -94,6 +95,7 @@ ynh_app_setting_set "$app" language "$language" ### - Remove the section "REMOVE DEPENDENCIES" in the remove script ### - As well as the section "REINSTALL DEPENDENCIES" in the restore script ### - And the section "UPGRADE DEPENDENCIES" in the upgrade script +ynh_print_info "Install dependencies" wget "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 @@ -123,6 +125,7 @@ rm "$final_path/conf/zabbix.conf.php" #================================================= # CREATE A MYSQL DATABASE #================================================= +ynh_print_info "Create and add default data in db" ### Use these lines if you need a database for the application. ### `ynh_mysql_setup_db` will create a database, an associated user and a ramdom password. @@ -187,6 +190,8 @@ ynh_app_setting_set "$app" final_path "$final_path" # Download, check integrity, uncompress and patch the source from app.src #ynh_setup_source "$final_path" +ynh_print_info "Generate web config" + #================================================= # NGINX CONFIGURATION #================================================= @@ -273,18 +278,13 @@ systemctl reload nginx # Installation with curl #ynh_local_curl "/INSTALL_PATH" "key1=value1" "key2=value2" "key3=value3" -# Remove the public access -if [ "$is_public" -eq 0 ] -then - ynh_app_setting_delete "$app" skipped_uris -fi - #================================================= # MODIFY A CONFIG FILE #================================================= ### `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 " Date: Wed, 27 Feb 2019 16:55:35 +0100 Subject: [PATCH 015/144] precise information about curl for dns resolution for package_check --- scripts/install | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/scripts/install b/scripts/install index 9946f34..7577b1d 100644 --- a/scripts/install +++ b/scripts/install @@ -402,19 +402,20 @@ cp "$bashUserPpath" /etc/zabbix/zabbix_agentd.d/yunohost.sh chmod a+x /etc/zabbix/zabbix_agentd.d/yunohost.sh systemctl restart zabbix-agent +curlOptions="-k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt --resolve $domain:443:127.0.0.1" -curl -L -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ +curl -L $curlOptions \ --form "enter=Sign+in" \ --form "name=Admin" \ --form "password=zabbix" \ "$zabbixFullpath/index.php" if [ $? -eq 0 ];then - sid=$(curl -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ + sid=$(curl $curlOptions \ "$zabbixFullpath/conf.import.php?rules_preset=template" \ | grep -Po 'name="sid" value="\K([a-z0-9]{16})(?=")' ) - importState=$(curl -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ + importState=$(curl $curlOptions \ --form "config=1" \ --form "import_file=@$localpath" \ --form "rules[groups][createMissing]=1" \ @@ -450,10 +451,10 @@ if [ $? -eq 0 ];then #apply template to host - tokenapi=$(curl -k -s --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 -k -s --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') - zabbixTemplateID=$(curl -k -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"template.get","params":{"filter":{"host":["Template Yunohost"]}},"auth":"'"$tokenapi"'","id":1}' "${zabbixFullpath}/api_jsonrpc.php" | jq -r '.result[0].templateid') - applyTemplate=$(curl -k -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.massadd","params":{"hosts":[{"hostid":"'"$zabbixHostID"'"}],"templates":[{"templateid":"'"$zabbixTemplateID"'"}]},"auth":"'"$tokenapi"'","id":1}' "${zabbixFullpath}/api_jsonrpc.php" | jq -r '.result.hostids[]') + tokenapi=$(curl -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 -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') + zabbixTemplateID=$(curl -k -s --resolve $domain:443:127.0.0.1 --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"template.get","params":{"filter":{"host":["Template Yunohost"]}},"auth":"'"$tokenapi"'","id":1}' "${zabbixFullpath}/api_jsonrpc.php" | jq -r '.result[0].templateid') + applyTemplate=$(curl -k -s --resolve $domain:443:127.0.0.1 --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.massadd","params":{"hosts":[{"hostid":"'"$zabbixHostID"'"}],"templates":[{"templateid":"'"$zabbixTemplateID"'"}]},"auth":"'"$tokenapi"'","id":1}' "${zabbixFullpath}/api_jsonrpc.php" | jq -r '.result.hostids[]') if [ "$applyTemplate" -eq "$zabbixHostID" ];then ynh_print_info "Template Yunohost linked to Zabbix server !" else @@ -470,7 +471,7 @@ fi ynh_print_info "disable default admin" lastid=$(mysql -u"$db_user" -p"$db_pwd" "$db_name" -BN -e "SELECT max(id) from \`users_groups\`") lastid=$((lastid + 1 )) -mysql -u"$db_user" -p"$db_pwd" "$db_name" -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 1);" +#mysql -u"$db_user" -p"$db_pwd" "$db_name" -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 1);" #================================================= # SETUP SSOWAT From a7c83e3ad46b8be4621cf730eafe8a93902578a7 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 1 Mar 2019 09:41:18 +0100 Subject: [PATCH 016/144] generate functions and globals vars --- scripts/install | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/scripts/install b/scripts/install index 7577b1d..5a1cce4 100644 --- a/scripts/install +++ b/scripts/install @@ -143,10 +143,12 @@ ynh_app_setting_set "$app" db_name "$db_name" ynh_app_setting_set "$app" db_user "$db_user" ynh_mysql_setup_db "$db_user" "$db_name" -zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -u"$db_user" -p"$db_pwd" "$db_name" +export mysqlconn="mysql -u $db_user -p $db_pwd $db_name" + +zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | $mysqlconn #sso integration -mysql -u"$db_user" -p"$db_pwd" "$db_name" -e "UPDATE \`config\` SET \`http_auth_enabled\` = '1', \`http_login_form\` = '1' WHERE \`config\`.\`configid\` = 1;" +$mysqlconn -e "UPDATE \`config\` SET \`http_auth_enabled\` = '1', \`http_login_form\` = '1' WHERE \`config\`.\`configid\` = 1;" if [ "$language" == "fr" ];then lang="fr_FR" @@ -158,8 +160,8 @@ fi surname=$(ynh_user_get_info "$admin" lastname) name=$(ynh_user_get_info "$admin" firstname) -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 (3,'$admin', '$admin', '$admin', '5fce1b3e34b520afeffb37ce08c7cd66', '', 0, '0', '$lang', '30s', 3, 'default', 0, '', 0, 50);" -mysql -u"$db_user" -p"$db_pwd" "$db_name" -e "INSERT INTO \`users_groups\` (\`id\`, \`usrgrpid\`, \`userid\`) VALUES (5, 7, 3);" +$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 @@ -168,15 +170,12 @@ do if [ "$user" != "$admin" ];then surname=$(ynh_user_get_info "$user" lastname) name=$(ynh_user_get_info "$user" firstname) - 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 ($i,'$user', '$name', '$surname', '5fce1b3e34b520afeffb37ce08c7cd66', '', 0, '0', '$lang', '30s', 1, 'default', 0, '', 0, 50);" + $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 default guest -lastid=$(mysql -u"$db_user" -p"$db_pwd" "$db_name" -BN -e "SELECT max(id) from \`users_groups\`") -lastid=$(("$lastid" + 1 )) -mysql -u"$db_user" -p"$db_pwd" "$db_name" -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 2);" +disable_guest_user() #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -469,9 +468,7 @@ fi # disable default admin #================================================= ynh_print_info "disable default admin" -lastid=$(mysql -u"$db_user" -p"$db_pwd" "$db_name" -BN -e "SELECT max(id) from \`users_groups\`") -lastid=$((lastid + 1 )) -#mysql -u"$db_user" -p"$db_pwd" "$db_name" -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 1);" +disable_admin_user() #================================================= # SETUP SSOWAT From b1d5fa71e041112279c7c460224ae8e66ca7e726 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 1 Mar 2019 09:50:11 +0100 Subject: [PATCH 017/144] add functions --- scripts/_common.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/scripts/_common.sh b/scripts/_common.sh index bb04a03..8e8c2d2 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -10,4 +10,44 @@ ynh_delete_file_checksum () { local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_' ynh_app_setting_delete $app $checksum_setting_name +} + +#Zabbix part +#===================GET GUEST DEFAULT USER STATE============== +#return 0 if enable, else 1 +get_state_guest_user(){ + return $($mysqlconn -BN -e "SELECT count(id) from \`users_groups\` where userid=2 and usrgrpid=9") +} + +#================ DISABLE DEFAULT ZABBIX USER GUEST =================== + +disable_guest_user(){ + if [ get_state_guest_user -eq 0 ];then + lastid=$($mysqlconn -BN -e "SELECT max(id) from \`users_groups\`") + lastid=$(("$lastid" + 1 )) + $mysqlconn -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 2);" + fi +} + +#===================GET ADMIN DEFAULT USER STATE============== +#return 0 if enable, else 1 +get_state_admin_user(){ + return $($mysqlconn -BN -e "SELECT count(id) from \`users_groups\` where userid=1 and usrgrpid=9") +} + +#================ DISABLE DEFAULT ADMIN USER =================== +disable_admin_user(){ + if [ get_state_admin_user -eq 0 ] ;then + lastid=$($mysqlconn -BN -e "SELECT max(id) from \`users_groups\`") + lastid=$((lastid + 1 )) + $mysqlconn -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 1);" + fi +} + +enable_admin_user(){ + if [ get_state_admin_user -eq 1 ] ;then + ynh_print_info "Enable default admin" + #enable default admin temporaly + mysql -u"$db_user" -p"$db_pwd" "$db_name" -e "DELETE FROM users_groups where usrgrpid=9 and userid=1;" + fi } \ No newline at end of file From 6de436bf765a1c4111c7dbc4547f68dc62cb6fd8 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 1 Mar 2019 09:57:56 +0100 Subject: [PATCH 018/144] Update upgrade --- scripts/upgrade | 39 +++++++-------------------------------- 1 file changed, 7 insertions(+), 32 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index b3cc62b..da64139 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -51,18 +51,12 @@ if [ -z "$final_path" ]; then ynh_app_setting_set "$app" final_path "$final_path" fi +export mysqlconn="mysql -u $db_user -p $db_pwd $db_name" + #================================================= # Enable default admin temporaly #================================================= -haveDefaultAdminDisabled=$(mysql -BN -u"$db_user" -p"$db_pwd" "$db_name" -BN -e "SELECT count(id) from \`users_groups\` where userid=1 and usrgrpid=9") - -if [ "$haveDefaultAdminDisabled" -eq 1 ] ;then - ynh_print_info "Enable default admin" - #enable default admin temporaly - mysql -u"$db_user" -p"$db_pwd" "$db_name" -e "DELETE FROM users_groups where usrgrpid=9 and userid=1;" -else - ynh_print_info "default admin already enabled" -fi +enable_admin_user #================================================= # Import Yunohost template @@ -145,33 +139,14 @@ fi #================================================= # Disable default admin for security issue #================================================= -haveDefaultAdminDisabled=$(mysql -BN -u"$db_user" -p"$db_pwd" "$db_name" -BN -e "SELECT count(id) from \`users_groups\` where userid=1 and usrgrpid=9") - -if [ "$haveDefaultAdminDisabled" -eq 0 ] ;then - ynh_print_info "Disable default admin" - #disable default admin - lastid=$(mysql -u"$db_user" -p"$db_pwd" "$db_name" -BN -e "SELECT max(id) from \`users_groups\`") - lastid=$((lastid + 1 )) - mysql -u"$db_user" -p"$db_pwd" "$db_name" -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 1);" -else - ynh_print_info "default admin already disabled" -fi - +ynh_print_info "disable default admin" +disable_admin_user #================================================= # Disable default guest for security issue #================================================= -haveDefaultGuestDisabled=$(mysql -BN -u"$db_user" -p"$db_pwd" "$db_name" -BN -e "SELECT count(id) from \`users_groups\` where userid=2 and usrgrpid=9") - -if [ "$haveDefaultGuestDisabled" -eq 0 ] ;then - echo "Disable default guest" - #disable default guest - lastid=$(mysql -u"$db_user" -p"$db_pwd" "$db_name" -BN -e "SELECT max(id) from \`users_groups\`") - lastid=$((lastid + 1 )) - mysql -u"$db_user" -p"$db_pwd" "$db_name" -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 2);" -else - echo "default guest already disabled" -fi +ynh_print_info "disable default guest" +disable_guest_user #================================================= # CHECK THE PATH From 1e4df9c341065bdb4144689df8e62a8a4df57b57 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 1 Mar 2019 10:14:25 +0100 Subject: [PATCH 019/144] Update _common.sh --- scripts/_common.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 8e8c2d2..5c95379 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -41,6 +41,11 @@ disable_admin_user(){ lastid=$($mysqlconn -BN -e "SELECT max(id) from \`users_groups\`") lastid=$((lastid + 1 )) $mysqlconn -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 1);" + ynh_print_info "Default admin disabled" + + else + ynh_print_info "Default admin already disabled" + fi } @@ -48,6 +53,9 @@ enable_admin_user(){ if [ get_state_admin_user -eq 1 ] ;then ynh_print_info "Enable default admin" #enable default admin temporaly - mysql -u"$db_user" -p"$db_pwd" "$db_name" -e "DELETE FROM users_groups where usrgrpid=9 and userid=1;" + $mysqlconn -e "DELETE FROM users_groups where usrgrpid=9 and userid=1;" + ynh_print_info "Default admin enabled" + else + ynh_print_info "Default admin already enable" fi } \ No newline at end of file From ab86edb18a2dea4cb87c88fea70307c24d09f0d7 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 1 Mar 2019 10:18:53 +0100 Subject: [PATCH 020/144] Update install --- scripts/install | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/install b/scripts/install index 5a1cce4..2303677 100644 --- a/scripts/install +++ b/scripts/install @@ -19,8 +19,8 @@ ynh_abort_if_errors # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= -domain="$YNH_APP_ARG_DOMAIN" -path_url="$YNH_APP_ARG_PATH" +export domain="$YNH_APP_ARG_DOMAIN" +export path_url="$YNH_APP_ARG_PATH" admin="$YNH_APP_ARG_ADMIN" is_public="$YNH_APP_ARG_IS_PUBLIC" language="$YNH_APP_ARG_LANGUAGE" From 59607d69f2596d940effee3c7854946bf0a58154 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 1 Mar 2019 10:19:54 +0100 Subject: [PATCH 021/144] Update upgrade --- scripts/upgrade | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index da64139..a78e804 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -15,8 +15,8 @@ source /usr/share/yunohost/helpers app=$YNH_APP_INSTANCE_NAME trustedversion="1:4.0.4-1+stretch" -domain=$(ynh_app_setting_get "$app" domain) -path_url=$(ynh_app_setting_get "$app" path) +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) From bc99d2261f6aa1d133c424457f713313ecf6fa1f Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 1 Mar 2019 10:21:26 +0100 Subject: [PATCH 022/144] Update upgrade --- scripts/upgrade | 80 ++++--------------------------------------------- 1 file changed, 5 insertions(+), 75 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index a78e804..8797bfe 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -61,91 +61,21 @@ enable_admin_user #================================================= # Import Yunohost template #================================================= -ynh_print_info "Import Yunohost template" -#disable sso temporaly -ynh_app_setting_set "$app" unprotected_uris "/" -systemctl reload nginx -yunohost app ssowatconf - -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 "$confUserPpath" /etc/zabbix/zabbix_agentd.d/userP_yunohost.conf -cp "$bashUserPpath" /etc/zabbix/zabbix_agentd.d/yunohost.sh -chmod a+x /etc/zabbix/zabbix_agentd.d/yunohost.sh - -systemctl restart zabbix-agent - -curl -L -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ - --form "enter=Sign+in" \ - --form "name=Admin" \ - --form "password=zabbix" \ - "$zabbixFullpath/index.php" - -sid=$(curl -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ - "$zabbixFullpath/conf.import.php?rules_preset=template" \ - | grep -Po 'name="sid" value="\K([a-z0-9]{16})(?=")' ) - -importState=$(curl -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ - --form "config=1" \ - --form "import_file=@$localpath" \ - --form "rules[groups][createMissing]=1" \ - --form "rules[templates][updateExisting]=1" \ - --form "rules[templates][createMissing]=1" \ - --form "rules[templateScreens][updateExisting]=1" \ - --form "rules[templateScreens][createMissing]=1" \ - --form "rules[templateLinkage][createMissing]=1" \ - --form "rules[applications][createMissing]=1" \ - --form "rules[items][updateExisting]=1" \ - --form "rules[items][createMissing]=1" \ - --form "rules[discoveryRules][updateExisting]=1" \ - --form "rules[discoveryRules][createMissing]=1" \ - --form "rules[triggers][updateExisting]=1" \ - --form "rules[triggers][createMissing]=1" \ - --form "rules[graphs][updateExisting]=1" \ - --form "rules[graphs][createMissing]=1" \ - --form "rules[httptests][updateExisting]=1" \ - --form "rules[httptests][createMissing]=1" \ - --form "rules[valueMaps][createMissing]=1" \ - --form "import=Import" \ - --form "backurl=templates.php" \ - --form "form_refresh=1" \ - --form "sid=${sid}" \ \ - "${zabbixFullpath}/conf.import.php?rules_preset=template" \ - | grep -c "Imported successfully") - -if [ "$importState" -eq "1" ];then - ynh_print_info "Template Yunohost imported !" -else - ynh_print_warn "Template Yunohost not imported !" -fi - -#apply template to host -tokenapi=$(curl -k -s --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 -k -s --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') -zabbixTemplateID=$(curl -k -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"template.get","params":{"filter":{"host":["Template Yunohost"]}},"auth":"'"$tokenapi"'","id":1}' "${zabbixFullpath}/api_jsonrpc.php" | jq -r '.result[0].templateid') -applyTemplate=$(curl -k -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.massadd","params":{"hosts":[{"hostid":"'"$zabbixHostID"'"}],"templates":[{"templateid":"'"$zabbixTemplateID"'"}]},"auth":"'"$tokenapi"'","id":1}' "${zabbixFullpath}/api_jsonrpc.php" | jq -r '.result.hostids[]') -if [ "$applyTemplate" -eq "$zabbixHostID" ];then - ynh_print_info "Template Yunohost linked to Zabbix server !" -else - ynh_print_warn "Template Yunohost no linked to Zabbix server !" -fi +import_template +#================================================= +# Link Yunohost template to the ZAbbix Server Host +#================================================= +link_template #================================================= # Disable default admin for security issue #================================================= -ynh_print_info "disable default admin" disable_admin_user #================================================= # Disable default guest for security issue #================================================= -ynh_print_info "disable default guest" disable_guest_user #================================================= From 1a2e768a1c59bd739f1be7c6f89e26715cb68613 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 1 Mar 2019 10:23:24 +0100 Subject: [PATCH 023/144] Update install (function import,link template) --- scripts/install | 80 ++++--------------------------------------------- 1 file changed, 5 insertions(+), 75 deletions(-) diff --git a/scripts/install b/scripts/install index 2303677..5541ee2 100644 --- a/scripts/install +++ b/scripts/install @@ -388,86 +388,16 @@ yunohost app ssowatconf #================================================= # Import Yunohost template #================================================= -ynh_print_info "Import yunohost template" -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 "$confUserPpath" /etc/zabbix/zabbix_agentd.d/userP_yunohost.conf -cp "$bashUserPpath" /etc/zabbix/zabbix_agentd.d/yunohost.sh -chmod a+x /etc/zabbix/zabbix_agentd.d/yunohost.sh - -systemctl restart zabbix-agent -curlOptions="-k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt --resolve $domain:443:127.0.0.1" - -curl -L $curlOptions \ - --form "enter=Sign+in" \ - --form "name=Admin" \ - --form "password=zabbix" \ - "$zabbixFullpath/index.php" - -if [ $? -eq 0 ];then - sid=$(curl $curlOptions \ - "$zabbixFullpath/conf.import.php?rules_preset=template" \ - | grep -Po 'name="sid" value="\K([a-z0-9]{16})(?=")' ) - - importState=$(curl $curlOptions \ - --form "config=1" \ - --form "import_file=@$localpath" \ - --form "rules[groups][createMissing]=1" \ - --form "rules[templates][updateExisting]=1" \ - --form "rules[templates][createMissing]=1" \ - --form "rules[templateScreens][updateExisting]=1" \ - --form "rules[templateScreens][createMissing]=1" \ - --form "rules[templateLinkage][createMissing]=1" \ - --form "rules[applications][createMissing]=1" \ - --form "rules[items][updateExisting]=1" \ - --form "rules[items][createMissing]=1" \ - --form "rules[discoveryRules][updateExisting]=1" \ - --form "rules[discoveryRules][createMissing]=1" \ - --form "rules[triggers][updateExisting]=1" \ - --form "rules[triggers][createMissing]=1" \ - --form "rules[graphs][updateExisting]=1" \ - --form "rules[graphs][createMissing]=1" \ - --form "rules[httptests][updateExisting]=1" \ - --form "rules[httptests][createMissing]=1" \ - --form "rules[valueMaps][createMissing]=1" \ - --form "import=Import" \ - --form "backurl=templates.php" \ - --form "form_refresh=1" \ - --form "sid=${sid}" \ \ - "${zabbixFullpath}/conf.import.php?rules_preset=template" \ - | grep -c "Imported successfully") - - if [ "$importState" -eq "1" ];then - ynh_print_info "Template Yunohost imported !" - else - ynh_print_warn "Template Yunohost not imported !" - fi - - - #apply template to host - tokenapi=$(curl -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 -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') - zabbixTemplateID=$(curl -k -s --resolve $domain:443:127.0.0.1 --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"template.get","params":{"filter":{"host":["Template Yunohost"]}},"auth":"'"$tokenapi"'","id":1}' "${zabbixFullpath}/api_jsonrpc.php" | jq -r '.result[0].templateid') - applyTemplate=$(curl -k -s --resolve $domain:443:127.0.0.1 --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.massadd","params":{"hosts":[{"hostid":"'"$zabbixHostID"'"}],"templates":[{"templateid":"'"$zabbixTemplateID"'"}]},"auth":"'"$tokenapi"'","id":1}' "${zabbixFullpath}/api_jsonrpc.php" | jq -r '.result.hostids[]') - if [ "$applyTemplate" -eq "$zabbixHostID" ];then - ynh_print_info "Template Yunohost linked to Zabbix server !" - else - ynh_print_warn "Template Yunohost no linked to Zabbix server !" - fi -else - ynh_print_warn "Template Yunohost not imported ! (cannot connect admin)" -fi +import_template +#================================================= +# Link Yunohost template to the ZAbbix Server Host +#================================================= +link_template #================================================= # disable default admin #================================================= -ynh_print_info "disable default admin" disable_admin_user() #================================================= From 2a0d4e1db06956468ece23fecfc0aa235a8c890e Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 1 Mar 2019 10:27:39 +0100 Subject: [PATCH 024/144] add function add template and link --- scripts/_common.sh | 79 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/scripts/_common.sh b/scripts/_common.sh index 5c95379..6bcc699 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -58,4 +58,83 @@ enable_admin_user(){ else ynh_print_info "Default admin already enable" fi +} + +import_template(){ + ynh_print_info "Import yunohost template" + 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 "$confUserPpath" /etc/zabbix/zabbix_agentd.d/userP_yunohost.conf + cp "$bashUserPpath" /etc/zabbix/zabbix_agentd.d/yunohost.sh + chmod a+x /etc/zabbix/zabbix_agentd.d/yunohost.sh + + systemctl restart zabbix-agent + curlOptions="-k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt --resolve $domain:443:127.0.0.1" + + curl -L $curlOptions \ + --form "enter=Sign+in" \ + --form "name=Admin" \ + --form "password=zabbix" \ + "$zabbixFullpath/index.php" + + if [ $? -eq 0 ];then + sid=$(curl $curlOptions \ + "$zabbixFullpath/conf.import.php?rules_preset=template" \ + | grep -Po 'name="sid" value="\K([a-z0-9]{16})(?=")' ) + + importState=$(curl $curlOptions \ + --form "config=1" \ + --form "import_file=@$localpath" \ + --form "rules[groups][createMissing]=1" \ + --form "rules[templates][updateExisting]=1" \ + --form "rules[templates][createMissing]=1" \ + --form "rules[templateScreens][updateExisting]=1" \ + --form "rules[templateScreens][createMissing]=1" \ + --form "rules[templateLinkage][createMissing]=1" \ + --form "rules[applications][createMissing]=1" \ + --form "rules[items][updateExisting]=1" \ + --form "rules[items][createMissing]=1" \ + --form "rules[discoveryRules][updateExisting]=1" \ + --form "rules[discoveryRules][createMissing]=1" \ + --form "rules[triggers][updateExisting]=1" \ + --form "rules[triggers][createMissing]=1" \ + --form "rules[graphs][updateExisting]=1" \ + --form "rules[graphs][createMissing]=1" \ + --form "rules[httptests][updateExisting]=1" \ + --form "rules[httptests][createMissing]=1" \ + --form "rules[valueMaps][createMissing]=1" \ + --form "import=Import" \ + --form "backurl=templates.php" \ + --form "form_refresh=1" \ + --form "sid=${sid}" \ \ + "${zabbixFullpath}/conf.import.php?rules_preset=template" \ + | grep -c "Imported successfully") + + if [ "$importState" -eq "1" ];then + ynh_print_info "Template Yunohost imported !" + else + ynh_print_warn "Template Yunohost not imported !" + fi + else + ynh_print_warn "Admin user cannot connect interface !" + fi +} + +link_template(){ + #apply template to host + tokenapi=$(curl -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 -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') + zabbixTemplateID=$(curl -k -s --resolve $domain:443:127.0.0.1 --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"template.get","params":{"filter":{"host":["Template Yunohost"]}},"auth":"'"$tokenapi"'","id":1}' "${zabbixFullpath}/api_jsonrpc.php" | jq -r '.result[0].templateid') + applyTemplate=$(curl -k -s --resolve $domain:443:127.0.0.1 --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.massadd","params":{"hosts":[{"hostid":"'"$zabbixHostID"'"}],"templates":[{"templateid":"'"$zabbixTemplateID"'"}]},"auth":"'"$tokenapi"'","id":1}' "${zabbixFullpath}/api_jsonrpc.php" | jq -r '.result.hostids[]') + if [ "$applyTemplate" -eq "$zabbixHostID" ];then + ynh_print_info "Template Yunohost linked to Zabbix server !" + else + ynh_print_warn "Template Yunohost no linked to Zabbix server !" + fi + } \ No newline at end of file From 884ef8f0a87bef875ddf62f3680b3e22eeb1b1bb Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 1 Mar 2019 11:01:31 +0100 Subject: [PATCH 025/144] Update install ynh_abort_if_errors --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 5541ee2..79cf515 100644 --- a/scripts/install +++ b/scripts/install @@ -13,7 +13,7 @@ source /usr/share/yunohost/helpers #================================================= # Exit if an error occurs during the execution of the script -ynh_abort_if_errors +#ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST From d37399a48cab80ccd4760f2bc7f1b2eb5092dc98 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 1 Mar 2019 11:04:50 +0100 Subject: [PATCH 026/144] fix mysqlconn --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 79cf515..ecd38d2 100644 --- a/scripts/install +++ b/scripts/install @@ -143,7 +143,7 @@ ynh_app_setting_set "$app" db_name "$db_name" ynh_app_setting_set "$app" db_user "$db_user" ynh_mysql_setup_db "$db_user" "$db_name" -export mysqlconn="mysql -u $db_user -p $db_pwd $db_name" +export mysqlconn="mysql -u$db_user -p$db_pwd $db_name" zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | $mysqlconn From f08b962df8c1f466a7b36651c8417c4361d39c4e Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 1 Mar 2019 11:08:30 +0100 Subject: [PATCH 027/144] check functions --- scripts/install | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/install b/scripts/install index ecd38d2..ed2083f 100644 --- a/scripts/install +++ b/scripts/install @@ -175,7 +175,7 @@ do fi done -disable_guest_user() +disable_guest_user #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -398,7 +398,7 @@ link_template #================================================= # disable default admin #================================================= -disable_admin_user() +disable_admin_user #================================================= # SETUP SSOWAT From c72d148043ef7ad45e20d99d8052081ef5e030ef Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 1 Mar 2019 11:12:47 +0100 Subject: [PATCH 028/144] Update _common.sh --- scripts/_common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 6bcc699..6819758 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -32,7 +32,7 @@ disable_guest_user(){ #===================GET ADMIN DEFAULT USER STATE============== #return 0 if enable, else 1 get_state_admin_user(){ - return $($mysqlconn -BN -e "SELECT count(id) from \`users_groups\` where userid=1 and usrgrpid=9") + return $mysqlconn -BN -e "SELECT count(id) from \`users_groups\` where userid=1 and usrgrpid=9" } #================ DISABLE DEFAULT ADMIN USER =================== From 3c82944f1180d6a6afdb437a7006029f0e3ef5a5 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 1 Mar 2019 11:18:17 +0100 Subject: [PATCH 029/144] Update _common.sh --- scripts/_common.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 6819758..1cb3466 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -16,7 +16,7 @@ ynh_delete_file_checksum () { #===================GET GUEST DEFAULT USER STATE============== #return 0 if enable, else 1 get_state_guest_user(){ - return $($mysqlconn -BN -e "SELECT count(id) from \`users_groups\` where userid=2 and usrgrpid=9") + $mysqlconn -BN -e "SELECT count(id) from \`users_groups\` where userid=2 and usrgrpid=9" } #================ DISABLE DEFAULT ZABBIX USER GUEST =================== @@ -32,7 +32,7 @@ disable_guest_user(){ #===================GET ADMIN DEFAULT USER STATE============== #return 0 if enable, else 1 get_state_admin_user(){ - return $mysqlconn -BN -e "SELECT count(id) from \`users_groups\` where userid=1 and usrgrpid=9" + $mysqlconn -BN -e "SELECT count(id) from \`users_groups\` where userid=1 and usrgrpid=9" } #================ DISABLE DEFAULT ADMIN USER =================== From f6f063177453bd0dabac97964e9c8b8ed5408b4a Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 1 Mar 2019 11:27:25 +0100 Subject: [PATCH 030/144] Update _common.sh --- scripts/_common.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 1cb3466..52ee149 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -16,13 +16,13 @@ ynh_delete_file_checksum () { #===================GET GUEST DEFAULT USER STATE============== #return 0 if enable, else 1 get_state_guest_user(){ - $mysqlconn -BN -e "SELECT count(id) from \`users_groups\` where userid=2 and usrgrpid=9" + return $($mysqlconn -BN -e "SELECT count(id) from \`users_groups\` where userid=2 and usrgrpid=9") } #================ DISABLE DEFAULT ZABBIX USER GUEST =================== disable_guest_user(){ - if [ get_state_guest_user -eq 0 ];then + if [ get_state_guest_user = "0" ];then lastid=$($mysqlconn -BN -e "SELECT max(id) from \`users_groups\`") lastid=$(("$lastid" + 1 )) $mysqlconn -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 2);" @@ -32,12 +32,12 @@ disable_guest_user(){ #===================GET ADMIN DEFAULT USER STATE============== #return 0 if enable, else 1 get_state_admin_user(){ - $mysqlconn -BN -e "SELECT count(id) from \`users_groups\` where userid=1 and usrgrpid=9" + return $mysqlconn -BN -e "SELECT count(id) from \`users_groups\` where userid=1 and usrgrpid=9" } #================ DISABLE DEFAULT ADMIN USER =================== disable_admin_user(){ - if [ get_state_admin_user -eq 0 ] ;then + if [ get_state_admin_user = "0" ] ;then lastid=$($mysqlconn -BN -e "SELECT max(id) from \`users_groups\`") lastid=$((lastid + 1 )) $mysqlconn -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 1);" @@ -50,7 +50,7 @@ disable_admin_user(){ } enable_admin_user(){ - if [ get_state_admin_user -eq 1 ] ;then + if [ get_state_admin_user = "1" ] ;then ynh_print_info "Enable default admin" #enable default admin temporaly $mysqlconn -e "DELETE FROM users_groups where usrgrpid=9 and userid=1;" From 78ec23008b6788ce896e7e93bab4dac4e1bed956 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 1 Mar 2019 11:30:54 +0100 Subject: [PATCH 031/144] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fd1a450..d3815ec 100644 --- a/README.md +++ b/README.md @@ -32,15 +32,17 @@ Do not change admin password. * The Zabbix server port is not opened by default for external monitoring (active agent). * Install or update apply a template yunohost on the host "Zabbix-server" (127.0.0.1) for basic monitoring for Yunohost. * If you want more information about Yunohost in the template, please open an issue on git. +* This package install non-free (pinning for just snmp-mibs-downloader) and Zabbix repo (for last Zabbix stable version). **More information on the documentation page:** https://yunohost.org/packaging_apps ## LICENSE GNU AFFERO GENERAL PUBLIC LICENSE Version 3 - got to https://framagit.org/Mickael-Martin/zabbix_ynh/blob/master/LICENSE +snmp-mibs-downloader use this licence : https://metadata.ftp-master.debian.org/changelogs/non-free/s/snmp-mibs-downloader/snmp-mibs-downloader_1.1+nmu1_copyright + ## Links * Report a bug: https://framagit.org/Mickael-Martin/zabbix_ynh/issues From 5730e054ebac2c00d39243c01647c1152a7693dd Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 1 Mar 2019 11:36:17 +0100 Subject: [PATCH 032/144] Update manifest.json to add non-free option --- manifest.json | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index ef43492..a418f5a 100644 --- a/manifest.json +++ b/manifest.json @@ -65,7 +65,7 @@ }, { "name": "language", - "type": "string", + "type": "string", "ask": { "en": "Choose the application language", "fr": "Choisissez la langue de l'application" @@ -73,6 +73,15 @@ "choices": ["fr", "en"], "default": "en" } + { + "name": "accept_licence_non-free", + "type": "boolean", + "ask": { + "en": "This app can use non-free repo to install snmp-mibs-downloader package (help on OID resultion), do you want install this package ?", + "fr": "Cette application peut utiliser le repo non-free pour installer snmp-mibs-downloader (qui aide à la résolution des OID), souhaitez vous installez ce packet ?" + }, + "default": false + } ] } } From 5192e1e7f05a2ad81971818fa1a42c6bcb5966fa Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 1 Mar 2019 11:37:21 +0100 Subject: [PATCH 033/144] Update manifest.json --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index a418f5a..7157f24 100644 --- a/manifest.json +++ b/manifest.json @@ -72,7 +72,7 @@ }, "choices": ["fr", "en"], "default": "en" - } + }, { "name": "accept_licence_non-free", "type": "boolean", From 1ef40b18e50551c4356959c73495ae9a435ce075 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 1 Mar 2019 11:38:30 +0100 Subject: [PATCH 034/144] Revert "Update README.md" This reverts commit 78ec23008b6788ce896e7e93bab4dac4e1bed956 --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index d3815ec..fd1a450 100644 --- a/README.md +++ b/README.md @@ -32,16 +32,14 @@ Do not change admin password. * The Zabbix server port is not opened by default for external monitoring (active agent). * Install or update apply a template yunohost on the host "Zabbix-server" (127.0.0.1) for basic monitoring for Yunohost. * If you want more information about Yunohost in the template, please open an issue on git. -* This package install non-free (pinning for just snmp-mibs-downloader) and Zabbix repo (for last Zabbix stable version). **More information on the documentation page:** https://yunohost.org/packaging_apps ## LICENSE GNU AFFERO GENERAL PUBLIC LICENSE Version 3 -got to https://framagit.org/Mickael-Martin/zabbix_ynh/blob/master/LICENSE -snmp-mibs-downloader use this licence : https://metadata.ftp-master.debian.org/changelogs/non-free/s/snmp-mibs-downloader/snmp-mibs-downloader_1.1+nmu1_copyright +got to https://framagit.org/Mickael-Martin/zabbix_ynh/blob/master/LICENSE ## Links From 39905d8268ccfbf360fe7b6ef55b12620d5b8ce8 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 1 Mar 2019 11:41:25 +0100 Subject: [PATCH 035/144] Update manifest.json --- manifest.json | 9 --------- 1 file changed, 9 deletions(-) diff --git a/manifest.json b/manifest.json index 7157f24..4816e75 100644 --- a/manifest.json +++ b/manifest.json @@ -72,15 +72,6 @@ }, "choices": ["fr", "en"], "default": "en" - }, - { - "name": "accept_licence_non-free", - "type": "boolean", - "ask": { - "en": "This app can use non-free repo to install snmp-mibs-downloader package (help on OID resultion), do you want install this package ?", - "fr": "Cette application peut utiliser le repo non-free pour installer snmp-mibs-downloader (qui aide à la résolution des OID), souhaitez vous installez ce packet ?" - }, - "default": false } ] } From 755ec37db53f9d6e819a1e144f3614b66087a326 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 1 Mar 2019 11:42:18 +0100 Subject: [PATCH 036/144] Update _common.sh --- scripts/_common.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 52ee149..38f2362 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -16,7 +16,7 @@ ynh_delete_file_checksum () { #===================GET GUEST DEFAULT USER STATE============== #return 0 if enable, else 1 get_state_guest_user(){ - return $($mysqlconn -BN -e "SELECT count(id) from \`users_groups\` where userid=2 and usrgrpid=9") + $mysqlconn -BN -e "SELECT count(id) from \`users_groups\` where userid=2 and usrgrpid=9" } #================ DISABLE DEFAULT ZABBIX USER GUEST =================== @@ -32,7 +32,7 @@ disable_guest_user(){ #===================GET ADMIN DEFAULT USER STATE============== #return 0 if enable, else 1 get_state_admin_user(){ - return $mysqlconn -BN -e "SELECT count(id) from \`users_groups\` where userid=1 and usrgrpid=9" + $mysqlconn -BN -e "SELECT count(id) from \`users_groups\` where userid=1 and usrgrpid=9" } #================ DISABLE DEFAULT ADMIN USER =================== From ae54783519f5520363c10d352c71edc6543dd1f7 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 1 Mar 2019 19:30:25 +0100 Subject: [PATCH 037/144] Update manifest.json snmp downloader non-free --- manifest.json | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/manifest.json b/manifest.json index 4816e75..53317e3 100644 --- a/manifest.json +++ b/manifest.json @@ -72,6 +72,19 @@ }, "choices": ["fr", "en"], "default": "en" + }, + { + "name": "add_nonfree", + "type": "boolean", + "ask": { + "en": "This application can install snmp-mibs-downloader from non-free repository to resolve many OID by default, do you want install this package ?", + "fr": "Cette application peut installer snmp-mibs-downloader depuis le dépôt non-free afin de resoudre de nombreux OID par defaut, souhaitez vous installer ce package ?" + }, + "help": { + "en" : "Zabbix works without problem without the package snmp-mibs-downloader, however it help to resolve OIDs to comprehensive strings. If you make the choice of installing it, the pinning method is used", + "fr" : "Zabbix peut fonctionner sans le paquet snmp-mibs-downloader, cependant il aide à faire la résolution des OIDs en chaines de caractères compréhensibles. Si vous faites le choix de l'installer, il sera installé par méthode 'pinning'" + }, + "default": false } ] } From e870de8e7de9f35df6e8be5b10738e903dfa98bb Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 1 Mar 2019 19:37:23 +0100 Subject: [PATCH 038/144] Update install (adjust apt install) --- scripts/install | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/scripts/install b/scripts/install index ed2083f..de3e325 100644 --- a/scripts/install +++ b/scripts/install @@ -24,6 +24,7 @@ export path_url="$YNH_APP_ARG_PATH" admin="$YNH_APP_ARG_ADMIN" is_public="$YNH_APP_ARG_IS_PUBLIC" language="$YNH_APP_ARG_LANGUAGE" +nonfree="$YNH_APP_ARG_ADD_NONFREE" ### If it's a multi-instance app, meaning it can be installed several times independently ### The id of the app as stated in the manifest is available as $YNH_APP_ID @@ -100,20 +101,19 @@ ynh_print_info "Install dependencies" wget "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 -echo "deb http://deb.debian.org/debian stretch non-free" >/etc/apt/sources.list.d/non-free.list + +if [ $nonfree ];then + echo "deb http://deb.debian.org/debian stretch non-free" >/etc/apt/sources.list.d/non-free.list +fi ynh_package_update -ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd snmp-mibs-downloader libjs-prototype zabbix-server-mysql zabbix-agent jq -yunohost service add snmpd -d "Management of SNMP Daemon" -DEBIAN_FRONTEND=noninteractive apt-get -y download zabbix-frontend-php -ar x ./*.deb -tar xzf control.tar.gz -sed -i 's/apache2 | httpd, //' control -tar --ignore-failed-read -cvzf control.tar.gz {post,pre}{inst,rm} md5sums control -ar rcs zabbix-frontend-php+stretch_all-noapache2.deb debian-binary control.tar.gz data.tar.xz +if [ $nonfree ];then + ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd snmp-mibs-downloader libjs-prototype jq +else + ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd libjs-prototype jq -dpkg -i zabbix-frontend-php+stretch_all-noapache2.deb +fi -rm -fr zabbix-*.deb +ynh_package_install zabbix-server-mysql zabbix-agent zabbix-frontend-php 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 From 78a46c13715fcf52e4a82ea28ac2bf2105d78996 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 5 Mar 2019 10:52:53 +0100 Subject: [PATCH 039/144] Add new directory --- sources/extra_files/app/preferences.d/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 sources/extra_files/app/preferences.d/.gitkeep diff --git a/sources/extra_files/app/preferences.d/.gitkeep b/sources/extra_files/app/preferences.d/.gitkeep new file mode 100644 index 0000000..e69de29 From 3bc33e56d86caed35a6b4d1e2e7fd9bef09b8bb0 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 5 Mar 2019 10:54:11 +0100 Subject: [PATCH 040/144] add file preferences to disable all packages non-free --- sources/extra_files/app/preferences.d/non-free_policy | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 sources/extra_files/app/preferences.d/non-free_policy diff --git a/sources/extra_files/app/preferences.d/non-free_policy b/sources/extra_files/app/preferences.d/non-free_policy new file mode 100644 index 0000000..4353574 --- /dev/null +++ b/sources/extra_files/app/preferences.d/non-free_policy @@ -0,0 +1,4 @@ +Explanation: Disable packages from non-free tree by default (Zabbix app install with non-free option enable) +Package: * +Pin: release o=Debian,a=stable,l=Debian,c=non-free +Pin-Priority: -1 \ No newline at end of file From 5ffae31be541f666f73006049d7ffe45906984cd Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 5 Mar 2019 10:56:16 +0100 Subject: [PATCH 041/144] Add file to add snmp-mibs-downloader from non-free --- .../app/preferences.d/snmp-mibs-downloader_nonfree | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 sources/extra_files/app/preferences.d/snmp-mibs-downloader_nonfree diff --git a/sources/extra_files/app/preferences.d/snmp-mibs-downloader_nonfree b/sources/extra_files/app/preferences.d/snmp-mibs-downloader_nonfree new file mode 100644 index 0000000..1fb7921 --- /dev/null +++ b/sources/extra_files/app/preferences.d/snmp-mibs-downloader_nonfree @@ -0,0 +1,4 @@ +Explanation: Enable package snmp-mibs-downloader from non-free tree (Zabbix app install with non-free option enable) +Package: snmp-mibs-downloader +Pin: release o=Debian,a=stable,l=Debian,c=non-free +Pin-Priority: 600 \ No newline at end of file From 10e35a6e9edb6de45eadd0c041a2d724b94ef22d Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 5 Mar 2019 11:03:55 +0100 Subject: [PATCH 042/144] nonfree setup --- scripts/install | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index de3e325..29c8d6f 100644 --- a/scripts/install +++ b/scripts/install @@ -96,15 +96,22 @@ ynh_app_setting_set "$app" language "$language" ### - Remove the section "REMOVE DEPENDENCIES" in the remove script ### - As well as the section "REINSTALL DEPENDENCIES" in the restore script ### - And the section "UPGRADE DEPENDENCIES" in the upgrade script -ynh_print_info "Install dependencies" +ynh_print_info "Install Zabbix repository" wget "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_print_info "Install non-free repository with pinning" if [ $nonfree ];then echo "deb http://deb.debian.org/debian stretch non-free" >/etc/apt/sources.list.d/non-free.list + nonfreefilerepo=$(find /var/cache/yunohost/ -name "non-free_policy") + packagenonfreefilerepo=$(find /var/cache/yunohost/ -name "snmp-mibs-downloader_nonfree") + cp $nonfreefilerepo /etc/apt/preferences.d/ + cp $packagenonfreefilerepo /etc/apt/preferences.d/ fi + +ynh_print_info "Update and install dependencies" ynh_package_update if [ $nonfree ];then ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd snmp-mibs-downloader libjs-prototype jq From 12a85212cb09f75de16b76ecf7600a08b9d77105 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 5 Mar 2019 11:07:16 +0100 Subject: [PATCH 043/144] Update backup to include nonfree repo (pinning) --- scripts/backup | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/backup b/scripts/backup index 300cbbb..745ff1b 100644 --- a/scripts/backup +++ b/scripts/backup @@ -29,6 +29,8 @@ app="zabbix" 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) +nonfree=$(ynh_app_setting_get $app nonfree) + #================================================= # STANDARD BACKUP STEPS @@ -69,4 +71,8 @@ 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 From 33c39b0e9b6585b54e56cc49a943df2995bb3e33 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 5 Mar 2019 11:10:35 +0100 Subject: [PATCH 044/144] Update restore (add pinning for nonfree) --- scripts/restore | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/scripts/restore b/scripts/restore index 3bdab07..db08fa9 100644 --- a/scripts/restore +++ b/scripts/restore @@ -44,33 +44,42 @@ domain=$(ynh_app_setting_get $app domain) #admin=$(ynh_app_setting_get $app admin) #not used is_public=$(ynh_app_setting_get $app is_public) #language=$(ynh_app_setting_get $app language) #not used +nonfree=$(ynh_app_setting_get $app nonfree) + #================================================= # INSTALL DEPENDENCIES #================================================= +ynh_print_info "Install Zabbix repository" + wget "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 -echo "deb http://deb.debian.org/debian stretch non-free" >/etc/apt/sources.list.d/non-free.list + +ynh_print_info "Install non-free repository with pinning" +if [ $nonfree ];then + ynh_restore_file "/etc/apt/sources.list.d/non-free.list" + ynh_restore_file "/etc/apt/preferences.d" + +fi + +ynh_print_info "Update and install dependencies" ynh_package_update -ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd snmp-mibs-downloader libjs-prototype zabbix-server-mysql zabbix-agent -yunohost service add snmpd -d "Management of SNMP Daemon" -DEBIAN_FRONTEND=noninteractive apt-get -y download zabbix-frontend-php -ar x ./*.deb -tar xzf control.tar.gz -ynh_replace_string "apache2 | httpd, " "" control -tar --ignore-failed-read -cvzf control.tar.gz {post,pre}{inst,rm} md5sums control -ar rcs zabbix-frontend-php+stretch_all-noapache2.deb debian-binary control.tar.gz data.tar.xz +if [ $nonfree ];then + ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd snmp-mibs-downloader libjs-prototype jq +else + ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd libjs-prototype jq -dpkg -i zabbix-frontend-php+stretch_all-noapache2.deb +fi -rm -fr zabbix-*.deb +ynh_package_install zabbix-server-mysql zabbix-agent zabbix-frontend-php DEBIAN_FRONTEND=noninteractive apt-mark hold zabbix-server-mysql zabbix-frontend-php -ynh_replace_string "# fr_FR.UTF-8 UTF-8" "fr_FR.UTF-8 UTF-8" /etc/locale.gen +sed -i "s/# fr_FR.UTF-8 UTF-8/fr_FR.UTF-8 UTF-8/g" /etc/locale.gen locale-gen + ln -s /usr/share/zabbix /var/www/zabbix rm $final_path/conf/zabbix.conf.php @@ -136,9 +145,6 @@ ynh_restore_file "/etc/zabbix" systemctl enable zabbix-server && systemctl start zabbix-server - - - #================================================= # SETUP LOGROTATE #================================================= From 7cd8454b0ea152c734efcc9dd9134c8c3b66d5e2 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 5 Mar 2019 13:50:37 +0100 Subject: [PATCH 045/144] Update upgrade for pinning install (nonfree) --- scripts/upgrade | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 8797bfe..c019f92 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -24,6 +24,7 @@ final_path=$(ynh_app_setting_get "$app" final_path) 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) +nonfree=$(ynh_app_setting_get "$app" nonfree) #================================================= @@ -125,16 +126,28 @@ then cp -p /usr/share/zabbix/conf/zabbix.conf.php /tmp/ DEBIAN_FRONTEND=noninteractive apt-mark unhold zabbix-server-mysql zabbix-frontend-php - DEBIAN_FRONTEND=noninteractive apt-get -y download zabbix-frontend-php - ar x ./*.deb - tar xzf control.tar.gz - ynh_replace_string "apache2 | httpd, " "" control - tar --ignore-failed-read -cvzf control.tar.gz {post,pre}{inst,rm} md5sums control - ar rcs zabbix-frontend-php+stretch_all-noapache2.deb debian-binary control.tar.gz data.tar.xz - dpkg -i zabbix-frontend-php+stretch_all-noapache2.deb - rm -fr zabbix-*.deb - apt-get -y --only-upgrade install zabbix-server-mysql zabbix-agent - DEBIAN_FRONTEND=noninteractive apt-mark hold zabbix-server-mysql zabbix-frontend-php + + ynh_print_info "Install non-free repository with pinning" + if [ $nonfree ];then + echo "deb http://deb.debian.org/debian stretch non-free" >/etc/apt/sources.list.d/non-free.list + nonfreefilerepo=$(find /var/cache/yunohost/ -name "non-free_policy") + packagenonfreefilerepo=$(find /var/cache/yunohost/ -name "snmp-mibs-downloader_nonfree") + cp $nonfreefilerepo /etc/apt/preferences.d/ + cp $packagenonfreefilerepo /etc/apt/preferences.d/ + fi + + ynh_print_info "Update and install dependencies" + ynh_package_update + if [ $nonfree ];then + ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd snmp-mibs-downloader libjs-prototype jq + else + ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd libjs-prototype jq + + fi + + ynh_package_install zabbix-server-mysql zabbix-agent zabbix-frontend-php + DEBIAN_FRONTEND=noninteractive apt-mark hold zabbix-server-mysql zabbix-frontend-php + rm /usr/share/zabbix/conf/zabbix.conf.php cp -rpf /tmp/zabbix /etc/ From 134afaa556adee2d7de3e306d907f6ada42ae9e3 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 5 Mar 2019 13:53:24 +0100 Subject: [PATCH 046/144] Update upgrade to 1:4.0.5-1+stretch zabbix version --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index c019f92..eb8eb09 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -14,7 +14,7 @@ source /usr/share/yunohost/helpers #================================================= app=$YNH_APP_INSTANCE_NAME -trustedversion="1:4.0.4-1+stretch" +trustedversion="1:4.0.5-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 7b574df3b672f90c8c3b1a29ef638b756bb4bb91 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 5 Mar 2019 14:03:27 +0100 Subject: [PATCH 047/144] add compatibility for all languages. --- scripts/upgrade | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index eb8eb09..fbe4a00 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -95,14 +95,14 @@ ynh_package_update #REMOVE DUPLICATE LOG ENTRY IN LOGROTATE PATCH IF NEEDED ynh_remove_logrotate -zabbixServerInstalledVersion=$(apt-cache policy zabbix-server-mysql | grep -Po "Installed: \K(.*)") -zabbixServerCandidateVersion=$(apt-cache policy zabbix-server-mysql | grep -Po "Candidate: \K(.*)") +zabbixServerInstalledVersion=$(apt-cache policy zabbix-server-mysql | sed -n '2p' | grep -Po ".*: \K(.*)") +zabbixServerCandidateVersion=$(apt-cache policy zabbix-server-mysql | sed -n '3p' | grep -Po ".*: \K(.*)") -zabbixFrontendInstalledVersion=$(apt-cache policy zabbix-frontend-php | grep -Po "Installed: \K(.*)") -zabbixFrontendCandidateVersion=$(apt-cache policy zabbix-frontend-php | grep -Po "Candidate: \K(.*)") +zabbixFrontendInstalledVersion=$(apt-cache policy zabbix-frontend-php | sed -n '2p' | grep -Po ".*: \K(.*)") +zabbixFrontendCandidateVersion=$(apt-cache policy zabbix-frontend-php | sed -n '3p' | grep -Po ".*: \K(.*)") -zabbixagentInstalledVersion=$(apt-cache policy zabbix-agent | grep -Po "Installed: \K(.*)") -zabbixagentCandidateVersion=$(apt-cache policy zabbix-agent | grep -Po "Candidate: \K(.*)") +zabbixagentInstalledVersion=$(apt-cache policy zabbix-agent | sed -n '2p' | grep -Po ".*: \K(.*)") +zabbixagentCandidateVersion=$(apt-cache policy zabbix-agent | sed -n '3p' | grep -Po ".*: \K(.*)") if [ "$trustedversion" == "$zabbixServerCandidateVersion" ] then From 25be1100322d2f2b4af4066cdfcb4bc947818abd Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 7 Mar 2019 12:21:54 +0100 Subject: [PATCH 048/144] removing nonfree part --- manifest.json | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/manifest.json b/manifest.json index 53317e3..4816e75 100644 --- a/manifest.json +++ b/manifest.json @@ -72,19 +72,6 @@ }, "choices": ["fr", "en"], "default": "en" - }, - { - "name": "add_nonfree", - "type": "boolean", - "ask": { - "en": "This application can install snmp-mibs-downloader from non-free repository to resolve many OID by default, do you want install this package ?", - "fr": "Cette application peut installer snmp-mibs-downloader depuis le dépôt non-free afin de resoudre de nombreux OID par defaut, souhaitez vous installer ce package ?" - }, - "help": { - "en" : "Zabbix works without problem without the package snmp-mibs-downloader, however it help to resolve OIDs to comprehensive strings. If you make the choice of installing it, the pinning method is used", - "fr" : "Zabbix peut fonctionner sans le paquet snmp-mibs-downloader, cependant il aide à faire la résolution des OIDs en chaines de caractères compréhensibles. Si vous faites le choix de l'installer, il sera installé par méthode 'pinning'" - }, - "default": false } ] } From 06a52c20ae319cb0b8a41ccd7acaae0f806682d0 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 7 Mar 2019 12:22:50 +0100 Subject: [PATCH 049/144] removing nonfree part --- scripts/install | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/scripts/install b/scripts/install index 29c8d6f..df2f530 100644 --- a/scripts/install +++ b/scripts/install @@ -24,7 +24,6 @@ export path_url="$YNH_APP_ARG_PATH" admin="$YNH_APP_ARG_ADMIN" is_public="$YNH_APP_ARG_IS_PUBLIC" language="$YNH_APP_ARG_LANGUAGE" -nonfree="$YNH_APP_ARG_ADD_NONFREE" ### If it's a multi-instance app, meaning it can be installed several times independently ### The id of the app as stated in the manifest is available as $YNH_APP_ID @@ -102,23 +101,9 @@ wget "https://repo.zabbix.com/zabbix/4.0/debian/pool/main/z/zabbix-release/zabbi dpkg -i zabbix-release_*.deb rm zabbix-release_*.deb -ynh_print_info "Install non-free repository with pinning" -if [ $nonfree ];then - echo "deb http://deb.debian.org/debian stretch non-free" >/etc/apt/sources.list.d/non-free.list - nonfreefilerepo=$(find /var/cache/yunohost/ -name "non-free_policy") - packagenonfreefilerepo=$(find /var/cache/yunohost/ -name "snmp-mibs-downloader_nonfree") - cp $nonfreefilerepo /etc/apt/preferences.d/ - cp $packagenonfreefilerepo /etc/apt/preferences.d/ -fi - ynh_print_info "Update and install dependencies" ynh_package_update -if [ $nonfree ];then - ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd snmp-mibs-downloader libjs-prototype jq -else - ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd libjs-prototype jq - -fi +ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd libjs-prototype jq ynh_package_install zabbix-server-mysql zabbix-agent zabbix-frontend-php DEBIAN_FRONTEND=noninteractive apt-mark hold zabbix-server-mysql zabbix-frontend-php From ff3e0bd359c1c37c0b85bcad1ae5dd8c7ee237b8 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 7 Mar 2019 12:33:25 +0100 Subject: [PATCH 050/144] remove old (v1) nonfree part --- scripts/upgrade | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index fbe4a00..138b580 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -24,8 +24,6 @@ final_path=$(ynh_app_setting_get "$app" final_path) 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) -nonfree=$(ynh_app_setting_get "$app" nonfree) - #================================================= # ENSURE DOWNWARD COMPATIBILITY @@ -86,6 +84,12 @@ disable_guest_user # Normalize the URL path syntax path_url=$(ynh_normalize_url_path "$path_url") +#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 + rm /etc/apt/sources.list.d/non-free.list +fi + #================================================= # STANDARD UPGRADE STEPS #================================================= @@ -126,25 +130,10 @@ then cp -p /usr/share/zabbix/conf/zabbix.conf.php /tmp/ DEBIAN_FRONTEND=noninteractive apt-mark unhold zabbix-server-mysql zabbix-frontend-php - - ynh_print_info "Install non-free repository with pinning" - if [ $nonfree ];then - echo "deb http://deb.debian.org/debian stretch non-free" >/etc/apt/sources.list.d/non-free.list - nonfreefilerepo=$(find /var/cache/yunohost/ -name "non-free_policy") - packagenonfreefilerepo=$(find /var/cache/yunohost/ -name "snmp-mibs-downloader_nonfree") - cp $nonfreefilerepo /etc/apt/preferences.d/ - cp $packagenonfreefilerepo /etc/apt/preferences.d/ - fi - + ynh_print_info "Update and install dependencies" ynh_package_update - if [ $nonfree ];then - ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd snmp-mibs-downloader libjs-prototype jq - else - ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd libjs-prototype jq - - fi - + ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd libjs-prototype jq ynh_package_install zabbix-server-mysql zabbix-agent zabbix-frontend-php DEBIAN_FRONTEND=noninteractive apt-mark hold zabbix-server-mysql zabbix-frontend-php From 486b6754b499139db71208d163992374f8f8b565 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 7 Mar 2019 12:49:51 +0100 Subject: [PATCH 051/144] add details of imported template yunohost --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fd1a450..58de2be 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Do not change admin password. * Do not change the default admin user password. The user is disabled juste after the install but used to update templates. * The Zabbix server port is not opened by default for external monitoring (active agent). -* Install or update apply a template yunohost on the host "Zabbix-server" (127.0.0.1) for basic monitoring for Yunohost. +* A Yunohost template is imported and linked to the host "Zabbix-server" (127.0.0.1) for basic monitoring for Yunohost. * If you want more information about Yunohost in the template, please open an issue on git. **More information on the documentation page:** From 325eef7214621680e961a44958bf07dadcbec01f Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 7 Mar 2019 12:57:36 +0100 Subject: [PATCH 052/144] mysql str --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index 138b580..e8c3e97 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -50,7 +50,7 @@ if [ -z "$final_path" ]; then ynh_app_setting_set "$app" final_path "$final_path" fi -export mysqlconn="mysql -u $db_user -p $db_pwd $db_name" +export mysqlconn="mysql -u$db_user -p$db_pwd $db_name" #================================================= # Enable default admin temporaly From 3289cd3faf81e3e4092d0016364ab7e58266ed4a Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 7 Mar 2019 13:14:48 +0100 Subject: [PATCH 053/144] Update _common.sh if condition broken --- scripts/_common.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 38f2362..79bf17b 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -22,7 +22,7 @@ get_state_guest_user(){ #================ DISABLE DEFAULT ZABBIX USER GUEST =================== disable_guest_user(){ - if [ get_state_guest_user = "0" ];then + if [ $(get_state_guest_user) = "0" ];then lastid=$($mysqlconn -BN -e "SELECT max(id) from \`users_groups\`") lastid=$(("$lastid" + 1 )) $mysqlconn -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 2);" @@ -37,7 +37,7 @@ get_state_admin_user(){ #================ DISABLE DEFAULT ADMIN USER =================== disable_admin_user(){ - if [ get_state_admin_user = "0" ] ;then + if [ $(get_state_admin_user) = "0" ] ;then lastid=$($mysqlconn -BN -e "SELECT max(id) from \`users_groups\`") lastid=$((lastid + 1 )) $mysqlconn -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 1);" @@ -50,7 +50,7 @@ disable_admin_user(){ } enable_admin_user(){ - if [ get_state_admin_user = "1" ] ;then + if [ $(get_state_admin_user) = "1" ] ;then ynh_print_info "Enable default admin" #enable default admin temporaly $mysqlconn -e "DELETE FROM users_groups where usrgrpid=9 and userid=1;" From b5c354a5912587967025e23ad9cd368f2a6603a4 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 7 Mar 2019 13:41:23 +0100 Subject: [PATCH 054/144] removing dependencies snmp-mibs-downloader --- scripts/upgrade | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index e8c3e97..94885f6 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -87,7 +87,11 @@ path_url=$(ynh_normalize_url_path "$path_url") #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 - rm /etc/apt/sources.list.d/non-free.list + ynh_print_info "Removing snmp-mibs-downloader (non-free package)" + sed -i.$(date "+%m%d%y") 's/ snmp-mibs-downloader,//g' /var/lib/dpkg/status + DEBIAN_FRONTEND=noninteractive apt purge snmp-mibs-downloader + if [ -f /etc/apt/sources.list.d/non-free.list ];then + ynh_secure_remove /etc/apt/sources.list.d/non-free.list fi #================================================= From 77fb6333e4127ab8776985b18dddbb0d045a87aa Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 7 Mar 2019 13:45:28 +0100 Subject: [PATCH 055/144] close broken condition --- scripts/upgrade | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index 94885f6..695370a 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -91,7 +91,8 @@ if [ $(echo $nonfreepackagelist | wc -l) -eq 1 ] && [ $(echo $nonfreepackagelist sed -i.$(date "+%m%d%y") 's/ snmp-mibs-downloader,//g' /var/lib/dpkg/status DEBIAN_FRONTEND=noninteractive apt purge snmp-mibs-downloader if [ -f /etc/apt/sources.list.d/non-free.list ];then - ynh_secure_remove /etc/apt/sources.list.d/non-free.list + ynh_secure_remove /etc/apt/sources.list.d/non-free.list + fi fi #================================================= From 04a320adf942ab3f5ab89cceb6242b5cba606965 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 7 Mar 2019 13:46:45 +0100 Subject: [PATCH 056/144] add yes to purge --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index 695370a..666b60a 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -89,7 +89,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)" sed -i.$(date "+%m%d%y") 's/ snmp-mibs-downloader,//g' /var/lib/dpkg/status - DEBIAN_FRONTEND=noninteractive apt purge snmp-mibs-downloader + 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 From 3b6a8dd7290d81f37b0a668fcddb71f69e05fbdd Mon Sep 17 00:00:00 2001 From: root Date: Thu, 7 Mar 2019 13:01:01 +0100 Subject: [PATCH 057/144] remove nonfree part --- sources/extra_files/app/preferences.d/.gitkeep | 0 sources/extra_files/app/preferences.d/non-free_policy | 4 ---- .../app/preferences.d/snmp-mibs-downloader_nonfree | 4 ---- 3 files changed, 8 deletions(-) delete mode 100644 sources/extra_files/app/preferences.d/.gitkeep delete mode 100644 sources/extra_files/app/preferences.d/non-free_policy delete mode 100644 sources/extra_files/app/preferences.d/snmp-mibs-downloader_nonfree diff --git a/sources/extra_files/app/preferences.d/.gitkeep b/sources/extra_files/app/preferences.d/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/sources/extra_files/app/preferences.d/non-free_policy b/sources/extra_files/app/preferences.d/non-free_policy deleted file mode 100644 index 4353574..0000000 --- a/sources/extra_files/app/preferences.d/non-free_policy +++ /dev/null @@ -1,4 +0,0 @@ -Explanation: Disable packages from non-free tree by default (Zabbix app install with non-free option enable) -Package: * -Pin: release o=Debian,a=stable,l=Debian,c=non-free -Pin-Priority: -1 \ No newline at end of file diff --git a/sources/extra_files/app/preferences.d/snmp-mibs-downloader_nonfree b/sources/extra_files/app/preferences.d/snmp-mibs-downloader_nonfree deleted file mode 100644 index 1fb7921..0000000 --- a/sources/extra_files/app/preferences.d/snmp-mibs-downloader_nonfree +++ /dev/null @@ -1,4 +0,0 @@ -Explanation: Enable package snmp-mibs-downloader from non-free tree (Zabbix app install with non-free option enable) -Package: snmp-mibs-downloader -Pin: release o=Debian,a=stable,l=Debian,c=non-free -Pin-Priority: 600 \ No newline at end of file From 8518c14708bdffd063ac0767e6859f4f0aa81003 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 7 Mar 2019 15:03:07 +0100 Subject: [PATCH 058/144] Merge branch 'master' into 'testing' Master See merge request Mickael-Martin/zabbix_ynh!12 --- README.md | 2 +- manifest.json | 5 +- scripts/_common.sh | 127 +++++++++++++++++++++++++ scripts/backup | 6 ++ scripts/install | 226 +++++++++++++++++---------------------------- scripts/remove | 12 +-- scripts/restore | 51 +++++----- scripts/upgrade | 202 ++++++++++++---------------------------- 8 files changed, 313 insertions(+), 318 deletions(-) diff --git a/README.md b/README.md index fd1a450..58de2be 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Do not change admin password. * Do not change the default admin user password. The user is disabled juste after the install but used to update templates. * The Zabbix server port is not opened by default for external monitoring (active agent). -* Install or update apply a template yunohost on the host "Zabbix-server" (127.0.0.1) for basic monitoring for Yunohost. +* A Yunohost template is imported and linked to the host "Zabbix-server" (127.0.0.1) for basic monitoring for Yunohost. * If you want more information about Yunohost in the template, please open an issue on git. **More information on the documentation page:** diff --git a/manifest.json b/manifest.json index 04cd064..4816e75 100644 --- a/manifest.json +++ b/manifest.json @@ -7,7 +7,7 @@ "fr": "Zabbix pour Yunohost" }, "version": "2.0", - "url": "https://framagit.org/Mickael-Martin/zabbix_ynh", + "url": "https://www.zabbix.com", "license": "free", "maintainer": { "name": "Mickael Martin", @@ -61,10 +61,11 @@ "en": "Is it a public application?", "fr": "Est-ce une application publique ?" }, - "default": true + "default": false }, { "name": "language", + "type": "string", "ask": { "en": "Choose the application language", "fr": "Choisissez la langue de l'application" diff --git a/scripts/_common.sh b/scripts/_common.sh index bb04a03..79bf17b 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -10,4 +10,131 @@ ynh_delete_file_checksum () { local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_' ynh_app_setting_delete $app $checksum_setting_name +} + +#Zabbix part +#===================GET GUEST DEFAULT USER STATE============== +#return 0 if enable, else 1 +get_state_guest_user(){ + $mysqlconn -BN -e "SELECT count(id) from \`users_groups\` where userid=2 and usrgrpid=9" +} + +#================ DISABLE DEFAULT ZABBIX USER GUEST =================== + +disable_guest_user(){ + if [ $(get_state_guest_user) = "0" ];then + lastid=$($mysqlconn -BN -e "SELECT max(id) from \`users_groups\`") + lastid=$(("$lastid" + 1 )) + $mysqlconn -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 2);" + fi +} + +#===================GET ADMIN DEFAULT USER STATE============== +#return 0 if enable, else 1 +get_state_admin_user(){ + $mysqlconn -BN -e "SELECT count(id) from \`users_groups\` where userid=1 and usrgrpid=9" +} + +#================ DISABLE DEFAULT ADMIN USER =================== +disable_admin_user(){ + if [ $(get_state_admin_user) = "0" ] ;then + lastid=$($mysqlconn -BN -e "SELECT max(id) from \`users_groups\`") + lastid=$((lastid + 1 )) + $mysqlconn -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 1);" + ynh_print_info "Default admin disabled" + + else + ynh_print_info "Default admin already disabled" + + fi +} + +enable_admin_user(){ + if [ $(get_state_admin_user) = "1" ] ;then + ynh_print_info "Enable default admin" + #enable default admin temporaly + $mysqlconn -e "DELETE FROM users_groups where usrgrpid=9 and userid=1;" + ynh_print_info "Default admin enabled" + else + ynh_print_info "Default admin already enable" + fi +} + +import_template(){ + ynh_print_info "Import yunohost template" + 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 "$confUserPpath" /etc/zabbix/zabbix_agentd.d/userP_yunohost.conf + cp "$bashUserPpath" /etc/zabbix/zabbix_agentd.d/yunohost.sh + chmod a+x /etc/zabbix/zabbix_agentd.d/yunohost.sh + + systemctl restart zabbix-agent + curlOptions="-k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt --resolve $domain:443:127.0.0.1" + + curl -L $curlOptions \ + --form "enter=Sign+in" \ + --form "name=Admin" \ + --form "password=zabbix" \ + "$zabbixFullpath/index.php" + + if [ $? -eq 0 ];then + sid=$(curl $curlOptions \ + "$zabbixFullpath/conf.import.php?rules_preset=template" \ + | grep -Po 'name="sid" value="\K([a-z0-9]{16})(?=")' ) + + importState=$(curl $curlOptions \ + --form "config=1" \ + --form "import_file=@$localpath" \ + --form "rules[groups][createMissing]=1" \ + --form "rules[templates][updateExisting]=1" \ + --form "rules[templates][createMissing]=1" \ + --form "rules[templateScreens][updateExisting]=1" \ + --form "rules[templateScreens][createMissing]=1" \ + --form "rules[templateLinkage][createMissing]=1" \ + --form "rules[applications][createMissing]=1" \ + --form "rules[items][updateExisting]=1" \ + --form "rules[items][createMissing]=1" \ + --form "rules[discoveryRules][updateExisting]=1" \ + --form "rules[discoveryRules][createMissing]=1" \ + --form "rules[triggers][updateExisting]=1" \ + --form "rules[triggers][createMissing]=1" \ + --form "rules[graphs][updateExisting]=1" \ + --form "rules[graphs][createMissing]=1" \ + --form "rules[httptests][updateExisting]=1" \ + --form "rules[httptests][createMissing]=1" \ + --form "rules[valueMaps][createMissing]=1" \ + --form "import=Import" \ + --form "backurl=templates.php" \ + --form "form_refresh=1" \ + --form "sid=${sid}" \ \ + "${zabbixFullpath}/conf.import.php?rules_preset=template" \ + | grep -c "Imported successfully") + + if [ "$importState" -eq "1" ];then + ynh_print_info "Template Yunohost imported !" + else + ynh_print_warn "Template Yunohost not imported !" + fi + else + ynh_print_warn "Admin user cannot connect interface !" + fi +} + +link_template(){ + #apply template to host + tokenapi=$(curl -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 -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') + zabbixTemplateID=$(curl -k -s --resolve $domain:443:127.0.0.1 --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"template.get","params":{"filter":{"host":["Template Yunohost"]}},"auth":"'"$tokenapi"'","id":1}' "${zabbixFullpath}/api_jsonrpc.php" | jq -r '.result[0].templateid') + applyTemplate=$(curl -k -s --resolve $domain:443:127.0.0.1 --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.massadd","params":{"hosts":[{"hostid":"'"$zabbixHostID"'"}],"templates":[{"templateid":"'"$zabbixTemplateID"'"}]},"auth":"'"$tokenapi"'","id":1}' "${zabbixFullpath}/api_jsonrpc.php" | jq -r '.result.hostids[]') + if [ "$applyTemplate" -eq "$zabbixHostID" ];then + ynh_print_info "Template Yunohost linked to Zabbix server !" + else + ynh_print_warn "Template Yunohost no linked to Zabbix server !" + fi + } \ No newline at end of file diff --git a/scripts/backup b/scripts/backup index 300cbbb..745ff1b 100644 --- a/scripts/backup +++ b/scripts/backup @@ -29,6 +29,8 @@ app="zabbix" 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) +nonfree=$(ynh_app_setting_get $app nonfree) + #================================================= # STANDARD BACKUP STEPS @@ -69,4 +71,8 @@ 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 diff --git a/scripts/install b/scripts/install index f4cac42..df2f530 100644 --- a/scripts/install +++ b/scripts/install @@ -1,4 +1,5 @@ -#================================================= +#!/bin/bash +##================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS @@ -12,17 +13,17 @@ source /usr/share/yunohost/helpers #================================================= # Exit if an error occurs during the execution of the script -ynh_abort_if_errors +#ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= -domain=$YNH_APP_ARG_DOMAIN -path_url=$YNH_APP_ARG_PATH -admin=$YNH_APP_ARG_ADMIN -is_public=$YNH_APP_ARG_IS_PUBLIC -language=$YNH_APP_ARG_LANGUAGE +export domain="$YNH_APP_ARG_DOMAIN" +export path_url="$YNH_APP_ARG_PATH" +admin="$YNH_APP_ARG_ADMIN" +is_public="$YNH_APP_ARG_IS_PUBLIC" +language="$YNH_APP_ARG_LANGUAGE" ### If it's a multi-instance app, meaning it can be installed several times independently ### The id of the app as stated in the manifest is available as $YNH_APP_ID @@ -34,7 +35,7 @@ language=$YNH_APP_ARG_LANGUAGE ### The app instance name is probably what interests you most, since this is ### guaranteed to be unique. This is a good unique identifier to define installation path, ### db names, ... -app=$YNH_APP_INSTANCE_NAME +app="$YNH_APP_INSTANCE_NAME" #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS @@ -46,22 +47,23 @@ final_path=/var/www/zabbix 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) +path_url=$(ynh_normalize_url_path "$path_url") # Check web path availability -ynh_webpath_available $domain $path_url +ynh_webpath_available "$domain" "$path_url" # Register (book) web path -ynh_webpath_register $app $domain $path_url +ynh_webpath_register "$app" "$domain" "$path_url" #================================================= # STORE SETTINGS FROM MANIFEST #================================================= +ynh_print_info "Get infos from manifest" -ynh_app_setting_set $app domain $domain -ynh_app_setting_set $app path $path_url -ynh_app_setting_set $app admin $admin -ynh_app_setting_set $app is_public $is_public -ynh_app_setting_set $app language $language +ynh_app_setting_set "$app" domain "$domain" +ynh_app_setting_set "$app" path "$path_url" +ynh_app_setting_set "$app" admin "$admin" +ynh_app_setting_set "$app" is_public "$is_public" +ynh_app_setting_set "$app" language "$language" #================================================= # STANDARD MODIFICATIONS @@ -93,35 +95,29 @@ ynh_app_setting_set $app language $language ### - Remove the section "REMOVE DEPENDENCIES" in the remove script ### - As well as the section "REINSTALL DEPENDENCIES" in the restore script ### - And the section "UPGRADE DEPENDENCIES" in the upgrade script +ynh_print_info "Install Zabbix repository" wget "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 -echo "deb http://deb.debian.org/debian stretch non-free" >/etc/apt/sources.list.d/non-free.list + +ynh_print_info "Update and install dependencies" ynh_package_update -ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd snmp-mibs-downloader libjs-prototype zabbix-server-mysql zabbix-agent jq -yunohost service add snmpd -d "Management of SNMP Daemon" -DEBIAN_FRONTEND=noninteractive apt-get -y download zabbix-frontend-php -ar x *.deb -tar xzf control.tar.gz -sed -i 's/apache2 | httpd, //' control -tar --ignore-failed-read -cvzf control.tar.gz {post,pre}{inst,rm} md5sums control -ar rcs zabbix-frontend-php+stretch_all-noapache2.deb debian-binary control.tar.gz data.tar.xz +ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd libjs-prototype jq -dpkg -i zabbix-frontend-php+stretch_all-noapache2.deb - -rm -fr zabbix-*.deb +ynh_package_install zabbix-server-mysql zabbix-agent zabbix-frontend-php 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 locale-gen -ln -s /usr/share/zabbix $final_path -rm $final_path/conf/zabbix.conf.php +ln -s /usr/share/zabbix "$final_path" +rm "$final_path/conf/zabbix.conf.php" #================================================= # CREATE A MYSQL DATABASE #================================================= +ynh_print_info "Create and add default data in db" ### Use these lines if you need a database for the application. ### `ynh_mysql_setup_db` will create a database, an associated user and a ramdom password. @@ -132,46 +128,46 @@ rm $final_path/conf/zabbix.conf.php ### - Remove also the section "REMOVE THE MYSQL DATABASE" in the remove script ### - As well as the section "RESTORE THE MYSQL DATABASE" in the restore script -db_name=$(ynh_sanitize_dbid $app) -db_user=$db_name -ynh_app_setting_set $app db_name $db_name -ynh_app_setting_set $app db_user $db_user -ynh_mysql_setup_db $db_user $db_name +declare db_pwd +db_name=$(ynh_sanitize_dbid "$app") +db_user="$db_name" +ynh_app_setting_set "$app" db_name "$db_name" +ynh_app_setting_set "$app" db_user "$db_user" +ynh_mysql_setup_db "$db_user" "$db_name" -zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -u$db_user -p$db_pwd $db_name +export mysqlconn="mysql -u$db_user -p$db_pwd $db_name" + +zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | $mysqlconn #sso integration -mysql -u$db_user -p$db_pwd $db_name -e "UPDATE \`config\` SET \`http_auth_enabled\` = '1', \`http_login_form\` = '1' WHERE \`config\`.\`configid\` = 1;" +$mysqlconn -e "UPDATE \`config\` SET \`http_auth_enabled\` = '1', \`http_login_form\` = '1' WHERE \`config\`.\`configid\` = 1;" -if [ $language == "fr" ];then +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) +surname=$(ynh_user_get_info "$admin" lastname) +name=$(ynh_user_get_info "$admin" firstname) -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 (3,'"$admin"', '"$admin"', '"$admin"', '5fce1b3e34b520afeffb37ce08c7cd66', '', 0, '0', '"$lang"', '30s', 3, 'default', 0, '', 0, 50);" -mysql -u$db_user -p$db_pwd $db_name -e "INSERT INTO \`users_groups\` (\`id\`, \`usrgrpid\`, \`userid\`) VALUES (5, 7, 3);" +$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 u in $(ynh_user_list); +for user in $(ynh_user_list); do - if [ "$u" != "$admin" ];then - surname=$(ynh_user_get_info $u lastname) - name=$(ynh_user_get_info $u firstname) - 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 ("$i",'"$u"', '"$name"', '"$surname"', '5fce1b3e34b520afeffb37ce08c7cd66', '', 0, '0', '"$lang"', '30s', 1, 'default', 0, '', 0, 50);" - i=$(($i+1)) + 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 default guest -lastid=$(mysql -u$db_user -p$db_pwd $db_name -BN -e "SELECT max(id) from \`users_groups\`") -lastid=$(($lastid + 1 )) -mysql -u$db_user -p$db_pwd $db_name -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 2);" +disable_guest_user #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -181,10 +177,12 @@ mysql -u$db_user -p$db_pwd $db_name -e "INSERT INTO \`users_groups\` (\`id\` , \ ### downloaded from an upstream source, like a git repository. ### `ynh_setup_source` use the file conf/app.src -ynh_app_setting_set $app final_path $final_path +ynh_app_setting_set "$app" final_path "$final_path" # Download, check integrity, uncompress and patch the source from app.src #ynh_setup_source "$final_path" +ynh_print_info "Generate web config" + #================================================= # NGINX CONFIGURATION #================================================= @@ -271,18 +269,13 @@ systemctl reload nginx # Installation with curl #ynh_local_curl "/INSTALL_PATH" "key1=value1" "key2=value2" "key3=value3" -# Remove the public access -if [ $is_public -eq 0 ] -then - ynh_app_setting_delete $app skipped_uris -fi - #================================================= # MODIFY A CONFIG FILE #================================================= ### `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 "&2 - yunohost firewall disallow TCP $port 2>&1 + yunohost firewall disallow TCP "$port" 2>&1 fi #================================================= diff --git a/scripts/restore b/scripts/restore index 2bc111d..db08fa9 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,10 +1,11 @@ +#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= -#source _common.sh +source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers #================================================= @@ -39,37 +40,46 @@ rm -fr $final_path #================================================= domain=$(ynh_app_setting_get $app domain) -path_url=$(ynh_app_setting_get $app path) -admin=$(ynh_app_setting_get $app admin) +#path_url=$(ynh_app_setting_get $app path) #not used +#admin=$(ynh_app_setting_get $app admin) #not used is_public=$(ynh_app_setting_get $app is_public) -language=$(ynh_app_setting_get $app language) +#language=$(ynh_app_setting_get $app language) #not used +nonfree=$(ynh_app_setting_get $app nonfree) + #================================================= # INSTALL DEPENDENCIES #================================================= +ynh_print_info "Install Zabbix repository" + wget "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 -echo "deb http://deb.debian.org/debian stretch non-free" >/etc/apt/sources.list.d/non-free.list + +ynh_print_info "Install non-free repository with pinning" +if [ $nonfree ];then + ynh_restore_file "/etc/apt/sources.list.d/non-free.list" + ynh_restore_file "/etc/apt/preferences.d" + +fi + +ynh_print_info "Update and install dependencies" ynh_package_update -ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd snmp-mibs-downloader libjs-prototype zabbix-server-mysql zabbix-agent -yunohost service add snmpd -d "Management of SNMP Daemon" -DEBIAN_FRONTEND=noninteractive apt-get -y download zabbix-frontend-php -ar x *.deb -tar xzf control.tar.gz -sed -i 's/apache2 | httpd, //' control -tar --ignore-failed-read -cvzf control.tar.gz {post,pre}{inst,rm} md5sums control -ar rcs zabbix-frontend-php+stretch_all-noapache2.deb debian-binary control.tar.gz data.tar.xz +if [ $nonfree ];then + ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd snmp-mibs-downloader libjs-prototype jq +else + ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd libjs-prototype jq -dpkg -i zabbix-frontend-php+stretch_all-noapache2.deb +fi -rm -fr zabbix-*.deb +ynh_package_install zabbix-server-mysql zabbix-agent zabbix-frontend-php 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 locale-gen + ln -s /usr/share/zabbix /var/www/zabbix rm $final_path/conf/zabbix.conf.php @@ -104,7 +114,7 @@ yunohost app ssowatconf systemctl reload nginx # Remove the public access -if [ $is_public -eq 0 ] +if [ "$is_public" -eq 0 ] then ynh_app_setting_delete $app skipped_uris fi @@ -117,8 +127,8 @@ 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) -ynh_mysql_setup_db $db_user $db_name $db_pwd -ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql +ynh_mysql_setup_db "$db_user" "$db_name" "$db_pwd" +ynh_mysql_connect_as "$db_name" "$db_pwd" "$db_name" < ./db.sql #================================================= # Restore configs files @@ -135,9 +145,6 @@ ynh_restore_file "/etc/zabbix" systemctl enable zabbix-server && systemctl start zabbix-server - - - #================================================= # SETUP LOGROTATE #================================================= @@ -159,7 +166,7 @@ systemctl enable zabbix-server && systemctl start zabbix-server #================================================= # Make app public if necessary -if [ $is_public -eq 1 ] +if [ "$is_public" -eq 1 ] then # unprotected_uris allows SSO credentials to be passed anyway. ynh_app_setting_set $app unprotected_uris "/" diff --git a/scripts/upgrade b/scripts/upgrade index 02173a4..666b60a 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -14,17 +14,16 @@ source /usr/share/yunohost/helpers #================================================= app=$YNH_APP_INSTANCE_NAME -trustedversion="1:4.0.4-1+stretch" -domain=$(ynh_app_setting_get $app domain) -path_url=$(ynh_app_setting_get $app path) -admin=$(ynh_app_setting_get $app admin) -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) -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) - +trustedversion="1:4.0.5-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 +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) #================================================= # ENSURE DOWNWARD COMPATIBILITY @@ -32,153 +31,69 @@ db_pwd=$(ynh_app_setting_get $app mysqlpwd) # Fix is_public as a boolean value if [ "$is_public" = "Yes" ]; then - ynh_app_setting_set $app is_public 1 + ynh_app_setting_set "$app" is_public 1 is_public=1 elif [ "$is_public" = "No" ]; then - ynh_app_setting_set $app is_public 0 + 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 +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 +if [ -z "$final_path" ]; then final_path=/var/www/$app - ynh_app_setting_set $app final_path $final_path + ynh_app_setting_set "$app" final_path "$final_path" fi +export mysqlconn="mysql -u$db_user -p$db_pwd $db_name" + #================================================= # Enable default admin temporaly #================================================= -haveDefaultAdminDisabled=$(mysql -BN -u$db_user -p$db_pwd $db_name -BN -e "SELECT count(id) from \`users_groups\` where userid=1 and usrgrpid=9") - -if [ "$haveDefaultAdminDisabled" -eq 1 ] ;then - ynh_print_info "Enable default admin" - #enable default admin temporaly - mysql -u$db_user -p$db_pwd $db_name -e "DELETE FROM users_groups where usrgrpid=9 and userid=1;" -else - ynh_print_info "default admin already enabled" -fi +enable_admin_user #================================================= # Import Yunohost template #================================================= -ynh_print_info "Import Yunohost template" -#disable sso temporaly -ynh_app_setting_set $app unprotected_uris "/" -systemctl reload nginx -yunohost app ssowatconf - -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 $confUserPpath /etc/zabbix/zabbix_agentd.d/userP_yunohost.conf -cp $bashUserPpath /etc/zabbix/zabbix_agentd.d/yunohost.sh -chmod a+x /etc/zabbix/zabbix_agentd.d/yunohost.sh - -systemctl restart zabbix-agent - -curl -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ - --form enter=Sign+in \ - --form name=Admin \ - --form password=zabbix \ - "$zabbixFullpath/index.php" - -sid=$(curl -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ - "$zabbixFullpath/conf.import.php?rules_preset=template" \ - | grep -Po 'name="sid" value="\K([a-z0-9]{16})(?=")' ) - -importState=$(curl -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt \ - --form "config=1" \ - --form "import_file=@$localpath" \ - --form rules[groups][createMissing]=1 \ - --form rules[templates][updateExisting]=1 \ - --form rules[templates][createMissing]=1 \ - --form rules[templateScreens][updateExisting]=1 \ - --form rules[templateScreens][createMissing]=1 \ - --form rules[templateLinkage][createMissing]=1 \ - --form rules[applications][createMissing]=1 \ - --form rules[items][updateExisting]=1 \ - --form rules[items][createMissing]=1 \ - --form rules[discoveryRules][updateExisting]=1 \ - --form rules[discoveryRules][createMissing]=1 \ - --form rules[triggers][updateExisting]=1 \ - --form rules[triggers][createMissing]=1 \ - --form rules[graphs][updateExisting]=1 \ - --form rules[graphs][createMissing]=1 \ - --form rules[httptests][updateExisting]=1 \ - --form rules[httptests][createMissing]=1 \ - --form rules[valueMaps][createMissing]=1 \ - --form "import=Import" \ - --form "backurl=templates.php" \ - --form "form_refresh=1" \ - --form "sid=${sid}" \ \ - "${zabbixFullpath}/conf.import.php?rules_preset=template" \ - | grep -c "Imported successfully") - -if [ "$importState" -eq "1" ];then - ynh_print_info "Template Yunohost imported !" -else - ynh_print_warn "Template Yunohost not imported !" -fi - -#apply template to host -tokenapi=$(curl -k -s --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 -k -s --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') -zabbixTemplateID=$(curl -k -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"template.get","params":{"filter":{"host":["Template Yunohost"]}},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result[0].templateid') -applyTemplate=$(curl -k -s --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.massadd","params":{"hosts":[{"hostid":"'$zabbixHostID'"}],"templates":[{"templateid":"'$zabbixTemplateID'"}]},"auth":"'$tokenapi'","id":1}' ${zabbixFullpath}/api_jsonrpc.php | jq -r '.result.hostids[]') -if [ "$applyTemplate" -eq "$zabbixHostID" ];then - ynh_print_info "Template Yunohost linked to Zabbix server !" -else - ynh_print_warn "Template Yunohost no linked to Zabbix server !" -fi +import_template +#================================================= +# Link Yunohost template to the ZAbbix Server Host +#================================================= +link_template #================================================= # Disable default admin for security issue #================================================= -haveDefaultAdminDisabled=$(mysql -BN -u$db_user -p$db_pwd $db_name -BN -e "SELECT count(id) from \`users_groups\` where userid=1 and usrgrpid=9") - -if [ "$haveDefaultAdminDisabled" -eq 0 ] ;then - ynh_print_info "Disable default admin" - #disable default admin - lastid=$(mysql -u$db_user -p$db_pwd $db_name -BN -e "SELECT max(id) from \`users_groups\`") - lastid=$(($lastid + 1 )) - mysql -u$db_user -p$db_pwd $db_name -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 1);" -else - ynh_print_info "default admin already disabled" -fi - +disable_admin_user #================================================= # Disable default guest for security issue #================================================= -haveDefaultGuestDisabled=$(mysql -BN -u$db_user -p$db_pwd $db_name -BN -e "SELECT count(id) from \`users_groups\` where userid=2 and usrgrpid=9") - -if [ "$haveDefaultGuestDisabled" -eq 0 ] ;then - echo "Disable default guest" - #disable default guest - lastid=$(mysql -u$db_user -p$db_pwd $db_name -BN -e "SELECT max(id) from \`users_groups\`") - lastid=$(($lastid + 1 )) - mysql -u$db_user -p$db_pwd $db_name -e "INSERT INTO \`users_groups\` (\`id\` , \`usrgrpid\`, \`userid\`) VALUES ($lastid ,9, 2);" -else - echo "default guest already disabled" -fi +disable_guest_user #================================================= # CHECK THE PATH #================================================= # Normalize the URL path syntax -path_url=$(ynh_normalize_url_path $path_url) +path_url=$(ynh_normalize_url_path "$path_url") + +#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 "Removing snmp-mibs-downloader (non-free package)" + 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 + ynh_secure_remove /etc/apt/sources.list.d/non-free.list + fi +fi #================================================= # STANDARD UPGRADE STEPS @@ -189,19 +104,19 @@ ynh_package_update #REMOVE DUPLICATE LOG ENTRY IN LOGROTATE PATCH IF NEEDED ynh_remove_logrotate -zabbixServerInstalledVersion=$(apt-cache policy zabbix-server-mysql | grep -Po "Installed: \K(.*)") -zabbixServerCandidateVersion=$(apt-cache policy zabbix-server-mysql | grep -Po "Candidate: \K(.*)") +zabbixServerInstalledVersion=$(apt-cache policy zabbix-server-mysql | sed -n '2p' | grep -Po ".*: \K(.*)") +zabbixServerCandidateVersion=$(apt-cache policy zabbix-server-mysql | sed -n '3p' | grep -Po ".*: \K(.*)") -zabbixFrontendInstalledVersion=$(apt-cache policy zabbix-frontend-php | grep -Po "Installed: \K(.*)") -zabbixFrontendCandidateVersion=$(apt-cache policy zabbix-frontend-php | grep -Po "Candidate: \K(.*)") +zabbixFrontendInstalledVersion=$(apt-cache policy zabbix-frontend-php | sed -n '2p' | grep -Po ".*: \K(.*)") +zabbixFrontendCandidateVersion=$(apt-cache policy zabbix-frontend-php | sed -n '3p' | grep -Po ".*: \K(.*)") -zabbixagentInstalledVersion=$(apt-cache policy zabbix-agent | grep -Po "Installed: \K(.*)") -zabbixagentCandidateVersion=$(apt-cache policy zabbix-agent | grep -Po "Candidate: \K(.*)") +zabbixagentInstalledVersion=$(apt-cache policy zabbix-agent | sed -n '2p' | grep -Po ".*: \K(.*)") +zabbixagentCandidateVersion=$(apt-cache policy zabbix-agent | sed -n '3p' | grep -Po ".*: \K(.*)") if [ "$trustedversion" == "$zabbixServerCandidateVersion" ] then - if [ "$zabbixServerInstalledVersion" != "$zabbixServerCandidateVersion" -o "$zabbixFrontendInstalledVersion" != "$zabbixFrontendCandidateVersion" -o "$zabbixagentInstalledVersion" != "$zabbixagentCandidateVersion" ] + if [ "$zabbixServerInstalledVersion" != "$zabbixServerCandidateVersion" ] || [ "$zabbixFrontendInstalledVersion" != "$zabbixFrontendCandidateVersion" ] || [ "$zabbixagentInstalledVersion" != "$zabbixagentCandidateVersion" ] then #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP @@ -220,16 +135,13 @@ then cp -p /usr/share/zabbix/conf/zabbix.conf.php /tmp/ DEBIAN_FRONTEND=noninteractive apt-mark unhold zabbix-server-mysql zabbix-frontend-php - DEBIAN_FRONTEND=noninteractive apt-get -y download zabbix-frontend-php - ar x *.deb - tar xzf control.tar.gz - sed -i 's/apache2 | httpd, //' control - tar --ignore-failed-read -cvzf control.tar.gz {post,pre}{inst,rm} md5sums control - ar rcs zabbix-frontend-php+stretch_all-noapache2.deb debian-binary control.tar.gz data.tar.xz - dpkg -i zabbix-frontend-php+stretch_all-noapache2.deb - rm -fr zabbix-*.deb - apt-get -y --only-upgrade install zabbix-server-mysql zabbix-agent - DEBIAN_FRONTEND=noninteractive apt-mark hold zabbix-server-mysql zabbix-frontend-php + + ynh_print_info "Update and install dependencies" + ynh_package_update + ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd libjs-prototype jq + ynh_package_install zabbix-server-mysql zabbix-agent zabbix-frontend-php + DEBIAN_FRONTEND=noninteractive apt-mark hold zabbix-server-mysql zabbix-frontend-php + rm /usr/share/zabbix/conf/zabbix.conf.php cp -rpf /tmp/zabbix /etc/ @@ -248,13 +160,13 @@ fi # RE-ENABLE SSOWAT #================================================= ynh_print_info "re-enable SSOWAT" -# Make app public if necessary -if [ $is_public -eq 1 ] +# Make app private if necessary +if [ $is_public -eq 0 ] then # unprotected_uris allows SSO credentials to be passed anyway. - ynh_app_setting_set $app unprotected_uris "/" + ynh_app_setting_delete "$app" unprotected_uris else - ynh_app_setting_set $app unprotected_uris "" + ynh_app_setting_set "$app" unprotected_uris "/" fi systemctl reload nginx From 935c44c82bd71da086d90cff222a62fa133c0b14 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 7 Mar 2019 15:09:37 +0100 Subject: [PATCH 059/144] Update Template_Yunohost.xml --- sources/extra_files/app/Template_Yunohost.xml | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/sources/extra_files/app/Template_Yunohost.xml b/sources/extra_files/app/Template_Yunohost.xml index ef98bcf..ddd4f30 100644 --- a/sources/extra_files/app/Template_Yunohost.xml +++ b/sources/extra_files/app/Template_Yunohost.xml @@ -1,7 +1,7 @@ 4.0 - 2019-01-31T12:45:57Z + 2019-03-07T14:08:51Z Templates/Applications @@ -12,7 +12,7 @@ Template Yunohost cat /etc/sudoers.d/zabbix -zabbix ALL=(root) NOPASSWD: /etc/zabbix/zabbix_agentd.d/yunohost.sh +zabbix ALL=(ALL) NOPASSWD: /etc/zabbix/zabbix_agentd.d/yunohost.sh cat /etc/zabbix/zabbix_agentd.d/userP_yunohost.conf UserParameter=yunohost.users.discover,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.users.discover @@ -23,8 +23,8 @@ UserParameter=yunohost.services.discover,sudo /etc/zabbix/zabbix_agentd.d/yunoho UserParameter=yunohost.service.status[*],sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.service.status "$1" UserParameter=yunohost.backups.number,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.backups.number UserParameter=yunohost.backups.ageoflastbackup,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.backups.ageoflastbackup -UserParameter=yunohost.ports.tcp.discovery,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.ports.tcp.discovery -UserParameter=yunohost.ports.udp.discovery,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.ports.udp.discovery +UserParameter=yunohost.ports.tcp.discover,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.ports.tcp.discovery +UserParameter=yunohost.ports.udp.discover,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.ports.udp.discovery UserParameter=yunohost.migrations.lastinstalled,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.migrations.lastinstalled UserParameter=yunohost.migrations.lastavailable,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.migrations.lastavailable @@ -130,7 +130,7 @@ fi yunohost.backups.ageoflastbackup - 1d + 1d;h10m45 90d 365d 0 @@ -189,7 +189,7 @@ fi yunohost.backups.number - 1d + 1d;h11 90d 365d 0 @@ -248,7 +248,7 @@ fi yunohost.migrations.lastavailable - 1d + 1d;h10m50 90d 365d 0 @@ -307,7 +307,7 @@ fi yunohost.migrations.lastinstalled - 1d + 1d;h10m55 90d 365d 0 @@ -368,7 +368,7 @@ fi yunohost.domains.discover - 1d + 1d;h10 0 @@ -632,7 +632,7 @@ fi yunohost.ports.tcp.discover - 1d + 1d;h9m30 0 @@ -766,7 +766,7 @@ fi yunohost.ports.udp.discover - 1d + 1d;h9m45 0 @@ -900,7 +900,7 @@ fi yunohost.services.discover - 1d + 1d;h10m15 0 @@ -1146,7 +1146,7 @@ fi yunohost.users.discover - 1d + 1d;h10m30 0 @@ -1410,4 +1410,4 @@ fi - + \ No newline at end of file From a629d0b684bc5be0a1c45acdc0aa9826ac0383ce Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 7 Mar 2019 15:15:27 +0100 Subject: [PATCH 060/144] disable ssowat --- scripts/upgrade | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/upgrade b/scripts/upgrade index 666b60a..a470569 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -52,6 +52,12 @@ fi export mysqlconn="mysql -u$db_user -p$db_pwd $db_name" +#================================================= +# DISABLED SSOWAT +#================================================= +ynh_print_info "disable SSOWAT temporaly" +ynh_app_setting_set "$app" unprotected_uris "/" + #================================================= # Enable default admin temporaly #================================================= From 498b984730785c95594debe37a7f4eb22af2788c Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 7 Mar 2019 15:16:26 +0100 Subject: [PATCH 061/144] systemctl reload nginx yunohost app ssowatconf after disabling ssowat --- scripts/upgrade | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/upgrade b/scripts/upgrade index a470569..e7e0cab 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -57,6 +57,8 @@ export mysqlconn="mysql -u$db_user -p$db_pwd $db_name" #================================================= ynh_print_info "disable SSOWAT temporaly" ynh_app_setting_set "$app" unprotected_uris "/" +systemctl reload nginx +yunohost app ssowatconf #================================================= # Enable default admin temporaly From 2e4e51ec214a0f9e13bafd44c787fb122ffb170c Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 26 Mar 2019 09:17:39 +0100 Subject: [PATCH 062/144] Merge branch 'master' into 'testing' Master See merge request Mickael-Martin/zabbix_ynh!12 --- scripts/upgrade | 8 ++++++ sources/extra_files/app/Template_Yunohost.xml | 28 +++++++++---------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 666b60a..e7e0cab 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -52,6 +52,14 @@ fi export mysqlconn="mysql -u$db_user -p$db_pwd $db_name" +#================================================= +# DISABLED SSOWAT +#================================================= +ynh_print_info "disable SSOWAT temporaly" +ynh_app_setting_set "$app" unprotected_uris "/" +systemctl reload nginx +yunohost app ssowatconf + #================================================= # Enable default admin temporaly #================================================= diff --git a/sources/extra_files/app/Template_Yunohost.xml b/sources/extra_files/app/Template_Yunohost.xml index ef98bcf..ddd4f30 100644 --- a/sources/extra_files/app/Template_Yunohost.xml +++ b/sources/extra_files/app/Template_Yunohost.xml @@ -1,7 +1,7 @@ 4.0 - 2019-01-31T12:45:57Z + 2019-03-07T14:08:51Z Templates/Applications @@ -12,7 +12,7 @@ Template Yunohost cat /etc/sudoers.d/zabbix -zabbix ALL=(root) NOPASSWD: /etc/zabbix/zabbix_agentd.d/yunohost.sh +zabbix ALL=(ALL) NOPASSWD: /etc/zabbix/zabbix_agentd.d/yunohost.sh cat /etc/zabbix/zabbix_agentd.d/userP_yunohost.conf UserParameter=yunohost.users.discover,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.users.discover @@ -23,8 +23,8 @@ UserParameter=yunohost.services.discover,sudo /etc/zabbix/zabbix_agentd.d/yunoho UserParameter=yunohost.service.status[*],sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.service.status "$1" UserParameter=yunohost.backups.number,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.backups.number UserParameter=yunohost.backups.ageoflastbackup,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.backups.ageoflastbackup -UserParameter=yunohost.ports.tcp.discovery,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.ports.tcp.discovery -UserParameter=yunohost.ports.udp.discovery,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.ports.udp.discovery +UserParameter=yunohost.ports.tcp.discover,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.ports.tcp.discovery +UserParameter=yunohost.ports.udp.discover,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.ports.udp.discovery UserParameter=yunohost.migrations.lastinstalled,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.migrations.lastinstalled UserParameter=yunohost.migrations.lastavailable,sudo /etc/zabbix/zabbix_agentd.d/yunohost.sh yunohost.migrations.lastavailable @@ -130,7 +130,7 @@ fi yunohost.backups.ageoflastbackup - 1d + 1d;h10m45 90d 365d 0 @@ -189,7 +189,7 @@ fi yunohost.backups.number - 1d + 1d;h11 90d 365d 0 @@ -248,7 +248,7 @@ fi yunohost.migrations.lastavailable - 1d + 1d;h10m50 90d 365d 0 @@ -307,7 +307,7 @@ fi yunohost.migrations.lastinstalled - 1d + 1d;h10m55 90d 365d 0 @@ -368,7 +368,7 @@ fi yunohost.domains.discover - 1d + 1d;h10 0 @@ -632,7 +632,7 @@ fi yunohost.ports.tcp.discover - 1d + 1d;h9m30 0 @@ -766,7 +766,7 @@ fi yunohost.ports.udp.discover - 1d + 1d;h9m45 0 @@ -900,7 +900,7 @@ fi yunohost.services.discover - 1d + 1d;h10m15 0 @@ -1146,7 +1146,7 @@ fi yunohost.users.discover - 1d + 1d;h10m30 0 @@ -1410,4 +1410,4 @@ fi - + \ No newline at end of file From ef0b8c9ad226c6b996bf0a01d150bfb97084102b Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 26 Mar 2019 09:27:49 +0100 Subject: [PATCH 063/144] Update install with ynh_install_extra_repo --- scripts/install | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/scripts/install b/scripts/install index df2f530..f164c21 100644 --- a/scripts/install +++ b/scripts/install @@ -96,13 +96,9 @@ ynh_app_setting_set "$app" language "$language" ### - As well as the section "REINSTALL DEPENDENCIES" in the restore script ### - And the section "UPGRADE DEPENDENCIES" in the upgrade script ynh_print_info "Install Zabbix repository" - -wget "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_install_extra_repo --repo="http://repo.zabbix.com/zabbix/4.0/debian" --key="https://repo.zabbix.com/zabbix/4.0/debian/dists/stretch/Release.gpg" ynh_print_info "Update and install dependencies" -ynh_package_update ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd libjs-prototype jq ynh_package_install zabbix-server-mysql zabbix-agent zabbix-frontend-php From 4832d25c6e160429ea21fc304d853c9da1836e77 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 26 Mar 2019 09:45:11 +0100 Subject: [PATCH 064/144] add helper experimental ynh_add_secure_repos__2 --- scripts/install | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/install b/scripts/install index f164c21..231ec27 100644 --- a/scripts/install +++ b/scripts/install @@ -7,6 +7,7 @@ source _common.sh source /usr/share/yunohost/helpers +curl -o /usr/share/yunohost/helpers.d/ynh_add_secure_repos__2 https://raw.githubusercontent.com/YunoHost-Apps/Experimental_helpers/master/ynh_add_secure_repos/ynh_add_secure_repos__2 #================================================= # MANAGE SCRIPT FAILURE From c59ffc2a6f407d93c6858d9257ea7a9fd08708e5 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 26 Mar 2019 09:49:29 +0100 Subject: [PATCH 065/144] no comment... --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 231ec27..33870c9 100644 --- a/scripts/install +++ b/scripts/install @@ -6,8 +6,8 @@ #================================================= source _common.sh +curl -o /usr/share/yunohost/helpers.d/ynh_add_secure_repos__2 https://raw.githubusercontent.com/YunoHost-Apps/Experimental_helpers/master/ynh_add_secure_repos/ynh_add_secure_repos__2 source /usr/share/yunohost/helpers -curl -o /usr/share/yunohost/helpers.d/ynh_add_secure_repos__2 https://raw.githubusercontent.com/YunoHost-Apps/Experimental_helpers/master/ynh_add_secure_repos/ynh_add_secure_repos__2 #================================================= # MANAGE SCRIPT FAILURE From 4ab488d3fdb288d7bd0cf99744d0057e2b168194 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 26 Mar 2019 09:55:47 +0100 Subject: [PATCH 066/144] change args for ynh_install_extra_repo --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 33870c9..ca76443 100644 --- a/scripts/install +++ b/scripts/install @@ -97,7 +97,7 @@ ynh_app_setting_set "$app" language "$language" ### - As well as the section "REINSTALL DEPENDENCIES" in the restore script ### - And the section "UPGRADE DEPENDENCIES" in the upgrade script ynh_print_info "Install Zabbix repository" -ynh_install_extra_repo --repo="http://repo.zabbix.com/zabbix/4.0/debian" --key="https://repo.zabbix.com/zabbix/4.0/debian/dists/stretch/Release.gpg" +ynh_install_extra_repo --repo="http://repo.zabbix.com/zabbix/4.0/debian $(lsb_release -sc) main" --key="https://repo.zabbix.com/zabbix/4.0/debian/dists/stretch/Release.gpg" ynh_print_info "Update and install dependencies" ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd libjs-prototype jq From 01474d2dbddbfa2f49d3a2f8fdf60484a771d568 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 26 Mar 2019 09:59:14 +0100 Subject: [PATCH 067/144] Update key apt --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index ca76443..2ada506 100644 --- a/scripts/install +++ b/scripts/install @@ -97,7 +97,7 @@ ynh_app_setting_set "$app" language "$language" ### - As well as the section "REINSTALL DEPENDENCIES" in the restore script ### - And the section "UPGRADE DEPENDENCIES" in the upgrade script ynh_print_info "Install Zabbix repository" -ynh_install_extra_repo --repo="http://repo.zabbix.com/zabbix/4.0/debian $(lsb_release -sc) main" --key="https://repo.zabbix.com/zabbix/4.0/debian/dists/stretch/Release.gpg" +ynh_install_extra_repo --repo="http://repo.zabbix.com/zabbix/4.0/debian $(lsb_release -sc) main" --key="https://repo.zabbix.com/zabbix/4.0/debian/pool/main/z/zabbix-release/zabbix-release_4.0-2%2Bstretch.dsc" ynh_print_info "Update and install dependencies" ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd libjs-prototype jq From bd073b13287656fb8ed48c3792ad472d40793fee Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 26 Mar 2019 10:03:03 +0100 Subject: [PATCH 068/144] Update key gpg --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 2ada506..22b79e8 100644 --- a/scripts/install +++ b/scripts/install @@ -97,7 +97,7 @@ ynh_app_setting_set "$app" language "$language" ### - As well as the section "REINSTALL DEPENDENCIES" in the restore script ### - And the section "UPGRADE DEPENDENCIES" in the upgrade script ynh_print_info "Install Zabbix repository" -ynh_install_extra_repo --repo="http://repo.zabbix.com/zabbix/4.0/debian $(lsb_release -sc) main" --key="https://repo.zabbix.com/zabbix/4.0/debian/pool/main/z/zabbix-release/zabbix-release_4.0-2%2Bstretch.dsc" +ynh_install_extra_repo --repo="http://repo.zabbix.com/zabbix/4.0/debian $(lsb_release -sc) main" --key="http://repo.zabbix.com/RPM-GPG-KEY-ZABBIX" ynh_print_info "Update and install dependencies" ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd libjs-prototype jq From 87cfe22bb7e7d7a335a31fa8a109e038e523e826 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 26 Mar 2019 10:06:01 +0100 Subject: [PATCH 069/144] Update install key --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 22b79e8..498633b 100644 --- a/scripts/install +++ b/scripts/install @@ -97,7 +97,7 @@ ynh_app_setting_set "$app" language "$language" ### - As well as the section "REINSTALL DEPENDENCIES" in the restore script ### - And the section "UPGRADE DEPENDENCIES" in the upgrade script ynh_print_info "Install Zabbix repository" -ynh_install_extra_repo --repo="http://repo.zabbix.com/zabbix/4.0/debian $(lsb_release -sc) main" --key="http://repo.zabbix.com/RPM-GPG-KEY-ZABBIX" +ynh_install_extra_repo --repo="http://repo.zabbix.com/zabbix/4.0/debian $(lsb_release -sc) main" --key="https://repo.zabbix.com/zabbix-official-repo.key" ynh_print_info "Update and install dependencies" ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd libjs-prototype jq From 2c8edfb5634fd88684a0f612fb78a44d5abd1573 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 29 Mar 2019 12:23:58 +0100 Subject: [PATCH 070/144] add pre-requires version of yuno and help for public mode --- manifest.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 4816e75..eedd88d 100644 --- a/manifest.json +++ b/manifest.json @@ -15,7 +15,7 @@ "url": "http://www.librement-votre.fr" }, "requirements": { - "yunohost": ">= 2.7.14" + "yunohost": ">= 3.4.2" }, "multi_instance": false, "services": [ @@ -61,6 +61,10 @@ "en": "Is it a public application?", "fr": "Est-ce une application publique ?" }, + "help": { + "en": "A public app doesn't need SSO auth : the auth page is opened for everyone", + "fr": "Une application publique ne nécessite pas une authentification SSO : sa page d'authentication est ouverte au monde entier" + }, "default": false }, { From c763916d74cefe5f29e15b271974f1d0c2db94c1 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 29 Mar 2019 12:26:50 +0100 Subject: [PATCH 071/144] use ynh_install_app_dependencies only --- scripts/install | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/install b/scripts/install index df2f530..c623767 100644 --- a/scripts/install +++ b/scripts/install @@ -103,9 +103,8 @@ rm zabbix-release_*.deb ynh_print_info "Update and install dependencies" ynh_package_update -ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd libjs-prototype jq +ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-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 -ynh_package_install zabbix-server-mysql zabbix-agent zabbix-frontend-php 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 From d0f8f9d812d130cf136bf9e8c3a0c330f46f250e Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 29 Mar 2019 12:28:45 +0100 Subject: [PATCH 072/144] use ynh_install_app_dependencies only and clean old code (nonfree) --- scripts/restore | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/scripts/restore b/scripts/restore index db08fa9..3bf0207 100644 --- a/scripts/restore +++ b/scripts/restore @@ -57,23 +57,10 @@ wget "https://repo.zabbix.com/zabbix/4.0/debian/pool/main/z/zabbix-release/zabbi dpkg -i zabbix-release_*.deb rm zabbix-release_*.deb -ynh_print_info "Install non-free repository with pinning" -if [ $nonfree ];then - ynh_restore_file "/etc/apt/sources.list.d/non-free.list" - ynh_restore_file "/etc/apt/preferences.d" - -fi - ynh_print_info "Update and install dependencies" ynh_package_update -if [ $nonfree ];then - ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd snmp-mibs-downloader libjs-prototype jq -else - ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd libjs-prototype jq +ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-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 -fi - -ynh_package_install zabbix-server-mysql zabbix-agent zabbix-frontend-php 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 @@ -107,18 +94,6 @@ ynh_restore_file "/etc/php/7.0/fpm/pool.d/$app.conf" # Restore sudo file ynh_restore_file "/etc/sudoers.d/zabbix" -# Reload SSOwat config -yunohost app ssowatconf - -# Reload Nginx -systemctl reload nginx - -# Remove the public access -if [ "$is_public" -eq 0 ] -then - ynh_app_setting_delete $app skipped_uris -fi - #================================================= # Restore db #================================================= @@ -179,4 +154,5 @@ fi systemctl reload nginx systemctl reload php7.0-fpm - +# Reload SSOwat config +yunohost app ssowatconf From 1b9a76f85c5334d95c66f1006472010dc59c9e60 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 29 Mar 2019 12:29:09 +0100 Subject: [PATCH 073/144] re add ynh_abort_if_errors --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index c623767..c052f8e 100644 --- a/scripts/install +++ b/scripts/install @@ -13,7 +13,7 @@ source /usr/share/yunohost/helpers #================================================= # Exit if an error occurs during the execution of the script -#ynh_abort_if_errors +ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST From 72e4736b1335a18c3f3479028da5564c9eb4aa85 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 29 Mar 2019 12:46:58 +0100 Subject: [PATCH 074/144] re-add yunohost service add --- scripts/install | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index c052f8e..4d40028 100644 --- a/scripts/install +++ b/scripts/install @@ -360,7 +360,9 @@ yunohost service add zabbix-agent -d "Management of Zabbix Agent" ### - Remove the section "REMOVE SERVICE FROM ADMIN PANEL" in the remove script ### - As well as the section ADVERTISE SERVICE IN ADMIN PANEL" in the restore script -#yunohost service add NAME_INIT.D --log "/var/log/FILE.log" +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-client -d "Management Zabbix client daemon : send informations about this host to the server" # Make app public if for importing template # unprotected_uris allows SSO credentials to be passed anyway From d09e1bfd899f2e59e3618ace09a08e7223f44259 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 29 Mar 2019 12:48:05 +0100 Subject: [PATCH 075/144] add yunohost service add --- scripts/restore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/restore b/scripts/restore index 3bf0207..ea6c963 100644 --- a/scripts/restore +++ b/scripts/restore @@ -120,6 +120,10 @@ ynh_restore_file "/etc/zabbix" systemctl enable zabbix-server && systemctl start zabbix-server +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-client -d "Management Zabbix client daemon : send informations about this host to the server" + #================================================= # SETUP LOGROTATE #================================================= From 853981e8a2e336959c994a8db8366f519f002c58 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 29 Mar 2019 12:49:32 +0100 Subject: [PATCH 076/144] clean old code about services --- scripts/restore | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/restore b/scripts/restore index ea6c963..a00113a 100644 --- a/scripts/restore +++ b/scripts/restore @@ -72,9 +72,6 @@ rm $final_path/conf/zabbix.conf.php ynh_app_setting_set $app final_path $final_path -yunohost service add zabbix-server -d "Management of Zabbix Server - Monitoring server" -yunohost service add zabbix-agent -d "Management of Zabbix Agent" - #================================================= # NGINX CONFIGURATION #================================================= @@ -118,6 +115,7 @@ chown -R www-data. /usr/share/zabbix ynh_restore_file "/etc/zabbix" +# systemd and yunohost service management systemctl enable zabbix-server && systemctl start zabbix-server yunohost service add snmpd -d "Management of SNMP Daemon" From ad69c18f9f0aae9cf063fe030423535cdd0cdb28 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 29 Mar 2019 12:51:37 +0100 Subject: [PATCH 077/144] remove old code about services --- scripts/install | 4 ---- 1 file changed, 4 deletions(-) diff --git a/scripts/install b/scripts/install index 4d40028..e0641a2 100644 --- a/scripts/install +++ b/scripts/install @@ -304,10 +304,6 @@ sed -i "126a DBPassword=$db_pwd" /etc/zabbix/zabbix_server.conf systemctl enable zabbix-server && systemctl start zabbix-server -yunohost service add zabbix-server -d "Management of Zabbix Server - Monitoring server" -yunohost service add zabbix-agent -d "Management of Zabbix Agent" - - #================================================= # STORE THE CONFIG FILE CHECKSUM #================================================= From b53a29eee0b4444152b0721a7699e8ac5ee7b30e Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 29 Mar 2019 13:09:56 +0100 Subject: [PATCH 078/144] ynh_install_app_dependencies only use --- scripts/upgrade | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index e7e0cab..9bcf4fc 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -146,8 +146,7 @@ then ynh_print_info "Update and install dependencies" ynh_package_update - ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-bcmath patch smistrip unzip wget fping libcap2-bin libiksemel3 libopenipmi0 libpam-cap libsnmp-base libsnmp30 snmptrapd snmpd libjs-prototype jq - ynh_package_install zabbix-server-mysql zabbix-agent zabbix-frontend-php + ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-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 DEBIAN_FRONTEND=noninteractive apt-mark hold zabbix-server-mysql zabbix-frontend-php From ff43f163e0838f60996757106966ba7e8a02a409 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 29 Mar 2019 13:30:42 +0100 Subject: [PATCH 079/144] add check_proc_zabbixagent and check_proc_zabbixserver function --- scripts/_common.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/scripts/_common.sh b/scripts/_common.sh index 79bf17b..4e07fc2 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -137,4 +137,24 @@ link_template(){ ynh_print_warn "Template Yunohost no linked to Zabbix server !" fi +} + +check_proc_zabbixserver(){ + pgrep zabbix_server >/dev/null + if [ $? -eq 0 ];then + ynh_print_info "zabbix server is started !" + else + ynh_print_err "Zabbix Server not started, try to start it with the yunohost interface." + ynh_print_err "If Zabbix Server can't start, please open a issue on https://github.com/YunoHost-Apps/zabbix_ynh/issues" + fi +} + +check_proc_zabbixagent(){ + pgrep zabbix_agentd >/dev/null + if [ $? -eq 0 ];then + ynh_print_info "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 } \ No newline at end of file From 3083f26c7d1257b955c30816de6bd1d62c8b6aec Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 29 Mar 2019 13:31:07 +0100 Subject: [PATCH 080/144] add check_proc_zabbixagent and check_proc_zabbixserver functions --- scripts/install | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/install b/scripts/install index e0641a2..0a02ebb 100644 --- a/scripts/install +++ b/scripts/install @@ -409,3 +409,8 @@ systemctl reload php7.0-fpm # Reload SSOwat config yunohost app ssowatconf +#test if zabbix server is started +check_proc_zabbixagent + +#test if zabbix agent is started +check_proc_zabbixserver From 03d8ac7348f2b87e7f08dcd0daf8e7c4f926a65f Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 29 Mar 2019 13:32:10 +0100 Subject: [PATCH 081/144] add check function after update process --- scripts/upgrade | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index 9bcf4fc..ed16b76 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -155,7 +155,13 @@ then cp -pf /tmp/zabbix.conf.php /usr/share/zabbix/conf/ rm -fr /tmp/zabbix* - + + #test if zabbix server is started + check_proc_zabbixagent + + #test if zabbix agent is started + check_proc_zabbixserver + else ynh_print_info "No update from repo ! (Already up to date)" fi From fa79a817e1cb543d3e9843805b935f1bb4a8a5d9 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 29 Mar 2019 13:32:41 +0100 Subject: [PATCH 082/144] add 2 check process after restore --- scripts/restore | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/restore b/scripts/restore index a00113a..8fa4471 100644 --- a/scripts/restore +++ b/scripts/restore @@ -158,3 +158,9 @@ systemctl reload php7.0-fpm # Reload SSOwat config yunohost app ssowatconf + +#test if zabbix server is started +check_proc_zabbixagent + +#test if zabbix agent is started +check_proc_zabbixserver From 1977daab3c07982c2ca9c1b7588af2a230f7641a Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 29 Mar 2019 13:43:13 +0100 Subject: [PATCH 083/144] Update remove (non free part) and clean code --- scripts/remove | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/scripts/remove b/scripts/remove index 579bf84..25a2e98 100644 --- a/scripts/remove +++ b/scripts/remove @@ -21,22 +21,12 @@ db_name=$(ynh_app_setting_get "$app" db_name) db_user=$db_name #final_path=$(ynh_app_setting_get "$app" final_path) #not used -#================================================= -# STANDARD REMOVE -#================================================= -# STOP AND REMOVE SERVICE -#================================================= - -# Remove the dedicated systemd config -ynh_remove_systemd_config - -yunohost service remove snmpd - #================================================= # REMOVE SERVICE FROM ADMIN PANEL #================================================= - # Remove a service from the admin panel, added by `yunohost service add` + +yunohost service remove snmpd yunohost service remove zabbix-server yunohost service remove zabbix-agent @@ -53,18 +43,17 @@ systemctl reload php7.0-fpm # REMOVE DEPENDENCIES #================================================= -# Remove metapackage and its dependencies -#ynh_remove_app_dependencies - timeout 5 systemctl stop zabbix-server || killall zabbix_server systemctl disable zabbix-server killall zabbix_server timeout 5 systemctl stop zabbix-agent || killall zabbix_agentd systemctl disable zabbix-agent +killall zabbix_agentd -ynh_package_autopurge --allow-change-held-packages zabbix-server-mysql zabbix-frontend-php zabbix-release zabbix-ynh-deps zabbix-agent +ynh_remove_app_dependencies + #remove symlink rm /var/www/zabbix @@ -123,6 +112,18 @@ ynh_secure_remove "/run/zabbix" # Remove the sudoers file ynh_secure_remove "/etc/sudoers.d/zabbix" +#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 "Removing snmp-mibs-downloader (non-free package)" + 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 + ynh_secure_remove /etc/apt/sources.list.d/non-free.list + fi +fi + + #================================================= # GENERIC FINALIZATION #================================================= From 5c1898710c8b8e2693c0b710398596dea9b2276f Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 29 Mar 2019 13:57:35 +0100 Subject: [PATCH 084/144] wget -q --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 0a02ebb..3d5660d 100644 --- a/scripts/install +++ b/scripts/install @@ -97,7 +97,7 @@ ynh_app_setting_set "$app" language "$language" ### - And the section "UPGRADE DEPENDENCIES" in the upgrade script ynh_print_info "Install Zabbix repository" -wget "https://repo.zabbix.com/zabbix/4.0/debian/pool/main/z/zabbix-release/zabbix-release_4.0-2+stretch_all.deb" +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 From cfae021f4920bdc879e14733e3fcd98ae5318b89 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 29 Mar 2019 13:57:58 +0100 Subject: [PATCH 085/144] wget -q --- scripts/restore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/restore b/scripts/restore index 8fa4471..0e41db4 100644 --- a/scripts/restore +++ b/scripts/restore @@ -53,7 +53,7 @@ nonfree=$(ynh_app_setting_get $app nonfree) ynh_print_info "Install Zabbix repository" -wget "https://repo.zabbix.com/zabbix/4.0/debian/pool/main/z/zabbix-release/zabbix-release_4.0-2+stretch_all.deb" +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 From 042654078341bf34272c18bf061e812d9726a8ab Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 29 Mar 2019 14:00:17 +0100 Subject: [PATCH 086/144] Update install zabbix client -> zabbix agent --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 3d5660d..5b309cd 100644 --- a/scripts/install +++ b/scripts/install @@ -358,7 +358,7 @@ systemctl enable zabbix-server && systemctl start zabbix-server 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-client -d "Management Zabbix client daemon : send informations about this host to the server" +yunohost service add zabbix-agent -d "Management Zabbix agent daemon : send informations about this host to the server" # Make app public if for importing template # unprotected_uris allows SSO credentials to be passed anyway From 6ac41d8b60e22651e94cf6a886da584a19c82f73 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 29 Mar 2019 14:03:45 +0100 Subject: [PATCH 087/144] add service in management page of yunohost --- scripts/upgrade | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/upgrade b/scripts/upgrade index ed16b76..fafe948 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -156,6 +156,11 @@ then rm -fr /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" + #test if zabbix server is started check_proc_zabbixagent From 6e7aed28d3365672bc695c96b2af45531b5fc323 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 29 Mar 2019 14:05:41 +0100 Subject: [PATCH 088/144] Update remove --- scripts/remove | 134 ------------------------------------------------- 1 file changed, 134 deletions(-) diff --git a/scripts/remove b/scripts/remove index 25a2e98..e69de29 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,134 +0,0 @@ -#!/bin/bash - -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - -source _common.sh -source /usr/share/yunohost/helpers - -#================================================= -# LOAD SETTINGS -#================================================= - -app=$YNH_APP_INSTANCE_NAME - -#domain=$(ynh_app_setting_get "$app" domain) #not used -port=$(ynh_app_setting_get "$app" port) -db_name=$(ynh_app_setting_get "$app" db_name) -db_user=$db_name -#final_path=$(ynh_app_setting_get "$app" final_path) #not used - -#================================================= -# REMOVE SERVICE FROM ADMIN PANEL -#================================================= -# Remove a service from the admin panel, added by `yunohost service add` - -yunohost service remove snmpd -yunohost service remove zabbix-server -yunohost service remove zabbix-agent - -#================================================= -# REMOVE PHP-FPM CONFIGURATION -#================================================= - -# Remove the dedicated php-fpm config -ynh_remove_fpm_config - -systemctl reload php7.0-fpm - -#================================================= -# REMOVE DEPENDENCIES -#================================================= - -timeout 5 systemctl stop zabbix-server || killall zabbix_server -systemctl disable zabbix-server -killall zabbix_server - -timeout 5 systemctl stop zabbix-agent || killall zabbix_agentd -systemctl disable zabbix-agent -killall zabbix_agentd - - -ynh_remove_app_dependencies - -#remove symlink -rm /var/www/zabbix - -#================================================= -# REMOVE THE MYSQL DATABASE -#================================================= - -# Remove a database if it exists, along with the associated user -ynh_mysql_remove_db "$db_user" "$db_name" - -#================================================= -# REMOVE NGINX CONFIGURATION -#================================================= - -# Remove the dedicated nginx config -ynh_remove_nginx_config - -#================================================= -# RELOAD NGINX -#================================================= - -systemctl reload nginx - -#================================================= -# REMOVE LOGROTATE CONFIGURATION -#================================================= - -# Remove the app-specific logrotate config -ynh_remove_logrotate - -#================================================= -# CLOSE A PORT -#================================================= - -if yunohost firewall list | grep -q "\- $port$" -then - echo "Close port $port" >&2 - yunohost firewall disallow TCP "$port" 2>&1 -fi - -#================================================= -# SPECIFIC REMOVE -#================================================= -# REMOVE THE CRON FILE -#================================================= - -# Remove a directory securely -ynh_secure_remove "/etc/zabbix" - -# Remove the log files -ynh_secure_remove "/var/log/zabbix" - -# Remove the pid/socket files -ynh_secure_remove "/run/zabbix" - -# Remove the sudoers file -ynh_secure_remove "/etc/sudoers.d/zabbix" - -#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 "Removing snmp-mibs-downloader (non-free package)" - 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 - ynh_secure_remove /etc/apt/sources.list.d/non-free.list - fi -fi - - -#================================================= -# GENERIC FINALIZATION -#================================================= -# REMOVE DEDICATED USER -#================================================= - -# Delete a system user -ynh_system_user_delete zabbix From 0cbfa9fbd02440eac4f60a8a0e1447848ad9e6b9 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 29 Mar 2019 14:08:47 +0100 Subject: [PATCH 089/144] Revert "Update remove" This reverts commit 6e7aed28d3365672bc695c96b2af45531b5fc323 --- scripts/remove | 134 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) diff --git a/scripts/remove b/scripts/remove index e69de29..25a2e98 100644 --- a/scripts/remove +++ b/scripts/remove @@ -0,0 +1,134 @@ +#!/bin/bash + +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# LOAD SETTINGS +#================================================= + +app=$YNH_APP_INSTANCE_NAME + +#domain=$(ynh_app_setting_get "$app" domain) #not used +port=$(ynh_app_setting_get "$app" port) +db_name=$(ynh_app_setting_get "$app" db_name) +db_user=$db_name +#final_path=$(ynh_app_setting_get "$app" final_path) #not used + +#================================================= +# REMOVE SERVICE FROM ADMIN PANEL +#================================================= +# Remove a service from the admin panel, added by `yunohost service add` + +yunohost service remove snmpd +yunohost service remove zabbix-server +yunohost service remove zabbix-agent + +#================================================= +# REMOVE PHP-FPM CONFIGURATION +#================================================= + +# Remove the dedicated php-fpm config +ynh_remove_fpm_config + +systemctl reload php7.0-fpm + +#================================================= +# REMOVE DEPENDENCIES +#================================================= + +timeout 5 systemctl stop zabbix-server || killall zabbix_server +systemctl disable zabbix-server +killall zabbix_server + +timeout 5 systemctl stop zabbix-agent || killall zabbix_agentd +systemctl disable zabbix-agent +killall zabbix_agentd + + +ynh_remove_app_dependencies + +#remove symlink +rm /var/www/zabbix + +#================================================= +# REMOVE THE MYSQL DATABASE +#================================================= + +# Remove a database if it exists, along with the associated user +ynh_mysql_remove_db "$db_user" "$db_name" + +#================================================= +# REMOVE NGINX CONFIGURATION +#================================================= + +# Remove the dedicated nginx config +ynh_remove_nginx_config + +#================================================= +# RELOAD NGINX +#================================================= + +systemctl reload nginx + +#================================================= +# REMOVE LOGROTATE CONFIGURATION +#================================================= + +# Remove the app-specific logrotate config +ynh_remove_logrotate + +#================================================= +# CLOSE A PORT +#================================================= + +if yunohost firewall list | grep -q "\- $port$" +then + echo "Close port $port" >&2 + yunohost firewall disallow TCP "$port" 2>&1 +fi + +#================================================= +# SPECIFIC REMOVE +#================================================= +# REMOVE THE CRON FILE +#================================================= + +# Remove a directory securely +ynh_secure_remove "/etc/zabbix" + +# Remove the log files +ynh_secure_remove "/var/log/zabbix" + +# Remove the pid/socket files +ynh_secure_remove "/run/zabbix" + +# Remove the sudoers file +ynh_secure_remove "/etc/sudoers.d/zabbix" + +#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 "Removing snmp-mibs-downloader (non-free package)" + 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 + ynh_secure_remove /etc/apt/sources.list.d/non-free.list + fi +fi + + +#================================================= +# GENERIC FINALIZATION +#================================================= +# REMOVE DEDICATED USER +#================================================= + +# Delete a system user +ynh_system_user_delete zabbix From 7c8bacbec1700f442383ebc420921566d14e764b Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 29 Mar 2019 14:10:58 +0100 Subject: [PATCH 090/144] Update remove --- scripts/remove | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/remove b/scripts/remove index 25a2e98..29a5735 100644 --- a/scripts/remove +++ b/scripts/remove @@ -15,7 +15,7 @@ source /usr/share/yunohost/helpers app=$YNH_APP_INSTANCE_NAME -#domain=$(ynh_app_setting_get "$app" domain) #not used +domain=$(ynh_app_setting_get "$app" domain) port=$(ynh_app_setting_get "$app" port) db_name=$(ynh_app_setting_get "$app" db_name) db_user=$db_name From 1b582df2427b4ac8e945106f2a3b287a275fe8cd Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 29 Mar 2019 14:32:18 +0100 Subject: [PATCH 091/144] systemctl start php7.0-fpm --- scripts/remove | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/remove b/scripts/remove index 29a5735..03e8a81 100644 --- a/scripts/remove +++ b/scripts/remove @@ -36,9 +36,11 @@ yunohost service remove zabbix-agent # Remove the dedicated php-fpm config ynh_remove_fpm_config - systemctl reload php7.0-fpm +#sometimes php7.0-fpm crash on removing conf... +systemctl start php7.0-fpm + #================================================= # REMOVE DEPENDENCIES #================================================= @@ -54,9 +56,6 @@ killall zabbix_agentd ynh_remove_app_dependencies -#remove symlink -rm /var/www/zabbix - #================================================= # REMOVE THE MYSQL DATABASE #================================================= @@ -100,6 +99,9 @@ fi # REMOVE THE CRON FILE #================================================= +#remove symlink +rm /var/www/zabbix + # Remove a directory securely ynh_secure_remove "/etc/zabbix" From e8e94fee551fa62f70a06a6ffb0e91ae1872def1 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 29 Mar 2019 17:17:06 +0100 Subject: [PATCH 092/144] Update remove (delete duplicate reload causing crash php-fpm ) --- scripts/remove | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/scripts/remove b/scripts/remove index 03e8a81..a53573b 100644 --- a/scripts/remove +++ b/scripts/remove @@ -36,10 +36,6 @@ yunohost service remove zabbix-agent # Remove the dedicated php-fpm config ynh_remove_fpm_config -systemctl reload php7.0-fpm - -#sometimes php7.0-fpm crash on removing conf... -systemctl start php7.0-fpm #================================================= # REMOVE DEPENDENCIES @@ -53,7 +49,6 @@ timeout 5 systemctl stop zabbix-agent || killall zabbix_agentd systemctl disable zabbix-agent killall zabbix_agentd - ynh_remove_app_dependencies #================================================= @@ -70,12 +65,6 @@ ynh_mysql_remove_db "$db_user" "$db_name" # Remove the dedicated nginx config ynh_remove_nginx_config -#================================================= -# RELOAD NGINX -#================================================= - -systemctl reload nginx - #================================================= # REMOVE LOGROTATE CONFIGURATION #================================================= From bb08ef4db49e6c6e1a01fa73f394b171846bbb75 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 29 Mar 2019 17:45:48 +0100 Subject: [PATCH 093/144] force reinstall conf files --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 5b309cd..bcedf8a 100644 --- a/scripts/install +++ b/scripts/install @@ -104,7 +104,7 @@ rm zabbix-release_*.deb ynh_print_info "Update and install dependencies" ynh_package_update ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-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 - +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 From b2408f45e04f120e7ac40a212493e731378d40c8 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 11 Apr 2019 20:56:47 +0200 Subject: [PATCH 094/144] purge repo --- scripts/remove | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/remove b/scripts/remove index a53573b..84edc25 100644 --- a/scripts/remove +++ b/scripts/remove @@ -49,6 +49,7 @@ timeout 5 systemctl stop zabbix-agent || killall zabbix_agentd systemctl disable zabbix-agent killall zabbix_agentd +DEBIAN_FRONTEND=noninteractive apt purge zabbix-release -y ynh_remove_app_dependencies #================================================= From 7f876ea2f963a7e079453999217a013bfd5871db Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 11 Apr 2019 23:04:40 +0200 Subject: [PATCH 095/144] force removing old version --- scripts/remove | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/remove b/scripts/remove index 84edc25..3c6bddf 100644 --- a/scripts/remove +++ b/scripts/remove @@ -52,6 +52,12 @@ killall zabbix_agentd DEBIAN_FRONTEND=noninteractive apt 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 purge --allow-change-held-packages "$zabbix_pkg" -y +done + #================================================= # REMOVE THE MYSQL DATABASE #================================================= From 386adc64078f933a28272cc0578c61bcc4ef2697 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 11 Apr 2019 23:14:32 +0200 Subject: [PATCH 096/144] change timeout zabbix agent --- scripts/install | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/install b/scripts/install index bcedf8a..3088ecf 100644 --- a/scripts/install +++ b/scripts/install @@ -302,6 +302,8 @@ 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="# Timeout=3" --replace_string="# Timeout=3\nTimeout=10" --target_file=/etc/zabbix/zabbix_agentd.conf + systemctl enable zabbix-server && systemctl start zabbix-server #================================================= From fbb980109b42bec5de390f0a5359fc206a82bb6a Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 11 Apr 2019 23:21:06 +0200 Subject: [PATCH 097/144] patch timeout zabbix agent if needed --- scripts/upgrade | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/upgrade b/scripts/upgrade index fafe948..cb8c805 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -103,6 +103,12 @@ if [ $(echo $nonfreepackagelist | wc -l) -eq 1 ] && [ $(echo $nonfreepackagelist fi fi +#Patch timeout too short for zabbix agent if needed +timeout_ok=$(grep -c "^Timeout" /etc/zabbix/zabbix_agentd.conf 2>/dev/null) +if [ $timeout_ok -ne 1 ] ;then + ynh_replace_string --match_string="# Timeout=3" --replace_string="# Timeout=3\nTimeout=10" --target_file=/etc/zabbix/zabbix_agentd.conf +fi + #================================================= # STANDARD UPGRADE STEPS #================================================= From 5af820fd8ec74ac41a8da731e964b9bc79fb92e4 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 11 Apr 2019 23:30:26 +0200 Subject: [PATCH 098/144] add restart agent after timeout reconfig --- scripts/install | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 3088ecf..3f218d0 100644 --- a/scripts/install +++ b/scripts/install @@ -304,7 +304,8 @@ sed -i "126a DBPassword=$db_pwd" /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 -systemctl enable zabbix-server && systemctl start zabbix-server +systemctl enable zabbix-agent && systemctl restart zabbix-agent +systemctl enable zabbix-server && systemctl restart zabbix-server #================================================= # STORE THE CONFIG FILE CHECKSUM From 1b3f6466c905d6edf7ce63940f34a304c38b74bf Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 11 Apr 2019 23:30:55 +0200 Subject: [PATCH 099/144] restart agent after timeout reconfig --- scripts/upgrade | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/upgrade b/scripts/upgrade index cb8c805..38af75b 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -107,6 +107,7 @@ fi timeout_ok=$(grep -c "^Timeout" /etc/zabbix/zabbix_agentd.conf 2>/dev/null) if [ $timeout_ok -ne 1 ] ;then ynh_replace_string --match_string="# Timeout=3" --replace_string="# Timeout=3\nTimeout=10" --target_file=/etc/zabbix/zabbix_agentd.conf + systemctl enable zabbix-agent && systemctl restart zabbix-agent fi #================================================= From 94e87b58c1b01c3a250f360240779fa26d92d214 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Tue, 7 May 2019 13:53:55 +0200 Subject: [PATCH 100/144] Update to 1:4.0.7-1+stretch --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index 38af75b..7001b0b 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -14,7 +14,7 @@ source /usr/share/yunohost/helpers #================================================= app=$YNH_APP_INSTANCE_NAME -trustedversion="1:4.0.5-1+stretch" +trustedversion="1:4.0.7-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 6a587614e3b71ad2e7f15bef5d20e14117993cd4 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 9 May 2019 13:21:21 +0200 Subject: [PATCH 101/144] Update install to 4.2 --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 3f218d0..4a6a7c8 100644 --- a/scripts/install +++ b/scripts/install @@ -97,7 +97,7 @@ ynh_app_setting_set "$app" language "$language" ### - And the section "UPGRADE DEPENDENCIES" in the upgrade script 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" +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 From 97a16d260566a751a5edcbe0fab767e4c2d15d30 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 9 May 2019 13:30:24 +0200 Subject: [PATCH 102/144] upgrade to 4.2.1 --- scripts/upgrade | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index 7001b0b..a7ab9dd 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -14,7 +14,8 @@ source /usr/share/yunohost/helpers #================================================= app=$YNH_APP_INSTANCE_NAME -trustedversion="1:4.0.7-1+stretch" +trustedversion="1:4.2.1-1+stretch" +trustedVersionRepo="4.2-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 @@ -119,6 +120,18 @@ ynh_package_update #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 + + zabbixServerInstalledVersion=$(apt-cache policy zabbix-server-mysql | sed -n '2p' | grep -Po ".*: \K(.*)") zabbixServerCandidateVersion=$(apt-cache policy zabbix-server-mysql | sed -n '3p' | grep -Po ".*: \K(.*)") From ed59890d0ae4ff55119b34ee6a27877b0441873f Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 9 May 2019 13:34:16 +0200 Subject: [PATCH 103/144] check repo after upgrade repo --- scripts/upgrade | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index a7ab9dd..5a29de3 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -114,9 +114,6 @@ fi #================================================= # STANDARD UPGRADE STEPS #================================================= -ynh_print_info "Check if new zabbix version is available on repo" -ynh_package_update - #REMOVE DUPLICATE LOG ENTRY IN LOGROTATE PATCH IF NEEDED ynh_remove_logrotate @@ -131,6 +128,8 @@ if [ "$trustedVersionRepo" != "zabbixRepoInstalledVersion" ];then rm zabbix-release_*.deb fi +ynh_print_info "Check if new zabbix version is available on repo" +ynh_package_update zabbixServerInstalledVersion=$(apt-cache policy zabbix-server-mysql | sed -n '2p' | grep -Po ".*: \K(.*)") zabbixServerCandidateVersion=$(apt-cache policy zabbix-server-mysql | sed -n '3p' | grep -Po ".*: \K(.*)") From 9da93fd67ef5ddd4288a19bfc4663a87a3fc0981 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 9 May 2019 13:39:25 +0200 Subject: [PATCH 104/144] fix variable --- scripts/upgrade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/upgrade b/scripts/upgrade index 5a29de3..d3c1b72 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -119,7 +119,7 @@ ynh_remove_logrotate zabbixRepoInstalledVersion=$(apt-cache policy zabbix-release | sed -n '2p' | grep -Po ".*: \K(.*)") -if [ "$trustedVersionRepo" != "zabbixRepoInstalledVersion" ];then +if [ "$trustedVersionRepo" !=zabbixRepoInstalledVersion" ];then DEBIAN_FRONTEND=noninteractive apt remove zabbix-release -y ynh_print_info "Install New Zabbix repository" From 8ada47a232e0fc27d8c509c34663c3a144686fc4 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 9 May 2019 13:59:33 +0200 Subject: [PATCH 105/144] change ynh_print_info to echo cause ynh_print_info broken actually --- scripts/upgrade | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index d3c1b72..37d8542 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -187,10 +187,12 @@ then check_proc_zabbixserver else - ynh_print_info "No update from repo ! (Already up to date)" + #ynh_print_info "No update from repo ! (Already up to date)" + echo "No update from repo ! (Already up to date)" fi else - ynh_print_info "No update from repo ! (Trusted version)" + #ynh_print_info "No update from repo ! (Trusted version)" + echo "No update from repo ! (Trusted version)" fi #================================================= From ddf1a3ed88c6733d1a94fe2eb24f038350f9b6bc Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 9 May 2019 14:01:14 +0200 Subject: [PATCH 106/144] fix variable --- scripts/upgrade | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 37d8542..2e13060 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -119,7 +119,7 @@ ynh_remove_logrotate zabbixRepoInstalledVersion=$(apt-cache policy zabbix-release | sed -n '2p' | grep -Po ".*: \K(.*)") -if [ "$trustedVersionRepo" !=zabbixRepoInstalledVersion" ];then +if [ "$trustedVersionRepo" != "$zabbixRepoInstalledVersion" ];then DEBIAN_FRONTEND=noninteractive apt remove zabbix-release -y ynh_print_info "Install New Zabbix repository" @@ -187,12 +187,10 @@ then check_proc_zabbixserver else - #ynh_print_info "No update from repo ! (Already up to date)" - echo "No update from repo ! (Already up to date)" + ynh_print_info "No update from repo ! (Already up to date)" fi else - #ynh_print_info "No update from repo ! (Trusted version)" - echo "No update from repo ! (Trusted version)" + ynh_print_info "No update from repo ! (Trusted version)" fi #================================================= From 996bab5ad7dae704338451c5c578b8bb6dffc5f0 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Wed, 3 Jul 2019 12:49:33 +0200 Subject: [PATCH 107/144] apt purge zabbix* -y --- scripts/install | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index 4a6a7c8..a991758 100644 --- a/scripts/install +++ b/scripts/install @@ -95,8 +95,10 @@ ynh_app_setting_set "$app" language "$language" ### - Remove the section "REMOVE DEPENDENCIES" in the remove script ### - As well as the section "REINSTALL DEPENDENCIES" in the restore script ### - And the section "UPGRADE DEPENDENCIES" in the upgrade script -ynh_print_info "Install Zabbix repository" +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 From dd5fbf7fb75134021cc897e094e17788a101d37b Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Wed, 3 Jul 2019 12:55:07 +0200 Subject: [PATCH 108/144] #ynh_package_update commented --- scripts/install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install b/scripts/install index a991758..5b31c1d 100644 --- a/scripts/install +++ b/scripts/install @@ -104,7 +104,7 @@ dpkg -i zabbix-release_*.deb rm zabbix-release_*.deb ynh_print_info "Update and install dependencies" -ynh_package_update +#ynh_package_update no need cause ynh_install_app_dependencies after ynh_install_app_dependencies libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap liblua5.2-0 php7.0 php-bcmath php7.0-bcmath ttf-dejavu-core php7.0-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 dpkg -i --force-confmiss /var/cache/apt/archives/zabbix-server-mysql* DEBIAN_FRONTEND=noninteractive apt-mark hold zabbix-server-mysql zabbix-frontend-php From 9f3578ac8cdf11afb5ac4cbfdeac6af8e0a62d4d Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Wed, 3 Jul 2019 13:03:29 +0200 Subject: [PATCH 109/144] update path conf change --- scripts/_common.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/_common.sh b/scripts/_common.sh index 4e07fc2..1948850 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -68,7 +68,16 @@ import_template(){ 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 + + if [ -d /etc/zabbix/zabbix_agentd.d/ ];then + mv /etc/zabbix/zabbix_agentd.d/ /etc/zabbix/zabbix_agentd.conf.d/ + fi + if [ ! -L /etc/zabbix/zabbix_agentd.d/ ];then + ln -s /etc/zabbix/zabbix_agentd.d/ /etc/zabbix/zabbix_agentd.conf.d/ + fi + cp "$confUserPpath" /etc/zabbix/zabbix_agentd.d/userP_yunohost.conf cp "$bashUserPpath" /etc/zabbix/zabbix_agentd.d/yunohost.sh chmod a+x /etc/zabbix/zabbix_agentd.d/yunohost.sh From 2169449f69941c4ea27b80cb98eae13f987341d1 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Wed, 3 Jul 2019 13:05:28 +0200 Subject: [PATCH 110/144] update sym link conf --- scripts/_common.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 1948850..cff8792 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -71,11 +71,11 @@ import_template(){ cp "$sudoUserPpath" /etc/sudoers.d/zabbix - if [ -d /etc/zabbix/zabbix_agentd.d/ ];then - mv /etc/zabbix/zabbix_agentd.d/ /etc/zabbix/zabbix_agentd.conf.d/ + if [ -d /etc/zabbix/zabbix_agentd.d ];then + mv /etc/zabbix/zabbix_agentd.d /etc/zabbix/zabbix_agentd.conf.d fi - if [ ! -L /etc/zabbix/zabbix_agentd.d/ ];then - ln -s /etc/zabbix/zabbix_agentd.d/ /etc/zabbix/zabbix_agentd.conf.d/ + if [ ! -L /etc/zabbix/zabbix_agentd.d ];then + ln -s /etc/zabbix/zabbix_agentd.d /etc/zabbix/zabbix_agentd.conf.d fi cp "$confUserPpath" /etc/zabbix/zabbix_agentd.d/userP_yunohost.conf From ab68a71b79c37af57c3ba3b41c6b02ec1e0d19ee Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Wed, 3 Jul 2019 13:39:06 +0200 Subject: [PATCH 111/144] updated sym link --- scripts/_common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index cff8792..357ba63 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -75,7 +75,7 @@ import_template(){ mv /etc/zabbix/zabbix_agentd.d /etc/zabbix/zabbix_agentd.conf.d fi if [ ! -L /etc/zabbix/zabbix_agentd.d ];then - ln -s /etc/zabbix/zabbix_agentd.d /etc/zabbix/zabbix_agentd.conf.d + ln -s /etc/zabbix/zabbix_agentd.conf.d /etc/zabbix/zabbix_agentd.d fi cp "$confUserPpath" /etc/zabbix/zabbix_agentd.d/userP_yunohost.conf From 14efffe3eb43770266d0b021a897277e93b770cc Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Wed, 3 Jul 2019 13:58:59 +0200 Subject: [PATCH 112/144] --noproxy localhost --- scripts/_common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 357ba63..b739d79 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -83,7 +83,7 @@ import_template(){ chmod a+x /etc/zabbix/zabbix_agentd.d/yunohost.sh systemctl restart zabbix-agent - curlOptions="-k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt --resolve $domain:443:127.0.0.1" + curlOptions="--noproxy localhost -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt --resolve $domain:443:127.0.0.1" curl -L $curlOptions \ --form "enter=Sign+in" \ From 3b30f509953e55bddf42a087347c3cb1268df6a4 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Wed, 3 Jul 2019 14:02:41 +0200 Subject: [PATCH 113/144] debug curl --- scripts/_common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index b739d79..ebdc31f 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -83,7 +83,7 @@ import_template(){ chmod a+x /etc/zabbix/zabbix_agentd.d/yunohost.sh systemctl restart zabbix-agent - curlOptions="--noproxy localhost -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt --resolve $domain:443:127.0.0.1" + curlOptions="--noproxy localhost -k --cookie cookiejar.txt --cookie-jar cookiejar.txt --resolve $domain:443:127.0.0.1" curl -L $curlOptions \ --form "enter=Sign+in" \ From 5449c53d0aae39ed2c05be19bd24667ec3e2f21a Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Wed, 3 Jul 2019 14:06:37 +0200 Subject: [PATCH 114/144] disable proxy --- scripts/_common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index ebdc31f..629391a 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -83,7 +83,7 @@ import_template(){ chmod a+x /etc/zabbix/zabbix_agentd.d/yunohost.sh systemctl restart zabbix-agent - curlOptions="--noproxy localhost -k --cookie cookiejar.txt --cookie-jar cookiejar.txt --resolve $domain:443:127.0.0.1" + curlOptions="--noproxy $domain -k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt --resolve $domain:443:127.0.0.1" curl -L $curlOptions \ --form "enter=Sign+in" \ From e2eed9ffca446eed1d2a5c554a174290c253ad2e Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 4 Jul 2019 13:25:39 +0200 Subject: [PATCH 115/144] add --noproxy $domain by pass proxy localhost --- scripts/_common.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 629391a..d2e99a8 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -136,10 +136,10 @@ import_template(){ link_template(){ #apply template to host - tokenapi=$(curl -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 -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') - zabbixTemplateID=$(curl -k -s --resolve $domain:443:127.0.0.1 --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"template.get","params":{"filter":{"host":["Template Yunohost"]}},"auth":"'"$tokenapi"'","id":1}' "${zabbixFullpath}/api_jsonrpc.php" | jq -r '.result[0].templateid') - applyTemplate=$(curl -k -s --resolve $domain:443:127.0.0.1 --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.massadd","params":{"hosts":[{"hostid":"'"$zabbixHostID"'"}],"templates":[{"templateid":"'"$zabbixTemplateID"'"}]},"auth":"'"$tokenapi"'","id":1}' "${zabbixFullpath}/api_jsonrpc.php" | jq -r '.result.hostids[]') + 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') + zabbixTemplateID=$(curl --noproxy $domain -k -s --resolve $domain:443:127.0.0.1 --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"template.get","params":{"filter":{"host":["Template Yunohost"]}},"auth":"'"$tokenapi"'","id":1}' "${zabbixFullpath}/api_jsonrpc.php" | jq -r '.result[0].templateid') + applyTemplate=$(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.massadd","params":{"hosts":[{"hostid":"'"$zabbixHostID"'"}],"templates":[{"templateid":"'"$zabbixTemplateID"'"}]},"auth":"'"$tokenapi"'","id":1}' "${zabbixFullpath}/api_jsonrpc.php" | jq -r '.result.hostids[]') if [ "$applyTemplate" -eq "$zabbixHostID" ];then ynh_print_info "Template Yunohost linked to Zabbix server !" else From 5e09b033b1c2828dc47e5b826b061355b626708e Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Thu, 4 Jul 2019 13:33:20 +0200 Subject: [PATCH 116/144] 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 117/144] 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 118/144] 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 119/144] 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 120/144] 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 121/144] 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 122/144] 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 123/144] 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 124/144] 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 125/144] 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 126/144] 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 127/144] Update usr_share_zabbix_conf_zabbix.conf.php Date: Fri, 5 Jul 2019 13:50:11 +0200 Subject: [PATCH 128/144] 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 129/144] 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 130/144] 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 131/144] 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 132/144] 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 133/144] 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 134/144] 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 135/144] 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 136/144] 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 137/144] 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 138/144] 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 139/144] 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 140/144] 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 From 0f178e73b21f6b3fe844c5d65fa160ff1949c131 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Wed, 24 Jul 2019 13:45:19 +0200 Subject: [PATCH 141/144] move location /ynh_add_extra_apt_repos__3 --- scripts/ynh_add_extra_apt_repos__3 | 294 +++++++++++++++++++++++++++++ 1 file changed, 294 insertions(+) create mode 100644 scripts/ynh_add_extra_apt_repos__3 diff --git a/scripts/ynh_add_extra_apt_repos__3 b/scripts/ynh_add_extra_apt_repos__3 new file mode 100644 index 0000000..3276f00 --- /dev/null +++ b/scripts/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 ce109ff83160fe7504b6cccd57bd3888e6c50727 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Wed, 24 Jul 2019 15:14:58 +0200 Subject: [PATCH 142/144] Delete ynh_add_extra_apt_repos__3 --- .../app/ynh_add_extra_apt_repos__3 | 294 ------------------ 1 file changed, 294 deletions(-) delete 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 deleted file mode 100644 index 3276f00..0000000 --- a/sources/extra_files/app/ynh_add_extra_apt_repos__3 +++ /dev/null @@ -1,294 +0,0 @@ -#!/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 5deb3f07c1274b0b1a0b62d537eda83dacddcd75 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Wed, 24 Jul 2019 16:12:12 +0200 Subject: [PATCH 143/144] add install and installed path for ynh_add_extra_apt_repos__3 --- scripts/_common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 042d78a..58706d3 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -169,7 +169,7 @@ check_proc_zabbixagent(){ } install_zabbix_repo(){ - ynh_add_extra_apt_repos__3_path=$(find /var/cache/yunohost/ -name "ynh_add_extra_apt_repos__3") + ynh_add_extra_apt_repos__3_path=$(find /var/cache/yunohost/ /etc/yunohost/apps/zabbix/ -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 ca0e37355772e3db32068872155bda30342af8a6 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Wed, 24 Jul 2019 16:25:40 +0200 Subject: [PATCH 144/144] only one path for ynh_add_extra_apt_repos__3 --- scripts/_common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 58706d3..fcfa442 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -169,7 +169,7 @@ check_proc_zabbixagent(){ } install_zabbix_repo(){ - ynh_add_extra_apt_repos__3_path=$(find /var/cache/yunohost/ /etc/yunohost/apps/zabbix/ -name "ynh_add_extra_apt_repos__3") + ynh_add_extra_apt_repos__3_path=$(find /var/cache/yunohost/ /etc/yunohost/apps/zabbix/ -name "ynh_add_extra_apt_repos__3" | tail -n 1) 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