Skip to content

Commit

Permalink
demoservice: update shared folder creation
Browse files Browse the repository at this point in the history
- 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 SynoCommunity#5163: Fully use DSM7 var directory)
  • Loading branch information
hgy59 committed Aug 5, 2022
1 parent 8f39109 commit ec9d4d3
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 70 deletions.
32 changes: 18 additions & 14 deletions spk/demoservice/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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. <br>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<br/>2. Update for DSM7.<br/>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.<br/>2. Update for DSM7.<br/>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)
Expand All @@ -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 "<h3>Demo Service</h3>" > $(STAGING_INSTALL_PREFIX)/var/readme.html
@echo "<p>DemoService is a package without further files.<p><p/>" >> $(STAGING_INSTALL_PREFIX)/var/readme.html
@echo "<p>A demo MySQL/MariaDB database is created.<br/>" >> $(STAGING_INSTALL_PREFIX)/var/readme.html
@echo "Database credentials are stored in <code>var/demoservice.ini</code/>.</p>" >> $(STAGING_INSTALL_PREFIX)/var/readme.html
3 changes: 2 additions & 1 deletion spk/demoservice/PLIST
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
rsc:var/README
rsc:dummy.txt
rsc:var/readme.html
18 changes: 15 additions & 3 deletions spk/demoservice/src/conf/resource
Original file line number Diff line number Diff line change
@@ -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}}"
Expand Down
14 changes: 9 additions & 5 deletions spk/demoservice/src/service-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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 ()
Expand Down
91 changes: 65 additions & 26 deletions spk/demoservice/src/wizard/install_uifile
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -33,26 +65,33 @@
]
}
]
},
{
}, {
"step_title": "DSM Permissions",
"items": [
{
"desc": "Permissions are managed with the group <b>'sc-download'</b> in DSM.<br>The group 'users' is no longer used as of DSM 6.<br>Package user (= demoservice) will not appear on most UI settings.<br>Including the following:<br>- Application privilege's permission viewer<br>- FPT's chroot user selector<br>- File Stations's<br>- Change owner<br>- Shared Links Manager -> Enable secure sharing<br><br>The only exceptions are:<br>- Control Panel > Shared Folder > Edit > Permission > System internal user<br>- ACL editor<br>"
"items": [{
"desc": "Permissions in DSM are restricted to group defined in the previous step (default: <b>'sc-download'</b>).<br>The group 'users' is no longer used as of DSM 6+.<br>Package user (<b>'sc-demoservice'</b>) will not appear on most UI settings.<br>Including the following:<br>- Application privilege's permission viewer<br>- FPT's chroot user selector<br>- File Stations's<br>- Change owner<br>- Shared Links Manager -> Enable secure sharing<br><br>The only exceptions are:<br>- Control Panel > Shared Folder > Edit > Permission > System internal user<br>- ACL editor<br>"
}
]
},
{
"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.<br>"
},{
}, {
"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"
}
]
}
]
}
]
48 changes: 27 additions & 21 deletions spk/demoservice/src/wizard/uninstall_uifile
Original file line number Diff line number Diff line change
@@ -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
}
]
}
]
}
]

0 comments on commit ec9d4d3

Please sign in to comment.