diff --git a/cross/synology-autorun/Makefile b/cross/synology-autorun/Makefile new file mode 100644 index 00000000000..75f275c17c8 --- /dev/null +++ b/cross/synology-autorun/Makefile @@ -0,0 +1,23 @@ +PKG_NAME = synology-autorun +PKG_VERS = 1.10.0 +PKG_EXT = tar.gz +PKG_DIST_NAME = V$(PKG_VERS).$(PKG_EXT) +PKG_DIST_SITE = https://github.com/schmidhorst/synology-autorun/archive +PKG_DIST_FILE = $(PKG_NAME)-$(PKG_VERS).$(PKG_EXT) +PKG_DIR = $(PKG_NAME)-$(PKG_VERS) + +DEPENDS = + +HOMEPAGE = https://github.com/schmidhorst/synology-autorun +COMMENT = Executes a script on external drive \(USB / eSATA\) when it\'s connected to the disk station. +LICENSE = 3-clause BSD + +INSTALL_TARGET = synology-autorun_install + +include ../../mk/spksrc.install-resources.mk + +.PHONY: synology-autorun_install +synology-autorun_install: + @$(MSG) Extract the whole package + @install -d -m 755 $(STAGING_INSTALL_PREFIX)/$(PKG_NAME) + tar -cf - -C $(WORK_DIR)/$(PKG_DIR) . | tar -xf - -C $(STAGING_INSTALL_PREFIX)/$(PKG_NAME) diff --git a/cross/synology-autorun/PLIST b/cross/synology-autorun/PLIST new file mode 100644 index 00000000000..e69de29bb2d diff --git a/cross/synology-autorun/digests b/cross/synology-autorun/digests new file mode 100644 index 00000000000..a0dd5fee6ba --- /dev/null +++ b/cross/synology-autorun/digests @@ -0,0 +1,3 @@ +synology-autorun-1.10.0.tar.gz SHA1 67a8d2269908210a1cd94f493fde3fd0c9db3675 +synology-autorun-1.10.0.tar.gz SHA256 a2822dd2e5e417da661f487860779c741c8e84008f6a60d47f8a7fefb7f2c3c6 +synology-autorun-1.10.0.tar.gz MD5 e89de823634797512d309d7ecec68dc0 diff --git a/mk/spksrc.service.mk b/mk/spksrc.service.mk index cc7fb8eaef8..e2eaf09c707 100644 --- a/mk/spksrc.service.mk +++ b/mk/spksrc.service.mk @@ -418,6 +418,11 @@ endif ifeq ($(strip $(SERVICE_TYPE)),) SERVICE_TYPE=url endif +ifneq ($(strip $(DSM_APP_NAME)),) + SPK_APPNAME = $(DSM_APP_NAME) +else + SPK_APPNAME = com.synocommunity.packages.$(SPK_NAME) +endif DESC=$(shell echo ${DESCRIPTION} | sed -e 's/\\//g' -e 's/"/\\"/g') $(STAGING_DIR)/$(DSM_UI_DIR)/config: @@ -427,7 +432,7 @@ ifneq ($(wildcard $(DSM_UI_CONFIG)),) else @echo '{}' | jq --arg name "${DISPLAY_NAME}" \ --arg desc "${DESC}" \ - --arg id "com.synocommunity.packages.${SPK_NAME}" \ + --arg id "${SPK_APPNAME}" \ --arg icon "images/${SPK_NAME}-{0}.png" \ --arg prot "${SERVICE_PORT_PROTOCOL}" \ --arg port "${SERVICE_PORT}" \ diff --git a/mk/spksrc.spk.mk b/mk/spksrc.spk.mk index bf80a28f123..a1bc54aee12 100644 --- a/mk/spksrc.spk.mk +++ b/mk/spksrc.spk.mk @@ -150,6 +150,11 @@ ifeq ($(strip $(MAINTAINER)),) $(error Add MAINTAINER for '$(SPK_NAME)' in spk Makefile or set default MAINTAINER in local.mk.) endif +IS_GITHUB_MAINTAINER = 0 +ifeq ($(shell echo "${MAINTAINER}" | wc -w),1) +IS_GITHUB_MAINTAINER = 1 +endif + get_github_maintainer_url = $(shell wget --quiet --spider https://github.com/$(1) && echo "https://github.com/$(1)" || echo "") get_github_maintainer_name = $(shell curl -s -H application/vnd.github.v3+json https://api.github.com/users/$(1) | jq -r '.name' | sed -e 's|null||g' | sed -e 's|^$$|$(1)|g' ) @@ -172,7 +177,11 @@ $(WORK_DIR)/INFO: /bin/echo -n "$(DESCRIPTION_$(shell echo $(LANGUAGE) | tr [:lower:] [:upper:]))" | sed -e 's/"/\\\\\\"/g' && \ /bin/echo -n "\\\"\\\n")) | sed -e 's/ description_/description_/g' >> $@ @echo arch=\"$(SPK_ARCH)\" >> $@ +ifeq ($(IS_GITHUB_MAINTAINER),1) @echo maintainer=\"$(call get_github_maintainer_name,$(MAINTAINER))\" >> $@ +else + @echo maintainer=\"$(MAINTAINER)\" >> $@ +endif ifeq ($(strip $(MAINTAINER_URL)),) @echo maintainer_url=\"$(call get_github_maintainer_url,$(MAINTAINER))\" >> $@ else diff --git a/spk/autorun/Makefile b/spk/autorun/Makefile new file mode 100644 index 00000000000..c4c9efc137a --- /dev/null +++ b/spk/autorun/Makefile @@ -0,0 +1,53 @@ +SPK_NAME = autorun +SPK_VERS = 1.10.0 +SPK_REV = 11 +SPK_ICON = src/synology-autorun.png +DSM_UI_DIR = ui + +DEPENDS = cross/synology-autorun + +MAINTAINER = "Jan Reidemeister, Horst Schmid" +MAINTAINER_URL = https://github.com/schmidhorst/synology-autorun + +DESCRIPTION = Executes a script on external drive \(USB / eSATA\) when it\'s connected to the disk station. +DISPLAY_NAME = Autorun +CHANGELOG = "Initial package hosted by SynoCommunity
For full changelog see https://github.com/schmidhorst/synology-autorun/blob/main/CHANGELOG" + +HOMEPAGE = https://github.com/schmidhorst/synology-autorun +LICENSE = 3-clause BSD + +# Pure script package, make sure ARCH is not defined +override ARCH= + +CONF_DIR = $(STAGING_INSTALL_PREFIX)/synology-autorun/conf +WIZARDS_DIR = $(STAGING_INSTALL_PREFIX)/synology-autorun/WIZARD_UIFILES +SSS_SCRIPT = $(STAGING_INSTALL_PREFIX)/synology-autorun/scripts/start-stop-status +SERVICE_SETUP = src/service-setup.sh + +COPY_TARGET = autorun_install + +include ../../mk/spksrc.spk.mk + +# cht, krn, nor are not (yet) supported. +SPK_LANGUAGES = chs cht csy dan enu fre ger hun ita jpn nld plk ptb ptg rus spn sve trk +# we must escape parentheses and single quote characters for variables holding the description +SUBSTITUTION = -e 's/(/\\\(/g' -e 's/)/\\\)/g' -e s/\'/\\\\\'/g + +.PHONY: define_descriptions +define_descriptions: + @$(MSG) Define language dependent descriptions + $(foreach LANG, $(SPK_LANGUAGES), $(eval DESCRIPTION_$(shell echo $(LANG) | tr [:lower:] [:upper:]) := "$(shell grep descriptionINFO $(STAGING_INSTALL_PREFIX)/synology-autorun/package/ui/texts/$(LANG)/lang.txt | sed $(SUBSTITUTION) | cut -f2 -d=)")) + +.PHONY: autorun_install +autorun_install: define_descriptions + @$(MSG) Install package resources + @install -m 755 -d $(STAGING_DIR)/app $(STAGING_DIR)/../WIZARD_UIFILES + @tar -cf - -C $(STAGING_INSTALL_PREFIX)/synology-autorun/package . | tar -xf - -C $(STAGING_DIR) + @$(MSG) temporary fix: overwrite corrupt icons + @tar -cf - -C src/images . | tar -xf - -C $(STAGING_DIR)/ui/images + @chmod 755 -R $(STAGING_DIR)/ui + @$(MSG) Patch the application name + @sed -e s/SYNO.SDS._ThirdParty.App.autorun/com.synocommunity.packages.autorun/g -i $(STAGING_DIR)/ui/config + @$(MSG) Copy additional wizard files + @cp -p $(STAGING_INSTALL_PREFIX)/synology-autorun/WIZARD_UIFILES/initial_config.txt $(STAGING_DIR)/../WIZARD_UIFILES/ + @cp -p $(STAGING_INSTALL_PREFIX)/synology-autorun/WIZARD_UIFILES/*.json $(STAGING_DIR)/../WIZARD_UIFILES/ diff --git a/spk/autorun/src/images/icon_128.png b/spk/autorun/src/images/icon_128.png new file mode 100644 index 00000000000..0866cd62b67 Binary files /dev/null and b/spk/autorun/src/images/icon_128.png differ diff --git a/spk/autorun/src/images/icon_256.png b/spk/autorun/src/images/icon_256.png new file mode 100644 index 00000000000..1f4330eb9cf Binary files /dev/null and b/spk/autorun/src/images/icon_256.png differ diff --git a/spk/autorun/src/images/icon_32.png b/spk/autorun/src/images/icon_32.png new file mode 100644 index 00000000000..8f2ce3974c5 Binary files /dev/null and b/spk/autorun/src/images/icon_32.png differ diff --git a/spk/autorun/src/images/icon_64.png b/spk/autorun/src/images/icon_64.png new file mode 100644 index 00000000000..adc9cc01a39 Binary files /dev/null and b/spk/autorun/src/images/icon_64.png differ diff --git a/spk/autorun/src/service-setup.sh b/spk/autorun/src/service-setup.sh new file mode 100644 index 00000000000..77d18092fa9 --- /dev/null +++ b/spk/autorun/src/service-setup.sh @@ -0,0 +1,181 @@ +# should be migrated to ${SYNOPKG_PKGTMP} +LOG="/var/tmp/${SYNOPKG_PKGNAME}.log" +DTFMT="+%Y-%m-%d %H:%M:%S" +CURRENT_USER=$(whoami) +SCRIPTPATHTHIS="$(cd -- "$(dirname "${0}")" >/dev/null 2>&1 ; pwd -P )" + + +# service_preinst is obsolete. +# the DSM package installer already prevents to install when DSM version is less than os_min_ver. + + +service_postinst () +{ + echo "$(date "${DTFMT}"): postinst V${SYNOPKG_PKGVER} started as user '${CURRENT_USER}' ...
" >> "${LOG}" + + # need to fetch values entered by user from environment and put to the strings file for each language + # configFilePathName="$(dirname "$0")/initial_config.txt" is no more available! + items="$(env | grep "^config_")" + + # keys="config_WAIT config_BEEP config_LED_COPY config_EJECT_TIMEOUT config_LOG_MAX_LINES config_NOTIFY_USERS config_LOGLEVEL" + mapfile -t itemArray < <(/bin/printf '%s' "${items}") + + # echo "$(date "${DTFMT}"): Config-Items from ENV: '${itemArray[*]}'" >> "${LOG}" + # config_LED, Status LED usage: + # 0 = not used, + # 1 = orange while script is running, green when done, + # 2 = orange flashing if script result is neither 0 nor 100, + # 3 = orange while running, flashing if neither 0 nor 100, else green + + # config_LED_COPY, Copy LED usage: + # 0 = not used, + # 1 = on while script is running, off after end, + # 2 = flashing while script is running, off after the end, + # 4 = flashing if script result is neither 0 nor 100, + # 5 = on while running, flashing if script result is neither 0 nor 100, else off after end. + + # config_ADD_NEW_FINGERPRINTS, Security configuration: + # 0 = unrestricted, no hash check + # 1 = clear hash list now and register the hash of each newly executed script, + # 2 = allow only previously registered hashes, + # 3 = register the new onces + echo "$(date "${DTFMT}"): postinst: SYNOPKG_OLD_PKGVER='${SYNOPKG_OLD_PKGVER}', SYNOPKG_PKGVER='${SYNOPKG_PKGVER}'" >> "${LOG}" + rm -f "${SYNOPKG_PKGVAR}/config" + echo "$(date "${DTFMT}"): file pathName: '${SYNOPKG_PKGVAR}/config' will be generated now ...
" >> "${LOG}" + + # Messages (send to ${SYNOPKG_TEMP_LOGFILE}) are not shown up!? ==> Do the checks in start-stop-status + # If terminated with "exit 1" then the old setting are lost. ==> Do the checks in start-stop-status + # 1) Is the ${config_SCRIPT_AFTER_EJECT} file available, and has it correct line break and UTF8-Coding? + # 2) is user or group config_NOTIFY_USERS valid? Check for valid entry requires root access and is done in the start-stop-status script + + msg="" + for item in "${itemArray[@]}"; do + # eval "${item}" # e.g. ", config_NO_DSM_MESSAGE_RETURN_CODES='98'", the ";99" is lost!??? + key="${item%%=*}" + # Some values with, some without quotes, remove them: + val="$(sed -e 's/^\"//' -e 's/\"$//' <<<"${item#*=}")" + key2=${key#*config_} + if [[ -n "${key2}" ]]; then + echo "${key2}=\"${val}\"" >> "${SYNOPKG_PKGVAR}/config" + fi + # echo "${item}: ${key2}=\"${val}\"" >> "${LOG}" + msg="${msg} ${key2}='${val}'" + done + echo "$(date "${DTFMT}"): from ENV extracted: ${msg}" >> "${LOG}" + if [[ "${config_ADD_NEW_FINGERPRINTS}" -eq "1" ]]; then + KNOWNSCRIPTSFILEPATHNAME="${SYNOPKG_PKGVAR}/FINGERPRINTS" + res=$(rm -f "${KNOWNSCRIPTSFILEPATHNAME}") + ret=$? + echo "$(date "${DTFMT}"): Deletion of old fingerprints: ${ret}, ${res}" >> "${LOG}" + fi + + chmod 755 "${SYNOPKG_PKGVAR}/config" + # Distinguish between a) new Installation, b) upgrade or c) change of settings + action="Installation, upgrade or change of settings" + if [[ -z "${SYNOPKG_OLD_PKGVER}" ]]; then + action="Installation of V${SYNOPKG_PKGVER}" + elif [[ "${SYNOPKG_OLD_PKGVER}" == "${SYNOPKG_PKGVER}" ]]; then + action="Re-Installation (change of settings) of V${SYNOPKG_PKGVER}" + else + action="Upgrade from V${oldVers} to V${SYNOPKG_PKGVER}" + fi + + if [[ "${config_ADD_NEW_FINGERPRINTS}" -eq "1" ]]; then + echo "$(date "${DTFMT}"): ${action} done, previously registered script fingerprints deleted, not yet started" >> "${SYNOPKG_PKGVAR}/execLog" + else + echo "$(date "${DTFMT}"): ${action} done, not yet started" >> "${SYNOPKG_PKGVAR}/execLog" + fi + echo "$(date "${DTFMT}"): postinst done, not yet started, ${SYNOPKG_PKGNAME} installed
" >> "${LOG}" +} + +service_preupgrade () +{ + echo -e "\n$(date "${DTFMT}"): $0 (${SYNOPKG_PKGVER}) started with account '${CURRENT_USER}' ..." >> "${LOG}" + # preupgrade starts from an temporary folder like /volume1/@tmp/synopkg/install.XDdQUB/scripts/preupgrade + # Attention: if in the WIZARD_UIFILES folder a script is used for a dynamic ..._uifile, then it's not allowed to write here somthing to ${SYNOPKG_TEMP_LOGFILE} !!! + + #Developer Guide 7, Page 54, Script Execution Order + # Upgrade Installation Uninstall + # ------------------------------------------------------------------------------------------ + # newScript upgrade_uifile.sh install_uifile.sh uninstall_uifile.sh (if available) + # oldScript start-stop prestop (if running) start-stop prestop (if running) + # oldScript start-stop stop (if running) start-stop stop (if running) + # newScript preupgrade + # oldScript preuninst preuninst + # @appstore/ and @apptemp/ are deleted + # oldScript postuninst postuninst + # newScript prereplace?? prereplace?? + # newScript preinst preinst + # newScript postinst postinst + # newScript postreplace + # newScript postupgrade + # newScript start-stop prestart start-stop prestart + # newScript start-stop start start-stop start + + # tempStorageFolder="${SYNOPKG_TEMP_UPGRADE_FOLDER}/usersettings" # alternative temp folder (DemoUiSpk7) + # /volumeX/@appdata/ (= /var/packages//var) is preserved during upgrade! + # So there is no need for an temporary stprage folder. + + echo "$(date "${DTFMT}"): ... preupgrade done
" >> "${LOG}" +} + +service_postupgrade () +{ + echo "$(date "${DTFMT}"): postupgrade V${SYNOPKG_PKGVER} started ...
" >> "${LOG}" + if [[ ! -f "${SYNOPKG_PKGVAR}/config" ]]; then # not e.g. preserved from uninstall + tempStorageFolder="/tmp/net.reidemeister.${SYNOPKG_PKGNAME}" + if [ -d "${tempStorageFolder}" ]; then + echo "$(date "${DTFMT}"): temp data folder $}tempStorageFolder} found
" >> "${LOG}" + # restore log + if [ -f "${tempStorageFolder}/log" ]; then + (cp -v "${tempStorageFolder}/log" "${SYNOPKG_PKGVAR}") 2>&1 >> "${LOG}" + echo "$(date "${DTFMT}"): temp logfile copied
" >> "${LOG}" + fi + # clean-up + rm -r ${tempStorageFolder} + fi + fi + echo "$(date "${DTFMT}"): ... postupgrade done
" >> "${LOG}" +} + +post_uninst () +{ + echo "$(date "${DTFMT}"): postuninst V${SYNOPKG_PKGVER} started as ${CURRENT_USER}...
" >> "${LOG}" + # echo "$(date "${DTFMT}"): p0='$0'" >> "${LOG}" # ${app_name} is empty!! + configFilePathName="${SYNOPKG_PKGVAR}/config" # ${SYNOPKG_PKGVAR} is /volume1/@appdata/autorun and is o.k., still available + # echo "$(date "${DTFMT}"): configFilePathName='${configFilePathName}'" >> "${LOG}" + # after uninstall is /var/packages/${SYNOPKG_PKGNAME} no more available, only /volume1/@appdata/autorun !!! + # Attention: If a new version is installed, then this file from the old version + # is executed before the preinst of the new version! + if [[ "${pkgwizard_remove_settings}" == "true" ]] || [[ "${pkgwizard_remove_settings}" == "false" ]]; then + # WIZZARD_UIFILES/uninstall_uifile_ was done before! So it's a real uninstall, not an upgrade! + if [[ "${bDebug}" -eq "0" ]]; then + rm "${LOG}" + rm "/var/tmp/resource.${SYNOPKG_PKGNAME}.*" + rm "/var/log/packages/${SYNOPKG_PKGNAME}.log" + rm "/var/log/packages/${SYNOPKG_PKGNAME}.log.*.xz" + rm "${SYNOPKG_PKGVAR}/execLog" + # echo "$(date "${DTFMT}"): Old logfiles removed" >> "${LOG}" + else + echo "$(date "${DTFMT}"): Logfiles preserved due to bDebug!=0" >> "${LOG}" + fi + fi + if [[ "${pkgwizard_remove_settings}" == "true" ]]; then + res=$(rm -r --interactive=never "${SYNOPKG_PKGVAR}") # remove folder + ret=$? + # if [[ "${bDebug}" -ne "0" ]]; then + echo "$(date "${DTFMT}"): Result from 'rm -r \"${SYNOPKG_PKGVAR}\"': ${ret}, '${res}'" >> "${LOG}" + # fi + else + if [[ -f "${SYNOPKG_PKGVAR}\config" ]]; then + # put old version to config file, so that postinst can check whether its an upgrade or only settings change + res=$(grep "VERSION=" "${SYNOPKG_PKGVAR}\config") + if [[ -n "${res}" ]]; then + res="$(sed -i "s|^VERSION=.*$|VERSION=\"${SYNOPKG_PKGVAR}\"|" "${SYNOPKG_PKGVAR}\config")" + else + echo "VERSION=\"${SYNOPKG_PKGVAR}\"" >> "${SYNOPKG_PKGVAR}\config" + fi + fi + fi + echo "$(date "${DTFMT}"): ... postuninst done
" >> "${LOG}" +} diff --git a/spk/autorun/src/synology-autorun.png b/spk/autorun/src/synology-autorun.png new file mode 100644 index 00000000000..360633d6763 Binary files /dev/null and b/spk/autorun/src/synology-autorun.png differ