# /lib/rcscripts/addons/dm-crypt-start.sh # Copyright 1999-2005 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: /var/cvsroot/gentoo-x86/sys-fs/cryptsetup/files/dm-crypt-start.sh,v 1.6 2006/04/12 02:52:43 vapier Exp $ # Setup mappings for an individual mount/swap # # Note: This relies on variables localized in the main body below. dm-crypt-execute-checkfs() { local dev target ret if [[ -n ${loop_file} ]] ; then dev="/dev/mapper/${target}" ebegin " Setting up loop device ${source}" /sbin/losetup ${source} ${loop_file} fi if [[ -n ${mount} ]] ; then target=${mount} : ${options:='-c aes -h sha1'} [[ -n ${key} ]] && : ${gpg_options:='-q -d'} elif [[ -n ${swap} ]] ; then target=${swap} : ${options:='-c aes -h sha1 -d /dev/urandom'} : ${pre_mount:='mkswap ${dev}'} else return fi if /bin/cryptsetup status ${target} | egrep -q '\/dev/console /dev/null ; then ret=1 while [[ ${ret} -gt 0 ]] ; do keystring=$(gpg ${gpg_options} ${key} 2>/dev/null /dev/null ewend $? || cryptfs_status=1 fi fi } # Run any post_mount commands for an individual mount # # Note: This relies on variables localized in the main body below. dm-crypt-execute-localmount() { local mount_point target if [[ -n ${mount} && -n ${post_mount} ]] ; then target=${mount} else return fi if ! /bin/cryptsetup status ${target} | egrep -q '\/dev/null eend $? || cryptfs_status=1 fi } local cryptfs_status=0 local gpg_options key loop_file mount mountline options pre_mount post_mount source swap if [[ -f /etc/conf.d/cryptfs ]] && [[ -x /bin/cryptsetup ]] ; then ebegin "Setting up dm-crypt mappings" while read mountline ; do # skip comments and blank lines [[ ${mountline}\# == \#* ]] && continue # check for the start of a new mount/swap case ${mountline} in mount=*|swap=*) # If we have a mount queued up, then execute it dm-crypt-execute-${myservice} # Prepare for the next mount/swap by resetting variables unset gpg_options key loop_file mount options pre_mount post_mount source swap ;; gpg_options=*|key=*|loop_file=*|options=*|pre_mount=*|post_mount=*|source=*) if [[ -z ${mount} && -z ${swap} ]] ; then ewarn "Ignoring setting outside mount/swap section: ${mountline}" continue fi ;; *) ewarn "Skipping invalid line in /etc/conf.d/cryptfs: ${mountline}" ;; esac # Queue this setting for the next call to dm-crypt-execute-${myservice} eval "${mountline}" done < /etc/conf.d/cryptfs # If we have a mount queued up, then execute it dm-crypt-execute-${myservice} ewend ${cryptfs_status} "Failed to setup dm-crypt devices" fi # vim:ts=4