Subversion Repositories configs

Rev

Rev 4 | Rev 34 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 - 1
# -*-Shell-script-*-
2
#
3
# functions	This file contains functions to be used by most or all
4
#		shell scripts in the /etc/init.d directory.
5
#
6
 
7
TEXTDOMAIN=initscripts
8
 
9
# Make sure umask is sane
10
umask 022
11
 
12
# Set up a default search path.
13
PATH="/sbin:/usr/sbin:/bin:/usr/bin"
14
export PATH
15
 
16
# Get a sane screen width
17
[ -z "${COLUMNS:-}" ] && COLUMNS=80
18
 
19
[ -z "${CONSOLETYPE:-}" ] && CONSOLETYPE="$(/sbin/consoletype)"
20
 
21
if [ -f /etc/sysconfig/i18n -a -z "${NOLOCALE:-}" -a -z "${LANGSH_SOURCED:-}" ] ; then
22
  . /etc/profile.d/lang.sh 2>/dev/null
23
  # avoid propagating LANGSH_SOURCED any further
24
  unset LANGSH_SOURCED
25
fi
26
 
27
# Read in our configuration
28
if [ -z "${BOOTUP:-}" ]; then
29
  if [ -f /etc/sysconfig/init ]; then
30
      . /etc/sysconfig/init
31
  else
32
    # This all seem confusing? Look in /etc/sysconfig/init,
33
    # or in /usr/doc/initscripts-*/sysconfig.txt
34
    BOOTUP=color
35
    RES_COL=60
36
    MOVE_TO_COL="echo -en \\033[${RES_COL}G"
37
    SETCOLOR_SUCCESS="echo -en \\033[1;32m"
38
    SETCOLOR_FAILURE="echo -en \\033[1;31m"
39
    SETCOLOR_WARNING="echo -en \\033[1;33m"
40
    SETCOLOR_NORMAL="echo -en \\033[0;39m"
41
    LOGLEVEL=1
42
  fi
43
  if [ "$CONSOLETYPE" = "serial" ]; then
44
      BOOTUP=serial
45
      MOVE_TO_COL=
46
      SETCOLOR_SUCCESS=
47
      SETCOLOR_FAILURE=
48
      SETCOLOR_WARNING=
49
      SETCOLOR_NORMAL=
50
  fi
51
fi
52
 
53
# Interpret escape sequences in an fstab entry
54
fstab_decode_str() {
55
	fstab-decode echo "$1"
56
}
57
 
58
# Check if any of $pid (could be plural) are running
59
checkpid() {
60
	local i
61
 
62
	for i in $* ; do
63
		[ -d "/proc/$i" ] && return 0
64
	done
65
	return 1
66
}
67
 
68
__readlink() {
69
    ls -bl "$@" 2>/dev/null| awk '{ print $NF }'
70
}
71
 
72
__fgrep() {
73
    s=$1
74
    f=$2
75
    while read line; do
76
	if strstr "$line" "$s"; then
77
	    echo $line
78
	    return 0
79
	fi
80
    done < $f
81
    return 1
82
}
83
 
84
# __umount_loop awk_program fstab_file first_msg retry_msg retry_umount_args
85
# awk_program should process fstab_file and return a list of fstab-encoded
86
# paths; it doesn't have to handle comments in fstab_file.
87
__umount_loop() {
88
	local remaining sig=
89
	local retry=3 count
90
 
91
	remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
92
	while [ -n "$remaining" -a "$retry" -gt 0 ]; do
93
		if [ "$retry" -eq 3 ]; then
94
			action "$3" fstab-decode umount $remaining
95
		else
96
			action "$4" fstab-decode umount $5 $remaining
97
		fi
98
		count=4
99
		remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
100
		while [ "$count" -gt 0 ]; do
101
			[ -z "$remaining" ] && break
102
			count=$(($count-1))
103
			usleep 500000
104
			remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
105
		done
106
		[ -z "$remaining" ] && break
9 - 107
		kill $sig $(fstab-decode /sbin/fuser -m $remaining 2>/dev/null  | sed -e "s/\b$$\b//g") > /dev/null
4 - 108
		sleep 3
109
		retry=$(($retry -1))
110
		sig=-9
111
	done
112
}
113
 
