File: perform_recipe

package info (click to toggle)
partman-auto 41
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 664 kB
  • ctags: 13
  • sloc: sh: 646; makefile: 42
file content (198 lines) | stat: -rwxr-xr-x 4,349 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/bin/sh

. /lib/partman/definitions.sh
. /lib/partman/recipes.sh

dev=$1
free_space=$2
recipe=$3

# Let us be safe and update the directories
update_all

cd $dev
open_dialog PARTITION_INFO $free_space
read_line x1 x2 free_size free_type x3 x4 x5
close_dialog

free_size=$(expr 0000000"$free_size" : '0*\(..*\)......$') # convert to megabytes

if [ "$free_type" = unusable ]; then
    db_input critical partman-auto/unusable_space || true
    db_go || true
    exit 1
fi

db_progress START 0 6 partman-auto/text/automatically_partition
db_progress INFO partman-auto/progress/info

decode_recipe $recipe

db_progress STEP 1

# Make factors small numbers so we can multiply on them.
# Also ensure that fact, max and fs are valid
# (Ofcourse in valid recipes they must be valid.)
factsum=$(($(factor_sum) - $(min_size)))
scheme=$(
    foreach_partition '
        local min fact max fs
        min=$1
	fact=$((($2 - $min) * 100 / $factsum))
	max=$3
	fs=$4
        case "$fs" in
	    ext2|ext3|linux-swap|fat16|fat32|hfs)
		true
		;;
	    *)
		fs=ext2
		;;
        esac
	shift; shift; shift; shift
	echo $min $fact $max $fs $*'
)

db_progress STEP 1

oldscheme=''
while [ "$scheme" != "$oldscheme" ]; do
    oldscheme="$scheme"
    factsum=$(factor_sum)
    unallocated=$(($free_size - $(min_size)))
    if [ $unallocated -lt 0 ]; then
	unallocated=0
    fi
    scheme=$(
	foreach_partition '
	    local min fact max newmin
	    min=$1
	    fact=$2
	    max=$3
	    shift; shift; shift
	    newmin=$(($min + $unallocated * $fact / $factsum))
	    if [ $newmin -le $max ]; then
		echo $newmin $fact $max $*
	    else
		echo $max 0 $max $*
	    fi'
    )
done

db_progress STEP 1

for device in $DEVICES/*; do
    [ -d "$device" ] || continue
    cd $device
    open_dialog PARTITIONS
    while { read_line num id size type fs path name; [ "$id" ]; }; do
	if [ -f $id/method ]; then
	    rm $id/method
	fi
    done
    close_dialog
done

db_progress STEP 1

cd $dev

while
    [ "$free_type" = pri/log ] \
    && echo $scheme | grep '\$primary{' >/dev/null
do
    pull_primary
    set -- $primary
    open_dialog NEW_PARTITION primary $4 $free_space beginning ${1}000001
    read_line num id size type fs path name
    close_dialog
    if [ -z "$id" ]; then
	db_progress STOP
	autopartitioning_failed
    fi
    neighbour=$(partition_after $id)
    if [ "$neighbour" ]; then
	open_dialog PARTITION_INFO $neighbour
	read_line x1 new_free_space x2 new_free_type fs x3 x4
	close_dialog
    fi
    if 
	[ -z "$neighbour" -o "$fs" != free \
	  -o "$new_free_type" = primary -o "$new_free_type" = unusable ]
    then
	open_dialog DELETE_PARTITION $id
	close_dialog
	open_dialog NEW_PARTITION primary $4 $free_space end ${1}000001
	read_line num id size type fs path name
	close_dialog
	if [ -z "$id" ]; then
	    db_progress STOP
	    autopartitioning_failed
	fi
	neighbour=$(partition_before $id)
	if [ "$neighbour" ]; then
	    open_dialog PARTITION_INFO $neighbour
	    read_line x1 new_free_space x2 new_free_type fs x3 x4
	    close_dialog
	fi
	if 
	    [ -z "$neighbour" -o "$fs" != free -o "$new_free_type" = unusable ]
	then
	    open_dialog DELETE_PARTITION $id
	    close_dialog
	    break
	fi
    fi
    shift; shift; shift; shift
    setup_partition $id $*
    primary=''
    scheme="$logical"
    free_space=$new_free_space
    free_type="$new_free_type"
done

db_progress STEP 1

foreach_partition '
    if [ -z "$free_space" ]; then
        db_progress STOP
	autopartitioning_failed
    fi
    open_dialog PARTITION_INFO $free_space
    read_line x1 free_space x2 free_type fs x3 x4
    close_dialog
    if [ "$fs" != free ]; then
        free_type=unusable
    fi
    case "$free_type" in
	primary|logical)
	    type="$free_type"
	    ;;
	pri/log)
	    type=logical
	    ;;
	unusable)
            db_progress STOP
	    autopartitioning_failed
	    ;;
    esac
    if [ "$last" = yes ]; then
        open_dialog NEW_PARTITION $type $4 $free_space full ${1}000001
    else
        open_dialog NEW_PARTITION $type $4 $free_space beginning ${1}000001
    fi
    read_line num id size type fs path name
    close_dialog
    if [ -z "$id" ]; then
        db_progress STOP
	autopartitioning_failed
    fi
    shift; shift; shift; shift
    setup_partition $id $*
    free_space=$(partition_after $id)'

db_progress STEP 1

update_all

db_progress STOP