summaryrefslogtreecommitdiffstats
path: root/netapp/bin/bfh-netapp-mount
blob: 2fa707428bcbaa872193231a8bd2cdcced4e53be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/sh

set -e

# 192.168
#vmware-arz.bfh.ch \
#vmware-be.bfh.ch \
#vmware-be-ssd.bfh.ch \
#vmware-bi.bfh.ch \

NETAPPS=" \
	app-nfs-arz.bfh.ch \
	app-nfs-be.bfh.ch \
	app-nfs-ssd.bfh.ch \
	backup-be.bfh.ch \
	data-arz.bfh.ch \
	data-be.bfh.ch \
	\
	app-nfs-bi.bfh.ch \
	app-smb-bi.bfh.ch \
	backup-bi.bfh.ch \
	data-bi.bfh.ch \
"
RED="\033[1;33;31m"
GREEN="\033[1;33;32m"
YELLOW="\033[1;33;33m"
BLUE="\033[1;33;34m"
NORMAL="\033[0m"

for NETAPP in ${NETAPPS}
do
	echo "Mounting ${BLUE}${NETAPP}${NORMAL}:"

	MOUNTS="$(showmount --no-headers -e "${NETAPP}" | awk '{ print $1 }')"

	for MOUNT in ${MOUNTS}
	do
		case "${MOUNT}" in
			/|/bfh_img_01_be)
				continue
				;;

			*)
				MOUNT_POINT="/mnt/${NETAPP}/${MOUNT}"
				;;
		esac

		MOUNT_POINT="$(echo "${MOUNT_POINT}" | sed -e 's|//|/|g')"

		echo -n "  * ${NETAPP}:${MOUNT}"

		if mount | grep -qs " ${MOUNT_POINT} "
		then
			echo " ${YELLOW}already done${NORMAL}"
			continue
		fi

		set +e
		MOUNT_RETURN=""
		MOUNT_ERROR="$(mkdir -p "${MOUNT_POINT}" && mount -t nfs -o vers=3,ro "${NETAPP}:${MOUNT}" "${MOUNT_POINT}" 2>&1)"
		MOUNT_RETURN="${?}"
		set -e

		case "${MOUNT_RETURN}" in
			0)
				echo " ${GREEN}done${NORMAL}"

				if ! grep -qs "^${NETAPP}:${MOUNT} " /etc/fstab
				then
					echo "${NETAPP}:${MOUNT} ${MOUNT_POINT} nfs noatime,noauto,ro,vers=3 0 0" >> /etc/fstab
				fi
				;;

			*)
				echo " ${RED}failed${NORMAL} (${MOUNT_ERROR})"

				rmdir -p "${MOUNT_POINT}" > /dev/null 2>&1 || true
				;;
		esac
	done

	echo
done