Handle sudo gracefully

This commit is contained in:
2022-01-14 10:17:20 -05:00
parent 1c429d1129
commit a0428bbe80
2 changed files with 28 additions and 26 deletions

View File

@@ -1,11 +1,11 @@
# installJRMC # installJRMC
This program will install [JRiver Media Center](https://www.jriver.com/) and associated helper services on most major distros. This program will install [JRiver Media Center](https://www.jriver.com/) (JRMC) and associated helper services on most major distros.
## README ## README
1. This script will not point major upgrades to your old library. You should **first perform a library backup**, install the new major version, and then restore the library backup in the new version. 1. This script will not point major upgrades to your old library. You should **first perform a library backup**, install the new major version, and then restore the library backup in the new version.
2. Typically `installJRMC` should be **executed as your normal user** (i.e. don't run it with `sudo`). Services are installed for the user that executes the script so do not execute as root unless you want to install system-level services. Doing so may lead to permissions issues. `installJRMC` will prompt you for your `sudo` password as necessary to install dependencies and services. 2. Typically, `installJRMC` should be **executed as your normal user** (i.e. don't run it with `sudo`) so services can be installed for the current user. `installJRMC` will prompt you for your `sudo` password as necessary to install dependencies and services.
## Executing ## Executing
@@ -21,13 +21,13 @@ You can always find the latest supported options by running `installJRMC --help`
--install, -i repo|local --install, -i repo|local
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
local: Build and install MC package locally local: Build and install MC package locally
--build=[suse|fedora|centos] --build[=suse|fedora|centos]
Build RPM from source DEB but do not install Build RPM from source DEB but do not install
Optionally specify cross-build target (ex. --build=suse, note the '=') Optionally, specify a target distro for cross-building (ex. --build=suse, note the '=')
--compat --compat
Build/install MC without minimum library specifiers Build/install MC without minimum library specifiers
--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.100"
--outputdir PATH --outputdir PATH
Generate rpmbuild output in this PATH (Default: ./output) Generate rpmbuild output in this PATH (Default: ./output)
--restorefile RESTOREFILE --restorefile RESTOREFILE
@@ -40,8 +40,9 @@ You can always find the latest supported options by running `installJRMC --help`
Starts services at boot (system) or user login (user) (Default: system) Starts services at boot (system) or user login (user) (Default: system)
--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[=suse|fedora|centos]
Build rpm, copy to webroot, and run createrepo. Build rpm, copy to webroot, and run createrepo.
Optionally, specify a target distro for non-native repo (ex. --createrepo=fedora, note the '=')
--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
@@ -100,19 +101,19 @@ It is possible to install multiple services at one time using multiple `--servic
* `installJRMC` * `installJRMC`
Install the latest version of JRiver Media Center from the repository. Install the latest version of MC from the best available repository.
* `installJRMC --install repo --service jriver-mediaserver` * `installJRMC --install repo --service jriver-mediacenter --service-type user`
Install JRiver Media Center from the repository and starts/enables the /MediaServer service. Install MC from the repository and start/enable `jriver-mediacenter.service` as a user service.
* `installJRMC --install rpm --restorefile /path/to/license.mjr --mcversion 28.0.87` * `installJRMC --install local --compat --restorefile /path/to/license.mjr --mcversion 28.0.100`
Build JRiver Media Center version 28.0.87 RPM from the source DEB, installs it (RPM distros only), and activates it using the specified .mjr license file. Build and install a MC version 28.0.100 comptability RPM locally and activate it using the `/path/to/license`.mjr
* `installJRMC --createrepo --createrepo-webroot /srv/jriver/repo --createrepo-user www-user` * `installJRMC --createrepo --createrepo-webroot /srv/jriver/repo --createrepo-user www-user`
Build the RPM, moves it to the webroot, and runs createrepo as `www-user`. Build the RPM locally (specify cross-build target), move it to the webroot, and run createrepo as `www-user`.
* `installJRMC --service jriver-createrepo --createrepo-webroot /srv/jriver/repo --createrepo-user www-user` * `installJRMC --service jriver-createrepo --createrepo-webroot /srv/jriver/repo --createrepo-user www-user`
@@ -120,19 +121,19 @@ It is possible to install multiple services at one time using multiple `--servic
* `installJRMC --install repo --service jriver-x11vnc --service jriver-mediacenter --vncpass "letmein"` * `installJRMC --install repo --service jriver-x11vnc --service jriver-mediacenter --vncpass "letmein"`
Install services to share the existing local desktop via VNC and automatically run Media Center on startup. Install services to share the existing local desktop via VNC and automatically run MC on startup.
* `installJRMC --install repo --service jriver-xvnc --display ":2"` * `installJRMC --install repo --service jriver-xvnc --display ":2"`
Install an Xvnc server on display ':2' that starts Media Center. Install an Xvnc server on display ':2' that starts MC.
* `installJRMC --install deb --compat` * `installJRMC --install deb --compat`
Install a more widely-compatible version of MC on deb-based distros. Install a more widely-compatible version of that latest MC on deb-based distros.
* `installJRMC --uninstall` * `installJRMC --uninstall`
Uninstall JRiver Media Center and its associated services and firewall rules. This will **not** remove your media, media library/database, or automated library backup folder. Uninstall MC and its associated services and firewall rules. This will **not** remove your media, media library/database, or automated library backup folder.
## Additional Info ## Additional Info

View File

@@ -22,7 +22,7 @@ shopt -s extglob
declare -g SCRIPTVERSION="1.0b6" declare -g SCRIPTVERSION="1.0b6"
declare -g OUTPUTDIR="$PWD/output" declare -g OUTPUTDIR="$PWD/output"
declare -g CREATEREPO_WEBROOT="/var/www/jriver" declare -g CREATEREPO_WEBROOT="/var/www/jriver"
declare -g USER; USER="${USER:-$(id -un)}" declare -g USER="${SUDO_USER:-$USER}"
printHelp() { printHelp() {
debug "Running: ${FUNCNAME[0]}" debug "Running: ${FUNCNAME[0]}"
@@ -37,13 +37,13 @@ printHelp() {
--install, -i repo|local --install, -i repo|local
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
local: Build and install MC package locally local: Build and install MC package locally
--build=[suse|fedora|centos] --build[=suse|fedora|centos]
Build RPM from source DEB but do not install Build RPM from source DEB but do not install
Optionally specify cross-build target (ex. --build=suse, note the '=') Optionally, specify a target distro for cross-building (ex. --build=suse, note the '=')
--compat --compat
Build/install MC locally without minimum library specifiers Build/install MC locally without minimum library specifiers
--mcversion VERSION --mcversion VERSION
Specify the MC version, ex. "28.0.94" (Default: latest) Specify the MC version, ex. "28.0.100" (Default: latest)
--outputdir PATH --outputdir PATH
Generate rpmbuild output in this directory (Default: ./output) Generate rpmbuild output in this directory (Default: ./output)
--restorefile RESTOREFILE --restorefile RESTOREFILE
@@ -56,8 +56,9 @@ printHelp() {
Starts services at boot (system) or at user login (user) (Default: boot) Starts services at boot (system) or at user login (user) (Default: boot)
--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[=suse|fedora|centos]
Build rpm, copy to webroot, and run createrepo. Use in conjunction with --build=TARGET for crossbuilding repos Build rpm, copy to webroot, and run createrepo. Use in conjunction with --build=TARGET for crossbuilding repos
Optionally, specify a target distro for non-native repo (ex. --createrepo=fedora, note the '=')
--createrepo-webroot PATH --createrepo-webroot PATH
Specify the webroot directory to install the repo (Default: /var/www/jriver) Specify the webroot directory to install the repo (Default: /var/www/jriver)
--createrepo-user USER --createrepo-user USER
@@ -173,7 +174,7 @@ parseInput() {
fi fi
long_opts="install:,build::,outputdir:,mcversion:,restorefile:,betapass:," long_opts="install:,build::,outputdir:,mcversion:,restorefile:,betapass:,"
long_opts+="service-type:,service:,version,debug,help,uninstall,createrepo," long_opts+="service-type:,service:,version,debug,help,uninstall,createrepo::,"
long_opts+="createrepo-webroot:,createrepo-user:,vncpass:,display:,container:,tests,compat" long_opts+="createrepo-webroot:,createrepo-user:,vncpass:,display:,container:,tests,compat"
short_opts="+i:vb::dhus:c:" short_opts="+i:vb::dhus:c:"
@@ -218,6 +219,7 @@ parseInput() {
--createrepo) --createrepo)
BUILD_SWITCH=1 BUILD_SWITCH=1
CREATEREPO_SWITCH=1 CREATEREPO_SWITCH=1
shift && TARGET="$1"
;; ;;
--createrepo-webroot) --createrepo-webroot)
shift && CREATEREPO_WEBROOT="$1" shift && CREATEREPO_WEBROOT="$1"
@@ -448,7 +450,7 @@ installMCFromRepo() {
exit 1 exit 1
fi fi
echo "Installing JRiver Media Center using your package manager" echo "Installing JRiver Media Center using package manager"
pkg_install_cmd="installPackage --skip-check-installed --nogpgcheck $MCPKG" pkg_install_cmd="installPackage --skip-check-installed --nogpgcheck $MCPKG"
debug "$pkg_install_cmd" || pkg_install_cmd+=" &>/dev/null" debug "$pkg_install_cmd" || pkg_install_cmd+=" &>/dev/null"
eval "$pkg_install_cmd" eval "$pkg_install_cmd"
@@ -945,7 +947,7 @@ setDisplay() {
####################################### #######################################
# Create associated service variables based on service name # Create associated service variables based on service name
# Arguments # Arguments
# Pre-defined service to enable # Pre-defined service name
####################################### #######################################
setServiceVars() { setServiceVars() {
debug "Running: ${FUNCNAME[0]}" debug "Running: ${FUNCNAME[0]}"
@@ -1150,7 +1152,7 @@ service_jriver-x11vnc() {
service_jriver-createrepo() { service_jriver-createrepo() {
debug "Running: ${FUNCNAME[0]}" debug "Running: ${FUNCNAME[0]}"
if [[ "$USER" != "$CREATEREPO_USER" ]]; then if [[ "$CREATEREPO_USER" != "$USER" ]]; then
USER="root" SERVICE_TYPE="system" setServiceVars "${FUNCNAME[0]##*_}" USER="root" SERVICE_TYPE="system" setServiceVars "${FUNCNAME[0]##*_}"
else else
setServiceVars "${FUNCNAME[0]##*_}" setServiceVars "${FUNCNAME[0]##*_}"
@@ -1415,7 +1417,6 @@ uninstall() {
if eval "$mc_pkg_rm_cmd"; then if eval "$mc_pkg_rm_cmd"; 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"
echo "To remove your rpmbuild output files, run: rm -rf $OUTPUTDIR"
elif [[ $? -eq 100 ]]; then elif [[ $? -eq 100 ]]; then
err "JRiver Media Center package '$MCPKG' is not present" err "JRiver Media Center package '$MCPKG' is not present"
err "and was not uninstalled" err "and was not uninstalled"