Browse Source

Merge pull request #1751 from marcin1j/patchwork/nbd

nbd: import from oldpackages, add nbd-server package
lilik-openwrt-22.03
Steven Barth 9 years ago
parent
commit
1adb6aa6fa
5 changed files with 309 additions and 0 deletions
  1. +88
    -0
      net/nbd/Makefile
  2. +9
    -0
      net/nbd/files/nbd-client.conf
  3. +69
    -0
      net/nbd/files/nbd-client.init
  4. +31
    -0
      net/nbd/files/nbd-server.conf
  5. +112
    -0
      net/nbd/files/nbd-server.init

+ 88
- 0
net/nbd/Makefile View File

@ -0,0 +1,88 @@
#
# Copyright (C) 2006-2015 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=nbd
PKG_VERSION:=3.11
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
PKG_SOURCE_URL:=@SF/nbd
PKG_MD5SUM:=73d11644a28b9f335292cdb3bdc4b74b
PKG_LICENSE:=GPL-2.0+
PKG_MAINTAINER:=Marcin Jurkowski <marcin1j@gmail.com>
PKG_INSTALL:=1
include $(INCLUDE_DIR)/package.mk
# -liconv due to glib2, to be revisited later
include $(INCLUDE_DIR)/nls.mk
PKG_BUILD_DEPENDS:=glib2 libintl
define Package/nbd
SECTION:=net
CATEGORY:=Network
TITLE:=Network Block Device utilities
URL:=http://nbd.sourceforge.net
DEPENDS:=+kmod-nbd
endef
define Package/nbd/description
This package contains the network block device client.
endef
define Package/nbd-server
SECTION:=net
CATEGORY:=Network
TITLE:=Network Block Device Server
URL:=http://nbd.sourceforge.net
DEPENDS:=+glib2
endef
define Package/nbd-server/description
This package contains the network block device server.
endef
CONFIGURE_ARGS += \
--disable-glibtest
TARGET_CFLAGS += --std=gnu99 -DNODAEMON
define Package/nbd/install
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/nbd-client $(1)/usr/sbin/
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_CONF) ./files/nbd-client.conf $(1)/etc/config/nbd-client
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/nbd-client.init $(1)/etc/init.d/nbd-client
endef
define Package/nbd/conffiles
/etc/config/nbd-client
endef
$(eval $(call BuildPackage,nbd))
define Package/nbd-server/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/nbd-server $(1)/usr/bin/
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_CONF) ./files/nbd-server.conf $(1)/etc/config/nbd-server
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/nbd-server.init $(1)/etc/init.d/nbd-server
endef
define Package/nbd-server/conffiles
/etc/config/nbd-server
/etc/nbd-server/conf.d
/etc/nbd-server/allow
endef
$(eval $(call BuildPackage,nbd-server))

+ 9
- 0
net/nbd/files/nbd-client.conf View File

@ -0,0 +1,9 @@
config nbd-client nbd0
option enabled '0'
option server '127.0.0.1'
option port 10809
option sdp 0
option swap 0
option persist 0
option blocksize 1024
option exportname foo

+ 69
- 0
net/nbd/files/nbd-client.init View File

@ -0,0 +1,69 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2015 OpenWrt.org
START=90
STOP=10
USE_PROCD=1
append_arg() {
local cfg="$1"
local var="$2"
local opt="$3"
local def="$4"
local val
config_get val "$cfg" "$var"
[ -n "$val" -o -n "$def" ] && procd_append_param command $opt "${val:-$def}"
}
append_bool() {
local cfg="$1"
local var="$2"
local opt="$3"
local def="$4"
local val
config_get_bool val "$cfg" "$var" "$def"
[ "$val" = 1 ] && procd_append_param command "$opt"
}
start_instance() {
local cfg="$1"
local enabled
config_get_bool enabled "$cfg" 'enabled' '0'
[ "$enabled" = 0 ] && return 1
procd_open_instance
procd_set_param command /usr/sbin/nbd-client
append_arg "$cfg" server
append_arg "$cfg" port
# device path
procd_append_param command "/dev/$cfg"
procd_append_param command -nofork
append_bool "$cfg" sdp "-sdp"
append_bool "$cfg" swap "-swap"
append_bool "$cfg" persist "-persist"
append_arg "$cfg" blocksize "-block-size"
append_arg "$cfg" timeout "-timeout"
append_arg "$cfg" exportname "-name"
procd_close_instance
}
service_triggers() {
procd_add_reload_trigger "nbd-client"
}
start_service() {
config_load nbd-client
config_foreach start_instance nbd-client
}
stop_service() {
for dev in /dev/nbd*; do
nbd-client -d $dev 1>/dev/null 2>&1
done
}

