Skip to content

Commit

Permalink
Remove DSM 6 code
Browse files Browse the repository at this point in the history
  • Loading branch information
mreid-tt committed Sep 14, 2024
1 parent 22adedf commit d4d496c
Show file tree
Hide file tree
Showing 9 changed files with 1 addition and 231 deletions.
9 changes: 0 additions & 9 deletions spk/cops/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ DSM_UI_DIR = app
DSM_UI_CONFIG = src/app/config
CONF_DIR = src/conf/

include ../../mk/spksrc.common.mk

# Alternate conf dir for DSM 6
ifeq ($(call version_lt, ${TCVERSION}, 7.0),1)
CONF_DIR = src/conf_6/
endif

SERVICE_USER = auto
SERVICE_SETUP = src/service-setup.sh
STARTABLE = no
Expand All @@ -48,7 +41,5 @@ include ../../mk/spksrc.spk.mk
.PHONY: cops_extra_install
cops_extra_install:
install -m 755 -d $(STAGING_DIR)/web
install -m 644 src/web/cops.conf $(STAGING_DIR)/web/cops.conf
install -m 644 src/web/cops.json $(STAGING_DIR)/web/cops.json
@$(MSG) Install default config file
install -m 666 src/web/config_local.php.synology $(STAGING_DIR)/web/config_local.php.synology
11 changes: 0 additions & 11 deletions spk/cops/src/conf_6/resource

This file was deleted.

133 changes: 1 addition & 132 deletions spk/cops/src/service-setup.sh
Original file line number Diff line number Diff line change
@@ -1,99 +1,13 @@

# Package
PACKAGE="cops"
DNAME="COPS"
SC_PKG_PREFIX="com-synocommunity-packages-"
PACKAGE_NAME="${SC_PKG_PREFIX}${PACKAGE}"

# Others
SYNOSVC="/usr/syno/sbin/synoservice"
WEB_DIR="/var/services/web_packages"
# for backwards compatability
if [ $SYNOPKG_DSM_VERSION_MAJOR -lt 7 ];then
WEB_DIR="/var/services/web"
fi
WEB_ROOT="${WEB_DIR}/${PACKAGE}"

validate_preinst ()
{
# Check for modification to PHP template defaults on DSM 6
if [ ${SYNOPKG_DSM_VERSION_MAJOR} -lt 7 ]; then
WS_TMPL_PATH="/var/packages/WebStation/target/misc"
WS_TMPL_FILE="php74_fpm.mustache"
FULL_WS_TMPL_FILE="${WS_TMPL_PATH}/${WS_TMPL_FILE}"
# Check for PHP template defaults
if ! grep -q -E '^user = http$' "${FULL_WS_TMPL_FILE}" || ! grep -q -E '^listen\.owner = http$' "${FULL_WS_TMPL_FILE}"; then
echo "PHP template defaults have been modified. Installation is not supported."
exit 1
fi
fi
}

