diff options
author | 7heo <7heo@mail.com> | 2016-09-17 15:24:46 +0200 |
---|---|---|
committer | Jakub Jirutka <jakub@jirutka.cz> | 2017-01-18 12:50:54 +0100 |
commit | 47e87b829c09ae3c6f3bcbabc9824d4be9bf35f9 (patch) | |
tree | a01b14d301943365196e4b2bedad8feabbb45bf7 /.travis/common.sh | |
parent | 5906619ff0d1cca4466cb4e93595c6cc5f005111 (diff) | |
download | mkinitfs-47e87b829c09ae3c6f3bcbabc9824d4be9bf35f9.tar.bz2 mkinitfs-47e87b829c09ae3c6f3bcbabc9824d4be9bf35f9.tar.xz |
nlplug-findfs: enable automated testing
Diffstat (limited to '.travis/common.sh')
-rw-r--r-- | .travis/common.sh | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/.travis/common.sh b/.travis/common.sh new file mode 100644 index 0000000..f91e024 --- /dev/null +++ b/.travis/common.sh @@ -0,0 +1,45 @@ +# 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" +} |