#!/bin/bash

mode=$1

smart_list=`smartctl --scan | awk '{print $1 ";" $3}'`

#for disk in /dev/{sd[a-z],sd[a-z][a-z],nvme[0-9]n[0-9],nvme[0-9]n[0-9][0-9]}; do

for drv in $smart_list; do
	drive_dev=${drv%%;*}
	drive_type=${drv##*;}

	case $drive_type in
		ata)
			ts=''
		;;
		scsi)
			ts=''
		;;
		*)
			ts="-d $drive_type"
		;;
	esac

		echo "==============================================================================="
		echo "${drive_dev} (${drive_type})"

		case $mode in
			ls)
				smartctl -i $drive_dev $ts |grep --color -e "\(Model\|Capacity\)"
				;;
			id|ids|sn|serial)
				smartctl -i $drive_dev $ts |grep --color -e "\(Model\|Serial\|WWN\|Capacity\)"
				;;
			brief)
#				smartctl -a $drive_dev $ts |grep --color -E '(Model|Wear_Leveling_Count|Power_On_Hours|Pending|Reallocated_Sector|Offline_Uncorrectable)'
				smartctl -a $drive_dev $ts |grep --color -e "\(Model\|Serial\|WWN\|Capacity\|Pending_Sector\|Reallocated_Sector\|Power_On_Hours\|Wear\)"
				;;
			speed|link)
				smartctl -i $drive_dev $ts |grep --color -ie "\(sata\|ata\) version"
				;;
			full|verbose)
				smartctl -a $drive_dev $ts
				;;
			*)
				smartctl -x $drive_dev $ts |grep --color -e "\(Model\|Serial\|WWN\|Capacity\|[P][-O][-S][-R][-C][-K]\|Pending_Sector\|Reallocated_Sector\|Offline_Uncorrectable\|Power_On_Hours\|Temperature_\|Wear\)"
				;;
		esac
		echo
done
