Refactoring

This commit is contained in:
2021-05-10 17:08:18 -04:00
parent 97e734e1ac
commit 437f3da360
2 changed files with 1183 additions and 1347 deletions

View File

@@ -11,21 +11,21 @@ This program will install [JRiver Media Center](https://www.jriver.com/) and ass
`installJRMC [--option [ARGUMENT]]`
Running `installJRMC` without any options will install the latest version of JRiver Media Center from the official JRiver repository (Ubuntu/Debian) or my [unofficial repository](https://repos.bryanroessler.com/jriver/) (Fedora/CentOS) using the system package manager. If any other option is specified then the default install method will need to be specified using `--install-repo` (or `--install-rpm`). This makes it possible to install services, containers, repos, etc. independent from Media Center.
Running `installJRMC` without any options will install the latest version of JRiver Media Center from the official JRiver repository (Ubuntu/Debian) or my [unofficial repository](https://repos.bryanroessler.com/jriver/) (Fedora/CentOS) using the system package manager. If any other option is specified then the default install method will need to be specified using `--repo` or `--rpm`. This makes it possible to install services, containers, repos, etc. independent of Media Center.
## Options
Here is a list of possible options that can be passed to the script. You can always find the latest supported options by running `installJRMC --help`.
```text
--install-repo
Install JRiver Media Center from repository using package manager (Default)
--repo
Install JRiver Media Center from repository using package manager
DEB-based OSes: Official package repository
RPM-based OSes: BryanC's unofficial repository
--install-rpm
(RPM-based OSes only) Build RPM from source DEB and install it
--rpm
Build RPM from source DEB and install it
--rpmbuild
Build RPM from source DEB
Build RPM from source DEB but do not install
--outputdir PATH
Generate rpmbuild output in this directory (Default: $PWD/outputdir)
--mcversion VERSION
@@ -81,7 +81,7 @@ jriver-createrepo
Install hourly service to build latest MC RPM and run createrepo
```
It is possible to install multiple services at one time using multiple `--service` blocks: `installJRMC --install-repo --service jriver-x11vnc --service jriver-mediacenter`
It is possible to install multiple services at one time using multiple `--service` blocks: `installJRMC --repo --service jriver-x11vnc --service jriver-mediacenter`
#### `jriver-x11vnc` versus `jriver-xvnc-mediacenter`
@@ -105,11 +105,11 @@ It is possible to install multiple services at one time using multiple `--servic
Installs the latest version of JRiver Media Center from the repository.
* `installJRMC --install-repo --service jriver-mediaserver`
* `installJRMC --repo --service jriver-mediaserver`
Installs JRiver Media Center from the repository and starts/enables the /MediaServer service.
* `installJRMC --install-rpm --restorefile /path/to/license.mjr --mcversion 26.0.56`
* `installJRMC --rpm --restorefile /path/to/license.mjr --mcversion 26.0.56`
Builds JRiver Media Center version 26.0.56 RPM from the source DEB, installs it (RPM distros only), and activates it using the specified .mjr license file.
@@ -121,11 +121,11 @@ It is possible to install multiple services at one time using multiple `--servic
Installs the jriver-createrepo timer and service to build the RPM, move it to the webroot, and run createrepo as `www-user` hourly.
* `installJRMC --install-repo --service jriver-x11vnc --service jriver-mediacenter --vncpass "letmein"`
* `installJRMC --repo --service jriver-x11vnc --service jriver-mediacenter --vncpass "letmein"`
Installs services to share the existing local desktop via VNC and automatically run Media Center on startup.
* `installJRMC --install-repo --service jriver-xvnc-mediacenter --display ":2"`
* `installJRMC --repo --service jriver-xvnc-mediacenter --display ":2"`
Installs an Xvnc server on display ':2' that starts Media Center.

View File

@@ -10,21 +10,13 @@ shopt -s extglob
# 1. Raspberry Pi OS support
# 2. Interactive installation (ncurses?)
#
# installJRMC can be run directly or sourced as a function (by sourcing this file)
# Arguments:
# see _printHelpAndExit() and _parseInput() for available options
# Returns:
# 0 if critical functions complete successfully
#######################################
installJRMC() {
_scriptversion="0.9.5"
_scriptversion="0.9.6"
_boardurl="https://yabb.jriver.com/interact/index.php/board,67.0.html"
_outputdir="$_basedir/output"
_outputdir="$PWD/output"
_createrepo_webroot="/srv/jriver"
_exec_user="$(whoami)"
_available_services=("jriver-createrepo" "jriver-x11vnc" "jriver-mediaserver" "jriver-mediacenter" "jriver-xvnc-mediacenter")
#_available_containers=("mediacenter-xvnc" "createrepo")
_printHelpAndExit() {
debug "Running: ${FUNCNAME[0]}"
@@ -33,15 +25,17 @@ installJRMC() {
USAGE:
installJRMC [[OPTION] [VALUE]]...
If no options (besides -d) are provided, the script will default to --repo
OPTIONS
--install-repo
Install JRiver Media Center from repository using package manager (Default)
DEB-based OSes: Official package repository
--repo
Install JRiver Media Center from repository using package manager
DEB-based OSes: JRiver official package repository
RPM-based OSes: BryanC unofficial repository
--install-rpm
(RPM-based OSes only) Build RPM from source DEB and install it
--rpm
Build RPM from source DEB and install it
--rpmbuild
Build RPM from source DEB
Build RPM from source DEB (no installation)
--outputdir PATH
Generate rpmbuild output in this directory (Default: $PWD/outputdir)
--mcversion VERSION
@@ -51,7 +45,7 @@ installJRMC() {
--betapass PASSWORD
Enter beta team password for access to beta builds
--service-user USER
Install systemd services and containers for USER
Install systemd services and containers for USER (Default: current user)
--service, -s SERVICE
See SERVICES section below for a list of possible services to install
--container, -c CONTAINER (TODO: Under construction)
@@ -101,22 +95,178 @@ installJRMC() {
}
_parseInput() {
_init() {
debug "Running: ${FUNCNAME[0]}"
# set default behavior
_getOS
_parseInput "$@"
# Agnostic commands
_bash_cmd(){ _ifSudo bash -c "$@"; }
_rm_cmd(){ _ifSudo rm -rf "$@"; }
_cp_cmd(){ _ifSudo cp -n "$@"; }
_mkdir_cmd(){ _ifSudo mkdir -p "$@"; }
_ln_cmd(){ _ifSudo ln -s "$@"; }
_systemctl_reload(){ _ifSudo systemctl daemon-reload; }
_systemctl_enable(){ _ifSudo systemctl enable --now "$@"; }
_systemctl_disable(){ _ifSudo systemctl disable --now "$@"; }
# OS-specific commands
if [[ "$ID" =~ ^(fedora|centos)$ ]]; then
_pkg_install(){ _ifSudo dnf install -y "$@"; }
_pkg_reinstall(){ _ifSudo dnf reinstall -y "$@"; }
_pkg_install_nogpg(){ _ifSudo dnf install --nogpgcheck -y "$@"; }
_pkg_remove(){ _ifSudo dnf remove -y "$@"; }
_pkg_update(){ _ifSudo dnf makecache; }
_pkg_query(){ _ifSudo rpm -q "$@"; }
_firewall_cmd(){ _ifSudo firewall-cmd "$@"; }
elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then
_pkg_install(){ _ifSudo apt-get install -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 -y -q0 "$@"; }
_pkg_update(){ _ifSudo apt-get update -y -q0; }
_pkg_query(){ _ifSudo dpkg -s "$@"; }
_firewall_cmd(){ _ifSudo ufw "$@"; }
fi
# Set defaults
if [[ $# -eq 0 ]] || [[ $# -eq 1 && "$1" =~ ^(--debug|-d)$ ]]; then
debug "No options passed, defaulting to --repo installation method"
_repoinstall="true"
fi
if _input=$(getopt -o +vdhus:c: -l install-repo,install-rpm,rpmbuild,outputdir:,mcversion:,restorefile:,betapass:,service-user:,service:,version,debug,help,uninstall,createrepo,createrepo-webroot:,createrepo-user:,vncpass:,display:,container: -- "$@"); then
_service_user="${_service_user:-$_exec_user}"
_createrepo_user="${_createrepo_user:-$_exec_user}"
# Set package aliases
if [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then
declare -Ag PKG_ALIASES
PKG_ALIASES["xorg-x11-utils"]="xorg-x11"
PKG_ALIASES["rpm-build"]="rpm"
PKG_ALIASES["createrepo_c"]="createrepo"
PKG_ALIASES["tigervnc-server"]="tigervnc-standalone-server"
fi
# Install script dependencies
[[ "$ID" == "centos" ]] && _installPackage epel-release
[[ ! -v _mcversion ]] && _installPackage wget
# Set MC version
_setVersion
}
_main() {
_init "$@"
# Uninstall and exit
if [[ -v _uninstall ]]; then
_uninstall
exit $?
fi
# Install MC using package manager
if [[ -v _repoinstall ]]; then
_installMCFromRepo
_symlinkCerts
_restoreLicense
_openFirewall "jriver"
fi
# Build RPM from source deb package
if [[ -v _rpmbuild ]]; then
_acquireDeb
_buildRPM
fi
# Run createrepo
if [[ -v _createrepo ]]; then
_runCreaterepo "$_mcrpm"
fi
# Install the rpm
if [[ -v _rpminstall ]]; then
_installPackage --noquery "$_mcrpm"
_symlinkCerts
_restoreLicense
_openFirewall "jriver"
fi
# Install services
_setDisplay
for _service in "${_services[@]}"; do
_servicePrep "$_service"
if ! "_service_$_service"; then
if [[ $? -eq 127 ]]; then
err "Service $_service does not exist, check your service name"
else
err "Failed to create service: $_service"
fi
fi
done
# Install containers
for _container in "${_containers[@]}"; do
if ! "_container_$_container"; then
if [[ $? -eq 127 ]]; then
err "Container $_container does not exist, check your container name"
else
err "Failed to create container: $_container"
fi
fi
done
}
#######################################
# Helper functions
#######################################
err() { echo "Error: $*" >&2; }
debug() {
if [[ -v _debug ]]; then
if [[ $# -gt 0 ]]; then
echo "Debug: $*"
fi
else
return 1
fi
}
#######################################
# Prepend this to any command that you wish to execute with sudo
# Requires:
# _exec_user
#######################################
_ifSudo() {
if [[ "$_exec_user" != "root" ]]; then
sudo "$@"
else
"$@"
fi
}
#######################################
# Parse CLI input from the user w/ getopt
#######################################
_parseInput() {
debug "Running: ${FUNCNAME[0]}"
if _input=$(getopt -o +vdhus:c: -l repo,rpm,rpmbuild,outputdir:,mcversion:,restorefile:,betapass:,service-user:,service:,version,debug,help,uninstall,createrepo,createrepo-webroot:,createrepo-user:,vncpass:,display:,container: -- "$@"); then
eval set -- "$_input"
while true; do
case "$1" in
--install-repo)
--repo)
_repoinstall="true"
;;
--install-rpm)
--rpm)
[[ ! "$ID" =~ ^(fedora|centos)$ ]] && \
err "RPM installation not available on $ID" && \
_printHelpAndExit 1
_rpmbuild="true"
_rpminstall="true"
;;
@@ -141,6 +291,22 @@ installJRMC() {
--service|-s)
shift && _services+=("$1")
;;
--createrepo)
_rpmbuild="true"
_createrepo="true"
;;
--createrepo-webroot)
shift && _createrepo_webroot="$1"
;;
--createrepo-user)
shift && _createrepo_user="$1"
;;
--vncpass)
shift && _vncpass="$1"
;;
--display)
shift && _display="$1"
;;
--container|-c)
shift && _containers+=("$1")
;;
@@ -159,22 +325,6 @@ installJRMC() {
--uninstall|-u)
_uninstall="true"
;;
--createrepo)
_createrepo="true"
_rpmbuild="true"
;;
--createrepo-webroot)
shift && _createrepo_webroot="$1"
;;
--createrepo-user)
shift && _createrepo_user="$1"
;;
--vncpass)
shift && _vncpass="$1"
;;
--display)
shift && _display="$1"
;;
--)
shift
break
@@ -188,27 +338,9 @@ installJRMC() {
fi
}
err() { echo "Error: $*" >&2; }
debug() { [[ -v _debug ]] && echo "Debug: $*"; }
#######################################
# Prepend this to any command that you wish to execute with sudo
# Requires:
# _exec_user
#######################################
_ifSudo() {
if [[ "$_exec_user" != "root" ]]; then
sudo "$@"
else
"$@"
fi
}
#######################################
# Sources /etc/os-release so we know which OS we're running on
# Used in: _buildCommands()
# Get host OS from /etc/os-release
#######################################
_getOS() {
debug "Running: ${FUNCNAME[0]}"
@@ -216,7 +348,7 @@ installJRMC() {
if [[ -e "/etc/os-release" ]]; then
source "/etc/os-release"
else
err "No /etc/os-release found"
err "/etc/os-release not found"
err "Your OS is unsupported"
_printHelpAndExit 1
fi
@@ -226,80 +358,29 @@ installJRMC() {
#######################################
# Creates some OS-specific functions to query, install, and remove packages and edit
# firewalls, run bash, remove and copy files, etc.
# Get our MC working version from input argument or scraping Interact
# Requires:
# _boardurl
#######################################
_buildCommands() {
# Detect OS
_getOS
_setVersion() {
debug "Running: ${FUNCNAME[0]}"
# Agnostic commands
_bash_cmd(){ _ifSudo bash -c "$@"; }
_rm_cmd(){ _ifSudo rm -rf "$@"; }
_cp_cmd(){ _ifSudo cp -n "$@"; }
_mkdir_cmd(){ _ifSudo mkdir -p "$@"; }
_ln_cmd(){ _ifSudo ln -s "$@"; }
_systemctl_reload(){ _ifSudo systemctl daemon-reload; }
_systemctl_start(){
echo "Starting $*"
if ! _ifSudo systemctl start "$@"; then
err "Could not start $*"
err "Check service status using \"sudo systemctl status $*\""
return 1
fi
}
_systemctl_enable(){ _ifSudo systemctl enable "$@"; }
_systemctl_disable(){ _ifSudo systemctl disable --now "$@"; }
# OS-specific commands
if [[ "$ID" =~ ^(fedora|centos)$ ]]; then
_pkg_install(){ _ifSudo dnf install -y "$@"; }
_pkg_reinstall(){ _ifSudo dnf reinstall -y "$@"; }
_pkg_install_nogpg(){ _ifSudo dnf install --nogpgcheck -y "$@"; }
_pkg_remove(){ _ifSudo dnf remove -y "$@"; }
_pkg_update(){ _ifSudo dnf makecache; }
_pkg_query(){ _ifSudo rpm -q "$@"; }
_firewall_cmd(){ _ifSudo firewall-cmd "$@"; }
elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then
_pkg_install(){ _ifSudo apt-get install -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 -y -q0 "$@"; }
_pkg_update(){ _ifSudo apt-get update -y -q0; }
_pkg_query(){ _ifSudo dpkg -s "$@"; }
_firewall_cmd(){ _ifSudo ufw "$@"; }
fi
# Some additional commands specifically for createrepo (primarily to handle user rights)
# Could also go in runCreaterepo() but let's leave it here for now
if [[ $_createrepo_user != "root" ]]; then
if [[ -d "$_createrepo_webroot/repodata" ]]; then
_createrepo_cmd(){ sudo -u "$_createrepo_user" createrepo -q --update "$@"; }
else
_createrepo_cmd(){ sudo -u "$_createrepo_user" createrepo -q "$@"; }
fi
_cr_mkdir_cmd(){ sudo -u "$_createrepo_user" mkdir -p "$@"; }
_cr_cp_cmd(){ sudo -u "$_createrepo_user" cp -n "$@"; }
else
if [[ -d "$_createrepo_webroot/repodata" ]]; then
_createrepo_cmd(){ createrepo -q --update "$@"; }
else
_createrepo_cmd(){ createrepo -q "$@"; }
# If user does not specify a version, scrape the latest from Interact
if [[ ! -v _mcversion ]]; then
echo "Scraping latest MC version number from Interact..."
if ! _mcversion=$(wget -qO- "$_boardurl" | grep -o "[0-9][0-9]\.[0-9]\.[0-9]\+" | head -n 1); then
err "MC version could not be scraped. Please recheck the boardurl: $_boardurl or specify a version manually using --mcversion"
_printHelpAndExit 1
fi
fi
}
echo "Using version: $_mcversion"
#######################################
# Sets default user variables
#######################################
_setUser() {
# Extract major version number
_mversion="${_mcversion%%.*}"
[[ ! -v _service_user ]] && _service_user="$_exec_user"
[[ ! -v _createrepo_user ]] && _createrepo_user="$_exec_user"
# Saving this substituion in case it's needed in the future
#_variation="${_mcversion##*.}"
}
@@ -313,7 +394,6 @@ installJRMC() {
# Will exit 1 if failed
#######################################
_installPackage() {
debug "Running: ${FUNCNAME[0]}" "$@"
if _input=$(getopt -o +n -l noquery -- "$@"); then
@@ -339,12 +419,10 @@ installJRMC() {
local -a _pkg_array
local -a _url_pkg_array
# parse arguments (packages)
# Parse packages
for _pkg in "$@"; do
# Clean up package name and handle OS-specific tweaks
_packageQuirks "$_pkg"
[[ -v PKG_ALIASES && -v PKG_ALIASES["$_pkg"] ]] && _pkg=PKG_ALIASES["$_pkg"]
# Insert the package name to test if already installed
if [[ "$_pkg" != "" ]]; then
if [[ -v _noquery ]] || ! _pkg_query "$_pkg" > /dev/null 2>&1; then
if [[ -v _url_pkg ]]; then
_url_pkg_array+=("$_url_pkg")
@@ -352,13 +430,12 @@ installJRMC() {
_pkg_array+=("$_pkg")
fi
fi
fi
done
# Install from package name (with gpg check)
if [[ ${#_pkg_array[@]} -ge 1 ]]; then
echo "Installing:" "${_pkg_array[@]}"
if [[ -v _debug ]]; then
if debug; then
if ! _pkg_install "${_pkg_array[@]}"; then
err "Failed to install package. Attempting to continue..."
return 1
@@ -372,7 +449,7 @@ installJRMC() {
# Install from package url (without gpg check)
if [[ ${#_url_pkg_array[@]} -ge 1 ]]; then
echo "Installing:" "${_url_pkg_array[@]}"
if [[ -v _debug ]]; then
if debug; then
if ! _pkg_install_nogpg "${_url_pkg_array[@]}"; then
err "Failed to install package. Attempting to continue..."
return 1
@@ -385,170 +462,6 @@ installJRMC() {
}
#######################################
# Handles OS-specific package name tweaks and source urls
# Arguments:
# A package name
# Globals:
# _pkg
# _url_pkg
#######################################
_packageQuirks() {
debug "Running: ${FUNCNAME[0]}" "$@"
unset _url_pkg
if [[ "$1" == "xorg-x11-utils" && "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then
_pkg="x11-utils"
elif [[ "$1" == "rpm-build" && "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then
_pkg="rpm"
elif [[ "$1" == "createrepo_c" && "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then
_pkg="createrepo"
elif [[ "$1" == "rpmfusion-free-release" ]]; then
if [[ "$ID" == "fedora" ]]; then
# As of MC26 and Fedora 32 I don't believe that the rpmfusion repo is necessary
#_url_pkg="https://download1.rpmfusion.org/free/$ID/rpmfusion-free-release-$VERSION_ID.noarch.rpm"
#_pkg="$1"
_pkg=""
elif [[ "$ID" == "centos" ]]; then
_url_pkg="https://download1.rpmfusion.org/free/el/rpmfusion-free-release-$VERSION_ID.noarch.rpm"
_pkg="$1"
else
_pkg=""
fi
elif [[ "$1" == "epel-release" && "$ID" != "centos" ]]; then
_pkg=""
elif [[ "$1" == "tigervnc-server" && "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then
_pkg="tigervnc-standalone-server"
else
_pkg="$1"
fi
}
#######################################
# Get our MC working version from input argument or scraping Interact
# Requires:
# _boardurl
# _installPackage
# Globals:
# _mcversion
# _mversion
#######################################
_setVersion() {
debug "Running: ${FUNCNAME[0]}"
if [[ ! -v _mcversion ]]; then
_installPackage wget
# Get latest version from Interact
echo "Scraping latest MC version number from Interact..."
if ! _mcversion=$(wget -qO- "$_boardurl" | grep -o "[0-9][0-9]\.[0-9]\.[0-9]\+" | head -n 1); then
err "MC version could not be scraped. Please specify a version manually using --mcversion or check your --boardurl"
_printHelpAndExit 1
fi
fi
echo "Using version: $_mcversion"
# Extract major version number
_mversion="${_mcversion%%.*}"
# Saving this substituion in case it's needed in the future
#_variation="${_mcversion##*.}"
}
#######################################
# Check if an argument exists in an array
# Arguments:
# The first argument is the string to match to the following arguments
# Example:
# _inArray "zebra" "${animals_arr[@]}"
# Returns:
# 0 if a match is found, 1 if not
#######################################
_inArray() {
local _match="$1"
shift
local _item
for _item in "$@"; do
[[ "$_item" == "$_match" ]] && return 0
done
return 1
}
#######################################
# Clean up nonsensical user input
# Notes:
# I try to keep this function as short as possible and provide better input options and
# sensible defaults than workarounds
# Test:
# _installJRMC should run sucessfully even without running _sanityChecks()
#######################################
_sanityChecks() {
debug "Running: ${FUNCNAME[0]}"
# Check for bad service name
_checkServices() {
debug "Running: ${FUNCNAME[0]}"
for _service in "${_services[@]}"; do
if ! _inArray "$_service" "${_available_services[@]}"; then
echo "Incorrect service type provided"
_printHelpAndExit 1
fi
done
}
_checkMCInstalled() {
debug "Running: ${FUNCNAME[0]}"
for _service in "${_services[@]}"; do
if [[ "$_service" =~ ^(jriver-mediacenter|jriver-mediaserver|jriver-xvnc-mediacenter|jriver-x11vnc)$ ]] \
&& [[ ! -v _repoinstall && ! -v _rpminstall ]] \
&& [[ ! -x $(command -v "mediacenter$_mversion") ]]; then
err "You are attempting to install a service that depends on JRiver Media Center"
err "without installing JRiver Media Center"
err "Automatically enabling --repo-install"
_repoinstall="true"
fi
done
}
_checkUser() {
debug "Running: ${FUNCNAME[0]}"
if [[ "$_exec_user" == "root" && ! -v _service_user && "${_services[*]}" ]]; then
err "Attempting to install services as the root user"
err "This is not recommended and we are exiting now to prevent permission hell"
err "You can override this safety check by manually specifying --user root"
return 1
fi
}
# Enable/disable sanity checks
if _checkServices && _checkMCInstalled && _checkUser; then
debug "Sanity checks passed!"
return 0
else
err "Sanity checks failed!"
exit 1
fi
}
#######################################
# Installs JRiver Media Center from a repository
# Returns:
@@ -558,8 +471,9 @@ installJRMC() {
debug "Running: ${FUNCNAME[0]}"
echo "Installing JRiver Media Center from repo..."
[[ ! -v _debug ]] && \
echo "This may take a few minutes"; \
! debug && \
echo "This may take a few minutes to complete"; \
echo "Use --debug for verbose output"
local _mcpkg
@@ -567,7 +481,7 @@ installJRMC() {
# Add repository files
_addRepo() {
debug "Running: ${FUNCNAME[0]}"
# Add repositories to OS-specific package managers
if [[ "$ID" =~ ^(fedora|centos)$ ]]; then
_bash_cmd 'cat <<- EOF > /etc/yum.repos.d/jriver.repo
[jriver]
@@ -592,21 +506,13 @@ installJRMC() {
exit 1
fi
# If user specifies a version, use that
if [[ -v _mcversion ]]; then
_setVersion
local _specific_version="true"
fi
local _mcpkg
# Fedora/CentOS use a universal package name -- easy
if [[ "$ID" =~ ^(fedora|centos)$ ]]; then
_mcpkg="MediaCenter"
fi
# Ubuntu/Debian incorporate the mversion into the package name -- more fun!
if [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then
elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then
if [[ ! -v _mversion ]]; then
# Try parsing the latest mversion from the repo
if _mcpkg=$(apt-get install mediacenter?? -s -q0 | grep "selecting" | tail -1| awk '{print $3}'); then
@@ -614,7 +520,6 @@ installJRMC() {
_mcpkg="${_mcpkg#\'}"
# Scrape Interact
else
_setVersion
_mcpkg="mediacenter$_mversion"
fi
else
@@ -629,20 +534,20 @@ installJRMC() {
if [[ -v _specific_version ]]; then
if [[ "$ID" =~ ^(fedora|centos)$ ]]; then
if [[ -v _debug ]]; then
if debug; then
_installPackage "$_mcpkg-$_mcversion"
else
_installPackage "$_mcpkg-$_mcversion" > /dev/null 2>&1
fi
elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then
if [[ -v _debug ]]; then
if debug; then
_installPackage "$_mcpkg=$_mcversion"
else
_installPackage "$_mcpkg=$_mcversion" > /dev/null 2>&1
fi
fi
else
if [[ -v _debug ]]; then
if debug; then
_installPackage "$_mcpkg"
else
_installPackage "$_mcpkg" > /dev/null 2>&1
@@ -650,14 +555,12 @@ installJRMC() {
fi
# shellcheck disable=SC2181
# Rationale: More compact to check this once
if [[ $? -eq 0 ]]; then
echo "JRiver Media Center installed successfully"
return 0
else
if [[ $? -ne 0 ]]; then
err "JRiver Media Center installation failed"
exit 1
fi
echo "JRiver Media Center installed successfully"
}
@@ -669,7 +572,7 @@ installJRMC() {
_acquireDeb() {
debug "Running: ${FUNCNAME[0]}"
local _debfilename="$_outputdir/SOURCES/MediaCenter-${_mcversion}-amd64.deb"
local _debfilename="$_outputdir/SOURCES/MediaCenter-$_mcversion-amd64.deb"
# If necessary, create SOURCES dir
[[ ! -d "$_outputdir/SOURCES" ]] && mkdir -p "$_outputdir/SOURCES"
@@ -680,16 +583,16 @@ installJRMC() {
# Else check beta repo
elif [[ -v _betapass ]]; then
if wget -q -O "$_debfilename" \
"https://files.jriver.com/mediacenter/channels/v${_mversion}/beta/${_betapass}/MediaCenter-${_mcversion}-amd64.deb"; then
"https://files.jriver.com/mediacenter/channels/v$_mversion/beta/$_betapass/MediaCenter-$_mcversion-amd64.deb"; then
true
fi
# Else check test repo
elif wget -q -O "$_debfilename" \
"https://files.jriver.com/mediacenter/test/MediaCenter-${_mcversion}-amd64.deb"; then
"https://files.jriver.com/mediacenter/test/MediaCenter-$_mcversion-amd64.deb"; then
true
# Else check latest repo
elif wget -q -O "$_debfilename" \
"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
true
else
err "Cannot find DEB file. Exiting..."
@@ -769,7 +672,7 @@ installJRMC() {
Provides: mediacenter$_mversion
License: Copyright 1998-2020, JRiver, Inc. All rights reserved. Protected by U.S. patents #7076468 and #7062468
License: Copyright 1998-2021, JRiver, Inc. All rights reserved. Protected by U.S. patents #7076468 and #7062468
URL: http://www.jriver.com/
%define __provides_exclude_from ^%{_libdir}/jriver/.*/.*\\.so.*$
@@ -802,10 +705,11 @@ installJRMC() {
if [[ -f "$_mcrpm" ]]; then
echo "$_mcrpm already exists. Skipping build step..."
return 0
else
fi
# Run rpmbuild
echo "Building version $_mcversion, please wait..."
if [[ -v _debug ]]; then
if debug; then
rpmbuild --define="%_topdir $_outputdir" --define="%_libdir /usr/lib" -bb "$_outputdir/SPECS/mediacenter.spec"
else
rpmbuild --quiet --define="%_topdir $_outputdir" --define="%_libdir /usr/lib" -bb "$_outputdir/SPECS/mediacenter.spec" > /dev/null 2>&1
@@ -819,7 +723,6 @@ installJRMC() {
else
echo "Build successful. The RPM file is located at: $_mcrpm"
fi
fi
}
@@ -835,6 +738,23 @@ installJRMC() {
_runCreaterepo() {
debug "Running: ${FUNCNAME[0]}"
# Some additional commands specifically for createrepo (primarily to handle user rights)
if [[ $_createrepo_user != "root" ]]; then
if [[ -d "$_createrepo_webroot/repodata" ]]; then
_createrepo_cmd(){ sudo -u "$_createrepo_user" createrepo -q --update "$@"; }
else
_createrepo_cmd(){ sudo -u "$_createrepo_user" createrepo -q "$@"; }
fi
_cr_mkdir_cmd(){ sudo -u "$_createrepo_user" mkdir -p "$@"; }
_cr_cp_cmd(){ sudo -u "$_createrepo_user" cp -n "$@"; }
else
if [[ -d "$_createrepo_webroot/repodata" ]]; then
_createrepo_cmd(){ createrepo -q --update "$@"; }
else
_createrepo_cmd(){ createrepo -q "$@"; }
fi
fi
_installPackage createrepo_c
local _rpmfile="$1"
@@ -843,7 +763,7 @@ installJRMC() {
if [[ ! -d "$_createrepo_webroot" ]]; then
if ! _cr_mkdir_cmd "$_createrepo_webroot"; then
err "Could not create the createrepo-webroot path!"
err "Make sure that the createrepo-webroot is writeable by createrepo-user"
err "Make sure that the createrepo-webroot is writeable by createrepo-user: $_createrepo_user"
return 1
fi
fi
@@ -851,7 +771,7 @@ installJRMC() {
# Copy built rpms to webroot
if ! _cr_cp_cmd -f "$_rpmfile" "$_createrepo_webroot"; then
err "Could not copy the RPM to the createrepo-webroot path"
err "Make sure that the createrepo-webroot path is writeable by createrepo-user"
err "Make sure that the createrepo-webroot path is writeable by createrepo-user: $_createrepo_user"
return 1
fi
@@ -900,14 +820,14 @@ installJRMC() {
# Allow user to drop an mjr file next to installJRMC
if [[ ! -v _restorefile ]]; then
for _mjr in "$_basedir"/*.mjr; do
for _mjr in "$PWD"/*.mjr; do
[[ $_mjr -nt $_restorefile ]] && _restorefile="$_mjr"
done
fi
# Restore license
if [[ -f "$_restorefile" ]]; then
if ! "mediacenter${_mversion}" /RestoreFromFile "$_restorefile"; then
if ! "mediacenter$_mversion" /RestoreFromFile "$_restorefile"; then
err "Automatic license restore failed"
return 1
fi
@@ -918,7 +838,7 @@ installJRMC() {
#######################################
# Opens ports using the system firewall tool
# Arguments
# Takes one argument, the pre-specified name of the service to enable
# Service to enable (pre-defined)
# Requires:
# ID
# _bash_cmd
@@ -937,11 +857,8 @@ installJRMC() {
_f_ports=("52100-52200/tcp" "1900/udp")
_u_ports="52100:52200/tcp|1900/udp"
elif [[ "$1" =~ ^(jriver-x11vnc|jriver-xvnc)$ ]]; then
_f_ports=("$_port/tcp")
_u_ports="$_port/tcp"
else
err "_openFirewall unrecognized service name"
exit 1
_f_ports=("$_port/tcp" "1900/udp")
_u_ports="$_port/tcp|1900/udp"
fi
# Open the ports
@@ -1110,10 +1027,6 @@ installJRMC() {
}
#######################################
# SERVICES
#######################################
#######################################
# Starts and enables (at startup) a JRiver Media Center service
# Arguments:
@@ -1143,8 +1056,8 @@ installJRMC() {
[Install]
WantedBy=graphical.target
EOF"
_systemctl_reload && \
_systemctl_start "$_service_name" && \
_systemctl_enable "$_service_name" && \
_openFirewall "jriver"
}
@@ -1196,7 +1109,6 @@ installJRMC() {
EOF"
_systemctl_reload && \
_systemctl_start "$_service_name" && \
_systemctl_enable "$_service_name" && \
echo "Xvnc running on localhost:$_port" && \
_openFirewall "jriver-xvnc" && \
@@ -1251,7 +1163,6 @@ installJRMC() {
EOF"
_systemctl_reload && \
_systemctl_start "$_service_name" && \
_systemctl_enable "$_service_name" && \
echo "x11vnc running on localhost:$_port" && \
_openFirewall "jriver-x11vnc"
@@ -1271,7 +1182,7 @@ installJRMC() {
[Service]
$_user_specifier
ExecStart=$_basedir/installJRMC --outputdir $_outputdir --createrepo --createrepo-webroot $_createrepo_webroot --createrepo-user $_createrepo_user
ExecStart=$PWD/installJRMC --outputdir $_outputdir --createrepo --createrepo-webroot $_createrepo_webroot --createrepo-user $_createrepo_user
[Install]
WantedBy=default.target
@@ -1290,7 +1201,6 @@ installJRMC() {
EOF"
_systemctl_reload && \
_systemctl_start "$_timer_name" && \
_systemctl_enable "$_timer_name"
}
@@ -1325,7 +1235,7 @@ installJRMC() {
# Uninstall services
echo "Stopping and removing all associated Media Center services"
for _service in "${_available_services[@]}"; do
for _service in $(compgen -A "function" "_service"); do
_servicePrep "$_service"
_systemctl_disable "$_service_name"
_systemctl_disable "$_timer_name"
@@ -1363,78 +1273,4 @@ installJRMC() {
}
_main() {
# Parse input
_parseInput "$@"
# Sanity checks
_sanityChecks
# Set user variables
_setUser
# Build some OS-specific commands based on the selected OS
_buildCommands
# Install MC using package manager
if [[ -v _repoinstall ]]; then
[[ "$ID" =~ ^(fedora|centos)$ ]] && _installPackage rpmfusion-free-release epel-release
_installMCFromRepo
_symlinkCerts
_restoreLicense
_openFirewall "jriver"
fi
# Set version to install/uninstall
_setVersion
# Uninstall and exit
if [[ -v _uninstall ]]; then
_uninstall
exit $?
fi
# Build RPM from source DEB
if [[ -v _rpmbuild ]]; then
_installPackage epel-release
_acquireDeb
_buildRPM
fi
# Run createrepo
if [[ -v _createrepo ]]; then
_runCreaterepo "$_mcrpm"
fi
# Install the rpm
if [[ -v _rpminstall ]]; then
if [[ "$ID" =~ ^(fedora|centos)$ ]]; then
_installPackage rpmfusion-free-release epel-release
_installPackage --noquery "$_mcrpm"
_symlinkCerts
_restoreLicense
_openFirewall "jriver"
fi
fi
# Install services
_setDisplay
for _service in "${_services[@]}"; do
_servicePrep "$_service"
"_service_$_service"
done
# Install containers
for _container in "${_containers[@]}"; do
"_container_$_container"
done
}
}
# Allow this file to be executed directly if not being sourced
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
_basedir=$(dirname "$(readlink -f "$0")")
installJRMC
_main "$@"
fi