Add information messages and silent mode
This commit is contained in:
parent
19dcf6a96e
commit
842543d62f
|
@ -12,10 +12,15 @@ readonly PROGNAME=$(basename "${0}")
|
||||||
readonly PROGDIR=$(readlink -m $(dirname "${0}"))
|
readonly PROGDIR=$(readlink -m $(dirname "${0}"))
|
||||||
readonly ARGS="${*}"
|
readonly ARGS="${*}"
|
||||||
readonly NBARGS="${#}"
|
readonly NBARGS="${#}"
|
||||||
|
|
||||||
[ -z "${DEBUG}" ] && DEBUG=1
|
[ -z "${DEBUG}" ] && DEBUG=1
|
||||||
## Export DEBUG for sub-script
|
## Export DEBUG for sub-script
|
||||||
export DEBUG
|
export DEBUG
|
||||||
|
|
||||||
|
[ -z "${OUTPUT_MESSAGE}" ] && OUTPUT_MESSAGE=0
|
||||||
|
## Export OUTPUT_MESSAGE for sub-script
|
||||||
|
export OUTPUT_MESSAGE
|
||||||
|
|
||||||
## Colors
|
## Colors
|
||||||
readonly PURPLE='\033[1;35m'
|
readonly PURPLE='\033[1;35m'
|
||||||
readonly RED='\033[0;31m'
|
readonly RED='\033[0;31m'
|
||||||
|
@ -45,10 +50,21 @@ EXAMPLES :
|
||||||
# }}}
|
# }}}
|
||||||
debug_message() { # {{{
|
debug_message() { # {{{
|
||||||
|
|
||||||
local_message="${1}"
|
local_debug_message="${1}"
|
||||||
|
|
||||||
## Print message if DEBUG is enable (=0)
|
## Print message if DEBUG is enable (=0)
|
||||||
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6b\e[m\n' "DEBUG − ${PROGNAME} : ${local_message}"
|
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6b\e[m\n' "DEBUG − ${PROGNAME} : ${local_debug_message}"
|
||||||
|
|
||||||
|
}
|
||||||
|
# }}}
|
||||||
|
message() { # {{{
|
||||||
|
|
||||||
|
local_message="${1}"
|
||||||
|
|
||||||
|
## Print message if OUTPUT_MESSAGE is enable (=0)
|
||||||
|
[ "${OUTPUT_MESSAGE}" -eq "0" ] && printf '%b' "${local_message}"
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
}
|
}
|
||||||
# }}}
|
# }}}
|
||||||
|
@ -59,6 +75,7 @@ is_maco_urgent_upgrade_require() {
|
||||||
if [ "${URGENT_TIMESTAMP}" -gt "${CURRENT_TIMESTAMP}" ]; then
|
if [ "${URGENT_TIMESTAMP}" -gt "${CURRENT_TIMESTAMP}" ]; then
|
||||||
debug_message "is_maco_urgent_upgrade_require − \
|
debug_message "is_maco_urgent_upgrade_require − \
|
||||||
Urgent Maco upgrade is available (from version ${CURRENT_MACO_VERSION} to ${URGENT_MACO_VERSION})."
|
Urgent Maco upgrade is available (from version ${CURRENT_MACO_VERSION} to ${URGENT_MACO_VERSION})."
|
||||||
|
message "Urgent Maco upgrade is available (from version ${CURRENT_MACO_VERSION} to ${URGENT_MACO_VERSION})."
|
||||||
return_urgent_upgrade="0"
|
return_urgent_upgrade="0"
|
||||||
else
|
else
|
||||||
debug_message "is_maco_urgent_upgrade_require − \
|
debug_message "is_maco_urgent_upgrade_require − \
|
||||||
|
@ -77,6 +94,7 @@ is_maco_upgrade_require() { # {{{
|
||||||
if [ "${LATEST_TIMESTAMP}" -gt "${CURRENT_TIMESTAMP}" ]; then
|
if [ "${LATEST_TIMESTAMP}" -gt "${CURRENT_TIMESTAMP}" ]; then
|
||||||
debug_message "is_maco_upgrade_require − \
|
debug_message "is_maco_upgrade_require − \
|
||||||
Latest Maco upgrade is available (from version ${CURRENT_MACO_VERSION} to ${LATEST_MACO_VERSION})."
|
Latest Maco upgrade is available (from version ${CURRENT_MACO_VERSION} to ${LATEST_MACO_VERSION})."
|
||||||
|
message "Latest Maco upgrade is available (from version ${CURRENT_MACO_VERSION} to ${LATEST_MACO_VERSION})."
|
||||||
return_upgrade="0"
|
return_upgrade="0"
|
||||||
else
|
else
|
||||||
debug_message "is_maco_upgrade_require − \
|
debug_message "is_maco_upgrade_require − \
|
||||||
|
@ -95,6 +113,7 @@ is_maco_uptodate() { # {{{
|
||||||
if [ "${CURRENT_TIMESTAMP}" = "${LATEST_TIMESTAMP}" ]; then
|
if [ "${CURRENT_TIMESTAMP}" = "${LATEST_TIMESTAMP}" ]; then
|
||||||
debug_message "is_maco_uptodate − \
|
debug_message "is_maco_uptodate − \
|
||||||
Local Maco (${CURRENT_MACO_VERSION}) is up to date (latest : ${LATEST_MACO_VERSION})."
|
Local Maco (${CURRENT_MACO_VERSION}) is up to date (latest : ${LATEST_MACO_VERSION})."
|
||||||
|
message "Local Maco (${CURRENT_MACO_VERSION}) is up to date (latest : ${LATEST_MACO_VERSION})."
|
||||||
return_uptodate="0"
|
return_uptodate="0"
|
||||||
else
|
else
|
||||||
debug_message "is_maco_uptodate − \
|
debug_message "is_maco_uptodate − \
|
||||||
|
@ -152,6 +171,14 @@ if [ ! "${NBARGS}" -eq "0" ]; then
|
||||||
## Re-export new DEBUG value
|
## Re-export new DEBUG value
|
||||||
export DEBUG
|
export DEBUG
|
||||||
;;
|
;;
|
||||||
|
-q|--quiet ) ## Silent mode
|
||||||
|
## Avoid to display any message on standard output
|
||||||
|
OUTPUT_MESSAGE=1
|
||||||
|
;;
|
||||||
|
-s|--silent ) ## Silent mode
|
||||||
|
## Avoid to display any message on standard output
|
||||||
|
OUTPUT_MESSAGE=1
|
||||||
|
;;
|
||||||
-- ) ## End of options list
|
-- ) ## End of options list
|
||||||
## End the while loop
|
## End the while loop
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in New Issue