/usr/lib/bash/messages.sh is in libbash 0.9.11-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Do not run this script directly!
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
###########################################################################
# Copyright (c) 2004-2009 Hai Zaar and Gil Ran #
# #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of version 3 of the GNU General Public License as #
# published by the Free Software Foundation. #
# #
###########################################################################
#
# $Date: 2009-05-10 20:08:10 +0300 (Sun, 10 May 2009) $
# $Author: hai-zaar $
#
# Very simple library to help printing message in format similar
# to init scripts
#
#-------------------------------------------------------------------------
#EXPORT=printOK printFAIL printNA printATTN
#REQUIRE=colorPrint
#-------------------------------------------------------------------------
#
# __messages_calculateShift
# Calculate tty width (X) and reports X-10. If its unable to
# determite tty width (for example, in case of serial console),
# returns 80-10
#
# Return value:
# number of columns to move to
#
__messages_calculateShift() {
local ttyXxY=$(stty size 2>/dev/null)
local ttyX=${ttyXxY##* }
# When using remote connections, such as a serial port, stty size returns 0
if [ "$ttyX" = "0" ]; then ttyX=80; fi
let "ttyX = ttyX - 10"
retval=$ttyX
}
#
# __messages_print <COLOR> <TEXT> <INDENT>
#
# Prints TEXT in the color COLOR in the column INDENT.
#
# Parameters:
# COLOR - The color for the tty print.
# TEXT - The text to be printed in the color COLOR.
# INDENT - The column that the message will be printed in.
__messages_print()
{
local COLOR=$1
local TEXT=$2
local INDENT=$3
echo -en "\\033[${INDENT}G["
case ${#TEXT} in
0) echo -en " " ;;
1) echo -en " " ;;
2) echo -en " " ;;
3) echo -en " " ;;
*) echo -en
esac
colorPrint $COLOR $TEXT
case ${#TEXT} in
1) echo -en " " ;;
2) echo -en " " ;;
*) echo -en
esac
echo -e "]"
}
#
# printOK printOK [INDENT]
#
# Prints an OK message.
#
# Parameters:
# INDENT
# The column that the message will be printed in.
# This parameter is optional. If not given, a default value (60) is assined.
printOK()
{
__messages_calculateShift
local SHIFT=$retval
__messages_print GREEN "OK" ${1:-$SHIFT}
}
# printFAIL printFAIL [INDENT]
#
# Prints an FAIL message.
#
# Parameters:
# INDENT
# The column that the message will be printed in.
# This parameter is optional. If not given, a default value (60) is assined.
printFAIL()
{
__messages_calculateShift
local SHIFT=$retval
__messages_print RED "FAIL" ${1:-$SHIFT}
}
# printNA printNA [INDENT]
#
# Prints an N/A message.
#
# Parameters:
# INDENT
# The column that the message will be printed in.
# This parameter is optional. If not given, a default value (60) is assined.
printNA()
{
__messages_calculateShift
local SHIFT=$retval
__messages_print YELLOW "N/A" ${1:-$SHIFT}
}
# printATTN printATTN [INDENT]
#
# Prints an ATTN message.
#
# Parameters:
# INDENT
# The column that the message will be printed in.
# This parameter is optional. If not given, a default value (60) is assined.
printATTN()
{
__messages_calculateShift
local SHIFT=$retval
__messages_print YELLOW "ATTN" ${INDENT:-$SHIFT}
}
# printWAIT printWAIT [INDENT]
#
# Prints an WAIT message.
#
# Parameters:
# INDENT
# The column that the message will be printed in.
# This parameter is optional. If not given, a default value (60) is assined.
printWAIT()
{
__messages_calculateShift
local SHIFT=$retval
__messages_print YELLOW "WAIT" ${INDENT:-$SHIFT}
}
|