[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#267168: Successful cdrom-detect (w/ osamu fix)



tags 267168 patch
thanks

Since I posted many buggy codes :-( , I post the working one here.
(The bottom of BTS for cdrom-detect.)

This should solve most of cdrom-detect bug reports :-)

I reported success for Dell DMA case on 265636 using this patch.

Osamu

#! /bin/sh

set -e
. /usr/share/debconf/confmodule
#set -x

log() {
    logger -t cdrom-detect "$@"
}

fail () {
    log "$@"
    db_input critical cdrom-detect/failure || [ $? -eq 30 ]
    db_go
    # redundant but to be sure
    umount /cdrom 2>/dev/null || true
    exit 1
}

hw-detect cdrom-detect/detect_progress_title || true

maxmount=2	# max counts of the mounting tries
imount=0	# mount counter
mounted=0	# 0=initial, 1=detection in progress, 2=mounted
while true
do
    log "Searching for Debian installation media..."
    if [ ! -e /cdrom ] ; then
	mkdir /cdrom 2>/dev/null || true
    elif [ "$mounted" = "1" ]; then
	log "Cdrom device was detected but the mount failed."
	db_input critical cdrom-detect/retry || [ $? -eq 30 ]
	db_go
	db_get cdrom-detect/retry
	if [ "$RET" = "true" ]; then
	    mounted=0
	    continue
	else
	    fail "Retry of cdrom detect refused."
	fi
    elif [ -e /cdrom/.disk/info ] ; then
	log "Sanity check of CD before aproving mounted CD"
	CDNAME=`cat /cdrom/.disk/info`
	log "Detected CD '$CDNAME'"
        # Set the suite used by base-installer and base-config to
        # the suite that is on the CD from Release file.
	for distlink in stable testing unstable ; do
	    relfile=/cdrom/dists/$distlink/Release
	    if [ -e $relfile ] ; then
		suite=$(sed -n 's/^Suite: *//p' $relfile)
		log "Detected CD with '$suite' distribution"
		db_set mirror/suite $suite
		break
	    fi
	done
        # For DMA related mount errors. (RR extension)
	if [ "X" = "X${suite}" ]; then
	    log "Could not determine the package 'suite'. Is the cdrom OK?"
	    umount /cdrom 2>/dev/null || true
	    mounted=1
	    continue
	elif [ ! -e "/cdrom/dists/$suite/Release" ]; then
	    log "No such file '/cdrom/dists/$suite/Release'. Is the cdrom OK?"
	    umount /cdrom 2>/dev/null || true
	    mounted=1
	    continue
	fi
	log "Exit main loop after approving mounted CD."
	break

    elif mount | grep -q 'on /cdrom ' ; then
	log "The available CD is not a Debian CD!"
	umount /cdrom 2>/dev/null || true
	db_input critical cdrom-detect/wrong-cd || [ $? -eq 30 ]
	db_go
	imount=$((${imount}-1))
	mounted=0
	continue
    fi
    
    # Start detecting and mounting cdrom
    if [ "$imount" -ge "$maxmount" ] ; then
	fail "Tried to mount media $imount times and failed."
    fi
    imount=$((${imount}+1))
    log "Loop $imount out of $maxmount"
    mounted=1

    log "Try to detect a cdrom automatically by devfs."
    # This cdrom detection can be disabled by CDROM_DEVICES=none
    if [ -n "$CDROM_DEVICES" ]; then
	devices="$CDROM_DEVICES"
    elif [ -d /dev/cdroms ]; then
	devices=$(echo /dev/cdroms/*|grep -Fv '*' || true)
    else
	devices=""
    fi
    if [ -n "$devices" ] && [ "$devices" != "none" ]; then
	for device in $devices
	do
	    if mount -t iso9660 -o ro,exec $device /cdrom; then
		log "Cdrom-mount succeeded: device=$device"
		mounted=2
		db_set cdrom-detect/cdrom_device $device
		break # for device loop
	    else
		log "Cdrom-mount failed (error=$?): device=$device"
		umount /cdrom 2>/dev/null || true
		mounted=0
	    fi
	done
	continue
    fi
 
    log "Try to mount a driver floppy since no auto-cdrom device found."
    if [ -e /usr/lib/debian-installer/retriever/floppy-retriever ]; then
	db_input critical cdrom-detect/load_floppy
	db_go
	db_get cdrom-detect/load_floppy
	if [ "$RET" = true ]; then
	    anna floppy-retriever
	    hw-detect cdrom-detect/detect_progress_title || true
	    imount=$((${imount}-1))
	    mounted=2
	    continue
	fi
    fi
    
    log "Try to mount a cdrom on old non-devfs hardwares manually."
    db_input critical cdrom-detect/manual_config || [ $? -eq 30 ]
    db_go
    db_get cdrom-detect/manual_config

    modules=none
    for i in `ls -1 /lib/modules/*/kernel/drivers/cdrom/ | sed 's/\.ko$//' | sed 's/\.o$//'`
    do
	modules="$modules, $i"
    done
    
    if [ "$RET" = "true" ]; then
	db_subst cdrom-detect/cdrom_module choices "$modules"
	db_input critical cdrom-detect/cdrom_module || [ $? -eq 30 ]
	db_go

	db_get cdrom-detect/cdrom_module
	module="$RET"

	db_input critical cdrom-detect/cdrom_device || [ $? -eq 30 ]
	db_go

	db_get cdrom-detect/cdrom_device
	device="$RET"

	if [ "$module" != "none" ]; then
	    modprobe $module
	fi
	if mount -t iso9660 -o ro,exec $device /cdrom; then
	    log "Cdrom-mount succeeded: device=$device"
	    db_set cdrom-detect/cdrom_device $device
	    mounted=2
	    db_set cdrom-detect/cdrom_device $device
	else
	    log "Cdrom-mount failed (error=$?): device=$device"
	    umount /cdrom 2>/dev/null || true
	    imount=$((${imount}-1))
	    mounted=0
	fi
	continue
    fi
    fail "No media detected: auto-cdrom, floppy, manual-cdrom."
done


# Ask for eject to be installed into /target/, to be able to use it in
# the prebaseconfig script.
apt-install eject || true

# Hey, we're done
db_subst cdrom-detect/success cdname "$CDNAME"
db_input low cdrom-detect/success || [ $? -eq 30 ]
db_go

exit 0

Reply to: