]> git.pld-linux.org Git - projects/rc-scripts.git/blob - rc.d/init.d/functions
- unified indentation (ts=8 sw=4, as vi modeline says)
[projects/rc-scripts.git] / rc.d / init.d / functions
1 #!/bin/sh - keep it for file(1) to get bourne shell script result
2 # functions     This file contains functions to be used by most or all
3 #               shell scripts in the /etc/init.d directory.
4 #
5 # $Id$
6 #
7 # Author:       Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
8 # Hacked by:    Greg Galloway and Marc Ewing
9 # Modified for PLD by:
10 #               Marek Obuchowicz <elephant@pld-linux.org>
11 #               Arkadiusz Mi¶kiewicz <misiek@pld-linux.org>
12 #               Micha³ Kochanowicz <mkochano@pld-linux.org>
13 #               £ukasz Pawelczyk <havner@pld-linux.org>
14
15 # First set up a default search path.
16 export PATH="/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin"
17
18 # Set defaults
19 INIT_COL=67
20
21 [ -z "${CONSOLETYPE}" ] && CONSOLETYPE="$(/sbin/consoletype)"
22
23 # Set colors
24 RED=1
25 GREEN=2
26 YELLOW=3
27 BLUE=4
28 MAGENTA=5
29 CYAN=6
30 WHITE=7
31 NORMAL=9
32 # Bold definition (second parameter to termput setaf)
33 BOLD=1
34 NOBOLD=0
35 # Default colors
36 CBRACKETS="$CYAN"       # brackets [ ] color
37 CDONE="$GREEN"          # DONE and WORK color
38 CBUSY="$MAGENTA"        # BUSY color
39 CFAIL="$RED"            # FAIL and DIED color
40 CPOWEREDBY="$CYAN"      # "Powered by" color
41 CPLD="$GREEN"           # "PLD Linux Distribution" color
42 CI="$RED"               # Capital I color (press I to enter interactive startup)
43 CRESMAN="$GREEN"        # "Resource Manager" color
44 CHARS=""                # Characters displayed on the begining of show line
45 CCHARS="$NORMAL"        # Color of these characters (look at /etc/sysconfig/init-colors.gentoo example)
46
47 # Source configuration if available - may override default values
48 [ -r /etc/sysconfig/init-colors ] && . /etc/sysconfig/init-colors
49 [ -r /etc/sysconfig/system ] && . /etc/sysconfig/system
50 [ -r /etc/sysconfig/bootsplash ] && . /etc/sysconfig/bootsplash
51
52 [ -z "$COLUMNS" ] && COLUMNS=80
53
54 is_yes()
55 {
56         # Test syntax
57         if [ $# = 0 ] ; then
58                 msg_usage " is_yes {value}"
59                 return 2
60         fi
61
62         # Check value
63         case "$1" in
64           yes|Yes|YES|true|True|TRUE|on|On|ON|Y|y|1)
65                 # true returns zero
66                 return 0
67                 ;;
68           *)
69                 # false returns one
70                 return 1
71                 ;;
72         esac
73 }
74
75 is_no()
76 {
77         # Test syntax
78         if [ $# = 0 ] ; then
79                 msg_usage " is_no {value}"
80                 return 2
81         fi
82
83         case "$1" in
84           no|No|NO|false|False|FALSE|off|Off|OFF|N|n|0)
85                 # true returns zero
86                 return 0
87                 ;;
88           *)
89                 # false returns one
90                 return 1
91                 ;;
92         esac
93 }
94
95 if is_yes "$FASTRC"; then
96         INIT_DOTS=$(awk "BEGIN{for(\$i=0;\$i<$INIT_COL;\$i++)printf(\".\");}")
97         initlog()
98         {
99                 RESULT=0
100                 while [ "$1" != "${1##-}" ] || [ "$1" != "${1##+}" ]; do
101                         case $1 in
102                                 -c)
103                                         shift
104                                         $1
105                                         RESULT=$?
106                                         break
107                                         ;;
108                                  *)
109                                         shift
110                                         ;;
111                         esac
112                 done
113                 return $RESULT
114         }
115 fi
116
117 kernelver()
118 {
119         awk '{split($3,v,"."); printf("%03d%03d%03d\n", v[1],v[2],v[3]);}' /proc/version
120 }
121
122 kernelverser()
123 {
124         awk '{split($3,v,"."); printf("%03d%03d\n", v[1],v[2]);}' /proc/version
125 }
126
127 kernelvermser()
128 {
129         awk '{split($3,v,"."); printf("%03d\n", v[1]);}' /proc/version
130 }
131
132 # Colors workaround
133 termput()
134 {
135         if is_yes "$FASTRC" || [ ! -d /usr/share/terminfo ] || \
136            [ ! -x /usr/bin/tput -a ! -x /bin/tput ]; then
137                 case "$1" in
138                   hpa)
139                         echo -ne "\033[$(($2+1))G"
140                         ;;
141                   cuu*)
142                         echo -ne "\033[${2}A"
143                         ;;
144                   el)
145                         echo -ne "\033[0K"
146                         ;;
147                   setaf)
148                         typeset ISBOLD
149                         if [ -n "$3" ]; then
150                                 ISBOLD="$3"
151                         else
152                                 ISBOLD="$NOBOLD";
153                         fi
154                         is_yes "$COLOR_INIT" && echo -ne "\033[${ISBOLD};3${2}m"
155                         ;;
156                   op)
157                         termput setaf $NORMAL
158                         ;;
159                 esac
160         else
161                 # check if we are on proper terminal
162                 tput longname > /dev/null 2>&1 || return
163
164                 case "$1" in
165                   hpa | cuu* | el)
166                         tput "$@"
167                         ;;
168                   setaf)
169                         if [ "$3" == "1" ]; then tput bold; else tput sgr0; fi
170                         is_yes "$COLOR_INIT" && tput setaf "$2"
171                         ;;
172                   op)
173                         termput setaf $NORMAL
174                         ;;
175                 esac
176         fi
177 }
178
179 # printf equivalent
180 printf_()
181 {
182         typeset text m
183         text="$1" ;
184         shift ;
185         if [ $# -gt 0 ]; then
186                 m="$1";
187                 shift;
188                 while [ $# -gt 0 ]; do
189                         m="$m\",\"$1" ;
190                         shift ;
191                 done
192         fi
193         awk "BEGIN {printf \"$text\", \"$m\"; }"
194 }
195
196 # National language support function
197 nls()
198 {
199         typeset msg_echo old_nls_domain text message
200         msg_echo='\n'
201         old_nls_domain="$NLS_DOMAIN"
202         # parse command line
203         # don't use -o instead || here - this will break ksh --misiek
204         while [ "$1" != "${1##-}" ] || [ "$1" != "${1##+}" ]; do
205                 case "$1" in
206                   --nls-domain)
207                         shift
208                         NLS_DOMAIN="$1"
209                         shift
210                         ;;
211                   -n)
212                         msg_echo=''
213                         shift
214                         ;;
215                 esac
216         done
217         message="$1"
218         shift
219         # empty message, so we return --misiek
220         if [ -z "$message" ]; then
221                 NLS_DOMAIN="$old_nls_domain"
222                 echo -en "$msg_echo"
223                 return
224         fi
225
226         if is_yes "$FASTRC"; then
227                 printf "$message" "$@"
228         elif [ -x /bin/gettext -o -x /usr/bin/gettext ]; then
229                 text=$(TEXTDOMAINDIR="/etc/sysconfig/locale" gettext -e --domain="${NLS_DOMAIN:-rc-scripts}" "$message")
230                 printf_ "$text" "$@"
231         else
232                 printf_ "$message" "$@"
233         fi
234
235         echo -en "$msg_echo"
236         NLS_DOMAIN="$old_nls_domain"
237 }
238
239 rc_splash()
240 {
241         typeset action
242
243         action="$1"
244
245         if ! is_no "$BOOT_SPLASH"; then
246                 [ -x /bin/splash ] && /bin/splash "$action"
247         fi
248
249         : $((progress++))
250 }
251
252 msg_network_down()
253 {
254         nls "ERROR: Networking is down. %s can't be run." "$1" >&2
255 }
256
257 msg_starting()
258 {
259         show "Starting %s service" "$1"
260 }
261
262 msg_already_running()
263 {
264         nls "%s service is already running." "$1"
265 }
266
267 msg_stopping()
268 {
269         show "Stopping %s service" "$1"
270 }
271
272 msg_not_running()
273 {
274         nls "%s service is not running." "$1"
275 }
276
277 msg_reloading()
278 {
279         show "Reloading %s service" "$1"
280 }
281
282 msg_usage()
283 {
284         nls "Usage: %s" "$*"
285 }
286
287 # Some functions to handle PLD-style messages
288 show()
289 {
290         typeset text
291
292         if is_yes "$FASTRC"; then
293                 echo -n "$INIT_DOTS"
294                 termput hpa 0
295                 if [ -n "$CHARS" ]; then
296                         termput setaf $CCHARS
297                         echo -n "$CHARS"
298                         termput op
299                 fi
300                 printf "$@"
301                 termput hpa $INIT_COL
302         else
303                 text=$(nls "$@")
304                 if [ -n "$CHARS" ]; then
305                         termput setaf $CCHARS
306                         echo -n "$CHARS"
307                         termput op
308                 fi
309                 echo -n "$text"
310                 awk "BEGIN { for (j=length(\"$text\"); j<$INIT_COL; j++) printf \".\" }"
311         fi
312 }
313
314 # Displays message in square brackests ("[ DONE ]"). Takes two arguments.
315 # First is the text to display, second is color number to use (argument to
316 # tput setaf). If second argument is not given, default (2, green) will be
317 # used).
318 progress()
319 {
320         typeset COLOR
321         if [ -n "$2" ]; then COLOR="$2"; else COLOR="$CDONE"; fi
322         deltext
323         echo -n "$(termput setaf $CBRACKETS)[$(termput setaf $COLOR) $(nls --nls-domain rc-scripts "$1") $(termput setaf $CBRACKETS)]$(termput op)"
324 }
325
326 busy()
327 {
328         progress "BUSY" "$CBUSY"
329 }
330
331 ok()
332 {
333         progress "DONE"
334         echo
335 }
336
337 started()
338 {
339         progress "WORK"
340         echo
341 }
342
343 fail()
344 {
345         progress "FAIL" "$CFAIL"
346         echo
347         return 1
348 }
349
350 died()
351 {
352         progress "DIED" "$CFAIL"
353         echo
354         return 1
355 }
356
357 deltext()
358 {
359         termput hpa $INIT_COL
360 }
361
362 # Check if $pid (could be plural) are running
363 checkpid()
364 {
365         while [ "$1" ]; do
366                 [ -d "/proc/$1" ] && return 0
367                 shift
368         done
369         return 1
370 }
371
372 # outside chroot get only thsese processes which are outside chroot.
373 # inside chroot get only these processes which are inside of chroot.
374 # (note: some processes like named are chrooted but run outside chroot)
375 filter_chroot()
376 {
377         if [ $# -lt 1 -o ! -d /proc/1 ] ; then
378                 echo $@
379                 return
380         fi
381         good_pids=""
382         for root_pid in $@; do
383                 root_dir=$(resolvesymlink /proc/${root_pid}/root)
384                 if [ -n "$root_dir" ]; then
385                         good_add_pid=1
386                         if [ -n "${SYSTEM_CHROOTS}" ]; then
387                                 for r_dir in ${SYSTEM_CHROOTS}; do
388                                         echo "$root_dir" | grep -q "^${r_dir}" && good_add_pid=0
389                                 done
390                         fi
391                         [ "$good_add_pid" -eq 1 ] && good_pids="$good_pids $root_pid"
392                 fi
393         done
394         echo $good_pids
395 }
396
397 # Usage run_cmd Message command_to_run
398 run_cmd()
399 {
400         typeset exit_code errors message force_err
401         typeset -i force_err=0
402         typeset -i exit_code=0
403         case "$1" in
404           -a)
405                 force_err=1
406                 shift
407                 ;;
408         esac
409         message=$1
410         show "$message"; busy
411         shift
412         cd /
413         if errors=$(HOME=/tmp TMPDIR=/tmp initlog -c "$*" 2>&1); then
414                 ok
415                 log_success "$1 $message"
416         else
417                 fail
418                 log_failed "$1 $message"
419                 exit_code=1
420         fi
421         [ -n "$errors" ] && [ $exit_code -eq 1 -o $force_err -eq 1 ] && echo "$errors"
422         return $exit_code
423 }
424
425 # A function to start a program (now it's useful on read-only filesystem too)
426 daemon()
427 {
428         typeset errors="" prog="" limits="" waitname="" waittime=""
429         typeset -i exit_code=0
430         [ -z "$DEFAULT_SERVICE_RUN_NICE_LEVEL" ] && DEFAULT_SERVICE_RUN_NICE_LEVEL=0
431         # "-u unlimited" (-p for ksh) to make sure daemons will be able to fork.
432         # "-c 0" to make sure it doesn't core dump anywhere; while this could mask
433         # problems with the daemon, it also closes some security problems.
434         # Users' limits are set via pam_limits.
435         [ -z "$DEFAULT_SERVICE_LIMITS" ] && DEFAULT_SERVICE_LIMITS_HARD="-u unlimited -c 0"
436         # Test syntax. Don't use -o instead || here - this will break ksh --misiek
437         while [ "$1" != "${1##-}" ] || [ "$1" != "${1##+}" ]; do
438                 case $1 in
439                   '')
440                         msg_usage " daemon [--user user] [--fork] [+/-nicelevel] {program}"
441                         return 2
442                         ;;
443                   --check)
444                         # for compatibility with redhat/mandrake
445                         nls "warning: --check option is ignored!"
446                         shift
447                         shift
448                         ;;
449                   --user)
450                         shift
451                         [ "$1" != "root" ] && prog="/bin/su $1 -s /bin/sh -c \""
452                         shift
453                         ;;
454                   --fork)
455                         prog="/usr/bin/setsid sh -c \""
456                         end='&'
457                         shift
458                         ;;
459                   --waitforname)
460                         shift
461                         waitname="$1"
462                         shift
463                         ;;
464                   --waitfortime)
465                         shift
466                         waittime="$1"
467                         shift
468                         ;;
469                   -*|+*) SERVICE_RUN_NICE_LEVEL=$1
470                         shift
471                         ;;
472                 esac
473         done
474         # If command to execute ends with quotation mark, add remaining
475         # arguments and close quotation.
476         if [ "$prog" != "${prog%\"}" ]; then
477                 prog="$prog $*$end\""
478         else
479                 prog="$prog $*$end"
480         fi
481
482         if [ -n "$KSH_VERSION" ]; then
483                 limits="`echo "${SERVICE_LIMITS:-$DEFAULT_SERVICE_LIMITS}" | awk '/-Su/ {sub(/-Su/,"-Sp");} /-Hu/ {sub(/-Hu/,"-Hp");} /-u/ {sub(/-u/,"-p");} {print;}'`"
484         elif [ -n "$ZSH_VERSION" ]; then
485                 limits="${SERVICE_LIMITS:-$DEFAULT_SERVICE_LIMITS}"
486         elif [ -n "$BASH_VERSION" ]; then
487                 limits="${SERVICE_LIMITS:-$DEFAULT_SERVICE_LIMITS}"
488 #       elif [ -n "`$SH -c 'echo ${.sh.version}' 2>/dev/null`" ]; then
489         fi
490
491         [ -n "$limits" ] && eval `echo "$limits" | awk 'BEGIN {RS="[\n-]";} !/^ *$/ { printf("ulimit -%s ;", $0); }'`
492
493         [ -z "$DEFAULT_SERVICE_UMASK" ] && DEFAULT_SERVICE_UMASK=022
494
495         # And start it up.
496         busy
497         cd /
498         if errors=$(umask ${SERVICE_UMASK:-$DEFAULT_SERVICE_UMASK}; USER=root HOME=/tmp TMPDIR=/tmp nice -n ${SERVICE_RUN_NICE_LEVEL:-$DEFAULT_SERVICE_RUN_NICE_LEVEL} initlog -c "$prog" 2>&1); then
499                 if [ -n "$waitname" -a -n "$waittime" ]; then
500                         # Save basename.
501                         base=$(basename "$waitname")
502                         # Find pid.
503                         pid=$(pidofproc "$waitname" "$pidfile")
504                         [ -z "$pid" ] && pid=$(pidofproc "$base" "$pidfile")
505                         i=0
506                         while [ "$i" -lt "$waittime" ]; do
507                                 checkpid $pid && sleep 1 || break
508                         done
509                 fi
510                 log_success "$1 startup"
511                 ok
512         else
513                 exit_code=1
514                 fail
515                 log_failed "$1 startup"
516                 [ -n "$errors" ] && echo "$errors"
517         fi
518         return $exit_code
519 }
520
521 # A function to stop a program.
522 killproc()
523 {
524         typeset notset killlevel base pid pidfile result
525         # Test syntax.
526         if [ $# = 0 ]; then
527                 msg_usage " killproc {program} [signal]"
528                 return 2
529         fi
530
531         while [ "$1" != "${1##-}" ] || [ "$1" != "${1##+}" ]; do
532                 case $1 in
533                         --pidfile)
534                                 shift
535                                 pidfile="$1"
536                                 shift
537                         ;;
538                         --waitforname)
539                                 shift
540                                 waitname="$1"
541                                 shift
542                         ;;
543                         --waitfortime)
544                                 shift
545                                 waittime="$1"
546                                 shift
547                         ;;
548                 esac
549         done
550
551         busy
552
553         typeset -i notset=0
554         # check for second arg to be kill level
555         if [ -n "$2" ] ; then
556                 killlevel=$2
557         else
558                 notset=1
559                 killlevel="-9"
560         fi
561
562         # Save basename.
563         base=$(basename "$1")
564
565         # Find pid.
566         pid=$(pidofproc "$1" "$pidfile")
567         [ -z "$pid" ] && pid=$(pidofproc "$base" "$pidfile")
568
569         # Kill it.
570         if [ -n "$pid" -a "$pid" != "$$" ] && checkpid $pid 2>&1 ; then
571                 if [ "$notset" = "1" ] ; then
572                         if checkpid $pid 2>&1; then
573                                 # TERM first, then KILL if not dead
574                                 kill -TERM $pid
575                                 usleep 100000
576                                 if checkpid $pid && sleep 1 &&
577                                         checkpid $pid && sleep 3 &&
578                                         checkpid $pid; then
579                                         kill -KILL $pid
580                                         usleep 100000
581                                 fi
582                         fi
583                         checkpid $pid
584                         result=$?
585                         if [ "$result" -eq 0 ]; then
586                                 fail
587                                 log_failed "$1 shutdown"
588                         else
589                                 ok
590                                 log_success "$1 shutdown"
591                         fi
592                         result=$(( ! $result ))
593                 else
594                         # use specified level only
595                         if checkpid $pid > /dev/null 2>&1; then
596                                 kill $killlevel $pid
597                                 result=$?
598                                 if [ "$result" -eq 0 ]; then
599                                         ok
600                                         log_success "$1 got $killlevel"
601                                 else
602                                         result=7
603                                         fail
604                                         log_failed "$1 didn't get $killlevel"
605                                 fi
606                         else
607                                 result=7
608                                 died
609                                 log_failed "$1 shutdown"
610                         fi
611                 fi
612         else
613                 died
614                 log_failed "$1 shutdown"
615                 result=7
616         fi
617         
618         if [ -n "$waitname" -a -n "$waittime" ]; then
619                 i=0
620                 while [ "$i" -lt "$waittime" ]; do
621                         checkpid $pid && sleep 1 || break
622                 done
623         fi
624
625         # Remove pid file if any.
626         if [ "$notset" = "1" ]; then
627                 rm -f /var/run/${base}.pid
628         fi
629
630         return $result
631 }
632
633 # A function to find the pid of a program.
634 pidofproc()
635 {
636         typeset pid pidfile base
637         base=$(basename "$1")
638         pidfile="$base.pid"
639         [ -n "$2" ] && pidfile="$2"
640
641         # Test syntax.
642         if [ $# = 0 ] ; then
643                 msg_usage " pidofproc {program}"
644                 return 2
645         fi
646
647         # First try pidfile or "/var/run/*.pid"
648         if [ -f /var/run/${pidfile} ] ; then
649                 typeset line p pid
650                 pid=
651                 read line < /var/run/${pidfile}
652                 for p in $line; do
653                         [ -z "$(echo "$p" | awk '{gsub(/[0-9]/,"");print;}')" ] && pid="$pid $p"
654                 done
655         fi
656
657         # Next try "pidof"
658         [ -z "$pid" ] && pidof -o $$ -o $PPID -o %PPID -x "$1"
659         pid=$(filter_chroot "$pid")
660         echo $pid
661 }
662
663 status()
664 {
665         typeset base pid subsys daemon
666         subsys=$1
667         daemon=${2:-$subsys}
668         base=$(basename $daemon)
669
670         # Test syntax.
671         if [ $# = 0 ] ; then
672                 msg_usage " status {subsys} [{daemon}]"
673                 return 2
674         fi
675
676         # First try "pidof"
677         pid=$(pidof -o $$ -o $PPID -o %PPID -x $daemon)
678         pid=$(filter_chroot "$pid")
679
680         if [ "$pid" != "" ]; then
681                 nls "%s (pid %s) is running..." "$daemon" "$pid"
682                 return 0
683 #       else
684 #               pid=`ps ax | awk 'BEGIN { prog=ARGV[1]; ARGC=1 }
685 #                    { if ((prog == $5) || (("(" prog ")") == $5) ||
686 #                         (("[" prog "]") == $5) ||
687 #                         ((prog ":") == $5)) { print $1 ; exit 0 } }' $1`
688 #               if [ "$pid" != "" ]; then
689 #                       nls "%s (pid %s) is running..." "$daemon" "$pid"
690 #                       return 0
691 #               fi
692         fi
693
694         # Next try "/var/run/*.pid" files
695         if [ -f /var/run/${base}.pid ]; then
696                 read pid < /var/run/${base}.pid
697                 pid=$(filter_chroot "$pid")
698                 if [ "$pid" != "" ]; then
699                         nls "%s dead but pid file exists" "$subsys"
700                         return 1
701                 fi
702         fi
703
704         # See if /var/lock/subsys/$subsys exists
705         if [ -f /var/lock/subsys/$subsys ]; then
706                 nls "%s dead but subsys locked" "$subsys"
707                 return 2
708         fi
709         nls "%s is stopped" "$subsys"
710         return 3
711 }
712
713 # Confirm whether we really want to run this service
714 confirm() {
715         typeset answer
716         nls -n "Start service %s (Y)es/(N)o/(C)ontinue? [Y] " "$1"
717         read answer
718         case $answer in
719           y|Y|t|T|j|J|"")
720                 return 0
721                 ;;
722           c|C|k|K|w|W)
723                 return 2
724                 ;;
725           n|N)
726                 return 1
727                 ;;
728           *)
729                 confirm $1
730                 return $?
731                 ;;
732         esac
733 }
734
735 # module is needed (ie. is requested, is available and isn't loaded already)
736 is_module()
737 {
738         # module name without .o at end
739         if ! (lsmod | grep -q "$1"); then
740                 if (ls -R /lib/modules/$(uname -r)/ 2> /dev/null | grep -q "${1}.\(\|k\)o\(\|.gz\)"); then
741                         # true
742                         return 0
743                 fi
744         fi
745         # false
746         return 1
747 }
748
749 _modprobe()
750 {
751         typeset parsed single die args foo result
752         parsed=no
753         while is_no "$parsed" ; do
754                 case "$1" in
755                   "single")
756                         single=yes
757                         shift
758                         ;;
759                   "die")
760                         die=yes
761                         shift
762                         ;;
763                   -*)
764                         args="$args $1"
765                         shift
766                         ;;
767                   *)
768                         parsed=yes
769                         ;;
770                 esac
771         done
772         if is_yes "${single}" ; then
773                 foo="$@"
774                 show "Loading %s kernel module(s)" "$foo"
775                 busy
776         fi
777         if [ -x /sbin/modprobe ] ; then
778                 /sbin/modprobe -s $args "$@"
779                 result=$?
780         else
781                 deltext ; fail
782                 result=1
783         fi
784         if is_yes "${single}" ; then
785                 deltext
786                 if [ $result == "0" ] ; then
787                         is_yes "$single" && ok
788                 else
789                         fail
790                         if is_yes "$die" ; then
791                                 nls "Could not load %s kernel module(s)" "$@"
792                                 exit 1
793                         fi
794                 fi
795         fi
796 }
797
798 log_success ()
799 {
800         initlog -n $0 -s "$1 $2" -e 1
801 }
802
803 log_failed ()
804 {
805         initlog -n $0 -s "$1 $2" -e 2
806 }
807
808 # RedHat/Mandrake specific functions
809 action () { STRING=$1; shift; run_cmd "$STRING" "$*"; }
810 success () { return 0; }
811 failure () { return 1; }
812
813 disable_selinux() {
814         selinuxfs=`awk '/ selinuxfs / { print $2 }' /proc/mounts`
815         echo "*** Warning -- SELinux is active"
816         echo "*** Disabling security enforcement for system recovery."
817         echo "*** Run 'setenforce 1' to reenable."
818         echo "0" > $selinuxfs/enforce
819 }
820
821 relabel_selinux() {
822         selinuxfs=`awk '/ selinuxfs / { print $2 }' /proc/mounts`
823         echo "
824          *** Warning -- SELinux relabel is required. ***
825          *** Disabling security enforcement.         ***
826          *** Relabeling could take a very long time, ***
827          *** depending on file system size.          ***
828          "
829         echo "0" > $selinuxfs/enforce
830         /sbin/fixfiles -F relabel > /dev/null 2>&1
831         rm -f  /.autorelabel
832         echo "*** Enabling security enforcement.         ***"
833         echo $SELINUX > $selinuxfs/enforce
834 }
835
836 #/*
837 # * Local variables:
838 # * mode: sh
839 # * indent-tabs-mode: notnil
840 # * End:
841 # *
842 # */
843 # vi: syntax=sh:shiftwidth=8:
This page took 0.149849 seconds and 4 git commands to generate.