Try new eval method

This commit is contained in:
2022-01-07 17:06:06 -05:00
parent a232119b8d
commit c63ae42a5f
2 changed files with 189 additions and 234 deletions

View File

@@ -22,9 +22,9 @@ You can always find the latest supported options by running `installJRMC --help`
repo: Install MC from repository, future updates will be handled by the system package manager repo: Install MC from repository, future updates will be handled by the system package manager
rpm: Build and install MC locally (RPM-based OSes only) rpm: Build and install MC locally (RPM-based OSes only)
--build --build
Build RPM from source DEB (no installation) Build RPM from source DEB but do not install
--build-suse --target opensuse|fedora|centos
Override OS detection and build SUSE RPM Crossbuild RPM for target distro
--mcversion VERSION --mcversion VERSION
Build or install a specific MC version, ex. "28.0.25" Build or install a specific MC version, ex. "28.0.25"
--outputdir PATH --outputdir PATH
@@ -35,20 +35,18 @@ You can always find the latest supported options by running `installJRMC --help`
Enter beta team password for access to beta builds Enter beta team password for access to beta builds
--service, -s SERVICE --service, -s SERVICE
See SERVICES section below for the list of services to deploy See SERVICES section below for the list of services to deploy
--service-user USER --service-user USER
Install systemd services and containers for user USER (Default: executing user) Install systemd services and containers for user USER (Default: executing user)
--container, -c CONTAINER (TODO: Under construction) --container, -c CONTAINER (TODO: Under construction)
See CONTAINERS section below for a list of containers to deploy See CONTAINERS section below for a list of containers to deploy
--createrepo --createrepo
Build rpm, copy to webroot, and run createrepo Build rpm, copy to webroot, and run createrepo.
--createrepo-suse --createrepo-webroot PATH
Override OS detection and run --createrepo with SUSE RPM
--createrepo-webroot PATH
The webroot directory to install the repo (Default: /var/www/jriver/) The webroot directory to install the repo (Default: /var/www/jriver/)
--createrepo-user USER --createrepo-user USER
The web server user (Default: current user) The web server user (Default: current user)
--compat --compat
Build/install RPM without minimum version specifiers Build/install RPM without minimum library specifiers.
--version, -v --version, -v
Print this script version and exit Print this script version and exit
--debug, -d --debug, -d
@@ -74,11 +72,9 @@ jriver-x11vnc
jriver-xvnc jriver-xvnc
Enable and start a new Xvnc session running JRiver Media Center Enable and start a new Xvnc session running JRiver Media Center
--vncpass PASSWORD --vncpass PASSWORD
Set vnc password for x11vnc/Xvnc access. If no password is set, the script Set vnc password for x11vnc/Xvnc access. If no password is set, the script will either use existing password stored in ~/.vnc/jrmc_passwd or use no password
will either use existing password stored in ~/.vnc/jrmc_passwd or use no password
--display DISPLAY --display DISPLAY
Display to start x11vnc/Xvnc (Default: The current display (x11vnc) or the Manually specify display to use for x11vnc/Xvnc (ex. )
current display incremented by 1 (Xvnc))
jriver-createrepo jriver-createrepo
Install hourly service to build latest MC RPM and run createrepo Install hourly service to build latest MC RPM and run createrepo
``` ```

View File

