#!/bin/bash if [ "$1" = -f ] then FORCE=y shift fi if [ $# = 0 ] then TARGET=/dev/stderr else TARGET=$1 fi die() { printf "%s: Error: %s\n" "$0" "$*" >&2; exit 1; } # uses $DIR measure_write_speed() { if [ "$FORCE" -o ! -e "$1" ] then mkdir -p "$(dirname "$1")" sync begin=$(date +%s%N) count=500 dd if=/dev/urandom of="$DIR"/urandom.out bs=1M count=$count conv=fdatasync end=$(date +%s%N) nanosecs=$(( end - begin )) millisecs=$(( nanosecs / 1000 / 1000 )) bytes=$(( count * 1000 * 1000 )) bytes_per_second=$(( 1000 * bytes / millisecs )) rm "$DIR"/urandom.out printf "Sanity check: megabytes/second = %s\n" \ "$(( bytes_per_second / 1000 / 1000 ))" >&2 printf '%s\n' "$bytes_per_second" > "$1" fi cat "$1" } DIR=~/.mozilla CONFDIR=$HOME/.config/firestart if [ -e "$CONFDIR"/conf ] then . "$CONFDIR"/conf fi disk_write_speed=$(measure_write_speed "$CONFDIR"/diskspeed.dat) WRITE_OPS=$(( disk_write_speed / 2 )) READ_OPS=$WRITE_OPS [ -e "$DIR" ] || die "does not exist: $DIR" [ -d "$DIR" ] || die "not a directory: $DIR" DEV=$(echo $(findmnt --target "$DIR" -o MAJ:MIN -n)) [ "$DEV" ] || die "could not determine backing device for $DIR" cat > "$TARGET" <