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

redesign shared folder handling #5649

Merged
merged 20 commits into from
Oct 14, 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
12 changes: 6 additions & 6 deletions cross/adminer/patches/001-not-use-pgsql-extension.patch
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# See https://github.com/SynoCommunity/spksrc/issues/2662
# Remove the extension pgsql because the extension pgsql does not work with the PostgreSQL server from DSM. The Extension pdo_pgsql works perfectly.
--- adminer/drivers/pgsql.inc.php.org 2020-01-31 10:23:04.000000000 +0000
+++ adminer/drivers/pgsql.inc.php 2020-02-23 16:59:43.482304615 +0000
@@ -4,146 +4,8 @@
--- adminer/drivers/pgsql.inc.php.orig 2021-05-14 05:39:59.000000000 +0000
+++ adminer/drivers/pgsql.inc.php 2023-10-07 23:07:43.616901493 +0000
@@ -3,146 +3,7 @@

if (isset($_GET["pgsql"])) {
$possible_drivers = array("PgSQL", "PDO_PgSQL");
define("DRIVER", "pgsql");
- if (extension_loaded("pgsql")) {
- class Min_DB {
- var $extension = "PgSQL", $_link, $_result, $_string, $_database = true, $server_info, $affected_rows, $error, $timeout;
-
- function _error($errno, $error) {
- if (ini_bool("html_errors")) {
- $error = html_entity_decode(strip_tags($error));
Expand Down Expand Up @@ -43,7 +43,7 @@
- }
-
- function value($val, $field) {
- return ($field["type"] == "bytea" ? pg_unescape_bytea($val) : $val);
- return ($field["type"] == "bytea" && $val !== null ? pg_unescape_bytea($val) : $val);
- }
-
- function quoteBinary($string) {
Expand Down
2 changes: 1 addition & 1 deletion cross/cops/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ DEPENDS =

HOMEPAGE = https://blog.slucas.fr/en/oss/calibre-opds-php-server
COMMENT = Calibre OPDS and HTML PHP Server : light alternative to Calibre content server / Calibre2OPDS.
LICENSE = GPL
LICENSE = GPLv2

INSTALL_TARGET = cops_install

Expand Down
4 changes: 3 additions & 1 deletion mk/spksrc.icon.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ ICON_COOKIE = $(WORK_DIR)/.$(COOKIE_PREFIX)icon_done
# Icons are only needed with "DSM UI configuration" (see spksrc.service.mk)
ifneq ($(strip $(DSM_UI_DIR)),)
ifneq ($(strip $(SPK_ICON)),)
ifneq ($(or $(strip $(SERVICE_PORT)), $(strip $(ADMIN_URL))),)
ifneq ($(strip $(DSM_UI_CONFIG)),)
ICON_DIR = $(STAGING_DIR)/$(DSM_UI_DIR)/images
else ifneq ($(or $(strip $(SERVICE_PORT)), $(strip $(ADMIN_URL))),)
ifeq ($(strip $(NO_SERVICE_SHORTCUT)),)
ICON_DIR = $(STAGING_DIR)/$(DSM_UI_DIR)/images
endif
Expand Down
69 changes: 41 additions & 28 deletions mk/spksrc.service.installer.dsm5
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fi


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

# init variables either from ${INST_VARIABLES}, from package or from wizard
call_func "initialize_variables"
Expand Down Expand Up @@ -140,9 +140,9 @@ set_syno_permissions ()
# Ensure directory resides in /volumeX before setting GROUP permissions
if [ "$(echo ${VOLUME} | cut -c2-7)" = "volume" ]; then
# Set read/write permissions for GROUP for folder and subfolders
if [ ! "$(synoacltool -get \"${DIRNAME}\"| grep \"group:${GROUP}:allow:rwxpdDaARWcC-:fd--\")" ]; then
if [ ! "$(synoacltool -get ${DIRNAME} | grep ""group:${GROUP}:allow:rwxpdDaARWcC-:fd--"")" ]; then
# First Unix permissions, but only if it's in Linux mode
if [ "$(synoacltool -get \"${DIRNAME}\"| grep \"Linux mode\")" ]; then
if [ "$(synoacltool -get ${DIRNAME} | grep -i 'Linux mode')" ]; then
set_unix_permissions "${DIRNAME}"
# If it is linux mode (due to old package) we need to add "administrators"-group,
# otherwise the folder is not accessible from File Station anymore!
Expand All @@ -157,9 +157,9 @@ set_syno_permissions ()

# Walk up the tree and set traverse execute permissions for GROUP up to VOLUME
while [ "${DIRNAME}" != "${VOLUME}" ]; do
if [ ! "$(synoacltool -get \"${DIRNAME}\"| grep \"group:${GROUP}:allow:r.x\")" ]; then
if [ ! "$(synoacltool -get ""${DIRNAME}"" | grep ""group:${GROUP}:allow:r.x"")" ]; then
# Here we also need to make sure the admin can access data via File Station
if [ "$(synoacltool -get \"${DIRNAME}\"| grep \"Linux mode\")" ]; then
if [ "$(synoacltool -get ""${DIRNAME}"" | grep -i 'Linux mode')" ]; then
synoacltool -add "${DIRNAME}" "group:administrators:allow:rwxpdDaARWc--:fd--"
fi
# Add the new group permissions
Expand Down Expand Up @@ -212,26 +212,12 @@ preinst ()
call_func "validate_preinst"
call_func "service_preinst"

# Check volume exists
if [ -n "${SHARE_PATH}" ]; then
if [ ! -d "${SHARE_VOLUME}" ]; then
echo "ERROR: Volume ${SHARE_VOLUME} does not exist." | $TEE 1>&2
exit 1
fi
fi

exit 0
}

postinst ()
{
log_step "postinst"
call_func "save_wizard_variables"
# Restrict permissions to protect sensitive options
if [ -e "${INST_VARIABLES}" ]; then
chmod go-rwx ${INST_VARIABLES}
chown ${EFF_USER} ${INST_VARIABLES}
fi

# Link for backward compatibility of binaries location
$LN "${SYNOPKG_PKGDEST}" "/usr/local/${SYNOPKG_PKGNAME}" 2>&1 | install_log
Expand Down Expand Up @@ -278,34 +264,58 @@ postinst ()

# 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}" "" "" "" 1 0 2>&1 | install_log
# Create share if it does not exist
# invalid characters: !"#$%&’()*+,/:;<=>?@[]nˆ`{} |
if ! synoshare --get "${SHARE_NAME}" > /dev/null 2>&1; then
SHARE_PATH=${SYNOPKG_PKGDEST_VOL}/${SHARE_NAME}
install_log "Create share SHARE_NAME=${SHARE_NAME}, SHARE_PATH=${SHARE_PATH}"
# mandatory arguments:
# name desc path na rw ro browseable adv_privilege
# na, rw and ro are list of user(s) and/or group(s), separated by comma
synoshare --add "${SHARE_NAME}" "Share created for package ${SYNOPKG_PKGNAME}" "${SHARE_PATH}" "" "" "" 1 0 2>&1 | install_log
else
install_log "Share already exists SHARE_NAME=${SHARE_NAME}, SHARE_PATH=${SHARE_PATH}"
fi

# Add user permission if no GROUP is set in UI
# Add user permission if no GROUP is set in service-setup
# GROUP permission will be added in set_syno_permissions
if [ -z "$GROUP" ] && [ -n "${EFF_USER}" ]; then
synoshare --setuser "${SHARE_NAME}" RW + "${EFF_USER}" 2>&1 | install_log
# check whether user is already added to RW users
_synoshare_parameter="--getmap"
if synoshare --getmap "${SHARE_NAME}" | grep "ACL.*\[yes\]" > /dev/null 2>&1; then
_synoshare_parameter="--list_acl"
fi
if synoshare ${_synoshare_parameter} "${SHARE_NAME}" | grep "RW list" | grep -o "\[.*\]" | sed 's/[\[,]/ /g' | sed 's/\]/ /g' | grep -q " ${EFF_USER} " > /dev/null 2>&1; then
install_log "User has already RW access to share: SHARE_NAME=${SHARE_NAME}, EFF_USER=${EFF_USER}"
else
install_log "Set user for share: SHARE_NAME=${SHARE_NAME}, EFF_USER=${EFF_USER}"
synoshare --setuser "${SHARE_NAME}" RW + "${EFF_USER}" 2>&1 | install_log
fi
fi
synoshare --build 2>&1 | install_log

$MKDIR "${SHARE_PATH}"

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

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

call_func "save_wizard_variables"
# Restrict permissions to protect sensitive options
if [ -e "${INST_VARIABLES}" ]; then
chmod go-rwx ${INST_VARIABLES}
chown ${EFF_USER} ${INST_VARIABLES}
fi

call_func "service_postinst"

call_func "service_create_links"

$CP "${INST_LOG_TEMP}" "${INST_LOG}" 2>&1 | install_log

if [ -n "${LOG_FILE}" ]; then
echo "Installation log: ${INST_LOG}" >> ${LOG_FILE}
fi
Expand All @@ -330,6 +340,7 @@ preuninst ()
fi

call_func "service_preuninst"

exit 0
}

Expand All @@ -354,6 +365,7 @@ postuninst ()
if [ "${SYNOPKG_PKG_STATUS}" == "UNINSTALL" ]; then
$RM "${INST_VARIABLES}" 2>&1 | install_log
fi

exit 0
}

Expand Down Expand Up @@ -393,5 +405,6 @@ postupgrade ()

# Make sure we also have the logging for this step
$CP "${INST_LOG_TEMP}" "${INST_LOG}" 2>&1 | install_log

exit 0
}
86 changes: 51 additions & 35 deletions mk/spksrc.service.installer.dsm6
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fi


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

# init variables either from ${INST_VARIABLES}, from package or from wizard
call_func "initialize_variables"
Expand Down Expand Up @@ -148,9 +148,9 @@ set_syno_permissions ()
# Ensure directory resides in /volumeX before setting GROUP permissions
if [ "$(echo ${VOLUME} | cut -c2-7)" = "volume" ]; then
# Set read/write permissions for GROUP for folder and subfolders
if [ ! "$(synoacltool -get ""${DIRNAME}"" | grep ""group:${GROUP}:allow:rwxpdDaARWcC-:fd--"")" ]; then
if [ ! "$(synoacltool -get ${DIRNAME} | grep ""group:${GROUP}:allow:rwxpdDaARWcC-:fd--"")" ]; then
# First Unix permissions, but only if it's in Linux mode
if [ "$(synoacltool -get ""${DIRNAME}"" | grep -i 'Linux mode')" ]; then
if [ "$(synoacltool -get ${DIRNAME} | grep -i 'Linux mode')" ]; then
set_unix_permissions "${DIRNAME}"
# If it is linux mode (due to old package) we need to add "administrators"-group,
# otherwise the folder is not accessible from File Station anymore!
Expand Down Expand Up @@ -224,26 +224,12 @@ preinst ()
call_func "validate_preinst"
call_func "service_preinst" install_log

# Check volume exists
if [ -n "${SHARE_PATH}" ]; then
if [ ! -d "${SHARE_VOLUME}" ]; then
echo "ERROR: Volume ${SHARE_VOLUME} does not exist." | $TEE 1>&2
exit 1
fi
fi

exit 0
}

postinst ()
{
log_step "postinst"
call_func "save_wizard_variables" install_log
# Restrict permissions to protect sensitive options
if [ -e "${INST_VARIABLES}" ]; then
chmod go-rwx ${INST_VARIABLES}
chown ${EFF_USER} ${INST_VARIABLES}
fi

# Link for backward compatibility of binaries location
$LN "${SYNOPKG_PKGDEST}" "/usr/local/${SYNOPKG_PKGNAME}" 2>&1 | install_log
Expand Down Expand Up @@ -273,33 +259,60 @@ postinst ()
synogroup --rebuild all 2>&1 | install_log
fi

# Share management
# Share management (can be removed when SERVICE_WIZARD_SHARE is not used anymore)
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}" "" "" "" 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 [ -z "$GROUP" ] && [ -n "${EFF_USER}" ]; then
synoshare --setuser "${SHARE_NAME}" RW + "${EFF_USER}" 2>&1 | install_log
fi
synoshare --build 2>&1 | install_log
if [ "${SHARE_WORKER}" != "0" ]; then
install_log "Shared folder [${SHARE_PATH}] will be created by DSM."
else
# Create share if it does not exist
# invalid characters: !"#$%&’()*+,/:;<=>?@[]nˆ`{} |
if ! synoshare --get "${SHARE_NAME}" > /dev/null 2>&1; then
SHARE_PATH=${SYNOPKG_PKGDEST_VOL}/${SHARE_NAME}
install_log "Create share SHARE_NAME=${SHARE_NAME}, SHARE_PATH=${SHARE_PATH}"
# mandatory arguments:
# name desc path na rw ro browseable adv_privilege
# na, rw and ro are list of user(s) and/or group(s), separated by comma
synoshare --add "${SHARE_NAME}" "Share created for package ${SYNOPKG_PKGNAME}" "${SHARE_PATH}" "" "" "" 1 0 2>&1 | install_log
else
install_log "Share already exists SHARE_NAME=${SHARE_NAME}, SHARE_PATH=${SHARE_PATH}"
fi

$MKDIR "${SHARE_PATH}"
# Add user permission if no GROUP is set in service-setup
# GROUP permission will be added in set_syno_permissions
if [ -z "$GROUP" ] && [ -n "${EFF_USER}" ]; then
# check whether user is already added to RW users
_synoshare_parameter="--getmap"
if synoshare --getmap "${SHARE_NAME}" | grep "ACL.*\[yes\]" > /dev/null 2>&1; then
_synoshare_parameter="--list_acl"
fi
if synoshare ${_synoshare_parameter} "${SHARE_NAME}" | grep "RW list" | grep -o "\[.*\]" | sed 's/[\[,]/ /g' | sed 's/\]/ /g' | grep -q " ${EFF_USER} " > /dev/null 2>&1; then
install_log "User has already RW access to share: SHARE_NAME=${SHARE_NAME}, EFF_USER=${EFF_USER}"
else
install_log "Set user for share: SHARE_NAME=${SHARE_NAME}, EFF_USER=${EFF_USER}"
synoshare --setuser "${SHARE_NAME}" RW + "${EFF_USER}" 2>&1 | install_log
fi
fi
synoshare --build 2>&1 | install_log

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

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

call_func "save_wizard_variables" install_log
# Restrict permissions to protect sensitive options
if [ -e "${INST_VARIABLES}" ]; then
chmod go-rwx ${INST_VARIABLES}
chown ${EFF_USER} ${INST_VARIABLES}
fi

call_func "service_postinst" install_log

call_func "service_clean_tmpdir" install_log

if [ -n "${LOG_FILE}" ]; then
Expand All @@ -317,6 +330,7 @@ preuninst ()
log_step "preuninst"
call_func "validate_preuninst"
call_func "service_preuninst" install_log

exit 0
}

Expand All @@ -340,6 +354,7 @@ postuninst ()
if [ "${SYNOPKG_PKG_STATUS}" == "UNINSTALL" ]; then
$RM "${INST_VARIABLES}" 2>&1 | install_log
fi

exit 0
}

Expand All @@ -358,6 +373,7 @@ preupgrade ()
# Beware of /. outside the quotes
# Needed to copy all files including hidden ones
$CP "${SYNOPKG_PKGVAR}"/. "$TMP_DIR" 2>&1 | install_log

exit 0
}

Expand Down
Loading