Skip to content

Commit

Permalink
use resource linker for DSM6 (#4578)
Browse files Browse the repository at this point in the history
* migrate SPK_LINKS to SPK_USR_LOCAL_LINKS
- SPK_LINKS is not supported anymore, use SPK_USR_LOCAL_LINKS and/or SPK_COMMANDS
- adjust all packages with former SPK_LINKS (beets, borgbackup, rdiff-backup)
* Use resource definitions for DSM6
- resource workers for ports/links/shares are supported from DSM>=6.0
- keep the /usr/local/{package} link in DSM 6 for now, as not all dependent packages are redesigned
* rename spksrc.service.installer to spksrc.service.installer.dsm6
- rename and remove obsolete DSM 5 code

Co-authored-by: Sebastian Schmidt <[email protected]>
  • Loading branch information
hgy59 and publicarray authored Apr 30, 2021
1 parent a0c5692 commit 35e4364
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 110 deletions.
8 changes: 4 additions & 4 deletions mk/spksrc.service.create_links
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ service_create_links ()
fi
done

for item in ${SPK_LINKS}
for item in ${SPK_USR_LOCAL_LINKS}
do
_link=$(echo ${item} | sed "s/:.*//g")
_target=$(echo ${item} | sed "s/.*://g")
_link=/usr/local/$(echo ${item} | sed "s/:.*//g")/${_target##*/}
if [ -e "${SYNOPKG_PKGDEST}/${_target}" ]; then
mkdir -p "$(dirname ${_link})"
echo "create link: ${_link} -> ${SYNOPKG_PKGDEST}/${_target}"
Expand All @@ -40,10 +40,10 @@ service_remove_links ()
fi
done

for item in ${SPK_LINKS}
for item in ${SPK_USR_LOCAL_LINKS}
do
_link=$(echo ${item} | sed "s/:.*//g")
_target=$(echo ${item} | sed "s/.*://g")
_link=/usr/local/$(echo ${item} | sed "s/:.*//g")/${_target##*/}
if [ -L "${_link}" ]; then
if [ "$(readlink ${_link})" == "${SYNOPKG_PKGDEST}/${_target}" ]; then
echo "remove link: ${_link} -> ${SYNOPKG_PKGDEST}/${_target}"
Expand Down
21 changes: 10 additions & 11 deletions mk/spksrc.service.installer.dsm5
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/bin/sh

# DSM 5 -> 6 upgrade path:
# Cannot remove user as still in use or may be DSM service itself
# Require warning in ChangeLog and manual user/group cleanup
# - Not supported anymore

# define SYNOPKG_PKGVAR for compatibility with DSM7 (replaces former INST_VAR)
SYNOPKG_PKGVAR="${SYNOPKG_PKGDEST}/var"
Expand All @@ -23,15 +22,15 @@ TMP_DIR="/var/tmp/${SYNOPKG_PKGNAME}/var"

install_log ()
{
local _msg_="$@"
if [ -z "${_msg_}" ]; then
# read multiline from stdin
while IFS=$'\n' read -r line; do
install_log "${line}"
done
else
echo -e "$(date +'%Y/%m/%d %H:%M:%S')\t${_msg_}" >> ${INST_LOG_TEMP} 2>&1
fi
local _msg_="$@"
if [ -z "${_msg_}" ]; then
# read multiline from stdin
while IFS=$'\n' read -r line; do
install_log "${line}"
done
else
echo -e "$(date +'%Y/%m/%d %H:%M:%S')\t${_msg_}" >> ${INST_LOG_TEMP} 2>&1
fi
}

# Invoke shell function if available
Expand Down
60 changes: 6 additions & 54 deletions mk/spksrc.service.installer → mk/spksrc.service.installer.dsm6
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#!/bin/sh

# DSM 5 -> 6 upgrade path:
# - Not supported anymore

# define SYNOPKG_PKGVAR for compatibility with DSM7 (replaces former INST_VAR)
SYNOPKG_PKGVAR="${SYNOPKG_PKGDEST}/var"

# installer log is not writable, use for reference only.
INST_LOG="/var/log/packages/${SYNOPKG_PKGNAME}.log"

INST_ETC="/var/packages/${SYNOPKG_PKGNAME}/etc"
INST_VARIABLES="${INST_ETC}/installer-variables"
# define SYNOPKG_PKGVAR for compatibility with DSM7 (replaces former INST_VAR)
SYNOPKG_PKGVAR="${SYNOPKG_PKGDEST}/var"

# Optional FWPORTS file
FWPORTS_FILE="/var/packages/${SYNOPKG_PKGNAME}/target/app/${SYNOPKG_PKGNAME}.sc"
Expand Down Expand Up @@ -273,25 +277,8 @@ postinst ()
# Link for backward compatibility of binaries location
$LN "${SYNOPKG_PKGDEST}" "/usr/local/${SYNOPKG_PKGNAME}" 2>&1 | install_log

# Add firewall config
if [ -r "${FWPORTS_FILE}" ]; then
install_log "Installing service configuration ${FWPORTS_FILE}"
servicetool --install-configure-file --package "${FWPORTS_FILE}" 2>&1 | install_log
fi

# Service user management
if [ -n "${EFF_USER}" ]; then
if [ $SYNOPKG_DSM_VERSION_MAJOR -lt 6 ]; then
# DSM 5 specific operations
# Create prefixed synouser
if ! cat /etc/passwd | grep "${EFF_USER}:x:" &> /dev/null; then
synouser --add "${EFF_USER}" "" "$USER_DESC" 0 "" 0 2>&1 | install_log
# Set HOME for consistency with DSM 6, location available even if homes not enabled
BACKUP_PASSWD="/tmp/install_${SYNOPKG_PKGNAME}_passwd"
cp /etc/passwd ${BACKUP_PASSWD} 2>&1 | install_log
sed -i "s#/var/services/homes/${EFF_USER}#/var/packages/${SYNOPKG_PKGNAME}/target#" /etc/passwd 2>&1 | install_log
fi
fi
# Register service in "users" group to access any content
if [ "$ADD_USER_IN_USERS" = "yes" ]; then
syno_user_add_to_group "${EFF_USER}" "users" 2>&1 | install_log
Expand All @@ -312,34 +299,9 @@ postinst ()
synogroup --rebuild all 2>&1 | install_log
fi

# Share management
if [ -n "${SHARE_PATH}" ]; then
install_log "Configuring ${SHARE_PATH}"
# Create share if does not exist
# !"#$%&’()*+,/:;<=>?@[]nˆ`{} |
if ! synoshare --get "${SHARE_NAME}" &> /dev/null; then
synoshare --add "${SHARE_NAME}" "${SHARE_DESC}" "${SHARE_PATH}" "" "rw" "" 1 0 2>&1 | install_log
fi

# Add user permission if no GROUP is set in UI
# GROUP permission will be added in set_syno_permissions
if [ ! -n "$GROUP" ] && [ -n "${EFF_USER}" ]; then
synoshare --setuser "${SHARE_NAME}" RW + "${EFF_USER}" 2>&1 | install_log
fi
synoshare --build 2>&1 | install_log

$MKDIR "${SHARE_PATH}"

# Permissions for folder, up to volume
if [ -n "$GROUP" ]; then
set_syno_permissions "${SHARE_PATH}" "${GROUP}" 2>&1 | install_log
fi
fi

$MKDIR "${SYNOPKG_PKGVAR}" 2>&1 | install_log

call_func "service_postinst" install_log
call_func "service_create_links" install_log

if [ -n "${LOG_FILE}" ]; then
echo "Installation log: ${INST_LOG}" >> ${LOG_FILE}
Expand All @@ -355,15 +317,6 @@ preuninst ()
{
log_step "preuninst"
call_func "validate_preuninst"

if [ "${SYNOPKG_PKG_STATUS}" == "UNINSTALL" ]; then
# Remove firewall config
if [ -r "${FWPORTS_FILE}" ]; then
install_log "Removing service configuration ${SYNOPKG_PKGNAME}.sc"
servicetool --remove-configure-file --package "${SYNOPKG_PKGNAME}.sc" 2>&1 | install_log
fi
fi

call_func "service_preuninst" install_log
exit 0
}
Expand All @@ -384,7 +337,6 @@ postuninst ()
fi

call_func "service_postuninst" install_log
call_func "service_remove_links" install_log

if [ "${SYNOPKG_PKG_STATUS}" == "UNINSTALL" ]; then
$RM "${INST_VARIABLES}" 2>&1 | install_log
Expand Down
4 changes: 2 additions & 2 deletions mk/spksrc.service.installer.dsm7
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@ postinst ()
fi

call_func "service_postinst" install_log

if [ -n "${LOG_FILE}" ]; then
echo "Installation log: ${INST_LOG}" >> ${LOG_FILE}
fi

exit 0
}

Expand Down
43 changes: 20 additions & 23 deletions mk/spksrc.service.mk
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,9 @@ SPK_USER = $(SPK_NAME)
endif

# Recommend explicit STARTABLE=no
ifeq ($(strip $(SSS_SCRIPT)),)
ifeq ($(strip $(SERVICE_COMMAND)),)
ifeq ($(strip $(SPK_COMMANDS)),)
ifeq ($(strip $(SERVICE_EXE)),)
ifeq ($(strip $(STARTABLE)),)
$(error Set STARTABLE=no or provide either SERVICE_COMMAND, SPK_COMMANDS or specific SSS_SCRIPT)
endif
endif
endif
ifeq ($(strip $(SSS_SCRIPT) $(SERVICE_COMMAND) $(SERVICE_EXE) $(STARTABLE)),)
ifeq ($(strip $(SPK_COMMANDS) $(SPK_USR_LOCAL_LINKS)),)
$(error Set STARTABLE=no or provide either SERVICE_COMMAND, SERVICE_EXE, SSS_SCRIPT, SPK_COMMANDS or SPK_USR_LOCAL_LINKS)
endif
endif

Expand Down Expand Up @@ -142,19 +136,13 @@ ifneq ($(strip $(SERVICE_SETUP)),)
@cat $(CURDIR)/$(SERVICE_SETUP) >> $@
endif

ifneq ($(call version_ge, ${TCVERSION}, 7.0),1)
ifneq ($(strip $(SPK_COMMANDS) $(SPK_LINKS)),)
@echo "# List of commands to create links for" >> $@
@echo "SPK_COMMANDS=\"${SPK_COMMANDS}\"" >> $@
@echo "SPK_LINKS=\"${SPK_LINKS}\"" >> $@
@cat $(SPKSRC_MK)spksrc.service.create_links >> $@
endif
else
ifneq ($(strip $(SPK_LINKS)),)
@echo "${RED}ERROR: SPK_LINKS is unsupported in DSM7${NC}"
@echo "${GREEN}Please migrate to SPK_USR_LOCAL_LINKS=${NC}"
@exit 1
endif
# Define resources for
# - firewall rules/port definitions (DSM >= 6.0-5936)
# - usr local links (DSM >= 6.0-5941)
# - SERVICE_WIZARD_SHARE (DSM >= 6.0-5914)
# for DSM<6.0 link creation is provided by spksrc.service.create_links
# and other facilities are defined in the generic installer (spksrc.service.installer.dsm5)
ifeq ($(call version_ge, ${TCVERSION}, 6.0),1)
$(DSM_CONF_DIR)/resource:
$(create_target_dir)
@echo '{}' > $@
Expand Down Expand Up @@ -182,6 +170,15 @@ ifneq ($(strip $(SERVICE_WIZARD_SHARE)),)
'."data-share" = {"shares": [{"name": $$share, "permission":{"rw":[$$user]}} ] }' $@ 1<>$@
endif
SERVICE_FILES += $(DSM_CONF_DIR)/resource

# Less than DSM 6.0
else
ifneq ($(strip $(SPK_COMMANDS) $(SPK_USR_LOCAL_LINKS)),)
@echo "# List of commands to create links for" >> $@
@echo "SPK_COMMANDS=\"${SPK_COMMANDS}\"" >> $@
@echo "SPK_USR_LOCAL_LINKS=\"${SPK_USR_LOCAL_LINKS}\"" >> $@
@cat $(SPKSRC_MK)spksrc.service.create_links >> $@
endif
endif


Expand All @@ -196,7 +193,7 @@ ifeq ($(call version_ge, ${TCVERSION}, 7.0),1)
$(DSM_SCRIPTS_DIR)/installer: $(SPKSRC_MK)spksrc.service.installer.dsm7
@$(dsm_script_copy)
else ifeq ($(call version_ge, ${TCVERSION}, 6.0),1)
$(DSM_SCRIPTS_DIR)/installer: $(SPKSRC_MK)spksrc.service.installer
$(DSM_SCRIPTS_DIR)/installer: $(SPKSRC_MK)spksrc.service.installer.dsm6
@$(dsm_script_copy)
else
$(DSM_SCRIPTS_DIR)/installer: $(SPKSRC_MK)spksrc.service.installer.dsm5
Expand Down
6 changes: 0 additions & 6 deletions spk/beets/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,7 @@ SERVICE_SETUP = src/service-setup.sh

STARTABLE = no

include ../../mk/spksrc.common.mk
ifeq ($(call version_ge, ${TCVERSION}, 7.0),1)
SPK_USR_LOCAL_LINKS = bin:env/bin/beet
else
SPK_LINKS = /usr/local/bin/beet:env/bin/beet
endif


# Pure Python package, make sure ARCH is not defined
override ARCH=
Expand Down
5 changes: 0 additions & 5 deletions spk/borgbackup/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ LICENSE = BSD-3-Clause

SERVICE_SETUP = src/service-setup.sh

include ../../mk/spksrc.common.mk
ifeq ($(call version_ge, ${TCVERSION}, 7.0),1)
SPK_USR_LOCAL_LINKS = bin:env/bin/borg bin:env/bin/borgmatic
else
SPK_LINKS = /usr/local/bin/borg:env/bin/borg /usr/local/bin/borgmatic:env/bin/borgmatic
endif

include ../../mk/spksrc.spk.mk
5 changes: 0 additions & 5 deletions spk/rdiff-backup/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ LICENSE = GPLv2

SERVICE_SETUP = src/service-setup.sh

include ../../mk/spksrc.common.mk
ifeq ($(call version_ge, ${TCVERSION}, 7.0),1)
SPK_USR_LOCAL_LINKS = bin:env/bin/rdiff-backup bin:env/bin/rdiff-backup-statistics
else
SPK_LINKS = /usr/local/bin/rdiff-backup:env/bin/rdiff-backup /usr/local/bin/rdiff-backup-statistics:env/bin/rdiff-backup-statistics
endif

include ../../mk/spksrc.spk.mk

0 comments on commit 35e4364

Please sign in to comment.