~ubuntu-installer/wubi/hardy

316 by ago
Added preliminary workarounds via override_files to be able to complete
1
#! /bin/sh
2
3
. /lib/partman/definitions.sh
4
. /lib/partman/resize.sh
5
. /lib/partman/recipes.sh
6
set -x
7
# busybox wants mount -o move; util-linux wants mount --move. Sigh.
8
if [ -d /lib/debian-installer ]; then
9
	mount_move='-o move'
10
else
11
	mount_move='--move'
12
fi
13
14
modprobe loop >/dev/null 2>&1 || true
15
16
# Set up working directory.
17
18
if type mktemp >/dev/null 2>&1; then
19
	recipe_dir="$(mktemp -d /tmp/partman-auto-loop.XXXXXX)"
20
	trap "rm -rf $recipe_dir" EXIT HUP INT QUIT TERM
21
else
22
	recipe_dir=/tmp
23
fi
24
25
# Fetch parameters.
26
27
disk="$1"
28
29
cd $disk
30
31
if ! db_get partman-auto-loop/partition || [ -z "$RET" ]; then
32
	logger -t partman-auto-loop "Error: No partition number specified in partman-auto-loop/partition"
33
	exit 1
34
fi
35
partition="$RET"
36
37
if ! db_get partman-auto-loop/recipe || [ -z "$RET" ]; then
38
	logger -t partman-auto-loop "Error: No recipe specified in partman-auto-loop/recipe"
39
	exit 1
40
fi
41
recipe="$RET"
42
echo "$recipe" >"$recipe_dir/loop_recipe"
43
44
# Find the requested partition.
45
46
db_progress START 0 5 partman-auto/text/automatically_partition
47
db_progress INFO partman-auto/progress/info
48
49
partition_id=
50
partition_fs=
51
open_dialog PARTITIONS
52
while { read_line num id size type fs path name; [ "$id" ]; }; do
53
	if [ "$num" = "$partition" ]; then
54
		partition_id="$id"
55
		partition_fs="$fs"
56
		# go ahead and read all remaining input
57
	fi
58
done
59
close_dialog
60
if [ -z "$partition_id" ]; then
61
	logger -t partman-auto-loop "Error: Partition number $partition not found in $disk"
62
	exit 1