@@ -1,12 +1,12 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# This script will install JRiver Media Center and associated services # This script will install JRiver Media Center and associated services
# on Fedora, CentOS, Debian, and Ubuntu # on Fedora, CentOS, Debian, and Ubuntu
#
# Copyright (c) 2021 Bryan C. Roessler # Copyright (c) 2021 Bryan C. Roessler
# This software is released under the Apache License. # This software is released under the Apache License.
# https://www.apache.org/licenses/LICENSE-2.0 # https://www.apache.org/licenses/LICENSE-2.0
# #
# Use installJRMC --help to see available options or # See installJRMC --help or printHelp() below
# read printHelp() below.
# #
# TODO # TODO
# 1. Raspberry Pi OS support # 1. Raspberry Pi OS support
@@ -15,8 +15,7 @@
# 4. Tests # 4. Tests
# #
# BUGS # BUGS
# 1. SUSE probably broken # 1. No createrepo on Mint
# 2. No createrepo on Mint
shopt -s extglob shopt -s extglob
@@ -42,10 +41,12 @@ printHelp() {
--install, -i repo|rpm --install, -i repo|rpm
repo: Install MC from repository, updates are handled by the system package manager repo: Install MC from repository, updates are handled by the system package manager
rpm: Build and install RPM locally (RPM-based distros only) rpm: Build and install RPM locally (RPM-based distros only)
--build [TARGET DISTRO] --build
Build RPM from source DEB but do not install. Optional parameter allows cross-building RPMs (ex. 'suse', 'fedora', 'centos'). Build RPM from source DEB but do not install. Optional TARGET parameter enables RPM crossbuilding (ex. 'opensuse', 'fedora', 'centos')
--target opensuse|fedora|centos
Cross-build RPM or createrepo for target distro
--mcversion VERSION --mcversion VERSION
Specify the MC version, ex. "28.0.25" (Default: latest version) Specify the MC version, ex. "28.0.94" (Default: latest)
--outputdir PATH --outputdir PATH
Generate rpmbuild output in this directory (Default: $PWD/output) Generate rpmbuild output in this directory (Default: $PWD/output)
--restorefile RESTOREFILE --restorefile RESTOREFILE
@@ -59,15 +60,13 @@ printHelp() {
--container, -c CONTAINER (TODO: Under construction) --container, -c CONTAINER (TODO: Under construction)
See CONTAINERS section below for a list of possible services to install See CONTAINERS section below for a list of possible services to install
--createrepo --createrepo
Build rpm, copy to webroot, and run createrepo Build rpm, copy to webroot, and run createrepo. Use in conjunction with --build=TARGET for crossbuilding repos
--createrepo-webroot PATH --createrepo-webroot PATH
The webroot directory to install the repo (Default: /var/www/jriver) The webroot directory to install the repo (Default: /var/www/jriver)
--createrepo-user USER --createrepo-user USER
The web server user (Default: current user) The web server user (Default: current user)
--createrepo-suse
Override OS detection and run --createrepo with SUSE RPM
--compat --compat
Build/install RPM without minimum version specifiers Build/install RPM without minimum library specifiers
--version, -v --version, -v
Print this script version and exit Print this script version and exit
--debug, -d --debug, -d
@@ -107,8 +106,8 @@ printHelp() {
init() { init() {
debug "Running: ${FUNCNAME[0]}" debug "Running: ${FUNCNAME[0]}"
declare _version_source declare version_source
declare -g SERVICE_USER CREATEREPO_USER MCVERSION MVERSION declare -g SERVICE_USER CREATEREPO_USER MCVERSION MVERSION MCPKG
getOS getOS
@@ -157,45 +156,40 @@ init() {
# Select MC version to work with # Select MC version to work with
if [[ -v MCVERSION ]]; then if [[ -v MCVERSION ]]; then
_version_source="user input" version_source="user input"
else else
getLatestVersion getLatestVersion
fi fi
[[ ! "$MCVERSION" =~ ([0-9]+.[0-9]+.[0-9]+) ]] && err "Invalid version number" && exit 1 [[ ! "$MCVERSION" =~ ([0-9]+.[0-9]+.[0-9]+) ]] && err "Invalid version number" && exit 1
echo "Using MC version $MCVERSION determined by $_version_source" echo "Using MC version $MCVERSION determined by $version_source"
[[ "$_version_source" != "user input" ]] && echo "To override, use --MCVERSION" [[ "$version_source" != "user input" ]] && echo "To override, use --MCVERSION"
# Extract major version number # Extract major version number
MVERSION="${MCVERSION%%.*}" MVERSION="${MCVERSION%%.*}"
# Set target package name
if [[ "$ID" =~ ^(fedora|centos|opensuse.*)$ ]]; then
MCPKG="MediaCenter"
[[ "$version_source" == "user input" ]] && MCPKG="$MCPKG-$MCVERSION"
elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then
MCPKG="mediacenter$MVERSION"
[[ "$version_source" == "user input" ]] && MCPKG="$MCPKG=$MCVERSION"
fi
# Saving this substituion in case it's needed in the future # Saving this substituion in case it's needed in the future
# _variation="${MCVERSION##*.}" # _variation="${MCVERSION##*.}"
} }
askOk() { # Helpers
declare _response debug() { [[ -v DEBUG && $# -gt 0 ]] && echo "Debug: $*"; }
read -r -p "$* [y/N]" _response
_response=${_response,,}
[[ ! "$_response" =~ ^(yes|y)$ ]] && return 1
return 0
}
debug() {
if [[ -v _debug ]]; then
if [[ $# -gt 0 ]]; then
echo "Debug: $*"
fi
else
return 1
fi
}
err() { echo "Error: $*" >&2; } err() { echo "Error: $*" >&2; }
askOk() {
declare response
read -r -p "$* [y/N]" response
[[ "${response,,}" =~ ^(yes|y)$ ]]
return $?
}
getOS() { getOS() {
debug "Running: ${FUNCNAME[0]}" debug "Running: ${FUNCNAME[0]}"
if [[ -e "/etc/os-release" ]]; then if [[ -e "/etc/os-release" ]]; then
@@ -232,11 +226,11 @@ parseInput() {
debug "Running: ${FUNCNAME[0]}" debug "Running: ${FUNCNAME[0]}"
if [[ $# -eq 0 ]] || [[ $# -eq 1 && "$1" =~ ^(--debug|-d)$ ]]; then if [[ $# -eq 0 ]] || [[ $# -eq 1 && "$1" =~ ^(--debug|-d)$ ]]; then
debug "No options passed, defaulting to repo installation method" echo "No options passed, defaulting to repo installation method"
INSTALL_TYPE="repo" INSTALL_TYPE="repo"
fi fi
if _input=$(getopt -o +i:vdhus:c: -l install:,build::,outputdir:,mcversion:,restorefile:,betapass:,service-user:,service:,version,debug,help,uninstall,createrepo,createrepo-suse,createrepo-webroot:,createrepo-user:,vncpass:,display:,container:,tests,compat -- "$@"); then if _input=$(getopt -o +i:vdhus:c: -l install:,build,target:,outputdir:,mcversion:,restorefile:,betapass:,service-user:,service:,version,debug,help,uninstall,createrepo,createrepo-webroot:,createrepo-user:,vncpass:,display:,container:,tests,compat -- "$@"); then
eval set -- "$_input" eval set -- "$_input"
while true; do while true; do
case "$1" in case "$1" in
@@ -253,7 +247,9 @@ parseInput() {
;; ;;
--build) --build)
BUILD_SWITCH=true BUILD_SWITCH=true
shift && BUILD_TARGET="$1" ;;
--target)
shift && TARGET="$1"
;; ;;
--outputdir) --outputdir)
shift && OUTPUTDIR="$1" shift && OUTPUTDIR="$1"
@@ -277,11 +273,6 @@ parseInput() {
BUILD_SWITCH=true BUILD_SWITCH=true
CREATEREPO_SWITCH=true CREATEREPO_SWITCH=true
;; ;;
--createrepo-suse)
BUILD_SWITCH=true
BUILD_SUSE_SWITCH=true
CREATEREPO_SWITCH=true
;;
--createrepo-webroot) --createrepo-webroot)
shift && CREATEREPO_WEBROOT="$1" shift && CREATEREPO_WEBROOT="$1"
;; ;;
@@ -307,7 +298,7 @@ parseInput() {
--debug|-d) --debug|-d)
echo "Debugging on" echo "Debugging on"
echo "installJRMC version: $SCRIPTVERSION" echo "installJRMC version: $SCRIPTVERSION"
_debug="true" DEBUG=true
;; ;;
--help|-h) --help|-h)
printHelp && exit $? printHelp && exit $?
@@ -330,13 +321,9 @@ parseInput() {
err "Incorrect options provided" err "Incorrect options provided"
printHelp && exit 1 printHelp && exit 1
fi fi
echo "Build target:"
echo "$BUILD_TARGET"
} }
####################################### #######################################
# Use several methods to determine the latest JRiver MC version # Use several methods to determine the latest JRiver MC version
####################################### #######################################
@@ -354,7 +341,7 @@ getLatestVersion() {
#boardurl26="https://yabb.jriver.com/interact/index.php/board,64.0.html" # jessie/stretch #boardurl26="https://yabb.jriver.com/interact/index.php/board,64.0.html" # jessie/stretch
# Peg older versions to prevent ABI and dependency mismatches in automatic mode # Peg older versions to prevent ABI and dependency mismatches in automatic mode
# This can be overriden w/ --MCVERSION # This can be overriden w/ --mcversion
# TODO need user input here # TODO need user input here
# disable version checks for createrepo or rpmbuild (servers) # disable version checks for createrepo or rpmbuild (servers)
# if [[ -v INSTALL_TYPE ]]; then # if [[ -v INSTALL_TYPE ]]; then
@@ -381,7 +368,7 @@ getLatestVersion() {
# fi # fi
# [[ -v MCVERSION ]] && \ # [[ -v MCVERSION ]] && \
# _version_source="compatibility lookup" && \ # version_source="compatibility lookup" && \
# debug "To override, use --MCVERSION" && \ # debug "To override, use --MCVERSION" && \
# return 0 # return 0
# fi # fi
@@ -393,18 +380,18 @@ getLatestVersion() {
buildah run "$CNT" -- bash -c \ buildah run "$CNT" -- bash -c \
"echo 'deb [trusted=no arch=amd64,i386,armhf,arm64] http://dist.jriver.com/latest/mediacenter/ $BASE main' > /etc/apt/sources.list 2>&1" "echo 'deb [trusted=no arch=amd64,i386,armhf,arm64] http://dist.jriver.com/latest/mediacenter/ $BASE main' > /etc/apt/sources.list 2>&1"
buildah run "$CNT" -- bash -c \ buildah run "$CNT" -- bash -c \
"apt-get update --allow-insecure-repositories > /dev/null 2>&1" "apt-get update --allow-insecure-repositories &>/dev/null"
if MCVERSION=$(buildah run "$CNT" -- apt-cache policy mediacenter?? | grep Candidate | awk '{print $2}' | sort -V | tail -n1) \ if MCVERSION=$(buildah run "$CNT" -- apt-cache policy mediacenter?? | grep Candidate | awk '{print $2}' | sort -V | tail -n1) \
&& [[ "$MCVERSION" =~ ([0-9]+.[0-9]+.[0-9]+) ]]; then && [[ "$MCVERSION" =~ ([0-9]+.[0-9]+.[0-9]+) ]]; then
_version_source="containerized package manager" version_source="containerized package manager"
fi fi
buildah rm "$CNT" > /dev/null 2>&1 buildah rm "$CNT" &>/dev/null
return 0 return 0
fi fi
# Scrape from Interact # Scrape from Interact
installPackage --silent wget installPackage --silent wget
if MCVERSION=$(wget -qO- "$BOARDURL" | grep -o "[0-9][0-9]\.[0-9]\.[0-9]\+" | head -n 1); then if MCVERSION=$(wget -qO- "$BOARDURL" | grep -o "[0-9][0-9]\.[0-9]\.[0-9]\+" | head -n 1); then
_version_source="webscrape" version_source="webscrape"
fi fi
if ! [[ -v MCVERSION ]]; then if ! [[ -v MCVERSION ]]; then
@@ -426,30 +413,30 @@ getLatestVersion() {
installPackage() { installPackage() {
debug "Running: ${FUNCNAME[0]}" "$@" debug "Running: ${FUNCNAME[0]}" "$@"
declare -a _pkg_array _install_flags declare -a pkg_array install_flags
declare _pkg _nocheck _silent _return declare pkg nocheck silent _return
if _input=$(getopt -o +s -l nocheck,nogpgcheck,nobest,silent -- "$@"); then if _input=$(getopt -o +s -l nocheck,nogpgcheck,nobest,silent -- "$@"); then
eval set -- "$_input" eval set -- "$_input"
while true; do while true; do
case "$1" in case "$1" in
--nocheck) --nocheck)
_nocheck=true nocheck=true
;; ;;
--nogpgcheck) --nogpgcheck)
if [[ "$ID" =~ ^(fedora|centos)$ ]]; then if [[ "$ID" =~ ^(fedora|centos)$ ]]; then
_install_flags+=("--nogpgcheck") install_flags+=("--nogpgcheck")
elif [[ "$ID" =~ ^opensuse.* ]]; then elif [[ "$ID" =~ ^opensuse.* ]]; then
_install_flags+=("--allow-unsigned-rpm") install_flags+=("--allow-unsigned-rpm")
fi fi
;; ;;
--nobest) --nobest)
if [[ "$ID" =~ ^(fedora|centos)$ ]]; then if [[ "$ID" =~ ^(fedora|centos)$ ]]; then
_install_flags+=("--nobest") install_flags+=("--nobest")
fi fi
;; ;;
--silent|-s) --silent|-s)
_silent=true silent=true
;; ;;
--) --)
shift shift
@@ -472,30 +459,29 @@ installPackage() {
PKG_ALIASES["tigervnc-server"]="tigervnc-standalone-server" PKG_ALIASES["tigervnc-server"]="tigervnc-standalone-server"
fi fi
for _pkg in "$@"; do for pkg in "$@"; do
# Check for alias # Check for alias
if [[ ! -v _nocheck && -v PKG_ALIASES[$_pkg] ]]; then if [[ ! -v nocheck && -v PKG_ALIASES[$pkg] ]]; then
_pkg=${PKG_ALIASES[$_pkg]} pkg=${PKG_ALIASES[$pkg]}
fi fi
# Check if already installed # Check if already installed
if [[ -v _nocheck ]] \ if [[ -v nocheck ]] \
|| ([[ ! -x $(command -v $_pkg) ]] \ || ([[ ! -x $(command -v $pkg) ]] \
&& ! pkg_query "$_pkg" > /dev/null 2>&1); then && ! pkg_query "$pkg" &>/dev/null); then
_pkg_array+=("$_pkg") pkg_array+=("$pkg")
fi fi
done done
# Install packages from package array # Install packages from package array
if [[ ${#_pkg_array[@]} -ge 1 ]]; then if [[ ${#pkg_array[@]} -ge 1 ]]; then
debug "Installing: ${_pkg_array[*]}" debug "pkg_install ${install_flags[*]} ${pkg_array[*]}"
if debug; then if DEBUG; then
debug "pkg_install ${_install_flags[*]} ${_pkg_array[*]}" pkg_install "${install_flags[@]}" "${pkg_array[@]}"
pkg_install "${_install_flags[@]}" "${_pkg_array[@]}"
else else
pkg_install "${_install_flags[@]}" "${_pkg_array[@]}" > /dev/null 2>&1 pkg_install "${install_flags[@]}" "${pkg_array[@]}" &>/dev/null
fi fi
_return=$? _return=$?
[[ $_return -ne 0 && ! -v _silent ]] && err "Failed to install ${_pkg_array[*]}. Attempting to continue..." [[ $_return -ne 0 && ! -v silent ]] && err "Failed to install ${pkg_array[*]}. Attempting to continue..."
return $_return return $_return
fi fi
} }
@@ -517,10 +503,10 @@ addRepo() {
elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then
# MVERSION depends on $BASE unless --MCVERSION is passed # MVERSION depends on $BASE unless --MCVERSION is passed
installPackage --silent wget installPackage --silent wget
wget -q "http://dist.jriver.com/mediacenter@jriver.com.gpg.key" -O- | ifSudo apt-key add - > /dev/null 2>&1 wget -q "http://dist.jriver.com/mediacenter@jriver.com.gpg.key" -O- | ifSudo apt-key add - &>/dev/null
ifSudo wget "http://dist.jriver.com/latest/mediacenter/mediacenter$MVERSION.list" -O "/etc/apt/sources.list.d/mediacenter$MVERSION.list" > /dev/null 2>&1 ifSudo wget "http://dist.jriver.com/latest/mediacenter/mediacenter$MVERSION.list" -O "/etc/apt/sources.list.d/mediacenter$MVERSION.list" &>/dev/null
elif [[ "$ID" =~ ^opensuse.* ]]; then elif [[ "$ID" =~ ^opensuse.* ]]; then
ifSudo zypper addrepo --no-gpgcheck "https://repos.bryanroessler.com/jriver" jriver > /dev/null 2>&1 ifSudo zypper addrepo --no-gpgcheck "https://repos.bryanroessler.com/jriver" jriver &>/dev/null
fi fi
} }
@@ -531,7 +517,7 @@ addRepo() {
installMCFromRepo() { installMCFromRepo() {
debug "Running: ${FUNCNAME[0]}" debug "Running: ${FUNCNAME[0]}"
declare _mcpkg declare MCPKG
echo "Installing JRiver Media Center $MCVERSION from repository." echo "Installing JRiver Media Center $MCVERSION from repository."
echo "Future updates will be handled by your package manager." echo "Future updates will be handled by your package manager."
@@ -545,29 +531,15 @@ installMCFromRepo() {
# Update package list # Update package list
debug "Updating package list" debug "Updating package list"
if ! pkg_update > /dev/null 2>&1; then if ! pkg_update &>/dev/null; then
err "Package update failed!" err "Package update failed!"
exit 1 exit 1
fi fi
if [[ "$ID" =~ ^(fedora|centos|opensuse.*)$ ]]; then if DEBUG; then
_mcpkg="MediaCenter" installPackage --nocheck --nogpgcheck "$MCPKG"
elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then
_mcpkg="mediacenter$MVERSION"
fi
if [[ -v _specific_version ]]; then
if [[ "$ID" =~ ^(fedora|centos|opensuse.*)$ ]]; then
_mcpkg="$_mcpkg-$MCVERSION"
elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then
_mcpkg="$_mcpkg=$MCVERSION"
fi
fi
if debug; then
installPackage --nocheck --nogpgcheck "$_mcpkg"
else else
installPackage --nocheck --nogpgcheck "$_mcpkg" > /dev/null 2>&1 installPackage --nocheck --nogpgcheck "$MCPKG" &>/dev/null
fi fi
return $? return $?
@@ -616,23 +588,13 @@ acquireDeb() {
} }
#######################################
# Translate deb package dependencies for each distro
#######################################
packageTranslations() {
debug "Running: ${FUNCNAME[0]}"
}
####################################### #######################################
# Creates a SPEC file and builds the RPM from the source DEB using rpmbuild # Creates a SPEC file and builds the RPM from the source DEB using rpmbuild
####################################### #######################################
buildRPM() { buildRPM() {
debug "Running: ${FUNCNAME[0]}" debug "Running: ${FUNCNAME[0]}"
declare _ec id i declare id i rpmbuild_cmd
declare -a requires recommends declare -a requires recommends
declare -A dupes declare -A dupes
declare -g MCRPM="$OUTPUTDIR/RPMS/x86_64/MediaCenter-$MCVERSION.x86_64.rpm" declare -g MCRPM="$OUTPUTDIR/RPMS/x86_64/MediaCenter-$MCVERSION.x86_64.rpm"
@@ -645,8 +607,8 @@ buildRPM() {
[[ ! -d "$OUTPUTDIR/SPECS" ]] && mkdir -p "$OUTPUTDIR/SPECS" [[ ! -d "$OUTPUTDIR/SPECS" ]] && mkdir -p "$OUTPUTDIR/SPECS"
id="$ID" # For crossbuilding, use a temp mutable ID # Use --target parameter override
[[ -v BUILD_SUSE_SWITCH ]] && id="opensuse" id="${TARGET:-$ID}"
# Load deb dependencies into array # Load deb dependencies into array
IFS=',' read -ra requires <<< "$(dpkg-deb -f "$DEBFILENAME" Depends)" IFS=',' read -ra requires <<< "$(dpkg-deb -f "$DEBFILENAME" Depends)"
@@ -757,8 +719,8 @@ buildRPM() {
AutoReq: 0 AutoReq: 0
${requires:-} $requires
${recommends:-} $recommends
Provides: mediacenter$MVERSION Provides: mediacenter$MVERSION
@@ -792,14 +754,17 @@ buildRPM() {
# Run rpmbuild # Run rpmbuild
echo "Building version $MCVERSION, please wait..." echo "Building version $MCVERSION, please wait..."
if debug; then rpmbuild_cmd="rpmbuild --define=%_topdir $OUTPUTDIR --define=%_libdir /usr/lib -bb $OUTPUTDIR/SPECS/mediacenter.spec"
rpmbuild --define="%_topdir $OUTPUTDIR" --define="%_libdir /usr/lib" -bb "$OUTPUTDIR/SPECS/mediacenter.spec" DEBUG || rpmbuild_cmd+=" &>/dev/null"
if eval "$rpmbuild_cmd" && [[ -f "$MCRPM" ]] ; then
echo "Build successful. The RPM file is located at: $MCRPM"
else else
rpmbuild --quiet --define="%_topdir $OUTPUTDIR" --define="%_libdir /usr/lib" -bb "$OUTPUTDIR/SPECS/mediacenter.spec" > /dev/null 2>&1 err "Build failed."
# For automation, let's remove the source DEB and reaquire it on next run
# after failure in case it is corrupted or buggy
[[ -f "$DEBFILENAME" ]] && echo "Removing source DEB" && rm -f "$DEBFILENAME"
exit 1
fi fi
_ec=$?
[[ "$_ec" == 0 ]] && echo "Build successful. The RPM file is located at: $MCRPM"
return $_ec
} }
@@ -816,7 +781,7 @@ runCreaterepo() {
# If the webroot does not exist, create it # If the webroot does not exist, create it
if [[ ! -d "$CREATEREPO_WEBROOT" ]]; then if [[ ! -d "$CREATEREPO_WEBROOT" ]]; then
debug "ifSudo -u $CREATEREPO_USER mkdir -p $CREATEREPO_WEBROOT" debug "ifSudo -u $CREATEREPO_USER mkdir -p $CREATEREPO_WEBROOT"
if ! ifSudo -u "$CREATEREPO_USER" mkdir -p "$CREATEREPO_WEBROOT" > /dev/null 2>&1; then if ! ifSudo -u "$CREATEREPO_USER" mkdir -p "$CREATEREPO_WEBROOT" &>/dev/null; then
debug "ifSudo mkdir -p $CREATEREPO_WEBROOT" debug "ifSudo mkdir -p $CREATEREPO_WEBROOT"
if ifSudo mkdir -p "$CREATEREPO_WEBROOT" && \ if ifSudo mkdir -p "$CREATEREPO_WEBROOT" && \
ifSudo chown -R "$CREATEREPO_USER":"$CREATEREPO_USER" "$CREATEREPO_WEBROOT"; then ifSudo chown -R "$CREATEREPO_USER":"$CREATEREPO_USER" "$CREATEREPO_WEBROOT"; then
@@ -831,7 +796,7 @@ runCreaterepo() {
# Copy built rpms to webroot # Copy built rpms to webroot
debug "ifSudo -u $CREATEREPO_USER cp -n -f $MCRPM $CREATEREPO_WEBROOT" debug "ifSudo -u $CREATEREPO_USER cp -n -f $MCRPM $CREATEREPO_WEBROOT"
if ! ifSudo -u "$CREATEREPO_USER" cp -n -f "$MCRPM" "$CREATEREPO_WEBROOT" > /dev/null 2>&1; then if ! ifSudo -u "$CREATEREPO_USER" cp -n -f "$MCRPM" "$CREATEREPO_WEBROOT" &>/dev/null; then
debug "cp_cmd $MCRPM $CREATEREPO_WEBROOT" debug "cp_cmd $MCRPM $CREATEREPO_WEBROOT"
if cp_cmd "$MCRPM" "$CREATEREPO_WEBROOT" && \ if cp_cmd "$MCRPM" "$CREATEREPO_WEBROOT" && \
ifSudo chown -R "$CREATEREPO_USER":"$CREATEREPO_USER" "$CREATEREPO_WEBROOT"; then ifSudo chown -R "$CREATEREPO_USER":"$CREATEREPO_USER" "$CREATEREPO_WEBROOT"; then
@@ -922,14 +887,14 @@ openFirewall() {
if [[ "$ID" =~ ^(fedora|centos|opensuse.*)$ ]]; then if [[ "$ID" =~ ^(fedora|centos|opensuse.*)$ ]]; then
installPackage firewalld installPackage firewalld
if ! firewall_cmd --get-services | grep -q "$1"; then if ! firewall_cmd --get-services | grep -q "$1"; then
firewall_cmd --permanent --new-service="$1" > /dev/null 2>&1 firewall_cmd --permanent --new-service="$1" &>/dev/null
firewall_cmd --permanent --service="$1" --set-description="$1 installed by installJRMC" > /dev/null 2>&1 firewall_cmd --permanent --service="$1" --set-description="$1 installed by installJRMC" &>/dev/null
firewall_cmd --permanent --service="$1" --set-short="$1" > /dev/null 2>&1 firewall_cmd --permanent --service="$1" --set-short="$1" &>/dev/null
for _f_port in "${_f_ports[@]}"; do for _f_port in "${_f_ports[@]}"; do
firewall_cmd --permanent --service="$1" --add-port="$_f_port" > /dev/null 2>&1 firewall_cmd --permanent --service="$1" --add-port="$_f_port" &>/dev/null
done done
firewall_cmd --add-service "$1" --permanent > /dev/null 2>&1 firewall_cmd --add-service "$1" --permanent &>/dev/null
firewall_cmd --reload > /dev/null 2>&1 firewall_cmd --reload &>/dev/null
fi fi
elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then
# Debian ufw package state is broken on fresh installations # Debian ufw package state is broken on fresh installations
@@ -943,7 +908,7 @@ openFirewall() {
EOF" EOF"
fi fi
firewall_cmd app update "$1" firewall_cmd app update "$1"
firewall_cmd allow "$1" > /dev/null 2>&1 firewall_cmd allow "$1" &>/dev/null
fi fi
# shellcheck disable=SC2181 # More concise # shellcheck disable=SC2181 # More concise
@@ -1022,23 +987,15 @@ setVNCPass() {
setDisplay() { setDisplay() {
debug "Running: ${FUNCNAME[0]}" debug "Running: ${FUNCNAME[0]}"
# Check USER_DISPLAY, else DISPLAY, else set to :0 by default declare -g DISPLAY DISPLAYNUM NEXT_DISPLAY NEXT_DISPLAYNUM
if [[ -v USER_DISPLAY ]]; then declare displaynum
_next_display="$USER_DISPLAY"
elif [[ -v DISPLAY ]]; then
USER_DISPLAY="${DISPLAY}"
_displaynum="${USER_DISPLAY#:}" # strip colon
_displaynum="${_displaynum%.*}" # strip suffix
_next_displaynum=$(( _displaynum + 1 ))
_next_display=":$_next_displaynum"
else
USER_DISPLAY=":0"
_next_display=":1"
fi
_displaynum="${USER_DISPLAY#:}" # strip colon # Check USER_DISPLAY, else environment DISPLAY, else set to :0 by default
_displaynum="${_displaynum%.*}" # strip suffix DISPLAY="${USER_DISPLAY:-${DISPLAY:-0}}"
_next_displaynum=$(( _displaynum + 1 )) DISPLAYNUM="${DISPLAY#*:}" # strip prefix
DISPLAYNUM="${DISPLAYNUM%%.*}" # strip suffix
NEXT_DISPLAYNUM=$(( DISPLAYNUM + 1 ))
NEXT_DISPLAY=":$NEXT_DISPLAYNUM"
} }
@@ -1048,18 +1005,20 @@ setDisplay() {
setServiceVars() { setServiceVars() {
debug "Running: ${FUNCNAME[0]}" debug "Running: ${FUNCNAME[0]}"
declare -g SERVICE_FNAME TIMER_FNAME SERVICE_NAME SERVICE_FNAME USER_STRING
if [[ "$SERVICE_USER" == "root" ]]; then if [[ "$SERVICE_USER" == "root" ]]; then
_service_fname="$SERVICEDIR/${1}.service" SERVICE_FNAME="$SERVICEDIR/${1}.service"
_timer_fname="$SERVICEDIR/${1}.timer" TIMER_FNAME="$SERVICEDIR/${1}.timer"
_service_name="${1}.service" SERVICE_NAME="${1}.service"
_timer_name="${1}.timer" TIMER_NAME="${1}.timer"
_user_specifier="" USER_STRING=""
else else
_service_fname="$SERVICEDIR/${1}@.service" SERVICE_FNAME="$SERVICEDIR/${1}@.service"
_timer_fname="$SERVICEDIR/${1}@.timer" TIMER_FNAME="$SERVICEDIR/${1}@.timer"
_service_name="${1}@$SERVICE_USER.service" SERVICE_NAME="${1}@$SERVICE_USER.service"
_timer_name="${1}@$SERVICE_USER.timer" TIMER_NAME="${1}@$SERVICE_USER.timer"
_user_specifier="User=%I" USER_STRING="User=%I"
fi fi
} }
@@ -1072,15 +1031,15 @@ setServiceVars() {
service_jriver-mediacenter() { service_jriver-mediacenter() {
debug "Running: ${FUNCNAME[0]}" debug "Running: ${FUNCNAME[0]}"
bash_cmd "cat <<- EOF > $_service_fname bash_cmd "cat <<- EOF > $SERVICE_FNAME
[Unit] [Unit]
Description=JRiver Media Center $MVERSION Description=JRiver Media Center $MVERSION
After=graphical.target After=graphical.target
[Service] [Service]
$_user_specifier $USER_STRING
Type=simple Type=simple
Environment=DISPLAY=$USER_DISPLAY Environment=DISPLAY=$DISPLAY
Environment=XAUTHORITY=$XAUTHORITY Environment=XAUTHORITY=$XAUTHORITY
ExecStart=/usr/bin/mediacenter$MVERSION $* ExecStart=/usr/bin/mediacenter$MVERSION $*
Restart=always Restart=always
@@ -1093,7 +1052,7 @@ service_jriver-mediacenter() {
EOF" EOF"
systemctl_reload && \ systemctl_reload && \
systemctl_enable "$_service_name" && \ systemctl_enable "$SERVICE_NAME" && \
openFirewall "jriver" openFirewall "jriver"
} }
@@ -1114,29 +1073,30 @@ service_jriver-mediaserver() {
service_jriver-xvnc() { service_jriver-xvnc() {
debug "Running: ${FUNCNAME[0]}" debug "Running: ${FUNCNAME[0]}"
declare start_cmd
declare port=$(( NEXT_DISPLAYNUM + 5900 ))
installPackage tigervnc-server installPackage tigervnc-server
setVNCPass setVNCPass
declare _port=$(( _next_displaynum + 5900 ))
if [[ -v _novncauth ]]; then if [[ -v _novncauth ]]; then
_exec_start_cmd="/usr/bin/vncserver $_next_display -geometry 1440x900 -alwaysshared -name jriver$_next_display -SecurityTypes None -autokill -xstartup /usr/bin/mediacenter$MVERSION" start_cmd="/usr/bin/vncserver $NEXT_DISPLAY -geometry 1440x900 -alwaysshared -name jriver$NEXT_DISPLAY -SecurityTypes None -autokill -xstartup /usr/bin/mediacenter$MVERSION"
else else
_exec_start_cmd="/usr/bin/vncserver $_next_display -geometry 1440x900 -alwaysshared -rfbauth $HOME/.vnc/jrmc_passwd -autokill -xstartup /usr/bin/mediacenter$MVERSION" start_cmd="/usr/bin/vncserver $NEXT_DISPLAY -geometry 1440x900 -alwaysshared -rfbauth $HOME/.vnc/jrmc_passwd -autokill -xstartup /usr/bin/mediacenter$MVERSION"
fi fi
bash_cmd "cat <<- EOF > $_service_fname bash_cmd "cat <<- EOF > $SERVICE_FNAME
[Unit] [Unit]
Description=Remote desktop service (VNC) Description=Remote desktop service (VNC)
After=syslog.target network.target After=syslog.target network.target
[Service] [Service]
Type=simple Type=simple
$_user_specifier $USER_STRING
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill $_next_display > /dev/null 2>&1 || :' ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill $NEXT_DISPLAY &>/dev/null || :'
ExecStart=$_exec_start_cmd ExecStart=$start_cmd
ExecStop=/usr/bin/vncserver -kill $_next_display ExecStop=/usr/bin/vncserver -kill $NEXT_DISPLAY
Restart=always Restart=always
[Install] [Install]
@@ -1144,8 +1104,8 @@ service_jriver-xvnc() {
EOF" EOF"
systemctl_reload && \ systemctl_reload && \
systemctl_enable "$_service_name" && \ systemctl_enable "$SERVICE_NAME" && \
echo "Xvnc running on localhost:$_port" && \ echo "Xvnc running on localhost:$port" && \
openFirewall "jriver-xvnc" && \ openFirewall "jriver-xvnc" && \
openFirewall "jriver" openFirewall "jriver"
} }
@@ -1157,37 +1117,38 @@ service_jriver-xvnc() {
service_jriver-x11vnc() { service_jriver-x11vnc() {
debug "Running: ${FUNCNAME[0]}" debug "Running: ${FUNCNAME[0]}"
declare start_cmd
declare port=$(( DISPLAYNUM + 5900 ))
installPackage x11vnc installPackage x11vnc
setX11VNCPass setX11VNCPass
declare _port=$(( _displaynum + 5900 ))
# Get current desktop resolution # Get current desktop resolution
# TODO: may need to break this out into its own function and get smarter at identifying multi-monitors # TODO: may need to break this out into its own function and get smarter at identifying multi-monitors
_getResolution() { # _getResolution() {
debug "Running: ${FUNCNAME[0]}" # debug "Running: ${FUNCNAME[0]}"
installPackage xorg-x11-utils # installPackage xorg-x11-utils
_res=$(xdpyinfo | grep dimensions | awk '{print $2}') # _res=$(xdpyinfo | grep dimensions | awk '{print $2}')
} # }
_getResolution # _getResolution
if [[ -v _novncauth ]]; then if [[ -v _novncauth ]]; then
_exec_start_cmd="/usr/bin/x11vnc -display $USER_DISPLAY -noscr -geometry $_res -auth guess -forever -bg -nopw" start_cmd="/usr/bin/x11vnc -display $DISPLAY -noscr -auth guess -forever -bg -nopw"
else else
_exec_start_cmd="/usr/bin/x11vnc -display $USER_DISPLAY -noscr -geometry $_res -auth guess -forever -bg -rfbauth $HOME/.vnc/jrmc_passwd" start_cmd="/usr/bin/x11vnc -display $DISPLAY -noscr -auth guess -forever -bg -rfbauth $HOME/.vnc/jrmc_passwd"
fi fi
bash_cmd "cat <<-EOF > $_service_fname bash_cmd "cat <<-EOF > $SERVICE_FNAME
[Unit] [Unit]
Description=x11vnc Description=x11vnc
After=multi.service After=multi.service
[Service] [Service]
$_user_specifier $USER_STRING
Type=forking Type=forking
Environment=DISPLAY=$USER_DISPLAY Environment=DISPLAY=$DISPLAY
ExecStart=$_exec_start_cmd ExecStart=$start_cmd
Restart=always Restart=always
RestartSec=10 RestartSec=10
@@ -1196,8 +1157,8 @@ service_jriver-x11vnc() {
EOF" EOF"
systemctl_reload && \ systemctl_reload && \
systemctl_enable "$_service_name" && \ systemctl_enable "$SERVICE_NAME" && \
echo "x11vnc running on localhost:$_port" && \ echo "x11vnc running on localhost:$port" && \
openFirewall "jriver-x11vnc" openFirewall "jriver-x11vnc"
} }
@@ -1209,19 +1170,21 @@ service_jriver-x11vnc() {
service_jriver-createrepo() { service_jriver-createrepo() {
debug "Running: ${FUNCNAME[0]}" debug "Running: ${FUNCNAME[0]}"
bash_cmd "cat <<-EOF > $_service_fname declare id="${TARGET:-$ID}"
bash_cmd "cat <<-EOF > $SERVICE_FNAME
[Unit] [Unit]
Description=Builds JRiver Media Center RPM file, moves it to the repo dir, and runs createrepo Description=Builds JRiver Media Center RPM file, moves it to the repo dir, and runs createrepo
[Service] [Service]
$_user_specifier $USER_STRING
ExecStart=$PWD/installJRMC --outputdir $OUTPUTDIR --createrepo --createrepo-webroot $CREATEREPO_WEBROOT --createrepo-user $CREATEREPO_USER ExecStart=$PWD/installJRMC --target $id --outputdir $OUTPUTDIR --createrepo --createrepo-webroot $CREATEREPO_WEBROOT --createrepo-user $CREATEREPO_USER
[Install] [Install]
WantedBy=default.target WantedBy=default.target
EOF" EOF"
bash_cmd "cat <<-EOF > $_timer_fname bash_cmd "cat <<-EOF > $TIMER_FNAME
[Unit] [Unit]
Description=Run JRiver MC rpmbuild hourly Description=Run JRiver MC rpmbuild hourly
@@ -1234,7 +1197,7 @@ service_jriver-createrepo() {
EOF" EOF"
systemctl_reload && \ systemctl_reload && \
systemctl_enable "$_timer_name" systemctl_enable "$TIMER_NAME"
} }
@@ -1382,7 +1345,7 @@ service_jriver-createrepo() {
# brc add-pkg --virtual .build-deps wget # brc add-pkg --virtual .build-deps wget
# brc sh -s <<- EOF # brc sh -s <<- EOF
# wget -q "http://dist.jriver.com/mediacenter@jriver.com.gpg.key" -O- | apt-key add - > /dev/null 2>&1 # wget -q "http://dist.jriver.com/mediacenter@jriver.com.gpg.key" -O- | apt-key add - &>/dev/null
# EOF # EOF
# brc wget "http://dist.jriver.com/latest/mediacenter/mediacenter$MVERSION.list" -O "/etc/apt/sources.list.d/mediacenter$MVERSION.list" # brc wget "http://dist.jriver.com/latest/mediacenter/mediacenter$MVERSION.list" -O "/etc/apt/sources.list.d/mediacenter$MVERSION.list"
@@ -1397,22 +1360,24 @@ service_jriver-createrepo() {
uninstall() { uninstall() {
debug "Running: ${FUNCNAME[0]}" debug "Running: ${FUNCNAME[0]}"
declare MCPKG service unit f
if ! askOk "Do you really want to uninstall JRiver Media Center"; then if ! askOk "Do you really want to uninstall JRiver Media Center"; then
echo "Cancelling uninstall..." echo "Cancelling uninstall..."
exit 0 exit 0
fi fi
debug "Stopping and removing all associated Media Center services" debug "Stopping and removing all associated Media Center services"
for _service in $(compgen -A "function" "service"); do for service in $(compgen -A "function" "service"); do
_service="${_service##service_}" service="${service##service_}"
setServiceVars "$_service" setServiceVars "$service"
for unit in "$_service_name" "$_timer_name"; do for unit in "$SERVICE_NAME" "$TIMER_NAME"; do
if systemctl is-active -q "$unit" > /dev/null 2>&1 || systemctl is-enabled -q "$unit" > /dev/null 2>&1; then if systemctl is-active -q "$unit" &>/dev/null || systemctl is-enabled -q "$unit" &>/dev/null; then
debug "Disabling $unit" debug "Disabling $unit"
systemctl_disable "$unit" systemctl_disable "$unit"
fi fi
done done
for f in "$_service_fname" "$_timer_fname"; do for f in "$SERVICE_FNAME" "$TIMER_FNAME"; do
[[ -f "$f" ]] && debug "Removing $f" && rm_cmd "$f" [[ -f "$f" ]] && debug "Removing $f" && rm_cmd "$f"
done done
systemctl_reload systemctl_reload
@@ -1424,7 +1389,7 @@ uninstall() {
[[ -f "/etc/apt/sources.list.d/jriver.list" ]] \ [[ -f "/etc/apt/sources.list.d/jriver.list" ]] \
&& rm_cmd "/etc/apt/sources.list.d/jriver.list" && rm_cmd "/etc/apt/sources.list.d/jriver.list"
if [[ "$ID" =~ ^opensuse.* ]]; then if [[ "$ID" =~ ^opensuse.* ]]; then
ifSudo zypper rr jriver > /dev/null 2>&1 ifSudo zypper rr jriver &>/dev/null
fi fi
debug "Removing firewall rules" debug "Removing firewall rules"
@@ -1437,15 +1402,15 @@ uninstall() {
debug "firewall_cmd --reload" debug "firewall_cmd --reload"
firewall_cmd --reload firewall_cmd --reload
else else
firewall_cmd --permanent --remove-service=jriver > /dev/null 2>&1 firewall_cmd --permanent --remove-service=jriver &>/dev/null
firewall_cmd --permanent --delete-service=jriver > /dev/null 2>&1 firewall_cmd --permanent --delete-service=jriver &>/dev/null
firewall_cmd --reload > /dev/null 2>&1 firewall_cmd --reload &>/dev/null
fi fi
elif [[ -x $(command -v ufw) ]]; then elif [[ -x $(command -v ufw) ]]; then
if [[ -v debug ]]; then if [[ -v debug ]]; then
firewall_cmd delete allow jriver firewall_cmd delete allow jriver
else else
firewall_cmd delete allow jriver > /dev/null 2>&1 firewall_cmd delete allow jriver &>/dev/null
fi fi
[[ -f "/etc/ufw/applications.d/jriver" ]] \ [[ -f "/etc/ufw/applications.d/jriver" ]] \
&& rm_cmd /etc/ufw/applications.d/jriver && rm_cmd /etc/ufw/applications.d/jriver
@@ -1453,16 +1418,16 @@ uninstall() {
debug "Uninstalling Media Center packages" debug "Uninstalling Media Center packages"
if [[ "$ID" =~ ^(fedora|centos|opensuse.*)$ ]]; then if [[ "$ID" =~ ^(fedora|centos|opensuse.*)$ ]]; then
_mcpkg="MediaCenter" MCPKG="MediaCenter"
elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then
_mcpkg="mediacenter$MVERSION" MCPKG="mediacenter$MVERSION"
fi fi
if debug; then if DEBUG; then
debug "pkg_remove $_mcpkg" debug "pkg_remove $MCPKG"
pkg_remove "$_mcpkg" pkg_remove "$MCPKG"
else else
pkg_remove "$_mcpkg" > /dev/null 2>&1 pkg_remove "$MCPKG" &>/dev/null
fi fi
echo "JRiver Media Center has been completely uninstalled." echo "JRiver Media Center has been completely uninstalled."
@@ -1515,13 +1480,7 @@ main() {
if [[ -v BUILD_SWITCH ]]; then if [[ -v BUILD_SWITCH ]]; then
installPackage --silent "wget" "dpkg" "rpm-build" installPackage --silent "wget" "dpkg" "rpm-build"
acquireDeb acquireDeb
if ! buildRPM; then buildRPM
err "Build failed."
# For automation, let's remove the source DEB and reaquire it on next run
# after failure in case it is corrupted or buggy
[[ -f "$DEBFILENAME" ]] && echo "Removing source DEB" && rm -f "$DEBFILENAME"
exit 1
fi
fi fi
# Run createrepo # Run createrepo