Convert more commands to arrays for execute()

This commit is contained in:
2023-02-15 12:38:16 -05:00
parent df980f103c
commit 51282e0472

View File

@@ -258,6 +258,7 @@ init() {
debug "Running: ${FUNCNAME[0]}" debug "Running: ${FUNCNAME[0]}"
declare -g ID RPM_MGR ARCH declare -g ID RPM_MGR ARCH
declare -ga PKG_INSTALL PKG_REMOVE PKG_UPDATE
echo "Starting installJRMC" echo "Starting installJRMC"
debug || echo "To enable debugging output, use --debug or -d" debug || echo "To enable debugging output, use --debug or -d"
@@ -306,7 +307,7 @@ init() {
ID="debian" 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 if hash dnf &>/dev/null; then
ID="fedora" ID="fedora"
RPM_MGR="dnf" RPM_MGR="dnf"
@@ -329,33 +330,32 @@ init() {
# Abstract distro-specific package manager commands # Abstract distro-specific package manager commands
case "$ID" in case "$ID" in
fedora|centos) fedora|centos)
pkg_install(){ sudo "$RPM_MGR" install -y "$@"; } PKG_INSTALL=(sudo "$RPM_MGR" install -y)
pkg_install_local() { installMCRPM; } PKG_REMOVE=(sudo "$RPM_MGR" remove -y)
pkg_remove(){ sudo "$RPM_MGR" remove -y "$@"; } PKG_UPDATE=(sudo "$RPM_MGR" makecache)
pkg_update(){ sudo "$RPM_MGR" makecache; } PKG_QUERY(){ rpm -q "$@"; }
pkg_swap() { sudo dnf swap -y "$1" "$2"; } PKG_INSTALL_LOCAL(){ installMCRPM; }
pkg_query(){ rpm -q "$@"; }
;; ;;
debian|ubuntu) debian|ubuntu)
pkg_install(){ sudo apt-get -f install -y -q0 "$@"; } PKG_INSTALL=(sudo apt-get -f install -y -q0)
pkg_install_local() { installMCDEB; } PKG_REMOVE=(sudo apt-get remove --auto-remove -y -q0)
pkg_remove(){ sudo apt-get remove --auto-remove -y -q0 "$@"; } PKG_UPDATE=(sudo apt-get update -y -q0)
pkg_update(){ sudo apt-get update -y -q0; } PKG_QUERY(){ dpkg -s "$@"; }
pkg_query(){ dpkg -s "$@"; } PKG_INSTALL_LOCAL(){ installMCDEB; }
;; ;;
suse) suse)
pkg_install(){ sudo zypper --non-interactive -q install --force --no-confirm "$@"; } 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_remove(){ sudo zypper --non-interactive -q remove --clean-deps "$@"; } PKG_UPDATE=(sudo zypper --non-interactive -q refresh jriver)
pkg_update(){ sudo zypper --non-interactive -q refresh jriver; } PKG_QUERY(){ rpm -q "$@"; }
pkg_query(){ rpm -q "$@"; } PKG_INSTALL_LOCAL(){ installMCRPM; }
;; ;;
arch) arch)
pkg_install(){ sudo pacman -Sy --noconfirm "$@"; } PKG_INSTALL=(sudo pacman -Sy --noconfirm)
pkg_install_local() { installMCARCH; } PKG_REMOVE=(sudo pacman -Rs --noconfirm)
pkg_remove(){ sudo pacman -Rs --noconfirm "$@"; } PKG_UPDATE=(sudo pacman -Syy)
pkg_update(){ sudo pacman -Syy ; } PKG_QUERY(){ sudo pacman -Qs "$@"; }
pkg_query(){ sudo pacman -Qs "$@"; } PKG_INSTALL_LOCAL(){ installMCARCH; }
;; ;;
esac esac
} }
@@ -485,7 +485,7 @@ installPackage() {
fi fi
if (( skip_check_installed )) || if (( skip_check_installed )) ||
! (hash "$pkg" &>/dev/null || ! (hash "$pkg" &>/dev/null ||
pkg_query "$pkg" &>/dev/null); then PKG_QUERY "$pkg" &>/dev/null); then
pkg_array+=("$pkg") pkg_array+=("$pkg")
else else
debug "$pkg already installed, skipping installation" debug "$pkg already installed, skipping installation"
@@ -509,7 +509,7 @@ installPackage() {
# Install packages from package array # Install packages from package array
if [[ ${#pkg_array[@]} -ge 1 ]]; then 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" (( silent )) || err "Failed to install ${pkg_array[*]}. Attempting to continue"
return 1 return 1
fi fi
@@ -551,7 +551,7 @@ installMCFromRepo() {
;; ;;
esac esac
if ! execute "pkg_update"; then if ! execute "${PKG_UPDATE[@]}"; then
err "Package update failed!" err "Package update failed!"
return 1 return 1
fi fi
@@ -840,16 +840,16 @@ installMesa() {
# Currently only necessary in Fedora/CentOS # Currently only necessary in Fedora/CentOS
case "$ID" in case "$ID" in
fedora|centos) fedora|centos)
if ! pkg_query mesa-va-drivers-freeworld &>/dev/null; then if ! PKG_QUERY mesa-va-drivers-freeworld &>/dev/null; then
if pkg_query mesa-va-drivers &>/dev/null; then if PKG_QUERY mesa-va-drivers &>/dev/null; then
if ! execute pkg_swap \ if ! execute sudo dnf swap -y \
mesa-va-drivers \ mesa-va-drivers \
mesa-va-drivers-freeworld; then mesa-va-drivers-freeworld; then
err "Package swap failed!" err "Package swap failed!"
return 1 return 1
fi fi
else else
pkg_install mesa-va-drivers-freeworld execute "${PKG_INSTALL[*]} mesa-va-drivers-freeworld"
fi fi
fi fi
;; ;;
@@ -1582,7 +1582,7 @@ uninstall() {
fi fi
echo "Uninstalling JRiver Media Center package" 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 "JRiver Media Center has been completely uninstalled"
echo "To remove your library files, run: rm -rf $HOME/.jriver" echo "To remove your library files, run: rm -rf $HOME/.jriver"
elif [[ $? -eq 100 ]]; then elif [[ $? -eq 100 ]]; then
@@ -1643,13 +1643,13 @@ main() {
echo "Adding EPEL repository" echo "Adding EPEL repository"
installPackage epel-release installPackage epel-release
fi fi
if ! pkg_query rpmfusion-free-release &>/dev/null; then if ! PKG_QUERY rpmfusion-free-release &>/dev/null; then
installPackage --skip-check-installed \ installPackage --skip-check-installed \
"https://download1.rpmfusion.org/free/el/rpmfusion-free-release-$VERSION_ID.noarch.rpm" "https://download1.rpmfusion.org/free/el/rpmfusion-free-release-$VERSION_ID.noarch.rpm"
fi fi
;; ;;
fedora) fedora)
if ! pkg_query rpmfusion-free-release &>/dev/null; then if ! PKG_QUERY rpmfusion-free-release &>/dev/null; then
installPackage --skip-check-installed \ installPackage --skip-check-installed \
"https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$VERSION_ID.noarch.rpm" "https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$VERSION_ID.noarch.rpm"
fi fi
@@ -1681,7 +1681,7 @@ main() {
fi fi
if (( LOCAL_INSTALL_SWITCH )); then if (( LOCAL_INSTALL_SWITCH )); then
if pkg_install_local; then if PKG_INSTALL_LOCAL; then
echo "JRiver Media Center installed successfully from local package" echo "JRiver Media Center installed successfully from local package"
else else
err "JRiver Media Center local package installation failed" err "JRiver Media Center local package installation failed"