Skip to content

Fix compatibility with POSIX shell in SRM (ash) #5570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions mk/spksrc.service.installer.dsm5
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ if [ -r "${SVC_SETUP}" ]; then
fi


# Reload wizard variables stored by postinst
call_func "reload_inst_variables"
# Load (wizard) variables stored by postinst
call_func "load_variables_from_file" ${INST_VARIABLES}

# init variables either reloaded, from package or from wizard
# init variables either from ${INST_VARIABLES}, from package or from wizard
call_func "initialize_variables"


Expand Down
6 changes: 3 additions & 3 deletions mk/spksrc.service.installer.dsm6
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ if [ -r "${SVC_SETUP}" ]; then
fi


# Reload wizard variables stored by postinst
call_func "reload_inst_variables"
# Load (wizard) variables stored by postinst
call_func "load_variables_from_file" ${INST_VARIABLES}

# init variables either reloaded, from package or from wizard
# init variables either from ${INST_VARIABLES}, from package or from wizard
call_func "initialize_variables"


Expand Down
7 changes: 4 additions & 3 deletions mk/spksrc.service.installer.dsm7
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ if [ -r "${SVC_SETUP}" ]; then
fi


# Reload wizard variables stored by postinst
call_func "reload_inst_variables"
# Load (wizard) variables stored by postinst
call_func "load_variables_from_file" ${INST_VARIABLES}

# init variables either reloaded, from package or from wizard
# init variables either from ${INST_VARIABLES}, from package or from wizard
call_func "initialize_variables"


### Functions library

#
Expand Down
29 changes: 17 additions & 12 deletions mk/spksrc.service.installer.functions
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
### common installer functions and variables for synocommunity generic service installer
#
# functions are common for all DSM versions
#
# The script must be sh/ash compatible and not use bash syntax.
# SRM and DSM < 6.0 have only the busybox built-in shell an not bash
#

# Tools shortcuts
MV="/bin/mv -f"
RM="/bin/rm -rf"
Expand Down Expand Up @@ -90,18 +93,20 @@ install_python_wheels ()
}


reload_inst_variables ()
# function to read and export variables from a text file
# empty lines and lines starting with # are ignored
# we cannot 'source' the file to load the variables, when values have special characters like <, >, ...
load_variables_from_file ()
{
# Reload wizard variables stored by postinst
if [ -r "${INST_VARIABLES}" ]; then
# we cannot source the file to reload variables, when values have special characters.
# This works even with following characers (e.g. for passwords): " ' < \ > :space: = $ | ...
while read -r _line; do
_key="$(echo ${_line} | cut --fields=1 --delimiter='=')"
_value="$(echo ${_line} | cut --fields=2- --delimiter='=')"
declare "${_key}=${_value}"
done < ${INST_VARIABLES}
fi
if [ -n "$1" -a -r "$1" ]; then
while read -r _line; do
if [ "$(echo ${_line} | grep -v ^[/s]*#)" != "" ]; then
_key="$(echo ${_line} | cut --fields=1 --delimiter==)"
_value="$(echo ${_line} | cut --fields=2- --delimiter==)"
export "${_key}=${_value}"
fi
done < "$1"
fi
}


Expand Down
6 changes: 3 additions & 3 deletions mk/spksrc.service.start-stop-status
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ call_func ()

start_daemon ()
{
declare -i i=0
i=0
if [ -z "${SVC_QUIET}" ]; then
if [ -z "${SVC_KEEP_LOG}" ]; then
date > ${LOG_FILE}
Expand All @@ -38,9 +38,9 @@ start_daemon ()
fi
fi
call_func "service_prestart"
for service in "${SERVICE_COMMAND[@]}"
printf "%s" "$SERVICE_COMMAND" | while read -r service || [ -n "$service" ]
do
let i=i+1
i=$((i + 1))
if [ -z "${SVC_QUIET}" ]; then
echo "Starting ${DNAME} command ${service}" >> ${LOG_FILE}
fi
Expand Down
4 changes: 2 additions & 2 deletions spk/deluge/src/service-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ SVC_WRITE_PID=yes
DELUGEWEB_DAEMON="${DELUGEWEB} -c ${CFG_PATH} ${DELUGE_ARGS} -l ${DELUGEWEB_LOG} -L info --logrotate -P ${DELUGEWEB_PID} -d"
DELUGED_DAEMON="${DELUGED} -c ${CFG_PATH} ${DELUGE_ARGS} -l ${DELUGED_LOG} -L info --logrotate -P ${DELUGED_PID} -d"
#
SERVICE_COMMAND[0]="${DELUGED_DAEMON}"
SERVICE_COMMAND[1]="${DELUGEWEB_DAEMON}"

SERVICE_COMMAND=$(printf "${DELUGED_DAEMON}\n${DELUGEWEB_DAEMON}")

if [ "${SYNOPKG_DSM_VERSION_MAJOR}" -ge 7 ]; then
GROUP="synocommunity"
Expand Down