63
fi
64
65
# Set up the requested partition in partman.
66
67
existing=no
68
for j in $(
69
	for i in /lib/partman/valid_filesystems/*; do
70
		[ -x $i ] || continue
71
		$i $disk $partition_id existing
72
	done
73
); do
74
	if [ "$j" = "$partition_fs" ]; then
75
		existing=yes
76
	fi
77
done
78
79
if [ "$existing" = no ]; then
80
	logger -t partman-auto-loop "Error: No filesystem on $disk/$partition_id"
81
	exit 1
82
fi
83
84
echo keep >$partition_id/method
85
rm -f $partition_id/format
86
>$partition_id/use_filesystem
87
echo $partition_fs >$partition_id/filesystem
88
mkdir -p $partition_id/options
89
echo / >$partition_id/mountpoint
90
update_partition $disk $partition_id
91
92
# Is there enough space to perform the recipe?
93
94
dev="$disk"
95
oldid="$partition_id"
96
383 by ago
Changed version to 8.04
97
#skip resize_range check since images are already created
98
#cursize=10000000000
99
#minsize=0
100
#if false; then 
316 by ago
Added preliminary workarounds via override_files to be able to complete
101
case $partition_fs in
102
	linux-swap|fat16|fat32|hfs|hfs+|hfsx)
103
		get_resize_range
104
		;;
105
	ext2|ext3)
106
		if ! search-path tune2fs; then
107
			logger -t partman-auto-loop "Error: tune2fs not found"
108
			exit 1
109
		fi
110
		if ! search-path resize2fs; then
111
			logger -t partman-auto-loop "Error: resize2fs not found"
112
			exit 1
113
		fi
114
		if ! get_ext2_resize_range; then
115
			logger -t partman-auto-loop "Error: Failed to get ext2 resize range for $disk/$partition_id"
116
			exit 1
117
		fi
118
		;;
119
	ntfs)
120
		if ! search-path ntfsresize; then
121
			logger -t partman-auto-loop "Error: ntfsresize not found"
122
			exit 1
123
		fi
124
		if ! get_ntfs_resize_range; then
381.1.1 by ago
Clearer error message when ntfsresize fails
125
			db_input critical partman-auto-loop/unclean_ntfs || true
126
			db_go || true
316 by ago
Added preliminary workarounds via override_files to be able to complete
127
			logger -t partman-auto-loop "Error: Failed to get NTFS resize range for $disk/$partition_id"
381.1.1 by ago
Clearer error message when ntfsresize fails
128
			reboot
316 by ago
Added preliminary workarounds via override_files to be able to complete
129
			exit 1
130
		fi
131
		;;
132
	*)
133
		logger -t partman-auto-loop "Cannot calculate free space on filesystems of type $partition_fs"
134
		exit 1
135
		;;
136
esac
383 by ago
Changed version to 8.04
137
#fi
316 by ago
Added preliminary workarounds via override_files to be able to complete
138
free_size="$(expr \( "$cursize" - "$minsize" \) \* 9 / 10)"
139
# convert to megabytes
140
free_size="$(expr 0000000"$free_size" : '0*\(..*\)......$')"
141
142
recipe_new=
143
firstword=
144
imagepaths=
145
for word in $(cat "$recipe_dir/loop_recipe"); do
146
	case $word in
147
		.)
148
			recipe_new="${recipe_new:+$recipe_new }\$imagepath{ $firstword } $word"
149
			firstword=
150
			;;
151
		*)
152
			if [ "$firstword" ]; then
153
				recipe_new="${recipe_new:+$recipe_new }$word"
154
			else
155
				firstword="$word"
156
				imagepaths="${imagepaths:+$imagepaths }$word"
157
			fi
158
			;;
159
	esac
160
done
161
echo "$recipe_new" >"$recipe_dir/loop_recipe_new"
162
decode_recipe "$recipe_dir/loop_recipe_new" loop
163
if [ $(min_size) -gt $free_size ]; then
164
	logger -t partman-auto-loop "Error: partman-auto-loop/recipe too large ($(min_size) > $free_size)"
165
	exit 1
166
fi
167
168
db_progress STEP 1
169
170
fstab="$(
171
	for i in /lib/partman/fstab.d/*; do
172
		[ -x "$i" ] || continue
173
		$i
174
	done |
175
	while read fs mp type options dump pass; do
176
		case $mp in
177
			(/)
178
				echo $fs $mp $type $options $dump $pass
179
				;;
180
		esac
181
	done
182
)"
183
184
if [ -z "$fstab" ]; then
185
	logger -t partman-auto-loop "Error: No fstab output for $disk/$partition_id"
186
	exit 1
187
fi
188
189
mkdir -p /target
190
191
mountpoint="$(grep "^${fstab%% *} [^ ]* [^ ]* [^ ]*rw" /proc/mounts | cut -d ' ' -f2)" || mountpoint=
192
if [ "$mountpoint" = /target ]; then
193
	# nothing to do
194
	:
195
elif [ "$mountpoint" ]; then
196
	if ! mount $mount_move "$mountpoint" /target; then
197
		logger -t partman-auto-loop "Error: Failed to move $mountpoint to /target"
198
		exit 1
199
	fi
200
	unmount_cmd='umount /target'
201
else
202
	for m in /lib/partman/mount.d/*; do
203
		[ -x "$m" ] || continue
204
205
		unmount_cmd="$($m "$fstab")"
206
		if [ "$?" = 0 ]; then
207
			break
208
		fi
209
	done
210
fi
211
if [ -d /var/run ]; then
321 by ago
Added sendsig.omit for mount.ntfs to autopartition-loop
212
	pidof /sbin/mount.ntfs >> /var/run/sendsigs.omit
316 by ago
Added preliminary workarounds via override_files to be able to complete
213
	pidof /sbin/mount.ntfs-3g >> /var/run/sendsigs.omit
214
fi
215
216
# TODO: handle errors if no mount succeeded
217
218
mkdir -p /host
219
mount $mount_move /target /host # TODO error handling
220
221
# Don't try to mount this again later.
222
rm -f $partition_id/mountpoint
223
365 by ago
Disk images are now generated on the windows side to allow for fast creation of zeroed files.
224
# Ensure that no old loop images are present and mountable.
225
mkdir -p /tmpmountpoint
316 by ago
Added preliminary workarounds via override_files to be able to complete
226
for path in $imagepaths; do
227
	case $path in
228
		/*)	;;
229
		*)	path="/$path" ;;
230
	esac
231
	if [ -e "/host$path" ]; then
365 by ago
Disk images are now generated on the windows side to allow for fast creation of zeroed files.
232
		if mount -t auto -o loop,ro /host$path /tmpmountpoint 2>/dev/null; then
233
			db_progress STOP
234
			db_subst partman-auto-loop/unclean_host PARTITION "$partition"
235
			db_subst partman-auto-loop/unclean_host DISK "$disk"
236
			db_subst partman-auto-loop/unclean_host IMAGES "$found_images"
237
			db_input critical partman-auto-loop/unclean_host || true
238
			db_capb
239
			db_go || true
240
			db_capb backup
241
			umount /tmpmountpoint || true
242
			rmdir /tmpmountpoint || true
243
			umount /host || true
244
			exit 1
245
		fi
316 by ago
Added preliminary workarounds via override_files to be able to complete
246
	fi
247
done
248
249
db_progress STEP 1
250
251
expand_scheme
252
253
db_progress STEP 1
254
255
clean_method
256
257
db_progress STEP 1
258
259
setup_loop () {
260
	[ "$1" != 0 ] || return
261
	path="$(echo "$*" | sed 's/.*\$imagepath{  *\([^ }]*\) *}.*/\1/')"
262
	[ "$path" != "$*" ] || return
263
264
	case $path in
265
		/*)	;;
266
		*)	path="/$path" ;;
267
	esac
375 by ago
Fix to avoid skipping swap disk
268
	[ -f "/host$path" ] || return
269
	#~ mkdir -p "/host${path%/*}"
365 by ago
Disk images are now generated on the windows side to allow for fast creation of zeroed files.
270
	#~ rm -f "/host$path"
271
	#~ if [ "$(basename /host$path)" = "swap.disk" ]; then	
272
		#~ #swap requires a file with no holes
273
		#~ dd if=/dev/zero of="/host$path" bs="1MB" count=$1
274
	#~ else
275
		#~ zeroedsize=$([ $1 -lt 50 ] && echo $1 || echo 50)
276
		#~ dd if=/dev/zero of="/host$path" bs="1MB" count=$zeroedsize
277
		#~ dd if=/dev/zero of="/host$path" bs="1MB" seek="$1" count=0
278
	#~ fi
319 by ago
Minor fix
279
	if ! losetup -f "/host$path"; then
316 by ago
Added preliminary workarounds via override_files to be able to complete
280
		shift
281
		continue
282
	fi
283
	if [ "$4" = linux-swap ]; then
284
		loops="/host$path"
285
	else
286
		loops="$(echo /dev/loop* /dev/loop/*)"
287
	fi
288
	for loop in $loops; do
289
		[ -e "$loop" ] || continue
290
		case $loop in
291
			/dev/loop*)
292
				loopfile="$(losetup "$loop")" || continue
293
				# The following works with both busybox's
294
				# losetup and util-linux's losetup. Yes,
295
				# this is ugly.
296
				loopfile="$(echo "$loopfile" | sed 's,.*\(/host/[^)]*\).*,\1,')"
297
				;;
298
			*)
299
				loopfile="$loop"
300
				;;
301
		esac
302
		[ "$loopfile" = "/host$path" ] || continue
303
304
		dirname="$(echo "$loop" | sed 's:/:=:g')"
305
		dev="$DEVICES/$dirname"
306
307
		rm -rf "$dev"
308
		mkdir "$dev" || autopartitioning_failed
309
		printf "%s" "$loop" >"$dev/device"
310
		printf "%s" "$1" >"$dev/size"
311
		echo "Loopback on $loopfile" >"$dev/model"
312
		echo "$loopfile" >"$dev/loop"
313
314
		cd "$dev"
315
		open_dialog OPEN "$(cat "$dev/device")"
316
		read_line response
317
		close_dialog
318
		if [ "$response" = failed ]; then
319
			cd /
320
			rm -rf "$dev"
321
			autopartitioning_failed
322
		fi
323
324
		open_dialog NEW_LABEL loop
325
		close_dialog
326
327
		# find the free space
328
		open_dialog PARTITIONS
329
		free_space=
330
		while { read_line num id size type fs path name; [ "$id" ]; }; do
331
			if [ "$fs" = free ]; then
332
				free_space=$id
333
				free_size=$size
334
			fi
335
		done
336
		close_dialog
337
338
		# create partition in the free space
339
		[ "$free_space" ] || autopartitioning_failed
340
		open_dialog NEW_PARTITION primary $4 $free_space full ${1}000001
341
		read_line num id size type fs path name
342
		close_dialog
343
344
		shift; shift; shift; shift
345
		setup_partition $id $*
346
		break
347
	done
348
}
349
350
foreach_partition 'setup_loop $*'
351
352
db_progress STEP 1
353
354
update_all
355
356
apt-install lupin-support
357
358
db_progress STOP
359
360
exit 0