diff --git a/cross/restic-rest-server/Makefile b/cross/restic-rest-server/Makefile new file mode 100644 index 00000000000..c2efa16f506 --- /dev/null +++ b/cross/restic-rest-server/Makefile @@ -0,0 +1,23 @@ +PKG_NAME = restic-rest-server +PKG_REAL_NAME = rest-server +PKG_VERS = 0.12.1 +PKG_EXT = tar.gz +PKG_DIST_NAME = $(PKG_REAL_NAME)-$(PKG_VERS).$(PKG_EXT) +PKG_DIST_SITE = https://github.com/restic/rest-server/releases/download/v$(PKG_VERS) +EXTRACT_PATH = $(WORK_DIR)/$(PKG_NAME) +PKG_DIR = $(PKG_NAME) + +BUILD_DEPENDS = native/go + +HOMEPAGE = https://restic.net/ +COMMENT = Rest Server is a high performance HTTP server that implements restic's REST backend API. +LICENSE = BSD 2-Clause License + +GO_SRC_DIR = $(EXTRACT_PATH) +GO_BIN_DIR = $(GO_SRC_DIR)/$(PKG_NAME) + +ENV += CGO_ENABLED=0 + +GO_BUILD_ARGS = ./cmd/rest-server + +include ../../mk/spksrc.cross-go.mk diff --git a/cross/restic-rest-server/PLIST b/cross/restic-rest-server/PLIST new file mode 100644 index 00000000000..1132f0ca894 --- /dev/null +++ b/cross/restic-rest-server/PLIST @@ -0,0 +1 @@ +bin:bin/restic-rest-server diff --git a/cross/restic-rest-server/digests b/cross/restic-rest-server/digests new file mode 100644 index 00000000000..6690e4bbc30 --- /dev/null +++ b/cross/restic-rest-server/digests @@ -0,0 +1,3 @@ +rest-server-0.12.1.tar.gz SHA1 50a68154ffebc228bffae7cd06744a9224fdb9b9 +rest-server-0.12.1.tar.gz SHA256 f1b4e4ce581d698847c8a4a354a7fe201b073ebca223abf01898c53d87ccbf31 +rest-server-0.12.1.tar.gz MD5 970aa609b3a2793b82480cc4344881ef diff --git a/mk/spksrc.cross-go-env.mk b/mk/spksrc.cross-go-env.mk index 712d359edd7..fd92c000d45 100644 --- a/mk/spksrc.cross-go-env.mk +++ b/mk/spksrc.cross-go-env.mk @@ -37,7 +37,7 @@ ifeq ($(GO_ARCH),) endif # Use -buildvcs=false to disable VCS stamping. -GO_BUILD_ARGS += -buildvcs=false +GO_BUILD_ARGS := -buildvcs=false $(GO_BUILD_ARGS) ifeq ($(strip $(GO_STATIC_BINARIES)),1) GO_BUILD_ARGS += -no-upgrade diff --git a/spk/restic-rest-server/Makefile b/spk/restic-rest-server/Makefile new file mode 100644 index 00000000000..96b42a7cecd --- /dev/null +++ b/spk/restic-rest-server/Makefile @@ -0,0 +1,29 @@ +SPK_NAME = restic-rest-server +SPK_VERS = 0.12.1 +SPK_REV = 1 +SPK_ICON = src/logo.png + +DEPENDS = cross/restic-rest-server + +UNSUPPORTED_ARCHS = $(PPC_ARCHS) + +MAINTAINER = fgma +DESCRIPTION = Rest Server is a high performance HTTP server that implements restic's REST backend API. +DISPLAY_NAME = Restic rest-server +CHANGELOG = "Initial release." +LICENSE_FILE = $(WORK_DIR)/restic-rest-server/LICENSE +HOMEPAGE = https://restic.net/ +LICENSE = BSD 2-Clause License + +WIZARDS_DIR = src/wizard + +STARTABLE = yes +SERVICE_USER = auto +SERVICE_SETUP = src/service-setup.sh +SERVICE_WIZARD_SHARE = wizard_data_directory +USE_DATA_SHARE_WORKER = yes +FWPORTS = src/restic-rest-server.sc +SERVICE_PORT = 8500 +NO_SERVICE_SHORTCUT = yes + +include ../../mk/spksrc.spk.mk diff --git a/spk/restic-rest-server/src/logo.png b/spk/restic-rest-server/src/logo.png new file mode 100644 index 00000000000..21c5884bc1f Binary files /dev/null and b/spk/restic-rest-server/src/logo.png differ diff --git a/spk/restic-rest-server/src/restic-rest-server.sc b/spk/restic-rest-server/src/restic-rest-server.sc new file mode 100644 index 00000000000..c5646bcfd23 --- /dev/null +++ b/spk/restic-rest-server/src/restic-rest-server.sc @@ -0,0 +1,5 @@ +[restic-rest-server] +title="Restic rest-server" +desc="Restic rest-server" +port_forward="yes" +dst.ports="8500/tcp" diff --git a/spk/restic-rest-server/src/service-setup.sh b/spk/restic-rest-server/src/service-setup.sh new file mode 100644 index 00000000000..f011f215b63 --- /dev/null +++ b/spk/restic-rest-server/src/service-setup.sh @@ -0,0 +1,52 @@ + +PATH="${SYNOPKG_PKGDEST}/bin:${PATH}" +GROUP="sc-restic-rest-server" + +# Source installer variables and functions to be available for service start (and not only during installation) +INST_FUNCTIONS=$(dirname $0)"/functions" +if [ -r "${INST_FUNCTIONS}" ]; then + . "${INST_FUNCTIONS}" +fi + +load_variables_from_file "${INST_VARIABLES}" + +REST_SERVER_CUSTOM_ARGS_FILE="${WIZARD_DATA_VOLUME}/${WIZARD_DATA_DIRECTORY}/restic_rest_server_custom_args.txt" + +service_prestart () +{ + ARGS="" + + if [ "${WIZARD_APPEND_ONLY}" == "true" ]; then + ARGS="${ARGS} --append-only" + fi + if [ "${WIZARD_PRIVATE_REPOS}" == "true" ]; then + ARGS="${ARGS} --private-repos" + fi + if [ "${WIZARD_PROMETHEUS}" == "true" ]; then + ARGS="${ARGS} --prometheus" + + if [ "${WIZARD_PROMETHEUS_NO_AUTH}" == "true" ]; then + ARGS="${ARGS} --prometheus-no-auth" + fi + fi + if [ -f "$REST_SERVER_CUSTOM_ARGS_FILE" -a -r "$REST_SERVER_CUSTOM_ARGS_FILE" ]; then + CUSTOM_ARGS=`cat ${REST_SERVER_CUSTOM_ARGS_FILE}` + ARGS="${ARGS} ${CUSTOM_ARGS}" + fi + + SERVICE_COMMAND="${SYNOPKG_PKGDEST}/bin/restic-rest-server --listen ":${SERVICE_PORT}" --path ${WIZARD_DATA_VOLUME}/${WIZARD_DATA_DIRECTORY} ${ARGS}" + SVC_BACKGROUND=y + SVC_WRITE_PID=y +} + +service_postinst () +{ + touch ${wizard_data_volume}/${wizard_data_directory}/.htpasswd + touch ${REST_SERVER_CUSTOM_ARGS_FILE} + echo WIZARD_DATA_VOLUME="${wizard_data_volume}" >> ${INST_VARIABLES} + echo WIZARD_DATA_DIRECTORY="${wizard_data_directory}" >> ${INST_VARIABLES} + echo WIZARD_APPEND_ONLY="${wizard_append_only}" >> ${INST_VARIABLES} + echo WIZARD_PRIVATE_REPOS="${wizard_private_repos}" >> ${INST_VARIABLES} + echo WIZARD_PROMETHEUS="${wizard_prometheus}" >> ${INST_VARIABLES} + echo WIZARD_PROMETHEUS_NO_AUTH="${wizard_prometheus_no_auth}" >> ${INST_VARIABLES} +} diff --git a/spk/restic-rest-server/src/wizard/install_uifile b/spk/restic-rest-server/src/wizard/install_uifile new file mode 100644 index 00000000000..4e53fe92132 --- /dev/null +++ b/spk/restic-rest-server/src/wizard/install_uifile @@ -0,0 +1,108 @@ +[ + { + "step_title": "Restic rest-server 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": "Data shared folder (using the volume chosen above)", + "subitems": [ + { + "key": "wizard_data_directory", + "desc": "Data shared folder", + "defaultValue": "restic-rest-server", + "validator": { + "allowBlank": false, + "regex": { + "expr": "/^[\\w _-]+$/", + "errorText": "Subdirectories are not supported." + } + } + } + ] + }, + { + "desc": "The folder will be created on demand as regular DSM shared folder for the service user sc-restic-rest-server. For details about the DSM permissions see Permission Management.
" + }, + { + "desc": "The non-standard port 8500 is used. The .htpasswd file and restic_rest_server_custom_args.txt to specify custom arguments to the service are located at the root of the shared folder defined above. Add users acccording to the official documentation. Please define the following additional settings for restic rest-server:" + }, + { + "type": "multiselect", + "desc": "Append only mode", + "subitems": [ + { + "key": "wizard_append_only", + "desc": "enabled", + "defaultValue": true + } + ] + }, + { + "type": "multiselect", + "desc": "Private repositories", + "subitems": [ + { + "key": "wizard_private_repos", + "desc": "enabled", + "defaultValue": true + } + ] + }, + { + "type": "multiselect", + "desc": "Prometheus", + "subitems": [ + { + "key": "wizard_prometheus", + "desc": "enabled", + "defaultValue": true + } + ] + }, + { + "type": "multiselect", + "desc": "Prometheus no auth", + "subitems": [ + { + "key": "wizard_prometheus_no_auth", + "desc": "enabled", + "defaultValue": false + } + ] + } + ] + } +] \ No newline at end of file diff --git a/spk/restic-rest-server/src/wizard/upgrade_uifile.sh b/spk/restic-rest-server/src/wizard/upgrade_uifile.sh new file mode 100644 index 00000000000..6573f7f08d1 --- /dev/null +++ b/spk/restic-rest-server/src/wizard/upgrade_uifile.sh @@ -0,0 +1,127 @@ +#!/bin/sh + +INST_ETC="/var/packages/${SYNOPKG_PKGNAME}/etc" +INST_VARIABLES="${INST_ETC}/installer-variables" + +# Reload wizard variables stored by postinst +if [ -r "${INST_VARIABLES}" ]; then + # we cannot source the file to reload the variables, when values have special characters like <, >, ... + for _line in $(cat "${INST_VARIABLES}"); do + _key="$(echo ${_line} | awk -F'=' '{print $1}')" + _value="$(echo ${_line} | awk -F'=' '{print $2}')" + declare "${_key}=${_value}" + done +fi + +cat <