参考网址:https://forum.openmediavault....创建应用程序GUI创建应用程序目录:/var/www/openmediavault/js/omv/module/admin/service/example创建菜单节点:Node.js//require("js/omv/WorkspaceManager.js")OMV.WorkspaceManager.registerNode({id:'example',path:'/service',text:_('Example'),icon16:'images/example.png',iconSvg:'images/example.svg'});设置菜单节点图标var/www/openmediavault/images在Node.js创建2个对应的图像创建设置面板:Settings.js//require("js/omv/WorkspaceManager.js")//require("js/omv/workspace/form/Panel.js")Ext.define('OMV.module.admin.service.example.Settings',{extend:'OMV.workspace.form.Panel',rpcService:'Example',rpcGetMethod:'getSettings',rpcSetMethod:'setSettings',getFormItems:function(){返回[{xtype:'fieldset',title:_('General'),fieldDefaults:{labelSeparator:''},项目:[{xtype:'checkbox',name:'enable',fieldLabel:_('Enable'),checked:false},{xtype:'numberfield',name:'max_value',fieldLabel:_('最大值'),minValue:0,maxValue:100,allowDecimals:假,allowBlank:真}]}];}});OMV.WorkspaceManager.registerPanel({id:'settings',path:'/service/example',text:_('Settings'),position:10,className:'OMV.module.admin.service.示例.设置'});刷新js缓存:source/usr/share/openmediavault/scripts/helper-functions&&omv_purge_internal_cache创建shell脚本生成配置信息postinst命令执行:/bin/shpostinstconfigure#!/bin/shset-e。/etc/默认/openmediavault./usr/share/openmediavault/scripts/helper-functionscase"$1"inconfigure)SERVICE_XPATH_NAME="example"SERVICE_XPATH="/config/services/${SERVICE_XPATH_NAME}"#添加默认配置如果!omv_config_exists"${SERVICE_XPATH}";thenomv_config_add_element"/config/services""${SERVICE_XPATH_NAME}"omv_config_add_element"${SERVICE_XPATH}""enable""0"omv_config_add_element"${SERVICE_XPATH}""max_value""0"fi#下面2条命令用于安装包并直接执行它们。你可以注释掉dpkg-triggerupdate-fixpermsdpkg-triggerupdate-locale;;中止升级|中止删除|中止取消配置);;*)echo"postinstcalledwithunknownargument">&2exit1;;esac#DEBHELPER#exit0创建删除配置信息的shell脚本postrm执行命令:/bin/shpostrmpurge#!/bin/shset-e。/etc/默认/openmediavault./usr/share/openmediavault/scripts/helper-functionsSERVICE_XPATH_NAME="example"SERVICE_XPATH="/config/services/${SERVICE_XPATH_NAME}"case"$1"inpurge)ifomv_config_exists${SERVICE_XPATH};然后omv_config_delete${SERVICE_XPATH};消除);;升级|升级失败|中止t-安装|中止升级|消失);;*)echo"postrmcalledwithunknownargument\\`$1'">&2exit1;;esac#DEBHELPER#exit0创建rpc在目录/usr/share/openmediavault/engined/rpc创建example.incregisterMethod("getSettings");$this->registerMethod("setSettings");}publicfunctiongetSettings($params,$context){//验证RPC调用者上下文。$this->validateMethodContext($context,["role"=>OMV_ROLE_ADMINISTRATOR]);//获取配置对象。$db=\\OMV\\Config\\Database::getInstance();$object=$db->get("conf.service.example");//从对象中删除无用的属性。返回$object->getAssoc();}公共函数setSettings($params,$context){//验证RPC调用者上下文。$this->validateMethodContext($context,["role"=>OMV_ROLE_ADMINISTRATOR]);//验证RPC服务方法的参数。$this->validateMethodParams($params,"rpc.example.setsettings");//获取现有的配置对象。$db=\\OMV\\Config\\Database::getInstance();$object=$db->get("conf.service.example");$object->setAssoc($params);$db->set($object);//返回配置对象。返回$object->getAssoc();}}创建对应的配置文件在usr\share\openmediavault\datamodels创建conf.service.example.json{"type":"config","id":"conf.service.example","title":"EXAMPLE","queryinfo":{"xpath":"//services/example","iterable":false},"properties":{"enable":{"type":"boolean","default":false},"max_value":{"type":"integer","minimum":1,"maximum":100,"default":0}}}在usr\share\openmediavault\datamodels[{"type":"rpc","id":"rpc.example.setsettings","params":{"type":"object","properties":{"enable":{"type":"boolean","required":true},"max_value":{"type":"integer","minimum":1,"maximum":100,"required":true}}}}]运行命令重启omv服务:serviceopenmediavault-enginedrestart创建shell脚本获取配置信息创建执行脚本示例执行命令:omv-mkconfexample#!/bin/shset-e。/etc/默认/openmediavault./usr/share/openmediavault/scripts/helper-functionsOMV_EXAMPLE_XPATH="/config/services/example"OMV_EXAMPLE_CONF="/tmp/example.conf"cat<
