Skip to content
This repository was archived by the owner on Apr 3, 2025. It is now read-only.

Commit 7d080eb

Browse files
achekulaevtonivdv
authored andcommitted
Fix and improve /etc/exports updates (#60)
* Fix and improve /etc/exports changes. Properly remove old bindings. Make them machine-name dependent * Fix the bug that changing shared dir to parent one would not update boot2docker configuration. i.e. if old share was "/Users/macuser" and new one is "/Users" then isNFSMounted would wrongfully report that NFS already mounted * Convert tabs to spaces for code style to be inline with the rest of the file
1 parent 1de478d commit 7d080eb

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

docker-machine-nfs.sh

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -328,16 +328,32 @@ configureNFS()
328328

329329
echoWarn "\n !!! Sudo will be necessary for editing /etc/exports !!!"
330330

331+
#-- Update the /etc/exports file and restart nfsd
332+
333+
local exports_begin="# docker-machine-nfs-begin $prop_machine_name"
334+
local exports_end="# docker-machine-nfs-end $prop_machine_name"
335+
336+
# Remove old docker-machine-nfs exports
337+
local exports=$(cat /etc/exports | \
338+
tr "\n" "\r" | \
339+
sed "s/${exports_begin}.*${exports_end}//" | \
340+
tr "\r" "\n"
341+
)
342+
343+
# Write new exports blocks beginning
344+
exports="${exports}\n${exports_begin}\n"
345+
331346
for shared_folder in "${prop_shared_folders[@]}"
332347
do
333-
# Update the /etc/exports file and restart nfsd
334-
(
335-
echo '\n'$shared_folder' '$prop_machine_ip' '$prop_nfs_config'\n' |
336-
sudo tee -a /etc/exports && awk '!a[$0]++' /etc/exports |
337-
sudo tee /etc/exports
338-
) > /dev/null
348+
# Add new exports
349+
exports="${exports}$shared_folder $prop_machine_ip $prop_nfs_config\n"
339350
done
340351

352+
# Write new exports block ending
353+
exports="${exports}${exports_end}"
354+
#Export to file
355+
echo "$exports" | sudo tee /etc/exports >/dev/null
356+
341357
sudo nfsd restart ; sleep 2 && sudo nfsd checkexports
342358

343359
echoSuccess "\t\t\t\t\t\tOK"
@@ -405,8 +421,8 @@ isNFSMounted()
405421
{
406422
for shared_folder in "${prop_shared_folders[@]}"
407423
do
408-
local nfs_mount=$(docker-machine ssh $prop_machine_name "sudo df" |
409-
grep "$prop_nfshost_ip:$prop_shared_folders")
424+
local nfs_mount=$(docker-machine ssh $prop_machine_name "sudo mount" |
425+
grep "$prop_nfshost_ip:$prop_shared_folders on")
410426
if [ "" = "$nfs_mount" ]; then
411427
echo "false";
412428
return;

0 commit comments

Comments
 (0)