syncthing: add stdiscosrv and strelaysrv
authorVan Waholtz <brvphoenix@gmail.com>
Mon, 24 Oct 2022 14:02:05 +0000 (22:02 +0800)
committerRosen Penev <rosenp@gmail.com>
Fri, 4 Nov 2022 20:13:43 +0000 (13:13 -0700)
Signed-off-by: Van Waholtz <brvphoenix@gmail.com>
12 files changed:
utils/syncthing/Makefile
utils/syncthing/files/etc/config/syncthing [deleted file]
utils/syncthing/files/etc/init.d/syncthing [deleted file]
utils/syncthing/files/etc/sysctl.d/90-syncthing-inotify.conf [deleted file]
utils/syncthing/files/stdiscosrv.conf [new file with mode: 0644]
utils/syncthing/files/stdiscosrv.init [new file with mode: 0644]
utils/syncthing/files/strelaysrv.conf [new file with mode: 0644]
utils/syncthing/files/strelaysrv.init [new file with mode: 0644]
utils/syncthing/files/syncthing-sysctl.conf [new file with mode: 0644]
utils/syncthing/files/syncthing.conf [new file with mode: 0644]
utils/syncthing/files/syncthing.init [new file with mode: 0644]
utils/syncthing/test.sh

index 2dccbabcb79b737f16d27b1d202bca96afbe36c9..0062bdbb6e55e99eb2ff9e446c3f9af166839148 100644 (file)
@@ -20,7 +20,10 @@ PKG_BUILD_PARALLEL:=1
 PKG_USE_MIPS16:=0
 
 GO_PKG:=github.com/syncthing/syncthing/
-GO_PKG_BUILD_PKG:=github.com/syncthing/syncthing/cmd/syncthing/
+GO_PKG_BUILD_PKG:=\
+       $(if $(CONFIG_PACKAGE_syncthing),github.com/syncthing/syncthing/cmd/syncthing/) \
+       $(if $(CONFIG_PACKAGE_stdiscosrv),github.com/syncthing/syncthing/cmd/stdiscosrv/) \
+       $(if $(CONFIG_PACKAGE_strelaysrv),github.com/syncthing/syncthing/cmd/strelaysrv/)
 GO_PKG_INSTALL_EXTRA:=^gui/
 
 GO_PKG_LDFLAGS_X:=\
@@ -34,32 +37,90 @@ GO_PKG_TAGS:=noupgrade
 include $(INCLUDE_DIR)/package.mk
 include ../../lang/golang/golang-package.mk
 
-define Package/syncthing
-  TITLE:=Continuous file synchronization program
+define Package/syncthing/Default
   URL:=https://syncthing.net
   DEPENDS:=$(GO_ARCH_DEPENDS)
   SECTION:=utils
   CATEGORY:=Utilities
+endef
+
+define Package/syncthing
+  $(call Package/syncthing/Default)
+  TITLE:=Continuous file synchronization program
   USERID:=syncthing=499:syncthing=499
 endef
 
+define Package/stdiscosrv
+  $(call Package/syncthing/Default)
+  TITLE:=Discovery server for syncthing
+endef
+
+define Package/strelaysrv
+  $(call Package/syncthing/Default)
+  TITLE:=Relay server for syncthing
+endef
+
 define Package/syncthing/conffiles
 /etc/config/syncthing
 /etc/syncthing
 endef
 
+define Package/stdiscosrv/conffiles
+/etc/config/stdiscosrv
+/etc/stdiscosrv
+endef
+
+define Package/strelaysrv/conffiles
+/etc/config/strelaysrv
+/etc/strelaysrv
+endef
+
 define Package/syncthing/description
-               Syncthing replaces proprietary sync and cloud services with something
-               open, trustworthy and decentralized. Your data is your data alone and
-               you deserve to choose where it is stored, if it is shared with some
-               third party and how it's transmitted over the Internet.
+  Syncthing replaces proprietary sync and cloud services with something
+  open, trustworthy and decentralized. Your data is your data alone and
+  you deserve to choose where it is stored, if it is shared with some
+  third party and how it's transmitted over the Internet.
 endef
 
