summaryrefslogtreecommitdiff
path: root/firestart.redux
blob: 59d8f8a5cb5c7467cf2d658a4dfa70ebc8dc676c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash

die() { printf "%s: Error: %s\n" "$0" "$*" >&2; exit 1; }

# Test DEVICE WRITE OPS BY WRITEOPS
test_write_ops()
{
    if ! [ -e "$1" ]
    then
        mkdir -p "$(dirname "$1")"
        sync
        begin=$(date +%s%N)
        dd if=/dev/urandom of="$DIR"/urandom.out bs=1M count=300
        sync
        end=$(date +%s%N)
        ops=$(( (end - begin) / 1000000000 ))
        rm "$DIR"/urandom.out
        echo "$ops" > "$1"
    fi
    cat "$1"
}

CMD=firefox
UNIT=$CMD
DIR=~/.mozilla
READ_OPS=1G
WRITE_OPS=$READ_OPS
CONFDIR=$HOME/.config/firestart

if [ -e "$CONFDIR"/conf ]
then
    . "$CONFDIR"/conf
fi

WRITE_OPS=$(test_write_ops "$CONFDIR"/diskspeed.dat)
WRITE_OPS=${WRITE_OPS%.*}
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"

IOReadIOPSMax="$DEV $READ_OPS"
IOWriteIOPSMax="$DEV $WRITE_OPS"

sed -e "s/^IOReadIOPSMax *=.*/IOReadIOPSMax = $IOReadIOPSMax/" \
    -e "s/^IOWriteIOPSMax *=.*/IOWriteIOPSMax = $IOWriteIOPSMax/" \
    < firefox@.service.in > firefox@.service

set -x

systemctl --user link "$PWD"/firefox@.service
systemctl --user link "$PWD"/ioslay@.service
systemctl --user daemon-reload
systemctl --user start "firefox@$DISPLAY"