Advertisement
Guest User

Untitled

a guest
Sep 18th, 2013
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.50 KB | None | 0 0
  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
  107. fstab-decode /sbin/fuser -k -m $sig $remaining >/dev/null
  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}
  151.  
  152. pid=
  153. if [ -f "$pid_file" ] ; then
  154. local line p
  155.  
  156. [ ! -r "$pid_file" ] && return 4 # "user had insufficient privilege"
  157. while : ; do
  158. read line
  159. [ -z "$line" ] && break
  160. for p in $line ; do
  161. [ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && pid="$pid $p"
  162. done
  163. done < "$pid_file"
  164.  
  165. if [ -n "$pid" ]; then
  166. return 0
  167. fi
  168. return 1 # "Program is dead and /var/run pid file exists"
  169. fi
  170. return 3 # "Program is not running"
  171. }
  172.  
  173. # Output PIDs of matching processes, found using pidof
  174. __pids_pidof() {
  175. pidof -c -o $$ -o $PPID -o %PPID -x "$1" || \
  176. pidof -c -o $$ -o $PPID -o %PPID -x "${1##*/}"
  177. }
  178.  
  179.  
  180. # A function to start a program.
  181. daemon() {
  182. # Test syntax.
  183. local gotbase= force= nicelevel corelimit
  184. local pid base= user= nice= bg= pid_file=
  185. local cgroup=
  186. nicelevel=0
  187. while [ "$1" != "${1##[-+]}" ]; do
  188. case $1 in
  189. '') echo $"$0: Usage: daemon [+/-nicelevel] {program}"
  190. return 1;;
  191. --check)
  192. base=$2
  193. gotbase="yes"
  194. shift 2
  195. ;;
  196. --check=?*)
  197. base=${1#--check=}
  198. gotbase="yes"
  199. shift
  200. ;;
  201. --user)
  202. user=$2
  203. shift 2
  204. ;;
  205. --user=?*)
  206. user=${1#--user=}
  207. shift
  208. ;;
  209. --pidfile)
  210. pid_file=$2
  211. shift 2
  212. ;;
  213. --pidfile=?*)
  214. pid_file=${1#--pidfile=}
  215. shift
  216. ;;
  217. --force)
  218. force="force"
  219. shift
  220. ;;
  221. [-+][0-9]*)
  222. nice="nice -n $1"
  223. shift
  224. ;;
  225. *) echo $"$0: Usage: daemon [+/-nicelevel] {program}"
  226. return 1;;
  227. esac
  228. done
  229.  
  230. # Save basename.
  231. [ -z "$gotbase" ] && base=${1##*/}
  232.  
  233. # See if it's already running. Look *only* at the pid file.
  234. __pids_var_run "$base" "$pid_file"
  235.  
  236. [ -n "$pid" -a -z "$force" ] && return
  237.  
  238. # make sure it doesn't core dump anywhere unless requested
  239. corelimit="ulimit -S -c ${DAEMON_COREFILE_LIMIT:-0}"
  240.  
  241. # if they set NICELEVEL in /etc/sysconfig/foo, honor it
  242. [ -n "${NICELEVEL:-}" ] && nice="nice -n $NICELEVEL"
  243.  
  244. # if they set CGROUP_DAEMON in /etc/sysconfig/foo, honor it
  245. if [ -n "${CGROUP_DAEMON}" ]; then
  246. if [ ! -x /bin/cgexec ]; then
  247. echo -n "Cgroups not installed"; warning
  248. echo
  249. else
  250. cgroup="/bin/cgexec";
  251. for i in $CGROUP_DAEMON; do
  252. cgroup="$cgroup -g $i";
  253. done
  254. fi
  255. fi
  256.  
  257. # Echo daemon
  258. [ "${BOOTUP:-}" = "verbose" -a -z "${LSB:-}" ] && echo -n " $base"
  259.  
  260. # And start it up.
  261. if [ -z "$user" ]; then
  262. $cgroup $nice /bin/bash -c "$corelimit >/dev/null 2>&1 ; $*"
  263. else
  264. $cgroup $nice runuser -s /bin/bash $user -c "$corelimit >/dev/null 2>&1 ; $*"
  265. fi
  266.  
  267. [ "$?" -eq 0 ] && success $"$base startup" || failure $"$base startup"
  268. }
  269.  
  270. # A function to stop a program.
  271. killproc() {
  272. local RC killlevel= base pid pid_file= delay
  273.  
  274. RC=0; delay=3
  275. # Test syntax.
  276. if [ "$#" -eq 0 ]; then
  277. echo $"Usage: killproc [-p pidfile] [ -d delay] {program} [-signal]"
  278. return 1
  279. fi
  280. if [ "$1" = "-p" ]; then
  281. pid_file=$2
  282. shift 2
  283. fi
  284. if [ "$1" = "-d" ]; then
  285. delay=$2
  286. shift 2
  287. fi
  288.  
  289.  
  290. # check for second arg to be kill level
  291. [ -n "${2:-}" ] && killlevel=$2
  292.  
  293. # Save basename.
  294. base=${1##*/}
  295.  
  296. # Find pid.
  297. __pids_var_run "$1" "$pid_file"
  298. RC=$?
  299. if [ -z "$pid" ]; then
  300. if [ -z "$pid_file" ]; then
  301. pid="$(__pids_pidof "$1")"
  302. else
  303. [ "$RC" = "4" ] && { failure $"$base shutdown" ; return $RC ;}
  304. fi
  305. fi
  306.  
  307. # Kill it.
  308. if [ -n "$pid" ] ; then
  309. [ "$BOOTUP" = "verbose" -a -z "${LSB:-}" ] && echo -n "$base "
  310. if [ -z "$killlevel" ] ; then
  311. if checkpid $pid 2>&1; then
  312. # TERM first, then KILL if not dead
  313. kill -TERM $pid >/dev/null 2>&1
  314. usleep 100000
  315. if checkpid $pid && sleep 1 &&
  316. checkpid $pid && sleep $delay &&
  317. checkpid $pid ; then
  318. kill -KILL $pid >/dev/null 2>&1
  319. usleep 100000
  320. fi
  321. fi
  322. checkpid $pid
  323. RC=$?
  324. [ "$RC" -eq 0 ] && failure $"$base shutdown" || success $"$base shutdown"
  325. RC=$((! $RC))
  326. # use specified level only
  327. else
  328. if checkpid $pid; then
  329. kill $killlevel $pid >/dev/null 2>&1
  330. RC=$?
  331. [ "$RC" -eq 0 ] && success $"$base $killlevel" || failure $"$base $killlevel"
  332. elif [ -n "${LSB:-}" ]; then
  333. RC=7 # Program is not running
  334. fi
  335. fi
  336. else
  337. if [ -n "${LSB:-}" -a -n "$killlevel" ]; then
  338. RC=7 # Program is not running
  339. else
  340. failure $"$base shutdown"
  341. RC=0
  342. fi
  343. fi
  344.  
  345. # Remove pid file if any.
  346. if [ -z "$killlevel" ]; then
  347. rm -f "${pid_file:-/var/run/$base.pid}"
  348. fi
  349. return $RC
  350. }
  351.  
  352. # A function to find the pid of a program. Looks *only* at the pidfile
  353. pidfileofproc() {
  354. local pid
  355.  
  356. # Test syntax.
  357. if [ "$#" = 0 ] ; then
  358. echo $"Usage: pidfileofproc {program}"
  359. return 1
  360. fi
  361.  
  362. __pids_var_run "$1"
  363. [ -n "$pid" ] && echo $pid
  364. return 0
  365. }
  366.  
  367. # A function to find the pid of a program.
  368. pidofproc() {
  369. local RC pid pid_file=
  370.  
  371. # Test syntax.
  372. if [ "$#" = 0 ]; then
  373. echo $"Usage: pidofproc [-p pidfile] {program}"
  374. return 1
  375. fi
  376. if [ "$1" = "-p" ]; then
  377. pid_file=$2
  378. shift 2
  379. fi
  380. fail_code=3 # "Program is not running"
  381.  
  382. # First try "/var/run/*.pid" files
  383. __pids_var_run "$1" "$pid_file"
  384. RC=$?
  385. if [ -n "$pid" ]; then
  386. echo $pid
  387. return 0
  388. fi
  389.  
  390. [ -n "$pid_file" ] && return $RC
  391. __pids_pidof "$1" || return $RC
  392. }
  393.  
  394. status() {
  395. local base pid lock_file= pid_file=
  396.  
  397. # Test syntax.
  398. if [ "$#" = 0 ] ; then
  399. echo $"Usage: status [-p pidfile] {program}"
  400. return 1
  401. fi
  402. if [ "$1" = "-p" ]; then
  403. pid_file=$2
  404. shift 2
  405. fi
  406. if [ "$1" = "-l" ]; then
  407. lock_file=$2
  408. shift 2
  409. fi
  410. base=${1##*/}
  411.  
  412. # First try "pidof"
  413. __pids_var_run "$1" "$pid_file"
  414. RC=$?
  415. if [ -z "$pid_file" -a -z "$pid" ]; then
  416. pid="$(__pids_pidof "$1")"
  417. fi
  418. if [ -n "$pid" ]; then
  419. echo $"${base} (pid $pid) is running..."
  420. return 0
  421. fi
  422.  
  423. case "$RC" in
  424. 0)
  425. echo $"${base} (pid $pid) is running..."
  426. return 0
  427. ;;
  428. 1)
  429. echo $"${base} dead but pid file exists"
  430. return 1
  431. ;;
  432. 4)
  433. echo $"${base} status unknown due to insufficient privileges."
  434. return 4
  435. ;;
  436. esac
  437. if [ -z "${lock_file}" ]; then
  438. lock_file=${base}
  439. fi
  440. # See if /var/lock/subsys/${lock_file} exists
  441. if [ -f /var/lock/subsys/${lock_file} ]; then
  442. echo $"${base} dead but subsys locked"
  443. return 2
  444. fi
  445. echo $"${base} is stopped"
  446. return 3
  447. }
  448.  
  449. echo_success() {
  450. [ "$BOOTUP" = "color" ] && $MOVE_TO_COL
  451. echo -n "["
  452. [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS
  453. echo -n $" OK "
  454. [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
  455. echo -n "]"
  456. echo -ne "\r"
  457. return 0
  458. }
  459.  
  460. echo_failure() {
  461. [ "$BOOTUP" = "color" ] && $MOVE_TO_COL
  462. echo -n "["
  463. [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
  464. echo -n $"FAILED"
  465. [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
  466. echo -n "]"
  467. echo -ne "\r"
  468. return 1
  469. }
  470.  
  471. echo_passed() {
  472. [ "$BOOTUP" = "color" ] && $MOVE_TO_COL
  473. echo -n "["
  474. [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
  475. echo -n $"PASSED"
  476. [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
  477. echo -n "]"
  478. echo -ne "\r"
  479. return 1
  480. }
  481.  
  482. echo_warning() {
  483. [ "$BOOTUP" = "color" ] && $MOVE_TO_COL
  484. echo -n "["
  485. [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
  486. echo -n $"WARNING"
  487. [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
  488. echo -n "]"
  489. echo -ne "\r"
  490. return 1
  491. }
  492.  
  493. # Inform the graphical boot of our current state
  494. update_boot_stage() {
  495. if [ -x /bin/plymouth ]; then
  496. /bin/plymouth --update="$1"
  497. fi
  498. return 0
  499. }
  500.  
  501. # Log that something succeeded
  502. success() {
  503. [ "$BOOTUP" != "verbose" -a -z "${LSB:-}" ] && echo_success
  504. return 0
  505. }
  506.  
  507. # Log that something failed
  508. failure() {
  509. local rc=$?
  510. [ "$BOOTUP" != "verbose" -a -z "${LSB:-}" ] && echo_failure
  511. [ -x /bin/plymouth ] && /bin/plymouth --details
  512. return $rc
  513. }
  514.  
  515. # Log that something passed, but may have had errors. Useful for fsck
  516. passed() {
  517. local rc=$?
  518. [ "$BOOTUP" != "verbose" -a -z "${LSB:-}" ] && echo_passed
  519. return $rc
  520. }
  521.  
  522. # Log a warning
  523. warning() {
  524. local rc=$?
  525. [ "$BOOTUP" != "verbose" -a -z "${LSB:-}" ] && echo_warning
  526. return $rc
  527. }
  528.  
  529. # Run some action. Log its output.
  530. action() {
  531. local STRING rc
  532.  
  533. STRING=$1
  534. echo -n "$STRING "
  535. shift
  536. "$@" && success $"$STRING" || failure $"$STRING"
  537. rc=$?
  538. echo
  539. return $rc
  540. }
  541.  
  542. # returns OK if $1 contains $2
  543. strstr() {
  544. [ "${1#*$2*}" = "$1" ] && return 1
  545. return 0
  546. }
  547.  
  548. # Confirm whether we really want to run this service
  549. confirm() {
  550. [ -x /bin/plymouth ] && /bin/plymouth --hide-splash
  551. while : ; do
  552. echo -n $"Start service $1 (Y)es/(N)o/(C)ontinue? [Y] "
  553. read answer
  554. if strstr $"yY" "$answer" || [ "$answer" = "" ] ; then
  555. return 0
  556. elif strstr $"cC" "$answer" ; then
  557. rm -f /var/run/confirm
  558. [ -x /bin/plymouth ] && /bin/plymouth --show-splash
  559. return 2
  560. elif strstr $"nN" "$answer" ; then
  561. return 1
  562. fi
  563. done
  564. }
  565.  
  566. # resolve a device node to its major:minor numbers in decimal or hex
  567. get_numeric_dev() {
  568. (
  569. fmt="%d:%d"
  570. if [ "$1" == "hex" ]; then
  571. fmt="%x:%x"
  572. fi
  573. ls -lH "$2" | awk '{ sub(/,/, "", $5); printf("'"$fmt"'", $5, $6); }'
  574. ) 2>/dev/null
  575. }
  576.  
  577. # Check whether file $1 is a backup or rpm-generated file and should be ignored
  578. is_ignored_file() {
  579. case "$1" in
  580. *~ | *.bak | *.orig | *.rpmnew | *.rpmorig | *.rpmsave)
  581. return 0
  582. ;;
  583. esac
  584. return 1
  585. }
  586.  
  587. # Evaluate shvar-style booleans
  588. is_true() {
  589. case "$1" in
  590. [tT] | [yY] | [yY][eE][sS] | [tT][rR][uU][eE])
  591. return 0
  592. ;;
  593. esac
  594. return 1
  595. }
  596.  
  597. # Evaluate shvar-style booleans
  598. is_false() {
  599. case "$1" in
  600. [fF] | [nN] | [nN][oO] | [fF][aA][lL][sS][eE])
  601. return 0
  602. ;;
  603. esac
  604. return 1
  605. }
  606.  
  607. # Apply sysctl settings, including files in /etc/sysctl.d
  608. apply_sysctl() {
  609. sysctl -e -p /etc/sysctl.conf >/dev/null 2>&1
  610. for file in /etc/sysctl.d/* ; do
  611. is_ignored_file "$file" && continue
  612. test -f "$file" && sysctl -e -p "$file" >/dev/null 2>&1
  613. done
  614. }
  615.  
  616. key_is_random() {
  617. [ "$1" = "/dev/urandom" -o "$1" = "/dev/hw_random" \
  618. -o "$1" = "/dev/random" ]
  619. }
  620.  
  621. find_crypto_mount_point() {
  622. local fs_spec fs_file fs_vfstype remaining_fields
  623. local fs
  624. while read fs_spec fs_file remaining_fields; do
  625. if [ "$fs_spec" = "/dev/mapper/$1" ]; then
  626. echo $fs_file
  627. break;
  628. fi
  629. done < /etc/fstab
  630. }
  631.  
  632. # Because of a chicken/egg problem, init_crypto must be run twice. /var may be
  633. # encrypted but /var/lib/random-seed is needed to initialize swap.
  634. init_crypto() {
  635. local have_random dst src key opt mode owner params makeswap skip arg opt
  636. local param value rc ret mke2fs mdir prompt mount_point
  637.  
  638. ret=0
  639. have_random=$1
  640. while read dst src key opt; do
  641. [ -z "$dst" -o "${dst#\#}" != "$dst" ] && continue
  642. [ -b "/dev/mapper/$dst" ] && continue;
  643. if [ "$have_random" = 0 ] && key_is_random "$key"; then
  644. continue
  645. fi
  646. if [ -n "$key" -a "x$key" != "xnone" ]; then
  647. if test -e "$key" ; then
  648. owner=$(ls -l $key | (read a b owner rest; echo $owner))
  649. if ! key_is_random "$key"; then
  650. mode=$(ls -l "$key" | cut -c 5-10)
  651. if [ "$mode" != "------" ]; then
  652. echo $"INSECURE MODE FOR $key"
  653. fi
  654. fi
  655. if [ "$owner" != root ]; then
  656. echo $"INSECURE OWNER FOR $key"
  657. fi
  658. else
  659. echo $"Key file for $dst not found, skipping"
  660. ret=1
  661. continue
  662. fi
  663. else
  664. key=""
  665. fi
  666. params=""
  667. makeswap=""
  668. mke2fs=""
  669. skip=""
  670. # Parse the src field for UUID= and convert to real device names
  671. if [ "${src%%=*}" == "UUID" ]; then
  672. src=$(/sbin/blkid -t "$src" -l -o device)
  673. elif [ "${src/^\/dev\/disk\/by-uuid\/}" != "$src" ]; then
  674. src=$(__readlink $src)
  675. fi
  676. # Is it a block device?
  677. [ -b "$src" ] || continue
  678. # Is it already a device mapper slave? (this is gross)
  679. devesc=${src##/dev/}
  680. devesc=${devesc//\//!}
  681. for d in /sys/block/dm-*/slaves ; do
  682. [ -e $d/$devesc ] && continue 2
  683. done
  684. # Parse the options field, convert to cryptsetup parameters and
  685. # contruct the command line
  686. while [ -n "$opt" ]; do
  687. arg=${opt%%,*}
  688. opt=${opt##$arg}
  689. opt=${opt##,}
  690. param=${arg%%=*}
  691. value=${arg##$param=}
  692.  
  693. case "$param" in
  694. cipher)
  695. params="$params -c $value"
  696. if [ -z "$value" ]; then
  697. echo $"$dst: no value for cipher option, skipping"
  698. skip="yes"
  699. fi
  700. ;;
  701. size)
  702. params="$params -s $value"
  703. if [ -z "$value" ]; then
  704. echo $"$dst: no value for size option, skipping"
  705. skip="yes"
  706. fi
  707. ;;
  708. hash)
  709. params="$params -h $value"
  710. if [ -z "$value" ]; then
  711. echo $"$dst: no value for hash option, skipping"
  712. skip="yes"
  713. fi
  714. ;;
  715. verify)
  716. params="$params -y"
  717. ;;
  718. swap)
  719. makeswap=yes
  720. ;;
  721. tmp)
  722. mke2fs=yes
  723. esac
  724. done
  725. if [ "$skip" = "yes" ]; then
  726. ret=1
  727. continue
  728. fi
  729. if [ -z "$makeswap" ] && cryptsetup isLuks "$src" 2>/dev/null ; then
  730. if key_is_random "$key"; then
  731. echo $"$dst: LUKS requires non-random key, skipping"
  732. ret=1
  733. continue
  734. fi
  735. if [ -n "$params" ]; then
  736. echo "$dst: options are invalid for LUKS partitions," \
  737. "ignoring them"
  738. fi
  739. if [ -n "$key" ]; then
  740. /sbin/cryptsetup -d $key luksOpen "$src" "$dst" <&1 2>/dev/null && success || failure
  741. rc=$?
  742. else
  743. mount_point="$(find_crypto_mount_point $dst)"
  744. [ -n "$mount_point" ] || mount_point=${src##*/}
  745. prompt=$(printf $"%s is password protected" "$mount_point")
  746. plymouth ask-for-password --prompt "$prompt" --command="/sbin/cryptsetup luksOpen -T1 $src $dst" <&1
  747. rc=$?
  748. fi
  749. else
  750. [ -z "$key" ] && plymouth --hide-splash
  751. /sbin/cryptsetup $params ${key:+-d $key} create "$dst" "$src" <&1 2>/dev/null && success || failure
  752. rc=$?
  753. [ -z "$key" ] && plymouth --show-splash
  754. fi
  755. if [ $rc -ne 0 ]; then
  756. ret=1
  757. continue
  758. fi
  759. if [ -b "/dev/mapper/$dst" ]; then
  760. if [ "$makeswap" = "yes" ]; then
  761. mkswap "/dev/mapper/$dst" 2>/dev/null >/dev/null
  762. fi
  763. if [ "$mke2fs" = "yes" ]; then
  764. if mke2fs "/dev/mapper/$dst" 2>/dev/null >/dev/null \
  765. && mdir=$(mktemp -d /tmp/mountXXXXXX); then
  766. mount "/dev/mapper/$dst" "$mdir" && chmod 1777 "$mdir"
  767. umount "$mdir"
  768. rmdir "$mdir"
  769. fi
  770. fi
  771. fi
  772. done < /etc/crypttab
  773. return $ret
  774. }
  775.  
  776. # A sed expression to filter out the files that is_ignored_file recognizes
  777. __sed_discard_ignored_files='/\(~\|\.bak\|\.orig\|\.rpmnew\|\.rpmorig\|\.rpmsave\)$/d'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement