/[baselayout]/trunk/sbin/functions.sh
Gentoo

Diff of /trunk/sbin/functions.sh

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 344 Revision 345
30# 30#
31# Internal variables 31# Internal variables
32# 32#
33 33
34# Dont output to stdout? 34# Dont output to stdout?
35QUIET_STDOUT="no" 35RC_QUIET_STDOUT="no"
36
37# Should we use color?
38RC_NOCOLOR="no"
36 39
37# 40#
38# Default values for rc system 41# Default values for rc system
39# 42#
40RC_NET_STRICT_CHECKING="no" 43RC_NET_STRICT_CHECKING="no"
45 48
46getcols() { 49getcols() {
47 echo "$2" 50 echo "$2"
48} 51}
49 52
53# Should we use colors ?
50if [ -n "${EBUILD}" ] && [ "${*/depend}" != "$*" ] 54if [ -n "${EBUILD}" ] && [ "${*/depend}" = "$*" ]
51then 55then
56 # Check user pref in portage
57 RC_NOCOLOR="`python -c 'import portage; print portage.settings["NOCOLOR"]' 2> /dev/null`"
58
59elif [ -n "${EBUILD}" ] && [ "${*/depend}" != "$*" ]
60then
61 # We do not want colors or stty to run during emerge depend
62 RC_NOCOLOR="yes"
63
64elif [ "`/bin/consoletype 2> /dev/null`" = "serial" ]
65then
66 # We do not want colors on serial terminals
67 RC_NOCOLOR="yes"
68else
69 # Lastly check if the user disabled it with --nocolor argument
70 for arg in $*
71 do
72 case "${arg}" in
73 --nocolor)
74 RC_NOCOLOR="yes"
75 ;;
76 esac
77 done
78fi
79
80if [ "${RC_NOCOLOR}" = "yes" ]
81then
52 COLS="48 80" 82 COLS="25 80"
83 ENDCOL=
84
85 if [ -n "${EBUILD}" ] && [ "${*/depend}" = "$*" ]
86 then
87 stty cols 80 &>/dev/null
88 stty rows 25 &>/dev/null
89 fi
53else 90else
54 COLS="`stty size 2> /dev/null`" 91 COLS="`stty size 2> /dev/null`"
92 COLS="`getcols ${COLS}`"
93 COLS=$((${COLS} - 7))
94 ENDCOL=$'\e[A\e['${COLS}'G' # Now, ${ENDCOL} will move us to the end of the
95 # column; irregardless of character width
55fi 96fi
56if [ "${COLS}" = "0 0" ]
57then
58 # Fix for serial tty (bug #11557)
59 COLS="24 80"
60 stty cols 80 &>/dev/null
61 stty rows 24 &>/dev/null
62fi
63 97
64COLS="`getcols ${COLS}`" 98if [ "${RC_NOCOLOR}" = "yes" ]
65COLS=$((${COLS} -7))
66ENDCOL=$'\e[A\e['${COLS}'G'
67# Now, ${ENDCOL} will move us to the end of the column;
68# irregardless of character width
69
70# Now setup colors for easy reading
71if [ -n "${EBUILD}" ] && [ "${*/depend}" = "$*" ]
72then
73 NOCOLOR="`python -c 'import portage; print portage.settings["NOCOLOR"]' 2> /dev/null`"
74fi
75if [ -n "${EBUILD}" ] && [ "${*/depend}" = "$*" ] && [ "${NOCOLOR}" = "true" ]
76then 99then
77 GOOD="" 100 GOOD=""
78 WARN="" 101 WARN=""
79 BAD="" 102 BAD=""
80 NORMAL="" 103 NORMAL=""
98esyslog() { 121esyslog() {
99 if [ -x /usr/bin/logger ] 122 if [ -x /usr/bin/logger ]
100 then 123 then
101 pri="$1" 124 pri="$1"
102 tag="$2" 125 tag="$2"
126
103 shift 2 127 shift 2
104 [ -z "$*" ] && return 0 128 [ -z "$*" ] && return 0
129
105 /usr/bin/logger -p "${pri}" -t "${tag}" -- "$*" 130 /usr/bin/logger -p "${pri}" -t "${tag}" -- "$*"
106 fi 131 fi
107} 132}
108 133
109# void einfo(char* message) 134# void einfo(char* message)
110# 135#
111# show an informative message (with a newline) 136# show an informative message (with a newline)
112# 137#
113einfo() { 138einfo() {
114 if [ "${QUIET_STDOUT}" = "yes" ] 139 if [ "${RC_QUIET_STDOUT}" = "yes" ]
115 then 140 then
116 return 141 return
117 else 142 else
118 echo -e " ${GOOD}*${NORMAL} ${*}" 143 echo -e " ${GOOD}*${NORMAL} ${*}"
119 fi 144 fi
122# void einfon(char* message) 147# void einfon(char* message)
123# 148#
124# show an informative message (without a newline) 149# show an informative message (without a newline)
125# 150#
126einfon() { 151einfon() {
127 if [ "${QUIET_STDOUT}" = "yes" ] 152 if [ "${RC_QUIET_STDOUT}" = "yes" ]
128 then 153 then
129 return 154 return
130 else 155 else
131 echo -ne " ${GOOD}*${NORMAL} ${*}" 156 echo -ne " ${GOOD}*${NORMAL} ${*}"
132 fi 157 fi
135# void ewarn(char* message) 160# void ewarn(char* message)
136# 161#
137# show a warning message + log it 162# show a warning message + log it
138# 163#
139ewarn() { 164ewarn() {
140 if [ "${QUIET_STDOUT}" = "yes" ] 165 if [ "${RC_QUIET_STDOUT}" = "yes" ]
141 then 166 then
142 echo " ${*}" 167 echo " ${*}"
143 else 168 else
144 echo -e " ${WARN}*${NORMAL} ${*}" 169 echo -e " ${WARN}*${NORMAL} ${*}"
145 fi 170 fi
151# void eerror(char* message) 176# void eerror(char* message)
152# 177#
153# show an error message + log it 178# show an error message + log it
154# 179#
155eerror() { 180eerror() {
156 if [ "${QUIET_STDOUT}" = "yes" ] 181 if [ "${RC_QUIET_STDOUT}" = "yes" ]
157 then 182 then
158 echo " ${*}" >/dev/stderr 183 echo " ${*}" >/dev/stderr
159 else 184 else
160 echo -e " ${BAD}*${NORMAL} ${*}" 185 echo -e " ${BAD}*${NORMAL} ${*}"
161 fi 186 fi
167# void ebegin(char* message) 192# void ebegin(char* message)
168# 193#
169# show a message indicating the start of a process 194# show a message indicating the start of a process
170# 195#
171ebegin() { 196ebegin() {
172 if [ "${QUIET_STDOUT}" = "yes" ] 197 if [ "${RC_QUIET_STDOUT}" = "yes" ]
173 then 198 then
174 return 199 return
175 else 200 else
201 if [ "${RC_NOCOLOR}" = "yes" ]
202 then
203 echo -ne " ${GOOD}*${NORMAL} ${*}..."
204 else
176 echo -e " ${GOOD}*${NORMAL} ${*}..." 205 echo -e " ${GOOD}*${NORMAL} ${*}..."
206 fi
177 fi 207 fi
178} 208}
179 209
180# void eend(int error, char* errstr) 210# void eend(int error, char* errstr)
181# 211#
183# if error, show errstr via eerror 213# if error, show errstr via eerror
184# 214#
185eend() { 215eend() {
186 if [ "$#" -eq 0 ] || ([ -n "$1" ] && [ "$1" -eq 0 ]) 216 if [ "$#" -eq 0 ] || ([ -n "$1" ] && [ "$1" -eq 0 ])
187 then 217 then
188 if [ "${QUIET_STDOUT}" != "yes" ] 218 if [ "${RC_QUIET_STDOUT}" != "yes" ]
189 then 219 then
190 echo -e "${ENDCOL} ${BRACKET}[ ${GOOD}ok${BRACKET} ]${NORMAL}" 220 echo -e "${ENDCOL} ${BRACKET}[ ${GOOD}ok${BRACKET} ]${NORMAL}"
191 fi 221 fi
192 else 222 else
193 local returnme="$1" 223 local retval="$1"
194 if [ "$#" -ge 2 ] 224 if [ "$#" -ge 2 ]
195 then 225 then
196 shift 226 shift
197 eerror "${*}" 227 eerror "${*}"
198 fi 228 fi
199 if [ "${QUIET_STDOUT}" != "yes" ] 229 if [ "${RC_QUIET_STDOUT}" != "yes" ]
200 then 230 then
201 echo -e "${ENDCOL} ${BRACKET}[ ${BAD}!!${BRACKET} ]${NORMAL}" 231 echo -e "${ENDCOL} ${BRACKET}[ ${BAD}!!${BRACKET} ]${NORMAL}"
202 # extra spacing makes it easier to read 232 # extra spacing makes it easier to read
203 echo 233 echo
204 fi 234 fi
205 return ${returnme} 235 return ${retval}
206 fi 236 fi
207} 237}
208 238
209# void ewend(int error, char *warnstr) 239# void ewend(int error, char *warnstr)
210# 240#
212# if error, show warnstr via ewarn 242# if error, show warnstr via ewarn
213# 243#
214ewend() { 244ewend() {
215 if [ "$#" -eq 0 ] || ([ -n "$1" ] && [ "$1" -eq 0 ]) 245 if [ "$#" -eq 0 ] || ([ -n "$1" ] && [ "$1" -eq 0 ])
216 then 246 then
217 if [ "${QUIET_STDOUT}" != "yes" ] 247 if [ "${RC_QUIET_STDOUT}" != "yes" ]
218 then 248 then
219 echo -e "${ENDCOL} ${BRACKET}[ ${GOOD}ok${BRACKET} ]${NORMAL}" 249 echo -e "${ENDCOL} ${BRACKET}[ ${GOOD}ok${BRACKET} ]${NORMAL}"
220 fi 250 fi
221 else 251 else
222 local returnme="$1" 252 local retval="$1"
223 if [ "$#" -ge 2 ] 253 if [ "$#" -ge 2 ]
224 then 254 then
225 shift 255 shift
226 ewarn "${*}" 256 ewarn "${*}"
227 fi 257 fi
228 if [ "${QUIET_STDOUT}" != "yes" ] 258 if [ "${RC_QUIET_STDOUT}" != "yes" ]
229 then 259 then
230 echo -e "${ENDCOL} ${BRACKET}[ ${WARN}!!${BRACKET} ]${NORMAL}" 260 echo -e "${ENDCOL} ${BRACKET}[ ${WARN}!!${BRACKET} ]${NORMAL}"
231 # extra spacing makes it easier to read 261 # extra spacing makes it easier to read
232 echo 262 echo
233 fi 263 fi
234 return "${returnme}" 264 return "${retval}"
235 fi 265 fi
236} 266}
237 267
238# bool wrap_rcscript(full_path_and_name_of_rc-script) 268# bool wrap_rcscript(full_path_and_name_of_rc-script)
239# 269#

Legend:
Removed from v.344  
changed lines
  Added in v.345

  ViewVC Help
Powered by ViewVC 1.1.20