This commit is contained in:
2022-01-12 13:42:25 -05:00
parent 06f9934b64
commit c3f6f4d629
2 changed files with 17 additions and 10 deletions

View File

@@ -37,7 +37,7 @@ You can always find the latest supported options by running `installJRMC --help`
--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-type user|system --service-type user|system
Starts services at boot (system) or at user login (user) (Default: boot) Starts services at boot (system) or at 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

View File

@@ -896,17 +896,17 @@ setServiceVars() {
debug "Running: ${FUNCNAME[0]}" debug "Running: ${FUNCNAME[0]}"
declare -g SERVICE_NAME SERVICE_FNAME TIMER_NAME TIMER_FNAME USER_STRING EXEC_USER declare -g SERVICE_NAME SERVICE_FNAME TIMER_NAME TIMER_FNAME USER_STRING EXEC_USER
declare -g SERVICE_TYPE"${SERVICE_TYPE:-system}"
declare service_system_dir="/usr/lib/systemd/system" declare service_system_dir="/usr/lib/systemd/system"
declare service_user_dir="$USER_HOME/.config/systemd/user" declare service_user_dir="$USER_HOME/.config/systemd/user"
declare service_type="${SERVICE_TYPE:-system}"
if [[ "$USER" == "root" && "$service_type" == "user" ]]; then if [[ "$USER" == "root" && "$SERVICE_TYPE" == "user" ]]; then
err "Trying to install user service as root" err "Trying to install user service as root"
err "Use --service-type service and/or execute installJRMC as non-root user" err "Use --service-type service and/or execute installJRMC as non-root user"
return 1 return 1
fi fi
if [[ "$service_type" == "system" ]]; then if [[ "$SERVICE_TYPE" == "system" ]]; then
service_dir="$service_system_dir" service_dir="$service_system_dir"
EXEC_USER="root" EXEC_USER="root"
systemctl_reload_cmd(){ sudo systemctl daemon-reload; } systemctl_reload_cmd(){ sudo systemctl daemon-reload; }
@@ -914,7 +914,7 @@ setServiceVars() {
systemctl_disable_cmd(){ sudo systemctl disable --now "$@"; } systemctl_disable_cmd(){ sudo systemctl disable --now "$@"; }
systemctl_is_enabled_cmd(){ sudo systemctl is-enabled -q "$@"; } systemctl_is_enabled_cmd(){ sudo systemctl is-enabled -q "$@"; }
systemctl_is_active_cmd(){ sudo systemctl is-active -q "$@"; } systemctl_is_active_cmd(){ sudo systemctl is-active -q "$@"; }
elif [[ "$service_type" == "user" ]]; then elif [[ "$SERVICE_TYPE" == "user" ]]; then
service_dir="$service_user_dir" service_dir="$service_user_dir"
EXEC_USER="$USER" EXEC_USER="$USER"
systemctl_reload_cmd(){ systemctl --user daemon-reload; } systemctl_reload_cmd(){ systemctl --user daemon-reload; }
@@ -926,7 +926,7 @@ setServiceVars() {
[[ ! -d "$service_dir" ]] && sudo -u "$EXEC_USER" mkdir -p "$service_dir" [[ ! -d "$service_dir" ]] && sudo -u "$EXEC_USER" mkdir -p "$service_dir"
if [[ "$USER" == "root" || "$service_type" == "user" ]]; then if [[ "$USER" == "root" || "$SERVICE_TYPE" == "user" ]]; then
SERVICE_NAME="${1}.service" SERVICE_NAME="${1}.service"
TIMER_NAME="${1}.timer" TIMER_NAME="${1}.timer"
SERVICE_FNAME="$service_dir/${SERVICE_NAME}" SERVICE_FNAME="$service_dir/${SERVICE_NAME}"
@@ -950,6 +950,8 @@ setServiceVars() {
service_jriver-mediacenter() { service_jriver-mediacenter() {
debug "Running: ${FUNCNAME[0]}" debug "Running: ${FUNCNAME[0]}"
setServiceVars
sudo -u "$EXEC_USER" bash -c "cat <<- EOF > $SERVICE_FNAME sudo -u "$EXEC_USER" bash -c "cat <<- EOF > $SERVICE_FNAME
[Unit] [Unit]
Description=JRiver Media Center $MVERSION Description=JRiver Media Center $MVERSION
@@ -982,6 +984,8 @@ service_jriver-mediacenter() {
service_jriver-mediaserver() { service_jriver-mediaserver() {
debug "Running: ${FUNCNAME[0]}" debug "Running: ${FUNCNAME[0]}"
setServiceVars
service_jriver-mediacenter "/MediaServer" service_jriver-mediacenter "/MediaServer"
} }
@@ -992,6 +996,8 @@ service_jriver-mediaserver() {
service_jriver-xvnc() { service_jriver-xvnc() {
debug "Running: ${FUNCNAME[0]}" debug "Running: ${FUNCNAME[0]}"
setServiceVars
setDisplay
declare start_cmd declare start_cmd
declare port=$(( NEXT_DISPLAYNUM + 5900 )) declare port=$(( NEXT_DISPLAYNUM + 5900 ))
@@ -1036,6 +1042,9 @@ service_jriver-xvnc() {
service_jriver-x11vnc() { service_jriver-x11vnc() {
debug "Running: ${FUNCNAME[0]}" debug "Running: ${FUNCNAME[0]}"
setServiceVars
setDisplay
declare start_cmd declare start_cmd
declare port=$(( DISPLAYNUM + 5900 )) declare port=$(( DISPLAYNUM + 5900 ))
@@ -1091,6 +1100,8 @@ service_jriver-createrepo() {
declare id="${TARGET:-$ID}" declare id="${TARGET:-$ID}"
USER="root" setServiceVars
sudo -u "$EXEC_USER" bash -c "cat <<-EOF > $SERVICE_FNAME sudo -u "$EXEC_USER" bash -c "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
@@ -1499,11 +1510,7 @@ main() {
if [[ "${#SERVICES[@]}" -gt 0 ]]; then if [[ "${#SERVICES[@]}" -gt 0 ]]; then
declare service declare service
setDisplay
for service in "${SERVICES[@]}"; do for service in "${SERVICES[@]}"; do
if ! setServiceVars "$service"; then
continue
fi
if ! "service_$service"; then if ! "service_$service"; then
if [[ $? -eq 127 ]]; then if [[ $? -eq 127 ]]; then
err "Service $service does not exist, check your service name" err "Service $service does not exist, check your service name"