Simplify external repo installation

This commit is contained in:
2020-04-13 10:04:32 -04:00
parent c541190d83
commit 0114e6af2c

View File

@@ -212,7 +212,7 @@ EOF
# build some basic command arrays based on OS and user input # build some basic command arrays based on OS and user input
if [[ "$ID" =~ ^(fedora|centos)$ ]]; then if [[ "$ID" =~ ^(fedora|centos)$ ]]; then
_install_cmd=("dnf" "install" "-y") _install_cmd=("dnf" "install" "-y")
_update_cmd=("dnf" "update" "-y") _update_cmd=("dnf" "makecache" "-y")
_pkg_query_cmd=("rpm" "-q") _pkg_query_cmd=("rpm" "-q")
elif [[ "$ID" =~ ^(ubuntu|debian)$ ]]; then elif [[ "$ID" =~ ^(ubuntu|debian)$ ]]; then
_install_cmd=("apt-get" "install" "-y") _install_cmd=("apt-get" "install" "-y")
@@ -245,34 +245,56 @@ EOF
# We will add packages to this array if their command is not available # We will add packages to this array if their command is not available
local -a _pkg_array local -a _pkg_array
local -a _url_pkg_array
# parse commands # parse commands
for _pkg in "$@"; do for _pkg in "$@"; do
# Clean up package name and handle OS-specific tweaks
_pkg=$(_packageOverrides "$_pkg") _pkg=$(_packageOverrides "$_pkg")
# Insert the package name to test if already installed one element from the end # Insert the package name to test if already installed
# and silence output if [[ "$_pkg" != "" ]] && ! "${_pkg_query_cmd[@]}" "$_pkg" > /dev/null 2>&1; then
if ! "${_pkg_query_cmd[@]}" "$_pkg" > /dev/null 2>&1; then if [[ -n $_url_pkg ]]; then
_pkg_array+=("$_pkg") _url_pkg_array+=("$_url_pkg")
else
_pkg_array+=("$_pkg")
fi
fi fi
done done
if [[ ${#_pkg_array[@]} -ge 1 ]]; then if [[ ${#_pkg_array[@]} -ge 1 ]]; then
echo "Installing ${_pkg_array[*]}" [[ -n $_debug ]] && echo "Installing: " "${_pkg_array[@]}"
"${_install_cmd[@]}" "${_pkg_array[@]}" > /dev/null 2>&1 "${_install_cmd[@]}" "${_pkg_array[@]}" > /dev/null 2>&1
fi fi
if [[ ${#_url_pkg_array[@]} -ge 1 ]]; then
[[ -n $_debug ]] && echo "Installing: " "${_url_pkg_array[@]}"
"${_install_cmd_nogpg[@]}" "${_url_pkg_array[@]}" > /dev/null 2>&1
fi
} }
_packageOverrides () { _packageOverrides () {
if [[ "$ID" == "ubuntu" || "$ID" == "debian" ]]; then unset _url_pkg
if [[ "$1" == "rpm-build" ]]; then
echo "rpm" if [[ "$1" == "rpm-build" && "$ID" =~ ^(ubuntu|debian)$ ]]; then
elif [[ "$1" == "createrepo_c" ]]; then echo "rpm"
echo "createrepo" elif [[ "$1" == "createrepo_c" && "$ID" =~ ^(ubuntu|debian)$ ]]; then
else echo "createrepo"
elif [[ "$1" == "rpmfusion-free-release" ]]; then
if [[ "$ID" == "fedora" ]]; then
_url_pkg="https://download1.rpmfusion.org/free/$ID/rpmfusion-free-release-$VERSION_ID.noarch.rpm"
echo "$1" echo "$1"
elif [[ "$ID" == "centos" ]]; then
_url_pkg="https://download1.rpmfusion.org/free/el/rpmfusion-free-release-$VERSION_ID.noarch.rpm"
echo "$1"
else
echo ""
fi fi
elif [[ "$1" == "epel-release" && "$ID" != "centos" ]]; then
echo ""
else else
echo "$1" echo "$1"
fi fi
@@ -321,21 +343,7 @@ EOF
_installExternalRepos () { _installExternalRepos () {
if [[ "$ID" == "fedora" ]]; then _installPackage rpmfusion-free-release epel-release
if ! rpm --quiet --query rpmfusion-free-release; then
echo "Installing rpmfusion-free-release repo..."
"${_install_cmd_nogpg[@]}" "https://download1.rpmfusion.org/free/$ID/rpmfusion-free-release-$VERSION_ID.noarch.rpm" > /dev/null 2>&1
fi
elif [[ "$ID" == "centos" ]]; then
if ! rpm --quiet --query epel-release; then
echo "Installing epel-release repo..."
"${_install_cmd_nogpg[@]}" epel-release > /dev/null 2>&1
fi
if ! rpm --quiet --query rpmfusion-free-release; then
echo "Installing rpmfusion-free-release repo..."
"${_install_cmd_nogpg[@]}" "https://download1.rpmfusion.org/free/el/rpmfusion-free-release-$VERSION_ID.noarch.rpm" > /dev/null 2>&1
fi
fi
} }
@@ -352,7 +360,7 @@ gpgcheck=0
EOF' EOF'
[[ -n $_debug ]] && cat /etc/yum.repos.d/jriver.repo [[ -n $_debug ]] && cat /etc/yum.repos.d/jriver.repo
echo "Installing latest JRiver Media Center from repo..." echo "Installing latest JRiver Media Center from repo..."
if "${_update_cmd[@]}" && "${_install_cmd[@]}" MediaCenter; then if "${_update_cmd[@]}" && "${_install_cmd[@]}" MediaCenter > /dev/null 2>&1; then
echo "JRiver Media Center installed successfully!" echo "JRiver Media Center installed successfully!"
echo "You can check for future MC updates by running \"sudo dnf update\"" echo "You can check for future MC updates by running \"sudo dnf update\""
else else