Skip to content
This repository was archived by the owner on Apr 23, 2024. It is now read-only.

Commit d3b757d

Browse files
committed
Fix word splitting issues with cli args
1 parent 2aafc69 commit d3b757d

File tree

4 files changed

+26
-20
lines changed

4 files changed

+26
-20
lines changed
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#!/usr/bin/with-contenv bash
22

3+
IFS="|" read -r -a CLI_OPTIONS <<< "$CLI_OPTIONS_STRING"
4+
35
cd / || exit 1
46

57
# halt startup if no config file is found
68
if [[ -n ${PMM_CONFIG} ]]; then
79
CONFIG_FILE=${PMM_CONFIG}
8-
elif echo "${CLI_OPTIONS}" | grep -qPo '([\s]|^)(--config|-c)([\s])(.+\/[^\/]+)\.(yml|yaml)'; then
9-
CONFIG_FILE=$(echo "${CLI_OPTIONS}" | grep -Po '([\s]|^)(--config|-c)([\s])\K(.+\/[^\/]+)\.(yml|yaml)')
10+
elif echo "${CLI_OPTIONS[@]}" | grep -qPo '([\s]|^)(--config|-c)([\s])(.+\/[^\/]+)\.(yml|yaml)'; then
11+
CONFIG_FILE=$(echo "${CLI_OPTIONS[@]}" | grep -Po '([\s]|^)(--config|-c)([\s])\K(.+\/[^\/]+)\.(yml|yaml)')
1012
else
1113
CONFIG_FILE="/config/config.yml"
1214
fi
@@ -17,12 +19,12 @@ if [[ -n "${CONFIG_FILE}" ]] && [[ ! -e "${CONFIG_FILE}" ]]; then
1719
s6-rc -bad change
1820
fi
1921

20-
if { echo "${CLI_OPTIONS}" | grep -qPo '([\s]|^)(--run|-r)([\s]|$)'; } && { echo "${CLI_OPTIONS}" | grep -qPo '([\s]|^)(--config|-c)([\s])(.+\/[^\/]+)\.(yml|yaml)'; }; then
21-
s6-setuidgid abc python3 /app/pmm/plex_meta_manager.py ${CLI_OPTIONS}
22-
elif echo "${CLI_OPTIONS}" | grep -qPo '([\s]|^)(--run|-r)([\s]|$)'; then
23-
s6-setuidgid abc python3 /app/pmm/plex_meta_manager.py --config "${CONFIG_FILE}" ${CLI_OPTIONS}
24-
elif echo "${CLI_OPTIONS}" | grep -qPo '([\s]|^)(--config|-c)([\s])(.+\/[^\/]+)\.(yml|yaml)'; then
25-
s6-setuidgid abc python3 /app/pmm/plex_meta_manager.py --run ${CLI_OPTIONS}
22+
if { echo "${CLI_OPTIONS[@]}" | grep -qPo '([\s]|^)(--run|-r)([\s]|$)'; } && { echo "${CLI_OPTIONS[@]}" | grep -qPo '([\s]|^)(--config|-c)([\s])(.+\/[^\/]+)\.(yml|yaml)'; }; then
23+
s6-setuidgid abc python3 /app/pmm/plex_meta_manager.py "${CLI_OPTIONS[@]}"
24+
elif echo "${CLI_OPTIONS[@]}" | grep -qPo '([\s]|^)(--run|-r)([\s]|$)'; then
25+
s6-setuidgid abc python3 /app/pmm/plex_meta_manager.py --config "${CONFIG_FILE}" "${CLI_OPTIONS[@]}"
26+
elif echo "${CLI_OPTIONS[@]}" | grep -qPo '([\s]|^)(--config|-c)([\s])(.+\/[^\/]+)\.(yml|yaml)'; then
27+
s6-setuidgid abc python3 /app/pmm/plex_meta_manager.py --run "${CLI_OPTIONS[@]}"
2628
else
27-
s6-setuidgid abc python3 /app/pmm/plex_meta_manager.py --run --config "${CONFIG_FILE}" ${CLI_OPTIONS}
29+
s6-setuidgid abc python3 /app/pmm/plex_meta_manager.py --run --config "${CONFIG_FILE}" "${CLI_OPTIONS[@]}"
2830
fi
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#!/usr/bin/with-contenv bash
22

3+
IFS="|" read -r -a CLI_OPTIONS <<< "$CLI_OPTIONS_STRING"
4+
35
cd / || exit 1
46