+ 31
- 0
net/nbd/files/nbd-server.conf View File

@ -0,0 +1,31 @@
config nbd-server
option enabled 0
# option port 10809
# option user root
# option group root
# option allowlist 0
# option includedir '/etc/nbd-server/conf.d'
# option listenaddr '0.0.0.0'
# option oldstyle 0
config share usb_sda1
option filename '/dev/sda1'
# option authfile '/etc/nbd-server/allow'
# option timeout 0
# option flush 0
# option fua 0
# option rotational 0
# option sync 0
# option discard 0
# option maxconnections 10
# option filesize 1000000
# option multifile 0
# option copyonwrite 0
# option sparse_cow 1
# option readonly 0
# option prerun '/bin/true'
# option postrun '/bin/true'
# option virtstyle 'ipliteral'
# option oldstyle_port 12345
# option oldstyle_listenaddr '0.0.0.0'

+ 112
- 0
net/nbd/files/nbd-server.init View File

@ -0,0 +1,112 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2015 OpenWrt.org
START=60
STOP=40
USE_PROCD=1
PROG=/usr/bin/nbd-server
CONFIGFILE="/var/etc/nbd-server.conf"
append_plain() {
echo "$1" >> $CONFIGFILE
}
append_val_str() {
local resultname="$1"
local cfg="$2"
local uciname="${3:-$1}"
local value=
config_get value "$cfg" "$uciname"
if [ -z "$value" ]; then
return
fi
append_plain "$resultname = $value"
}
append_val_bool() {
local resultname="$1"
local cfg="$2"
local uciname="${3:-$1}"
local value=
config_get_bool value "$cfg" "$uciname"
if [ -z "$value" ]; then
return
fi
[ $value == 1 ] && value="true" || value="false"
append_plain "$resultname = $value"
}
config_handle_generic() {
local cfg="$1"
append_plain "[generic]"
append_val_str user "$cfg"
append_val_str group "$cfg"
append_val_str port "$cfg"
append_val_str listenaddr "$cfg"
append_val_bool allowlist "$cfg"
append_val_str includedir "$cfg"
append_val_bool oldstyle "$cfg"
config_get_bool SERVICE_ENABLED "$cfg" enabled 0
}
config_handle_share() {
local cfg="$1"
append_plain
append_plain "[$cfg]"
append_val_str exportname "$cfg" filename
append_val_str timeout "$cfg"
append_val_str maxconnections "$cfg"
append_val_str authfile "$cfg"
append_val_str filesize "$cfg"
append_val_str readonly "$cfg"
append_val_str multifile "$cfg"
append_val_str copyonwrite "$cfg"
append_val_bool sparse_cow "$cfg"
append_val_bool flush "$cfg"
append_val_bool fua "$cfg"
append_val_bool rotational "$cfg"
append_val_bool sync "$cfg"
append_val_bool discard "$cfg"
append_val_str prerun "$cfg"
append_val_str postrun "$cfg"
append_val_str virtstyle "$cfg"
append_val_str port "$cfg" oldstyle_port
append_val_str listenaddr "$cfg" oldstyle_listenaddr
}
start_instance() {
local cfg="$1"
local enabled
config_get_bool enabled "$cfg" 'enabled' '0'
[ "$enabled" = 0 ] && return 1
procd_open_instance
procd_set_param command $PROG --config-file=$CONFIGFILE
procd_set_param file $CONFIGFILE
procd_close_instance
}
start_service() {
config_load nbd-server
mkdir -p $(dirname $CONFIGFILE)
echo "# auto-generated config file from /etc/config/nbd-server" > $CONFIGFILE
config_foreach config_handle_generic nbd-server
config_foreach config_handle_share share
config_foreach start_instance nbd-server
}
service_triggers() {
procd_add_reload_trigger "nbd-server"
}

Loading…
Cancel
Save