File: initial_auto

package info (click to toggle)
partman-auto 178
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,740 kB
  • sloc: sh: 1,342; makefile: 17
file content (111 lines) | stat: -rwxr-xr-x 2,516 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
#!/bin/sh

. /usr/lib/partman/lib/base.sh

# Only run the first time
if [ -f /var/lib/partman/initial_auto ]; then
	exit 0
fi

. /usr/lib/partman/lib/auto-shared.sh

# Skip if no disks detected and don't run on S/390
if [ -z "$(get_auto_disks)" ] || \
   [ "$(udpkg --print-architecture)" = s390 ]; then
	exit 0
fi

mkdir -p /var/lib/partman
touch /var/lib/partman/initial_auto

# See if any autopartition method has been set
method=""
if db_get partman-auto/method && [ "$RET" ]; then
	method="$RET"
fi

# See if any autopartition disks have been set
disks=""
if db_get partman-auto/disk && [ "$RET" ]; then
	disks="$RET"
fi

# If there's only one disk, then preseeding partman-auto/disk is
# unnecessary, and sometimes inconvenient in heterogeneous environments
if [ "$method" ] && [ -z "$disks" ]; then
	DEVS="$(get_auto_disks)"
	if [ "$(echo "$DEVS" | wc -l)" -eq 1 ]; then
		disks="$(cat "${DEVS%$TAB*}"/device)"
	fi
fi

# If both are set, let's try to do a completely automatic partitioning
if [ "$method" ] && [ "$disks" ]; then
	# The code for the methods could be merged, but in the future non-regular
	# methods may support multiple disks
	case "$method" in
	    regular)
		for disk in $disks; do
			id=$(dev_to_partman "$disk") || true
			if [ "$id" ]; then
				autopartition "$id"
				exit 0
			fi
		done
		exit 1
		;;
	    lvm)
		search-path autopartition-lvm || exit 1
		ids=""
		for disk in $disks; do
			id=$(dev_to_partman "$disk") || true
			ids="${ids:+$ids }$id"
		done
		if [ "$ids" ]; then
			autopartition-lvm "$ids"
			exit 0
		fi
		exit 1
		;;
	    crypto)
		search-path autopartition-crypto || exit 1
		for disk in $disks; do
			id=$(dev_to_partman "$disk") || true
			if [ "$id" ]; then
				autopartition-crypto "$id"
				exit 0
			fi
		done
		exit 1
		;;
	    raid)
		# Partition all the disks given ready for
		# partman-auto-raid
		ids=""
		for disk in $disks; do
			id=$(dev_to_partman "$disk") || true
			ids="${ids:+$ids }$id"
		done
		auto_init_disks $ids || exit $?
		autopartition "$ids"
		exit 0
		;;
	    *)
		logger -t partman-auto "Unsupported method '$method'"
		exit 1
		;;
	esac
fi

qfile=/usr/lib/partman/automatically_partition/question
echo "partman-auto/init_automatically_partition" >$qfile
code=99 # signals a retry
while [ $code = 99 ]; do
	ask_user /usr/lib/partman/automatically_partition
	code=$?
done
if [ $code -gt 0 ] && [ $code -lt 100 ]; then
	rm -f /var/lib/partman/initial_auto # try again
fi
echo "partman-auto/automatically_partition" >$qfile
exit $code