1 | # Used to store profile data
|
---|
2 | TIME_FILE=$(dirname $0)/eta-times.txt
|
---|
3 |
|
---|
4 | p_list () {
|
---|
5 | echo "$*" | sed -e 's/ /|## /g' -e 's/^/## /g'
|
---|
6 | }
|
---|
7 |
|
---|
8 | p_info () {
|
---|
9 | echo "$*" | tr '|' '\n' | sed 's/^/# /'
|
---|
10 | }
|
---|
11 |
|
---|
12 | p_warn () {
|
---|
13 | echo "$*" | tr '|' '\n' | sed 's/^/#WARN: /'
|
---|
14 | }
|
---|
15 |
|
---|
16 | p_err () {
|
---|
17 | echo "$*" | tr '|' '\n' | sed 's/^/#ERR: /'
|
---|
18 | }
|
---|
19 |
|
---|
20 | p_sleep() {
|
---|
21 | SLEEP=${1-5}
|
---|
22 | while [ "${SLEEP}" -gt 0 ]; do
|
---|
23 | printf '.'
|
---|
24 | sleep 1
|
---|
25 | SLEEP=`expr ${SLEEP} - 1`
|
---|
26 | done
|
---|
27 | printf '\n'
|
---|
28 | }
|
---|
29 |
|
---|
30 | # Print estimation on how long it normally if going to take
|
---|
31 | f_time() {
|
---|
32 | COMMAND="$*"
|
---|
33 | ETA_TIME=` grep "${COMMAND}$" ${TIME_FILE} 2>/dev/null | awk '{print $1}'`
|
---|
34 | if [ -z "${ETA_TIME}" ]; then
|
---|
35 | ETA_TIME="NaN"
|
---|
36 | fi
|
---|
37 |
|
---|
38 | p_info Last run of "'${COMMAND}'" took ${ETA_TIME}
|
---|
39 | p_info Start time: `date`
|
---|
40 |
|
---|
41 | # Execute command
|
---|
42 | START_TIME=`date "+%s"`
|
---|
43 | $COMMAND
|
---|
44 | RETVAL=$?
|
---|
45 | STOP_TIME=`date "+%s"`
|
---|
46 |
|
---|
47 | p_info End time: `date`
|
---|
48 | # Calculate time it took
|
---|
49 | TOTAL_TIME=`expr ${STOP_TIME} - ${START_TIME}`
|
---|
50 | HUMAN_FMT=`date -ur ${TOTAL_TIME} "+%H:%M:%S"`
|
---|
51 |
|
---|
52 | # Store new time if command is succesfull
|
---|
53 | if [ "${RETVAL}" -eq 0 ]; then
|
---|
54 | grep -v "${COMMAND}$" ${TIME_FILE} > ${TIME_FILE}.tmp 2>/dev/null
|
---|
55 | echo "${HUMAN_FMT} ${COMMAND}" >> ${TIME_FILE}.tmp
|
---|
56 | mv ${TIME_FILE}.tmp ${TIME_FILE}
|
---|
57 | fi
|
---|
58 |
|
---|
59 | # Return the command it's output
|
---|
60 | return ${RETVAL}
|
---|
61 | }
|
---|
62 |
|
---|
63 | f_check_root() {
|
---|
64 | # No Root, no fun
|
---|
65 | if [ `id -u` -ne 0 ]; then
|
---|
66 | print_err Root only
|
---|
67 | exit 1
|
---|
68 | fi
|
---|
69 | }
|
---|
70 |
|
---|
71 | # Find object directory
|
---|
72 | BASEDIR=`dirname $0`
|
---|
73 |
|
---|
74 | # Load the NanoBSD Configuration entries
|
---|
75 | NANO_CFG_FILE="${BASEDIR}/../cfg/nanobsd.wleiden"
|
---|
76 | customize_cmd() { return; }
|
---|
77 | late_customize_cmd() { return; }
|
---|
78 | . $NANO_CFG_FILE
|
---|
79 |
|
---|
80 | OBJDIR="/usr/obj/nanobsd.${NANO_NAME}"
|
---|
81 |
|
---|