### xmount  -*- Sh -*-
## (Re)mount multiple filesystems in one go.

### Ivan Shmakov, 2019

## To the extent possible under law, the author(s) have dedicated
## all copyright and related and neighboring rights to this software
## to the public domain worldwide.  This software is distributed
## without any warranty.

## You should have received a copy of the CC0 Public Domain Dedication
## along with this software.  If not, see
## <http://creativecommons.org/publicdomain/zero/1.0/>.

### Commentary:

##  Example:
##    # xmount -v -o remount,rw -- /var/log /dev/vgyotli/lvachij \
##          2b7ab98f-87bb-4ef3-94ec-a2c119d186ba 

### History:

## 0.2  2019-10-31
##      Now a separate program (was: a function in .sh.func.)

## 0.1  2019-09-14
##      Initial revision (as a function in .sh.func.)

### Code:

set -e
set -C -u

# x f
opts=
while [ $# -gt 0 ] ; do
    case "$1" in
        (-v) opts="${opts} ${1}" ; shift ;;
        (-o | -vo) opts="${opts} ${1} ${2}" ; shift 2 ;;
        (--) shift ; break ;;
        (*) break ;;
    esac
done
for x ; do
    if [ -d "$x" ] ; then mount ${opts} -- "$x" ; continue ; fi
    for f in "$x" \
            /dev/disk/by-uuid/"$x" /dev/disk/by-label/"$x" \
            /dev/disk/by-id/"$x" ; do
        test -b "$f" && break
    done
    if [ -b "$f" ] ; then mount ${opts} -- "$x" ; continue ; fi
    printf >&2 "%s: Seems to be none of: a directory, a block device, a UUID, a label\\n" "$x"
done

### xmount ends here
