uvol: unbreak if LVM is installed but unused

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>
This commit is contained in:
Daniel Golle 2022-04-07 11:54:50 +01:00
parent cbc1b0790d
commit 3959a9b22c
No known key found for this signature in database
GPG key ID: 5A8F39C31C3217CA
3 changed files with 10 additions and 13 deletions

View file

@ -54,7 +54,7 @@ function pvs() {
return null; return null;
let tmp = lvm("pvs", "-o", "vg_name", "-S", sprintf("\"pv_name=~^/dev/%s.*\$\"", rootdev)); 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; return tmp.report.pv[0].vg_name;
else else
return null; return null;
@ -115,8 +115,8 @@ function getdev(lv) {
function lvm_init(ctx) { function lvm_init(ctx) {
cursor = ctx.cursor; cursor = ctx.cursor;
fs = ctx.fs; fs = ctx.fs;
// if (!fs.access(lvm_exec, "x")) if (type(fs.access) == "function" && !fs.access(lvm_exec, "x"))
// return false; return false;
vg_name = pvs(); vg_name = pvs();
if (!vg_name) if (!vg_name)

View file

@ -23,7 +23,7 @@ commands:
status volname return status of volume status volname return status of volume
return code: 0 - volume is ready for use return code: 0 - volume is ready for use
1 - volume is not 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 write volname size write to volume from stdin, size in bytes
"; ";
@ -101,21 +101,19 @@ let legacy_output = function(var) {
out += "\n"; out += "\n";
} }
} else if (type(var) == "object") { } else if (type(var) == "object") {
out += join(" ", values(line)); out += join(" ", values(var));
out += "\n";
} else if (type(var) == "string") {
out += var;
out += "\n"; out += "\n";
} }
return out; return out;
}; };
if (type(backend[cmd]) == "string") { if (type(backend[cmd]) == "function") {
printf("%s\n", backend[cmd]);
} else if (type(backend[cmd]) == "function") {
let ret = backend[cmd](...ARGV); let ret = backend[cmd](...ARGV);
if (type(ret) == "int") if (type(ret) == "int") {
exit(ret); exit(ret);
if (type(ret) == "string") {
printf("%s\n", ret);
} else { } else {
if (json_output) if (json_output)
printf("%.J\n", ret); printf("%.J\n", ret);

View file

@ -19,4 +19,3 @@ boot() {
service_triggers() { service_triggers() {
procd_add_raw_trigger "mount.ready" 200 /etc/init.d/uvol start procd_add_raw_trigger "mount.ready" 200 /etc/init.d/uvol start
} }