aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVan Waholtz <brvphoenix@gmail.com>2022-10-24 22:02:05 +0800
committerRosen Penev <rosenp@gmail.com>2022-11-04 13:13:43 -0700
commit9d17ba1a9387efdc08e236d4eaa937eb103472f4 (patch)
treef1360bcea9e2d84e1661088018b01999d641c54c
parented493247aa8b4a189936f2d6f63c937f6126d2af (diff)
syncthing: add stdiscosrv and strelaysrv
Signed-off-by: Van Waholtz <brvphoenix@gmail.com>
-rw-r--r--utils/syncthing/Makefile81
-rwxr-xr-xutils/syncthing/files/etc/init.d/syncthing69
-rw-r--r--utils/syncthing/files/stdiscosrv.conf18
-rw-r--r--utils/syncthing/files/stdiscosrv.init80
-rw-r--r--utils/syncthing/files/strelaysrv.conf26
-rw-r--r--utils/syncthing/files/strelaysrv.init78
-rw-r--r--utils/syncthing/files/syncthing-sysctl.conf (renamed from utils/syncthing/files/etc/sysctl.d/90-syncthing-inotify.conf)0
-rw-r--r--utils/syncthing/files/syncthing.conf (renamed from utils/syncthing/files/etc/config/syncthing)14
-rw-r--r--utils/syncthing/files/syncthing.init106
-rw-r--r--utils/syncthing/test.sh5
10 files changed, 396 insertions, 81 deletions
diff --git a/utils/syncthing/Makefile b/utils/syncthing/Makefile
index 2dccbabcb..0062bdbb6 100644
--- a/utils/syncthing/Makefile
+++ b/utils/syncthing/Makefile
@@ -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/init.d/syncthing b/utils/syncthing/files/etc/init.d/syncthing
deleted file mode 100755
index f77aad8ae..000000000
--- a/utils/syncthing/files/etc/init.d/syncthing
+++ /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/stdiscosrv.conf b/utils/syncthing/files/stdiscosrv.conf
new file mode 100644
index 000000000..e51ddef66
--- /dev/null
+++ b/utils/syncthing/files/stdiscosrv.conf
@@ -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
index 000000000..112ea5dbd
--- /dev/null
+++ b/utils/syncthing/files/stdiscosrv.init
@@ -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
index 000000000..56ac299ff
--- /dev/null
+++ b/utils/syncthing/files/strelaysrv.conf
@@ -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
index 000000000..166f4a8df
--- /dev/null
+++ b/utils/syncthing/files/strelaysrv.init
@@ -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/etc/sysctl.d/90-syncthing-inotify.conf b/utils/syncthing/files/syncthing-sysctl.conf
index 1e65bf95d..1e65bf95d 100644
--- a/utils/syncthing/files/etc/sysctl.d/90-syncthing-inotify.conf
+++ b/utils/syncthing/files/syncthing-sysctl.conf
diff --git a/utils/syncthing/files/etc/config/syncthing b/utils/syncthing/files/syncthing.conf
index 291675d40..193f5e9ea 100644
--- a/utils/syncthing/files/etc/config/syncthing
+++ b/utils/syncthing/files/syncthing.conf
@@ -2,7 +2,7 @@
config syncthing 'syncthing'
option enabled '0'
- option gui_address 'http://127.0.0.1:8384'
+ option gui_address 'http://0.0.0.0:8384'
# Use internal flash for evaluation purpouses. Use external storage
# for production.
@@ -24,3 +24,15 @@ config syncthing 'syncthing'
# 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
index 000000000..3ec81e593
--- /dev/null
+++ b/utils/syncthing/files/syncthing.init
@@ -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
+}
diff --git a/utils/syncthing/test.sh b/utils/syncthing/test.sh
index f582111ce..5e8c1c782 100644
--- a/utils/syncthing/test.sh
+++ b/utils/syncthing/test.sh
@@ -1,3 +1,6 @@
#!/bin/sh
-syncthing --version | grep "$2"
+PKG=$1
+ver=$2
+
+"$PKG" --version | grep "$ver"