#!/bin/sh -e
#============================================================================#
# run fstrim for all SSD-based partitions                                    #
#============================================================================#
# (C) Denis Smirnov <mithraen@freesource.info>          http://mithraen.ru/  #
#============================================================================#

cat /proc/mounts \
    | grep ^/dev/sd \
    | perl -npe 's,/dev/(.+?)\d*\s+,$1 ,' \
    | while read dev mnt undef;
do
    [ -f /sys/block/${dev}/queue/rotational ] || continue
    rotational=`cat /sys/block/${dev}/queue/rotational`
    [ "x$rotational" = "x0" ] || continue
    fstrim "$mnt"
done
