-
Notifications
You must be signed in to change notification settings - Fork 2
/
nfs-start.sh
executable file
·82 lines (62 loc) · 1.78 KB
/
nfs-start.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env bash
YES=0; # set option yes
if [[ $1 = "-y" ]]; then
YES=1;
fi
OS=`uname -s`
if [ $OS != "Darwin" ]; then
echo "This script is OSX-only. Please do not run it on any other Unix."
exit 1
fi
if [[ $EUID -eq 0 ]]; then
echo "This script must NOT be run with sudo/root. Please re-run without sudo." 1>&2
exit 1
fi
echo ""
echo " +-----------------------------+"
echo " | Setup native NFS for Docker |"
echo " +-----------------------------+"
echo ""
echo "WARNING: This script will shut down running containers."
if [ "$YES" -ne "1" ]; then
echo -n "Do you wish to proceed? [y]: "
read decision
if [ "$decision" != "y" ]; then
echo "Exiting. No changes made."
exit 1
fi
fi
echo ""
if ! docker ps > /dev/null 2>&1 ; then
echo "== Waiting for docker to start..."
fi
open -a Docker
while ! docker ps > /dev/null 2>&1 ; do sleep 2; done
echo "== Stopping and removing running docker containers..."
docker container rm $(docker container ls -q) -f -v > /dev/null 2>&1
docker volume prune -f > /dev/null
osascript -e 'quit app "Docker"'
U=`id -u`
G=`id -g`
echo "== Setting up nfs..."
FILE="$(pwd)/configuration/etc/exports"
CONTENT=""
while IFS= read -r LINE
do
echo "== changing file permission to ${LINE}"
sudo chown -Rf "$U":"$G" $LINE
echo "== add line to /etc/exports"
echo "${LINE} -alldirs -mapall=${U}:${G} localhost" >> "$(pwd)/builds/exports"
done < "$FILE"
FILE=/etc/exports
sudo cp "$(pwd)/builds/exports" $FILE
sudo rm "$(pwd)/builds/exports"
echo "== setting up etc/nfs.conf"
FILE=/etc/nfs.conf
sudo cp "$(pwd)/configuration/etc/nfs.conf" $FILE
echo "== Restarting nfsd..."
sudo nfsd restart
echo "== Restarting docker..."
open -a Docker
while ! docker ps > /dev/null 2>&1 ; do sleep 2; done
echo "== SUCCESS! Now go run your containers 🐳"