owfs: Add init scripts and config files
authorMarcin Jurkowski <marcin1j@gmail.com>
Wed, 6 Mar 2013 09:30:36 +0000 (09:30 +0000)
committerMarcin Jurkowski <marcin1j@gmail.com>
Mon, 31 Aug 2015 23:19:40 +0000 (01:19 +0200)
Owfs daemons lack control scripts. This patch adds init.d scripts for owfs,
owserver, owhttpd and owftpd packages.
Most daemon options (both common libow and program-specific parameters)
are reflected as uci config variables.

Signed-off-by: Marcin Jurkowski <marcin1j@gmail.com>
utils/owfs/Makefile
utils/owfs/files/owfs.conf [new file with mode: 0644]
utils/owfs/files/owfs.init [new file with mode: 0644]
utils/owfs/files/owftpd.conf [new file with mode: 0644]
utils/owfs/files/owftpd.init [new file with mode: 0644]
utils/owfs/files/owhttpd.conf [new file with mode: 0644]
utils/owfs/files/owhttpd.init [new file with mode: 0644]
utils/owfs/files/owserver.conf [new file with mode: 0644]
utils/owfs/files/owserver.init [new file with mode: 0644]

index bec087f894ec6be4bbf62ff6b574378d6682c180..b939d618e0d311b184cf30f86541529e38da6fc2 100644 (file)
@@ -198,6 +198,15 @@ endef
 define Package/owfs/install
        $(INSTALL_DIR) $(1)/usr/bin
        $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/owfs $(1)/usr/bin/
+       $(INSTALL_DIR) $(1)/etc/config
+       $(INSTALL_DATA) ./files/owfs.conf $(1)/etc/config/owfs
+       $(INSTALL_DIR) $(1)/etc/init.d
+       $(INSTALL_BIN) ./files/owfs.init $(1)/etc/init.d/owfs
+       mkdir -p $(1)/mnt/owfs
+endef
+
+define Package/owfs/conffiles
+/etc/config/owfs
 endef
 
 define Package/owshell/install
@@ -213,18 +222,41 @@ endef
 define Package/owserver/install
        $(INSTALL_DIR) $(1)/usr/bin
        $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/owserver $(1)/usr/bin/
+       $(INSTALL_DIR) $(1)/etc/config
+       $(INSTALL_DATA) ./files/owserver.conf $(1)/etc/config/owserver
+       $(INSTALL_DIR) $(1)/etc/init.d
+       $(INSTALL_BIN) ./files/owserver.init $(1)/etc/init.d/owserver
+endef
+
+define Package/owserver/conffiles
+/etc/config/owserver
 endef
 
 define Package/owhttpd/install
        $(INSTALL_DIR) $(1)/usr/bin
        $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/owhttpd $(1)/usr/bin/
+       $(INSTALL_DIR) $(1)/etc/config
+       $(INSTALL_DATA) ./files/owhttpd.conf $(1)/etc/config/owhttpd
+       $(INSTALL_DIR) $(1)/etc/init.d
+       $(INSTALL_BIN) ./files/owhttpd.init $(1)/etc/init.d/owhttpd
+endef
+
+define Package/owhttpd/conffiles
+/etc/config/owhttpd
 endef
 
 define Package/owftpd/install
        $(INSTALL_DIR) $(1)/usr/bin
        $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/owftpd $(1)/usr/bin/
+       $(INSTALL_DIR) $(1)/etc/config
+       $(INSTALL_DATA) ./files/owftpd.conf $(1)/etc/config/owftpd
+       $(INSTALL_DIR) $(1)/etc/init.d
+       $(INSTALL_BIN) ./files/owftpd.init $(1)/etc/init.d/owftpd
 endef
 
+define Package/owftpd/conffiles
+/etc/config/owftpd
+endef
 
 define Package/libow/install
        $(INSTALL_DIR) $(1)/usr/lib
