mirror of
https://github.com/kvz/bash3boilerplate.git
synced 2025-03-10 22:43:52 +00:00
* Make the license less restrictive. See #14 So that people can use _just_ main.sh without bothering with also distributing the license * Add license update to changelog * Add a comment about expansion, see #26 * Use an unmodified MIT License, with the more permissive clause inside the code As modifying the MIT License will needlessly (but rightfully) cause suspicion * Credit @bravo-kernel for his feedback * Fix another typo * Reword copyright
78 lines
2.2 KiB
Bash
78 lines
2.2 KiB
Bash
#!/usr/bin/env bash
|
|
# BASH3 Boilerplate: megamount
|
|
#
|
|
# This file:
|
|
#
|
|
# - Takes a URL (smb, nfs, afs) and tries to mount it at a given target directory
|
|
# - Forceully unmounts any active mount at the target directory first
|
|
# - Displays the mounts contents for verification
|
|
#
|
|
# Depends on:
|
|
#
|
|
# - ./parse_url.sh
|
|
#
|
|
# More info:
|
|
#
|
|
# - https://github.com/kvz/bash3boilerplate
|
|
# - http://kvz.io/blog/2013/02/26/introducing-bash3boilerplate/
|
|
#
|
|
# Version: 2.0.0
|
|
#
|
|
# Authors:
|
|
#
|
|
# - Kevin van Zonneveld (http://kvz.io)
|
|
#
|
|
# Usage as a function:
|
|
#
|
|
# source megamount.sh
|
|
# megamount smb://janedoe:abc123@192.168.0.1/documents /mnt/documents
|
|
#
|
|
# Usage as a command:
|
|
#
|
|
# megamount.sh smb://janedoe:abc123@192.168.0.1/documents /mnt/documents
|
|
#
|
|
# Copyright (c) 2013 Kevin van Zonneveld and [contributors](https://github.com/kvz/bash3boilerplate#authors)
|
|
# Licensed under [MIT](https://raw.githubusercontent.com/kvz/bash3boilerplate/master/LICENSE)
|
|
# You are not obligated to bundle the LICENSE file with your b3bp projects as long
|
|
# as you leave these references intact.
|
|
|
|
__dir=$(cd `dirname "${BASH_SOURCE[0]}"` && pwd)
|
|
source "${__dir}/parse_url.sh"
|
|
|
|
function megamount () {
|
|
local url="${1}"
|
|
local target="${2}"
|
|
|
|
local proto=$(parse_url "${url}" "proto")
|
|
local user=$(parse_url "${url}" "user")
|
|
local pass=$(parse_url "${url}" "pass")
|
|
local host=$(parse_url "${url}" "host")
|
|
local port=$(parse_url "${url}" "port")
|
|
local path=$(parse_url "${url}" "path")
|
|
|
|
(umount -lf "${target}" || umount -f "${target}") > /dev/null 2>&1 || true
|
|
mkdir -p "${target}"
|
|
if [ "${proto}" = "smb://" ]; then
|
|
mount -t cifs --verbose -o "username=${user},password=${pass},hard" "//${host}/${path}" "${target}"
|
|
elif [ "${proto}" = "afp://" ]; then
|
|
# start syslog-ng
|
|
# afpfsd || echo "Unable to run afpfsd. Does /dev/log exist?" && exit 1
|
|
mount_afp "${url}" "${target}"
|
|
elif [ "${proto}" = "nfs://" ]; then
|
|
mount -t nfs --verbose -o "vers=3,nolock,soft,intr,rsize=32768,wsize=32768" "${host}:/${path}" "${target}"
|
|
else
|
|
echo "ERR: Unknown protocol: '${proto}'"
|
|
exit 1
|
|
fi
|
|
|
|
# chmod 777 "${target}"
|
|
ls -al "${target}/"
|
|
}
|
|
|
|
if [ "${BASH_SOURCE[0]}" != ${0} ]; then
|
|
export -f megamount
|
|
else
|
|
megamount "${@}"
|
|
exit ${?}
|
|
fi
|