From ec9d4d368c3bb300f048db3b46774cefa4031422 Mon Sep 17 00:00:00 2001 From: hgy59 Date: Fri, 5 Aug 2022 22:05:57 +0200 Subject: [PATCH] demoservice: update shared folder creation - use resource worker to create shared folder - adjust wizards for shared folder creation - create readme.html that can be opened in the browser - create dummy file as for DSM7 we cannot create packages without content (since #5163: Fully use DSM7 var directory) --- spk/demoservice/Makefile | 32 ++++---- spk/demoservice/PLIST | 3 +- spk/demoservice/src/conf/resource | 18 +++- spk/demoservice/src/service-setup.sh | 14 ++-- spk/demoservice/src/wizard/install_uifile | 91 +++++++++++++++------ spk/demoservice/src/wizard/uninstall_uifile | 48 ++++++----- 6 files changed, 136 insertions(+), 70 deletions(-) diff --git a/spk/demoservice/Makefile b/spk/demoservice/Makefile index d084e905601..893fc60cef3 100644 --- a/spk/demoservice/Makefile +++ b/spk/demoservice/Makefile @@ -7,26 +7,28 @@ SPK_ICON = src/demoservice.png override ARCH= MAINTAINER = ymartin59 -DESCRIPTION = Demonstration package to show installer script capabilities when requiring non-root user for background service.
Further more this package creates a demo MySQL database. Upon deinstallation the demo database and/or user can be kept or droped. -DISPLAY_NAME = DemoService -CHANGELOG = "1. Update with new installer logs
2. Update for DSM7.
3. Add db creation demo." +DESCRIPTION = Demonstration package to show installer script capabilities when requiring non-root user for background service. Further more this package creates a demo MySQL database. Upon deinstallation the demo database and/or user can be kept or droped. +DISPLAY_NAME = Demo Service +CHANGELOG = "1. Update with new installer logs.
2. Update for DSM7.
3. Add db creation demo." LICENSE = GPLv2 WIZARDS_DIR = src/wizard/ + # The demo database is created by definitions in conf/resource and controlled by wizard variables. -CONF_DIR = src/conf/ +CONF_DIR = src/conf/ # 'auto' reserved value grabs SPK_NAME -SERVICE_USER = auto +SERVICE_USER = auto SERVICE_WIZARD_GROUP = wizard_group -SERVICE_WIZARD_SHARE = wizard_download_dir -SERVICE_SETUP = src/service-setup.sh -STARTABLE = yes +SERVICE_WIZARD_SHARE = wizard_data_folder +USE_DATA_SHARE_WORKER = yes +SERVICE_SETUP = src/service-setup.sh +STARTABLE = yes # Service configuration SERVICE_PORT = 8888 -SERVICE_PORT_TITLE = DemoService(HTTP) +SERVICE_PORT_TITLE = Demo Service (HTTP) # Admin link ADMIN_PORT = $(SERVICE_PORT) @@ -38,8 +40,10 @@ include ../../mk/spksrc.spk.mk .PHONY: demoservice_install # Replace standard copy/install targets, no sources, no content demoservice_pre_copy: - rm -rf $(STAGING_DIR) - mkdir $(STAGING_DIR) - mkdir --parents $(STAGING_INSTALL_PREFIX)/var - echo "No files package with MySQL DB creation." > $(STAGING_INSTALL_PREFIX)/var/README - + @rm -rf $(STAGING_INSTALL_PREFIX) + @mkdir --parents $(STAGING_INSTALL_PREFIX)/var + @echo -e "dummy file to avoid empty package.\n" > $(STAGING_INSTALL_PREFIX)/dummy.txt + @echo "

Demo Service

" > $(STAGING_INSTALL_PREFIX)/var/readme.html + @echo "

DemoService is a package without further files.

" >> $(STAGING_INSTALL_PREFIX)/var/readme.html + @echo "

A demo MySQL/MariaDB database is created.
" >> $(STAGING_INSTALL_PREFIX)/var/readme.html + @echo "Database credentials are stored in var/demoservice.ini.

" >> $(STAGING_INSTALL_PREFIX)/var/readme.html diff --git a/spk/demoservice/PLIST b/spk/demoservice/PLIST index 5c6be48927b..a32c01b5028 100644 --- a/spk/demoservice/PLIST +++ b/spk/demoservice/PLIST @@ -1 +1,2 @@ -rsc:var/README +rsc:dummy.txt +rsc:var/readme.html diff --git a/spk/demoservice/src/conf/resource b/spk/demoservice/src/conf/resource index 17e10b09255..64b27bac43a 100644 --- a/spk/demoservice/src/conf/resource +++ b/spk/demoservice/src/conf/resource @@ -1,15 +1,27 @@ { + "data-share": { + "shares": [{ + "name": "{{wizard_data_folder}}", + "permission": { + "rw": [ + "sc-demoservice", + "{{wizard_group}}" + ] + } + } + ] + }, "mysql-db": { "info": { "db-name": "demoservice" }, "root-pw": "{{wizard_mysql_password_root}}", - "create-db" : { + "create-db": { "db-collision": "skip" }, "grant-user": { - "user-name" : "demoservice", - "rand-pw" : true + "user-name": "demoservice", + "user-pw": "{{wizard_mysql_password_user}}" }, "drop-db-uninst": "{{wizard_mysql_drop_database}}", "drop-user-uninst": "{{wizard_mysql_drop_db_user}}" diff --git a/spk/demoservice/src/service-setup.sh b/spk/demoservice/src/service-setup.sh index f3b535c2245..a829955df64 100644 --- a/spk/demoservice/src/service-setup.sh +++ b/spk/demoservice/src/service-setup.sh @@ -7,7 +7,7 @@ PYTHON_VERSION=$(python --version 2>&1) PYTHON_MAJOR_VERSION=$(echo ${PYTHON_VERSION} | cut -d ' ' -f2 | cut -d . -f1) if [ "${PYTHON_MAJOR_VERSION}" == "3" ]; then -SERVER_MODULE="http.server" + SERVER_MODULE="http.server" fi @@ -69,16 +69,20 @@ service_preinst () service_postinst () { echo "service_postinst ${SYNOPKG_PKG_STATUS}" - echo "# Database created with random password:" > ${DEMOSERVICE_INI} - echo "${SYNOPKG_DB_USER_RAND_PW}" >> ${DEMOSERVICE_INI} + echo "# Database credentials" > ${DEMOSERVICE_INI} + echo "password: ${wizard_mysql_password_user}" >> ${DEMOSERVICE_INI} + echo "" >> ${DEMOSERVICE_INI} + echo "# Shared folder" >> ${DEMOSERVICE_INI} + echo "folder: ${wizard_data_volume}/${wizard_data_folder}" >> ${DEMOSERVICE_INI} echo "ini file created: ${DEMOSERVICE_INI}" } service_preuninst () { echo "service_preuninst ${SYNOPKG_PKG_STATUS}" - echo "wizard_mysql_drop_database = ${wizard_mysql_drop_database}" >> $INST_LOG - echo "wizard_mysql_drop_db_user = ${wizard_mysql_drop_db_user}" >> $INST_LOG + echo "wizard_mysql_drop_database = ${wizard_mysql_drop_database}" + echo "wizard_mysql_drop_db_user = ${wizard_mysql_drop_db_user}" + echo "wizard_mysql_create_backup = ${wizard_mysql_create_backup}" } service_postuninst () diff --git a/spk/demoservice/src/wizard/install_uifile b/spk/demoservice/src/wizard/install_uifile index 8744e02b048..0ebf74205a8 100644 --- a/spk/demoservice/src/wizard/install_uifile +++ b/spk/demoservice/src/wizard/install_uifile @@ -1,24 +1,56 @@ -[ - { - "step_title": "Example configuration for demoservice", - "items": [ - { +[{ + "step_title": "Shared folder configuration", + "items": [{ + "type": "combobox", + "desc": "Please select a volume to use for the data folder", + "subitems": [{ + "key": "wizard_data_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 configuration", - "subitems": [ - { - "key": "wizard_download_dir", - "desc": "Download location", - "defaultValue": "/volume1/downloads", + "desc": "Shared folder. This must be a name for the shared folder only, without any path. This share is created at installation when it does not already exist.", + "subitems": [{ + "key": "wizard_data_folder", + "desc": "Shared folder", + "defaultValue": "demo-downloads", "validator": { "allowBlank": false, "regex": { - "expr": "/^\\\/volume[0-9]{1,2}\\\/[^<>: */?\"]*/", - "errorText": "Path should begin with /volume?/ where ? is volume number (1-99)" + "expr": "/^[^<>: */?\"]*/", + "errorText": "Share name must be a folder name only. Path separators, spaces and other special chars are not allowed." } } - }, - { + } + ] + }, { + "type": "textfield", + "desc": "Define a group to access files in the shared folder defined above.", + "subitems": [{ "key": "wizard_group", "desc": "DSM group", "defaultValue": "sc-download", @@ -33,26 +65,33 @@ ] } ] - }, - { + }, { "step_title": "DSM Permissions", - "items": [ - { - "desc": "Permissions are managed with the group 'sc-download' in DSM.
The group 'users' is no longer used as of DSM 6.
Package user (= demoservice) will not appear on most UI settings.
Including the following:
- Application privilege's permission viewer
- FPT's chroot user selector
- File Stations's
- Change owner
- Shared Links Manager -> Enable secure sharing

The only exceptions are:
- Control Panel > Shared Folder > Edit > Permission > System internal user
- ACL editor
" + "items": [{ + "desc": "Permissions in DSM are restricted to group defined in the previous step (default: 'sc-download').
The group 'users' is no longer used as of DSM 6+.
Package user ('sc-demoservice') will not appear on most UI settings.
Including the following:
- Application privilege's permission viewer
- FPT's chroot user selector
- File Stations's
- Change owner
- Shared Links Manager -> Enable secure sharing

The only exceptions are:
- Control Panel > Shared Folder > Edit > Permission > System internal user
- ACL editor
" } ] - }, - { - "step_title": "Create MySQL Demo Database", + }, { + "step_title": "MySQL Demo Database", "items": [{ "desc": "This package creates a demo database 'demoservice' and a db user 'demoservice' with full access to this database. The password for the db user is randomly generated by DSM and is stored in the file demoservice.ini by package specific install function.
" - },{ + }, { "type": "password", "desc": "Enter your MySQL root password", "subitems": [{ "key": "wizard_mysql_password_root", "desc": "MySQL root password" - }] - }] + } + ] + }, { + "type": "password", + "desc": "Enter a password for the demoservice db user", + "subitems": [{ + "key": "wizard_mysql_password_user", + "desc": "MySQL user password" + } + ] + } + ] } ] diff --git a/spk/demoservice/src/wizard/uninstall_uifile b/spk/demoservice/src/wizard/uninstall_uifile index 4438820f50d..12869e6e120 100644 --- a/spk/demoservice/src/wizard/uninstall_uifile +++ b/spk/demoservice/src/wizard/uninstall_uifile @@ -1,25 +1,31 @@ -[ - { +[{ "step_title": "MySQL Demo Database", "items": [{ - "type": "password", - "desc": "Enter your MySQL root password if you want to drop the database and/or the db user.", - "subitems": [{ - "key": "wizard_mysql_password_root", - "desc": "MySQL root password" - }] - },{ - "type": "multiselect", - "desc": "Cleanup the Demo Database:", - "subitems": [{ - "key": "wizard_mysql_drop_database", - "desc": "Drop demo database", - "defaultValue": true - },{ - "key": "wizard_mysql_drop_db_user", - "desc": "Drop demo db user", - "defaultValue": true - }] - }] + "type": "password", + "desc": "Enter your MySQL root password if you want to drop the database and/or the db user.", + "subitems": [{ + "key": "wizard_mysql_password_root", + "desc": "MySQL root password" + } + ] + }, { + "type": "multiselect", + "desc": "Cleanup the Demo Database:", + "subitems": [{ + "key": "wizard_mysql_drop_database", + "desc": "Drop demo database", + "defaultValue": true + }, { + "key": "wizard_mysql_drop_db_user", + "desc": "Drop demo db user", + "defaultValue": true + }, { + "key": "wizard_mysql_create_backup", + "desc": "Create a backup of the demo database.", + "defaultValue": true + } + ] + } + ] } ]