From 35e4364cabb01c2f59ea22a003a516f781c1d572 Mon Sep 17 00:00:00 2001 From: hgy59 Date: Fri, 30 Apr 2021 16:57:21 +0200 Subject: [PATCH] use resource linker for DSM6 (#4578) * 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 --- mk/spksrc.service.create_links | 8 +-- mk/spksrc.service.installer.dsm5 | 21 ++++--- ...nstaller => spksrc.service.installer.dsm6} | 60 ++----------------- mk/spksrc.service.installer.dsm7 | 4 +- mk/spksrc.service.mk | 43 +++++++------ spk/beets/Makefile | 6 -- spk/borgbackup/Makefile | 5 -- spk/rdiff-backup/Makefile | 5 -- 8 files changed, 42 insertions(+), 110 deletions(-) rename mk/{spksrc.service.installer => spksrc.service.installer.dsm6} (83%) diff --git a/mk/spksrc.service.create_links b/mk/spksrc.service.create_links index 36b0a9d1c6b..507521fe052 100644 --- a/mk/spksrc.service.create_links +++ b/mk/spksrc.service.create_links @@ -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}" @@ -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}" diff --git a/mk/spksrc.service.installer.dsm5 b/mk/spksrc.service.installer.dsm5 index 54f10035769..09cecc39fa2 100644 --- a/mk/spksrc.service.installer.dsm5 +++ b/mk/spksrc.service.installer.dsm5 @@ -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" @@ -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 diff --git a/mk/spksrc.service.installer b/mk/spksrc.service.installer.dsm6 similarity index 83% rename from mk/spksrc.service.installer rename to mk/spksrc.service.installer.dsm6 index cdeec5b72dc..b4613545055 100644 --- a/mk/spksrc.service.installer +++ b/mk/spksrc.service.installer.dsm6 @@ -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" @@ -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 @@ -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} @@ -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 } @@ -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 diff --git a/mk/spksrc.service.installer.dsm7 b/mk/spksrc.service.installer.dsm7 index 46653fe659f..268226dd9b8 100644 --- a/mk/spksrc.service.installer.dsm7 +++ b/mk/spksrc.service.installer.dsm7 @@ -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 } diff --git a/mk/spksrc.service.mk b/mk/spksrc.service.mk index bef1587794b..0d01787cff2 100644 --- a/mk/spksrc.service.mk +++ b/mk/spksrc.service.mk @@ -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 @@ -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 '{}' > $@ @@ -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 @@ -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 diff --git a/spk/beets/Makefile b/spk/beets/Makefile index 745fa094ada..fe12f4897e8 100644 --- a/spk/beets/Makefile +++ b/spk/beets/Makefile @@ -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= diff --git a/spk/borgbackup/Makefile b/spk/borgbackup/Makefile index 0f5396f2cd9..b09f1255818 100644 --- a/spk/borgbackup/Makefile +++ b/spk/borgbackup/Makefile @@ -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 diff --git a/spk/rdiff-backup/Makefile b/spk/rdiff-backup/Makefile index 91a4122c73c..8e3fdb16aee 100644 --- a/spk/rdiff-backup/Makefile +++ b/spk/rdiff-backup/Makefile @@ -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