Skip to content
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

Transmission DSM7 support #4719

Merged
merged 26 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a51155e
[Transmission] Acquire Shared folder resource/permissions
publicarray Feb 21, 2021
5096590
Transmission: Remove busybox from deps (#4373)
zyrill Jan 13, 2021
4b4a035
Transmission: mentionnès -> mentionnés
publicarray Jan 19, 2021
f184908
Transmission fix upgrade from dsm6
publicarray Apr 17, 2021
9d92dcd
fix shared folder resource worker on DSM6
publicarray Jul 8, 2021
8c5efcf
style fix
publicarray Jul 8, 2021
248c714
Also update the download folder on upgrades
publicarray Aug 9, 2021
89ecc38
set default volume
publicarray Aug 9, 2021
3a9dc6d
fix shellcheck warning
publicarray Aug 16, 2021
54383ea
improve messages
publicarray Aug 16, 2021
504d53b
transmission: attempt to create folders
publicarray Aug 17, 2021
ec52657
transmission: Let the package manage the "watch" and "incomplete"
publicarray Aug 17, 2021
85c10f2
fix DSM Version specific Wizards
publicarray Aug 17, 2021
222a49d
transmission: Let the package manage the "watch" and "incomplete"
publicarray Aug 17, 2021
65be930
Move the upgrade wizard to DSM7 only
publicarray Aug 17, 2021
53aca47
only update folder if DSM7
publicarray Aug 17, 2021
ca0dfd5
remove old wizards
publicarray Aug 18, 2021
6942ad6
remove the extra validation
publicarray Aug 26, 2021
5462944
revert some unnecessary changes
publicarray Aug 28, 2021
992ede4
Migrate files
publicarray Aug 28, 2021
c20363d
create folder first
publicarray Aug 28, 2021
2549bf4
make sure the config is consistent with the install config after upgrade
publicarray Aug 28, 2021
8b0dae7
copy hidden folder/files too
publicarray Aug 28, 2021
05a3a96
Update python path
publicarray Aug 29, 2021
cf67243
don't use legacy group for DSM7
publicarray Aug 31, 2021
e7de616
cleanup
publicarray Aug 31, 2021
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
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
112 changes: 74 additions & 38 deletions spk/transmission/src/service-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
# 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}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no SPK_DEPENDS=python... in this package, it is not defined which python should be used.

For synocommunity packages the path /usr/local/{package} must not be used anymore, i.e. it must be defined as /var/packages/{package}/target.

I suppose that python2 should not be used anymore, so the package must be python3 or python38.

Proposal:
remove these lines and rely on python that is already installed and available in the path.

if no python is found in path, a lookup for synocommunity python3 and python38 could be used here to add it to the path for transmission.

Copy link
Member Author

@publicarray publicarray Aug 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Good catch! I didn't even notice that python can be used from transmission.

Copy link

@BenjV BenjV Aug 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of DSM 7, Python 3 is standard available and can be found via the path.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if no python is found in path, a lookup for synocommunity python3 and python38 could be used here to add it to the path for transmission.

@hgy59 I didn't do any fancy detection because that is what $PATH is for anyway. Don't need to do it twice and this way it still works if a python package is added or removed. Agreed, for DSM7 the build in Python should be good enough.

CFG_FILE="${SYNOPKG_PKGDEST}/var/settings.json"
CFG_FILE="${SYNOPKG_PKGVAR}/settings.json"
TRANSMISSION="${SYNOPKG_PKGDEST}/bin/transmission-daemon"

GROUP="sc-download"

SERVICE_COMMAND="${TRANSMISSION} -g ${SYNOPKG_PKGDEST}/var/ -x ${PID_FILE} -e ${LOG_FILE}"
SERVICE_COMMAND="${TRANSMISSION} -g ${SYNOPKG_PKGVAR} -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 +29,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 +66,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