Skip to content

Commit

Permalink
Transmission: add DSM7 support (#4719)
Browse files Browse the repository at this point in the history
* Framework: Acquire Shared folder resource/permissions
set using SERVICE_WIZARD_SHARE
only disadvantage is that this does not support sub-folders currently

* Transmission: Remove busybox from deps (#4373)

* transmission: Let the package manage the "watch" and "incomplete"
folders for DSM7

* framework: add DSM Version specific Wizards

* transmission: Let the package manage the "watch" and "incomplete" folders

* Migrate "watch" and "incomplete" files on upgrade

* Update python path

Co-authored-by: pkleinejaeger <[email protected]>
  • Loading branch information
publicarray and zyrill authored Aug 31, 2021
1 parent ac96619 commit f5fc4a3
Show file tree
Hide file tree
Showing 12 changed files with 374 additions and 204 deletions.
4 changes: 2 additions & 2 deletions mk/spksrc.service.installer.dsm5
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,10 @@ postinst ()
if [ -n "${LOG_FILE}" ]; then
echo "Installation log: ${INST_LOG}" >> ${LOG_FILE}
fi

# On DSM 5 set package files permissions for consistency with DSM 6
set_unix_permissions "${SYNOPKG_PKGDEST}" 2>&1 | install_log

exit 0
}

Expand Down
3 changes: 1 addition & 2 deletions mk/spksrc.service.installer.dsm7
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ postinst ()
# and don't override old configurations
if [ -d ${SYNOPKG_PKGDEST}/var ] && [ "$(find ${SYNOPKG_PKGVAR} -mindepth 1 -not -name '*.log' -print)" = "" ]; then
$CP ${SYNOPKG_PKGDEST}/var/. ${SYNOPKG_PKGVAR} 2>&1 | install_log
fi
fi

call_func "service_postinst" install_log

Expand Down Expand Up @@ -234,4 +234,3 @@ postupgrade ()
call_func "service_postupgrade" install_log
exit 0
}

2 changes: 1 addition & 1 deletion mk/spksrc.service.mk
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ ifneq ($(strip $(SPK_USR_LOCAL_LINKS)),)
endif
ifneq ($(strip $(SERVICE_WIZARD_SHARE)),)
# e.g. SERVICE_WIZARD_SHARE=wizard_download_dir
ifeq ($(call version_ge, ${TCVERSION}, 7.0),1)
ifeq ($(call version_ge, ${TCVERSION}, 6.0),1)
@jq --arg share "{{${SERVICE_WIZARD_SHARE}}}" --arg user sc-${SPK_USER} \
'."data-share" = {"shares": [{"name": $$share, "permission":{"rw":[$$user]}} ] }' $@ | sponge $@
endif
Expand Down
15 changes: 11 additions & 4 deletions mk/spksrc.spk.mk
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
### Rules to create the spk package
# Most of the rules are imported from spksrc.*.mk files
#
#
# Variables used in this file:
# NAME: The internal name of the package.
# Note that all synocoummunity packages use lowercase names.
# This enables to have concurrent packages with synology.com, that use
# package names starting with upper case letters.
# This enables to have concurrent packages with synology.com, that use
# package names starting with upper case letters.
# (e.g. Mono => synology.com, mono => synocommunity.com)
# SPK_FILE_NAME: The full spk name with folder, package name, arch, tc- and package version.
# SPK_CONTENT: List of files and folders that are added to package.tgz within the spk file.
# DSM_SCRIPT_FILES: List of script files that are in the scripts folder within the spk file.
#
#

