uvol: unbreak if LVM is installed but unused
authorDaniel Golle <daniel@makrotopia.org>
Thu, 7 Apr 2022 10:54:50 +0000 (11:54 +0100)
committerDaniel Golle <daniel@makrotopia.org>
Wed, 13 Apr 2022 17:01:49 +0000 (18:01 +0100)
Fix and simplify console output, make sure uvol doesn't break in case
of LVM being installed but not used.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
utils/uvol/files/lvm.uc
utils/uvol/files/uvol
utils/uvol/files/uvol.init

index 36fb37c5fb9c0913182fc54711b8399b068efc2e..c93a50e8e60ad046c9fec91c3b1f19c60a9e7bdb 100644 (file)
@@ -54,7 +54,7 @@ function pvs() {
                return null;
 
        let tmp = lvm("pvs", "-o", "vg_name", "-S", sprintf("\"pv_name=~^/dev/%s.*\$\"", rootdev));
-       if (tmp.report.pv)
+       if (tmp.report.pv[0])
                return tmp.report.pv[0].vg_name;
        else
                return null;
@@ -115,8 +115,8 @@ function getdev(lv) {
 function lvm_init(ctx) {
        cursor = ctx.cursor;
        fs = ctx.fs;
-//     if (!fs.access(lvm_exec, "x"))
-//             return false;
+       if (type(fs.access) == "function" && !fs.access(lvm_exec, "x"))
+               return false;
 
        vg_name = pvs();
        if (!vg_name)
index a4f023ffd78133c85a81d09a452f33c05fceb348..2e2ea2928bec244bb42dce8332af52e06f70d932 100644 (file)
@@ -23,7 +23,7 @@ commands:
   status volname               return status of volume
     return code: 0 - volume is ready for use
                  1 - volume is not ready for use
-                 2 - volume doesn'y exist
+                 2 - volume doesn't exist
   write volname size           write to volume from stdin, size in bytes
 ";
 
@@ -101,21 +101,19 @@ let legacy_output = function(var) {
                        out += "\n";
                }
        } else if (type(var) == "object") {
-               out += join(" ", values(line));
+               out += join(" ", values(var));
+               out += "\n";
+       } else if (type(var) == "string") {
+               out += var;
                out += "\n";
        }
        return out;
 };
 
-if (type(backend[cmd]) == "string") {
-       printf("%s\n", backend[cmd]);
-} else if (type(backend[cmd]) == "function") {
+if (type(backend[cmd]) == "function") {
        let ret = backend[cmd](...ARGV);
-       if (type(ret) == "int")
+       if (type(ret) == "int") {
                exit(ret);
-
-       if (type(ret) == "string") {
-               printf("%s\n", ret);
        } else {
                if (json_output)
                        printf("%.J\n", ret);
index 98216214fea00900f1df2d51b5c32d98e9e001c6..d75187368a7155fb7e723ff8ecd5ba4d3699eadf 100644 (file)
@@ -19,4 +19,3 @@ boot() {
 service_triggers() {
        procd_add_raw_trigger "mount.ready" 200 /etc/init.d/uvol start
 }
-