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

Loading…
Cancel
Save