114
# Similar to __umount loop above, specialized for loopback devices
115
__umount_loopback_loop() {
116
	local remaining devremaining sig=
117
	local retry=3
118
 
119
	remaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts)
120
	devremaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $1}' /proc/mounts)
121
	while [ -n "$remaining" -a "$retry" -gt 0 ]; do
122
		if [ "$retry" -eq 3 ]; then
123
			action $"Unmounting loopback filesystems: " \
124
				fstab-decode umount $remaining
125
		else
126
			action $"Unmounting loopback filesystems (retry):" \
127
				fstab-decode umount $remaining
128
		fi
129
		for dev in $devremaining ; do
130
			losetup $dev > /dev/null 2>&1 && \
131
				action $"Detaching loopback device $dev: " \
132
				losetup -d $dev
133
		done
134
		remaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts)
135
		devremaining=$(awk '$1 ~ /^\/dev\/loop/ && $2 != "/" {print $1}' /proc/mounts)
136
		[ -z "$remaining" ] && break
137
		fstab-decode /sbin/fuser -k -m $sig $remaining >/dev/null
138
		sleep 3
139
		retry=$(($retry -1))
140
		sig=-9
141
	done
142
}
143
 
144
# __proc_pids {program} [pidfile]
145
# Set $pid to pids from /var/run* for {program}.  $pid should be declared
146
# local in the caller.
147
# Returns LSB exit code for the 'status' action.
148
__pids_var_run() {
149
	local base=${1##*/}
150
	local pid_file=${2:-/var/run/$base.pid}
9 - 151
	local pid_dir=$(/usr/bin/dirname $pid_file)
4 - 152
	local binary=$3
153
 
9 - 154
	[ -d "$pid_dir" -a ! -r "$pid_dir" ] && return 4
155
 
4 - 156
	pid=
157
	if [ -f "$pid_file" ] ; then
158
	        local line p
159
 
160
		[ ! -r "$pid_file" ] && return 4 # "user had insufficient privilege"
161
		while : ; do
162
			read line
163
			[ -z "$line" ] && break
164
			for p in $line ; do
165
				if [ -z "${p//[0-9]/}" -a -d "/proc/$p" ] ; then
166
					if [ -n "$binary" ] ; then
9 - 167
						local b=$(readlink /proc/$p/exe | sed -e 's/\s*(deleted)$//')
4 - 168
						[ "$b" != "$binary" ] && continue
169
					fi
170
					pid="$pid $p"
171
				fi
172
			done
173
		done < "$pid_file"
174
 
175
	        if [ -n "$pid" ]; then
176
	                return 0
177
	        fi
178
		return 1 # "Program is dead and /var/run pid file exists"
179
	fi
180
	return 3 # "Program is not running"
181
}
182
 
183
# Output PIDs of matching processes, found using pidof
184
__pids_pidof() {
185
	pidof -c -o $$ -o $PPID -o %PPID -x "$1" || \
186
		pidof -c -o $$ -o $PPID -o %PPID -x "${1##*/}"
187
}
188
 
189
 
190
# A function to start a program.
191
daemon() {
192
	# Test syntax.
193
	local gotbase= force= nicelevel corelimit
194
	local pid base= user= nice= bg= pid_file=
195
	local cgroup=
196
	nicelevel=0
197
	while [ "$1" != "${1##[-+]}" ]; do
198
	  case $1 in
199
	    '')    echo $"$0: Usage: daemon [+/-nicelevel] {program}"
200
	           return 1;;
201
	    --check)
202
		   base=$2
203
		   gotbase="yes"
204
		   shift 2
205
		   ;;
206
	    --check=?*)
207
	    	   base=${1#--check=}
208
		   gotbase="yes"
209
		   shift
210
		   ;;
211
	    --user)
212
		   user=$2
213
		   shift 2
214
		   ;;
215
	    --user=?*)
216
	           user=${1#--user=}
217
		   shift
218
		   ;;
219
	    --pidfile)
220
		   pid_file=$2
221
		   shift 2
222
		   ;;
223
	    --pidfile=?*)
224
		   pid_file=${1#--pidfile=}
225
		   shift
226
		   ;;
227
	    --force)
228
	    	   force="force"
