From 0f5677e5440dfe33c1ed6b88f8f257d01d2ca604 Mon Sep 17 00:00:00 2001 From: Amin Ben Ramdhane Date: Wed, 27 Apr 2022 12:14:13 +0100 Subject: [PATCH] bulkdata: align with new design - remove libbbfdm dependency - make bulkdata run on top of ubus usp.raw object --- bulkdata/Makefile | 49 +++--------- bulkdata/files/etc/config/bulkdata | 39 +--------- bulkdata/files/etc/init.d/bulkdatad | 20 ++--- .../95-bulkdata-translation-options | 75 +++++++++++++++++++ 4 files changed, 97 insertions(+), 86 deletions(-) create mode 100644 bulkdata/files/etc/uci-defaults/95-bulkdata-translation-options diff --git a/bulkdata/Makefile b/bulkdata/Makefile index eb4a96d36..f9874be94 100755 --- a/bulkdata/Makefile +++ b/bulkdata/Makefile @@ -1,5 +1,5 @@ # -# Copyright (C) 2020 iopsys Software Solutions AB +# Copyright (C) 2022 iopsys Software Solutions AB # # This is free software, licensed under the GNU General Public License v2. # See /LICENSE for more information. @@ -8,52 +8,31 @@ include $(TOPDIR)/rules.mk PKG_NAME:=bulkdata -PKG_VERSION:=1.0.5 +PKG_VERSION:=2.0.0 LOCAL_DEV:=0 ifneq ($(LOCAL_DEV),1) PKG_SOURCE_PROTO:=git PKG_SOURCE_URL:=https://dev.iopsys.eu/iopsys/bulkdata.git -PKG_SOURCE_VERSION:=b35e7862bc17fc11dc1f757c7b93900995a28633 +PKG_SOURCE_VERSION:=7e14c87cf1e627ba9ddeb3098ee95c64d3f0d9aa PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz PKG_MIRROR_HASH:=skip endif +PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION) +PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION) + PKG_LICENSE:=GPL-2.0-only PKG_LICENSE_FILES:=LICENSE include $(INCLUDE_DIR)/package.mk -define Package/bulkdata/default +define Package/$(PKG_NAME) SECTION:=utils CATEGORY:=Utilities SUBMENU:=TRx69 TITLE:=BBF BulkData Collection - DEPENDS:=+libubus +libuci +libubox +libjson-c +libcurl +curl +libblobmsg-json +libbbf_api -endef - -define Package/bulkdata-mbedtls - $(Package/bulkdata/default) - TITLE += (mbedtls) - DEPENDS += +libbbfdm-mbedtls - VARIANT:=mbedtls - DEFAULT_VARIANT:=1 -endef - -define Package/bulkdata-openssl - $(Package/bulkdata/default) - TITLE += (openssl) - DEPENDS += +libbbfdm-openssl - CONFLICTS := bulkdata-mbedtls - VARIANT:=openssl -endef - -define Package/bulkdata-wolfssl - $(Package/bulkdata/default) - TITLE += (wolfssl) - DEPENDS += +libbbfdm-wolfssl - CONFLICTS := bulkdata-mbedtls bulkdata-openssl - VARIANT:=wolfssl + DEPENDS:=+libubus +libuci +libubox +libjson-c +libcurl +libblobmsg-json +libbbf_api endef TARGET_CFLAGS += \ @@ -66,18 +45,12 @@ define Build/Prepare endef endif -define Package/bulkdata/default/install +define Package/$(PKG_NAME)/install $(INSTALL_DIR) $(1)/usr/sbin $(INSTALL_BIN) $(PKG_BUILD_DIR)/bulkdatad $(1)/usr/sbin/ $(INSTALL_DIR) $(1)/usr/lib/bbfdm - $(INSTALL_BIN) $(PKG_BUILD_DIR)/*.so $(1)/usr/lib/bbfdm + $(INSTALL_BIN) $(PKG_BUILD_DIR)/bbf_plugin/*.so $(1)/usr/lib/bbfdm $(CP) ./files/* $(1)/ endef -Package/bulkdata-openssl/install = $(Package/bulkdata/default/install) -Package/bulkdata-wolfssl/install = $(Package/bulkdata/default/install) -Package/bulkdata-mbedtls/install = $(Package/bulkdata/default/install) - -$(eval $(call BuildPackage,bulkdata-openssl)) -$(eval $(call BuildPackage,bulkdata-wolfssl)) -$(eval $(call BuildPackage,bulkdata-mbedtls)) +$(eval $(call BuildPackage,$(PKG_NAME))) diff --git a/bulkdata/files/etc/config/bulkdata b/bulkdata/files/etc/config/bulkdata index 7ef0df97d..3b3ceae1a 100644 --- a/bulkdata/files/etc/config/bulkdata +++ b/bulkdata/files/etc/config/bulkdata @@ -1,43 +1,6 @@ config bulkdata 'bulkdata' option enable '0' - #Log levels: Critical=0, Warning=1, Notice=2, Info=3, Debug=4 + #Log levels: Error=1, Warning=2, Info=3, Debug=4 option log_level '3' -config profile - option profile_id '1' - option enable '0' - option name '' - option nbre_of_retained_failed_reports '0' - option protocol 'http' - option encoding_type '' - option reporting_interval '86400' - option time_reference '0' - option csv_encoding_field_separator ',' - option csv_encoding_row_separator ' ' - option csv_encoding_escape_character '"' - option csv_encoding_report_format 'column' - option csv_encoding_row_time_stamp 'unix' - option json_encoding_report_format 'objecthierarchy' - option json_encoding_report_time_stamp 'unix' - option http_url '' - option http_username '' - option http_password '' - option http_compression 'none' - option http_method 'post' - option http_use_date_header '1' - option http_retry_enable '0' - option http_retry_minimum_wait_interval '5' - option http_retry_interval_multiplier '2000' - option http_persist_across_reboot '0' - -config profile_parameter - option profile_id '1' - option name '' - option reference '' - -config profile_http_request_uri_parameter - option profile_id '1' - option name '' - option reference '' - diff --git a/bulkdata/files/etc/init.d/bulkdatad b/bulkdata/files/etc/init.d/bulkdatad index 3d7f13750..88b1d5588 100755 --- a/bulkdata/files/etc/init.d/bulkdatad +++ b/bulkdata/files/etc/init.d/bulkdatad @@ -1,7 +1,4 @@ #!/bin/sh /etc/rc.common -# Bulkdata Software -# Copyright (C) 2020 iopsys Software Solutions AB -# Author: Amin Ben Ramdhane START=99 STOP=10 @@ -10,13 +7,16 @@ USE_PROCD=1 PROG="/usr/sbin/bulkdatad" start_service() { - local bulkdata_enable=`uci -q get bulkdata.bulkdata.enable` - if [ "$bulkdata_enable" = "1" ]; then - procd_open_instance - procd_set_param command "$PROG" - procd_set_param respawn "3" "7" "0" - procd_close_instance - fi + local enable=$(uci -q get bulkdata.bulkdata.enable) + + [ "$enable" != "1" ] && { + return 0 + } + + procd_open_instance + procd_set_param command "$PROG" + procd_set_param respawn "3" "7" "0" + procd_close_instance } boot() { diff --git a/bulkdata/files/etc/uci-defaults/95-bulkdata-translation-options b/bulkdata/files/etc/uci-defaults/95-bulkdata-translation-options new file mode 100644 index 000000000..2e9da0117 --- /dev/null +++ b/bulkdata/files/etc/uci-defaults/95-bulkdata-translation-options @@ -0,0 +1,75 @@ +#!/bin/sh + +. /lib/functions.sh + +PROFILE_COUNT=1 + +get_next_count() +{ + local config="$1" + local default_name="${2}" + local count=${3} + local found=0 + + if [ -z "$count" ]; then + count=1 + fi + + while [ "${found}" -ne 1 ]; do + uci -q get ${config}.${default_name}_${count} >/dev/null + if [ $? -eq 0 ]; then + count=$((count + 1)) + else + found=1; + fi + done + + echo "${default_name}_${count}" +} + +translate_profile_id_to_profile_name() { + local section="${1}" + local profile_id="${2}" + local profile_name="${3}" + local curr_profile_id + + config_get curr_profile_id "${section}" profile_id + + [ -n "${curr_profile_id}" ] || return + + [ "${curr_profile_id}" != "${profile_id}" ] && return + + uci -q set bulkdata.${section}.profile_name="${profile_name}" + uci -q set bulkdata.${section}.profile_id="" +} + +update_profile_sections() { + local section="${1}" + local default="${2}" + local profile_name + + config_get profile_id "${section}" profile_id + + [ -n "${profile_id}" ] || return + + case "${section}" in + "cfg"*) + profile_name="$(get_next_count bulkdata ${default} ${PROFILE_COUNT})" + uci_rename bulkdata "${section}" "${profile_name}" + ;; + esac + PROFILE_COUNT=$((PROFILE_COUNT + 1)) + + [ -n "$profile_name" ] && section="${profile_name}" + + uci -q set bulkdata.${section}.profile_id="" + + config_foreach translate_profile_id_to_profile_name profile_parameter "${profile_id}" "${profile_name}" + config_foreach translate_profile_id_to_profile_name profile_http_request_uri_parameter "${profile_id}" "${profile_name}" +} + +config_load bulkdata +config_foreach update_profile_sections profile profile +uci commit bulkdata + +exit 0