#!/bin/bash

CMD=/usr/local/bin/mvcli
DISK=0

function help-message() {
    echo
    echo "(c) 2020 Instituto Superior Tecnico"
    echo "License GPL 2"
    echo "Author: Jose Calhariz <jose.calhariz@tecnico.ulisboa.pt>"
    echo
    usage
}

function usage() {
    echo "-h"
    echo "    print this help message"
    echo "-c cmd"
    echo "    command to check a single disk by default: $CMD"
    echo "-d disk_number"
    echo "    disk number for mvcli"
}

while test $# -ge 1 ; do
    case $1 in
        -h)
	    help-message
	    shift
	    exit 0
	    ;;
        -c)
	    CMD="$2"
	    shift 2
            ;;
        -d)
            DISK=$2
            shift 2
            ;;
        *)
            usage
            exit 1
    esac
done


if $CMD smart -p $DISK | head -n 1 | fgrep -q "OK." ; then
    echo "Disk OK"
    exit 0
fi

$CMD smart -p $DISK | head -n 1
exit 1
