#!/bin/bash
#
# This script accompanies AutoFsck by Jonathan Musther.
# 
# This is a simple script which sets the max-mount-count
# of all of your filesystems to a user specified number
# using tune2fs.
#
# jmusther@gmail.com
#
#------------------SCRIPT STARTS--------------------
#
#Ask the user if they want to continue:
zenity --question --text "This is a simple script to alter the frequency with which your drives will be checked by AutoFsck (if you don't have AutoFsck installed, this will change the frequency with which they are checked on boot).  Do you wish to continue?" --title="AutoFsck - Set Frequency"
if [ "$?" = "1" ]; then
exit
fi
#Find out how often the user wants fsck (or AutoFsck) to run:
FREQ=$(zenity --entry --text="How often would you like to check your drives (in number of boots):" --title="AutoFsck - Set Frequency")
if [ "$?" = "1" ]; then
exit
fi
#Get the password for sudo:
gksudo -u root -k -m "Please enter your password to continue." echo
if [ "$?" != "0" ]; then
zenity --info --text "Cannot continue without the correct password, sorry."
exit
fi
#Find the partitions we need to change:
function mountread {
	for i in $( mount | grep --regexp="/dev/hd" --regexp="/dev/sd" ); do
		echo $i
	done
}
#Loop to determine filesystems that need changing, and change them.
#MC = Mount count - MMC = Max Mount Count.
for i in $( mountread | grep --regexp="/dev/hd" --regexp="/dev/sd" ); do
	sudo tune2fs $i -c $FREQ
done
#Confirm:
zenity --info --text "Your drives will now need checking after every $FREQ boots.  Enjoy :-)" --title="AutoFsck - Set Frequency"
exit
