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