Skip to content

Instantly share code, notes, and snippets.

@manu-romero-411
Created January 5, 2024 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manu-romero-411/c0d3927caf877fa6233ae6bae5e10cb1 to your computer and use it in GitHub Desktop.
Save manu-romero-411/c0d3927caf877fa6233ae6bae5e10cb1 to your computer and use it in GitHub Desktop.
A little script to remount NTFS drives as read-write in macOS (ntfs-3g and macfuse required)
#!/bin/bash
# PEQUEÑA UTILIDAD PARA SACAR PROVECHO DE MACFUSE Y NTFS-3G
# FECHA: 5 de enero de 2024
function print_info(){
green=$(tput setaf 2)
reset=$(tput sgr0)
echo "${green}${@}${reset}"
}
function print_error(){
red=$(tput setaf 1)
yellow=$(tput setaf 3)
echo "${red}${@}${reset}"
}
function print_query(){
cyan=$(tput setaf 6)
yellow=$(tput setaf 3)
echo "${red}${@}${reset}"
}
function mount_disk(){
DISKID="$1"
DISKNAME="$2"
if mount | grep "$DISKID" 2>&1 >/dev/null; then
diskutil umount "$DISKID" 2>&1 >/dev/null || exit 1
fi
mount_ntfs "/dev/$DISKID" "/Volumes/$DISKNAME"
print_info "[INFO] Disco $DISKID montado en /Volumes/$DISKNAME."
}
if [ ! -z $1 ]; then
exit 1
fi
NUM=$(diskutil list | grep "Windows_NTFS" | wc -l | awk '{print $1}')
if [ $NUM -eq 0 ]; then
exit 1
elif [ $NUM -eq 1 ]; then
DISKID=$(diskutil list | grep "Windows_NTFS" | head -n 1 | awk '{print $6}')
DISKNAME=$(diskutil list | grep "Windows_NTFS" | head -n 1 | awk '{print $3}')
mount_disk "$DISKID" "$DISKNAME"
else
print_query "[INFO] Discos a montar:"
IT=1
while [ $IT -le $NUM ]; do
LINE=$(diskutil list | grep 'Windows_NTFS' | head -n $IT | tail -n 1)
print_query "* DISCO $IT ($(echo $LINE | awk '{print $3}')): $(echo $LINE | awk '{print $6}')"
IT=$(($IT + 1))
done
DISKSEL=0
echo " "
while [ $DISKSEL -lt 1 ] || [ $DISKSEL -gt $NUM ]; do
read -p $(print_query "NÚMERO: ") DISKSEL
if [ $DISKSEL -lt 1 ] || [ $DISKSEL -gt $NUM ]; then
print_error "[ERROR] Disco no válido"
fi
done
DISKID=$(diskutil list | grep "Windows_NTFS" | head -n $DISKSEL | tail -n 1 | awk '{print $6}')
DISKNAME=$(diskutil list | grep "Windows_NTFS" | head -n $DISKSEL | tail -n 1 | awk '{print $3}')
mount_disk "$DISKID" "$DISKNAME"
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment