Skip to content

Instantly share code, notes, and snippets.

@dacostafilipe
Created February 14, 2019 15:01
Show Gist options
  • Save dacostafilipe/d4889f3f5245cd1b44963a4c02b08068 to your computer and use it in GitHub Desktop.
Save dacostafilipe/d4889f3f5245cd1b44963a4c02b08068 to your computer and use it in GitHub Desktop.
Add application directory to "/etc/exports" on macOS
#!/usr/bin/env bash
# Inspired by : https://raw.githubusercontent.com/drud/ddev/master/scripts/macos_ddev_nfs_setup.sh
# Move to script folder
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $DIR;
OS=$(uname -s)
if [ $OS != "Darwin" ]; then
echo "This script is OSX-only. Please do not run it on any other Unix."
exit 101
fi
if [[ $EUID -eq 0 ]]; then
echo "This script must NOT be run with sudo/root. Please re-run without sudo." 1>&2
exit 102
fi
# Get parent folder
# In my case, the script is in "./.ddev" that's I need the parent folder for the app
parent="$( cd ../; pwd)";
LINE="${parent} -alldirs -mapall=$(id -u):$(id -g) localhost"
FILE=/etc/exports
TRACKER="#TEST_DISK_ACCESS#";
echo "== Testing write access ..."
# Test to write
sudo bash -c "echo '${TRACKER}' >> $FILE" || ( echo "Unable to edit /etc/exports, need Full Disk Access on Mojave and later" && exit 103 )
# If write was successful, remove the test pattern from file
sudo sed -i "" "/${TRACKER}/d" /etc/exports
echo "== Write to files ..."
# Write to exports
grep -qF -- "$LINE" "$FILE" || ( sudo echo "$LINE" | sudo tee -a $FILE > /dev/null )
# Write to configuration
LINE="nfs.server.mount.require_resv_port = 0"
FILE=/etc/nfs.conf
grep -qF -- "$LINE" "$FILE" || ( sudo echo "$LINE" | sudo tee -a $FILE > /dev/null )
echo "== Restarting nfsd..."
sudo nfsd enable && sudo nfsd restart
hooks:
pre-start:
- exec-host: "bash .ddev/add-to-exports.sh"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment