#!/bin/sh
# check the filesystems listed in fstab with / read only
. /usr/lib/nitro/rc.lib
case $1 in
up)
    log "remounting rootfs read-only..."
    mount -o remount,ro / || sos

    log "checking filesystems..."
    fsck -ATat noopts=_netdev
    rc=$?

    # fsck doesn't use 0/nonzero
    case $rc in
        0|1) ;;
        2|3)
            log "filesystem repairs need a reboot to take effect, rebooting..."
            nitroctl Reboot
            sleep 60
        ;;
        *)
            log "fsck failed (exit $rc)"
            sos
        ;;
    esac
    ;;
esac
exit 0
