initrd.scripts: refactor findmediamount and rename to media_find()

master
Fabio Erculiani 12 years ago
parent 90b81e9f4b
commit 6b8bde737d

@ -24,79 +24,67 @@ real_root_init() {
zfs_real_root_init
}
findmediamount() {
media_find() {
# $1 = mount dir name / media name
# $2 = recognition file
# $3 = variable to have the device path
# $4 = actual mount dir path (full path)
# args remaining are possible devices
local media=$1 recon=$2 vrbl=$3 mntdir=$4
local media="${1}" recon="${2}" vrbl="${3}" mntdir="${4}"
shift 4
good_msg "Looking for the ${media}" ${CRYPT_SILENT}
if [ "$#" -gt "0" ]
then
[ ! -d "${mntdir}" ] && mkdir -p ${mntdir} 2>/dev/null >/dev/null
if [ -n "${ISOBOOT}" ]
then
if [ "$#" -gt "0" ]; then
[ ! -d "${mntdir}" ] && \
mkdir -p "${mntdir}" 2>/dev/null >/dev/null
local mntcddir="${mntdir}"
if [ -n "${ISOBOOT}" ]; then
mntcddir="${mntdir%${media}}iso"
if [ ! -f ${mntcddir} ]
then
mkdir ${mntcddir}
if [ ! -f "${mntcddir}" ]; then
mkdir "${mntcddir}"
fi
else
mntcddir=${mntdir}
fi
for x in $*
do
for x in ${*}; do
# Check for a block device to mount
if [ -b "${x}" ]
then
skip=0
bsn=$(basename "${x}")
#
# If disk and it has at least one partition, skip.
# We use /sys/block/${bsn}/${bsn}[0-9]* to make sure that we
# don't skip device mapper devices. Even the craziest scenario
# deserves a fair chance.
#
for part in $(ls /sys/block/${bsn}/${bsn}*[0-9]* 2>/dev/null)
do
skip=1
break;
done
if [ ${skip} -eq 1 ]
then
continue
fi
good_msg "Attempting to mount media: ${x}" ${CRYPT_SILENT}
if [ ! -b "${x}" ]; then
continue
fi
mount -r -t ${CDROOT_TYPE} ${x} ${mntcddir} >/dev/null 2>&1
if [ "$?" = '0' ]
then
if [ -n "${ISOBOOT}" ]; then
if [ -f ${mntcddir}/${ISOBOOT} ]; then
mount -o loop ${mntcddir}/${ISOBOOT} ${mntdir}
if [ "$?" = "0" ]; then
good_msg "iso mounted on ${mntdir}"
fi
fi
fi
#
# If disk and it has at least one partition, skip.
# We use /sys/block/${bsn}/${bsn}[0-9]* to make sure that we
# don't skip device mapper devices. Even the craziest scenario
# deserves a fair chance.
#
local bsn=$(basename "${x}")
local bpath="/sys/block/${bsn}"
local parts=$(find "${bpath}/" \
-regex "${bpath}/${bsn}[0-9]" -type d 2>/dev/null)
[ -n "${parts}" ] && continue
good_msg "Attempting to mount media: ${x}" ${CRYPT_SILENT}
mount -r -t "${CDROOT_TYPE}" "${x}" "${mntcddir}" >/dev/null 2>&1 \
|| continue
if [ -n "${ISOBOOT}" ] && [ -f "${mntcddir}/${ISOBOOT}" ]; then
mount -o loop "${mntcddir}/${ISOBOOT}" "${mntdir}" && \
good_msg "iso mounted on ${mntdir}"
fi
# Check for the media
if [ -f "${mntdir}/${recon}" ]
then
#set REAL_ROOT, CRYPT_ROOT_KEYDEV or whatever ${vrbl} is
eval ${vrbl}'='"${x}"
good_msg "Media found on ${x}" ${CRYPT_SILENT}
break
else
umount ${mntcddir}
fi
fi
# Check for the media
if [ -f "${mntdir}/${recon}" ]; then
# Set REAL_ROOT, CRYPT_ROOT_KEYDEV or whatever ${vrbl} is
eval ${vrbl}'='"${x}"
good_msg "Media found on ${x}" ${CRYPT_SILENT}
break
else
umount "${mntcddir}"
fi
done
fi
@ -140,7 +128,7 @@ bootstrap_cd() {
[ -n "${CDROOT_DEV}" ] && DEVICES="${CDROOT_DEV}"
[ -z "${CDROOT_DEV}" ] && DEVICES=$(devicelist)
findmediamount "cdrom" "${SUBDIR}/${CDROOT_MARKER}" \
media_find "cdrom" "${SUBDIR}/${CDROOT_MARKER}" \
"REAL_ROOT" "${CDROOT_PATH}" ${DEVICES}
}
@ -149,7 +137,7 @@ bootstrap_key() {
local KEYDEVS=$(devicelist)
eval local keyloc='"${CRYPT_'${1}'_KEY}"'
findmediamount "key" "${keyloc}" "CRYPT_${1}_KEYDEV" "/mnt/key" ${KEYDEVS}
media_find "key" "${keyloc}" "CRYPT_${1}_KEYDEV" "/mnt/key" ${KEYDEVS}
}
cache_cd_contents() {

Loading…
Cancel
Save