From e20228f16f7b4f10174c19b639e3884f65a0dc09 Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Wed, 15 Sep 2021 22:31:30 +0100 Subject: [PATCH] uvol: update to version 0.5 Adds '-j' option for 'list' command to generate JSON output. Signed-off-by: Daniel Golle --- utils/uvol/Makefile | 2 +- utils/uvol/files/lvm.sh | 25 ++++++++++++++++++++++--- utils/uvol/files/ubi.sh | 24 ++++++++++++++++++++++-- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/utils/uvol/Makefile b/utils/uvol/Makefile index e988d5168..e167e20d0 100644 --- a/utils/uvol/Makefile +++ b/utils/uvol/Makefile @@ -1,7 +1,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=uvol -PKG_VERSION:=0.4 +PKG_VERSION:=0.5 PKG_RELEASE:=$(AUTORELEASE) PKG_MAINTAINER:=Daniel Golle diff --git a/utils/uvol/files/lvm.sh b/utils/uvol/files/lvm.sh index 95281194b..08ff8d979 100644 --- a/utils/uvol/files/lvm.sh +++ b/utils/uvol/files/lvm.sh @@ -295,7 +295,12 @@ updatevol() { } listvols() { - local reports rep lv lvs lv_name lv_size lv_mode volname + local reports rep lv lvs lv_name lv_size lv_mode volname json_output json_notfirst + if [ "$1" = "-j" ]; then + json_output=1 + echo "[" + shift + fi volname=${1:-.*} json_init json_load "$(lvs -o lv_name,lv_size -S "lv_name=~^[rw][owp]_$volname\$ && vg_name=$vg_name")" @@ -311,14 +316,28 @@ listvols() { lv_mode="${lv_name:0:2}" lv_name="${lv_name:3}" lv_size=${lv_size%B} - echo "$lv_name $lv_mode $lv_size" + if [ "$json_output" = "1" ]; then + [ "$json_notfirst" = "1" ] && echo "," + echo -e "\t{" + echo -e "\t\t\"name\": \"$lv_name\"," + echo -e "\t\t\"mode\": \"$lv_mode\"," + echo -e "\t\t\"size\": $lv_size" + echo -n -e "\t}" + json_notfirst=1 + else + echo "$lv_name $lv_mode $lv_size" + fi json_select .. done json_select .. break done -} + if [ "$json_output" = "1" ]; then + [ "$json_notfirst" = "1" ] && echo + echo "]" + fi +} detect() { local reports rep lv lvs lv_name lv_full_name lv_mode volname devname lv_skip_activation diff --git a/utils/uvol/files/ubi.sh b/utils/uvol/files/ubi.sh index b0b363d7e..0af34f3c0 100644 --- a/utils/uvol/files/ubi.sh +++ b/utils/uvol/files/ubi.sh @@ -194,7 +194,12 @@ updatevol() { } listvols() { - local volname volmode volsize + local volname volmode volsize json_output json_notfirst + if [ "$1" = "-j" ]; then + json_output=1 + shift + echo "[" + fi for voldir in "/sys/devices/virtual/ubi/${ubidev}/${ubidev}_"*; do read -r volname < "$voldir/name" case "$volname" in @@ -207,8 +212,23 @@ listvols() { esac volmode="${volname:5:2}" volname="${volname:8}" - echo "$volname $volmode $volsize" + if [ "$json_output" = "1" ]; then + [ "$json_notfirst" = "1" ] && echo "," + echo -e "\t{" + echo -e "\t\t\"name\": \"$volname\"," + echo -e "\t\t\"mode\": \"$volmode\"," + echo -e "\t\t\"size\": $volsize" + echo -n -e "\t}" + json_notfirst=1 + else + echo "$volname $volmode $volsize" + fi done + + if [ "$json_output" = "1" ]; then + [ "$json_notfirst" = "1" ] && echo + echo "]" + fi } bootvols() {