-
Notifications
You must be signed in to change notification settings - Fork 27
/
mount.sh
executable file
·63 lines (46 loc) · 1.39 KB
/
mount.sh
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
#!/bin/bash
# mounts the volume, run as root
source .env
set -u # break on unbound variables
set -x # verbose
mkdir -p "${CONTENT_SERVER_STORAGE}"
MOUNT_DISK=${MOUNT_DISK:-}
# mount the disk $MOUNT_DISK to $CONTENT_SERVER_STORAGE
if [ "$MOUNT_DISK" ]; then
# format if no XFS filesystem
file -s "$MOUNT_DISK" | grep -o XFS
if [ $? -ne 0 ]; then
mkfs.xfs "$MOUNT_DISK"
else
xfs_growfs "$MOUNT_DISK"
fi
echo "Tryint to mount $MOUNT_DISK to ${CONTENT_SERVER_STORAGE}.."
until mount | grep "${CONTENT_SERVER_STORAGE}"; do
mount "$MOUNT_DISK" "${CONTENT_SERVER_STORAGE}";
sleep 10
done
backupFile="/etc/fstab.$(date +%s)"
# find the mounted disk in fstab
presentInFstab=$(cat /etc/fstab | grep -o "$CONTENT_SERVER_STORAGE")
if [ ! "$presentInFstab" ]; then
echo "Configuring fstab"
echo "Backing up to $backupFile"
cp /etc/fstab $backupFile
echo "Setting up automatic mounting of EBS volume..."
blkid \
| grep "$MOUNT_DISK" \
| awk '{print $2}' \
| sed s/\"//g \
| awk '{print $1" '$CONTENT_SERVER_STORAGE' xfs defaults 0 2"}' \
| cat >> /etc/fstab
diff $backupFile /etc/fstab
# unmount
umount "$MOUNT_DISK"
mount -a
# this should work
mount | grep "${CONTENT_SERVER_STORAGE}"
if [ $? -ne 0 ]; then
echo 'ERROR it was not possible to configure automatic mounting of the disk'
fi
fi
fi