# Common makefiles
include ../../mk/spksrc.common.mk
Expand Down Expand Up @@ -333,6 +333,13 @@ ifneq ($(strip $(WIZARDS_DIR)),)
@mkdir -p $(DSM_WIZARDS_DIR)
@find $${SPKSRC_WIZARDS_DIR} -maxdepth 1 -type f -and \( -name "install_uifile" -or -name "install_uifile_???" -or -name "install_uifile.sh" -or -name "install_uifile_???.sh" -or -name "upgrade_uifile" -or -name "upgrade_uifile_???" -or -name "upgrade_uifile.sh" -or -name "upgrade_uifile_???.sh" -or -name "uninstall_uifile" -or -name "uninstall_uifile_???" -or -name "uninstall_uifile.sh" -or -name "uninstall_uifile_???.sh" \) -print -exec cp -f {} $(DSM_WIZARDS_DIR) \;
endif
ifneq ($(strip $(WIZARDS_DIR)),)
@$(MSG) "Look for DSM Version specific Wizards: $(WIZARDS_DIR)$(TCVERSION)"
@mkdir -p $(DSM_WIZARDS_DIR)
@if [ -d "$(WIZARDS_DIR)$(TCVERSION)" ]; then \
find $${SPKSRC_WIZARDS_DIR}$(TCVERSION) -maxdepth 1 -type f -and \( -name "install_uifile" -or -name "install_uifile_???" -or -name "install_uifile.sh" -or -name "install_uifile_???.sh" -or -name "upgrade_uifile" -or -name "upgrade_uifile_???" -or -name "upgrade_uifile.sh" -or -name "upgrade_uifile_???.sh" -or -name "uninstall_uifile" -or -name "uninstall_uifile_???" -or -name "uninstall_uifile.sh" -or -name "uninstall_uifile_???.sh" \) -print -exec cp -f {} $(DSM_WIZARDS_DIR) \; ;\
fi
endif
ifneq ($(strip $(WIZARDS_DIR)),)
@find $(DSM_WIZARDS_DIR) -maxdepth 1 -type f -not -name "*.sh" -print -exec chmod 0644 {} \;
@find $(DSM_WIZARDS_DIR) -maxdepth 1 -type f -name "*.sh" -print -exec chmod 0755 {} \;
Expand Down
7 changes: 1 addition & 6 deletions spk/transmission/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SPK_VERS = 3.00
SPK_REV = 19
SPK_ICON = src/transmission.png

DEPENDS = cross/busybox cross/$(SPK_NAME)
DEPENDS = cross/$(SPK_NAME)

MAINTAINER = SynoCommunity
DESCRIPTION = Transmission is an easy and fast BitTorrent client. You can control it remotely with its web interface or dedicated applications.
Expand All @@ -30,13 +30,8 @@ ADMIN_PORT = $(SERVICE_PORT)

POST_STRIP_TARGET = transmission_extra_install

BUSYBOX_CONFIG = usrmng
ENV += BUSYBOX_CONFIG="$(BUSYBOX_CONFIG)"


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


.PHONY: transmission_extra_install
transmission_extra_install:
install -m 755 -d $(STAGING_DIR)/var
Expand Down
124 changes: 82 additions & 42 deletions spk/transmission/src/service-setup.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
# Add python to path
# This gives tranmission the power to execute python scripts on completion (like TorrentToMedia).
PYTHON_DIR="/usr/local/python"
PATH="${SYNOPKG_PKGDEST}/bin:${PYTHON_DIR}/bin:${PATH}"
CFG_FILE="${SYNOPKG_PKGDEST}/var/settings.json"
if [ "${SYNOPKG_DSM_VERSION_MAJOR}" -ge 7 ]; then
# use system python for DSM7
PYTHON_BIN_PATHS=""
else
GROUP="sc-download"
PYTHON_BIN_PATHS="/var/packages/python38/target/bin:/var/packages/python3/target/bin:"
fi
PATH="${SYNOPKG_PKGDEST}/bin:${PYTHON_BIN_PATHS}${PATH}"
CFG_FILE="${SYNOPKG_PKGVAR}/settings.json"
TRANSMISSION="${SYNOPKG_PKGDEST}/bin/transmission-daemon"

GROUP="sc-download"
SERVICE_COMMAND="${TRANSMISSION} -g ${SYNOPKG_PKGVAR} -x ${PID_FILE} -e ${LOG_FILE}"

SERVICE_COMMAND="${TRANSMISSION} -g ${SYNOPKG_PKGDEST}/var/ -x ${PID_FILE} -e ${LOG_FILE}"

