#!/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; } measure_write_speed() { MEASURE_PATH=$1/urandom.out CACHED_RESULT=$2 if [ "$FORCE" -o ! -e "$CACHED_RESULT" ] then mkdir -p "$(dirname "$CACHED_RESULT")" sync begin=$(date +%s%N) count=500 dd if=/dev/urandom of="$MEASURE_PATH" 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 "$MEASURE_PATH" printf "Sanity check: megabytes/second = %s\n" \ "$(( bytes_per_second / 1000 / 1000 ))" >&2 printf '%s\n' "$bytes_per_second" > "$CACHED_RESULT" fi cat "$CACHED_RESULT" } DIR=~/.mozilla CONFDIR=$HOME/.config/firestart if [ -e "$CONFDIR"/conf ] then . "$CONFDIR"/conf fi disk_write_speed=$(measure_write_speed "$DIR" "$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" <