229
		   shift
230
		   ;;
231
	    [-+][0-9]*)
232
	    	   nice="nice -n $1"
233
	           shift
234
		   ;;
235
	    *)     echo $"$0: Usage: daemon [+/-nicelevel] {program}"
236
	           return 1;;
237
	  esac
238
	done
239
 
240
        # Save basename.
241
        [ -z "$gotbase" ] && base=${1##*/}
242
 
243
        # See if it's already running. Look *only* at the pid file.
244
	__pids_var_run "$base" "$pid_file"
245
 
246
	[ -n "$pid" -a -z "$force" ] && return
247
 
248
	# make sure it doesn't core dump anywhere unless requested
249
	corelimit="ulimit -S -c ${DAEMON_COREFILE_LIMIT:-0}"
250
 
251
	# if they set NICELEVEL in /etc/sysconfig/foo, honor it
252
	[ -n "${NICELEVEL:-}" ] && nice="nice -n $NICELEVEL"
253
 
254
	# if they set CGROUP_DAEMON in /etc/sysconfig/foo, honor it
255
	if [ -n "${CGROUP_DAEMON}" ]; then
256
		if [ ! -x /bin/cgexec ]; then
257
			echo -n "Cgroups not installed"; warning
258
			echo
259
		else
260
			cgroup="/bin/cgexec";
261
			for i in $CGROUP_DAEMON; do
262
				cgroup="$cgroup -g $i";
263
			done
264
		fi
265
	fi
266
 
267
	# Echo daemon
268
        [ "${BOOTUP:-}" = "verbose" -a -z "${LSB:-}" ] && echo -n " $base"
269
 
270
	# And start it up.
271
	if [ -z "$user" ]; then
272
	   $cgroup $nice /bin/bash -c "$corelimit >/dev/null 2>&1 ; $*"
273
	else
274
	   $cgroup $nice runuser -s /bin/bash $user -c "$corelimit >/dev/null 2>&1 ; $*"
275
	fi
276
 
277
	[ "$?" -eq 0 ] && success $"$base startup" || failure $"$base startup"
278
}
279
 
