#!/bin/sh # mount filesystems to $HOME/mnt/{basename_or_label} option_sudo=0 option_label=0 default_opts= mount_dir="$HOME/mnt" while test $# -gt 0 do case "$1" in -s) option_sudo=1;; -l) option_label=1;; -o) shift; default_opts="$1";; --) shift; break;; -*) echo "Unknown option: $1" >&2; exit 1;; *) break;; esac shift done if test $# -eq 0 then echo "usage: $0 [-s] [-l] [-o opts] source ..." echo "mount_dir: $mount_dir" exit fi mkdir -p "$mount_dir" for src in "$@" do if test "$option_label" -eq 1 then tgt="$mount_dir/$src" opts="-L $default_opts" else tgt="$mount_dir/$(basename "$src")" opts="$default_opts" fi if mountpoint --quiet "$tgt" then echo "$tgt already mounted" continue fi mkdir -p "$tgt" if test "$option_sudo" -eq 1 then sudo mount $opts "$src" "$tgt" else mount $opts "$src" "$tgt" fi done