Tidying up

This commit is contained in:
2021-11-23 14:03:44 -05:00
parent db64348a9d
commit 28b9d72a2c

View File

@@ -6,21 +6,22 @@
# https://www.apache.org/licenses/LICENSE-2.0
#
# Use installJRMC --help to see available options or
# read printHelpAndExit() below.
# read printHelp() below.
#
# TODO:
# 1. Raspberry Pi OS support
# 2. Interactive installation (ncurses?)
# 3. Additional containerization
shopt -s extglob
_scriptversion="28.0a1"
_scriptversion="1.1.0"
_boardurl="https://yabb.jriver.com/interact/index.php/board,71.0.html" # Media Center 28
_outputdir="$PWD/output"
_createrepo_webroot="/srv/jriver"
_exec_user="$(whoami)"
printHelpAndExit() {
printHelp() {
debug "Running: ${FUNCNAME[0]}"
cat <<- 'EOF'
@@ -88,14 +89,10 @@ printHelpAndExit() {
mediacenter-xvnc
createrepo
EOF
# Exit using passed exit code
[[ ! -v 1 ]] && exit 0 || exit "$1"
}
init() {
debug "Running: ${FUNCNAME[0]}"
getOS
@@ -158,7 +155,13 @@ init() {
}
# HELPERS
err() { echo "Error: $*" >&2; }
askOk() {
local _response
read -r -p "$* [y/N]" _response
_response=${_response,,}
[[ ! "$_response" =~ ^(yes|y)$ ]] && return 1
return 0
}
debug() {
if [[ -v _debug ]]; then
if [[ $# -gt 0 ]]; then
@@ -168,6 +171,20 @@ debug() {
return 1
fi
}
err() { echo "Error: $*" >&2; }
getOS() {
debug "Running: ${FUNCNAME[0]}"
if [[ -e "/etc/os-release" ]]; then
source "/etc/os-release"
else
err "/etc/os-release not found"
err "Your OS is unsupported"
printHelp && exit 1
fi
debug "Platform: $ID $VERSION_ID"
}
ifSudo() {
if [[ "$_exec_user" != "root" ]]; then
sudo "$@"
@@ -175,13 +192,6 @@ ifSudo() {
"$@"
fi
}
askOk() {
local _response
read -r -p "$* [y/N]" _response
_response=${_response,,}
[[ ! "$_response" =~ ^(yes|y)$ ]] && return 1
return 0
}
#######################################
@@ -205,7 +215,7 @@ parseInput() {
if [[ "$_install" == "rpm" ]]; then
if [[ ! "$ID" =~ ^(fedora|centos)$ ]]; then
err "RPM install method not available on $ID"
printHelpAndExit 1
printHelp && exit 1
fi
_build=true
fi
@@ -260,7 +270,7 @@ parseInput() {
_debug="true"
;;
--help|-h)
printHelpAndExit 0
printHelp && exit $?
;;
--uninstall|-u)
_uninstall=true
@@ -274,29 +284,14 @@ parseInput() {
done
else
err "Incorrect options provided"
printHelpAndExit 1
printHelp && exit 1
fi
}
getOS() {
debug "Running: ${FUNCNAME[0]}"
if [[ -e "/etc/os-release" ]]; then
source "/etc/os-release"
else
err "/etc/os-release not found"
err "Your OS is unsupported"
printHelpAndExit 1
fi
debug "Platform: $ID $VERSION_ID"
}
#######################################
# If no MC version is provided, find the latest
# Requires:
# Optional (only required if container method fails):
# _boardurl
#######################################
getLatestVersion() {
@@ -420,7 +415,7 @@ addRepo() {
elif [[ "$ID" =~ ^(debian|ubuntu|linuxmint)$ ]]; then
installPackage wget
wget -q "http://dist.jriver.com/mediacenter@jriver.com.gpg.key" -O- | ifSudo apt-key add - > /dev/null 2>&1
ifSudo wget "http://dist.jriver.com/latest/mediacenter/mediacenter$_mversion.list" -O "/etc/apt/sources.list.d/mediacenter$_mversion.list"
ifSudo wget "http://dist.jriver.com/latest/mediacenter/mediacenter$_mversion.list" -O "/etc/apt/sources.list.d/mediacenter$_mversion.list" > /dev/null 2>&1
fi
}
@@ -743,7 +738,7 @@ restoreLicense() {
local _mjr
# Allow user to drop an mjr file next to installJRMC
# Allow user to put the mjr file next to installJRMC
if [[ ! -v _restorefile ]]; then
for _mjr in "$PWD"/*.mjr; do
[[ $_mjr -nt $_restorefile ]] && _restorefile="$_mjr"
@@ -1245,8 +1240,15 @@ uninstall() {
}
main() {
tests() {
# To test on Mint: sudo apt-get install -y spice-vdagent ca-certificates git
:
}
main() {
debug "Running: ${FUNCNAME[0]}"
init "$@"