service_postinst ()
{
# Web interface setup for DSM 6 -- used by INSTALL and UPGRADE
if [ ${SYNOPKG_DSM_VERSION_MAJOR} -lt 7 ]; then
# Install the web interface
echo "Installing web interface"
${MKDIR} ${WEB_ROOT}
rsync -aX ${SYNOPKG_PKGDEST}/share/${PACKAGE}/ ${WEB_ROOT} 2>&1

# Install web configurations
TEMPDIR="${SYNOPKG_PKGTMP}/web"
${MKDIR} ${TEMPDIR}
WS_CFG_DIR="/usr/syno/etc/packages/WebStation"
WS_CFG_FILE="WebStation.json"
WS_CFG_PATH="${WS_CFG_DIR}/${WS_CFG_FILE}"
TMP_WS_CFG_PATH="${TEMPDIR}/${WS_CFG_FILE}"
PHP_CFG_FILE="PHPSettings.json"
PHP_CFG_PATH="${WS_CFG_DIR}/${PHP_CFG_FILE}"
TMP_PHP_CFG_PATH="${TEMPDIR}/${PHP_CFG_FILE}"
PHP_PROF_NAME="Default PHP 7.4 Profile"
WS_BACKEND="$(jq -r '.default.backend' ${WS_CFG_PATH})"
WS_PHP="$(jq -r '.default.php' ${WS_CFG_PATH})"
RESTART_APACHE="no"
RSYNC_ARCH_ARGS="--backup --suffix=.bak --remove-source-files"
# Check if Apache is the selected back-end
if [ ! "$WS_BACKEND" = "2" ]; then
echo "Set Apache as the back-end server"
jq '.default.backend = 2' ${WS_CFG_PATH} > ${TMP_WS_CFG_PATH}
rsync -aX ${RSYNC_ARCH_ARGS} ${TMP_WS_CFG_PATH} ${WS_CFG_DIR}/ 2>&1
RESTART_APACHE="yes"
fi
# Check if default PHP profile is selected
if [ -z "$WS_PHP" ] || [ "$WS_PHP" = "null" ]; then
echo "Enable default PHP profile"
# Locate default PHP profile
PHP_PROF_ID="$(jq -r '. | to_entries[] | select(.value | type == "object" and .profile_desc == "'"$PHP_PROF_NAME"'") | .key' "${PHP_CFG_PATH}")"
jq ".default.php = \"$PHP_PROF_ID\"" "${WS_CFG_PATH}" > ${TMP_WS_CFG_PATH}
rsync -aX ${RSYNC_ARCH_ARGS} ${TMP_WS_CFG_PATH} ${WS_CFG_DIR}/ 2>&1
RESTART_APACHE="yes"
fi
# Check for PHP profile
if ! jq -e ".[\"${PACKAGE_NAME}\"]" "${PHP_CFG_PATH}" >/dev/null; then
echo "Add PHP profile for ${DNAME}"
jq --slurpfile ocNode ${SYNOPKG_PKGDEST}/web/${PACKAGE}.json '.["'"${PACKAGE_NAME}"'"] = $ocNode[0]' ${PHP_CFG_PATH} > ${TMP_PHP_CFG_PATH}
rsync -aX ${RSYNC_ARCH_ARGS} ${TMP_PHP_CFG_PATH} ${WS_CFG_DIR}/ 2>&1
RESTART_APACHE="yes"
fi
# Check for Apache config
if [ ! -f "/usr/local/etc/apache24/sites-enabled/${PACKAGE}.conf" ]; then
echo "Add Apache config for ${DNAME}"
rsync -aX ${SYNOPKG_PKGDEST}/web/${PACKAGE}.conf /usr/local/etc/apache24/sites-enabled/ 2>&1
RESTART_APACHE="yes"
fi
# Restart Apache if configs have changed
if [ "$RESTART_APACHE" = "yes" ]; then
if jq -e 'to_entries | map(select((.key | startswith("'"${SC_PKG_PREFIX}"'")) and .key != "'"${PACKAGE_NAME}"'")) | length > 0' "${PHP_CFG_PATH}" >/dev/null; then
echo " [WARNING] Multiple PHP profiles detected, will require restart of DSM to load new configs"
else
echo "Restart Apache to load new configs"
${SYNOSVC} --restart pkgctl-Apache2.4
fi
fi
# Clean-up temporary files
${RM} ${TEMPDIR}
fi
# Initialize or update configuration file based on user preferences.
if [ "${SYNOPKG_PKG_STATUS}" = "INSTALL" ]; then
CFG_FILE="${WEB_ROOT}/config_local.php"
Expand All @@ -110,51 +24,6 @@ service_postinst ()
fi
}

service_postuninst ()
{
# Web interface removal for DSM 6 -- used by UNINSTALL and UPGRADE
if [ ${SYNOPKG_DSM_VERSION_MAJOR} -lt 7 ]; then
# Remove the web interface
echo "Removing web interface"
${RM} ${WEB_ROOT}

# Remove web configurations
TEMPDIR="${SYNOPKG_PKGTMP}/web"
${MKDIR} ${TEMPDIR}
WS_CFG_DIR="/usr/syno/etc/packages/WebStation"
PHP_CFG_FILE="PHPSettings.json"
PHP_CFG_PATH="${WS_CFG_DIR}/${PHP_CFG_FILE}"
TMP_PHP_CFG_PATH="${TEMPDIR}/${PHP_CFG_FILE}"
RESTART_APACHE="no"
RSYNC_ARCH_ARGS="--backup --suffix=.bak --remove-source-files"
# Check for PHP profile
if jq -e ".[\"${PACKAGE_NAME}\"]" "${PHP_CFG_PATH}" >/dev/null; then
echo "Removing PHP profile for ${DNAME}"
jq 'del(.["'"${PACKAGE_NAME}"'"])' ${PHP_CFG_PATH} > ${TMP_PHP_CFG_PATH}
rsync -aX ${RSYNC_ARCH_ARGS} ${TMP_PHP_CFG_PATH} ${WS_CFG_DIR}/ 2>&1
${RM} "${WS_CFG_DIR}/php_profile/${PACKAGE_NAME}"
RESTART_APACHE="yes"
fi
# Check for Apache config
if [ -f "/usr/local/etc/apache24/sites-enabled/${PACKAGE}.conf" ]; then
echo "Removing Apache config for ${DNAME}"
${RM} /usr/local/etc/apache24/sites-enabled/${PACKAGE}.conf
RESTART_APACHE="yes"
fi
# Restart Apache if configs have changed
if [ "$RESTART_APACHE" = "yes" ]; then
if jq -e 'to_entries | map(select((.key | startswith("'"${SC_PKG_PREFIX}"'")) and .key != "'"${PACKAGE_NAME}"'")) | length > 0' "${PHP_CFG_PATH}" >/dev/null; then
echo " [WARNING] Multiple PHP profiles detected, will require restart of DSM to load new configs"
else
echo "Restart Apache to load new configs"
${SYNOSVC} --restart pkgctl-Apache2.4
fi
fi
# Clean-up temporary files
${RM} ${TEMPDIR}
fi
}

