diff --git a/CHANGELOG.md b/CHANGELOG.md index 35b6821..738053f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file. ### Changed +- Change apt to dpkg for better performance. ([#89](https://github.com/wazuh/wazuh-installation-assistant/pull/89)) - Added check when generating certificates for multiple DNS. ([#88](https://github.com/wazuh/wazuh-installation-assistant/pull/88)) - Change cert-tool to use only one wazuh-certificates folder. ([#87](https://github.com/wazuh/wazuh-installation-assistant/pull/87)) - Solve bugs when changing passwords in the manager, indexer and dashboard services. ([#86](https://github.com/wazuh/wazuh-installation-assistant/pull/86)) diff --git a/common_functions/common.sh b/common_functions/common.sh index 359624b..72c1804 100644 --- a/common_functions/common.sh +++ b/common_functions/common.sh @@ -74,7 +74,7 @@ function common_checkRoot() { fi common_logger -d "Checking sudo package." - if ! command -v sudo > /dev/null; then + if ! command -v sudo > /dev/null; then common_logger -e "The sudo package is not installed and it is necessary for the installation." exit 1; fi @@ -91,7 +91,9 @@ function common_checkInstalled() { if [ "${sys_type}" == "yum" ]; then eval "rpm -q wazuh-manager --quiet && wazuh_installed=1" elif [ "${sys_type}" == "apt-get" ]; then - wazuh_installed=$(apt list --installed 2>/dev/null | grep wazuh-manager) + if dpkg -l wazuh-manager 2>/dev/null | grep -q -E '^ii\s'; then + wazuh_installed=1 + fi fi if [ -d "/var/ossec" ]; then @@ -103,7 +105,9 @@ function common_checkInstalled() { eval "rpm -q wazuh-indexer --quiet && indexer_installed=1" elif [ "${sys_type}" == "apt-get" ]; then - indexer_installed=$(apt list --installed 2>/dev/null | grep wazuh-indexer) + if dpkg -l wazuh-indexer 2>/dev/null | grep -q -E '^ii\s'; then + indexer_installed=1 + fi fi if [ -d "/var/lib/wazuh-indexer/" ] || [ -d "/usr/share/wazuh-indexer" ] || [ -d "/etc/wazuh-indexer" ] || [ -f "${base_path}/search-guard-tlstool*" ]; then @@ -114,7 +118,9 @@ function common_checkInstalled() { if [ "${sys_type}" == "yum" ]; then eval "rpm -q filebeat --quiet && filebeat_installed=1" elif [ "${sys_type}" == "apt-get" ]; then - filebeat_installed=$(apt list --installed 2>/dev/null | grep filebeat) + if dpkg -l filebeat 2>/dev/null | grep -q -E '^ii\s'; then + filebeat_installed=1 + fi fi if [ -d "/var/lib/filebeat/" ] || [ -d "/usr/share/filebeat" ] || [ -d "/etc/filebeat" ]; then @@ -125,7 +131,9 @@ function common_checkInstalled() { if [ "${sys_type}" == "yum" ]; then eval "rpm -q wazuh-dashboard --quiet && dashboard_installed=1" elif [ "${sys_type}" == "apt-get" ]; then - dashboard_installed=$(apt list --installed 2>/dev/null | grep wazuh-dashboard) + if dpkg -l wazuh-dashboard 2>/dev/null | grep -q -E '^ii\s'; then + dashboard_installed=1 + fi fi if [ -d "/var/lib/wazuh-dashboard/" ] || [ -d "/usr/share/wazuh-dashboard" ] || [ -d "/etc/wazuh-dashboard" ] || [ -d "/run/wazuh-dashboard/" ]; then diff --git a/install_functions/checks.sh b/install_functions/checks.sh index 0d42d2a..a458ab6 100644 --- a/install_functions/checks.sh +++ b/install_functions/checks.sh @@ -472,10 +472,10 @@ function checks_firewall(){ eval "rpm -q firewalld --quiet && firewalld_installed=1" eval "rpm -q ufw --quiet && ufw_installed=1" elif [ "${sys_type}" == "apt-get" ]; then - if apt list --installed 2>/dev/null | grep -q -E ^"firewalld"\/; then + if dpkg -l "firewalld" 2>/dev/null | grep -q -E '^ii\s'; then firewalld_installed=1 fi - if apt list --installed 2>/dev/null | grep -q -E ^"ufw"\/; then + if dpkg -l "ufw" 2>/dev/null | grep -q -E '^ii\s'; then ufw_installed=1 fi fi diff --git a/install_functions/installCommon.sh b/install_functions/installCommon.sh index dee1f72..043f52a 100644 --- a/install_functions/installCommon.sh +++ b/install_functions/installCommon.sh @@ -121,7 +121,7 @@ function installCommon_aptInstallList(){ not_installed=() for dep in "${dependencies[@]}"; do - if ! apt list --installed 2>/dev/null | grep -q -E ^"${dep}"\/; then + if ! dpkg -l "${dep}" 2>/dev/null | grep -q -E '^ii\s'; then not_installed+=("${dep}") for wia_dep in "${wia_apt_dependencies[@]}"; do if [ "${wia_dep}" == "${dep}" ]; then @@ -631,7 +631,7 @@ function installCommon_rollBack() { elif [ "${sys_type}" == "apt-get" ]; then common_checkAptLock eval "apt-get remove --purge wazuh-manager -y ${debug}" - manager_installed=$(apt list --installed 2>/dev/null | grep wazuh-manager) + manager_installed=$(dpkg -l wazuh-manager 2>/dev/null | grep -E '^ii\s') fi if [ -n "${manager_installed}" ]; then @@ -657,7 +657,7 @@ function installCommon_rollBack() { elif [ "${sys_type}" == "apt-get" ]; then common_checkAptLock eval "apt-get remove --purge wazuh-indexer -y ${debug}" - indexer_installed=$(apt list --installed 2>/dev/null | grep wazuh-indexer) + indexer_installed=$(dpkg -l wazuh-indexer 2>/dev/null | grep -E '^ii\s') fi if [ -n "${indexer_installed}" ]; then @@ -684,7 +684,7 @@ function installCommon_rollBack() { elif [ "${sys_type}" == "apt-get" ]; then common_checkAptLock eval "apt-get remove --purge filebeat -y ${debug}" - filebeat_installed=$(apt list --installed 2>/dev/null | grep filebeat) + filebeat_installed=$(dpkg -l filebeat 2>/dev/null | grep -E '^ii\s') fi if [ -n "${filebeat_installed}" ]; then @@ -711,7 +711,7 @@ function installCommon_rollBack() { elif [ "${sys_type}" == "apt-get" ]; then common_checkAptLock eval "apt-get remove --purge wazuh-dashboard -y ${debug}" - dashboard_installed=$(apt list --installed 2>/dev/null | grep wazuh-dashboard) + dashboard_installed=$(dpkg -l wazuh-dashboard 2>/dev/null | grep -E '^ii\s') fi if [ -n "${dashboard_installed}" ]; then diff --git a/install_functions/wazuh-offline-installation.sh b/install_functions/wazuh-offline-installation.sh index dab1f82..d0769bb 100644 --- a/install_functions/wazuh-offline-installation.sh +++ b/install_functions/wazuh-offline-installation.sh @@ -18,9 +18,9 @@ function offline_checkDependencies() { if [ "${sys_type}" == "yum" ]; then eval "yum list installed 2>/dev/null | grep -q -E ^"${dep}"\\." elif [ "${sys_type}" == "apt-get" ]; then - eval "apt list --installed 2>/dev/null | grep -q -E ^"${dep}"\/" + eval "dpkg -l "${dep}" 2>/dev/null | grep -q -E '^ii\s'" fi - + if [ "${PIPESTATUS[0]}" != 0 ]; then common_logger -e "${dep} is necessary for the offline installation." exit 1 @@ -39,9 +39,9 @@ function offline_checkPrerequisites(){ if [ "${sys_type}" == "yum" ]; then eval "yum list installed 2>/dev/null | grep -q -E ^"${dep}"\\." elif [ "${sys_type}" == "apt-get" ]; then - eval "apt list --installed 2>/dev/null | grep -q -E ^"${dep}"\/" + eval "dpkg -l "${dep}" 2>/dev/null | grep -q -E '^ii\s'" fi - + if [ "${PIPESTATUS[0]}" != 0 ]; then common_logger -e "${dep} is necessary for the offline installation." exit 1 @@ -85,7 +85,7 @@ function offline_extractFiles() { "${offline_files_path}/wazuh-filebeat-*.tar.gz" "${offline_files_path}/wazuh-template.json" ) - + if [ "${sys_type}" == "apt-get" ]; then required_files+=("${offline_packages_path}/filebeat-oss-*.deb" "${offline_packages_path}/wazuh-dashboard_*.deb" "${offline_packages_path}/wazuh-indexer_*.deb" "${offline_packages_path}/wazuh-manager_*.deb") elif [ "${sys_type}" == "rpm" ]; then