1 |
Le 07/12/05, Michael Alves<malves@×××××××××.com> a écrit : |
2 |
> Bonjour à tous, |
3 |
> |
4 |
> Suite à une mauvaise manip ... j'ai supprimé le script |
5 |
> /etc/init.d/functions.sh ! (oui oui j'ai honte ! :-[ ) Du coût je me |
6 |
> retrouve avec des erreurs du style : |
7 |
> |
8 |
> /sbin/depscan.sh: line 6: /etc/init.d/functions.sh: No such file or |
9 |
> directory |
10 |
> /sbin/depscan.sh: line 12: eerror: command not found |
11 |
> /sbin/depscan.sh: line 44: ebegin: command not found |
12 |
> |
13 |
> Quelqu'un peut il me dire quel package dois je re-installer pour |
14 |
> récupérer ce script ? |
15 |
|
16 |
ben recréé le ca ira plus vite... : |
17 |
|
18 |
[[ ${RC_QUIET_STDOUT} == yes ]] && return 0 |
19 |
msg="${BRACKET}[ ${GOOD}ok${BRACKET} ]${NORMAL}" |
20 |
else |
21 |
if [[ -c /dev/null ]]; then |
22 |
rc_splash "stop" &>/dev/null & |
23 |
else |
24 |
rc_splash "stop" & |
25 |
fi |
26 |
if [[ -n "$*" ]]; then |
27 |
${efunc} "$*" |
28 |
fi |
29 |
msg="${BRACKET}[ ${BAD}!!${BRACKET} ]${NORMAL}" |
30 |
fi |
31 |
|
32 |
if [[ ${RC_ENDCOL} == yes ]]; then |
33 |
echo -e "${ENDCOL} ${msg}" |
34 |
else |
35 |
[[ ${LAST_E_CMD} == ebegin ]] || LAST_E_LEN=0 |
36 |
printf "%$(( COLS - LAST_E_LEN - 6 ))s%b\n" '' "${msg}" |
37 |
fi |
38 |
|
39 |
return ${retval} |
40 |
} |
41 |
|
42 |
# void eend(int error, char* errstr) |
43 |
# |
44 |
# indicate the completion of process |
45 |
# if error, show errstr via eerror |
46 |
# |
47 |
eend() { |
48 |
local retval=${1:-0} |
49 |
shift |
50 |
|
51 |
_eend ${retval} eerror "$*" |
52 |
|
53 |
LAST_E_CMD=eend |
54 |
return $retval |
55 |
} |
56 |
|
57 |
# void ewend(int error, char* errstr) |
58 |
# |
59 |
# indicate the completion of process |
60 |
# if error, show errstr via ewarn |
61 |
# |
62 |
ewend() { |
63 |
local retval=${1:-0} |
64 |
shift |
65 |
|
66 |
_eend ${retval} ewarn "$*" |
67 |
|
68 |
LAST_E_CMD=ewend |
69 |
return $retval |
70 |
} |
71 |
|
72 |
# v-e-commands honor RC_VERBOSE which defaults to no. |
73 |
# The condition is negated so the return value will be zero. |
74 |
veinfo() { [[ "${RC_VERBOSE}" != yes ]] || einfo "$@"; } |
75 |
veinfon() { [[ "${RC_VERBOSE}" != yes ]] || einfon "$@"; } |
76 |
vewarn() { [[ "${RC_VERBOSE}" != yes ]] || ewarn "$@"; } |
77 |
veerror() { [[ "${RC_VERBOSE}" != yes ]] || eerror "$@"; } |
78 |
vebegin() { [[ "${RC_VERBOSE}" != yes ]] || ebegin "$@"; } |
79 |
veend() { |
80 |
[[ "${RC_VERBOSE}" == yes ]] && { eend "$@"; return $?; } |
81 |
return ${1:-0} |
82 |
} |
83 |
veend() { |
84 |
[[ "${RC_VERBOSE}" == yes ]] && { ewend "$@"; return $?; } |
85 |
return ${1:-0} |
86 |
} |
87 |
|
88 |
# char *KV_major(string) |
89 |
# |
90 |
# Return the Major (X of X.Y.Z) kernel version |
91 |
# |
92 |
KV_major() { |
93 |
[[ -z $1 ]] && return 1 |
94 |
|
95 |
local KV=$@ |
96 |
echo ${KV%%.*} |
97 |
} |
98 |
|
99 |
# char *KV_minor(string) |
100 |
# |
101 |
# Return the Minor (Y of X.Y.Z) kernel version |
102 |
# |
103 |
KV_minor() { |
104 |
[[ -z $1 ]] && return 1 |
105 |
|
106 |
local KV=$@ |
107 |
KV=${KV#*.} |
108 |
echo ${KV%%.*} |
109 |
} |
110 |
|
111 |
# char *KV_micro(string) |
112 |
# |
113 |
# Return the Micro (Z of X.Y.Z) kernel version. |
114 |
# |
115 |
KV_micro() { |
116 |
[[ -z $1 ]] && return 1 |
117 |
|
118 |
local KV=$@ |
119 |
KV=${KV#*.*.} |
120 |
echo ${KV%%[^[:digit:]]*} |
121 |
} |
122 |
|
123 |
# int KV_to_int(string) |
124 |
# |
125 |
# Convert a string type kernel version (2.4.0) to an int (132096) |
126 |
# for easy compairing or versions ... |
127 |
# |
128 |
KV_to_int() { |
129 |
[[ -z $1 ]] && return 1 |
130 |
|
131 |
local KV_MAJOR=$(KV_major "$1") |
132 |
local KV_MINOR=$(KV_minor "$1") |
133 |
local KV_MICRO=$(KV_micro "$1") |
134 |
local KV_int=$(( KV_MAJOR * 65536 + KV_MINOR * 256 + KV_MICRO )) |
135 |
|
136 |
# We make version 2.2.0 the minimum version we will handle as |
137 |
# a sanity check ... if its less, we fail ... |
138 |
if [[ ${KV_int} -ge 131584 ]] ; then |
139 |
echo "${KV_int}" |
140 |
return 0 |
141 |
fi |
142 |
|
143 |
return 1 |
144 |
} |
145 |
|
146 |
# int get_KV() |
147 |
# |
148 |
# Return the kernel version (major, minor and micro concated) as an integer. |
149 |
# Assumes X and Y of X.Y.Z are numbers. Also assumes that some leading |
150 |
# portion of Z is a number. |
151 |
# e.g. 2.4.25, 2.6.10, 2.6.4-rc3, 2.2.40-poop, 2.0.15+foo |
152 |
# |
153 |
get_KV() { |
154 |
local KV=$(uname -r) |
155 |
|
156 |
echo $(KV_to_int "${KV}") |
157 |
|
158 |
return $? |
159 |
} |
160 |
|
161 |
# bool get_bootparam(param) |
162 |
# |
163 |
# return 0 if gentoo=param was passed to the kernel |
164 |
# |
165 |
# EXAMPLE: if get_bootparam "nodevfs" ; then .... |
166 |
# |
167 |
get_bootparam() { |
168 |
local x copt params retval=1 |
169 |
|
170 |
[ ! -r "/proc/cmdline" ] && return 1 |
171 |
|
172 |
for copt in $(< /proc/cmdline) |
173 |
do |
174 |
if [ "${copt%=*}" = "gentoo" ] |
175 |
then |
176 |
params="$(gawk -v PARAMS="${copt##*=}" ' |
177 |
BEGIN { |
178 |
split(PARAMS, nodes, ",") |
179 |
for (x in nodes) |
180 |
print nodes[x] |
181 |
}')" |
182 |
|
183 |
# Parse gentoo option |
184 |
for x in ${params} |
185 |
do |
186 |
if [ "${x}" = "$1" ] |
187 |
then |
188 |
# echo "YES" |
189 |
retval=0 |
190 |
fi |
191 |
done |
192 |
fi |
193 |
done |
194 |
|
195 |
return ${retval} |
196 |
} |
197 |
|
198 |
# Safer way to list the contents of a directory, |
199 |
# as it do not have the "empty dir bug". |
200 |
# |
201 |
# char *dolisting(param) |
202 |
# |
203 |
# print a list of the directory contents |
204 |
# |
205 |
# NOTE: quote the params if they contain globs. |
206 |
# also, error checking is not that extensive ... |
207 |
# |
208 |
dolisting() { |
209 |
local x= |
210 |
local y= |
211 |
local tmpstr= |
212 |
local mylist= |
213 |
local mypath="$*" |
214 |
|
215 |
if [ "${mypath%/\*}" != "${mypath}" ] |
216 |
then |
217 |
mypath="${mypath%/\*}" |
218 |
fi |
219 |
|
220 |
for x in ${mypath} |
221 |
do |
222 |
[ ! -e "${x}" ] && continue |
223 |
|
224 |
if [ ! -d "${x}" ] && ( [ -L "${x}" -o -f "${x}" ] ) |
225 |
then |
226 |
mylist="${mylist} $(ls "${x}" 2> /dev/null)" |
227 |
else |
228 |
[ "${x%/}" != "${x}" ] && x="${x%/}" |
229 |
|
230 |
cd "${x}"; tmpstr="$(ls)" |
231 |
|
232 |
for y in ${tmpstr} |
233 |
do |
234 |
mylist="${mylist} ${x}/${y}" |
235 |
done |
236 |
fi |
237 |
done |
238 |
|
239 |
echo "${mylist}" |
240 |
} |
241 |
|
242 |
# void save_options(char *option, char *optstring) |
243 |
# |
244 |
# save the settings ("optstring") for "option" |
245 |
# |
246 |
save_options() { |
247 |
local myopts="$1" |
248 |
|
249 |
shift |
250 |
if [ ! -d "${svcdir}/options/${myservice}" ] |
251 |
then |
252 |
mkdir -p -m 0755 "${svcdir}/options/${myservice}" |
253 |
fi |
254 |
|
255 |
echo "$*" > "${svcdir}/options/${myservice}/${myopts}" |
256 |
|
257 |
return 0 |
258 |
} |
259 |
|
260 |
# char *get_options(char *option) |
261 |
# |
262 |
# get the "optstring" for "option" that was saved |
263 |
# by calling the save_options function |
264 |
# |
265 |
get_options() { |
266 |
if [ -f "${svcdir}/options/${myservice}/$1" ] |
267 |
then |
268 |
echo "$(< ${svcdir}/options/${myservice}/$1)" |
269 |
fi |
270 |
|
271 |
return 0 |
272 |
} |
273 |
|
274 |
# char *add_suffix(char * configfile) |
275 |
# |
276 |
# Returns a config file name with the softlevel suffix |
277 |
# appended to it. For use with multi-config services. |
278 |
add_suffix() { |
279 |
if [ "${RC_USE_CONFIG_PROFILE}" = "yes" -a -e "$1.${DEFAULTLEVEL}" ] |
280 |
then |
281 |
echo "$1.${DEFAULTLEVEL}" |
282 |
else |
283 |
echo "$1" |
284 |
fi |
285 |
|
286 |
return 0 |
287 |
} |
288 |
|
289 |
# char *get_base_ver() |
290 |
# |
291 |
# get the version of baselayout that this system is running |
292 |
# |
293 |
get_base_ver() { |
294 |
[[ ! -r /etc/gentoo-release ]] && return 0 |
295 |
local ver=$(</etc/gentoo-release) |
296 |
echo ${ver##* } |
297 |
} |
298 |
|
299 |
# Network filesystems list for common use in rc-scripts. |
300 |
# This variable is used in is_net_fs and other places such as |
301 |
# localmount. |
302 |
NET_FS_LIST="afs cifs coda davfs gfs ncpfs nfs nfs4 ocfs2 shfs smbfs" |
303 |
|
304 |
# bool is_net_fs(path) |
305 |
# |
306 |
# return 0 if path is the mountpoint of a networked filesystem |
307 |
# |
308 |
# EXAMPLE: if is_net_fs / ; then ... |
309 |
# |
310 |
is_net_fs() { |
311 |
local fstype |
312 |
# /proc/mounts is always accurate but may not always be available |
313 |
if [[ -e /proc/mounts ]]; then |
314 |
fstype=$( sed -n -e '/^rootfs/!s:.* '"$1"' \([^ |
315 |
]*\).*:\1:p' /proc/mounts ) |
316 |
else |
317 |
fstype=$( mount | sed -n -e 's:.* on '"$1"' type \([^ |
318 |
]*\).*:\1:p' ) |
319 |
fi |
320 |
[[ " ${NET_FS_LIST} " == *" ${fstype} "* ]] |
321 |
return $? |
322 |
} |
323 |
|
324 |
# bool is_uml_sys() |
325 |
# |
326 |
# return 0 if the currently running system is User Mode Linux |
327 |
# |
328 |
# EXAMPLE: if is_uml_sys ; then ... |
329 |
# |
330 |
is_uml_sys() { |
331 |
grep -qs 'UML' /proc/cpuinfo |
332 |
return $? |
333 |
} |
334 |
|
335 |
# bool is_vserver_sys() |
336 |
# |
337 |
# return 0 if the currently running system is a Linux VServer |
338 |
# |
339 |
# EXAMPLE: if is_vserver_sys ; then ... |
340 |
# |
341 |
is_vserver_sys() { |
342 |
grep -qs '^s_context:[[:space:]]*[1-9]' /proc/self/status |
343 |
return $? |
344 |
} |
345 |
|
346 |
# bool is_xenU_sys() |
347 |
# |
348 |
# return 0 if the currently running system is an unprivileged Xen domain |
349 |
# |
350 |
# EXAMPLE: if is_xenU_sys ; then ... |
351 |
# |
352 |
is_xenU_sys() { |
353 |
[[ -d /proc/xen && ! -f /proc/xen/privcmd ]] |
354 |
} |
355 |
|
356 |
# bool get_mount_fstab(path) |
357 |
# |
358 |
# return the parameters to pass to the mount command generated from fstab |
359 |
# |
360 |
# EXAMPLE: cmd=$( get_mount_fstab /proc ) |
361 |
# cmd=${cmd:--t proc none /proc} |
362 |
# mount -n ${cmd} |
363 |
# |
364 |
get_mount_fstab() { |
365 |
awk '$1 ~ "^#" { next } |
366 |
$2 == "'$*'" { stab="-t "$3" -o "$4" "$1" "$2; } |
367 |
END { print stab; } |
368 |
' /etc/fstab |
369 |
} |
370 |
|
371 |
# char *reverse_list(list) |
372 |
# |
373 |
# Returns the reversed order of list |
374 |
# |
375 |
reverse_list() { |
376 |
for (( i = $# ; i > 0 ; --i )); do |
377 |
echo -n "${!i} " |
378 |
done |
379 |
} |
380 |
|
381 |
# void start_addon(addon) |
382 |
# |
383 |
# Starts addon. |
384 |
# |
385 |
start_addon() { |
386 |
local addon=$1 |
387 |
(import_addon ${addon}-start.sh) |
388 |
return 0 |
389 |
} |
390 |
|
391 |
# void start_volumes() |
392 |
# |
393 |
# Starts all volumes in RC_VOLUME_ORDER. |
394 |
# |
395 |
start_volumes() { |
396 |
local x= |
397 |
|
398 |
for x in ${RC_VOLUME_ORDER}; do |
399 |
start_addon "${x}" |
400 |
done |
401 |
|
402 |
return 0 |
403 |
} |
404 |
|
405 |
# void stop_addon(addon) |
406 |
# |
407 |
# Stops addon. |
408 |
# |
409 |
stop_addon() { |
410 |
local addon=$1 |
411 |
(import_addon ${addon}-stop.sh) |
412 |
return 0 |
413 |
} |
414 |
|
415 |
# void stop_volumes() |
416 |
# |
417 |
# Stops all volumes in RC_VOLUME_ORDER (reverse order). |
418 |
# |
419 |
stop_volumes() { |
420 |
local x= |
421 |
|
422 |
for x in $(reverse_list ${RC_VOLUME_ORDER}); do |
423 |
stop_addon "${x}" |
424 |
done |
425 |
|
426 |
return 0 |
427 |
} |
428 |
|
429 |
# bool is_older_than(reference, files/dirs to check) |
430 |
# |
431 |
# return 0 if any of the files/dirs are newer than |
432 |
# the reference file |
433 |
# |
434 |
# EXAMPLE: if is_older_than a.out *.o ; then ... |
435 |
is_older_than() { |
436 |
local x= |
437 |
local ref="$1" |
438 |
shift |
439 |
|
440 |
for x in "$@" ; do |
441 |
[[ ${x} -nt ${ref} ]] && return 0 |
442 |
|
443 |
if [[ -d ${x} ]] ; then |
444 |
is_older_than "${ref}" "${x}"/* && return 0 |
445 |
fi |
446 |
done |
447 |
|
448 |
return 1 |
449 |
} |
450 |
|
451 |
# char* bash_variable(char *variable) |
452 |
# |
453 |
# Turns the given variable into something that bash can use |
454 |
# Basically replaces anything not a-z,A-Z into a _ |
455 |
# |
456 |
bash_variable() { |
457 |
local args="$@" |
458 |
LC_ALL=C echo "${args//[![:word:]]/_}" |
459 |
} |
460 |
|
461 |
# void requote() |
462 |
# |
463 |
# Requotes params so they're suitable to be eval'd, just like this would: |
464 |
# set -- 1 2 "3 4" |
465 |
# /usr/bin/getopt -- '' "$@" | sed 's/^ -- //' |
466 |
# |
467 |
requote() { |
468 |
local q=\' |
469 |
set -- "${@//\'/$q\'$q}" # quote inner instances of ' |
470 |
set -- "${@/#/$q}" # add ' to start of each param |
471 |
set -- "${@/%/$q}" # add ' to end of each param |
472 |
echo "$*" |
473 |
} |
474 |
|
475 |
############################################################################## |
476 |
# # |
477 |
# This should be the last code in here, please add all functions above!! # |
478 |
# # |
479 |
# *** START LAST CODE *** # |
480 |
# # |
481 |
############################################################################## |
482 |
|
483 |
if [ -z "${EBUILD}" ] ; then |
484 |
# Setup a basic $PATH. Just add system default to existing. |
485 |
# This should solve both /sbin and /usr/sbin not present when |
486 |
# doing 'su -c foo', or for something like: PATH= rcscript start |
487 |
PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin:${PATH}" |
488 |
|
489 |
# Cache the CONSOLETYPE - this is important as backgrounded shells don't |
490 |
# have a TTY. rc unsets it at the end of running so it shouldn't hang |
491 |
# around |
492 |
if [[ -z ${CONSOLETYPE} ]]; then |
493 |
export CONSOLETYPE=$( /sbin/consoletype 2>/dev/null ) |
494 |
fi |
495 |
if [[ ${CONSOLETYPE} == "serial" ]] ; then |
496 |
RC_NOCOLOR="yes" |
497 |
RC_ENDCOL="no" |
498 |
fi |
499 |
|
500 |
for arg in "$@" ; do |
501 |
case "${arg}" in |
502 |
# Lastly check if the user disabled it with |
503 |
--nocolor argument |
504 |
--nocolor|-nc) |
505 |
RC_NOCOLOR="yes" |
506 |
;; |
507 |
esac |
508 |
done |
509 |
|
510 |
if [ -r "/proc/cmdline" ] ; then |
511 |
setup_defaultlevels |
512 |
fi |
513 |
else |
514 |
# Should we use colors ? |
515 |
if [[ $* != *depend* ]]; then |
516 |
# Check user pref in portage |
517 |
RC_NOCOLOR="$(portageq envvar NOCOLOR 2>/dev/null)" |
518 |
[ "${RC_NOCOLOR}" = "true" ] && RC_NOCOLOR="yes" |
519 |
else |
520 |
# We do not want colors during emerge depend |
521 |
RC_NOCOLOR="yes" |
522 |
# No output is seen during emerge depend, so this is not needed. |
523 |
RC_ENDCOL="no" |
524 |
fi |
525 |
fi |
526 |
|
527 |
if [[ -n ${EBUILD} && $* = *depend* ]]; then |
528 |
# We do not want stty to run during emerge depend |
529 |
COLS=80 |
530 |
else |
531 |
# Setup COLS and ENDCOL so eend can line up the [ ok ] |
532 |
COLS=${COLUMNS:-0} # bash's internal COLUMNS variable |
533 |
(( COLS == 0 )) && COLS=$(stty size 2>/dev/null | cut -d' ' -f2) |
534 |
(( COLS > 0 )) || (( COLS = 80 )) # width of [ ok ] == 7 |
535 |
fi |
536 |
|
537 |
if [[ ${RC_ENDCOL} == yes ]]; then |
538 |
ENDCOL=$'\e[A\e['$(( COLS - 8 ))'C' |
539 |
else |
540 |
ENDCOL='' |
541 |
fi |
542 |
|
543 |
# Setup the colors so our messages all look pretty |
544 |
if [[ ${RC_NOCOLOR} == yes ]]; then |
545 |
unset GOOD WARN BAD NORMAL HILITE BRACKET |
546 |
else |
547 |
GOOD=$'\e[32;01m' |
548 |
WARN=$'\e[33;01m' |
549 |
BAD=$'\e[31;01m' |
550 |
NORMAL=$'\e[0m' |
551 |
HILITE=$'\e[36;01m' |
552 |
BRACKET=$'\e[34;01m' |
553 |
fi |
554 |
|
555 |
############################################################################## |
556 |
# # |
557 |
# *** END LAST CODE *** # |
558 |
# # |
559 |
# This should be the last code in here, please add all functions above!! # |
560 |
# # |
561 |
############################################################################## |
562 |
|
563 |
|
564 |
# vim:ts=4 |
565 |
-=[root@couteausuisse]=(~)# cat /etc/init.d/functions.sh |
566 |
<(17:24:21)> |
567 |
# Copyright 1999-2005 Gentoo Foundation |
568 |
# Distributed under the terms of the GNU General Public License v2 |
569 |
|
570 |
RC_GOT_FUNCTIONS="yes" |
571 |
|
572 |
# Override defaults with user settings ... |
573 |
[ -f /etc/conf.d/rc ] && source /etc/conf.d/rc |
574 |
|
575 |
# daemontools dir |
576 |
SVCDIR="/var/lib/supervise" |
577 |
|
578 |
# Check /etc/conf.d/rc for a description of these ... |
579 |
svclib="/lib/rcscripts" |
580 |
svcdir=${svcdir:-/var/lib/init.d} |
581 |
svcmount=${svcmount:-no} |
582 |
svcfstype=${svcfstype:-tmpfs} |
583 |
svcsize=${svcsize:-1024} |
584 |
|
585 |
# Different types of dependencies |
586 |
deptypes="need use" |
587 |
# Different types of order deps |
588 |
ordtypes="before after" |
589 |
|
590 |
# |
591 |
# Internal variables |
592 |
# |
593 |
|
594 |
# Dont output to stdout? |
595 |
RC_QUIET_STDOUT="no" |
596 |
RC_VERBOSE=${RC_VERBOSE:-no} |
597 |
|
598 |
# Should we use color? |
599 |
RC_NOCOLOR=${RC_NOCOLOR:-no} |
600 |
# Can the terminal handle endcols? |
601 |
RC_ENDCOL="yes" |
602 |
|
603 |
# |
604 |
# Default values for rc system |
605 |
# |
606 |
RC_TTY_NUMBER=${RC_TTY_NUMBER:-11} |
607 |
RC_PARALLEL_STARTUP=${RC_PARALLEL_STARTUP:-no} |
608 |
RC_NET_STRICT_CHECKING=${RC_NET_STRICT_CHECKING:-no} |
609 |
RC_VOLUME_ORDER=${RC_VOLUME_ORDER:-raid evms lvm dm} |
610 |
RC_USE_FSTAB=${RC_USE_FSTAB:-no} |
611 |
RC_USE_CONFIG_PROFILE=${RC_USE_CONFIG_PROFILE:-yes} |
612 |
RC_FORCE_AUTO=${RC_FORCE_AUTO:-no} |
613 |
RC_DEVICES=${RC_DEVICES:-auto} |
614 |
|
615 |
# |
616 |
# Default values for e-message indentation and dots |
617 |
# |
618 |
RC_INDENTATION='' |
619 |
RC_DEFAULT_INDENT=2 |
620 |
#RC_DOT_PATTERN=' .' |
621 |
RC_DOT_PATTERN='' |
622 |
|
623 |
# void import_addon(char *addon) |
624 |
# |
625 |
# Import code from the specified addon if it exists |
626 |
# |
627 |
import_addon() { |
628 |
local addon=${svclib}/addons/$1 |
629 |
if [[ -r ${addon} ]] ; then |
630 |
source "${addon}" |
631 |
return 0 |
632 |
fi |
633 |
return 1 |
634 |
} |
635 |
|
636 |
# void splash(...) |
637 |
# |
638 |
# Notify bootsplash/splashutils/gensplash/whatever about |
639 |
# important events. |
640 |
# |
641 |
splash() { |
642 |
return 0 |
643 |
} |
644 |
# This will override the splash() function... |
645 |
if ! import_addon splash-functions.sh ; then |
646 |
[ -f /sbin/splash-functions.sh ] && source /sbin/splash-functions.sh |
647 |
fi |
648 |
|
649 |
# void profiling(...) |
650 |
# |
651 |
# Notify bootsplash/whatever about important events. |
652 |
# |
653 |
profiling() { |
654 |
return 0 |
655 |
} |
656 |
import_addon profiling-functions.sh |
657 |
|
658 |
# void bootlog(...) |
659 |
# |
660 |
# Notify bootlogger about important events. |
661 |
bootlog() { |
662 |
return 0 |
663 |
} |
664 |
[[ ${RC_BOOTLOG} == "yes" ]] && import_addon bootlogger.sh |
665 |
|
666 |
# void get_bootconfig() |
667 |
# |
668 |
# Get the BOOTLEVEL and SOFTLEVEL by setting |
669 |
# 'bootlevel' and 'softlevel' via kernel |
670 |
# parameters. |
671 |
# |
672 |
get_bootconfig() { |
673 |
local copt= |
674 |
local newbootlevel= |
675 |
local newsoftlevel= |
676 |
|
677 |
if [[ -r /proc/cmdline ]] ; then |
678 |
for copt in $(</proc/cmdline) ; do |
679 |
case "${copt%=*}" in |
680 |
bootlevel) |
681 |
newbootlevel=${copt##*=} |
682 |
;; |
683 |
softlevel) |
684 |
newsoftlevel=${copt##*=} |
685 |
;; |
686 |
esac |
687 |
done |
688 |
fi |
689 |
|
690 |
if [[ -n ${newbootlevel} ]] ; then |
691 |
export BOOTLEVEL=${newbootlevel} |
692 |
else |
693 |
export BOOTLEVEL="boot" |
694 |
fi |
695 |
|
696 |
if [[ -n ${newsoftlevel} ]] ; then |
697 |
export DEFAULTLEVEL=${newsoftlevel} |
698 |
else |
699 |
export DEFAULTLEVEL="default" |
700 |
fi |
701 |
|
702 |
return 0 |
703 |
} |
704 |
|
705 |
setup_defaultlevels() { |
706 |
get_bootconfig |
707 |
|
708 |
if get_bootparam "noconfigprofile" ; then |
709 |
export RC_USE_CONFIG_PROFILE="no" |
710 |
|
711 |
elif get_bootparam "configprofile" ; then |
712 |
export RC_USE_CONFIG_PROFILE="yes" |
713 |
fi |
714 |
|
715 |
if [ "${RC_USE_CONFIG_PROFILE}" = "yes" -a -n "${DEFAULTLEVEL}" ] && \ |
716 |
[ -d "/etc/runlevels/${BOOTLEVEL}.${DEFAULTLEVEL}" -o \ |
717 |
-L "/etc/runlevels/${BOOTLEVEL}.${DEFAULTLEVEL}" ] |
718 |
then |
719 |
export BOOTLEVEL="${BOOTLEVEL}.${DEFAULTLEVEL}" |
720 |
fi |
721 |
|
722 |
if [ -z "${SOFTLEVEL}" ] ; then |
723 |
if [ -f "${svcdir}/softlevel" ] ; then |
724 |
export SOFTLEVEL="$(< ${svcdir}/softlevel)" |
725 |
else |
726 |
export SOFTLEVEL="${BOOTLEVEL}" |
727 |
fi |
728 |
fi |
729 |
|
730 |
return 0 |
731 |
} |
732 |
|
733 |
# void get_libdir(void) |
734 |
# |
735 |
# prints the current libdir {lib,lib32,lib64} |
736 |
# |
737 |
get_libdir() { |
738 |
if [ -n "${CONF_LIBDIR_OVERRIDE}" ] ; then |
739 |
CONF_LIBDIR="${CONF_LIBDIR_OVERRIDE}" |
740 |
elif [ -x "/usr/bin/portageq" ] ; then |
741 |
CONF_LIBDIR="$(/usr/bin/portageq envvar CONF_LIBDIR)" |
742 |
fi |
743 |
echo ${CONF_LIBDIR:=lib} |
744 |
} |
745 |
|
746 |
# void esyslog(char* priority, char* tag, char* message) |
747 |
# |
748 |
# use the system logger to log a message |
749 |
# |
750 |
esyslog() { |
751 |
local pri= |
752 |
local tag= |
753 |
|
754 |
if [ -x /usr/bin/logger ] |
755 |
then |
756 |
pri="$1" |
757 |
tag="$2" |
758 |
|
759 |
shift 2 |
760 |
[[ -z "$*" ]] && return 0 |
761 |
|
762 |
/usr/bin/logger -p "${pri}" -t "${tag}" -- "$*" |
763 |
fi |
764 |
|
765 |
return 0 |
766 |
} |
767 |
|
768 |
# void eindent(int num) |
769 |
# |
770 |
# increase the indent used for e-commands. |
771 |
# |
772 |
eindent() { |
773 |
local i=$1 |
774 |
(( i > 0 )) || (( i = RC_DEFAULT_INDENT )) |
775 |
esetdent $(( ${#RC_INDENTATION} + i )) |
776 |
} |
777 |
|
778 |
# void eoutdent(int num) |
779 |
# |
780 |
# decrease the indent used for e-commands. |
781 |
# |
782 |
eoutdent() { |
783 |
local i=$1 |
784 |
(( i > 0 )) || (( i = RC_DEFAULT_INDENT )) |
785 |
esetdent $(( ${#RC_INDENTATION} - i )) |
786 |
} |
787 |
|
788 |
# void esetdent(int num) |
789 |
# |
790 |
# hard set the indent used for e-commands. |
791 |
# num defaults to 0 |
792 |
# |
793 |
esetdent() { |
794 |
local i=$1 |
795 |
(( i < 0 )) && (( i = 0 )) |
796 |
RC_INDENTATION=$(printf "%${i}s" '') |
797 |
} |
798 |
|
799 |
# void einfo(char* message) |
800 |
# |
801 |
# show an informative message (with a newline) |
802 |
# |
803 |
einfo() { |
804 |
einfon "$*\n" |
805 |
LAST_E_CMD=einfo |
806 |
return 0 |
807 |
} |
808 |
|
809 |
# void einfon(char* message) |
810 |
# |
811 |
# show an informative message (without a newline) |
812 |
# |
813 |
einfon() { |
814 |
[[ ${RC_QUIET_STDOUT} == yes ]] && return 0 |
815 |
[[ ${RC_ENDCOL} != yes && ${LAST_E_CMD} == ebegin ]] && echo |
816 |
echo -ne " ${GOOD}*${NORMAL} ${RC_INDENTATION}$*" |
817 |
LAST_E_CMD=einfon |
818 |
return 0 |
819 |
} |
820 |
|
821 |
# void ewarn(char* message) |
822 |
# |
823 |
# show a warning message + log it |
824 |
# |
825 |
ewarn() { |
826 |
if [[ ${RC_QUIET_STDOUT} == yes ]]; then |
827 |
echo " $*" |
828 |
else |
829 |
[[ ${RC_ENDCOL} != yes && ${LAST_E_CMD} == ebegin ]] && echo |
830 |
echo -e " ${WARN}*${NORMAL} ${RC_INDENTATION}$*" |
831 |
fi |
832 |
|
833 |
# Log warnings to system log |
834 |
esyslog "daemon.warning" "rc-scripts" "$*" |
835 |
|
836 |
LAST_E_CMD=ewarn |
837 |
return 0 |
838 |
} |
839 |
|
840 |
# void eerror(char* message) |
841 |
# |
842 |
# show an error message + log it |
843 |
# |
844 |
eerror() { |
845 |
if [[ ${RC_QUIET_STDOUT} == yes ]]; then |
846 |
echo " $*" >/dev/stderr |
847 |
else |
848 |
[[ ${RC_ENDCOL} != yes && ${LAST_E_CMD} == ebegin ]] && echo |
849 |
echo -e " ${BAD}*${NORMAL} ${RC_INDENTATION}$*" |
850 |
fi |
851 |
|
852 |
# Log errors to system log |
853 |
esyslog "daemon.err" "rc-scripts" "$*" |
854 |
|
855 |
LAST_E_CMD=eerror |
856 |
return 0 |
857 |
} |
858 |
|
859 |
# void ebegin(char* message) |
860 |
# |
861 |
# show a message indicating the start of a process |
862 |
# |
863 |
ebegin() { |
864 |
local msg="$*" dots spaces=${RC_DOT_PATTERN//?/ } |
865 |
[[ ${RC_QUIET_STDOUT} == yes ]] && return 0 |
866 |
|
867 |
if [[ -n ${RC_DOT_PATTERN} ]]; then |
868 |
dots=$(printf "%$(( COLS - 3 - ${#RC_INDENTATION} - |
869 |
${#msg} - 7 ))s" '') |
870 |
dots=${dots//${spaces}/${RC_DOT_PATTERN}} |
871 |
msg="${msg}${dots}" |
872 |
else |
873 |
msg="${msg} ..." |
874 |
fi |
875 |
einfon "${msg}" |
876 |
[[ ${RC_ENDCOL} == yes ]] && echo |
877 |
|
878 |
LAST_E_LEN=$(( 3 + ${#RC_INDENTATION} + ${#msg} )) |
879 |
LAST_E_CMD=ebegin |
880 |
return 0 |
881 |
} |
882 |
|
883 |
# void _eend(int error, char *efunc, char* errstr) |
884 |
# |
885 |
# indicate the completion of process, called from eend/ewend |
886 |
# if error, show errstr via efunc |
887 |
# |
888 |
# This function is private to functions.sh. Do not call it from a |
889 |
# script. |
890 |
# |
891 |
_eend() { |
892 |
local retval=${1:-0} efunc=${2:-eerror} msg |
893 |
shift 2 |
894 |
|
895 |
if [[ ${retval} == 0 ]]; then |
896 |
[[ ${RC_QUIET_STDOUT} == yes ]] && return 0 |
897 |
msg="${BRACKET}[ ${GOOD}ok${BRACKET} ]${NORMAL}" |
898 |
else |
899 |
if [[ -c /dev/null ]]; then |
900 |
rc_splash "stop" &>/dev/null & |
901 |
else |
902 |
rc_splash "stop" & |
903 |
fi |
904 |
if [[ -n "$*" ]]; then |
905 |
${efunc} "$*" |
906 |
fi |
907 |
msg="${BRACKET}[ ${BAD}!!${BRACKET} ]${NORMAL}" |
908 |
fi |
909 |
|
910 |
if [[ ${RC_ENDCOL} == yes ]]; then |
911 |
echo -e "${ENDCOL} ${msg}" |
912 |
else |
913 |
[[ ${LAST_E_CMD} == ebegin ]] || LAST_E_LEN=0 |
914 |
printf "%$(( COLS - LAST_E_LEN - 6 ))s%b\n" '' "${msg}" |
915 |
fi |
916 |
|
917 |
return ${retval} |
918 |
} |
919 |
|
920 |
# void eend(int error, char* errstr) |
921 |
# |
922 |
# indicate the completion of process |
923 |
# if error, show errstr via eerror |
924 |
# |
925 |
eend() { |
926 |
local retval=${1:-0} |
927 |
shift |
928 |
|
929 |
_eend ${retval} eerror "$*" |
930 |
|
931 |
LAST_E_CMD=eend |
932 |
return $retval |
933 |
} |
934 |
|
935 |
# void ewend(int error, char* errstr) |
936 |
# |
937 |
# indicate the completion of process |
938 |
# if error, show errstr via ewarn |
939 |
# |
940 |
ewend() { |
941 |
local retval=${1:-0} |
942 |
shift |
943 |
|
944 |
_eend ${retval} ewarn "$*" |
945 |
|
946 |
LAST_E_CMD=ewend |
947 |
return $retval |
948 |
} |
949 |
|
950 |
# v-e-commands honor RC_VERBOSE which defaults to no. |
951 |
# The condition is negated so the return value will be zero. |
952 |
veinfo() { [[ "${RC_VERBOSE}" != yes ]] || einfo "$@"; } |
953 |
veinfon() { [[ "${RC_VERBOSE}" != yes ]] || einfon "$@"; } |
954 |
vewarn() { [[ "${RC_VERBOSE}" != yes ]] || ewarn "$@"; } |
955 |
veerror() { [[ "${RC_VERBOSE}" != yes ]] || eerror "$@"; } |
956 |
vebegin() { [[ "${RC_VERBOSE}" != yes ]] || ebegin "$@"; } |
957 |
veend() { |
958 |
[[ "${RC_VERBOSE}" == yes ]] && { eend "$@"; return $?; } |
959 |
return ${1:-0} |
960 |
} |
961 |
veend() { |
962 |
[[ "${RC_VERBOSE}" == yes ]] && { ewend "$@"; return $?; } |
963 |
return ${1:-0} |
964 |
} |
965 |
|
966 |
# char *KV_major(string) |
967 |
# |
968 |
# Return the Major (X of X.Y.Z) kernel version |
969 |
# |
970 |
KV_major() { |
971 |
[[ -z $1 ]] && return 1 |
972 |
|
973 |
local KV=$@ |
974 |
echo ${KV%%.*} |
975 |
} |
976 |
|
977 |
# char *KV_minor(string) |
978 |
# |
979 |
# Return the Minor (Y of X.Y.Z) kernel version |
980 |
# |
981 |
KV_minor() { |
982 |
[[ -z $1 ]] && return 1 |
983 |
|
984 |
local KV=$@ |
985 |
KV=${KV#*.} |
986 |
echo ${KV%%.*} |
987 |
} |
988 |
|
989 |
# char *KV_micro(string) |
990 |
# |
991 |
# Return the Micro (Z of X.Y.Z) kernel version. |
992 |
# |
993 |
KV_micro() { |
994 |
[[ -z $1 ]] && return 1 |
995 |
|
996 |
local KV=$@ |
997 |
KV=${KV#*.*.} |
998 |
echo ${KV%%[^[:digit:]]*} |
999 |
} |
1000 |
|
1001 |
# int KV_to_int(string) |
1002 |
# |
1003 |
# Convert a string type kernel version (2.4.0) to an int (132096) |
1004 |
# for easy compairing or versions ... |
1005 |
# |
1006 |
KV_to_int() { |
1007 |
[[ -z $1 ]] && return 1 |
1008 |
|
1009 |
local KV_MAJOR=$(KV_major "$1") |
1010 |
local KV_MINOR=$(KV_minor "$1") |
1011 |
local KV_MICRO=$(KV_micro "$1") |
1012 |
local KV_int=$(( KV_MAJOR * 65536 + KV_MINOR * 256 + KV_MICRO )) |
1013 |
|
1014 |
# We make version 2.2.0 the minimum version we will handle as |
1015 |
# a sanity check ... if its less, we fail ... |
1016 |
if [[ ${KV_int} -ge 131584 ]] ; then |
1017 |
echo "${KV_int}" |
1018 |
return 0 |
1019 |
fi |
1020 |
|
1021 |
return 1 |
1022 |
} |
1023 |
|
1024 |
# int get_KV() |
1025 |
# |
1026 |
# Return the kernel version (major, minor and micro concated) as an integer. |
1027 |
# Assumes X and Y of X.Y.Z are numbers. Also assumes that some leading |
1028 |
# portion of Z is a number. |
1029 |
# e.g. 2.4.25, 2.6.10, 2.6.4-rc3, 2.2.40-poop, 2.0.15+foo |
1030 |
# |
1031 |
get_KV() { |
1032 |
local KV=$(uname -r) |
1033 |
|
1034 |
echo $(KV_to_int "${KV}") |
1035 |
|
1036 |
return $? |
1037 |
} |
1038 |
|
1039 |
# bool get_bootparam(param) |
1040 |
# |
1041 |
# return 0 if gentoo=param was passed to the kernel |
1042 |
# |
1043 |
# EXAMPLE: if get_bootparam "nodevfs" ; then .... |
1044 |
# |
1045 |
get_bootparam() { |
1046 |
local x copt params retval=1 |
1047 |
|
1048 |
[ ! -r "/proc/cmdline" ] && return 1 |
1049 |
|
1050 |
for copt in $(< /proc/cmdline) |
1051 |
do |
1052 |
if [ "${copt%=*}" = "gentoo" ] |
1053 |
then |
1054 |
params="$(gawk -v PARAMS="${copt##*=}" ' |
1055 |
BEGIN { |
1056 |
split(PARAMS, nodes, ",") |
1057 |
for (x in nodes) |
1058 |
print nodes[x] |
1059 |
}')" |
1060 |
|
1061 |
# Parse gentoo option |
1062 |
for x in ${params} |
1063 |
do |
1064 |
if [ "${x}" = "$1" ] |
1065 |
then |
1066 |
# echo "YES" |
1067 |
retval=0 |
1068 |
fi |
1069 |
done |
1070 |
fi |
1071 |
done |
1072 |
|
1073 |
return ${retval} |
1074 |
} |
1075 |
|
1076 |
# Safer way to list the contents of a directory, |
1077 |
# as it do not have the "empty dir bug". |
1078 |
# |
1079 |
# char *dolisting(param) |
1080 |
# |
1081 |
# print a list of the directory contents |
1082 |
# |
1083 |
# NOTE: quote the params if they contain globs. |
1084 |
# also, error checking is not that extensive ... |
1085 |
# |
1086 |
dolisting() { |
1087 |
local x= |
1088 |
local y= |
1089 |
local tmpstr= |
1090 |
local mylist= |
1091 |
local mypath="$*" |
1092 |
|
1093 |
if [ "${mypath%/\*}" != "${mypath}" ] |
1094 |
then |
1095 |
mypath="${mypath%/\*}" |
1096 |
fi |
1097 |
|
1098 |
for x in ${mypath} |
1099 |
do |
1100 |
[ ! -e "${x}" ] && continue |
1101 |
|
1102 |
if [ ! -d "${x}" ] && ( [ -L "${x}" -o -f "${x}" ] ) |
1103 |
then |
1104 |
mylist="${mylist} $(ls "${x}" 2> /dev/null)" |
1105 |
else |
1106 |
[ "${x%/}" != "${x}" ] && x="${x%/}" |
1107 |
|
1108 |
cd "${x}"; tmpstr="$(ls)" |
1109 |
|
1110 |
for y in ${tmpstr} |
1111 |
do |
1112 |
mylist="${mylist} ${x}/${y}" |
1113 |
done |
1114 |
fi |
1115 |
done |
1116 |
|
1117 |
echo "${mylist}" |
1118 |
} |
1119 |
|
1120 |
# void save_options(char *option, char *optstring) |
1121 |
# |
1122 |
# save the settings ("optstring") for "option" |
1123 |
# |
1124 |
save_options() { |
1125 |
local myopts="$1" |
1126 |
|
1127 |
shift |
1128 |
if [ ! -d "${svcdir}/options/${myservice}" ] |
1129 |
then |
1130 |
mkdir -p -m 0755 "${svcdir}/options/${myservice}" |
1131 |
fi |
1132 |
|
1133 |
echo "$*" > "${svcdir}/options/${myservice}/${myopts}" |
1134 |
|
1135 |
return 0 |
1136 |
} |
1137 |
|
1138 |
# char *get_options(char *option) |
1139 |
# |
1140 |
# get the "optstring" for "option" that was saved |
1141 |
# by calling the save_options function |
1142 |
# |
1143 |
get_options() { |
1144 |
if [ -f "${svcdir}/options/${myservice}/$1" ] |
1145 |
then |
1146 |
echo "$(< ${svcdir}/options/${myservice}/$1)" |
1147 |
fi |
1148 |
|
1149 |
return 0 |
1150 |
} |
1151 |
|
1152 |
# char *add_suffix(char * configfile) |
1153 |
# |
1154 |
# Returns a config file name with the softlevel suffix |
1155 |
# appended to it. For use with multi-config services. |
1156 |
add_suffix() { |
1157 |
if [ "${RC_USE_CONFIG_PROFILE}" = "yes" -a -e "$1.${DEFAULTLEVEL}" ] |
1158 |
then |
1159 |
echo "$1.${DEFAULTLEVEL}" |
1160 |
else |
1161 |
echo "$1" |
1162 |
fi |
1163 |
|
1164 |
return 0 |
1165 |
} |
1166 |
|
1167 |
# char *get_base_ver() |
1168 |
# |
1169 |
# get the version of baselayout that this system is running |
1170 |
# |
1171 |
get_base_ver() { |
1172 |
[[ ! -r /etc/gentoo-release ]] && return 0 |
1173 |
local ver=$(</etc/gentoo-release) |
1174 |
echo ${ver##* } |
1175 |
} |
1176 |
|
1177 |
# Network filesystems list for common use in rc-scripts. |
1178 |
# This variable is used in is_net_fs and other places such as |
1179 |
# localmount. |
1180 |
NET_FS_LIST="afs cifs coda davfs gfs ncpfs nfs nfs4 ocfs2 shfs smbfs" |
1181 |
|
1182 |
# bool is_net_fs(path) |
1183 |
# |
1184 |
# return 0 if path is the mountpoint of a networked filesystem |
1185 |
# |
1186 |
# EXAMPLE: if is_net_fs / ; then ... |
1187 |
# |
1188 |
is_net_fs() { |
1189 |
local fstype |
1190 |
# /proc/mounts is always accurate but may not always be available |
1191 |
if [[ -e /proc/mounts ]]; then |
1192 |
fstype=$( sed -n -e '/^rootfs/!s:.* '"$1"' \([^ |
1193 |
]*\).*:\1:p' /proc/mounts ) |
1194 |
else |
1195 |
fstype=$( mount | sed -n -e 's:.* on '"$1"' type \([^ |
1196 |
]*\).*:\1:p' ) |
1197 |
fi |
1198 |
[[ " ${NET_FS_LIST} " == *" ${fstype} "* ]] |
1199 |
return $? |
1200 |
} |
1201 |
|
1202 |
# bool is_uml_sys() |
1203 |
# |
1204 |
# return 0 if the currently running system is User Mode Linux |
1205 |
# |
1206 |
# EXAMPLE: if is_uml_sys ; then ... |
1207 |
# |
1208 |
is_uml_sys() { |
1209 |
grep -qs 'UML' /proc/cpuinfo |
1210 |
return $? |
1211 |
} |
1212 |
|
1213 |
# bool is_vserver_sys() |
1214 |
# |
1215 |
# return 0 if the currently running system is a Linux VServer |
1216 |
# |
1217 |
# EXAMPLE: if is_vserver_sys ; then ... |
1218 |
# |
1219 |
is_vserver_sys() { |
1220 |
grep -qs '^s_context:[[:space:]]*[1-9]' /proc/self/status |
1221 |
return $? |
1222 |
} |
1223 |
|
1224 |
# bool is_xenU_sys() |
1225 |
# |
1226 |
# return 0 if the currently running system is an unprivileged Xen domain |
1227 |
# |
1228 |
# EXAMPLE: if is_xenU_sys ; then ... |
1229 |
# |
1230 |
is_xenU_sys() { |
1231 |
[[ -d /proc/xen && ! -f /proc/xen/privcmd ]] |
1232 |
} |
1233 |
|
1234 |
# bool get_mount_fstab(path) |
1235 |
# |
1236 |
# return the parameters to pass to the mount command generated from fstab |
1237 |
# |
1238 |
# EXAMPLE: cmd=$( get_mount_fstab /proc ) |
1239 |
# cmd=${cmd:--t proc none /proc} |
1240 |
# mount -n ${cmd} |
1241 |
# |
1242 |
get_mount_fstab() { |
1243 |
awk '$1 ~ "^#" { next } |
1244 |
$2 == "'$*'" { stab="-t "$3" -o "$4" "$1" "$2; } |
1245 |
END { print stab; } |
1246 |
' /etc/fstab |
1247 |
} |
1248 |
|
1249 |
# char *reverse_list(list) |
1250 |
# |
1251 |
# Returns the reversed order of list |
1252 |
# |
1253 |
reverse_list() { |
1254 |
for (( i = $# ; i > 0 ; --i )); do |
1255 |
echo -n "${!i} " |
1256 |
done |
1257 |
} |
1258 |
|
1259 |
# void start_addon(addon) |
1260 |
# |
1261 |
# Starts addon. |
1262 |
# |
1263 |
start_addon() { |
1264 |
local addon=$1 |
1265 |
(import_addon ${addon}-start.sh) |
1266 |
return 0 |
1267 |
} |
1268 |
|
1269 |
# void start_volumes() |
1270 |
# |
1271 |
# Starts all volumes in RC_VOLUME_ORDER. |
1272 |
# |
1273 |
start_volumes() { |
1274 |
local x= |
1275 |
|
1276 |
for x in ${RC_VOLUME_ORDER}; do |
1277 |
start_addon "${x}" |
1278 |
done |
1279 |
|
1280 |
return 0 |
1281 |
} |
1282 |
|
1283 |
# void stop_addon(addon) |
1284 |
# |
1285 |
# Stops addon. |
1286 |
# |
1287 |
stop_addon() { |
1288 |
local addon=$1 |
1289 |
(import_addon ${addon}-stop.sh) |
1290 |
return 0 |
1291 |
} |
1292 |
|
1293 |
# void stop_volumes() |
1294 |
# |
1295 |
# Stops all volumes in RC_VOLUME_ORDER (reverse order). |
1296 |
# |
1297 |
stop_volumes() { |
1298 |
local x= |
1299 |
|
1300 |
for x in $(reverse_list ${RC_VOLUME_ORDER}); do |
1301 |
stop_addon "${x}" |
1302 |
done |
1303 |
|
1304 |
return 0 |
1305 |
} |
1306 |
|
1307 |
# bool is_older_than(reference, files/dirs to check) |
1308 |
# |
1309 |
# return 0 if any of the files/dirs are newer than |
1310 |
# the reference file |
1311 |
# |
1312 |
# EXAMPLE: if is_older_than a.out *.o ; then ... |
1313 |
is_older_than() { |
1314 |
local x= |
1315 |
local ref="$1" |
1316 |
shift |
1317 |
|
1318 |
for x in "$@" ; do |
1319 |
[[ ${x} -nt ${ref} ]] && return 0 |
1320 |
|
1321 |
if [[ -d ${x} ]] ; then |
1322 |
is_older_than "${ref}" "${x}"/* && return 0 |
1323 |
fi |
1324 |
done |
1325 |
|
1326 |
return 1 |
1327 |
} |
1328 |
|
1329 |
# char* bash_variable(char *variable) |
1330 |
# |
1331 |
# Turns the given variable into something that bash can use |
1332 |
# Basically replaces anything not a-z,A-Z into a _ |
1333 |
# |
1334 |
bash_variable() { |
1335 |
local args="$@" |
1336 |
LC_ALL=C echo "${args//[![:word:]]/_}" |
1337 |
} |
1338 |
|
1339 |
# void requote() |
1340 |
# |
1341 |
# Requotes params so they're suitable to be eval'd, just like this would: |
1342 |
# set -- 1 2 "3 4" |
1343 |
# /usr/bin/getopt -- '' "$@" | sed 's/^ -- //' |
1344 |
# |
1345 |
requote() { |
1346 |
local q=\' |
1347 |
set -- "${@//\'/$q\'$q}" # quote inner instances of ' |
1348 |
set -- "${@/#/$q}" # add ' to start of each param |
1349 |
set -- "${@/%/$q}" # add ' to end of each param |
1350 |
echo "$*" |
1351 |
} |
1352 |
|
1353 |
############################################################################## |
1354 |
# # |
1355 |
# This should be the last code in here, please add all functions above!! # |
1356 |
# # |
1357 |
# *** START LAST CODE *** # |
1358 |
# # |
1359 |
############################################################################## |
1360 |
|
1361 |
if [ -z "${EBUILD}" ] ; then |
1362 |
# Setup a basic $PATH. Just add system default to existing. |
1363 |
# This should solve both /sbin and /usr/sbin not present when |
1364 |
# doing 'su -c foo', or for something like: PATH= rcscript start |
1365 |
PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin:${PATH}" |
1366 |
|
1367 |
# Cache the CONSOLETYPE - this is important as backgrounded shells don't |
1368 |
# have a TTY. rc unsets it at the end of running so it shouldn't hang |
1369 |
# around |
1370 |
if [[ -z ${CONSOLETYPE} ]]; then |
1371 |
export CONSOLETYPE=$( /sbin/consoletype 2>/dev/null ) |
1372 |
fi |
1373 |
if [[ ${CONSOLETYPE} == "serial" ]] ; then |
1374 |
RC_NOCOLOR="yes" |
1375 |
RC_ENDCOL="no" |
1376 |
fi |
1377 |
|
1378 |
for arg in "$@" ; do |
1379 |
case "${arg}" in |
1380 |
# Lastly check if the user disabled it with |
1381 |
--nocolor argument |
1382 |
--nocolor|-nc) |
1383 |
RC_NOCOLOR="yes" |
1384 |
;; |
1385 |
esac |
1386 |
done |
1387 |
|
1388 |
if [ -r "/proc/cmdline" ] ; then |
1389 |
setup_defaultlevels |
1390 |
fi |
1391 |
else |
1392 |
# Should we use colors ? |
1393 |
if [[ $* != *depend* ]]; then |
1394 |
# Check user pref in portage |
1395 |
RC_NOCOLOR="$(portageq envvar NOCOLOR 2>/dev/null)" |
1396 |
[ "${RC_NOCOLOR}" = "true" ] && RC_NOCOLOR="yes" |
1397 |
else |
1398 |
# We do not want colors during emerge depend |
1399 |
RC_NOCOLOR="yes" |
1400 |
# No output is seen during emerge depend, so this is not needed. |
1401 |
RC_ENDCOL="no" |
1402 |
fi |
1403 |
fi |
1404 |
|
1405 |
if [[ -n ${EBUILD} && $* = *depend* ]]; then |
1406 |
# We do not want stty to run during emerge depend |
1407 |
COLS=80 |
1408 |
else |
1409 |
# Setup COLS and ENDCOL so eend can line up the [ ok ] |
1410 |
COLS=${COLUMNS:-0} # bash's internal COLUMNS variable |
1411 |
(( COLS == 0 )) && COLS=$(stty size 2>/dev/null | cut -d' ' -f2) |
1412 |
(( COLS > 0 )) || (( COLS = 80 )) # width of [ ok ] == 7 |
1413 |
fi |
1414 |
|
1415 |
if [[ ${RC_ENDCOL} == yes ]]; then |
1416 |
ENDCOL=$'\e[A\e['$(( COLS - 8 ))'C' |
1417 |
else |
1418 |
ENDCOL='' |
1419 |
fi |
1420 |
|
1421 |
# Setup the colors so our messages all look pretty |
1422 |
if [[ ${RC_NOCOLOR} == yes ]]; then |
1423 |
unset GOOD WARN BAD NORMAL HILITE BRACKET |
1424 |
else |
1425 |
GOOD=$'\e[32;01m' |
1426 |
WARN=$'\e[33;01m' |
1427 |
BAD=$'\e[31;01m' |
1428 |
NORMAL=$'\e[0m' |
1429 |
HILITE=$'\e[36;01m' |
1430 |
BRACKET=$'\e[34;01m' |
1431 |
fi |
1432 |
|
1433 |
############################################################################## |
1434 |
# # |
1435 |
# *** END LAST CODE *** # |
1436 |
# # |
1437 |
# This should be the last code in here, please add all functions above!! # |
1438 |
# # |
1439 |
############################################################################## |
1440 |
|
1441 |
|
1442 |
# vim:ts=4 |
1443 |
-=[root@couteausuisse]=(~)# |
1444 |
<(17:24:37)> |
1445 |
-=[root@couteausuisse]=(~)# |
1446 |
<(17:24:38)> |
1447 |
-=[root@couteausuisse]=(~)# |
1448 |
<(17:24:39)> |
1449 |
-=[root@couteausuisse]=(~)# |
1450 |
<(17:24:39)> |
1451 |
-=[root@couteausuisse]=(~)# |
1452 |
<(17:24:39)> |
1453 |
-=[root@couteausuisse]=(~)# |
1454 |
<(17:24:39)> |
1455 |
-=[root@couteausuisse]=(~)# |
1456 |
<(17:24:39)> |
1457 |
-=[root@couteausuisse]=(~)# |
1458 |
<(17:24:39)> |
1459 |
-=[root@couteausuisse]=(~)# |
1460 |
<(17:24:39)> |
1461 |
-=[root@couteausuisse]=(~)# |
1462 |
<(17:24:39)> |
1463 |
-=[root@couteausuisse]=(~)# |
1464 |
<(17:24:39)> |
1465 |
-=[root@couteausuisse]=(~)# |
1466 |
<(17:24:39)> |
1467 |
-=[root@couteausuisse]=(~)# |
1468 |
<(17:24:39)> |
1469 |
-=[root@couteausuisse]=(~)# |
1470 |
<(17:24:39)> |
1471 |
-=[root@couteausuisse]=(~)# |
1472 |
<(17:24:39)> |
1473 |
-=[root@couteausuisse]=(~)# |
1474 |
<(17:24:39)> |
1475 |
-=[root@couteausuisse]=(~)# |
1476 |
<(17:24:39)> |
1477 |
-=[root@couteausuisse]=(~)# |
1478 |
<(17:24:39)> |
1479 |
-=[root@couteausuisse]=(~)# |
1480 |
<(17:24:39)> |
1481 |
-=[root@couteausuisse]=(~)# |
1482 |
<(17:24:39)> |
1483 |
-=[root@couteausuisse]=(~)# |
1484 |
<(17:24:39)> |
1485 |
-=[root@couteausuisse]=(~)# |
1486 |
<(17:24:39)> |
1487 |
-=[root@couteausuisse]=(~)# |
1488 |
<(17:24:39)> |
1489 |
-=[root@couteausuisse]=(~)# |
1490 |
<(17:24:39)> |
1491 |
-=[root@couteausuisse]=(~)# |
1492 |
<(17:24:39)> |
1493 |
-=[root@couteausuisse]=(~)# |
1494 |
<(17:24:39)> |
1495 |
-=[root@couteausuisse]=(~)# |
1496 |
<(17:24:39)> |
1497 |
-=[root@couteausuisse]=(~)# |
1498 |
<(17:24:39)> |
1499 |
-=[root@couteausuisse]=(~)# |
1500 |
<(17:24:39)> |
1501 |
-=[root@couteausuisse]=(~)# |
1502 |
<(17:24:39)> |
1503 |
-=[root@couteausuisse]=(~)# |
1504 |
<(17:24:40)> |
1505 |
-=[root@couteausuisse]=(~)# |
1506 |
<(17:24:40)> |
1507 |
-=[root@couteausuisse]=(~)# |
1508 |
<(17:24:40)> |
1509 |
-=[root@couteausuisse]=(~)# |
1510 |
<(17:24:40)> |
1511 |
-=[root@couteausuisse]=(~)# |
1512 |
<(17:24:40)> |
1513 |
-=[root@couteausuisse]=(~)# |
1514 |
<(17:24:40)> |
1515 |
-=[root@couteausuisse]=(~)# |
1516 |
<(17:24:40)> |
1517 |
-=[root@couteausuisse]=(~)# |
1518 |
<(17:24:40)> |
1519 |
-=[root@couteausuisse]=(~)# |
1520 |
<(17:24:40)> |
1521 |
-=[root@couteausuisse]=(~)# |
1522 |
<(17:24:40)> |
1523 |
-=[root@couteausuisse]=(~)# |
1524 |
<(17:24:40)> |
1525 |
-=[root@couteausuisse]=(~)# |
1526 |
<(17:24:40)> |
1527 |
-=[root@couteausuisse]=(~)# cat /etc/init.d/functions.sh |
1528 |
<(17:24:40)> |
1529 |
# Copyright 1999-2005 Gentoo Foundation |
1530 |
# Distributed under the terms of the GNU General Public License v2 |
1531 |
|
1532 |
RC_GOT_FUNCTIONS="yes" |
1533 |
|
1534 |
# Override defaults with user settings ... |
1535 |
[ -f /etc/conf.d/rc ] && source /etc/conf.d/rc |
1536 |
|
1537 |
# daemontools dir |
1538 |
SVCDIR="/var/lib/supervise" |
1539 |
|
1540 |
# Check /etc/conf.d/rc for a description of these ... |
1541 |
svclib="/lib/rcscripts" |
1542 |
svcdir=${svcdir:-/var/lib/init.d} |
1543 |
svcmount=${svcmount:-no} |
1544 |
svcfstype=${svcfstype:-tmpfs} |
1545 |
svcsize=${svcsize:-1024} |
1546 |
|
1547 |
# Different types of dependencies |
1548 |
deptypes="need use" |
1549 |
# Different types of order deps |
1550 |
ordtypes="before after" |
1551 |
|
1552 |
# |
1553 |
# Internal variables |
1554 |
# |
1555 |
|
1556 |
# Dont output to stdout? |
1557 |
RC_QUIET_STDOUT="no" |
1558 |
RC_VERBOSE=${RC_VERBOSE:-no} |
1559 |
|
1560 |
# Should we use color? |
1561 |
RC_NOCOLOR=${RC_NOCOLOR:-no} |
1562 |
# Can the terminal handle endcols? |
1563 |
RC_ENDCOL="yes" |
1564 |
|
1565 |
# |
1566 |
# Default values for rc system |
1567 |
# |
1568 |
RC_TTY_NUMBER=${RC_TTY_NUMBER:-11} |
1569 |
RC_PARALLEL_STARTUP=${RC_PARALLEL_STARTUP:-no} |
1570 |
RC_NET_STRICT_CHECKING=${RC_NET_STRICT_CHECKING:-no} |
1571 |
RC_VOLUME_ORDER=${RC_VOLUME_ORDER:-raid evms lvm dm} |
1572 |
RC_USE_FSTAB=${RC_USE_FSTAB:-no} |
1573 |
RC_USE_CONFIG_PROFILE=${RC_USE_CONFIG_PROFILE:-yes} |
1574 |
RC_FORCE_AUTO=${RC_FORCE_AUTO:-no} |
1575 |
RC_DEVICES=${RC_DEVICES:-auto} |
1576 |
|
1577 |
# |
1578 |
# Default values for e-message indentation and dots |
1579 |
# |
1580 |
RC_INDENTATION='' |
1581 |
RC_DEFAULT_INDENT=2 |
1582 |
#RC_DOT_PATTERN=' .' |
1583 |
RC_DOT_PATTERN='' |
1584 |
|
1585 |
# void import_addon(char *addon) |
1586 |
# |
1587 |
# Import code from the specified addon if it exists |
1588 |
# |
1589 |
import_addon() { |
1590 |
local addon=${svclib}/addons/$1 |
1591 |
if [[ -r ${addon} ]] ; then |
1592 |
source "${addon}" |
1593 |
return 0 |
1594 |
fi |
1595 |
return 1 |
1596 |
} |
1597 |
|
1598 |
# void splash(...) |
1599 |
# |
1600 |
# Notify bootsplash/splashutils/gensplash/whatever about |
1601 |
# important events. |
1602 |
# |
1603 |
splash() { |
1604 |
return 0 |
1605 |
} |
1606 |
# This will override the splash() function... |
1607 |
if ! import_addon splash-functions.sh ; then |
1608 |
[ -f /sbin/splash-functions.sh ] && source /sbin/splash-functions.sh |
1609 |
fi |
1610 |
|
1611 |
# void profiling(...) |
1612 |
# |
1613 |
# Notify bootsplash/whatever about important events. |
1614 |
# |
1615 |
profiling() { |
1616 |
return 0 |
1617 |
} |
1618 |
import_addon profiling-functions.sh |
1619 |
|
1620 |
# void bootlog(...) |
1621 |
# |
1622 |
# Notify bootlogger about important events. |
1623 |
bootlog() { |
1624 |
return 0 |
1625 |
} |
1626 |
[[ ${RC_BOOTLOG} == "yes" ]] && import_addon bootlogger.sh |
1627 |
|
1628 |
# void get_bootconfig() |
1629 |
# |
1630 |
# Get the BOOTLEVEL and SOFTLEVEL by setting |
1631 |
# 'bootlevel' and 'softlevel' via kernel |
1632 |
# parameters. |
1633 |
# |
1634 |
get_bootconfig() { |
1635 |
local copt= |
1636 |
local newbootlevel= |
1637 |
local newsoftlevel= |
1638 |
|
1639 |
if [[ -r /proc/cmdline ]] ; then |
1640 |
for copt in $(</proc/cmdline) ; do |
1641 |
case "${copt%=*}" in |
1642 |
bootlevel) |
1643 |
newbootlevel=${copt##*=} |
1644 |
;; |
1645 |
softlevel) |
1646 |
newsoftlevel=${copt##*=} |
1647 |
;; |
1648 |
esac |
1649 |
done |
1650 |
fi |
1651 |
|
1652 |
if [[ -n ${newbootlevel} ]] ; then |
1653 |
export BOOTLEVEL=${newbootlevel} |
1654 |
else |
1655 |
export BOOTLEVEL="boot" |
1656 |
fi |
1657 |
|
1658 |
if [[ -n ${newsoftlevel} ]] ; then |
1659 |
export DEFAULTLEVEL=${newsoftlevel} |
1660 |
else |
1661 |
export DEFAULTLEVEL="default" |
1662 |
fi |
1663 |
|
1664 |
return 0 |
1665 |
} |
1666 |
|
1667 |
setup_defaultlevels() { |
1668 |
get_bootconfig |
1669 |
|
1670 |
if get_bootparam "noconfigprofile" ; then |
1671 |
export RC_USE_CONFIG_PROFILE="no" |
1672 |
|
1673 |
elif get_bootparam "configprofile" ; then |
1674 |
export RC_USE_CONFIG_PROFILE="yes" |
1675 |
fi |
1676 |
|
1677 |
if [ "${RC_USE_CONFIG_PROFILE}" = "yes" -a -n "${DEFAULTLEVEL}" ] && \ |
1678 |
[ -d "/etc/runlevels/${BOOTLEVEL}.${DEFAULTLEVEL}" -o \ |
1679 |
-L "/etc/runlevels/${BOOTLEVEL}.${DEFAULTLEVEL}" ] |
1680 |
then |
1681 |
export BOOTLEVEL="${BOOTLEVEL}.${DEFAULTLEVEL}" |
1682 |
fi |
1683 |
|
1684 |
if [ -z "${SOFTLEVEL}" ] ; then |
1685 |
if [ -f "${svcdir}/softlevel" ] ; then |
1686 |
export SOFTLEVEL="$(< ${svcdir}/softlevel)" |
1687 |
else |
1688 |
export SOFTLEVEL="${BOOTLEVEL}" |
1689 |
fi |
1690 |
fi |
1691 |
|
1692 |
return 0 |
1693 |
} |
1694 |
|
1695 |
# void get_libdir(void) |
1696 |
# |
1697 |
# prints the current libdir {lib,lib32,lib64} |
1698 |
# |
1699 |
get_libdir() { |
1700 |
if [ -n "${CONF_LIBDIR_OVERRIDE}" ] ; then |
1701 |
CONF_LIBDIR="${CONF_LIBDIR_OVERRIDE}" |
1702 |
elif [ -x "/usr/bin/portageq" ] ; then |
1703 |
CONF_LIBDIR="$(/usr/bin/portageq envvar CONF_LIBDIR)" |
1704 |
fi |
1705 |
echo ${CONF_LIBDIR:=lib} |
1706 |
} |
1707 |
|
1708 |
# void esyslog(char* priority, char* tag, char* message) |
1709 |
# |
1710 |
# use the system logger to log a message |
1711 |
# |
1712 |
esyslog() { |
1713 |
local pri= |
1714 |
local tag= |
1715 |
|
1716 |
if [ -x /usr/bin/logger ] |
1717 |
then |
1718 |
pri="$1" |
1719 |
tag="$2" |
1720 |
|
1721 |
shift 2 |
1722 |
[[ -z "$*" ]] && return 0 |
1723 |
|
1724 |
/usr/bin/logger -p "${pri}" -t "${tag}" -- "$*" |
1725 |
fi |
1726 |
|
1727 |
return 0 |
1728 |
} |
1729 |
|
1730 |
# void eindent(int num) |
1731 |
# |
1732 |
# increase the indent used for e-commands. |
1733 |
# |
1734 |
eindent() { |
1735 |
local i=$1 |
1736 |
(( i > 0 )) || (( i = RC_DEFAULT_INDENT )) |
1737 |
esetdent $(( ${#RC_INDENTATION} + i )) |
1738 |
} |
1739 |
|
1740 |
# void eoutdent(int num) |
1741 |
# |
1742 |
# decrease the indent used for e-commands. |
1743 |
# |
1744 |
eoutdent() { |
1745 |
local i=$1 |
1746 |
(( i > 0 )) || (( i = RC_DEFAULT_INDENT )) |
1747 |
esetdent $(( ${#RC_INDENTATION} - i )) |
1748 |
} |
1749 |
|
1750 |
# void esetdent(int num) |
1751 |
# |
1752 |
# hard set the indent used for e-commands. |
1753 |
# num defaults to 0 |
1754 |
# |
1755 |
esetdent() { |
1756 |
local i=$1 |
1757 |
(( i < 0 )) && (( i = 0 )) |
1758 |
RC_INDENTATION=$(printf "%${i}s" '') |
1759 |
} |
1760 |
|
1761 |
# void einfo(char* message) |
1762 |
# |
1763 |
# show an informative message (with a newline) |
1764 |
# |
1765 |
einfo() { |
1766 |
einfon "$*\n" |
1767 |
LAST_E_CMD=einfo |
1768 |
return 0 |
1769 |
} |
1770 |
|
1771 |
# void einfon(char* message) |
1772 |
# |
1773 |
# show an informative message (without a newline) |
1774 |
# |
1775 |
einfon() { |
1776 |
[[ ${RC_QUIET_STDOUT} == yes ]] && return 0 |
1777 |
[[ ${RC_ENDCOL} != yes && ${LAST_E_CMD} == ebegin ]] && echo |
1778 |
echo -ne " ${GOOD}*${NORMAL} ${RC_INDENTATION}$*" |
1779 |
LAST_E_CMD=einfon |
1780 |
return 0 |
1781 |
} |
1782 |
|
1783 |
# void ewarn(char* message) |
1784 |
# |
1785 |
# show a warning message + log it |
1786 |
# |
1787 |
ewarn() { |
1788 |
if [[ ${RC_QUIET_STDOUT} == yes ]]; then |
1789 |
echo " $*" |
1790 |
else |
1791 |
[[ ${RC_ENDCOL} != yes && ${LAST_E_CMD} == ebegin ]] && echo |
1792 |
echo -e " ${WARN}*${NORMAL} ${RC_INDENTATION}$*" |
1793 |
fi |
1794 |
|
1795 |
# Log warnings to system log |
1796 |
esyslog "daemon.warning" "rc-scripts" "$*" |
1797 |
|
1798 |
LAST_E_CMD=ewarn |
1799 |
return 0 |
1800 |
} |
1801 |
|
1802 |
# void eerror(char* message) |
1803 |
# |
1804 |
# show an error message + log it |
1805 |
# |
1806 |
eerror() { |
1807 |
if [[ ${RC_QUIET_STDOUT} == yes ]]; then |
1808 |
echo " $*" >/dev/stderr |
1809 |
else |
1810 |
[[ ${RC_ENDCOL} != yes && ${LAST_E_CMD} == ebegin ]] && echo |
1811 |
echo -e " ${BAD}*${NORMAL} ${RC_INDENTATION}$*" |
1812 |
fi |
1813 |
|
1814 |
# Log errors to system log |
1815 |
esyslog "daemon.err" "rc-scripts" "$*" |
1816 |
|
1817 |
LAST_E_CMD=eerror |
1818 |
return 0 |
1819 |
} |
1820 |
|
1821 |
# void ebegin(char* message) |
1822 |
# |
1823 |
# show a message indicating the start of a process |
1824 |
# |
1825 |
ebegin() { |
1826 |
local msg="$*" dots spaces=${RC_DOT_PATTERN//?/ } |
1827 |
[[ ${RC_QUIET_STDOUT} == yes ]] && return 0 |
1828 |
|
1829 |
if [[ -n ${RC_DOT_PATTERN} ]]; then |
1830 |
dots=$(printf "%$(( COLS - 3 - ${#RC_INDENTATION} - |
1831 |
${#msg} - 7 ))s" '') |
1832 |
dots=${dots//${spaces}/${RC_DOT_PATTERN}} |
1833 |
msg="${msg}${dots}" |
1834 |
else |
1835 |
msg="${msg} ..." |
1836 |
fi |
1837 |
einfon "${msg}" |
1838 |
[[ ${RC_ENDCOL} == yes ]] && echo |
1839 |
|
1840 |
LAST_E_LEN=$(( 3 + ${#RC_INDENTATION} + ${#msg} )) |
1841 |
LAST_E_CMD=ebegin |
1842 |
return 0 |
1843 |
} |
1844 |
|
1845 |
# void _eend(int error, char *efunc, char* errstr) |
1846 |
# |
1847 |
# indicate the completion of process, called from eend/ewend |
1848 |
# if error, show errstr via efunc |
1849 |
# |
1850 |
# This function is private to functions.sh. Do not call it from a |
1851 |
# script. |
1852 |
# |
1853 |
_eend() { |
1854 |
local retval=${1:-0} efunc=${2:-eerror} msg |
1855 |
shift 2 |
1856 |
|
1857 |
if [[ ${retval} == 0 ]]; then |
1858 |
[[ ${RC_QUIET_STDOUT} == yes ]] && return 0 |
1859 |
msg="${BRACKET}[ ${GOOD}ok${BRACKET} ]${NORMAL}" |
1860 |
else |
1861 |
if [[ -c /dev/null ]]; then |
1862 |
rc_splash "stop" &>/dev/null & |
1863 |
else |
1864 |
rc_splash "stop" & |
1865 |
fi |
1866 |
if [[ -n "$*" ]]; then |
1867 |
${efunc} "$*" |
1868 |
fi |
1869 |
msg="${BRACKET}[ ${BAD}!!${BRACKET} ]${NORMAL}" |
1870 |
fi |
1871 |
|
1872 |
if [[ ${RC_ENDCOL} == yes ]]; then |
1873 |
echo -e "${ENDCOL} ${msg}" |
1874 |
else |
1875 |
[[ ${LAST_E_CMD} == ebegin ]] || LAST_E_LEN=0 |
1876 |
printf "%$(( COLS - LAST_E_LEN - 6 ))s%b\n" '' "${msg}" |
1877 |
fi |
1878 |
|
1879 |
return ${retval} |
1880 |
} |
1881 |
|
1882 |
# void eend(int error, char* errstr) |
1883 |
# |
1884 |
# indicate the completion of process |
1885 |
# if error, show errstr via eerror |
1886 |
# |
1887 |
eend() { |
1888 |
local retval=${1:-0} |
1889 |
shift |
1890 |
|
1891 |
_eend ${retval} eerror "$*" |
1892 |
|
1893 |
LAST_E_CMD=eend |
1894 |
return $retval |
1895 |
} |
1896 |
|
1897 |
# void ewend(int error, char* errstr) |
1898 |
# |
1899 |
# indicate the completion of process |
1900 |
# if error, show errstr via ewarn |
1901 |
# |
1902 |
ewend() { |
1903 |
local retval=${1:-0} |
1904 |
shift |
1905 |
|
1906 |
_eend ${retval} ewarn "$*" |
1907 |
|
1908 |
LAST_E_CMD=ewend |
1909 |
return $retval |
1910 |
} |
1911 |
|
1912 |
# v-e-commands honor RC_VERBOSE which defaults to no. |
1913 |
# The condition is negated so the return value will be zero. |
1914 |
veinfo() { [[ "${RC_VERBOSE}" != yes ]] || einfo "$@"; } |
1915 |
veinfon() { [[ "${RC_VERBOSE}" != yes ]] || einfon "$@"; } |
1916 |
vewarn() { [[ "${RC_VERBOSE}" != yes ]] || ewarn "$@"; } |
1917 |
veerror() { [[ "${RC_VERBOSE}" != yes ]] || eerror "$@"; } |
1918 |
vebegin() { [[ "${RC_VERBOSE}" != yes ]] || ebegin "$@"; } |
1919 |
veend() { |
1920 |
[[ "${RC_VERBOSE}" == yes ]] && { eend "$@"; return $?; } |
1921 |
return ${1:-0} |
1922 |
} |
1923 |
veend() { |
1924 |
[[ "${RC_VERBOSE}" == yes ]] && { ewend "$@"; return $?; } |
1925 |
return ${1:-0} |
1926 |
} |
1927 |
|
1928 |
# char *KV_major(string) |
1929 |
# |
1930 |
# Return the Major (X of X.Y.Z) kernel version |
1931 |
# |
1932 |
KV_major() { |
1933 |
[[ -z $1 ]] && return 1 |
1934 |
|
1935 |
local KV=$@ |
1936 |
echo ${KV%%.*} |
1937 |
} |
1938 |
|
1939 |
# char *KV_minor(string) |
1940 |
# |
1941 |
# Return the Minor (Y of X.Y.Z) kernel version |
1942 |
# |
1943 |
KV_minor() { |
1944 |
[[ -z $1 ]] && return 1 |
1945 |
|
1946 |
local KV=$@ |
1947 |
KV=${KV#*.} |
1948 |
echo ${KV%%.*} |
1949 |
} |
1950 |
|
1951 |
# char *KV_micro(string) |
1952 |
# |
1953 |
# Return the Micro (Z of X.Y.Z) kernel version. |
1954 |
# |
1955 |
KV_micro() { |
1956 |
[[ -z $1 ]] && return 1 |
1957 |
|
1958 |
local KV=$@ |
1959 |
KV=${KV#*.*.} |
1960 |
echo ${KV%%[^[:digit:]]*} |
1961 |
} |
1962 |
|
1963 |
# int KV_to_int(string) |
1964 |
# |
1965 |
# Convert a string type kernel version (2.4.0) to an int (132096) |
1966 |
# for easy compairing or versions ... |
1967 |
# |
1968 |
KV_to_int() { |
1969 |
[[ -z $1 ]] && return 1 |
1970 |
|
1971 |
local KV_MAJOR=$(KV_major "$1") |
1972 |
local KV_MINOR=$(KV_minor "$1") |
1973 |
local KV_MICRO=$(KV_micro "$1") |
1974 |
local KV_int=$(( KV_MAJOR * 65536 + KV_MINOR * 256 + KV_MICRO )) |
1975 |
|
1976 |
# We make version 2.2.0 the minimum version we will handle as |
1977 |
# a sanity check ... if its less, we fail ... |
1978 |
if [[ ${KV_int} -ge 131584 ]] ; then |
1979 |
echo "${KV_int}" |
1980 |
return 0 |
1981 |
fi |
1982 |
|
1983 |
return 1 |
1984 |
} |
1985 |
|
1986 |
# int get_KV() |
1987 |
# |
1988 |
# Return the kernel version (major, minor and micro concated) as an integer. |
1989 |
# Assumes X and Y of X.Y.Z are numbers. Also assumes that some leading |
1990 |
# portion of Z is a number. |
1991 |
# e.g. 2.4.25, 2.6.10, 2.6.4-rc3, 2.2.40-poop, 2.0.15+foo |
1992 |
# |
1993 |
get_KV() { |
1994 |
local KV=$(uname -r) |
1995 |
|
1996 |
echo $(KV_to_int "${KV}") |
1997 |
|
1998 |
return $? |
1999 |
} |
2000 |
|
2001 |
# bool get_bootparam(param) |
2002 |
# |
2003 |
# return 0 if gentoo=param was passed to the kernel |
2004 |
# |
2005 |
# EXAMPLE: if get_bootparam "nodevfs" ; then .... |
2006 |
# |
2007 |
get_bootparam() { |
2008 |
local x copt params retval=1 |
2009 |
|
2010 |
[ ! -r "/proc/cmdline" ] && return 1 |
2011 |
|
2012 |
for copt in $(< /proc/cmdline) |
2013 |
do |
2014 |
if [ "${copt%=*}" = "gentoo" ] |
2015 |
then |
2016 |
params="$(gawk -v PARAMS="${copt##*=}" ' |
2017 |
BEGIN { |
2018 |
split(PARAMS, nodes, ",") |
2019 |
for (x in nodes) |
2020 |
print nodes[x] |
2021 |
}')" |
2022 |
|
2023 |
# Parse gentoo option |
2024 |
for x in ${params} |
2025 |
do |
2026 |
if [ "${x}" = "$1" ] |
2027 |
then |
2028 |
# echo "YES" |
2029 |
retval=0 |
2030 |
fi |
2031 |
done |
2032 |
fi |
2033 |
done |
2034 |
|
2035 |
return ${retval} |
2036 |
} |
2037 |
|
2038 |
# Safer way to list the contents of a directory, |
2039 |
# as it do not have the "empty dir bug". |
2040 |
# |
2041 |
# char *dolisting(param) |
2042 |
# |
2043 |
# print a list of the directory contents |
2044 |
# |
2045 |
# NOTE: quote the params if they contain globs. |
2046 |
# also, error checking is not that extensive ... |
2047 |
# |
2048 |
dolisting() { |
2049 |
local x= |
2050 |
local y= |
2051 |
local tmpstr= |
2052 |
local mylist= |
2053 |
local mypath="$*" |
2054 |
|
2055 |
if [ "${mypath%/\*}" != "${mypath}" ] |
2056 |
then |
2057 |
mypath="${mypath%/\*}" |
2058 |
fi |
2059 |
|
2060 |
for x in ${mypath} |
2061 |
do |
2062 |
[ ! -e "${x}" ] && continue |
2063 |
|
2064 |
if [ ! -d "${x}" ] && ( [ -L "${x}" -o -f "${x}" ] ) |
2065 |
then |
2066 |
mylist="${mylist} $(ls "${x}" 2> /dev/null)" |
2067 |
else |
2068 |
[ "${x%/}" != "${x}" ] && x="${x%/}" |
2069 |
|
2070 |
cd "${x}"; tmpstr="$(ls)" |
2071 |
|
2072 |
for y in ${tmpstr} |
2073 |
do |
2074 |
mylist="${mylist} ${x}/${y}" |
2075 |
done |
2076 |
fi |
2077 |
done |
2078 |
|
2079 |
echo "${mylist}" |
2080 |
} |
2081 |
|
2082 |
# void save_options(char *option, char *optstring) |
2083 |
# |
2084 |
# save the settings ("optstring") for "option" |
2085 |
# |
2086 |
save_options() { |
2087 |
local myopts="$1" |
2088 |
|
2089 |
shift |
2090 |
if [ ! -d "${svcdir}/options/${myservice}" ] |
2091 |
then |
2092 |
mkdir -p -m 0755 "${svcdir}/options/${myservice}" |
2093 |
fi |
2094 |
|
2095 |
echo "$*" > "${svcdir}/options/${myservice}/${myopts}" |
2096 |
|
2097 |
return 0 |
2098 |
} |
2099 |
|
2100 |
# char *get_options(char *option) |
2101 |
# |
2102 |
# get the "optstring" for "option" that was saved |
2103 |
# by calling the save_options function |
2104 |
# |
2105 |
get_options() { |
2106 |
if [ -f "${svcdir}/options/${myservice}/$1" ] |
2107 |
then |
2108 |
echo "$(< ${svcdir}/options/${myservice}/$1)" |
2109 |
fi |
2110 |
|
2111 |
return 0 |
2112 |
} |
2113 |
|
2114 |
# char *add_suffix(char * configfile) |
2115 |
# |
2116 |
# Returns a config file name with the softlevel suffix |
2117 |
# appended to it. For use with multi-config services. |
2118 |
add_suffix() { |
2119 |
if [ "${RC_USE_CONFIG_PROFILE}" = "yes" -a -e "$1.${DEFAULTLEVEL}" ] |
2120 |
then |
2121 |
echo "$1.${DEFAULTLEVEL}" |
2122 |
else |
2123 |
echo "$1" |
2124 |
fi |
2125 |
|
2126 |
return 0 |
2127 |
} |
2128 |
|
2129 |
# char *get_base_ver() |
2130 |
# |
2131 |
# get the version of baselayout that this system is running |
2132 |
# |
2133 |
get_base_ver() { |
2134 |
[[ ! -r /etc/gentoo-release ]] && return 0 |
2135 |
local ver=$(</etc/gentoo-release) |
2136 |
echo ${ver##* } |
2137 |
} |
2138 |
|
2139 |
# Network filesystems list for common use in rc-scripts. |
2140 |
# This variable is used in is_net_fs and other places such as |
2141 |
# localmount. |
2142 |
NET_FS_LIST="afs cifs coda davfs gfs ncpfs nfs nfs4 ocfs2 shfs smbfs" |
2143 |
|
2144 |
# bool is_net_fs(path) |
2145 |
# |
2146 |
# return 0 if path is the mountpoint of a networked filesystem |
2147 |
# |
2148 |
# EXAMPLE: if is_net_fs / ; then ... |
2149 |
# |
2150 |
is_net_fs() { |
2151 |
local fstype |
2152 |
# /proc/mounts is always accurate but may not always be available |
2153 |
if [[ -e /proc/mounts ]]; then |
2154 |
fstype=$( sed -n -e '/^rootfs/!s:.* '"$1"' \([^ |
2155 |
]*\).*:\1:p' /proc/mounts ) |
2156 |
else |
2157 |
fstype=$( mount | sed -n -e 's:.* on '"$1"' type \([^ |
2158 |
]*\).*:\1:p' ) |
2159 |
fi |
2160 |
[[ " ${NET_FS_LIST} " == *" ${fstype} "* ]] |
2161 |
return $? |
2162 |
} |
2163 |
|
2164 |
# bool is_uml_sys() |
2165 |
# |
2166 |
# return 0 if the currently running system is User Mode Linux |
2167 |
# |
2168 |
# EXAMPLE: if is_uml_sys ; then ... |
2169 |
# |
2170 |
is_uml_sys() { |
2171 |
grep -qs 'UML' /proc/cpuinfo |
2172 |
return $? |
2173 |
} |
2174 |
|
2175 |
# bool is_vserver_sys() |
2176 |
# |
2177 |
# return 0 if the currently running system is a Linux VServer |
2178 |
# |
2179 |
# EXAMPLE: if is_vserver_sys ; then ... |
2180 |
# |
2181 |
is_vserver_sys() { |
2182 |
grep -qs '^s_context:[[:space:]]*[1-9]' /proc/self/status |
2183 |
return $? |
2184 |
} |
2185 |
|
2186 |
# bool is_xenU_sys() |
2187 |
# |
2188 |
# return 0 if the currently running system is an unprivileged Xen domain |
2189 |
# |
2190 |
# EXAMPLE: if is_xenU_sys ; then ... |
2191 |
# |
2192 |
is_xenU_sys() { |
2193 |
[[ -d /proc/xen && ! -f /proc/xen/privcmd ]] |
2194 |
} |
2195 |
|
2196 |
# bool get_mount_fstab(path) |
2197 |
# |
2198 |
# return the parameters to pass to the mount command generated from fstab |
2199 |
# |
2200 |
# EXAMPLE: cmd=$( get_mount_fstab /proc ) |
2201 |
# cmd=${cmd:--t proc none /proc} |
2202 |
# mount -n ${cmd} |
2203 |
# |
2204 |
get_mount_fstab() { |
2205 |
awk '$1 ~ "^#" { next } |
2206 |
$2 == "'$*'" { stab="-t "$3" -o "$4" "$1" "$2; } |
2207 |
END { print stab; } |
2208 |
' /etc/fstab |
2209 |
} |
2210 |
|
2211 |
# char *reverse_list(list) |
2212 |
# |
2213 |
# Returns the reversed order of list |
2214 |
# |
2215 |
reverse_list() { |
2216 |
for (( i = $# ; i > 0 ; --i )); do |
2217 |
echo -n "${!i} " |
2218 |
done |
2219 |
} |
2220 |
|
2221 |
# void start_addon(addon) |
2222 |
# |
2223 |
# Starts addon. |
2224 |
# |
2225 |
start_addon() { |
2226 |
local addon=$1 |
2227 |
(import_addon ${addon}-start.sh) |
2228 |
return 0 |
2229 |
} |
2230 |
|
2231 |
# void start_volumes() |
2232 |
# |
2233 |
# Starts all volumes in RC_VOLUME_ORDER. |
2234 |
# |
2235 |
start_volumes() { |
2236 |
local x= |
2237 |
|
2238 |
for x in ${RC_VOLUME_ORDER}; do |
2239 |
start_addon "${x}" |
2240 |
done |
2241 |
|
2242 |
return 0 |
2243 |
} |
2244 |
|
2245 |
# void stop_addon(addon) |
2246 |
# |
2247 |
# Stops addon. |
2248 |
# |
2249 |
stop_addon() { |
2250 |
local addon=$1 |
2251 |
(import_addon ${addon}-stop.sh) |
2252 |
return 0 |
2253 |
} |
2254 |
|
2255 |
# void stop_volumes() |
2256 |
# |
2257 |
# Stops all volumes in RC_VOLUME_ORDER (reverse order). |
2258 |
# |
2259 |
stop_volumes() { |
2260 |
local x= |
2261 |
|
2262 |
for x in $(reverse_list ${RC_VOLUME_ORDER}); do |
2263 |
stop_addon "${x}" |
2264 |
done |
2265 |
|
2266 |
return 0 |
2267 |
} |
2268 |
|
2269 |
# bool is_older_than(reference, files/dirs to check) |
2270 |
# |
2271 |
# return 0 if any of the files/dirs are newer than |
2272 |
# the reference file |
2273 |
# |
2274 |
# EXAMPLE: if is_older_than a.out *.o ; then ... |
2275 |
is_older_than() { |
2276 |
local x= |
2277 |
local ref="$1" |
2278 |
shift |
2279 |
|
2280 |
for x in "$@" ; do |
2281 |
[[ ${x} -nt ${ref} ]] && return 0 |
2282 |
|
2283 |
if [[ -d ${x} ]] ; then |
2284 |
is_older_than "${ref}" "${x}"/* && return 0 |
2285 |
fi |
2286 |
done |
2287 |
|
2288 |
return 1 |
2289 |
} |
2290 |
|
2291 |
# char* bash_variable(char *variable) |
2292 |
# |
2293 |
# Turns the given variable into something that bash can use |
2294 |
# Basically replaces anything not a-z,A-Z into a _ |
2295 |
# |
2296 |
bash_variable() { |
2297 |
local args="$@" |
2298 |
LC_ALL=C echo "${args//[![:word:]]/_}" |
2299 |
} |
2300 |
|
2301 |
# void requote() |
2302 |
# |
2303 |
# Requotes params so they're suitable to be eval'd, just like this would: |
2304 |
# set -- 1 2 "3 4" |
2305 |
# /usr/bin/getopt -- '' "$@" | sed 's/^ -- //' |
2306 |
# |
2307 |
requote() { |
2308 |
local q=\' |
2309 |
set -- "${@//\'/$q\'$q}" # quote inner instances of ' |
2310 |
set -- "${@/#/$q}" # add ' to start of each param |
2311 |
set -- "${@/%/$q}" # add ' to end of each param |
2312 |
echo "$*" |
2313 |
} |
2314 |
|
2315 |
############################################################################## |
2316 |
# # |
2317 |
# This should be the last code in here, please add all functions above!! # |
2318 |
# # |
2319 |
# *** START LAST CODE *** # |
2320 |
# # |
2321 |
############################################################################## |
2322 |
|
2323 |
if [ -z "${EBUILD}" ] ; then |
2324 |
# Setup a basic $PATH. Just add system default to existing. |
2325 |
# This should solve both /sbin and /usr/sbin not present when |
2326 |
# doing 'su -c foo', or for something like: PATH= rcscript start |
2327 |
PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin:${PATH}" |
2328 |
|
2329 |
# Cache the CONSOLETYPE - this is important as backgrounded shells don't |
2330 |
# have a TTY. rc unsets it at the end of running so it shouldn't hang |
2331 |
# around |
2332 |
if [[ -z ${CONSOLETYPE} ]]; then |
2333 |
export CONSOLETYPE=$( /sbin/consoletype 2>/dev/null ) |
2334 |
fi |
2335 |
if [[ ${CONSOLETYPE} == "serial" ]] ; then |
2336 |
RC_NOCOLOR="yes" |
2337 |
RC_ENDCOL="no" |
2338 |
fi |
2339 |
|
2340 |
for arg in "$@" ; do |
2341 |
case "${arg}" in |
2342 |
# Lastly check if the user disabled it with |
2343 |
--nocolor argument |
2344 |
--nocolor|-nc) |
2345 |
RC_NOCOLOR="yes" |
2346 |
;; |
2347 |
esac |
2348 |
done |
2349 |
|
2350 |
if [ -r "/proc/cmdline" ] ; then |
2351 |
setup_defaultlevels |
2352 |
fi |
2353 |
else |
2354 |
# Should we use colors ? |
2355 |
if [[ $* != *depend* ]]; then |
2356 |
# Check user pref in portage |
2357 |
RC_NOCOLOR="$(portageq envvar NOCOLOR 2>/dev/null)" |
2358 |
[ "${RC_NOCOLOR}" = "true" ] && RC_NOCOLOR="yes" |
2359 |
else |
2360 |
# We do not want colors during emerge depend |
2361 |
RC_NOCOLOR="yes" |
2362 |
# No output is seen during emerge depend, so this is not needed. |
2363 |
RC_ENDCOL="no" |
2364 |
fi |
2365 |
fi |
2366 |
|
2367 |
if [[ -n ${EBUILD} && $* = *depend* ]]; then |
2368 |
# We do not want stty to run during emerge depend |
2369 |
COLS=80 |
2370 |
else |
2371 |
# Setup COLS and ENDCOL so eend can line up the [ ok ] |
2372 |
COLS=${COLUMNS:-0} # bash's internal COLUMNS variable |
2373 |
(( COLS == 0 )) && COLS=$(stty size 2>/dev/null | cut -d' ' -f2) |
2374 |
(( COLS > 0 )) || (( COLS = 80 )) # width of [ ok ] == 7 |
2375 |
fi |
2376 |
|
2377 |
if [[ ${RC_ENDCOL} == yes ]]; then |
2378 |
ENDCOL=$'\e[A\e['$(( COLS - 8 ))'C' |
2379 |
else |
2380 |
ENDCOL='' |
2381 |
fi |
2382 |
|
2383 |
# Setup the colors so our messages all look pretty |
2384 |
if [[ ${RC_NOCOLOR} == yes ]]; then |
2385 |
unset GOOD WARN BAD NORMAL HILITE BRACKET |
2386 |
else |
2387 |
GOOD=$'\e[32;01m' |
2388 |
WARN=$'\e[33;01m' |
2389 |
BAD=$'\e[31;01m' |
2390 |
NORMAL=$'\e[0m' |
2391 |
HILITE=$'\e[36;01m' |
2392 |
BRACKET=$'\e[34;01m' |
2393 |
fi |
2394 |
|
2395 |
############################################################################## |
2396 |
# # |
2397 |
# *** END LAST CODE *** # |
2398 |
# # |
2399 |
# This should be the last code in here, please add all functions above!! # |
2400 |
# # |
2401 |
############################################################################## |
2402 |
|
2403 |
|
2404 |
# vim:ts=4 |
2405 |
-=[root@couteausuisse]=(~)# |
2406 |
<(17:24:40)> |
2407 |
|
2408 |
-- |
2409 |
gentoo-user-fr@g.o mailing list |