Skip to content

Instantly share code, notes, and snippets.

@amanaplan
Last active May 31, 2017 19:52
Show Gist options
  • Save amanaplan/e0ab3354c8d393f011bbc06600bc9806 to your computer and use it in GitHub Desktop.
Save amanaplan/e0ab3354c8d393f011bbc06600bc9806 to your computer and use it in GitHub Desktop.
Fix Vagrant NFS Bash Script
#!/bin/bash
echo "\r"
echo "This script will attempt to resolve Vagrant-related"
echo "nfsd issues on macOS by removing all entries from"
echo "/etc/exports and restarting nfsd."
echo "\r"
# Ask user to confirm execution.
read -r -p "Would you like to continue? [y/N]: " response
echo "\r"
# Convert response string to lowercase.
response=$(echo "$response" | tr '[A-Z]' '[a-z]')
# Check whether to continue execution.
if [[ "$response" =~ ^(yes|y)$ ]]; then
# Check broadly if user is root or has sudo access.
if [ "$UID" -ne 0 ]; then
echo "This operation requires administrative access."
echo "You may be prompted for your password."
echo "\r"
fi
current_date=$(date +"%Y%m%d-%H%M%S")
filename="/etc/exports.$current_date"
# Copy existing /etc/exports file to backup file.
sudo cp /etc/exports "$filename"
echo "Backing up /etc/export to $filename."
# Delete the existing /etc/exports file,
# as it may be corrupted.
sudo rm -f /etc/exports
echo "Removing all entries from /etc/exports."
# Create a new empty file at /etc/exports
sudo touch /etc/exports
# Stop and start the nfsd service.
# Note: The `nfsd restart` command isn't used
# as it's not verbose.
sudo nfsd stop
sudo nfsd start
# Print the status of the nfsd service.
sudo nfsd status
else
echo "No changes were made."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment