#!/bin/bash

ACTIVER_SMARTMONTOOLS=$(CreoleGet activer_smartmontools)

if [ -z "$ACTIVER_SMARTMONTOOLS" ] || [ "$ACTIVER_SMARTMONTOOLS" == "non" ]
then
    exit 0
fi

. /usr/lib/eole/ihm.sh

# Associative array to map oui/on non/off
declare -A ONOFF
ONOFF=( [non]=off [oui]=on )

auto_save="${ONOFF[$(CreoleGet smartmontools_autosave)]}"
data_collect_online="${ONOFF[$(CreoleGet smartmontools_data_collect_online)]}"
data_collect_offline="${ONOFF[$(CreoleGet smartmontools_data_collect_offline)]}"

for disk in $(CreoleGet smartmontools_devs)
do
    smartctl -s "${data_collect_online}" -o "${data_collect_offline}" -S "${auto_save}" \
	"${disk}" > /dev/null 2>&1 \
        || EchoRouge "Problème d'accès au disque $disk: pas de support SMART ?"
done
