vagrant-lxc-base-boxes/common/ui.sh

56 lines
1.1 KiB
Bash
Raw Normal View History

2014-03-25 03:26:19 +00:00
#!/bin/bash
export NO_COLOR='\033[0m'
export OK_COLOR='\033[32;01m'
export ERROR_COLOR='\033[31;01m'
export WARN_COLOR='\033[33;01m'
log() {
2014-09-24 15:16:20 +00:00
LOG_PREFIX="${DISTRIBUTION}-${RELEASE}"
echo " [${LOG_PREFIX}] ${1}"
2014-03-25 03:26:19 +00:00
}
warn() {
2014-09-24 15:16:20 +00:00
LOG_PREFIX="${DISTRIBUTION}-${RELEASE}"
echo -e "${WARN_COLOR}==> [${LOG_PREFIX}] ${1}${NO_COLOR}"
2014-03-25 03:26:19 +00:00
}
info() {
2014-09-24 15:16:20 +00:00
LOG_PREFIX="${DISTRIBUTION}-${RELEASE}"
echo -e "${OK_COLOR}==> [${LOG_PREFIX}] ${1}${NO_COLOR}"
2014-03-25 03:26:19 +00:00
}
confirm() {
2014-09-24 15:16:20 +00:00
LOG_PREFIX="${DISTRIBUTION}-${RELEASE}"
2014-03-25 03:26:19 +00:00
question=${1}
default=${2}
default_prompt=
if [ $default = 'n' ]; then
default_prompt="y/N"
default='No'
else
default_prompt="Y/n"
default='Yes'
fi
2014-09-24 15:16:20 +00:00
echo -e -n "${WARN_COLOR}==> [${LOG_PREFIX}] ${question} [${default_prompt}] ${NO_COLOR}" >&2
2014-03-25 03:26:19 +00:00
read answer
if [ -z $answer ]; then
debug "Answer not provided, assuming '${default}'"
answer=${default}
fi
if $(echo ${answer} | grep -q -i '^y'); then
return 0
else
return 1
fi
}
debug() {
2014-09-24 15:16:20 +00:00
LOG_PREFIX="${DISTRIBUTION}-${RELEASE}"
[ ! $DEBUG ] || echo " [${LOG_PREFIX}] [DEBUG] ${1}" >&2
2014-03-25 03:26:19 +00:00
}