Added log level as param

This commit is contained in:
Matthias Fulz 2021-07-01 12:20:37 +02:00
parent 5b10887138
commit ab491739ba
3 changed files with 45 additions and 2 deletions

View File

@ -24,6 +24,7 @@ _OPT_DEPS=()
_OPT_KEYS=() _OPT_KEYS=()
_OPT_CON_BUILD_USER="archbuilder" _OPT_CON_BUILD_USER="archbuilder"
_OPT_CON_LOG_LEVEL=""
_OPT_CON_COPTIONS="" _OPT_CON_COPTIONS=""
# actions to initialize runtime # actions to initialize runtime
@ -53,6 +54,7 @@ function usage() {
echo -e " -r, --repo <string>\t\t\t\tHost path to use as repository inside the container. This can be used to avoid" echo -e " -r, --repo <string>\t\t\t\tHost path to use as repository inside the container. This can be used to avoid"
echo -e " \t\t\t\thanding over dependencies via command line arguments as they will be added to this repo" echo -e " \t\t\t\thanding over dependencies via command line arguments as they will be added to this repo"
echo -e " -s, --silent <string>\t\t\t\tMake container silent: No output from container commands will be send to shell." echo -e " -s, --silent <string>\t\t\t\tMake container silent: No output from container commands will be send to shell."
echo -e " -l, --level <string>\t\t\t\tLog level to use: Possible values are DEBUG, INFO, WARN, SUCCESS or ERROR"
echo -e " --version <string>\t\t\t\tPrint version information." echo -e " --version <string>\t\t\t\tPrint version information."
echo echo
echo "coptions:" echo "coptions:"
@ -61,7 +63,7 @@ function usage() {
} }
options=$(getopt \ options=$(getopt \
-o hkn:m:p:d:r:e:s \ -o hkn:m:p:d:r:e:sl: \
-l "help" \ -l "help" \
-l keep \ -l keep \
-l name: \ -l name: \
@ -69,6 +71,7 @@ options=$(getopt \
-l dep: \ -l dep: \
-l repo: \ -l repo: \
-l silent: \ -l silent: \
-l level: \
-l version \ -l version \
-l key: -- "$@" 2>/dev/null) -l key: -- "$@" 2>/dev/null)
@ -101,6 +104,13 @@ while true; do
-s|--silent) -s|--silent)
_FLAG_SILENT=1 _FLAG_SILENT=1
;; ;;
-l|--level)
shift
check_log_level "${1}" \
|| exit_error "${err}"
LOG_LEVEL_STDOUT="${1}"
LOG_LEVEL_LOG="${1}"
;;
--version) --version)
echo -e "archbuilder v${archbuilder_version}" echo -e "archbuilder v${archbuilder_version}"
exit 0 exit 0

View File

@ -6,7 +6,7 @@ function exit_error() {
} }
function check_mode() { function check_mode() {
log_debug "set_mode for val '${1}' called" log_debug "check_mode for val '${1}' called"
if [ -z "${1}" ] if [ -z "${1}" ]
then then
err="Mode not given" err="Mode not given"
@ -33,6 +33,30 @@ function check_mode() {
esac esac
} }
function check_log_level() {
log_debug "check_log_level for val '${1}' called"
if [ -z "${1}" ]
then
err="Log level cannot be empty"
return 1
fi
case "$1" in
"DEBUG" \
| "INFO" \
| "WARN" \
| "SUCCESS" \
| "ERROR")
log_debug "Log level set to '${1}'"
return 0
;;
*)
err="Log level '${1}' invalid"
return 1
;;
esac
}
function check_flag() { function check_flag() {
if [ -z "${2}" ] if [ -z "${2}" ]
then then
@ -44,6 +68,12 @@ function check_flag() {
function set_env() { function set_env() {
log_info "Checking environment and params" log_info "Checking environment and params"
check_log_level "${LOG_LEVEL_STDOUT}" \
|| exit_error "Error setting log level for stdout: '${err}'"
check_log_level "${LOG_LEVEL_LOG}" \
|| exit_error "Error setting log level for log file: '${err}'"
log_debug "Verifying mode '${_OPT_MODE}'" log_debug "Verifying mode '${_OPT_MODE}'"
check_mode "${_OPT_MODE}" \ check_mode "${_OPT_MODE}" \
|| exit_error "${err}" 1 || exit_error "${err}" 1

View File

@ -164,15 +164,18 @@ function buildah_build() {
arrExt=(${arrExt//=/ }) arrExt=(${arrExt//=/ })
ext=$(echo "${arrExt[1]}" | cut -d "'" -f 2) ext=$(echo "${arrExt[1]}" | cut -d "'" -f 2)
log_debug "Running makepkg"
exec_cmd buildah run --user "${_OPT_CON_BUILD_USER}" ${_BUILDAH_PARAMS} "${_BUILDAH_CONT}" \ exec_cmd buildah run --user "${_OPT_CON_BUILD_USER}" ${_BUILDAH_PARAMS} "${_BUILDAH_CONT}" \
bash -c "cd ${_BUILDAH_MKPKG_PATH} && ${_BUILDAH_MAKEPKG_ENV} makepkg ${_BUILDAH_MAKEPKG_FLAGS} ${_OPT_CON_COPTIONS}" bash -c "cd ${_BUILDAH_MKPKG_PATH} && ${_BUILDAH_MAKEPKG_ENV} makepkg ${_BUILDAH_MAKEPKG_FLAGS} ${_OPT_CON_COPTIONS}"
log_debug "Copying to cache repo"
test_null "PKGDEST" "${PKGDEST}" && { test_null "PKGDEST" "${PKGDEST}" && {
exec_cmd buildah run --user "${_OPT_CON_BUILD_USER}" ${_BUILDAH_PARAMS} "${_BUILDAH_CONT}" bash -c "cp ${_BUILDAH_MKPKG_PATH}/*${ext} ${_BUILDAH_CACHE_REPO_PATH}" exec_cmd buildah run --user "${_OPT_CON_BUILD_USER}" ${_BUILDAH_PARAMS} "${_BUILDAH_CONT}" bash -c "cp ${_BUILDAH_MKPKG_PATH}/*${ext} ${_BUILDAH_CACHE_REPO_PATH}"
} || { } || {
exec_cmd buildah run --user "${_OPT_CON_BUILD_USER}" ${_BUILDAH_PARAMS} "${_BUILDAH_CONT}" bash -c "cp ${_BUILDAH_PKGDEST_PATH}/*${ext} ${_BUILDAH_CACHE_REPO_PATH}" exec_cmd buildah run --user "${_OPT_CON_BUILD_USER}" ${_BUILDAH_PARAMS} "${_BUILDAH_CONT}" bash -c "cp ${_BUILDAH_PKGDEST_PATH}/*${ext} ${_BUILDAH_CACHE_REPO_PATH}"
} }
log_debug "Updating cache repo"
exec_cmd buildah run --user "${_OPT_CON_BUILD_USER}" ${_BUILDAH_PARAMS} "${_BUILDAH_CONT}" bash -c "repo-add -n ${_BUILDAH_CACHE_REPO} ${_BUILDAH_CACHE_REPO_PATH}/*${ext}" exec_cmd buildah run --user "${_OPT_CON_BUILD_USER}" ${_BUILDAH_PARAMS} "${_BUILDAH_CONT}" bash -c "repo-add -n ${_BUILDAH_CACHE_REPO} ${_BUILDAH_CACHE_REPO_PATH}/*${ext}"
buildah_exit buildah_exit