Last active
January 3, 2016 21:50
-
-
Save rbobillot/4ddbd80c373e49d18f7c to your computer and use it in GitHub Desktop.
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/sh | |
if [[ $UID != 0 ]] ; then | |
printf "\033[91mPlease run this script as \033[96mSuper User\033[0m\n" | |
exit | |
fi | |
cd /Volumes/ | |
printf "\033[92m" | |
PS3="Please enter your drive's number: " | |
select DRIVENAME in * ; do | |
case $DRIVENAME in | |
"") | |
printf "\n\033[91mError\033[0m: \033[96m$REPLY\033[0m" | |
printf " is not a valid number\n" | |
exit | |
;; | |
*) | |
printf "\n\033[0mYour choice was \033[96m$DRIVENAME\033[0m" | |
printf " (y/n) ? " | |
read choice | |
if [[ $choice != "y" ]] ; then | |
printf "\033[91mExit\033[0m\n" | |
exit | |
fi | |
printf "\033c\033[0m" | |
break | |
;; | |
esac | |
done | |
if [[ $DRIVENAME == "" ]] ; then exit ; fi | |
ERROR="0" | |
printf "Getting disk's UUID: " | |
UUID=$(diskutil info /Volumes/$DRIVENAME | grep UUID | awk '{print $3}') | |
AUTH="UUID=$UUID none ntfs rw,auto,nobrowse" | |
if [[ $UUID != "" ]] ; then | |
printf "\033[92mOK\033[0m\n" | |
printf "Setting up NTFS write support: " | |
if [[ `grep "$AUTH" /etc/fstab` == "" ]] ; then | |
echo $AUTH >> /etc/fstab | |
fi | |
if [[ $? == 0 ]] ; then | |
printf "\033[92mOK\033[0m\n" | |
else | |
printf "\033[91mKO\033[0m\n" | |
ERROR="1" | |
fi | |
printf "Giving access from Desktop: " | |
ln -s /Volumes/$DRIVENAME ~/Desktop/$DRIVENAME | |
if [[ $? == 0 ]] ; then | |
printf "\033[92mOK\033[0m\n" | |
else | |
printf "\033[91mKO\033[0m\n" | |
ERROR="1" | |
fi | |
else | |
printf "\033[91mKO\033[0m\n" | |
ERROR="1" | |
fi | |
function restoreCfg { | |
printf "\033[0mRestoring previous config... " | |
grep -v "$AUTH" /etc/fstab > /etc/fstab | |
rm -rf ~/Desktop/$DRIVENAME | |
diskutil unmount $UUID > /dev/null 2>&1 | |
diskutil mount $UUID > /dev/null 2>&1 | |
printf "\033[92mDone\033[0m\n" | |
} | |
if [[ $ERROR == "0" ]] ; then | |
printf "\033[92mDone\033[0m\n" | |
printf "Unmounting $DRIVENAME... " | |
diskutil unmount $UUID 2> /dev/null | |
printf "Mounting $DRIVENAME... " | |
diskutil mount $UUID 2> /dev/null | |
if [[ $? == 0 ]] ; then | |
printf "\033[92mDone\n\033[93m\n" | |
printf "\033[1;91mDO NOT CLOSE THIS WINDOW\033[93m\n\n" | |
printf "Once you're finished, it is recommended to restore previous settings\033[0m\n" | |
printf "Press \033[96mENTER\033[0m, when you're done, to restore settings...\n" | |
read -s finish | |
restoreCfg | |
else | |
printf "\033[91mError\033[0m\n" | |
restoreCfg | |
fi | |
else | |
printf "\033[91mError\033[0m\n" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment