Browse Source

Code cleanup for hdd.sh

Rewrite disk partition detections - now using gpart show -p insted mount
for get info about FUSE devices.
master
digital-freak 10 years ago
parent
commit
51f2088f0d
  1. 48
      hdd.sh

48
hdd.sh

@ -3,53 +3,66 @@
SMARTCMD="smartctl -B +./drivedb.h"
get_attached_devices() {
# DEVS="`sysctl kern.disks | awk '{$1=""; ;print $0}' | awk 'gsub(" ", "\n")' | grep -v ^$ | sed '/^cd[0-9]/d' | sort`"
DEVS="`sysctl -n kern.disks | tr ' ' '\n' | sed '/^cd[0-9]*/d' | sort`"
DEVS=$( sysctl -n kern.disks | \
tr ' ' '\n' | \
sed '/^cd[0-9]*/d' | \
sort )
echo ${DEVS}
}
get_device_model() {
DEVICE_MODEL="`${SMARTCMD} -i /dev/${1} | grep "Device Model" | awk -F\: '{print $2}' | sed 's/^[ \t]*//'`"
DEVICE_MODEL=$( ${SMARTCMD} -i /dev/${1} | \
grep "Device Model" | \
awk -F\: '{print $2}' | \
sed 's/^[ \t]*//' )
echo ${DEVICE_MODEL}
}
get_device_capacity() {
DEVICE_CAPACITY="`${SMARTCMD} -i /dev/${1} | grep "User Capacity" | awk -F\[ '{print $2}' | sed 's/]//'`"
DEVICE_CAPACITY=$( ${SMARTCMD} -i /dev/${1} | \
grep "User Capacity" | \
awk -F\[ '{print $2}' | \
sed 's/]//' )
echo ${DEVICE_CAPACITY}
}
get_device_temperature() {
DEVICE_TEMP="`${SMARTCMD} -A -f brief /dev/${1} | grep "Temperature_Celsius" | awk '{print $8}'`"
DEVICE_TEMP=$( ${SMARTCMD} -A -f brief /dev/${1} | \
grep "Temperature_Celsius" | \
awk '{print $8}' )
echo ${DEVICE_TEMP}
}
get_device_partitions() {
PARTITIONS="`mount | grep /dev/${1} | grep -v none | awk '{print $1}' | sed 's/\/dev\///' | sort`"
PARTITIONS=$( gpart show -p ${1} | \
grep -Ev "GPT|MBR|- free -" | \
awk '{print $3}' )
echo "${PARTITIONS}"
}
get_mount_point() {
MOUNT_POINT="`mount | grep /dev/${1} | awk '{print $3}'`"
MOUNT_POINT=$( mount | \
grep -E "/dev/${1}|/media/${1}" | \
awk '{print $3}' )
echo ${MOUNT_POINT}
}
for DEV in `get_attached_devices`; do
MODEL="`get_device_model ${DEV}`"
TEMP="`get_device_temperature ${DEV}`"
CAPACITY="`get_device_capacity ${DEV}`"
for DEV in $( get_attached_devices ); do
MODEL=$( get_device_model ${DEV} )
TEMP=$( get_device_temperature ${DEV} )
CAPACITY=$( get_device_capacity ${DEV} )
if [ "${TEMP}" != "" ]; then
TEMP="[ ${TEMP} ℃ ]"
fi
#BEB9A5
printf "\${color 2A403D}\${font Poky:size=16}y\${font}\${color} \${color B53C27}\${hr}\${color}\n"
printf "\${voffset -20}\${alignr}${MODEL} \n\n"
printf "\${voffset -7} ${DEV} (${CAPACITY})\${alignr}${TEMP} \n"
printf "\${voffset -4}\${color B53C27}\${stippled_hr}\${color}\n"
for PARTITION in `get_device_partitions ${DEV}`; do
MP="`get_mount_point ${PARTITION}`"
for PARTITION in $( get_device_partitions ${DEV} ); do
MP=$( get_mount_point ${PARTITION} )
if [ "${MP}" != "" ]; then
printf "\${goto 30}${MP}\${alignr}${PARTITION} \n"
@ -59,11 +72,4 @@ for DEV in `get_attached_devices`; do
fi
done
done
#printf "\n"
# ${font Poky:size=16}y${font} ${color B53C27}${stippled_hr}${color}
# ${voffset -18}${alignr}WDC WD2500AAKS-00F0A0
#
# ${voffset -4}ada2 (250 GB)${alignr}[ 41 ℃ ]
# ${voffset -4}${color B53C27}${hr}${color}

Loading…
Cancel
Save