IgnorantGuru / udevil

Mount without password
http://ignorantguru.github.com/udevil/
GNU General Public License v3.0
130 stars 30 forks source link

concise output for scripting #80

Open ian-bruce opened 6 years ago

ian-bruce commented 6 years ago

For purposes of scripting, it would be convenient if udevil could be made to output the filesystem mountpoint, and nothing else, so that you could do something like this:

MOUNTPOINT=$(udevil mount cdimage.iso)

However, it seems that this is currently not possible, without extra string processing:

$ udevil mount linuxmint-18.3-xfce.iso
Mounted /home/ian/linuxmint-18.3-xfce.iso at /media/ian/linuxmint-18.3-xfce.iso
$ 

$ udevil --quiet mount linuxmint-18.3-xfce.iso
$ 

The first command produces extra verbiage (to emulate "udisksctl"?), while the second produces no output at all. The only current option is to do some string processing to eliminate the text

"Mounted ${FILESYSTEM} at "

Notice that this is not informative at all, since it is only a literal string plus the commandline argument.

I propose that since there is no value in mounting a filesystem without knowing WHERE, in the case that the mountpoint is not specified on the commandline, as above, "udevil --quiet" should output the selected mountpoint, followed by a newline, and nothing else. If the mountpoint is specified, printing it would be redundant, so in that case, "udevil --quiet" can remain silent, as it is now.

Alternatively, perhaps the text "Mounted ${FS} at" can be removed from the non-option form of the command, as it tells you nothing you didn't already know. Or a new option ("--script"?) can be introduced, which outputs only the mountpoint.

Note that the Debian udevil package has incorporated various official, but unreleased, enhancements, of which #62, "Cannot mount iso file within iso file", is probably the most important.

http://metadata.ftp-master.debian.org/changelogs/main/u/udevil/udevil_0.4.4-2_changelog

Perhaps it would be useful to issue a bugfix release, so that other distributions could also benefit from these patches. However, before doing so, please address the problem discussed above.

Thanks.

ian-bruce commented 6 years ago

Consider what happens when udevil mounts this unfortunately-named ISO image file:

$ udevil mount 'linuxmint-18.3-xfce at 64bit.iso'
Mounted /home/ian/linuxmint-18.3-xfce at 64bit.iso at /media/ian/linuxmint-18.3-xfce at 64bit.iso

In order to parse that output, it is not sufficient to search for the rightmost (or leftmost) occurrence of the string " at ", and assume that the text to the right of it is the mountpoint. Something like this seems to be currently the best option:

$ OUTPUT=$(udevil mount "$ISOIMAGE")
$ MOUNTPOINT="/${OUTPUT##* at /}"
$ echo "$MOUNTPOINT"
/media/ian/linuxmint-18.3-xfce at 64bit.iso

But even that is going to fail, in the (unlikely?) event that one of the path components of the user-mount directory has the trailing string " at ":

$ udevil mount 'linuxmint-18.3-xfce at 64bit.iso'
Mounted /home/ian/linuxmint-18.3-xfce at 64bit.iso at /media/user mount at /linuxmint-18.3-xfce at 64bit.iso

Similarly, a shortest-prefix match -- MOUNTPOINT="/${OUTPUT#* at /}" -- is going to fail if one of the path components of the image file has the same evil suffix.

In general, it is unwise for scripts to make the assumption that spaces will not occur in Unix filenames, but in this case, it is hard to see how that could be avoided.

ian-bruce commented 6 years ago

Apparently, part of the original motivation for udevil was that the Gnome component that it replaced, udisks2, was explicitly not intended to be scriptable:

David Zeuthen seems to have no use for the Linux command line either -- new in version 2’s docs for the command line tool:

This program is not intended to be used by scripts or other programs -- options/commands may change in incompatible ways in the future even in maintenance releases. Scripts and/or other programs should either use the D-Bus APIs of udisks2-daemon(8) or native low-level commands such as mount(8).

Want to write a quick script to mount a device? Forget it, according to David Zeuthen -- that’s not to be done in Linux. While this update may make Gnome’s Disks utility prettier, it undermines the core philosophy of Linux, which is that programs interoperate using simple command line interfaces and text streams. Apparently, the vision here is to make it as closed and convoluted as Windows.

Compare the command line utilities in udisks1 vs udisks2 to see how it has been crippled. Also, all backwards compatibility has been broken, rendering all udisks scripts useless until rewritten.

https://igurublog.wordpress.com/2012/03/11/udisks2-another-loss-for-linux/

This being so, it seems strange that udevil does not offer an alternative to udisks script-unfriendly output. It is reasonable that the default output should remain the same, for compatibility reasons, but there should be an option for use by scripts. As suggested above, the "--quiet" option is currently useless when the mountpoint is not explicitly specified, because you won't know what mountpoint was selected. Either that, or "--script", seems like a sensible choice for scriptable output.