Cleanup installPackage()
This commit is contained in:
113
installJRMC
113
installJRMC
@@ -22,7 +22,7 @@ _exec_user="$(whoami)"
|
|||||||
|
|
||||||
# Version control
|
# Version control
|
||||||
_boardurl="https://yabb.jriver.com/interact/index.php/board,71.0.html" # Media Center 28, only required if buildah is unavailable
|
_boardurl="https://yabb.jriver.com/interact/index.php/board,71.0.html" # Media Center 28, only required if buildah is unavailable
|
||||||
# _mcversion="28.0.84" # set manually
|
# _mcversion="28.0.84" # to set manually
|
||||||
|
|
||||||
printHelp() {
|
printHelp() {
|
||||||
debug "Running: ${FUNCNAME[0]}"
|
debug "Running: ${FUNCNAME[0]}"
|
||||||
@@ -114,7 +114,6 @@ init() {
|
|||||||
if [[ "$ID" =~ ^(fedora|centos)$ ]]; then
|
if [[ "$ID" =~ ^(fedora|centos)$ ]]; then
|
||||||
pkg_install(){ ifSudo dnf install -y "$@"; }
|
pkg_install(){ ifSudo dnf install -y "$@"; }
|
||||||
pkg_reinstall(){ ifSudo dnf reinstall -y "$@"; }
|
pkg_reinstall(){ ifSudo dnf reinstall -y "$@"; }
|
||||||
pkg_install_nogpg(){ ifSudo dnf install --nogpgcheck -y "$@"; }
|
|
||||||
pkg_remove(){ ifSudo dnf remove -y "$@"; }
|
pkg_remove(){ ifSudo dnf remove -y "$@"; }
|
||||||
pkg_update(){ ifSudo dnf makecache; }
|
pkg_update(){ ifSudo dnf makecache; }
|
||||||
pkg_query(){ ifSudo rpm -q "$@"; }
|
pkg_query(){ ifSudo rpm -q "$@"; }
|
||||||
@@ -122,7 +121,6 @@ init() {
|
|||||||
elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then
|
elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then
|
||||||
pkg_install(){ ifSudo apt-get install -y -q0 "$@"; }
|
pkg_install(){ ifSudo apt-get install -y -q0 "$@"; }
|
||||||
pkg_reinstall(){ ifSudo apt-get reinstall -y -q0 "$@"; }
|
pkg_reinstall(){ ifSudo apt-get reinstall -y -q0 "$@"; }
|
||||||
pkg_install_nogpg(){ ifSudo apt-get install -y -q0 "$@"; }
|
|
||||||
pkg_remove(){ ifSudo apt-get remove --auto-remove -y -q0 "$@"; }
|
pkg_remove(){ ifSudo apt-get remove --auto-remove -y -q0 "$@"; }
|
||||||
pkg_update(){ ifSudo apt-get update -y -q0; }
|
pkg_update(){ ifSudo apt-get update -y -q0; }
|
||||||
pkg_query(){ ifSudo dpkg -s "$@"; }
|
pkg_query(){ ifSudo dpkg -s "$@"; }
|
||||||
@@ -306,6 +304,7 @@ getLatestVersion() {
|
|||||||
declare -g _mcversion
|
declare -g _mcversion
|
||||||
|
|
||||||
# Use a containerized package manager
|
# Use a containerized package manager
|
||||||
|
# TODO but how to determine build distro ('buster')?
|
||||||
[[ ! -x $(command -v buildah) ]] && installPackage --silent buildah
|
[[ ! -x $(command -v buildah) ]] && installPackage --silent buildah
|
||||||
if [[ -x $(command -v buildah) ]] && CNT=$(buildah from ubuntu:18.04); then
|
if [[ -x $(command -v buildah) ]] && CNT=$(buildah from ubuntu:18.04); then
|
||||||
buildah run "$CNT" -- bash -c \
|
buildah run "$CNT" -- bash -c \
|
||||||
@@ -333,18 +332,28 @@ getLatestVersion() {
|
|||||||
# Arguments:
|
# Arguments:
|
||||||
# One or more package names
|
# One or more package names
|
||||||
# Options:
|
# Options:
|
||||||
# --noquery, -n: Do not query the package state (useful if installing a local RPM)
|
# --no-check: Do not check if package is already installed
|
||||||
# --silent, -s: Do not report errors (useful if package is not strictly required)
|
# --no-gpg: Disable GPG checks for RPM based distros
|
||||||
|
# --silent, -s: Do not report errors (useful if package is not strictly required and errors are noisy)
|
||||||
#######################################
|
#######################################
|
||||||
installPackage() {
|
installPackage() {
|
||||||
debug "Running: ${FUNCNAME[0]}" "$@"
|
debug "Running: ${FUNCNAME[0]}" "$@"
|
||||||
|
|
||||||
if _input=$(getopt -o +ns -l noquery,silent -- "$@"); then
|
local -a _pkg_array
|
||||||
|
local -a _pkg
|
||||||
|
local _gpg=""
|
||||||
|
|
||||||
|
if _input=$(getopt -o +s -l no-check,no-gpg,silent -- "$@"); then
|
||||||
eval set -- "$_input"
|
eval set -- "$_input"
|
||||||
while true; do
|
while true; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--noquery|-n)
|
--no-check)
|
||||||
local _noquery="true"
|
local _no_check=true
|
||||||
|
;;
|
||||||
|
--no-gpg)
|
||||||
|
if [[ "$ID" =~ ^(fedora|centos)$ ]]; then
|
||||||
|
_gpg="--nogpgcheck"
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
--silent|-s)
|
--silent|-s)
|
||||||
local _silent=true
|
local _silent=true
|
||||||
@@ -361,54 +370,33 @@ installPackage() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local -a _pkg_array _url_pkg_array
|
|
||||||
local -a _pkg
|
|
||||||
|
|
||||||
# Parse packages
|
|
||||||
for _pkg in "$@"; do
|
for _pkg in "$@"; do
|
||||||
|
# Check for alias
|
||||||
[[ -v PKG_ALIASES && -v PKG_ALIASES["$_pkg"] ]] && _pkg=PKG_ALIASES["$_pkg"]
|
[[ -v PKG_ALIASES && -v PKG_ALIASES["$_pkg"] ]] && _pkg=PKG_ALIASES["$_pkg"]
|
||||||
# Insert the package name to test if already installed
|
# Check if already installed
|
||||||
if [[ -v _noquery ]] || ! pkg_query "$_pkg" > /dev/null 2>&1; then
|
if [[ -v _no_check ]] || ! pkg_query "$_pkg" > /dev/null 2>&1; then
|
||||||
if [[ -v _url_pkg ]]; then
|
_pkg_array+=("$_pkg")
|
||||||
_url_pkg_array+=("$_url_pkg")
|
|
||||||
else
|
|
||||||
_pkg_array+=("$_pkg")
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Install from package name (with gpg check)
|
# Install from package name
|
||||||
if [[ ${#_pkg_array[@]} -ge 1 ]]; then
|
if [[ ${#_pkg_array[@]} -ge 1 ]]; then
|
||||||
[[ ! -v _silent ]] && echo "Installing:" "${_pkg_array[@]}"
|
debug "Installing: ${_pkg_array[*]}"
|
||||||
if debug; then
|
if debug; then
|
||||||
if ! pkg_install "${_pkg_array[@]}"; then
|
debug "pkg_install $_gpg ${_pkg_array[*]}"
|
||||||
[[ ! -v _silent ]] && err "Failed to install package. Attempting to continue..."
|
pkg_install "$_gpg" "${_pkg_array[@]}"
|
||||||
return 1
|
else
|
||||||
fi
|
pkg_install "$_gpg" "${_pkg_array[@]}" > /dev/null 2>&1
|
||||||
elif ! pkg_install "${_pkg_array[@]}" > /dev/null 2>&1; then
|
|
||||||
[[ ! -v _silent ]] && err "Failed to install ${_pkg_array[*]}. Attempting to continue..."
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Install from package url (without gpg check)
|
|
||||||
if [[ ${#_url_pkg_array[@]} -ge 1 ]]; then
|
|
||||||
[[ ! -v _silent ]] && echo "Installing: " "${_url_pkg_array[@]}"
|
|
||||||
if debug; then
|
|
||||||
if ! pkg_install_nogpg "${_url_pkg_array[@]}"; then
|
|
||||||
[[ ! -v _silent ]] && err "Failed to install package. Attempting to continue..."
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
elif ! pkg_install_nogpg "${_url_pkg_array[@]}" > /dev/null 2>&1; then
|
|
||||||
[[ ! -v _silent ]] && err "Failed to install package. Attempting to continue..."
|
|
||||||
return 1
|
|
||||||
fi
|
fi
|
||||||
|
local _return=$?
|
||||||
|
[[ $_return -ne 0 && ! -v _silent ]] && err "Failed to install ${_pkg_array[*]}. Attempting to continue..."
|
||||||
|
return $_return
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#######################################
|
#######################################
|
||||||
# Adds the JRiver repos
|
# Add the JRiver repository files
|
||||||
#######################################
|
#######################################
|
||||||
addRepo() {
|
addRepo() {
|
||||||
debug "Running: ${FUNCNAME[0]}"
|
debug "Running: ${FUNCNAME[0]}"
|
||||||
@@ -441,7 +429,7 @@ installMCFromRepo() {
|
|||||||
|
|
||||||
if ! debug; then
|
if ! debug; then
|
||||||
echo "This may take a few minutes to complete."
|
echo "This may take a few minutes to complete."
|
||||||
echo "Use --debug for more verbose output."
|
echo "Use --debug for verbose output."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
addRepo
|
addRepo
|
||||||
@@ -461,24 +449,17 @@ installMCFromRepo() {
|
|||||||
|
|
||||||
if [[ -v _specific_version ]]; then
|
if [[ -v _specific_version ]]; then
|
||||||
if [[ "$ID" =~ ^(fedora|centos)$ ]]; then
|
if [[ "$ID" =~ ^(fedora|centos)$ ]]; then
|
||||||
if debug; then
|
_mcpkg="$_mcpkg-$_mcversion"
|
||||||
installPackage "$_mcpkg-$_mcversion"
|
|
||||||
else
|
|
||||||
installPackage "$_mcpkg-$_mcversion" > /dev/null 2>&1
|
|
||||||
fi
|
|
||||||
elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then
|
elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then
|
||||||
if debug; then
|
_mcpkg="$_mcpkg=$_mcversion"
|
||||||
installPackage "$_mcpkg=$_mcversion"
|
|
||||||
else
|
|
||||||
installPackage "$_mcpkg=$_mcversion" > /dev/null 2>&1
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if debug; then
|
||||||
|
debug "installPackage $_mcpkg"
|
||||||
|
installPackage "$_mcpkg"
|
||||||
else
|
else
|
||||||
if debug; then
|
installPackage "$_mcpkg" > /dev/null 2>&1
|
||||||
installPackage "$_mcpkg"
|
|
||||||
else
|
|
||||||
installPackage "$_mcpkg" > /dev/null 2>&1
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return $?
|
return $?
|
||||||
@@ -514,12 +495,12 @@ acquireDeb() {
|
|||||||
"https://files.jriver.com/mediacenter/channels/v$_mversion/latest/MediaCenter-$_mcversion-amd64.deb"; then
|
"https://files.jriver.com/mediacenter/channels/v$_mversion/latest/MediaCenter-$_mcversion-amd64.deb"; then
|
||||||
echo "Found!"
|
echo "Found!"
|
||||||
else
|
else
|
||||||
err "Cannot find DEB file. Exiting..."
|
err "Cannot find DEB file."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -f "$DEBFILENAME" ]]; then
|
if [[ ! -f "$DEBFILENAME" ]]; then
|
||||||
err "Downloaded DEB file missing or corrupted, exiting..."
|
err "Downloaded DEB file missing or corrupted."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -1183,9 +1164,9 @@ uninstall() {
|
|||||||
|
|
||||||
echo "Uninstalling Media Center packages"
|
echo "Uninstalling Media Center packages"
|
||||||
if [[ "$ID" =~ ^(fedora|centos)$ ]]; then
|
if [[ "$ID" =~ ^(fedora|centos)$ ]]; then
|
||||||
pkg_remove "MediaCenter"
|
pkg_remove "-q" "MediaCenter"
|
||||||
elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then
|
elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then
|
||||||
pkg_remove "mediacenter$_mversion"
|
pkg_remove "-q" "mediacenter$_mversion"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "JRiver Media Center has been completely uninstalled"
|
echo "JRiver Media Center has been completely uninstalled"
|
||||||
@@ -1195,7 +1176,7 @@ uninstall() {
|
|||||||
|
|
||||||
|
|
||||||
tests() {
|
tests() {
|
||||||
# To test on Mint: sudo apt-get install -y spice-vdagent ca-certificates git
|
# To test on Mint: sudo apt-get install -y spice-vdagent ca-certificates git; export GIT_SSL_NO_VERIFY=1
|
||||||
exit $?
|
exit $?
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1228,7 +1209,7 @@ main() {
|
|||||||
if [[ -v _build ]]; then
|
if [[ -v _build ]]; then
|
||||||
acquireDeb
|
acquireDeb
|
||||||
if ! buildRPM || [[ ! -f "$_mcrpm" ]] ; then
|
if ! buildRPM || [[ ! -f "$_mcrpm" ]] ; then
|
||||||
err "Build failed. Exiting..."
|
err "Build failed."
|
||||||
[[ -f "$DEBFILENAME" ]] && echo "Removing source DEB" && rm -f "$DEBFILENAME"
|
[[ -f "$DEBFILENAME" ]] && echo "Removing source DEB" && rm -f "$DEBFILENAME"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
@@ -1243,7 +1224,7 @@ main() {
|
|||||||
|
|
||||||
# Install RPM
|
# Install RPM
|
||||||
if [[ -v _install && "$_install" == "rpm" ]]; then
|
if [[ -v _install && "$_install" == "rpm" ]]; then
|
||||||
installPackage --noquery "$_mcrpm"
|
installPackage --no-check "$_mcrpm"
|
||||||
symlinkCerts
|
symlinkCerts
|
||||||
restoreLicense
|
restoreLicense
|
||||||
openFirewall "jriver"
|
openFirewall "jriver"
|
||||||
|
|||||||
Reference in New Issue
Block a user