12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- # shellcheck shell=sh
- : "${CRYPTTAB:=/etc/crypttab}"
- command -v cryptsetup && [ -f "${CRYPTTAB}" ] || return
- msg 'decrypting devices from crypttab'
- exec 4<&0; while read -r name dev pass opts err; do
- [ "${name##\#*}" ] || continue
- [ "${err}" ] && {
- error 'invalid crypttab file'
- break
- }
- copts=''
- _dev="$(findfs "${dev}")" || {
- error 'unable to resolve' "'${dev}'"
- continue
- }
- dev="${_dev}"
- # shellcheck disable=2086
- { IFS=,; set -- ${opts}; unset IFS; }
- for opt; do case "${opt}" in
- readonly|read-only) copts="${copts} -r" ;;
- header=*) copts="${copts} --${opt}" ;;
- tries=*) copts="${copts} -T ${opt##*=}" ;;
- discard) copts="${copts} --allow-discards" ;;
- noauto) copts=; continue 2 ;;
- esac; done
- initprint ' %b*%b decrypting%b "%s"...' \
- "${__b}${__cya}" "${__blu}" "${__clr}" "${dev}"
- # shellcheck disable=2086
- case "${pass}" in
- none|-|'')
- cryptsetup open ${copts} "${dev}" "${name}" <&4
- ;;
- *)
- cryptsetup open ${copts} -d "${pass}" "${dev}" "${name}"
- ;;
- esac && ok || failed
- done < "${CRYPTTAB}"; exec 4>&-
|