+define Package/stdiscosrv/description
+  Relay server for syncthing
+endef
+
+define Package/strelaysrv/description
+  Relay server for syncthing
+endef
+
+define Build/Install
+       $(call GoPackage/Package/Install/Bin,$(PKG_INSTALL_DIR))
+endef
+
+define SyncthingInstall
+       $(INSTALL_DIR) $(1)/etc/config/
+       $(INSTALL_CONF) $(CURDIR)/files/$(2).conf $(1)/etc/config/$(2)
+
+       $(INSTALL_DIR) $(1)/etc/init.d/
+       $(INSTALL_BIN) $(CURDIR)/files/$(2).init $(1)/etc/init.d/$(2)
+
+       $(INSTALL_DIR) $(1)/usr/bin/
+       $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/$(2) $(1)/usr/bin
+endef
+
+
 define Package/syncthing/install
-       $(call GoPackage/Package/Install/Bin,$(1))
+       $(call SyncthingInstall,$(1),syncthing)
+
+       $(INSTALL_DIR) $(1)/etc/sysctl.d/
+       $(INSTALL_BIN) $(CURDIR)/files/syncthing-sysctl.conf $(1)/etc/sysctl.d/90-syncthing-inotify.conf
+endef
+
+define Package/stdiscosrv/install
+       $(call SyncthingInstall,$(1),stdiscosrv)
+endef
 
