#!/bin/bash

#---
#Requires: ntfsprogs (ntfs-3g)
#Исправление ошибок на ntfs-разделах в Linux
#---

clear

#Проверка $UID (root)
if [ "$UID" -ne "0" ]; then
echo -e "Superuser rights are required to perform the operation! NTFS checking error!\n"
exit 1
fi;

#Найти все разделы ntfs
win=$(blkid | grep 'TYPE="ntfs"' | cut -f1 -d':')
#Разделы не найдены = выйти
if [ -z "$win" ]; then echo -e "NTFS volumes not found, exit...\n"; exit 1; fi

#Демонтаж, проверка, монтирование каждого раздела; (-b tries to fix bad clusters and -d to fix dirty states)
for vol in $win; do umount -l $vol 2>/dev/null; ntfsfix -d $vol; mount $vol 2>/dev/null; echo; done

exit 0;
