github.com/ddev/ddev@v1.23.2-0.20240519125000-d824ffe36ff3/scripts/windows_ddev_nfs_setup.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  # Set up NFS on Windows for ddev.
     4  
     5  set -o errexit
     6  set -o pipefail
     7  set -o nounset
     8  
     9  # Currently Windows ddev containers run as UID 1000
    10  # We want the NFS mount to do the same.
    11  DDEV_WINDOWS_UID=1000
    12  DDEV_WINDOWS_GID=1000
    13  
    14  nfs_addr=127.0.0.1
    15  
    16  mkdir -p ~/.ddev
    17  docker run --rm -t -v "/$HOME/.ddev:/tmp/junker99" busybox:stable ls //tmp/junker99 >/dev/null || ( echo "Docker does not seem to be running or functional, please check it for problems" && exit 101)
    18  
    19  
    20  status=uninstalled
    21  if nssm status nfsd 2>/dev/null ; then
    22      status=$(nssm status nfsd)
    23  fi
    24  if [ "$status" = "SERVICE_RUNNING" ] ; then
    25      echo "nfsd is already running. You can configure its behavior with 'nssm edit nfsd'."
    26      exit 0
    27  fi
    28  
    29  if [ "$status" = "SERVICE_STOPPED" ] ; then
    30      echo "nfsd was already installed, starting it. You can configure its behavior with 'nssm edit nfsd'"
    31      sudo nssm start nfsd
    32      exit 0
    33  fi
    34  
    35  if ! command -v winnfsd.exe >/dev/null; then
    36      echo "winnfsd.exe does not seem to be installed or is not in the PATH"
    37      exit 102
    38  fi
    39  winnfsd=$(command -v winnfsd.exe)
    40  
    41  if [ -f "$HOME/.ddev/nfs_exports.txt" ]; then
    42      printf "$HOME/.ddev/nfs_exports.txt already exists, not overwriting it, you will be responsible for its exports.\n"
    43  else
    44      echo "
    45  # Exports for winnfsd for ddev
    46  # You can edit these yourself to match your workflow
    47  # But nfs must share your project directory
    48  # Additional lines can be added for additional directories or drives.
    49  ${HOMEDRIVE}${HOMEPATH} > ${HOME}" >"$HOME/.ddev/nfs_exports.txt"
    50  fi
    51  exports=$(cygpath  "$HOMEDRIVE$HOMEPATH\.ddev\nfs_exports.txt")
    52  sudo nssm install nfsd "${winnfsd}" -id ${DDEV_WINDOWS_UID} ${DDEV_WINDOWS_GID} -addr $nfs_addr -log off -pathFile "${exports}"
    53  sudo nssm start nfsd || true
    54  sleep 2
    55  nssm status nfsd
    56  
    57  echo "winnfsd has been installed as service nfsd serving the mounts in ~/.ddev/nfs_exports.txt"
    58  echo "You can edit that file and restart the nfsd service"
    59  echo "with 'sudo nssm restart nfsd'"
    60  echo "Or you can edit its behavior with 'sudo nssm edit nfsd'"