280
# A function to stop a program.
281
killproc() {
282
	local RC killlevel= base pid pid_file= delay try binary=
283
 
284
	RC=0; delay=3; try=0
285
	# Test syntax.
286
	if [ "$#" -eq 0 ]; then
287
		echo $"Usage: killproc [-p pidfile] [ -d delay] {program} [-signal]"
288
		return 1
289
	fi
290
	if [ "$1" = "-p" ]; then
291
		pid_file=$2
292
		shift 2
293
	fi
294
	if [ "$1" = "-b" ]; then
295
		if [ -z $pid_file ]; then
296
			echo $"-b option can be used only with -p"
297
			echo $"Usage: killproc -p pidfile -b binary program"
298
			return 1
299
		fi
300
		binary=$2
301
		shift 2
302
	fi
303
	if [ "$1" = "-d" ]; then
304
		delay=$(echo $2 | awk -v RS=' ' -v IGNORECASE=1 '{if($1!~/^[0-9.]+[smhd]?$/) exit 1;d=$1~/s$|^[0-9.]*$/?1:$1~/m$/?60:$1~/h$/?60*60:$1~/d$/?24*60*60:-1;if(d==-1) exit 1;delay+=d*$1} END {printf("%d",delay+0.5)}')
305
		if [ "$?" -eq 1 ]; then
306
			echo $"Usage: killproc [-p pidfile] [ -d delay] {program} [-signal]"
307
			return 1
308
		fi
309
		shift 2
310
	fi
311
 
312
 
313
	# check for second arg to be kill level
314
	[ -n "${2:-}" ] && killlevel=$2
315
 
316
        # Save basename.
317
        base=${1##*/}
318
 
319
        # Find pid.
320
	__pids_var_run "$1" "$pid_file" "$binary"
321
	RC=$?
322
	if [ -z "$pid" ]; then
323
		if [ -z "$pid_file" ]; then
324
			pid="$(__pids_pidof "$1")"
325
		else
326
			[ "$RC" = "4" ] && { failure $"$base shutdown" ; return $RC ;}
327
		fi
328
	fi
329
 
330
        # Kill it.
331
        if [ -n "$pid" ] ; then
332
                [ "$BOOTUP" = "verbose" -a -z "${LSB:-}" ] && echo -n "$base "
333
		if [ -z "$killlevel" ] ; then
334
		       if checkpid $pid 2>&1; then
335
			   # TERM first, then KILL if not dead
336
			   kill -TERM $pid >/dev/null 2>&1
337
			   usleep 100000
338
			   if checkpid $pid ; then
339
				try=0
340
				while [ $try -lt $delay ] ; do
341
					checkpid $pid || break
342
					sleep 1
343
					let try+=1
344
				done
345
				if checkpid $pid ; then
346
					kill -KILL $pid >/dev/null 2>&1
347
					usleep 100000
348
				fi
349
			   fi
350
		        fi
351
			checkpid $pid
352
			RC=$?
353
			[ "$RC" -eq 0 ] && failure $"$base shutdown" || success $"$base shutdown"
354
			RC=$((! $RC))
355
		# use specified level only
356
		else
357
		        if checkpid $pid; then
358
	                	kill $killlevel $pid >/dev/null 2>&1
359
				RC=$?
360
				[ "$RC" -eq 0 ] && success $"$base $killlevel" || failure $"$base $killlevel"
361
			elif [ -n "${LSB:-}" ]; then
362
				RC=7 # Program is not running
363
			fi
364
		fi
365
	else
366
		if [ -n "${LSB:-}" -a -n "$killlevel" ]; then
367
			RC=7 # Program is not running
368
		else
369
			failure $"$base shutdown"
370
			RC=0
371
		fi
372
	fi
373
 
374
        # Remove pid file if any.
375
	if [ -z "$killlevel" ]; then
376
            rm -f "${pid_file:-/var/run/$base.pid}"
377
	fi
378
	return $RC
379
}
380
 
381
# A function to find the pid of a program. Looks *only* at the pidfile
382
pidfileofproc() {
383
	local pid
384
 
385
	# Test syntax.
386
	if [ "$#" = 0 ] ; then
387
		echo $"Usage: pidfileofproc {program}"
388
		return 1
389
	fi
390
 
391
	__pids_var_run "$1"
392
	[ -n "$pid" ] && echo $pid
393
	return 0
394
}
395
 
396
# A function to find the pid of a program.
397
pidofproc() {
398
	local RC pid pid_file=
399
 
400
	# Test syntax.
401
	if [ "$#" = 0 ]; then
402
		echo $"Usage: pidofproc [-p pidfile] {program}"
403
		return 1
404
	fi
405
	if [ "$1" = "-p" ]; then
406
		pid_file=$2
407
		shift 2
408
	fi
409
	fail_code=3 # "Program is not running"
410
 
411
	# First try "/var/run/*.pid" files
412
	__pids_var_run "$1" "$pid_file"
413
	RC=$?
414
	if [ -n "$pid" ]; then
415
		echo $pid
416
		return 0
417
	fi
418
 
419
	[ -n "$pid_file" ] && return $RC
420
	__pids_pidof "$1" || return $RC
421
}
422
 
423
status() {
424
	local base pid lock_file= pid_file= binary=
425
 
426
	# Test syntax.
427
	if [ "$#" = 0 ] ; then
428
		echo $"Usage: status [-p pidfile] {program}"
429
		return 1
430
	fi
431
	if [ "$1" = "-p" ]; then
432
		pid_file=$2
433
		shift 2
434
	fi
435
	if [ "$1" = "-l" ]; then
436
		lock_file=$2
437
		shift 2
438
	fi
439
	if [ "$1" = "-b" ]; then
440
		if [ -z $pid_file ]; then
441
			echo $"-b option can be used only with -p"
442
			echo $"Usage: status -p pidfile -b binary program"
443
			return 1
444
		fi
445
		binary=$2
446
		shift 2
447
	fi
448
	base=${1##*/}
449
 
450
	# First try "pidof"
451
	__pids_var_run "$1" "$pid_file" "$binary"
452
	RC=$?
453
	if [ -z "$pid_file" -a -z "$pid" ]; then
454
		pid="$(__pids_pidof "$1")"
455
	fi
456
	if [ -n "$pid" ]; then
457
	        echo $"${base} (pid $pid) is running..."
458
	        return 0
459
	fi
460
 
461
	case "$RC" in
462
		0)
463
			echo $"${base} (pid $pid) is running..."
464
			return 0
465
			;;
466
		1)
467
	                echo $"${base} dead but pid file exists"
468
	                return 1
469
			;;
470
		4)
