1
0
mirror of https://github.com/pi-hole/pi-hole synced 2024-12-22 14:58:08 +00:00

Move code from check_epel_repo_required into the rpm branch of the if check on package_manager_detect(), adjust tests to accommodate

Signed-off-by: Adam Warner <me@adamwarner.co.uk>
This commit is contained in:
Adam Warner 2022-07-30 19:18:33 +01:00
parent 0e8c1ec023
commit 9028898ba7
No known key found for this signature in database
GPG Key ID: 872950F3ECF2B173
4 changed files with 18 additions and 32 deletions

View File

@ -366,6 +366,21 @@ package_manager_detect() {
LIGHTTPD_GROUP="lighttpd" LIGHTTPD_GROUP="lighttpd"
LIGHTTPD_CFG="lighttpd.conf.fedora" LIGHTTPD_CFG="lighttpd.conf.fedora"
# If the host OS is centos (or a derivative), epel is required for lighttpd
if ! grep -qiE 'fedora|fedberry' /etc/redhat-release; then
# Check current CentOS major release version
CURRENT_CENTOS_VERSION=$(grep -oP '(?<= )[0-9]+(?=\.?)' /etc/redhat-release)
if rpm -qa | grep -qi 'epel'; then
printf " %b EPEL repository already installed\\n" "${TICK}"
else
# CentOS requires the EPEL repository to gain access to Fedora packages
EPEL_PKG="https://dl.fedoraproject.org/pub/epel/epel-release-latest-${CURRENT_CENTOS_VERSION}.noarch.rpm"
printf " %b Enabling EPEL package repository (https://fedoraproject.org/wiki/EPEL)\\n" "${INFO}"
"${PKG_INSTALL[@]}" "${EPEL_PKG}"
printf " %b Installed %s\\n" "${TICK}" "${EPEL_PKG}"
fi
fi
# If neither apt-get or yum/dnf package managers were found # If neither apt-get or yum/dnf package managers were found
else else
# we cannot install required packages # we cannot install required packages
@ -375,23 +390,6 @@ package_manager_detect() {
fi fi
} }
check_epel_repo_required(){
# If the host OS is centos (or a derivative), epel is required for lighttpd
if ! grep -qiE 'fedora|fedberry' /etc/redhat-release; then
# Check current CentOS major release version
CURRENT_CENTOS_VERSION=$(grep -oP '(?<= )[0-9]+(?=\.?)' /etc/redhat-release)
if rpm -qa | grep -qi 'epel'; then
printf " %b EPEL repository already installed\\n" "${TICK}"
else
# CentOS requires the EPEL repository to gain access to Fedora packages
EPEL_PKG="https://dl.fedoraproject.org/pub/epel/epel-release-latest-${CURRENT_CENTOS_VERSION}.noarch.rpm"
printf " %b Enabling EPEL package repository (https://fedoraproject.org/wiki/EPEL)\\n" "${INFO}"
"${PKG_INSTALL[@]}" ${EPEL_PKG}
printf " %b Installed %s\\n" "${TICK}" "${EPEL_PKG}"
fi
fi
}
# A function for checking if a directory is a git repository # A function for checking if a directory is a git repository
is_repo() { is_repo() {
# Use a named, local variable instead of the vague $1, which is the first argument passed to this function # Use a named, local variable instead of the vague $1, which is the first argument passed to this function
@ -2536,12 +2534,6 @@ main() {
printf " %b Checking for / installing Required dependencies for this install script...\\n" "${INFO}" printf " %b Checking for / installing Required dependencies for this install script...\\n" "${INFO}"
install_dependent_packages "${INSTALLER_DEPS[@]}" install_dependent_packages "${INSTALLER_DEPS[@]}"
#In case of RPM based distro, select the proper PHP version
if [[ "$PKG_MANAGER" == "yum" || "$PKG_MANAGER" == "dnf" ]] ; then
check_epel_repo_required
fi
# If the setup variable file exists, # If the setup variable file exists,
if [[ -f "${setupVars}" ]]; then if [[ -f "${setupVars}" ]]; then
# if it's running unattended, # if it's running unattended,

View File

@ -1107,7 +1107,7 @@ def test_package_manager_has_installer_deps(host):
install_dependent_packages ${INSTALLER_DEPS[@]} install_dependent_packages ${INSTALLER_DEPS[@]}
''') ''')
assert 'No package' not in output.stdout # centos7 still exits 0... assert 'No package' not in output.stdout
assert output.rc == 0 assert output.rc == 0
@ -1117,11 +1117,10 @@ def test_package_manager_has_pihole_deps(host):
output = host.run(''' output = host.run('''
source /opt/pihole/basic-install.sh source /opt/pihole/basic-install.sh
package_manager_detect package_manager_detect
check_epel_repo_required
install_dependent_packages ${PIHOLE_DEPS[@]} install_dependent_packages ${PIHOLE_DEPS[@]}
''') ''')
assert 'No package' not in output.stdout # centos7 still exits 0... assert 'No package' not in output.stdout
assert output.rc == 0 assert output.rc == 0
@ -1131,9 +1130,8 @@ def test_package_manager_has_web_deps(host):
output = host.run(''' output = host.run('''
source /opt/pihole/basic-install.sh source /opt/pihole/basic-install.sh
package_manager_detect package_manager_detect
check_epel_repo_required
install_dependent_packages ${PIHOLE_WEB_DEPS[@]} install_dependent_packages ${PIHOLE_WEB_DEPS[@]}
''') ''')
assert 'No package' not in output.stdout # centos7 still exits 0... assert 'No package' not in output.stdout
assert output.rc == 0 assert output.rc == 0

View File

@ -14,7 +14,6 @@ def test_enable_epel_repository_centos(host):
package_manager_detect = host.run(''' package_manager_detect = host.run('''
source /opt/pihole/basic-install.sh source /opt/pihole/basic-install.sh
package_manager_detect package_manager_detect
check_epel_repo_required
''') ''')
expected_stdout = info_box + (' Enabling EPEL package repository ' expected_stdout = info_box + (' Enabling EPEL package repository '
'(https://fedoraproject.org/wiki/EPEL)') '(https://fedoraproject.org/wiki/EPEL)')

View File

@ -6,11 +6,8 @@ def test_epel_and_remi_not_installed_fedora(host):
package_manager_detect = host.run(''' package_manager_detect = host.run('''
source /opt/pihole/basic-install.sh source /opt/pihole/basic-install.sh
package_manager_detect package_manager_detect
check_epel_repo_required
''') ''')
assert package_manager_detect.stdout == '' assert package_manager_detect.stdout == ''
epel_package = host.package('epel-release') epel_package = host.package('epel-release')
assert not epel_package.is_installed assert not epel_package.is_installed
remi_package = host.package('remi-release')
assert not remi_package.is_installed