aboutsummaryrefslogtreecommitdiffstats
path: root/.travis/common.sh
blob: badb440e405e43d64a0c595752b368a037d68215 (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
58
59
60
61
# vim: set ts=4:

readonly ALPINE_ROOT='/mnt/alpine'
readonly CLONE_DIR="${CLONE_DIR:-$(pwd)}"
readonly MIRROR_URI='http://nl.alpinelinux.org/alpine/edge'

# Runs commands inside the Alpine chroot.
alpine_run() {
	local user="${1:-root}"
	local cmd="${2:-sh}"

	local _sudo=
	[ "$(id -u)" -eq 0 ] || _sudo='sudo'

	$_sudo chroot "$ALPINE_ROOT" /usr/bin/env -i su -l $user \
		sh -c "cd $CLONE_DIR; $cmd"
}

die() {
	print -s1 -c1 "$@\n" 1>&2
	exit 1
}

# Marks start of named folding section for Travis and prints title.
fold_start() {
	local name="$1"
	local title="$2"

	printf "\ntravis_fold:start:$name "
	print -s1 -c6 "> $title\n"
}

# Marks end of the named folding section.
fold_end() {
	local name="$1"

	printf "travis_fold:end:$name\n"
}

# Prints formatted and colored text.
print() {
	local style=0
	local fcolor=9

	local opt; while getopts 's:c:' opt; do
		case "$opt" in
			s) style="$OPTARG";;
			c) fcolor="$OPTARG";;
		esac
	done

	shift $(( OPTIND - 1 ))
	local text="$@"

	printf "\033[${style};3${fcolor}m$text\033[0m"
}

title() {
	printf '\n'
	print -s1 -c6 "==> $@\n"
}