diff --git a/utils/owfs/files/owfs.conf b/utils/owfs/files/owfs.conf
new file mode 100644 (file)
index 0000000..3bb30a5
--- /dev/null
@@ -0,0 +1,11 @@
+config owfs 'owfs'
+       option enabled 0
+       option uid 0
+       option gid 0
+       option readonly 0
+       option mountpoint '/mnt/owfs'
+       option fuse_allow_other 0
+       option fuse_open_opt ''
+       option error_level 0
+       option options ''
+       list devices '-s localhost:4304'
diff --git a/utils/owfs/files/owfs.init b/utils/owfs/files/owfs.init
new file mode 100644 (file)
index 0000000..e70820f
--- /dev/null
@@ -0,0 +1,75 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2009-2012 OpenWrt.org
+
+START=99
+
+SERVICE_WRITE_PID=1
+SERVICE_DAEMONIZE=1
+
+# Workaround insufficient /dev/fuse permissions and the lack of /etc/fuse.conf
+DEFAULT_SERVICE_UID=0
+DEFAULT_SERVICE_GID=0
+
+append_device() {
+       append devices "$1"
+}
+
+
+start_owfs_daemon() {
+       local program="$1"
+       local config="$1"
+       local args="--foreground --error_print=1 $2"
+
+
+       local enabled
+       config_get_bool enabled "$config" enabled 0
+       [ "${enabled}" -eq 0 ] && return 1
+
+       local readonly
+       config_get_bool readonly "$config" readonly 0
+       [ "${readonly}" -eq 1 ] && append args "--readonly"
+
+       local error_level
+       config_get error_level "$config" error_level
+       [ -n "${error_level}" ] && append args "--error_level=${error_level}"
+
+       local options
+       config_get options "$config" options
+
+       devices=""
+       config_list_foreach "$config" devices append_device
+
+       config_get SERVICE_UID "$config" uid "$DEFAULT_SERVICE_UID"
+       config_get SERVICE_GID "$config" gid "$DEFAULT_SERVICE_GID"
+
+       service_start "/usr/bin/$program" $args $options $devices
+}
+
+start_owfs() {
+       local config="owfs"
+       local args=""
+
+       config_load "$config"
+
+       local mountpoint
+       config_get mountpoint "$config" mountpoint /mnt/owfs
+       append args "--mountpoint=${mountpoint}"
+
+       local fuse_allow_other
+       config_get_bool fuse_allow_other "$config" fuse_allow_other 0
+       [ "${fuse_allow_other}" -eq 1 ] && append args "--allow_other"
+
+       local fuse_open_opt
+       config_get fuse_open_opt "$config" fuse_open_opt
+       [ -n "${fuse_open_opt}" ] && append args "--fuse_open_opt=\"${fuse_open_opt}\""
+
+       start_owfs_daemon "$config" "$args"
+}
+
+start() {
+       start_owfs
+}
+
+stop() {
+       service_stop /usr/bin/owfs
+}
diff --git a/utils/owfs/files/owftpd.conf b/utils/owfs/files/owftpd.conf
new file mode 100644 (file)
index 0000000..88322c9
--- /dev/null
@@ -0,0 +1,9 @@
+config owftpd 'owftpd'
+       option enabled 0
+       option uid 0
+       option gid 0
+       option readonly 0
+       option port 21
+       option error_level 0
+       option options ''
+       list devices '-s localhost:4304'
diff --git a/utils/owfs/files/owftpd.init b/utils/owfs/files/owftpd.init
new file mode 100644 (file)
index 0000000..010b2b9
--- /dev/null
@@ -0,0 +1,72 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2009-2012 OpenWrt.org
+
+START=99
+
+SERVICE_WRITE_PID=1
+SERVICE_DAEMONIZE=1
+
+# Needed for restricted TCP port 21
+DEFAULT_SERVICE_UID=0
+DEFAULT_SERVICE_GID=0
+
+append_device() {
+       append devices "$1"
+}
+
+
+start_owfs_daemon() {
+       local program="$1"
+       local config="$1"
+       local args="--foreground --error_print=1 $2"
+
+
+       local enabled
+       config_get_bool enabled "$config" enabled 0
+       [ "${enabled}" -eq 0 ] && return 1
+
+       local readonly
+       config_get_bool readonly "$config" readonly 0
+       [ "${readonly}" -eq 1 ] && append args "--readonly"
+
+       local error_level
+       config_get error_level "$config" error_level
+       [ -n "${error_level}" ] && append args "--error_level=${error_level}"
+
+       local options
+       config_get options "$config" options
+
+       devices=""
+       config_list_foreach "$config" devices append_device
+
+       config_get SERVICE_UID "$config" uid "$DEFAULT_SERVICE_UID"
+       config_get SERVICE_GID "$config" gid "$DEFAULT_SERVICE_GID"
+
+       service_start "/usr/bin/$program" $args $options $devices
+}
+
+start_owftpd() {
+       local config="owftpd"
+       local args=""
+
+       config_load "$config"
+
+       local port
+       config_get port "$config" port
+       [ -n "${port}" ] && append args "--port=${port}"
+
+       local max_connections
+       config_get max_connections "$config" max_connections
+       [ -n "${max_connections}" ] && append args "--max_connections=${max_connections}"
+
+       start_owfs_daemon "$config" "$args"
+}
+
+
+start() {
+       start_owftpd
+}
+
+stop() {
+       service_stop /usr/bin/owftpd
+}
diff --git a/utils/owfs/files/owhttpd.conf b/utils/owfs/files/owhttpd.conf
new file mode 100644 (file)
index 0000000..e49e4ce
--- /dev/null
@@ -0,0 +1,9 @@
+config owhttpd 'owhttpd'
+       option enabled 0
+       option uid 65534
+       option gid 65534
+       option readonly 0
+       option port 3001
+       option error_level 0
+       option options ''
+       list devices '-s localhost:4304'
diff --git a/utils/owfs/files/owhttpd.init b/utils/owfs/files/owhttpd.init
new file mode 100644 (file)
index 0000000..fdabdbc
--- /dev/null
@@ -0,0 +1,71 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2009-2012 OpenWrt.org
+
+START=99
+
+SERVICE_WRITE_PID=1
+SERVICE_DAEMONIZE=1
+
+DEFAULT_SERVICE_UID=65534
+DEFAULT_SERVICE_GID=65534
+
+append_device() {
+       append devices "$1"
+}
+
+
+start_owfs_daemon() {
+       local program="$1"
+       local config="$1"
+       local args="--foreground --error_print=1 $2"
+
+
+       local enabled
+       config_get_bool enabled "$config" enabled 0
+       [ "${enabled}" -eq 0 ] && return 1
+
+       local readonly
+       config_get_bool readonly "$config" readonly 0
+       [ "${readonly}" -eq 1 ] && append args "--readonly"
+
+       local error_level
+       config_get error_level "$config" error_level
+       [ -n "${error_level}" ] && append args "--error_level=${error_level}"
+
+       local options
+       config_get options "$config" options
+
+       devices=""
+       config_list_foreach "$config" devices append_device
+
+       config_get SERVICE_UID "$config" uid "$DEFAULT_SERVICE_UID"
+       config_get SERVICE_GID "$config" gid "$DEFAULT_SERVICE_GID"
+
+       service_start "/usr/bin/$program" $args $options $devices
+}
+
+start_owhttpd() {
+       local config="owhttpd"
+       local args=""
+
+       config_load "$config"
+
+       local port
+       config_get port "$config" port
+       [ -n "${port}" ] && append args "--port=${port}"
+
+       local max_connections
+       config_get max_connections "$config" max_connections
+       [ -n "${max_connections}" ] && append args "--max_connections=${max_connections}"
+
+       start_owfs_daemon "$config" "$args"
+}
+
+
+start() {
+       start_owhttpd
+}
+
+stop() {
+       service_stop /usr/bin/owhttpd
+}
diff --git a/utils/owfs/files/owserver.conf b/utils/owfs/files/owserver.conf
new file mode 100644 (file)
index 0000000..e000894
--- /dev/null
@@ -0,0 +1,9 @@
+config owserver 'owserver'
+       option enabled 0
+       option uid 65534
+       option gid 65534
+       option readonly 0
+       option port 4304
+       option error_level 0
+       option options ''
+       list devices '-d /dev/ttyUSB0'
diff --git a/utils/owfs/files/owserver.init b/utils/owfs/files/owserver.init
new file mode 100644 (file)
index 0000000..bbf870d
--- /dev/null
@@ -0,0 +1,70 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2009-2012 OpenWrt.org
+
+START=98
+
+SERVICE_WRITE_PID=1
+SERVICE_DAEMONIZE=1
+
+DEFAULT_SERVICE_UID=65534
+DEFAULT_SERVICE_GID=65534
+
+append_device() {
+       append devices "$1"
+}
+
+
+start_owfs_daemon() {
+       local program="$1"
+       local config="$1"
+       local args="--foreground --error_print=1 $2"
+
+
+       local enabled
+       config_get_bool enabled "$config" enabled 0
+       [ "${enabled}" -eq 0 ] && return 1
+
+       local readonly
+       config_get_bool readonly "$config" readonly 0
+       [ "${readonly}" -eq 1 ] && append args "--readonly"
+
+       local error_level
+       config_get error_level "$config" error_level
+       [ -n "${error_level}" ] && append args "--error_level=${error_level}"
+
+       local options
+       config_get options "$config" options
+
+       devices=""
+       config_list_foreach "$config" devices append_device
+
+       config_get SERVICE_UID "$config" uid "$DEFAULT_SERVICE_UID"
+       config_get SERVICE_GID "$config" gid "$DEFAULT_SERVICE_GID"
+
+       service_start "/usr/bin/$program" $args $options $devices
+}
+
+start_owserver() {
+       local config="owserver"
+       local args=""
+
+       config_load "$config"
+
+       local port
+       config_get port "$config" port
+       [ -n "${port}" ] && append args "--port=${port}"
+
+       local max_connections
+       config_get max_connections "$config" max_connections
+       [ -n "${max_connections}" ] && append args "--max_connections=${max_connections}"
+
+       start_owfs_daemon "$config" "$args"
+}
+
+start() {
+       start_owserver
+}
+
+stop() {
+       service_stop /usr/bin/owserver
+}