From 51282e0472ad8336c89fe39ce06f5cac990502e5 Mon Sep 17 00:00:00 2001 From: bryan Date: Wed, 15 Feb 2023 12:38:16 -0500 Subject: [PATCH] Convert more commands to arrays for execute() --- installJRMC | 66 ++++++++++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/installJRMC b/installJRMC index a2bcef3..a2550b4 100755 --- a/installJRMC +++ b/installJRMC @@ -258,6 +258,7 @@ init() { debug "Running: ${FUNCNAME[0]}" declare -g ID RPM_MGR ARCH + declare -ga PKG_INSTALL PKG_REMOVE PKG_UPDATE echo "Starting installJRMC" debug || echo "To enable debugging output, use --debug or -d" @@ -306,7 +307,7 @@ init() { ID="debian" ;; *) - err "Autodetecting distro, this is unreliable and --compat may also be required" + err "Autodetecting distro, this is unreliable and --compat may be required" if hash dnf &>/dev/null; then ID="fedora" RPM_MGR="dnf" @@ -329,33 +330,32 @@ init() { # Abstract distro-specific package manager commands case "$ID" in fedora|centos) - pkg_install(){ sudo "$RPM_MGR" install -y "$@"; } - pkg_install_local() { installMCRPM; } - pkg_remove(){ sudo "$RPM_MGR" remove -y "$@"; } - pkg_update(){ sudo "$RPM_MGR" makecache; } - pkg_swap() { sudo dnf swap -y "$1" "$2"; } - pkg_query(){ rpm -q "$@"; } + PKG_INSTALL=(sudo "$RPM_MGR" install -y) + PKG_REMOVE=(sudo "$RPM_MGR" remove -y) + PKG_UPDATE=(sudo "$RPM_MGR" makecache) + PKG_QUERY(){ rpm -q "$@"; } + PKG_INSTALL_LOCAL(){ installMCRPM; } ;; debian|ubuntu) - pkg_install(){ sudo apt-get -f install -y -q0 "$@"; } - pkg_install_local() { installMCDEB; } - pkg_remove(){ sudo apt-get remove --auto-remove -y -q0 "$@"; } - pkg_update(){ sudo apt-get update -y -q0; } - pkg_query(){ dpkg -s "$@"; } + PKG_INSTALL=(sudo apt-get -f install -y -q0) + PKG_REMOVE=(sudo apt-get remove --auto-remove -y -q0) + PKG_UPDATE=(sudo apt-get update -y -q0) + PKG_QUERY(){ dpkg -s "$@"; } + PKG_INSTALL_LOCAL(){ installMCDEB; } ;; suse) - pkg_install(){ sudo zypper --non-interactive -q install --force --no-confirm "$@"; } - pkg_install_local() { installMCRPM; } - pkg_remove(){ sudo zypper --non-interactive -q remove --clean-deps "$@"; } - pkg_update(){ sudo zypper --non-interactive -q refresh jriver; } - pkg_query(){ rpm -q "$@"; } + PKG_INSTALL=(sudo zypper --non-interactive -q install --force --no-confirm) + PKG_REMOVE=(sudo zypper --non-interactive -q remove --clean-deps) + PKG_UPDATE=(sudo zypper --non-interactive -q refresh jriver) + PKG_QUERY(){ rpm -q "$@"; } + PKG_INSTALL_LOCAL(){ installMCRPM; } ;; arch) - pkg_install(){ sudo pacman -Sy --noconfirm "$@"; } - pkg_install_local() { installMCARCH; } - pkg_remove(){ sudo pacman -Rs --noconfirm "$@"; } - pkg_update(){ sudo pacman -Syy ; } - pkg_query(){ sudo pacman -Qs "$@"; } + PKG_INSTALL=(sudo pacman -Sy --noconfirm) + PKG_REMOVE=(sudo pacman -Rs --noconfirm) + PKG_UPDATE=(sudo pacman -Syy) + PKG_QUERY(){ sudo pacman -Qs "$@"; } + PKG_INSTALL_LOCAL(){ installMCARCH; } ;; esac } @@ -485,7 +485,7 @@ installPackage() { fi if (( skip_check_installed )) || ! (hash "$pkg" &>/dev/null || - pkg_query "$pkg" &>/dev/null); then + PKG_QUERY "$pkg" &>/dev/null); then pkg_array+=("$pkg") else debug "$pkg already installed, skipping installation" @@ -509,7 +509,7 @@ installPackage() { # Install packages from package array if [[ ${#pkg_array[@]} -ge 1 ]]; then - if ! execute "pkg_install ${install_flags[*]} ${pkg_array[*]}"; then + if ! execute "${PKG_INSTALL[*]} ${install_flags[*]} ${pkg_array[*]}"; then (( silent )) || err "Failed to install ${pkg_array[*]}. Attempting to continue" return 1 fi @@ -551,7 +551,7 @@ installMCFromRepo() { ;; esac - if ! execute "pkg_update"; then + if ! execute "${PKG_UPDATE[@]}"; then err "Package update failed!" return 1 fi @@ -840,16 +840,16 @@ installMesa() { # Currently only necessary in Fedora/CentOS case "$ID" in fedora|centos) - if ! pkg_query mesa-va-drivers-freeworld &>/dev/null; then - if pkg_query mesa-va-drivers &>/dev/null; then - if ! execute pkg_swap \ + if ! PKG_QUERY mesa-va-drivers-freeworld &>/dev/null; then + if PKG_QUERY mesa-va-drivers &>/dev/null; then + if ! execute sudo dnf swap -y \ mesa-va-drivers \ mesa-va-drivers-freeworld; then err "Package swap failed!" return 1 fi else - pkg_install mesa-va-drivers-freeworld + execute "${PKG_INSTALL[*]} mesa-va-drivers-freeworld" fi fi ;; @@ -1582,7 +1582,7 @@ uninstall() { fi echo "Uninstalling JRiver Media Center package" - if execute "pkg_remove $MCPKG"; then + if execute "${PKG_REMOVE[@]}" "$MCPKG"; then echo "JRiver Media Center has been completely uninstalled" echo "To remove your library files, run: rm -rf $HOME/.jriver" elif [[ $? -eq 100 ]]; then @@ -1643,13 +1643,13 @@ main() { echo "Adding EPEL repository" installPackage epel-release fi - if ! pkg_query rpmfusion-free-release &>/dev/null; then + if ! PKG_QUERY rpmfusion-free-release &>/dev/null; then installPackage --skip-check-installed \ "https://download1.rpmfusion.org/free/el/rpmfusion-free-release-$VERSION_ID.noarch.rpm" fi ;; fedora) - if ! pkg_query rpmfusion-free-release &>/dev/null; then + if ! PKG_QUERY rpmfusion-free-release &>/dev/null; then installPackage --skip-check-installed \ "https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$VERSION_ID.noarch.rpm" fi @@ -1681,7 +1681,7 @@ main() { fi if (( LOCAL_INSTALL_SWITCH )); then - if pkg_install_local; then + if PKG_INSTALL_LOCAL; then echo "JRiver Media Center installed successfully from local package" else err "JRiver Media Center local package installation failed"