Skip to content

Commit d87e0b8

Browse files
committed
added variable exports for plex command calls
1 parent bb19441 commit d87e0b8

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

bin-available/plex-command-caller.zsh

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ function main()
55
local -r call_name="${1}"
66
local -ra call_opts=("${@:2}")
77
local -r call_user='plex'
8-
local -r dflt_path='/usr/lib/plexmediaserver'
8+
local -r vars_path='/var/lib/plexmediaserver'
9+
local -r libs_path='/usr/lib/plexmediaserver'
910
local -r call_path="$(
1011
command -v "${call_name}" || \
11-
printf -- '%s/%s\n' "${dflt_path}" "${call_name}"
12+
printf -- '%s/%s\n' "${libs_path}" "${call_name}"
1213
)"
1314
local -r sudo_text='Please enter the %p user password to run command as the "%U" user: '
1415

@@ -18,7 +19,7 @@ function main()
1819
"$(printf -- '"%s" ' "${(@v)call_opts}")"
1920

2021
if [[ ! -x "${call_path}" ]]; then
21-
printf -- '!! FAIL: Command "%s" not found in PATH or default directory of "%s"!\n' "${call_name}" "${dflt_path}" >&2
22+
printf -- '!! FAIL: Command "%s" not found in PATH or default directory of "%s"!\n' "${call_name}" "${libs_path}" >&2
2223
return 1
2324
fi
2425

@@ -27,7 +28,22 @@ function main()
2728
return 1
2829
fi
2930

30-
sudo --login --user="${call_user}" --prompt="${sudo_text}" -- "${call_path}" "${(@v)call_opts}"
31+
export LD_LIBRARY_PATH="${libs_path}"
32+
export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR="${vars_path}/Library/Application Support"
33+
export PLEX_MEDIA_SERVER_HOME="${libs_path}"
34+
export PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS="$(lscpu | grep '^Core' | grep -oE '[0-9]+$')"
35+
export PLEX_MEDIA_SERVER_INFO_VENDOR="$(grep '^NAME=' /etc/os-release | awk -F= '{print $2}' | tr -d \")";
36+
export PLEX_MEDIA_SERVER_INFO_DEVICE="PC";
37+
export PLEX_MEDIA_SERVER_INFO_MODEL="$(uname -m)";
38+
export PLEX_MEDIA_SERVER_INFO_PLATFORM_VERSION="$(grep '^VERSION=' /etc/os-release | awk -F= '{print $2}' | tr -d \")";
39+
40+
sudo \
41+
--login \
42+
--user="${call_user}" \
43+
--preserve-env='LD_LIBRARY_PATH,PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR,PLEX_MEDIA_SERVER_HOME,PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS,PLEX_MEDIA_SERVER_INFO_VENDOR,PLEX_MEDIA_SERVER_INFO_DEVICE,PLEX_MEDIA_SERVER_INFO_MODEL,PLEX_MEDIA_SERVER_INFO_PLATFORM_VERSION' \
44+
--prompt="${sudo_text}" \
45+
-- \
46+
"${call_path}" "${(@v)call_opts}"
3147
}
3248

3349
main "${@}"

0 commit comments

Comments
 (0)