Revision 42f09a19 snf-image-helper/common.sh
b/snf-image-helper/common.sh | ||
---|---|---|
35 | 35 |
# Programs |
36 | 36 |
XMLSTARLET=xmlstarlet |
37 | 37 |
RESIZE2FS=resize2fs |
38 |
PARTED=parted |
|
38 | 39 |
|
39 | 40 |
CLEANUP=( ) |
40 | 41 |
|
... | ... | |
92 | 93 |
fi |
93 | 94 |
} |
94 | 95 |
|
96 |
get_last_partition() { |
|
97 |
local dev="$1" |
|
98 |
|
|
99 |
"$PARTED" -s -m "$dev" unit s print | tail -1 |
|
100 |
} |
|
101 |
|
|
102 |
get_partition() { |
|
103 |
local dev="$1" |
|
104 |
local id="$2" |
|
105 |
|
|
106 |
"$PARTED" -s -m "$dev" unit s print | grep "^$id" |
|
107 |
} |
|
108 |
|
|
109 |
get_partition_count() { |
|
110 |
local dev="$1" |
|
111 |
|
|
112 |
expr $("$PARTED" -s -m "$dev" unit s print | wc -l) - 2 |
|
113 |
} |
|
114 |
|
|
115 |
get_last_free_sector() { |
|
116 |
local dev="$1" |
|
117 |
local last_line=$("$PARTED" -s -m "$dev" unit s print free | tail -1) |
|
118 |
local type=$(echo "$last_line" | cut -d: -f 5) |
|
119 |
|
|
120 |
if [ "$type" = "free;" ]; then |
|
121 |
echo "$last_line" | cut -d: -f 3 |
|
122 |
fi |
|
123 |
} |
|
124 |
|
|
95 | 125 |
cleanup() { |
96 | 126 |
# if something fails here, it shouldn't call cleanup again... |
97 | 127 |
trap - EXIT |
Also available in: Unified diff