master
sh 69 lines 912 Bytes
Raw
1 #!/bin/sh
2
3 # This file is included by download.sh & build.sh
4
5 set -e
6
7 color() {
8 fg="$1"
9 bg="${2}"
10 ft="${3:-0}"
11
12 printf "\33[%s;%s;%s" "$ft" "$fg" "$bg"
13 }
14
15 color_reset() {
16 printf "\033[0m"
17 }
18
19 ok() {
20 if [ -t 1 ]; then
21 printf "%s[ OK ]%s\n" "$(color 37 42m 1)" "$(color_reset)"
22 else
23 printf "%s\n" "[ OK ]"
24 fi
25 }
26
27 err() {
28 if [ -t 1 ]; then
29 printf "%s[ ERR ]%s\n" "$(color 37 41m 1)" "$(color_reset)"
30 else
31 printf "%s\n" "[ ERR ]"
32 fi
33 }
34
35 run() {
36 retval=0
37 logfile="$(mktemp -t "run-XXXXXX")"
38 if "$@" 2> "$logfile"; then
39 ok
40 else
41 retval=$?
42 err
43 tail -n 100 "$logfile" || true
44 fi
45 rm -rf "$logfile"
46 return $retval
47 }
48
49 progress() {
50 printf "%-40s" "$(printf "%s ... " "$1")"
51 }
52
53 log() {
54 printf "%s\n" "$1"
55 }
56
57 error() {
58 log "ERROR: ${1}"
59 }
60
61 fail() {
62 log "FATAL: ${1}"
63 exit 1
64 }
65
66 debug() {
67 log "Dropping into a shell for debugging ..."
68 exec /bin/sh
69 }