home: hub: mkinitfs

ref: 26925318e5a5af67e9aaf90fdbbf5672339861a8
dir: /.travis/common.sh/

View raw version
# vim: set ts=4:

readonly ALPINE_ROOT='/mnt/alpine'
readonly ALPINE_USER='alpine'
readonly CLONE_DIR="${CLONE_DIR:-$(pwd)}"

# 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
}

# 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"
}