#!/bin/bash
#
# no-fsck-questions:       prevent fsck stalls.
#
# chkconfig: 2345 50 50
# description: Prevent fsck from stalling on a y/n question.
#

# Fsck question prevention.
#
# By default, on rare occasions fsck will discover errors that it is
# not confident to fix without human permission.  It has an option
# '-y' which lets it know you trust it, as if you were saying yes to
# everything.  Fedora's /etc/rc.sysinit checks for a file called
# /fsckoptions and uses its contents as options for fsck, after which
# it deletes it.  This script rewrites the /fsckoptions file on start.
# It does nothing on stop, because in the normal course of events stop
# is called before the next boot.

start() {
    echo '-y' > /fsckoptions
}

stop(){
    rm /fsckoptions
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
        ## Can't stop, because /fsckoptions needs to last till reboot.
	#stop
	;;
  status)
        if [ grep -q '\-y' /fsckoptions ]; then
            echo "no fsck questions on boot"
        else
            echo "fsck protection is OFF"
        fi
	;;
  restart)
        stop
        start
	;;
#  condrestart)
#	;;
#  condstop)
#	condstop
#	;;
#  reload|force-reload)
#	reload
#	;;
  *)
	echo $"Usage: $0 {start|stop|status|restart}"
	exit 1
esac

