#!/bin/bash
pname="$(basename "$0")"
default_server=kuiper.lan.informatimago.com
default_mountdir=/mnt/
umount=0
options=( -o nolockd  )
hostname=$(hostname)

function usage(){
    printf "\n%s usage:\n    %s [-s|--server server] [-m|--mountdir mountdir] [-u|--unmount|unmount]\n\n" "$pname" "$pname"
}

server=""
mountdir=""

args=("$@")
i=0;
while [[ $i -lt $# ]] ; do
    arg="${args[$i]}"
    case "$arg" in
    -s|--server|server)     i=$((i+1)) ; server="${args[$i]}"   ;;
    -m|--mountdir|mountdir) i=$((i+1)) ; mountdir="${args[$i]}" ;;
    -u|--umount|--unmount|umount|unmount) umount=1 ;;
    -h|--help|help) usage ; exit 0 ;;
    *)  printf "%s error: unknown option: %s\n" "$pname" "$arg" ; usage ; exit 1 ;;
    esac
    i=$((i+1))
done

server="${server:-${default_server}}"
mountdir="${mountdir:-${default_mountdir}}"

if [ $umount -eq 1 ] ; then
    umount                "${mountdir}"/data
    umount                "${mountdir}"/home
    umount                "${mountdir}"/srv
    case "${hostname}" in
    galatea)
        umount                "${mountdir}"/movies
        ;;
    larissa*)
        umount                "${mountdir}"/movies
        ;;
    triton*)
        true
        ;;
    despina*)
        true
        ;;
    *)
        true
        ;;
    esac
else
    mount "${options[@]}" "${server}":/local/data    "${mountdir}"/data
    mount "${options[@]}" "${server}":/local/home    "${mountdir}"/home
    mount "${options[@]}" "${server}":/local/srv     "${mountdir}"/srv
    case "${hostname}" in
    (larissa*|despina*)
        mount "${options[@]}" "${server}":/movies    "${mountdir}"/movies
        ;;
    galatea*)
        mount "${options[@]}" "${server}":/movies    "${mountdir}"/movies
        ;;
    triton*)
        true
        ;;
    *)
        true
        ;;
    esac
fi
ViewGit