471
			echo $"${base} status unknown due to insufficient privileges."
472
			return 4
473
			;;
474
	esac
475
	if [ -z "${lock_file}" ]; then
476
		lock_file=${base}
477
	fi
478
	# See if /var/lock/subsys/${lock_file} exists
479
	if [ -f /var/lock/subsys/${lock_file} ]; then
480
		echo $"${base} dead but subsys locked"
481
		return 2
482
	fi
483
	echo $"${base} is stopped"
484
	return 3
485
}
486
 
487
echo_success() {
488
  [ "$BOOTUP" = "color" ] && $MOVE_TO_COL
489
  echo -n "["
490
  [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS
491
  echo -n $"  OK  "
492
  [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
493
  echo -n "]"
494
  echo -ne "\r"
495
  return 0
496
}
497
 
498
echo_failure() {
499
  [ "$BOOTUP" = "color" ] && $MOVE_TO_COL
500
  echo -n "["
501
  [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
502
  echo -n $"FAILED"
503
  [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
504
  echo -n "]"
505
  echo -ne "\r"
506
  return 1
507
}
508
 
509
echo_passed() {
510
  [ "$BOOTUP" = "color" ] && $MOVE_TO_COL
511
  echo -n "["
512
  [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
513
  echo -n $"PASSED"
514
  [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
515
  echo -n "]"
516
  echo -ne "\r"
517
  return 1
518
}
519
 
520
echo_warning() {
521
  [ "$BOOTUP" = "color" ] && $MOVE_TO_COL
522
  echo -n "["
523
  [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
524
  echo -n $"WARNING"
525
  [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
526
  echo -n "]"
527
  echo -ne "\r"
528
  return 1
529
}
530
 
531
# Inform the graphical boot of our current state
532
update_boot_stage() {
533
  if [ -x /bin/plymouth ]; then
534
      /bin/plymouth --update="$1"
535
  fi
536
  return 0
537
}
538
 
539
# Log that something succeeded
540
success() {
541
  [ "$BOOTUP" != "verbose" -a -z "${LSB:-}" ] && echo_success
542
  return 0
543
}
544
 
545
# Log that something failed
546
failure() {
547
  local rc=$?
548
  [ "$BOOTUP" != "verbose" -a -z "${LSB:-}" ] && echo_failure
549
  [ -x /bin/plymouth ] && /bin/plymouth --details
550
  return $rc
551
}
552
 
553
# Log that something passed, but may have had errors. Useful for fsck
554
passed() {
555
  local rc=$?
556
  [ "$BOOTUP" != "verbose" -a -z "${LSB:-}" ] && echo_passed
557
  return $rc
558
}
559
 
560
# Log a warning
561
warning() {
562
  local rc=$?
563
  [ "$BOOTUP" != "verbose" -a -z "${LSB:-}" ] && echo_warning
564
  return $rc
565
}
566
 
567
# Run some action. Log its output.
568
action() {
569
  local STRING rc
570
 
571
  STRING=$1
572
  echo -n "$STRING "
573
  shift
574
  "$@" && success $"$STRING" || failure $"$STRING"
575
  rc=$?
576
  echo
577
  return $rc
578
}
579
 
580
# returns OK if $1 contains $2
581
strstr() {
582
  [ "${1#*$2*}" = "$1" ] && return 1
583
  return 0
584
}
585
 
586
# Confirm whether we really want to run this service
587
confirm() {
588
  [ -x /bin/plymouth ] && /bin/plymouth --hide-splash
589
  while : ; do
590
      echo -n $"Start service $1 (Y)es/(N)o/(C)ontinue? [Y] "
591
      read answer
592
      if strstr $"yY" "$answer" || [ "$answer" = "" ] ; then
593
         return 0
594
      elif strstr $"cC" "$answer" ; then
595
	 rm -f /var/run/confirm
596
	 [ -x /bin/plymouth ] && /bin/plymouth --show-splash
597
         return 2
598
      elif strstr $"nN" "$answer" ; then
599
         return 1
600
      fi
601
  done
602
}
603
 
604
# resolve a device node to its major:minor numbers in decimal or hex
605
get_numeric_dev() {
606
(
607
    fmt="%d:%d"
608
    if [ "$1" == "hex" ]; then
609
        fmt="%x:%x"
610
    fi
611
    ls -lH "$2" | awk '{ sub(/,/, "", $5); printf("'"$fmt"'", $5, $6); }'
612
) 2>/dev/null
613
}
614
 
615
# Check whether file $1 is a backup or rpm-generated file and should be ignored
616
is_ignored_file() {
617
    case "$1" in
618
	*~ | *.bak | *.orig | *.rpmnew | *.rpmorig | *.rpmsave)
619
	    return 0
620
	    ;;
621
    esac
622
    return 1
623
}
624
 
625
# Evaluate shvar-style booleans
626
is_true() {
627
    case "$1" in
628
	[tT] | [yY] | [yY][eE][sS] | [tT][rR][uU][eE])
629
	return 0
630
	;;
631
    esac
632
    return 1
633
}
634
 
635
# Evaluate shvar-style booleans
636
is_false() {
637
    case "$1" in
638
	[fF] | [nN] | [nN][oO] | [fF][aA][lL][sS][eE])
639
	return 0
640
	;;
641
    esac
642
    return 1
643
}
644
 
645
# Apply sysctl settings, including files in /etc/sysctl.d
646
apply_sysctl() {
647
    sysctl -e -p /etc/sysctl.conf >/dev/null 2>&1
648
    for file in /etc/sysctl.d/* ; do
649
        is_ignored_file "$file" && continue
650
        test -f "$file" && sysctl -e -p "$file" >/dev/null 2>&1
651
    done
652
}
653
 
654
key_is_random() {
655
    [ "$1" = "/dev/urandom" -o "$1" = "/dev/hw_random" \
656
	-o "$1" = "/dev/random" ]
657
}
658
 
659
find_crypto_mount_point() {
660
    local fs_spec fs_file fs_vfstype remaining_fields
661
    local fs
662
    while read fs_spec fs_file remaining_fields; do
663
	if [ "$fs_spec" = "/dev/mapper/$1" ]; then
664
	    echo $fs_file
665
	    break;
666
	fi
667
    done < /etc/fstab
668
}
669
 
670
# Because of a chicken/egg problem, init_crypto must be run twice.  /var may be
671
# encrypted but /var/lib/random-seed is needed to initialize swap.
672
init_crypto() {
673
    local have_random dst src key opt mode owner params makeswap skip arg opt
674
    local param value rc ret mke2fs mdir prompt mount_point
675
 
676
    ret=0
677
    have_random=$1
678
    while read dst src key opt; do
679
	[ -z "$dst" -o "${dst#\#}" != "$dst" ] && continue
680
        [ -b "/dev/mapper/$dst" ] && continue;
681
	if [ "$have_random" = 0 ] && key_is_random "$key"; then
682
	    continue
683
	fi
684
	if [ -n "$key" -a "x$key" != "xnone" ]; then
685
	    if test -e "$key" ; then
686
		owner=$(ls -l $key | (read a b owner rest; echo $owner))
687
		if ! key_is_random "$key"; then
688
		    mode=$(ls -l "$key" | cut -c 5-10)
689
		    if [ "$mode" != "------" ]; then
690
		       echo $"INSECURE MODE FOR $key"
691
		    fi
692
		fi
693
		if [ "$owner" != root ]; then
694
		    echo $"INSECURE OWNER FOR $key"
695
		fi
696
	    else
697
		echo $"Key file for $dst not found, skipping"
698
		ret=1
699
		continue
700
	    fi
701
	else
702
	    key=""
703
	fi
704
	params=""
705
	makeswap=""
706
	mke2fs=""
707
	skip=""
708
	# Parse the src field for UUID= and convert to real device names
709
	if [ "${src%%=*}" == "UUID" ]; then
710
		src=$(/sbin/blkid -t "$src" -l -o device)
711
	elif [ "${src/^\/dev\/disk\/by-uuid\/}" != "$src" ]; then
712
		src=$(__readlink $src)
713
	fi
714
	# Is it a block device?
715
	[ -b "$src" ] || continue
716
	# Is it already a device mapper slave? (this is gross)
717
	devesc=${src##/dev/}
718
	devesc=${devesc//\//!}
719
	for d in /sys/block/dm-*/slaves ; do
720
	    [ -e $d/$devesc ] && continue 2
721
	done
722
	# Parse the options field, convert to cryptsetup parameters and
723
	# contruct the command line
724
	while [ -n "$opt" ]; do
725
	    arg=${opt%%,*}
726
	    opt=${opt##$arg}
727
	    opt=${opt##,}
728
	    param=${arg%%=*}
729
	    value=${arg##$param=}
730
 
731
	    case "$param" in
732
	    cipher)
733
		params="$params -c $value"
734
		if [ -z "$value" ]; then
735
		    echo $"$dst: no value for cipher option, skipping"
736
		    skip="yes"
737
		fi
738
	    ;;
739
	    size)
740
		params="$params -s $value"
741
		if [ -z "$value" ]; then
742
		    echo $"$dst: no value for size option, skipping"
743
		    skip="yes"
744
		fi
745
	    ;;
746
	    hash)
747
		params="$params -h $value"
748
		if [ -z "$value" ]; then
749
		    echo $"$dst: no value for hash option, skipping"
750
		    skip="yes"
751
		fi
752
	    ;;
753
	    verify)
754
	        params="$params -y"
755
	    ;;
756
	    swap)
757
		makeswap=yes
758
		;;
759
	    tmp)
760
		mke2fs=yes
761
	    esac
762
	done
763
	if [ "$skip" = "yes" ]; then
764
	    ret=1
765
	    continue
766
	fi
767
	if [ -z "$makeswap" ] && cryptsetup isLuks "$src" 2>/dev/null ; then
768
	    if key_is_random "$key"; then
769
		echo $"$dst: LUKS requires non-random key, skipping"
770
		ret=1
771
		continue
772
	    fi
773
	    if [ -n "$params" ]; then
774
		echo "$dst: options are invalid for LUKS partitions," \
775
		    "ignoring them"
776
	    fi
777
	    if [ -n "$key" ]; then
778
		/sbin/cryptsetup -d $key luksOpen "$src" "$dst" <&1 2>/dev/null && success || failure
779
		rc=$?
780
	    else
781
		mount_point="$(find_crypto_mount_point $dst)"
782
		[ -n "$mount_point" ] || mount_point=${src##*/}
783
		prompt=$(printf $"%s is password protected" "$mount_point")
784
		plymouth ask-for-password --prompt "$prompt" --command="/sbin/cryptsetup luksOpen -T1 $src $dst" <&1
785
		rc=$?
786
	    fi
787
	else
788
	    [ -z "$key" ] && plymouth --hide-splash
789
	    /sbin/cryptsetup $params ${key:+-d $key} create "$dst" "$src" <&1 2>/dev/null && success || failure
790
	    rc=$?
791
	    [ -z "$key" ] && plymouth --show-splash
792
	fi
793
	if [ $rc -ne 0 ]; then
794
	    ret=1
795
	    continue
796
	fi
797
	if [ -b "/dev/mapper/$dst" ]; then
798
	    if [ "$makeswap" = "yes" ]; then
799
		mkswap "/dev/mapper/$dst" 2>/dev/null >/dev/null
800
	    fi
801
	    if [ "$mke2fs" = "yes" ]; then
802
		if mke2fs "/dev/mapper/$dst" 2>/dev/null >/dev/null \
803
		    && mdir=$(mktemp -d /tmp/mountXXXXXX); then
804
		    mount "/dev/mapper/$dst" "$mdir" && chmod 1777 "$mdir"
805
		    umount "$mdir"
806
		    rmdir "$mdir"
807
		fi
808
	    fi
809
	fi
810
    done < /etc/crypttab
811
    return $ret
812
}
813
 
814
# A sed expression to filter out the files that is_ignored_file recognizes
815
__sed_discard_ignored_files='/\(~\|\.bak\|\.orig\|\.rpmnew\|\.rpmorig\|\.rpmsave\)$/d'