summaryrefslogtreecommitdiff
path: root/nureadahead-init
blob: f8b315be54d90720506b87daaf1ca453a94f34f6 (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
#!/bin/sh

usage() {
    echo "usage: nureadahead-init [FILE [TIMEOUT [INIT [ARGS...]]]]" >&2
}

case "$1" in
    -*) usage; exit 1
esac

case "$#" in
    0) file=/.nureadahead            timeout=120 init=init;;
    1) file=$1                       timeout=120 init=init; shift 1;;
    2) file=$1                       timeout=$2  init=init; shift 2;;
    *) file=$1                       timeout=$2  init=$3;   shift 3;;
esac

export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
device=$(awk '$2 == "/" { d=$1 } END { print d }' < /proc/self/mounts)
if [ -n "$device" ]; then
    if [ -e "$file" ]; then
        nureadahead-preload "$device" < "$file" &
    else
        echo "nureadahead-init: no file, skipping preload" >&2
    fi
    nureadahead-collect "$device" "$timeout" > "$file" &
else
    echo "nureadahead-init: cannot find root device, skipping preload + collect" >&2
fi
exec "$init" "$@"