service_save ()
{
# Save some stuff
Expand All @@ -172,7 +41,7 @@ service_restore ()
# Restore some stuff
echo "Restore previous data from ${SYNOPKG_TEMP_UPGRADE_FOLDER}/${PACKAGE}"
# Restore cops configuration file
rsync -aX --update -I ${SYNOPKG_TEMP_UPGRADE_FOLDER}/${PACKAGE}/web/config_local.php ${WEB_ROOT}/config_local.php 2>&1
rsync -aX -I ${SYNOPKG_TEMP_UPGRADE_FOLDER}/${PACKAGE}/web/config_local.php ${WEB_ROOT}/config_local.php 2>&1
else
# Backup missing, re-initialise default values
CFG_FILE="${WEB_ROOT}/config_local.php"
Expand Down
16 changes: 0 additions & 16 deletions spk/cops/src/web/cops.conf

This file was deleted.

25 changes: 0 additions & 25 deletions spk/cops/src/web/cops.json

This file was deleted.

28 changes: 0 additions & 28 deletions spk/cops/src/wizard_templates/install_uifile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,6 @@ page_append ()
fi
}

# Check for multiple PHP profiles
check_php_profiles ()
{
PACKAGE="cops"
SC_PKG_PREFIX="com-synocommunity-packages-"
PACKAGE_NAME="${SC_PKG_PREFIX}${PACKAGE}"
PHP_CFG_PATH="/usr/syno/etc/packages/WebStation/PHPSettings.json"
if [ "${SYNOPKG_DSM_VERSION_MAJOR}" -lt 7 ] && \
jq -e 'to_entries | map(select((.key | startswith("'"${SC_PKG_PREFIX}"'")) and .key != "'"${PACKAGE_NAME}"'")) | length > 0' "${PHP_CFG_PATH}" >/dev/null; then
return 0 # true
else
return 1 # false
fi
}

PAGE_ADMIN_CONFIG=$(/bin/cat<<EOF
{
"step_title": "{{{COPS_CONFIGURATION_FIRST_STEP_TITLE}}}",
Expand Down Expand Up @@ -83,22 +68,9 @@ PAGE_ADMIN_CONFIG=$(/bin/cat<<EOF
EOF
)

PAGE_PHP_PROFILES=$(/bin/cat<<EOF
{
"step_title": "{{{PHP_PROFILES_TITLE}}}",
"items": [{
"desc": "{{{PHP_PROFILES_DESCRIPTION}}}"
}]
}
EOF
)

main () {
local install_page=""
install_page=$(page_append "$install_page" "$PAGE_ADMIN_CONFIG")
if check_php_profiles; then
install_page=$(page_append "$install_page" "$PAGE_PHP_PROFILES")
fi
echo "[$install_page]" > "${SYNOPKG_TEMP_LOGFILE}"
}

Expand Down
3 changes: 0 additions & 3 deletions spk/cops/src/wizard_templates/install_uifile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,3 @@ DO_YOU_WANT_TO_USE_COPS_WITH_A_KOBO_LABEL: "Kobo"

DSM_PERMISSIONS_TITLE: "Attention! DSM Permissions"
DSM_PERMISSIONS_TEXT: "Package user and group will not appear on most UI settings. Please read <a target=\\\"_blank\\\" href=\\\"https://github.com/SynoCommunity/spksrc/wiki/Permission-Management\\\">Permission Management</a> for details."

PHP_PROFILES_TITLE: "Multiple PHP profiles"
PHP_PROFILES_DESCRIPTION: "Attention: Multiple PHP profiles detected; the package webpage will not display until a DSM restart is performed to load new configurations."
3 changes: 0 additions & 3 deletions spk/cops/src/wizard_templates/install_uifile_fre.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,3 @@ DO_YOU_WANT_TO_USE_COPS_WITH_A_KOBO_LABEL: "Kobo"

DSM_PERMISSIONS_TITLE: "Attention! DSM Permissions"
DSM_PERMISSIONS_TEXT: "L'utilisateur et le group du package n'apparaîtront pas sur la plupart des UI réglages. Veuillez vous référrer à <a target=\\\"_blank\\\" href=\\\"https://github.com/SynoCommunity/spksrc/wiki/Permission-Management\\\">Permission Management</a> pour plus de détails."

PHP_PROFILES_TITLE: "Plusieurs profils PHP"
PHP_PROFILES_DESCRIPTION: "Attention : Plusieurs profils PHP détectés ; la page Web du package ne s'affichera pas tant qu'un redémarrage de DSM n'aura pas été effectué pour charger de nouvelles configurations."
4 changes: 0 additions & 4 deletions spk/cops/src/wizard_templates/upgrade_uifile.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#!/bin/bash

WEB_DIR="/var/services/web_packages"
# for backwards compatability
if [ "${SYNOPKG_DSM_VERSION_MAJOR}" -lt 7 ]; then
WEB_DIR="/var/services/web"
fi

quote_json ()
{
Expand Down

0 comments on commit d4d496c

Please sign in to comment.