#! /bin/bash

# Get temperature value
SENSOR_PROBE="/dev/disk/by-id/$2"
TEMP_STRING=$(hddtemp "$SENSOR_PROBE" | grep --only-matching '[0-9.]\+°C' | head --lines=1 )
TEMP_NUMBER=${TEMP_STRING%°C}

# Set display mode based on arguments
# Default is to display temperature in a console
DISPLAY_MODE="$1"
 
# Set display color based on temperature value
# ≥ 70°C is high, ≥ 80°C is critical
if [ $TEMP_NUMBER -ge 60 ]; then
	case "$DISPLAY_MODE" in
		('conky')
			COLOR='red'
		;;
		('shell')
			COLOR=31
		;;
	esac
elif [ $TEMP_NUMBER -ge 50 ]; then
	case "$DISPLAY_MODE" in
		('conky')
			COLOR='yellow'
		;;
		('shell')
			COLOR=33
		;;
	esac
else
	case "$DISPLAY_MODE" in
		('conky')
			 COLOR='green'
		;;
		('shell')
			COLOR=32
		;;
	esac
fi
 
# Set message syntax based on display mode
case "$DISPLAY_MODE" in
	('conky')
		MESSAGE='${color %s}%s${color}'
	;;
	('shell')
		MESSAGE='\033[1;%sm%s\033[0m\n'
	;;
esac
 
# Print the formatted message
printf "$MESSAGE" "$COLOR" "$TEMP_STRING"
 
exit 0