sshfs-mapper: Allow long command-line options. Test selected map existance.

git-svn-id: https://websvn.glenux.net/svn/Upoc/sshfs-mapper/trunk@1429 eaee96b3-f302-0410-b096-c6cfd47f7835
This commit is contained in:
Glenn Y. Rolland 2009-09-15 10:20:59 +00:00
parent bbcb584348
commit 2ead8e6c50

View file

@ -57,12 +57,12 @@ do_umount() {
do_usage() { do_usage() {
cat >&2 <<EOF cat >&2 <<EOF
Usage: `basename $0` [options] Usage: `basename $0` [options]
-h Show this help and exit. -h, --help Show this help and exit.
-i Initialize user configuration. -i, --init Initialize user configuration.
-l List available maps. -l, --list List available maps.
-a Use all maps. -a, --all Use all maps.
-s Only use specified map. -s, --select <map> Only use specified map.
-u Umount user maps (mount if not specified). -u, --umount Umount user maps (mount if not specified).
EOF EOF
exit 1 exit 1
} }
@ -107,36 +107,48 @@ SSHFS_HOST_PATTERN=" "
SSHFS_HOST_LIMIT=0 SSHFS_HOST_LIMIT=0
SSHFS_HOST_LIST=0 SSHFS_HOST_LIST=0
SSHFS_HOST_AUTO=0 SSHFS_HOST_AUTO=0
#TODO:while getopts h:u o OPTFOUND=0
while getopts ahiuls: o while OPT=${1:-} ; shift
do do
case "$o" in OPTARG=${1:-}
a) # mount all #echo "$OPT?"
case "$OPT" in
--all|-a) # mount all
SSHFS_HOST_AUTO=1 SSHFS_HOST_AUTO=1
OPTFOUND=1
;; ;;
i) # init (copy config files in user HOME) --init|-i) # init (copy config files in user HOME)
do_initialize do_initialize
OPTFOUND=1
;; ;;
u) # umount --umount|-u) # umount
echo "Umounting..." echo "Umounting..."
SSHFS_MOUNT=0 SSHFS_MOUNT=0
OPTFOUND=1
;; ;;
s) # only selected hosts --select|-s) # only selected hosts
SSHFS_HOST_PATTERN="${SSHFS_HOST_PATTERN}${OPTARG} " SSHFS_HOST_PATTERN="${SSHFS_HOST_PATTERN}${OPTARG} "
SSHFS_HOST_LIMIT=1 SSHFS_HOST_LIMIT=1
shift
OPTFOUND=1
;; ;;
l) --list|-l)
SSHFS_HOST_LIST=1 SSHFS_HOST_LIST=1
OPTFOUND=1
;; ;;
--help|-h)
h)
do_usage do_usage
OPTFOUND=1
;; ;;
[?]) *)
do_usage do_usage
OPTFOUND=1
;; ;;
esac esac
done done
if [ $OPTFOUND -eq 0 ]; then
do_usage
fi
if [ ! -e $SSHFS_DIR ]; then mkdir $SSHFS_DIR ; fi if [ ! -e $SSHFS_DIR ]; then mkdir $SSHFS_DIR ; fi
if [ ! -e $SSHFS_DIR ]; then if [ ! -e $SSHFS_DIR ]; then
@ -152,6 +164,12 @@ if [ ! -e "$SSHFS_CONFIG" ]; then
exit 1 exit 1
fi fi
for map_file in $SSHFS_HOST_PATTERN; do
if [ ! -e "$SSHFS_DIR/$map_file.map" ]; then
echo -e "\nERROR: Unable to find map file '$map_file.map'." >&2
fi
done
mountpoint=$( read_conf "$SSHFS_CONFIG" MOUNTPOINT ) mountpoint=$( read_conf "$SSHFS_CONFIG" MOUNTPOINT )
if [ "x$mountpoint" = "x" ]; then if [ "x$mountpoint" = "x" ]; then
echo -e "\nERROR: Mountpoint undefined." >&2 echo -e "\nERROR: Mountpoint undefined." >&2