57
# halt startup if no config file is found
68
if [[ -n ${PMM_CONFIG} ]]; then
79
CONFIG_FILE=${PMM_CONFIG}
8-
elif echo "${CLI_OPTIONS}" | grep -qPo '([\s]|^)(--config|-c)([\s])(.+\/[^\/]+)\.(yml|yaml)'; then
9-
CONFIG_FILE=$(echo "${CLI_OPTIONS}" | grep -Po '([\s]|^)(--config|-c)([\s])\K(.+\/[^\/]+)\.(yml|yaml)')
10+
elif echo "${CLI_OPTIONS[@]}" | grep -qPo '([\s]|^)(--config|-c)([\s])(.+\/[^\/]+)\.(yml|yaml)'; then
11+
CONFIG_FILE=$(echo "${CLI_OPTIONS[@]}" | grep -Po '([\s]|^)(--config|-c)([\s])\K(.+\/[^\/]+)\.(yml|yaml)')
1012
else
1113
CONFIG_FILE="/config/config.yml"
1214
fi
@@ -16,16 +18,16 @@ if [[ -n "${CONFIG_FILE}" ]] && [[ ! -e "${CONFIG_FILE}" ]]; then
1618
s6-rc -bad change
1719
fi
1820

19-
if { echo "${CLI_OPTIONS}" | grep -qPo '([\s]|^)(--time|-t)([\s])'; } && { echo "${CLI_OPTIONS}" | grep -qPo '([\s]|^)(--config|-c)([\s])(.+\/[^\/]+)\.(yml|yaml)'; }; then
21+
if { echo "${CLI_OPTIONS[@]}" | grep -qPo '([\s]|^)(--time|-t)([\s])'; } && { echo "${CLI_OPTIONS[@]}" | grep -qPo '([\s]|^)(--config|-c)([\s])(.+\/[^\/]+)\.(yml|yaml)'; }; then
2022
exec \
21-
s6-setuidgid abc python3 /app/pmm/plex_meta_manager.py ${CLI_OPTIONS}
22-
elif echo "${CLI_OPTIONS}" | grep -qPo '([\s]|^)(--time|-t)([\s])'; then
23+
s6-setuidgid abc python3 /app/pmm/plex_meta_manager.py "${CLI_OPTIONS[@]}"
24+
elif echo "${CLI_OPTIONS[@]}" | grep -qPo '([\s]|^)(--time|-t)([\s])'; then
2325
exec \
24-
s6-setuidgid abc python3 /app/pmm/plex_meta_manager.py --config "${CONFIG_FILE}" ${CLI_OPTIONS}
25-
elif echo "${CLI_OPTIONS}" | grep -qPo '([\s]|^)(--config|-c)([\s])(.+\/[^\/]+)\.(yml|yaml)'; then
26+
s6-setuidgid abc python3 /app/pmm/plex_meta_manager.py --config "${CONFIG_FILE}" "${CLI_OPTIONS[@]}"
27+
elif echo "${CLI_OPTIONS[@]}" | grep -qPo '([\s]|^)(--config|-c)([\s])(.+\/[^\/]+)\.(yml|yaml)'; then
2628
exec \
27-
s6-setuidgid abc python3 /app/pmm/plex_meta_manager.py --time "${PMM_TIME:-03:00}" ${CLI_OPTIONS}
29+
s6-setuidgid abc python3 /app/pmm/plex_meta_manager.py --time "${PMM_TIME:-03:00}" "${CLI_OPTIONS[@]}"
2830
else
2931
exec \
30-
s6-setuidgid abc python3 /app/pmm/plex_meta_manager.py --config "${CONFIG_FILE}" --time "${PMM_TIME:-03:00}" ${CLI_OPTIONS}
32+
s6-setuidgid abc python3 /app/pmm/plex_meta_manager.py --config "${CONFIG_FILE}" --time "${PMM_TIME:-03:00}" "${CLI_OPTIONS[@]}"
3133
fi

root/init-hook

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/with-contenv bash
22

3-
if [[ $(tr "[:upper:]" "[:lower:]" <<<"${PMM_RUN}") = "true" ]] || echo "${CLI_OPTIONS}" | grep -qPo '([\s]|^)(--run|-r)([\s]|$)'; then
3+
IFS="|" read -r -a CLI_OPTIONS <<< "$CLI_OPTIONS_STRING"
4+
5+
if [[ $(tr "[:upper:]" "[:lower:]" <<<"${PMM_RUN}") = "true" ]] || echo "${CLI_OPTIONS[@]}" | grep -qPo '([\s]|^)(--run|-r)([\s]|$)'; then
46
rm -rf /etc/s6-overlay/s6-rc.d/svc-pmm
57
rm -rf /etc/s6-overlay/s6-rc.d/user/contents.d/svc-pmm
68
rm -rf /etc/s6-overlay/s6-rc.d/init-config-end/dependencies.d/init-pmm-config

root/init-pmm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
if [ "${1:0:1}" = '-' ]; then
4-
export CLI_OPTIONS="$@"
4+
export CLI_OPTIONS_STRING=$(printf "%s|" "$@")
55
set --
66
fi
77
exec /init "$@"

0 commit comments

Comments
 (0)