#!/bin/bash

if [[ -n "$2" ]]; then
    sleep "$2"s
fi

#BINDFS_MOUNTS=( ebooks inbox )
BINDFS_MOUNTS=(backup downloads ebooks inbox move outbox public scripts)

for BINDFS_MOUNT in "${BINDFS_MOUNTS[@]}"
do
    NFSROOT="mnt-kutnas"    
    [[ "$BINDFS_MOUNT" == "move" || "$BINDFS_MOUNT" == "downloads" ]]  && NFSROOT=mnt-kutdownload
    if [ "$1" = "start" ]
    then
        sudo systemctl start "$NFSROOT"-"$BINDFS_MOUNT".mount >/dev/null 2>&1 && sudo systemctl start mnt-"$BINDFS_MOUNT".mount
    elif [ "$1" = "stop" ] 
    then
        mountpoint "/mnt/$BINDFS_MOUNT" >/dev/null 2>&1 && sudo fusermount -uz /mnt/"$BINDFS_MOUNT"
    fi
done