-       $(CP) ./files/* $(1)/
+define Package/strelaysrv/install
+       $(call SyncthingInstall,$(1),strelaysrv)
 endef
 
-$(eval $(call GoBinPackage,syncthing))
 $(eval $(call BuildPackage,syncthing))
+$(eval $(call BuildPackage,stdiscosrv))
+$(eval $(call BuildPackage,strelaysrv))
diff --git a/utils/syncthing/files/etc/config/syncthing b/utils/syncthing/files/etc/config/syncthing
deleted file mode 100644 (file)
index 291675d..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-
-config syncthing 'syncthing'
-       option enabled '0'
-
-       option gui_address 'http://127.0.0.1:8384'
-
-       # Use internal flash for evaluation purpouses. Use external storage
-       #   for production.
-       # This filesystem must either support ownership/attributes or
-       #   be readable/writable by the user specified in
-       #   'option user'.
-       # Consult syslog if things go wrong.
-       option home '/etc/syncthing'
-
-       # Changes to "niceness"/macprocs are not picked up by "reload_config"
-       #   nor by "restart": the service has to be stopped/started
-       #   for those to take effect
-       option nice '19'
-
-       # 0 to match the number of CPUs (default)
-       # >0 to explicitly specify concurrency
-       option macprocs '0'
-
-       # Running as 'root' is possible, but not recommended
-       option user 'syncthing'
-
diff --git a/utils/syncthing/files/etc/init.d/syncthing b/utils/syncthing/files/etc/init.d/syncthing
deleted file mode 100755 (executable)
index f77aad8..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-#!/bin/sh /etc/rc.common
-
-START=90
-STOP=10
-
-USE_PROCD=1
-
-PROG=/usr/bin/syncthing
-
-service_triggers()
-{
-  procd_add_reload_trigger "syncthing"
-}
-
-start_service() {
-  local gui_address home enabled nice macprocs user
-  config_load "syncthing"
-
-  # Some of the default values below might not match the defaults
-  #   in /etc/config/syncthing: the reason is to remain backwards
-  #   compatible with the older versions of this service as it
-  #   evolves.
-
-  config_get_bool enabled syncthing enabled 1
-  [ "$enabled" -gt 0 ] || return 0
-
-  config_get user syncthing user 'root'
-  config_get gui_address syncthing gui_address "http://127.0.0.1:8384"
-  config_get home syncthing home "/etc/syncthing"
-
-  # For backwards compatibility
-  IDX_DB=$(readlink -n "$home"/index-v0.14.0.db)
-  if [ ! -z "$IDX_DB" ]; then
-    [ -d "$IDX_DB" ] || mkdir -p "$IDX_DB"
-
-    # A separate step to handle an upgrade use case
-    [ -d "$IDX_DB" ] && chown -R $user:$user "$IDX_DB"
-  fi
-
-  [ -d "$home" ] || mkdir -p "$home"
-  # A separate step to handle an upgrade use case
-  [ -d "$home" ] && chown -R $user:$user "$home"
-
-  # Changes to "niceness"/macprocs are not picked up by "reload_config"
-  #   nor by "restart": the service has to be stopped/started
-  #   for it to take effect
-  config_get nice syncthing nice "0"
-
-  config_get macprocs syncthing macprocs 0
-  if [ $macprocs -le 0 ]; then
-    # Default to the number of cores in this case
-    macprocs=$(grep -c ^processor /proc/cpuinfo)
-  fi
-
-  procd_open_instance
-  procd_set_param command "$PROG"
-  procd_set_param file /etc/config/syncthing
-  procd_set_param env GOMAXPROCS="$macprocs" STNOUPGRADE=1
-  procd_append_param command -gui-address="$gui_address"
-  procd_append_param command -home="$home"
-  procd_append_param command -no-browser
-  procd_set_param nice "$nice"
-  procd_set_param term_timeout 15
-  procd_set_param user "$user"
-  procd_set_param respawn
-  procd_set_param stdout 1
-  procd_set_param stderr 1
-  procd_close_instance
-}
diff --git a/utils/syncthing/files/etc/sysctl.d/90-syncthing-inotify.conf b/utils/syncthing/files/etc/sysctl.d/90-syncthing-inotify.conf
deleted file mode 100644 (file)
index 1e65bf9..0000000
+++ /dev/null
@@ -1 +0,0 @@
-fs.inotify.max_user_watches=204800
diff --git a/utils/syncthing/files/stdiscosrv.conf b/utils/syncthing/files/stdiscosrv.conf
new file mode 100644 (file)
index 0000000..e51ddef
--- /dev/null
@@ -0,0 +1,18 @@
+
+config stdiscosrv 'stdiscosrv'
+       option enabled '0'
+       option listen ':8443'
+       option db_dir '/etc/stdiscosrv/discovery.db'
+
+       # # Find the documents from: https://docs.syncthing.net/users/stdiscosrv.html
+       # option cert '/etc/stdiscosrv/cert.pem'
+       # option key '/etc/stdiscosrv/key.pem'
+       # option metrics_listen ''
+       # option replicate ''
+       # option replication_listen ':19200'
+
+       # # CLI options with no value should be defined as booleans and theirs
+       # # names should be prefixed with '_'.
+       # option _debug '0'
+       # option _http '1'
+
diff --git a/utils/syncthing/files/stdiscosrv.init b/utils/syncthing/files/stdiscosrv.init
new file mode 100644 (file)
index 0000000..112ea5d
--- /dev/null
@@ -0,0 +1,80 @@
+#!/bin/sh /etc/rc.common
+
+START=90
+STOP=10
+
+USE_PROCD=1
+
+PROG=/usr/bin/stdiscosrv
+
+config_cb() {
+       [ $# -eq 0 ] && return
+
+       option_cb() {
+               local option="$1"
+               local value="$2"
+               case $option in
+               enabled|listen|cert|db_dir|key)
+                       eval $option=$value
+                       ;;
+               _*)
+                       [ "$value" = "0" ] || extra_args="$extra_args -${option//_/-}"
+                       ;;
+               *)
+                       extra_args="$extra_args -${option//_/-}=$value"
+                       ;;
+               esac
+       }
+
+       list_cb() {
+               local name="$1"
+               local value="$2"
+               [ "$name" = "_" ] && extra_args="$extra_args --${value//_/-}" || return 0
+       }
+}
+
+service_triggers()
+{
+       procd_add_reload_trigger "stdiscosrv"
+}
+
+start_service() {
+       local extra_args
+       # Options with default value different with the syncthing should be defined explicitly here
+       local enabled=0
+       local listen=":8443"
+       local cert="/etc/stdiscosrv/cert.pem"
+       local key="/etc/stdiscosrv/key.pem"
+       local db_dir="/etc/stdiscosrv/discovery.db"
+       local nice=0
+
+       config_load "stdiscosrv"
+
+       [ "$enabled" -gt 0 ] || return 0
+
+       [ -d "$db_dir" ] || mkdir -p "$db_dir"
+       [ -d "$db_dir" ] && chown -R nobody:nogroup "$db_dir"
+
+       config_get nice stdiscosrv nice "0"
+
+       procd_open_instance
+       procd_set_param command "$PROG"
+       procd_append_param command -listen="$listen"
+       procd_append_param command -db-dir="$db_dir"
+       procd_append_param command -cert="$cert"
+       procd_append_param command -key="$key"
+       [ -z "$extra_args" ] || procd_append_param command "$extra_args"
+
+       procd_set_param nice "$nice"
+       procd_set_param term_timeout 15
+       procd_set_param user "nobody"
+       procd_set_param respawn
+       procd_set_param stdout 1
+       procd_set_param stderr 1
+       procd_close_instance
+}
+
+reload_service() {
+       stop
+       start
+}
diff --git a/utils/syncthing/files/strelaysrv.conf b/utils/syncthing/files/strelaysrv.conf
new file mode 100644 (file)
index 0000000..56ac299
--- /dev/null
@@ -0,0 +1,26 @@
+
+config strelaysrv 'strelaysrv'
+       option enabled '0'
+       option keys '/etc/strelaysrv'
+       option listen ':22067'
+
+       # # Find the documents from: https://docs.syncthing.net/users/strelaysrv.html
+       # option ext_address ''
+       # option global_rate ''
+       # option message_timeout '1m0s'
+       # option nat_lease 60
+       # option nat_renewal 30
+       # option nat_timeout 10
+       # option network_timeout '2m0s'
+       # option per_session_rate ''
+       # option ping_interval '1m0s'
+       # option pools ''
+       # option protocol 'tcp'
+       # option provided_by ''
+       # option status_srv ':22070'
+
+       # # CLI options with no value should be defined as booleans and theirs
+       # # names should be prefixed with '_'.
+       # option _debug '0'
+       # option _nat '0'
+
diff --git a/utils/syncthing/files/strelaysrv.init b/utils/syncthing/files/strelaysrv.init
new file mode 100644 (file)
index 0000000..166f4a8
--- /dev/null
@@ -0,0 +1,78 @@
+#!/bin/sh /etc/rc.common
+
+START=90
+STOP=10
+
+USE_PROCD=1
+
+PROG=/usr/bin/strelaysrv
+
+config_cb() {
+       [ $# -eq 0 ] && return
+
+       option_cb() {
+               local option="$1"
+               local value="$2"
+               case $option in
+               enabled|keys|pools|status_srv)
+                       eval $option=$value
+                       ;;
+               _*)
+                       [ "$value" = "0" ] || extra_args="$extra_args -${option//_/-}"
+                       ;;
+               *)
+                       extra_args="$extra_args -${option//_/-}=$value"
+                       ;;
+               esac
+       }
+
+       list_cb() {
+               local name="$1"
+               local value="$2"
+               [ "$name" = "_" ] && extra_args="$extra_args --${value//_/-}" || return 0
+       }
+}
+
+service_triggers()
+{
+       procd_add_reload_trigger "strelaysrv"
+}
+
+start_service() {
+       local pools status_srv extra_args
+       # Options with default value different with the syncthing should be defined explicitly here
+       local enabled=0
+       local keys="/etc/strelaysrv"
+       local nice=0
+
+       config_load "strelaysrv"
+
+       [ "$enabled" -gt 0 ] || return 0
+
+       [ -d "$keys" ] || mkdir -p "$keys"
+       [ -d "$keys" ] && chown -R nobody:nogroup "$keys"
+
+       config_get nice strelaysrv nice "0"
+
+       procd_open_instance
+       procd_set_param command "$PROG"
+       procd_append_param command -keys="$keys"
+
+       # pools and status-srv are set to empty value by default
+       procd_append_param command -pools="$pools"
+       procd_append_param command -status-srv="$status_srv"
+       [ -z "$extra_args" ] || procd_append_param command $extra_args
+
+       procd_set_param nice "$nice"
+       procd_set_param term_timeout 15
+       procd_set_param user "nobody"
+       procd_set_param respawn
+       procd_set_param stdout 1
+       procd_set_param stderr 1
+       procd_close_instance
+}
+
+reload_service() {
+       stop
+       start
+}
diff --git a/utils/syncthing/files/syncthing-sysctl.conf b/utils/syncthing/files/syncthing-sysctl.conf
new file mode 100644 (file)
index 0000000..1e65bf9
--- /dev/null
@@ -0,0 +1 @@
+fs.inotify.max_user_watches=204800
diff --git a/utils/syncthing/files/syncthing.conf b/utils/syncthing/files/syncthing.conf
new file mode 100644 (file)
index 0000000..193f5e9
--- /dev/null
@@ -0,0 +1,38 @@
+
+config syncthing 'syncthing'
+       option enabled '0'
+
+       option gui_address 'http://0.0.0.0:8384'
+
+       # Use internal flash for evaluation purpouses. Use external storage
+       #   for production.
+       # This filesystem must either support ownership/attributes or
+       #   be readable/writable by the user specified in
+       #   'option user'.
+       # Consult syslog if things go wrong.
+       option home '/etc/syncthing'
+
+       # Changes to "niceness"/macprocs are not picked up by "reload_config"
+       #   nor by "restart": the service has to be stopped/started
+       #   for those to take effect
+       option nice '19'
+
+       # 0 to match the number of CPUs (default)
+       # >0 to explicitly specify concurrency
+       option macprocs '0'
+
+       # Running as 'root' is possible, but not recommended
+       option user 'syncthing'
+
+       option logfile '/etc/syncthing/syncthing.log'
+       option log_max_old_files 7
+       # Size in bytes
+       option log_max_size 1048576
+
+       # # CLI options with no value should be defined as booleans and theirs
+       # # names should be prefixed with '_'.
+       option _no_default_folder '1'
+
+       # # Extra settings
+       # list _ 'verbose'
+
diff --git a/utils/syncthing/files/syncthing.init b/utils/syncthing/files/syncthing.init
new file mode 100644 (file)
index 0000000..3ec81e5
--- /dev/null
@@ -0,0 +1,106 @@
+#!/bin/sh /etc/rc.common
+
+START=90
+STOP=10
+
+USE_PROCD=1
+
+PROG=/usr/bin/syncthing
+
+config_cb() {
+       [ $# -eq 0 ] && return
+
+       option_cb() {
+               local option="$1"
+               local value="$2"
+               case $option in
+               enabled|macprocs|nice|user|logfile)
+                       eval $option=$value
+                       ;;
+               debug)
+                       extra_args="$extra_args --${option//_/-}-$value"
+                       ;;
+               _*)
+                       [ "$value" = "0" ] || extra_args="$extra_args -${option//_/-}"
+                       ;;
+               *)
+                       extra_args="$extra_args --${option//_/-}=$value"
+                       ;;
+               esac
+       }
+
+       list_cb() {
+               local name="$1"
+               local value="$2"
+               [ "$name" = "_" ] && extra_args="$extra_args --${value//_/-}" || return 0
+       }
+}
+
+service_triggers()
+{
+       procd_add_reload_trigger "syncthing"
+}
+
+start_service() {
+       local extra_args="--no-browser"
+
+       # Options with default value different with the syncthing should be defined explicitly here
+       local enabled=0
+       local gui_address="http://0.0.0.0:8384"
+       local home="/etc/syncthing"
+       local logfile="/etc/syncthing/syncthing.log"
+       local macprocs=0
+       local nice=0
+       local user="syncthing"
+
+       config_load "syncthing"
+
+       # Some of the default values below might not match the defaults
+       #   in /etc/config/syncthing: the reason is to remain backwards
+       #   compatible with the older versions of this service as it
+       #   evolves.
+       [ "$enabled" -gt 0 ] || return 0
+
+       # For backwards compatibility
+       IDX_DB=$(readlink -n "$home"/index-v0.14.0.db)
+       if [ ! -z "$IDX_DB" ]; then
+               [ -d "$IDX_DB" ] || mkdir -p "$IDX_DB"
+
+               # A separate step to handle an upgrade use case
+               [ -d "$IDX_DB" ] && chown -R $user:$user "$IDX_DB"
+       fi
+
+       [ -d "$home" ] || mkdir -p "$home"
+       # A separate step to handle an upgrade use case
+       [ -d "$home" ] && chown -R $user:$user "$home"
+
+       # Changes to "niceness"/macprocs are not picked up by "reload_config"
+       #   nor by "restart": the service has to be stopped/started
+       #   for it to take effect
+       if [ $macprocs -le 0 ]; then
+               # Default to the number of cores in this case
+               macprocs=$(grep -c ^processor /proc/cpuinfo)
+       fi
+
+       procd_open_instance
+       procd_set_param command "$PROG"
+       procd_set_param env GOMAXPROCS="$macprocs" STNOUPGRADE=1
+       procd_append_param command serve
+       procd_append_param command --gui-address="$gui_address"
+       procd_append_param command --home="$home"
+       procd_append_param command --logfile="$logfile"
+       [ -z "$extra_args" ] || procd_append_param command $extra_args
+
+       procd_set_param nice "$nice"
+       procd_set_param term_timeout 15
+       procd_set_param user "$user"
+       procd_set_param respawn
+       procd_set_param stdout 0
+       procd_set_param stderr 1
+       procd_close_instance
+}
+
+reload_service() {
+       stop
+       start
+}
index f582111ce8bba251a121049ff175dcea4d9b7ccf..5e8c1c7820735a2d65161a09cab7ee77fbc755a6 100644 (file)
@@ -1,3 +1,6 @@
 #!/bin/sh
 
-syncthing --version | grep "$2"
+PKG=$1
+ver=$2
+
+"$PKG" --version | grep "$ver"