Created
May 13, 2018 17:10
-
-
Save Kevin-De-Koninck/d150036d92cac39a0c8853dae89d8195 to your computer and use it in GitHub Desktop.
Mount NTFS as RW on macOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Usage example: | |
# ./mount_ntfs.sh DISK_NAME | |
# | |
# Note: | |
# The disk must be mounted at the start of this script. | |
# Check required args | |
if [[ -z $1 ]]; then | |
echo "Please provide the name of the disk that you want to mount." | |
exit 1 | |
else | |
diskname="$1" | |
fi | |
# Check if brew is installed | |
check_brew=$(which brew) | |
install_brew_cmd='/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"' | |
if [[ -z $check_brew ]]; then | |
echo "brew is not installed. Please copy and paste the following command to install brew:" | |
echo $install_brew_cmd | |
exit 1 | |
fi | |
# Check if the required brew packages are installed and install them if not | |
required_osxfuse=$(pkgutil --pkgs | grep -i osxfuse | grep -i core) | |
required_ntfs3g=$(brew list | grep 'ntfs-3g') | |
if [[ -z $required_osxfuse ]]; then | |
echo "osxfuse is not installed. We will install osxfuse now..." | |
brew cask install osxfuse | |
fi | |
if [[ -z $required_ntfs3g ]]; then | |
echo "ntfs-3g is not installed. We will install ntfs-3g now..." | |
brew install ntfs-3g | |
fi | |
# Get real disk name | |
DISK=$(mount | grep $diskname | cut -d ' ' -f 1) | |
# Check if the Disk actually existed | |
if [[ -z $DISK ]]; then | |
echo " Disk '$diskname' does not exist. Nothing to mount..." | |
exit 1 | |
fi | |
# Make sure our mount point is available | |
if [ ! -d "/volumes/NTFS" ]; then | |
sudo mkdir /Volumes/NTFS | |
fi | |
# Now unmount our currently mounted disk | |
sudo umount $DISK | |
# Finally, mount it again as RW NTFS disk | |
sudo /usr/local/bin/ntfs-3g $DISK /Volumes/NTFS -olocal -oallow_other | |
# Check if everything was successfull: | |
success_check=$(mount | grep $DISK | grep osxfuse) | |
if [[ -z $success_check ]]; then | |
echo "Something went wrong!" | |
exit 1 | |
else | |
echo "The disk was mounted successfully, have fun!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment