Skip to content

Commit

Permalink
Change apt to dpkg for better performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Enaraque committed Jun 13, 2024
1 parent cbb4da5 commit 465ea5f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
16 changes: 12 additions & 4 deletions unattended_installer/common_functions/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions unattended_installer/install_functions/checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,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
Expand Down
10 changes: 5 additions & 5 deletions unattended_installer/install_functions/installCommon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -601,7 +601,7 @@ function installCommon_rollBack() {
elif [ "${sys_type}" == "apt-get" ]; then
common_checkAptLock
eval "apt-get remove --purge wazuh-manager -y ${debug}"
eval "apt list --installed 2>/dev/null | grep wazuh-manager"
eval "dpkg -l wazuh-manager 2>/dev/null | grep -E '^ii\s'"
fi

manager_installed=${PIPESTATUS[0]}
Expand Down Expand Up @@ -629,7 +629,7 @@ function installCommon_rollBack() {
elif [ "${sys_type}" == "apt-get" ]; then
common_checkAptLock
eval "apt-get remove --purge wazuh-indexer -y ${debug}"
eval "apt list --installed 2>/dev/null | grep wazuh-indexer"
eval "dpkg -l wazuh-indexer 2>/dev/null | grep -E '^ii\s'"
fi

indexer_installed=${PIPESTATUS[0]}
Expand Down Expand Up @@ -658,7 +658,7 @@ function installCommon_rollBack() {
elif [ "${sys_type}" == "apt-get" ]; then
common_checkAptLock
eval "apt-get remove --purge filebeat -y ${debug}"
eval "apt list --installed 2>/dev/null | grep filebeat"
eval "dpkg -l filebeat 2>/dev/null | grep -E '^ii\s'"
fi

filebeat_installed=${PIPESTATUS[0]}
Expand Down Expand Up @@ -687,7 +687,7 @@ function installCommon_rollBack() {
elif [ "${sys_type}" == "apt-get" ]; then
common_checkAptLock
eval "apt-get remove --purge wazuh-dashboard -y ${debug}"
eval "apt list --installed 2>/dev/null | grep wazuh-dashboard"
eval "dpkg -l wazuh-dashboard 2>/dev/null | grep -E '^ii\s'"
fi

dashboard_installed=${PIPESTATUS[0]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ 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
Expand Down

0 comments on commit 465ea5f

Please sign in to comment.