service_preinst ()
validate_preinst()
{
if [ "${SYNOPKG_PKG_STATUS}" == "INSTALL" ]; then
if [ "${SYNOPKG_PKG_STATUS}" == "INSTALL" ] && [ "${SYNOPKG_DSM_VERSION_MAJOR}" -lt 7 ]; then
# If chosen, they need to exist
if [ -n "${wizard_watch_dir}" -a ! -d "${wizard_watch_dir}" ]; then
if [ -n "${wizard_watch_dir}" ] && [ ! -d "${wizard_watch_dir}" ]; then
echo "Watch directory ${wizard_watch_dir} does not exist."
exit 1
fi
if [ -n "${wizard_incomplete_dir}" -a ! -d "${wizard_incomplete_dir}" ]; then
if [ -n "${wizard_incomplete_dir}" ] && [ ! -d "${wizard_incomplete_dir}" ]; then
echo "Incomplete directory ${wizard_incomplete_dir} does not exist."
exit 1
fi
Expand All @@ -29,23 +33,33 @@ service_preinst ()
service_postinst ()
{
if [ "${SYNOPKG_PKG_STATUS}" == "INSTALL" ]; then
# Attempt to create the folders after the user/group/shared folder has been created by the package (DSM7+)
# Let the package manage the "watch" and "incomplete" folders for DSM7
# https://github.com/SynoCommunity/spksrc/issues/4766#issuecomment-899875151
if [ "${SYNOPKG_DSM_VERSION_MAJOR}" -ge 7 ]; then
wizard_watch_dir="${wizard_volume:=/volume1}/${wizard_download_dir:=/downloads}/watch"
wizard_incomplete_dir="${wizard_volume:=/volume1}/${wizard_download_dir:=/downloads}/incomplete"
mkdir -p "${wizard_watch_dir}"
mkdir -p "${wizard_incomplete_dir}"
fi

# Edit the configuration according to the wizard
sed -i -e "s|@download_dir@|${wizard_download_dir:=/volume1/downloads}|g" ${CFG_FILE}
sed -i -e "s|@username@|${wizard_username:=admin}|g" ${CFG_FILE}
sed -i -e "s|@password@|${wizard_password:=admin}|g" ${CFG_FILE}
sed -i -e "s|@download_dir@|${wizard_volume:=/volume1}/${wizard_download_dir:=/downloads}|g" "${CFG_FILE}"
sed -i -e "s|@username@|${wizard_username:=admin}|g" "${CFG_FILE}"
sed -i -e "s|@password@|${wizard_password:=admin}|g" "${CFG_FILE}"
if [ -d "${wizard_watch_dir}" ]; then
sed -i -e "s|@watch_dir_enabled@|true|g" ${CFG_FILE}
sed -i -e "s|@watch_dir@|${wizard_watch_dir}|g" ${CFG_FILE}
sed -i -e "s|@watch_dir_enabled@|true|g" "${CFG_FILE}"
sed -i -e "s|@watch_dir@|${wizard_watch_dir}|g" "${CFG_FILE}"
else
sed -i -e "s|@watch_dir_enabled@|false|g" ${CFG_FILE}
sed -i -e "/@watch_dir@/d" ${CFG_FILE}
sed -i -e "s|@watch_dir_enabled@|false|g" "${CFG_FILE}"
sed -i -e "/@watch_dir@/d" "${CFG_FILE}"
fi
if [ -d "${wizard_incomplete_dir}" ]; then
sed -i -e "s|@incomplete_dir_enabled@|true|g" ${CFG_FILE}
sed -i -e "s|@incomplete_dir@|${wizard_incomplete_dir}|g" ${CFG_FILE}
sed -i -e "s|@incomplete_dir_enabled@|true|g" "${CFG_FILE}"
sed -i -e "s|@incomplete_dir@|${wizard_incomplete_dir}|g" "${CFG_FILE}"
else
sed -i -e "s|@incomplete_dir_enabled@|false|g" ${CFG_FILE}
sed -i -e "/@incomplete_dir@/d" ${CFG_FILE}
sed -i -e "s|@incomplete_dir_enabled@|false|g" "${CFG_FILE}"
sed -i -e "/@incomplete_dir@/d" "${CFG_FILE}"
fi

# Set permissions for optional folders
Expand All @@ -56,33 +70,59 @@ service_postinst ()
set_syno_permissions "${wizard_incomplete_dir}" "${GROUP}"
fi
fi

# Discard legacy obsolete busybox user account
BIN=${SYNOPKG_PKGDEST}/bin
$BIN/busybox --install $BIN >> ${INST_LOG}
$BIN/delgroup "${USER}" "users" >> ${INST_LOG}
$BIN/deluser "${USER}" >> ${INST_LOG}
}


service_postupgrade ()
{
# Needed to force correct permissions, during update
# Extract the right paths from config file
if [ -r "${CFG_FILE}" ]; then
DOWNLOAD_DIR=`sed -n 's/.*"download-dir"[ ]*:[ ]*"\(.*\)",/\1/p' ${CFG_FILE}`
INCOMPLETE_DIR=`sed -n 's/.*"incomplete-dir"[ ]*:[ ]*"\(.*\)",/\1/p' ${CFG_FILE}`
WATCHED_DIR=`sed -n 's/.*"watch-dir"[ ]*:[ ]*"\(.*\)",/\1/p' ${CFG_FILE}`
# Migrate to DSM7
if [ "${SYNOPKG_DSM_VERSION_MAJOR}" -ge 7 ]; then
OLD_DOWNLOAD_DIR=$(sed -n 's/.*"download-dir"\s*:\s*"\(.*\)",/\1/p' "${CFG_FILE}")
OLD_INCOMPLETE_DIR=$(sed -n 's/.*"incomplete-dir"\s*:\s*"\(.*\)",/\1/p' "${CFG_FILE}")
OLD_WATCHED_DIR=$(sed -n 's/.*"watch-dir"\s*:\s*"\(.*\)",/\1/p' "${CFG_FILE}")

# Apply permissions
if [ -n "${DOWNLOAD_DIR}" ] && [ -d "${DOWNLOAD_DIR}" ]; then
set_syno_permissions "${DOWNLOAD_DIR}" "${GROUP}"
fi
if [ -n "${INCOMPLETE_DIR}" ] && [ -d "${INCOMPLETE_DIR}" ]; then
set_syno_permissions "${INCOMPLETE_DIR}" "${GROUP}"
fi
if [ -n "${WATCHED_DIR}" ] && [ -d "${WATCHED_DIR}" ]; then
set_syno_permissions "${WATCHED_DIR}" "${GROUP}"
NEW_DOWNLOAD_DIR="${wizard_volume:=/volume1}/${wizard_download_dir:=/downloads}"
NEW_INCOMPLETE_DIR="${wizard_volume:=/volume1}/${wizard_download_dir:=/downloads}/incomplete"
NEW_WATCHED_DIR="${wizard_volume:=/volume1}/${wizard_download_dir:=/downloads}/watch"

# update folders
sed -i -e "s|\s\"download-dir\".*| \"download-dir\": \"${NEW_DOWNLOAD_DIR}\",|g" "${CFG_FILE}"
sed -i -e "s|\s\"watch-dir\".*| \"watch-dir\": \"${NEW_INCOMPLETE_DIR}\",|g" "${CFG_FILE}"
sed -i -e "s|\s\"watch-dir-enabled\".*| \"watch-dir-enabled\": true,|g" "${CFG_FILE}"
sed -i -e "s|\s\"incomplete-dir\".*| \"incomplete-dir\": \"${NEW_WATCHED_DIR}\",|g" "${CFG_FILE}"
sed -i -e "s|\s\"incomplete-dir-enabled\".*| \"incomplete-dir-enabled\": true,|g" "${CFG_FILE}"

mkdir -p "$NEW_INCOMPLETE_DIR"
mkdir -p "$NEW_WATCHED_DIR"

# move files
# not moving download dir because it could contain data not from this package
# if [ "$OLD_DOWNLOAD_DIR" != "$NEW_DOWNLOAD_DIR" ]; then
# mv -nv "$OLD_DOWNLOAD_DIR"/* "$NEW_DOWNLOAD_DIR"
# fi
shopt -s dotglob # copy hidden folder/files too
if [ -n "${OLD_INCOMPLETE_DIR}" ] && [ "$OLD_INCOMPLETE_DIR" != "$NEW_INCOMPLETE_DIR" ]; then
mv -nv "$OLD_INCOMPLETE_DIR"/* "$NEW_INCOMPLETE_DIR/"
fi
if [ -n "${OLD_WATCHED_DIR}" ] && [ "$OLD_WATCHED_DIR" != "$NEW_WATCHED_DIR" ]; then
mv -nv "$OLD_WATCHED_DIR"/* "$NEW_WATCHED_DIR/"
fi
shopt -d dotglob
else
# Extract the right paths from config file and update Permissions
DOWNLOAD_DIR=$(sed -n 's/.*"download-dir"\s*:\s*"\(.*\)",/\1/p' "${CFG_FILE}")
INCOMPLETE_DIR=$(sed -n 's/.*"incomplete-dir"\s*:\s*"\(.*\)",/\1/p' "${CFG_FILE}")
WATCHED_DIR=$(sed -n 's/.*"watch-dir"\s*:\s*"\(.*\)",/\1/p' "${CFG_FILE}")
# Apply permissions
if [ -n "${DOWNLOAD_DIR}" ] && [ -d "${DOWNLOAD_DIR}" ]; then
set_syno_permissions "${DOWNLOAD_DIR}" "${GROUP}"
fi
if [ -n "${INCOMPLETE_DIR}" ] && [ -d "${INCOMPLETE_DIR}" ]; then
set_syno_permissions "${INCOMPLETE_DIR}" "${GROUP}"
fi
if [ -n "${WATCHED_DIR}" ] && [ -d "${WATCHED_DIR}" ]; then
set_syno_permissions "${WATCHED_DIR}" "${GROUP}"
fi
fi
fi
}
91 changes: 91 additions & 0 deletions spk/transmission/src/wizard/7.0/install_uifile
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
[
{
"step_title": "Basic configuration",
"items": [
{
"type": "combobox",
"desc": "Please select a volume to use for the download folder",
"subitems": [
{
"key": "wizard_volume",
"desc": "volume name",
"displayField": "display_name",
"valueField": "volume_path",
"editable": false,
"mode": "remote",
"api_store": {
"api": "SYNO.Core.Storage.Volume",
"method": "list",
"version": 1,
"baseParams": {
"limit": -1,
"offset": 0,
"location": "internal"
},
"root": "volumes",
"idProperty": "volume_path",
"fields": [
"display_name",
"volume_path"
]
},
"validator": {
"fn": "{console.log(arguments);return true;}"
}
}
]
},
{
"type": "textfield",
"desc": "Download shared folder (using the volume chosen above)",
"subitems": [
{
"key": "wizard_download_dir",
"desc": "Download shared folder",
"defaultValue": "downloads",
"validator": {
"allowBlank": false,
"regex": {
"expr": "/^[\\w _-]+$/",
"errorText": "Subdirectories are not supported."
}
}
}
]
}
]
},
{
"step_title": "Basic configuration",
"items": [
{
"type": "textfield",
"desc": "Web interface username. Defaults to admin",
"subitems": [
{
"key": "wizard_username",
"desc": "Username"
}
]
},
{
"type": "password",
"desc": "Web interface password. Defaults to admin",
"subitems": [
{
"key": "wizard_password",
"desc": "Password"
}
]
}
]
},
{
"step_title": "DSM Permissions",
"items": [
{
"desc": "Please read <a target=\"_blank\" href=\"https://github.com/SynoCommunity/spksrc/wiki/Permission-Management\">Permission Management</a> for details."
}
]
}
]
Loading

0 comments on commit f5fc4a3

Please sign in to comment.