File: cdrom-detect.postinst

package info (click to toggle)
cdrom-detect 1.20etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 688 kB
  • ctags: 6
  • sloc: sh: 158; makefile: 39
file content (184 lines) | stat: -rwxr-xr-x 4,653 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#! /bin/sh

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

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

fail () {
	log "CDROM-detect failed; unmounting CD just to be sure"
	umount /cdrom 2>/dev/null || true
	exit 1
}

# Is a cdrom already mounted?  If so, assume it's the right one..
mount | grep -q 'on /cdrom' && exit 0
if [ -e /cdrom/.disk/info ] ; then
	CDNAME=`cat /cdrom/.disk/info`
	log "Detected CD '$CDNAME'"
	exit 0
fi

hw-detect cdrom-detect/detect_progress_title || true

log "Searching for Debian installation media..."

mkdir /cdrom 2>/dev/null || true

while true
do
	mounted=0

	devices="$(list-devices cd; list-devices maybe-usb-floppy)"
	for device in $devices; do
		if mount -t iso9660 -o ro,exec $device /cdrom; then
			log "CD-ROM mount succeeded: device=$device"
			mounted=1
			db_set cdrom-detect/cdrom_device $device
			break
		else
			log "CD-ROM mount failed: device=$device"
		fi
	done

	if [ "$mounted" = "1" ]; then
		break
	fi

	# If a device was detected but the mount failed, ask for the CD.
	if [ -n "$devices" ]; then
		db_input critical cdrom-detect/retry || [ $? -eq 30 ]
		db_go
		db_get cdrom-detect/retry
		if [ "$RET" = "true" ]; then
			log "Unmounting CD just to be sure"
			umount /cdrom 2>/dev/null || true
			continue
		else
			fail
		fi
	fi
 
	# If no device was detected, perhaps a driver floppy is needed.
	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
			continue
		fi
	fi
    
	# Otherwise manual configuration may be needed
	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 "CD-ROM mount succeeded: device=$device"
			mounted=1
			break
		else
			log "CD-ROM mount failed: device=$device"
			fail
		fi
	else
		fail
	fi
done

if [ -e /cdrom/.disk/info ] ; then
	CDNAME=`cat /cdrom/.disk/info`
	log "Detected CD '$CDNAME'"
else
	log "The available CD is not a Debian CD!"
	db_input critical cdrom-detect/wrong-cd || [ $? -eq 30 ]
	db_go
	fail 
fi

# Get all the pool directories into the dentry cache, to cut down on seek
# times.
poolcount="$(set -- /cdrom/pool/*/*; echo $#)"
db_progress START 0 "$poolcount" cdrom-detect/scanning_progress_title
for pooldir in /cdrom/pool/*/*; do
	if [ -d "$pooldir" ]; then
		db_subst cdrom-detect/scanning_progress_step DIR "$pooldir"
		db_progress INFO cdrom-detect/scanning_progress_step
		log-output --pass-stdout -t cdrom-detect find "$pooldir/" >/dev/null || true
	fi
	db_progress STEP 1
done
db_progress STOP

# Set the suite and codename used by base-installer and base-config
# to the suite/codename that is on the CD. This assumes that there
# will be no more than one distribution on the CD, and that one of
# the testing, stable, or unstable links will point to it. Since the
# CDs currently have many links, parse the Release file to get the
# actual suite name to use.
for distlink in stable testing unstable ; do
	relfile=/cdrom/dists/$distlink/Release
	if [ -e $relfile ] ; then
		suite=$(sed -n 's/^Suite: *//p' $relfile)
		codename=$(sed -n 's/^Codename: *//p' $relfile)
		log "Detected CD with '$suite' ($codename) distribution"
		db_set cdrom/suite $suite
		db_set cdrom/codename $codename

		break
	fi
done

if [ -z "$suite" ] ; then
	log "Error reading Release file; unable to determine distribution"
	db_input critical cdrom-detect/no-release || [ $? -eq 30 ]
	db_go
	fail
fi

# Ask for eject to be installed into /target/, to be able to use it in
# the finish-install 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

anna-install apt-mirror-setup || true
if [ ! -e /cdrom/.disk/base_installable ]; then
	log "Base system not installable from CD, requesting choose-mirror"
	anna-install choose-mirror || true
else
	anna-install apt-cdrom-setup || true
fi

exit 0