Revision 8576747b

b/snf-image-helper/common.sh
30 30
SFDISK=sfdisk
31 31
MKSWAP=mkswap
32 32
BLKID=blkid
33
BLOCKDEV=blockdev
33 34
REGLOOKUP=reglookup
34 35
CHNTPW=chntpw
35 36

  
......
97 98
    fi
98 99
}
99 100

  
100
get_last_partition_id() {
101
    local dev="$1"
102
    if ! output="$("$PARTED" -s -m "$dev" print)"; then
103
        log_error "Unable to read partition table for device \`${dev}'"
104
    fi
105

  
106
    last_line=$(tail -1 <<< "$output")
107

  
108
    echo $(cut -d: -f1 <<< "$last_line")
109
}
110 101

  
111 102
get_partition_table() {
112 103
    local dev="$1"
113
    if ! output="$("$PARTED" -s -m "$dev" unit s print)"; then
104
    # If the partition table is gpt then parted will raise an error if the
105
    # secondary gpt is not it the end of the disk, and a warning that has to
106
    # do with the "Last Usable LBA" entry in gpt.
107
    if ! output="$("$PARTED" -s -m "$dev" unit s print | grep -E -v "^(Warning|Error): ")"; then
114 108
        log_error "Unable to read partition table for device \`${dev}'"
115 109
    fi
116 110

  
......
133 127
    expr $(echo "$ptable" | wc -l) - 2
134 128
}
135 129

  
136
get_partition_by_id() {
130
get_partition_by_num() {
137 131
    local ptable="$1"
138 132
    local id="$2"
139 133

  
......
198 192
    echo ""
199 193
}
200 194

  
195
get_partition_to_resize() {
196
    local dev="$1"
197

  
198
    table=$(get_partition_table "$dev")
199

  
200
    if [ $(get_partition_count "$table") -eq 0 ]; then
201
        return 0
202
    fi
203

  
204
    table_type=$(get_partition_table_type "$table")
205
    last_part=$(get_last_partition "$table")
206
    last_part_num=$(cut -d: -f1 <<< "$last_part")
207

  
208
    if [ "$table_type" == "msdos" -a $last_part_num -gt 4 ]; then
209
        extended=$(get_extended_partition "$table")
210
        last_primary=$(get_last_primary_partition "$table")
211
        ext_num=$(cut -d: -f1 <<< "$extended")
212
        prim_num=$(cut -d: -f1 <<< "$last_primary")
213

  
214
        if [ "$ext_num" != "$last_prim_num" ]; then
215
            echo "$last_prim_num"
216
        else
217
            echo "$last_part_num"
218
        fi
219
    else
220
        echo "$last_part_num"
221
    fi
222
}
223

  
201 224
create_partition() {
202 225
    local device="$1"
203 226
    local part="$2"
b/snf-image-helper/snf-image-helper.in
59 59
add_cleanup rmdir "$target"
60 60

  
61 61
export SNF_IMAGE_TARGET="$target"
62
export SNF_IMAGE_RESIZE_PART="$(get_last_partition_id "$SNF_IMAGE_DEV")"
63 62

  
64 63
if [ ! -d "@tasksdir@" ]; then
65 64
    log_error "snf-image/tasks directory is missing"
......
76 75

  
77 76
if [ -z "$SNF_IMAGE_PROPERTY_EXCLUDE_ALL_TASKS" ]; then
78 77

  
78
    export SNF_IMAGE_RESIZE_PART="$(get_partition_to_resize "$SNF_IMAGE_DEV")"
79

  
79 80
    if [[ ! "$SNF_IMAGE_PROPERTY_OSFAMILY" =~ ^(linux|windows)$ ]]; then
80 81
        log_error "Supported values for OSFAMILY property are: linux|windows"
81 82
    fi
b/snf-image-helper/tasks/20FilesystemResizeUnmounted.in
40 40
fi
41 41

  
42 42
table=$(get_partition_table "$SNF_IMAGE_DEV")
43
partition=$(get_partition_by_id "$table" "$SNF_IMAGE_RESIZE_PART")
43
partition=$(get_partition_by_num "$table" "$SNF_IMAGE_RESIZE_PART")
44 44
id=$(cut -d: -f1 <<< "$partition")
45 45
ptype=$(cut -d: -f5 <<< "$partition")
46 46

  
b/snf-image-helper/tasks/50FilesystemResizeMounted.in
39 39
fi
40 40

  
41 41
table=$(get_partition_table "$SNF_IMAGE_DEV")
42
partition=$(get_partition_by_id "$table" "$SNF_IMAGE_RESIZE_PART")
42
partition=$(get_partition_by_num "$table" "$SNF_IMAGE_RESIZE_PART")
43 43
id=$(cut -d: -f1 <<< "$partition")
44 44
ptype=$(cut -d: -f5 <<< "$partition")
45 45

  

Also available in: Unified diff