Gentoo Archives: gentoo-commits

From: Matt Thode <prometheanfire@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: app-emulation/cloud-init/, app-emulation/cloud-init/files/
Date: Sun, 31 Jan 2016 23:39:38
Message-Id: 1454283538.03cde2b911bc4aee23bd284a93cfc96021ef4650.prometheanfire@gentoo
1 commit: 03cde2b911bc4aee23bd284a93cfc96021ef4650
2 Author: Matthew Thode <prometheanfire <AT> gentoo <DOT> org>
3 AuthorDate: Sun Jan 31 23:37:05 2016 +0000
4 Commit: Matt Thode <prometheanfire <AT> gentoo <DOT> org>
5 CommitDate: Sun Jan 31 23:38:58 2016 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=03cde2b9
7
8 app-emulation/cloud-init: split out growpart
9
10 Package-Manager: portage-2.2.26
11
12 app-emulation/cloud-init/Manifest | 1 -
13 .../cloud-init/cloud-init-0.7.5-r1.ebuild | 52 --
14 .../cloud-init/cloud-init-0.7.5-r2.ebuild | 84 ---
15 .../cloud-init/cloud-init-0.7.5-r3.ebuild | 88 ---
16 .../cloud-init/cloud-init-0.7.6-r1.ebuild | 6 +-
17 app-emulation/cloud-init/cloud-init-0.7.6.ebuild | 98 ---
18 .../files/cloud-init-0.7.5-tests-exclude.patch | 12 -
19 app-emulation/cloud-init/files/growpart | 778 ---------------------
20 8 files changed, 2 insertions(+), 1117 deletions(-)
21
22 diff --git a/app-emulation/cloud-init/Manifest b/app-emulation/cloud-init/Manifest
23 index 93c02cd..4f0a651 100644
24 --- a/app-emulation/cloud-init/Manifest
25 +++ b/app-emulation/cloud-init/Manifest
26 @@ -1,2 +1 @@
27 -DIST cloud-init-0.7.5.tar.gz 503717 SHA256 a92bb83809c139a7db378916414c18b0819e306852d6c60dd89388868857ed33 SHA512 79e1e4a9e1130a3a9deb0482278215baf5ed41e02beebed0a2c6fac4e215340a9537158bd259758a2e074f334c0c0b9e7b936c23eeb9c848c67f7e7835cf0f5d WHIRLPOOL 7d92a0e1b6a3faf550bc442b02c117280c47d160e7e318d9fb859d6d8b59a0ef947d057dfb615bd925420a25ca28852742ee87ffd6066664faf640ca53a13073
28 DIST cloud-init-0.7.6.tar.gz 515670 SHA256 9e8fd22eb7f6e40ae6a5f66173ddc3cc18f65ee406c460a728092b37db2f3ed7 SHA512 aa2397328afda8e77ed6d642e7642f41a4b4b5bcd3d0e87056aa8c88b56624ec65c57cfc66b0d13ccc235f1840baf1d577316974902a0439cf2f2eb0f8eef36d WHIRLPOOL 639a556e51b4b4b180951f9e481f9a0dcd45067d1d5760ce7e871ceea8bbb4e195258d96273d3ef88c7e2f2520318e9172c3ad0cb23d6ad0ae1835e17087e3a5
29
30 diff --git a/app-emulation/cloud-init/cloud-init-0.7.5-r1.ebuild b/app-emulation/cloud-init/cloud-init-0.7.5-r1.ebuild
31 deleted file mode 100644
32 index a01d1dc..0000000
33 --- a/app-emulation/cloud-init/cloud-init-0.7.5-r1.ebuild
34 +++ /dev/null
35 @@ -1,52 +0,0 @@
36 -# Copyright 1999-2014 Gentoo Foundation
37 -# Distributed under the terms of the GNU General Public License v2
38 -# $Id$
39 -
40 -EAPI=5
41 -PYTHON_COMPAT=( python2_7 )
42 -
43 -inherit distutils-r1 eutils multilib
44 -
45 -DESCRIPTION="Package provides configuration and customization of cloud instance"
46 -HOMEPAGE="https://launchpad.net/cloud-init"
47 -SRC_URI="https://launchpad.net/${PN}/trunk/${PV}/+download/${P}.tar.gz"
48 -
49 -LICENSE="GPL-3"
50 -SLOT="0"
51 -KEYWORDS="~amd64 ~x86"
52 -IUSE="test"
53 -
54 -RDEPEND="dev-python/cheetah[${PYTHON_USEDEP}]
55 - >=dev-python/prettytable-0.7.1[${PYTHON_USEDEP}]
56 - dev-python/oauth[${PYTHON_USEDEP}]
57 - dev-python/pyserial[${PYTHON_USEDEP}]
58 - dev-python/configobj[${PYTHON_USEDEP}]
59 - dev-python/pyyaml[${PYTHON_USEDEP}]
60 - dev-python/requests[${PYTHON_USEDEP}]
61 - dev-python/jsonpatch[${PYTHON_USEDEP}]"
62 -DEPEND="dev-python/setuptools[${PYTHON_USEDEP}]
63 - test? ( ${RDEPEND}
64 - sys-apps/iproute2 )"
65 -
66 -PATCHES=( "${FILESDIR}"/${P}-tests-exclude.patch )
67 -
68 -#python_prepare_all() {
69 -# distutils-r_python_prepare_all
70 -#}
71 -
72 -python_test() {
73 - # These tests are not broken but expect to locate an installed exe file
74 - # other than where a gentoo system installs it; (/bin/ip sought in /sbin)
75 - # See cloudinit/sources/DataSourceOpenNebula.py for possible patching
76 - sed -e 's:test_hostname:_&:' \
77 - -e 's:test_network_interfaces:_&:' \
78 - -i tests/unittests/test_datasource/test_opennebula.py
79 - emake test
80 -}
81 -
82 -python_install() {
83 - distutils-r1_python_install
84 - for svc in config final init init-local; do
85 - newinitd "${WORKDIR}/${P}/sysvinit/gentoo/cloud-${svc}" "cloud-${svc}"
86 - done
87 -}
88
89 diff --git a/app-emulation/cloud-init/cloud-init-0.7.5-r2.ebuild b/app-emulation/cloud-init/cloud-init-0.7.5-r2.ebuild
90 deleted file mode 100644
91 index d53ccc6..0000000
92 --- a/app-emulation/cloud-init/cloud-init-0.7.5-r2.ebuild
93 +++ /dev/null
94 @@ -1,84 +0,0 @@
95 -# Copyright 1999-2014 Gentoo Foundation
96 -# Distributed under the terms of the GNU General Public License v2
97 -# $Id$
98 -
99 -EAPI=5
100 -PYTHON_COMPAT=( python2_7 )
101 -DISTUTILS_SINGLE_IMPL=TRUE
102 -
103 -inherit distutils-r1 eutils multilib systemd
104 -
105 -DESCRIPTION="Cloud instance initialization"
106 -HOMEPAGE="https://launchpad.net/cloud-init"
107 -SRC_URI="https://launchpad.net/${PN}/trunk/${PV}/+download/${P}.tar.gz"
108 -
109 -LICENSE="GPL-3"
110 -SLOT="0"
111 -KEYWORDS="~amd64 ~x86"
112 -IUSE="test"
113 -
114 -CDEPEND="
115 - dev-python/cheetah[${PYTHON_USEDEP}]
116 - dev-python/configobj[${PYTHON_USEDEP}]
117 - dev-python/jsonpatch[${PYTHON_USEDEP}]
118 - dev-python/oauth[${PYTHON_USEDEP}]
119 - >=dev-python/prettytable-0.7.1[${PYTHON_USEDEP}]
120 - dev-python/pyserial[${PYTHON_USEDEP}]
121 - dev-python/pyyaml[${PYTHON_USEDEP}]
122 - dev-python/requests[${PYTHON_USEDEP}]
123 -"
124 -DEPEND="
125 - test? (
126 - ${CDEPEND}
127 - >=dev-python/httpretty-0.7.1[${PYTHON_USEDEP}]
128 - dev-python/mocker[${PYTHON_USEDEP}]
129 - dev-python/nose[${PYTHON_USEDEP}]
130 - dev-python/pep8[${PYTHON_USEDEP}]
131 - dev-python/pyflakes[${PYTHON_USEDEP}]
132 - dev-python/pylint[${PYTHON_USEDEP}]
133 - sys-apps/iproute2
134 - )
135 -"
136 -RDEPEND="
137 - ${CDEPEND}
138 - virtual/logger
139 -"
140 -
141 -python_prepare_all() {
142 - local PATCHES=(
143 - "${FILESDIR}"/${P}-tests-exclude.patch
144 - )
145 -
146 - distutils-r1_python_prepare_all
147 -
148 - # Skip SmartOS tests since they don't generally apply and don't skip based
149 - # on environment. Documented in bug #511384.
150 - rm tests/unittests/test_datasource/test_smartos.py
151 -}
152 -
153 -python_test() {
154 - # These tests are not broken but expect to locate an installed exe file
155 - # other than where a gentoo system installs it; (/bin/ip sought in /sbin)
156 - # See cloudinit/sources/DataSourceOpenNebula.py for possible patching
157 - sed \
158 - -e 's:test_hostname:_&:' \
159 - -e 's:test_network_interfaces:_&:' \
160 - -i tests/unittests/test_datasource/test_opennebula.py
161 -
162 - emake test
163 -}
164 -
165 -python_install_all() {
166 - distutils-r1_python_install_all
167 -
168 - doinitd "${S}"/sysvinit/gentoo/cloud-config
169 - doinitd "${S}"/sysvinit/gentoo/cloud-final
170 - doinitd "${S}"/sysvinit/gentoo/cloud-init
171 - doinitd "${S}"/sysvinit/gentoo/cloud-init-local
172 -
173 - systemd_dounit "${S}"/systemd/cloud-config.service
174 - systemd_dounit "${S}"/systemd/cloud-config.target
175 - systemd_dounit "${S}"/systemd/cloud-final.service
176 - systemd_dounit "${S}"/systemd/cloud-init-local.service
177 - systemd_dounit "${S}"/systemd/cloud-init.service
178 -}
179
180 diff --git a/app-emulation/cloud-init/cloud-init-0.7.5-r3.ebuild b/app-emulation/cloud-init/cloud-init-0.7.5-r3.ebuild
181 deleted file mode 100644
182 index c0861d4..0000000
183 --- a/app-emulation/cloud-init/cloud-init-0.7.5-r3.ebuild
184 +++ /dev/null
185 @@ -1,88 +0,0 @@
186 -# Copyright 1999-2015 Gentoo Foundation
187 -# Distributed under the terms of the GNU General Public License v2
188 -# $Id$
189 -
190 -EAPI=5
191 -PYTHON_COMPAT=( python2_7 )
192 -DISTUTILS_SINGLE_IMPL=TRUE
193 -
194 -inherit distutils-r1 eutils multilib systemd
195 -
196 -DESCRIPTION="Cloud instance initialization"
197 -HOMEPAGE="https://launchpad.net/cloud-init"
198 -SRC_URI="https://launchpad.net/${PN}/trunk/${PV}/+download/${P}.tar.gz"
199 -
200 -LICENSE="GPL-3"
201 -SLOT="0"
202 -KEYWORDS="~amd64 ~x86"
203 -IUSE="test"
204 -
205 -CDEPEND="
206 - dev-python/cheetah[${PYTHON_USEDEP}]
207 - dev-python/configobj[${PYTHON_USEDEP}]
208 - dev-python/jsonpatch[${PYTHON_USEDEP}]
209 - dev-python/oauth[${PYTHON_USEDEP}]
210 - >=dev-python/prettytable-0.7.1[${PYTHON_USEDEP}]
211 - dev-python/pyserial[${PYTHON_USEDEP}]
212 - dev-python/pyyaml[${PYTHON_USEDEP}]
213 - dev-python/requests[${PYTHON_USEDEP}]
214 -"
215 -DEPEND="
216 - test? (
217 - ${CDEPEND}
218 - >=dev-python/httpretty-0.7.1[${PYTHON_USEDEP}]
219 - dev-python/mocker[${PYTHON_USEDEP}]
220 - dev-python/nose[${PYTHON_USEDEP}]
221 - dev-python/pep8[${PYTHON_USEDEP}]
222 - dev-python/pyflakes[${PYTHON_USEDEP}]
223 - dev-python/pylint[${PYTHON_USEDEP}]
224 - sys-apps/iproute2
225 - )
226 -"
227 -RDEPEND="
228 - ${CDEPEND}
229 - virtual/logger
230 -"
231 -
232 -python_prepare_all() {
233 - local PATCHES=(
234 - "${FILESDIR}"/${P}-tests-exclude.patch
235 - )
236 -
237 - distutils-r1_python_prepare_all
238 -
239 - # Skip SmartOS tests since they don't generally apply and don't skip based
240 - # on environment. Documented in bug #511384.
241 - rm tests/unittests/test_datasource/test_smartos.py
242 -}
243 -
244 -python_test() {
245 - # These tests are not broken but expect to locate an installed exe file
246 - # other than where a gentoo system installs it; (/bin/ip sought in /sbin)
247 - # See cloudinit/sources/DataSourceOpenNebula.py for possible patching
248 - sed \
249 - -e 's:test_hostname:_&:' \
250 - -e 's:test_network_interfaces:_&:' \
251 - -i tests/unittests/test_datasource/test_opennebula.py
252 -
253 - emake test
254 -}
255 -
256 -python_install_all() {
257 - distutils-r1_python_install_all
258 -
259 - doinitd "${S}"/sysvinit/gentoo/cloud-config
260 - doinitd "${S}"/sysvinit/gentoo/cloud-final
261 - doinitd "${S}"/sysvinit/gentoo/cloud-init
262 - doinitd "${S}"/sysvinit/gentoo/cloud-init-local
263 -
264 - systemd_dounit "${S}"/systemd/cloud-config.service
265 - systemd_dounit "${S}"/systemd/cloud-config.target
266 - systemd_dounit "${S}"/systemd/cloud-final.service
267 - systemd_dounit "${S}"/systemd/cloud-init-local.service
268 - systemd_dounit "${S}"/systemd/cloud-init.service
269 -
270 - rm /etc/cloud/cloud.cfg
271 - insinto /etc/cloud
272 - doins "${FILESDIR}/cloud.cfg"
273 -}
274
275 diff --git a/app-emulation/cloud-init/cloud-init-0.7.6-r1.ebuild b/app-emulation/cloud-init/cloud-init-0.7.6-r1.ebuild
276 index 4ba95f2..9c1c7ea 100644
277 --- a/app-emulation/cloud-init/cloud-init-0.7.6-r1.ebuild
278 +++ b/app-emulation/cloud-init/cloud-init-0.7.6-r1.ebuild
279 @@ -1,4 +1,4 @@
280 -# Copyright 1999-2015 Gentoo Foundation
281 +# Copyright 1999-2016 Gentoo Foundation
282 # Distributed under the terms of the GNU General Public License v2
283 # $Id$
284
285 @@ -41,7 +41,7 @@ DEPEND="
286 "
287 RDEPEND="
288 ${CDEPEND}
289 - sys-apps/gptfdisk
290 + sys-fs/growpart
291 virtual/logger
292 "
293
294 @@ -92,8 +92,6 @@ python_install_all() {
295 doinitd "${S}"/sysvinit/gentoo/cloud-init-local
296 insinto /etc/cloud/templates
297 doins "${FILESDIR}/hosts.gentoo.tmpl"
298 - exeinto /usr/bin
299 - doexe "${FILESDIR}/growpart"
300 insinto /etc/cloud
301 doins "${FILESDIR}/cloud.cfg"
302
303
304 diff --git a/app-emulation/cloud-init/cloud-init-0.7.6.ebuild b/app-emulation/cloud-init/cloud-init-0.7.6.ebuild
305 deleted file mode 100644
306 index b35adae..0000000
307 --- a/app-emulation/cloud-init/cloud-init-0.7.6.ebuild
308 +++ /dev/null
309 @@ -1,98 +0,0 @@
310 -# Copyright 1999-2015 Gentoo Foundation
311 -# Distributed under the terms of the GNU General Public License v2
312 -# $Id$
313 -
314 -EAPI=5
315 -PYTHON_COMPAT=( python2_7 )
316 -
317 -inherit distutils-r1 eutils multilib systemd
318 -
319 -DESCRIPTION="EC2 initialisation magic"
320 -HOMEPAGE="https://launchpad.net/cloud-init"
321 -SRC_URI="https://launchpad.net/${PN}/trunk/${PV}/+download/${P}.tar.gz"
322 -
323 -LICENSE="GPL-3"
324 -SLOT="0"
325 -KEYWORDS="amd64 x86"
326 -IUSE="test"
327 -
328 -CDEPEND="
329 - dev-python/cheetah[${PYTHON_USEDEP}]
330 - dev-python/configobj[${PYTHON_USEDEP}]
331 - dev-python/jinja[${PYTHON_USEDEP}]
332 - dev-python/jsonpatch[${PYTHON_USEDEP}]
333 - dev-python/oauth[${PYTHON_USEDEP}]
334 - dev-python/prettytable[${PYTHON_USEDEP}]
335 - dev-python/pyserial[${PYTHON_USEDEP}]
336 - dev-python/pyyaml[${PYTHON_USEDEP}]
337 - dev-python/requests[${PYTHON_USEDEP}]
338 -"
339 -DEPEND="
340 - dev-python/setuptools[${PYTHON_USEDEP}]
341 - test? (
342 - ${CDEPEND}
343 - >=dev-python/httpretty-0.7.1[${PYTHON_USEDEP}]
344 - dev-python/mocker[${PYTHON_USEDEP}]
345 - dev-python/nose[${PYTHON_USEDEP}]
346 - ~dev-python/pep8-1.5.7[${PYTHON_USEDEP}]
347 - dev-python/pyflakes[${PYTHON_USEDEP}]
348 - sys-apps/iproute2
349 - )
350 -"
351 -RDEPEND="
352 - ${CDEPEND}
353 - virtual/logger
354 -"
355 -
356 -python_prepare_all() {
357 - # Note: Gentoo places ip in /sbin/ not /bin/
358 - ebegin 'patching cloudinit/sources/DataSourceOpenNebula.py'
359 - sed \
360 - -e '438s/sbin/bin/' \
361 - -i cloudinit/sources/DataSourceOpenNebula.py
362 - STATUS=$?
363 - eend ${STATUS}
364 - [[ ${STATUS} -gt 0 ]] && die
365 -
366 - # https://bugs.launchpad.net/cloud-init/+bug/1380424
367 - ebegin 'patching tests/unittests/test_distros/test_netconfig.py'
368 - sed \
369 - -e '177s/test_simple_write_freebsd/_&/' \
370 - -i tests/unittests/test_distros/test_netconfig.py
371 - STATUS=$?
372 - eend ${STATUS}
373 - [[ ${STATUS} -gt 0 ]] && die
374 -
375 - # Note Gentoo installs its own RC files
376 - ebegin 'patching setup.py'
377 - sed \
378 - -e "144 s/'tests'/'tests.*', &/" \
379 - -e '163,167 d' \
380 - -i setup.py
381 - STATUS=$?
382 - eend ${STATUS}
383 - [[ ${STATUS} -gt 0 ]] && die
384 -
385 - distutils-r1_python_prepare_all
386 -}
387 -
388 -python_test() {
389 - emake test
390 -}
391 -
392 -python_install_all() {
393 - keepdir /etc/cloud
394 -
395 - distutils-r1_python_install_all
396 -
397 - doinitd "${S}"/sysvinit/gentoo/cloud-config
398 - doinitd "${S}"/sysvinit/gentoo/cloud-final
399 - doinitd "${S}"/sysvinit/gentoo/cloud-init
400 - doinitd "${S}"/sysvinit/gentoo/cloud-init-local
401 -
402 - systemd_dounit "${S}"/systemd/cloud-config.service
403 - systemd_dounit "${S}"/systemd/cloud-config.target
404 - systemd_dounit "${S}"/systemd/cloud-final.service
405 - systemd_dounit "${S}"/systemd/cloud-init-local.service
406 - systemd_dounit "${S}"/systemd/cloud-init.service
407 -}
408
409 diff --git a/app-emulation/cloud-init/files/cloud-init-0.7.5-tests-exclude.patch b/app-emulation/cloud-init/files/cloud-init-0.7.5-tests-exclude.patch
410 deleted file mode 100644
411 index 225f1a1..0000000
412 --- a/app-emulation/cloud-init/files/cloud-init-0.7.5-tests-exclude.patch
413 +++ /dev/null
414 @@ -1,12 +0,0 @@
415 -diff -ur cloud-init-0.7.5.orig/setup.py cloud-init-0.7.5/setup.py
416 ---- setup.py 2014-04-02 02:26:07.000000000 +0800
417 -+++ setup.py 2014-05-01 23:38:15.848225975 +0800
418 -@@ -114,7 +114,7 @@
419 - author='Scott Moser',
420 - author_email='scott.moser@×××××××××.com',
421 - url='http://launchpad.net/cloud-init/',
422 -- packages=setuptools.find_packages(exclude=['tests']),
423 -+ packages=setuptools.find_packages(exclude=['tests','tests.*']),
424 - scripts=['bin/cloud-init',
425 - 'tools/cloud-init-per',
426 - ],
427
428 diff --git a/app-emulation/cloud-init/files/growpart b/app-emulation/cloud-init/files/growpart
429 deleted file mode 100644
430 index 4b67d8b..0000000
431 --- a/app-emulation/cloud-init/files/growpart
432 +++ /dev/null
433 @@ -1,778 +0,0 @@
434 -#!/bin/sh
435 -# Copyright (C) 2011 Canonical Ltd.
436 -# Copyright (C) 2013 Hewlett-Packard Development Company, L.P.
437 -#
438 -# Authors: Scott Moser <smoser@×××××××××.com>
439 -# Juerg Haefliger <juerg.haefliger@××.com>
440 -#
441 -# This program is free software: you can redistribute it and/or modify
442 -# it under the terms of the GNU General Public License as published by
443 -# the Free Software Foundation, version 3 of the License.
444 -#
445 -# This program is distributed in the hope that it will be useful,
446 -# but WITHOUT ANY WARRANTY; without even the implied warranty of
447 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
448 -# GNU General Public License for more details.
449 -#
450 -# You should have received a copy of the GNU General Public License
451 -# along with this program. If not, see <http://www.gnu.org/licenses/>.
452 -
453 -# the fudge factor. if within this many bytes dont bother
454 -FUDGE=${GROWPART_FUDGE:-$((1024*1024))}
455 -TEMP_D=""
456 -RESTORE_FUNC=""
457 -RESTORE_HUMAN=""
458 -VERBOSITY=0
459 -DISK=""
460 -PART=""
461 -PT_UPDATE=false
462 -DRY_RUN=0
463 -
464 -SFDISK_VERSION=""
465 -SFDISK_2_26="22600"
466 -MBR_BACKUP=""
467 -GPT_BACKUP=""
468 -_capture=""
469 -
470 -error() {
471 - echo "$@" 1>&2
472 -}
473 -
474 -fail() {
475 - [ $# -eq 0 ] || echo "FAILED:" "$@"
476 - exit 2
477 -}
478 -
479 -nochange() {
480 - echo "NOCHANGE:" "$@"
481 - exit 1
482 -}
483 -
484 -changed() {
485 - echo "CHANGED:" "$@"
486 - exit 0
487 -}
488 -
489 -change() {
490 - echo "CHANGE:" "$@"
491 - exit 0
492 -}
493 -
494 -cleanup() {
495 - if [ -n "${RESTORE_FUNC}" ]; then
496 - error "***** WARNING: Resize failed, attempting to revert ******"
497 - if ${RESTORE_FUNC} ; then
498 - error "***** Appears to have gone OK ****"
499 - else
500 - error "***** FAILED! ******"
501 - if [ -n "${RESTORE_HUMAN}" -a -f "${RESTORE_HUMAN}" ]; then
502 - error "**** original table looked like: ****"
503 - cat "${RESTORE_HUMAN}" 1>&2
504 - else
505 - error "We seem to have not saved the partition table!"
506 - fi
507 - fi
508 - fi
509 - [ -z "${TEMP_D}" -o ! -d "${TEMP_D}" ] || rm -Rf "${TEMP_D}"
510 -}
511 -
512 -debug() {
513 - local level=${1}
514 - shift
515 - [ "${level}" -gt "${VERBOSITY}" ] && return
516 - if [ "${DEBUG_LOG}" ]; then
517 - echo "$@" >>"${DEBUG_LOG}"
518 - else
519 - error "$@"
520 - fi
521 -}
522 -
523 -debugcat() {
524 - local level="$1"
525 - shift;
526 - [ "${level}" -gt "$VERBOSITY" ] && return
527 - if [ "${DEBUG_LOG}" ]; then
528 - cat "$@" >>"${DEBUG_LOG}"
529 - else
530 - cat "$@" 1>&2
531 - fi
532 -}
533 -
534 -mktemp_d() {
535 - # just a mktemp -d that doens't need mktemp if its not there.
536 - _RET=$(mktemp -d "${TMPDIR:-/tmp}/${0##*/}.XXXXXX" 2>/dev/null) &&
537 - return
538 - _RET=$(umask 077 && t="${TMPDIR:-/tmp}/${0##*/}.$$" &&
539 - mkdir "${t}" && echo "${t}")
540 - return
541 -}
542 -
543 -Usage() {
544 - cat <<EOF
545 -${0##*/} disk partition
546 - rewrite partition table so that partition takes up all the space it can
547 - options:
548 - -h | --help print Usage and exit
549 - --fudge F if part could be resized, but change would be
550 - less than 'F' bytes, do not resize (default: ${FUDGE})
551 - -N | --dry-run only report what would be done, show new 'sfdisk -d'
552 - -v | --verbose increase verbosity / debug
553 - -u | --update R update the the kernel partition table info after growing
554 - this requires kernel support and 'partx --update'
555 - R is one of:
556 - - 'auto' : [default] update partition if possible
557 - - 'force' : try despite sanity checks (fail on failure)
558 - - 'off' : do not attempt
559 - - 'on' : fail if sanity checks indicate no support
560 -
561 - Example:
562 - - ${0##*/} /dev/sda 1
563 - Resize partition 1 on /dev/sda
564 -EOF
565 -}
566 -
567 -bad_Usage() {
568 - Usage 1>&2
569 - error "$@"
570 - exit 2
571 -}
572 -
573 -sfdisk_restore_legacy() {
574 - sfdisk --no-reread "${DISK}" -I "${MBR_BACKUP}"
575 -}
576 -
577 -sfdisk_restore() {
578 - # files are named: sfdisk-<device>-<offset>.bak
579 - local f="" offset="" fails=0
580 - for f in "${MBR_BACKUP}"*.bak; do
581 - [ -f "$f" ] || continue
582 - offset=${f##*-}
583 - offset=${offset%.bak}
584 - [ "$offset" = "$f" ] && {
585 - error "WARN: confused by file $f";
586 - continue;
587 - }
588 - dd "if=$f" "of=${DISK}" seek=$(($offset)) bs=1 conv=notrunc ||
589 - { error "WARN: failed restore from $f"; fails=$(($fails+1)); }
590 - done
591 - return $fails
592 -}
593 -
594 -sfdisk_worked_but_blkrrpart_failed() {
595 - local ret="$1" output="$2"
596 - # exit code found was just 1, but dont insist on that
597 - #[ $ret -eq 1 ] || return 1
598 - # Successfully wrote the new partition table
599 - grep -qi "Success.* wrote.* new.* partition" "$output" &&
600 - grep -qi "BLKRRPART: Device or resource busy" "$output"
601 - return
602 -}
603 -
604 -get_sfdisk_version() {
605 - # set SFDISK_VERSION to MAJOR*10000+MINOR*100+MICRO
606 - local out oifs="$IFS" ver=""
607 - [ -n "$SFDISK_VERSION" ] && return 0
608 - # expected output: sfdisk from util-linux 2.25.2
609 - out=$(sfdisk --version) ||
610 - { error "failed to get sfdisk version"; return 1; }
611 - set -- $out
612 - ver=$4
613 - case "$ver" in
614 - [0-9]*.[0-9]*.[0-9]|[0-9].[0-9]*)
615 - IFS="."; set -- $ver; IFS="$oifs"
616 - SFDISK_VERSION=$(($1*10000+$2*100+${3:-0}))
617 - return 0;;
618 - *) error "unexpected output in sfdisk --version [$out]"
619 - return 1;;
620 - esac
621 -}
622 -
623 -resize_sfdisk() {
624 - local humanpt="${TEMP_D}/recovery"
625 - local mbr_backup="${TEMP_D}/orig.save"
626 - local restore_func=""
627 - local format="$1"
628 -
629 - local change_out=${TEMP_D}/change.out
630 - local dump_out=${TEMP_D}/dump.out
631 - local new_out=${TEMP_D}/new.out
632 - local dump_mod=${TEMP_D}/dump.mod
633 - local tmp="${TEMP_D}/tmp.out"
634 - local err="${TEMP_D}/err.out"
635 - local mbr_max_512="4294967296"
636 -
637 - local pt_start pt_size pt_end max_end new_size change_info dpart
638 - local sector_num sector_size disk_size tot out
639 -
640 - rqe sfd_list sfdisk --list --unit=S "$DISK" >"$tmp" ||
641 - fail "failed: sfdisk --list $DISK"
642 - if [ "${SFDISK_VERSION}" -lt ${SFDISK_2_26} ]; then
643 - # exected output contains: Units: sectors of 512 bytes, ...
644 - out=$(awk '$1 == "Units:" && $5 ~ /bytes/ { print $4 }' "$tmp") ||
645 - fail "failed to read sfdisk output"
646 - if [ -z "$out" ]; then
647 - error "WARN: sector size not found in sfdisk output, assuming 512"
648 - sector_size=512
649 - else
650 - sector_size="$out"
651 - fi
652 - local _w _cyl _w1 _heads _w2 sectors _w3 t s
653 - # show-size is in units of 1024 bytes (same as /proc/partitions)
654 - t=$(sfdisk --show-size "${DISK}") ||
655 - fail "failed: sfdisk --show-size $DISK"
656 - disk_size=$((t*1024))
657 - sector_num=$(($disk_size/$sector_size))
658 - msg="disk size '$disk_size' not evenly div by sector size '$sector_size'"
659 - [ "$((${disk_size}%${sector_size}))" -eq 0 ] ||
660 - error "WARN: $msg"
661 - restore_func=sfdisk_restore_legacy
662 - else
663 - # --list first line output:
664 - # Disk /dev/vda: 20 GiB, 21474836480 bytes, 41943040 sectors
665 - local _x
666 - read _x _x _x _x disk_size _x sector_num _x < "$tmp"
667 - sector_size=$((disk_size/$sector_num))
668 - restore_func=sfdisk_restore
669 - fi
670 -
671 - debug 1 "$sector_num sectors of $sector_size. total size=${disk_size} bytes"
672 - [ $(($disk_size/512)) -gt $mbr_max_512 ] &&
673 - debug 1 "WARN: disk is larger than 2TB. additional space will go unused."
674 -
675 - rqe sfd_dump sfdisk --unit=S --dump "${DISK}" >"${dump_out}" ||
676 - fail "failed to dump sfdisk info for ${DISK}"
677 - RESTORE_HUMAN="$dump_out"
678 -
679 - {
680 - echo "## sfdisk --unit=S --dump ${DISK}"
681 - cat "${dump_out}"
682 - } >"$humanpt"
683 -
684 - [ $? -eq 0 ] || fail "failed to save sfdisk -d output"
685 - RESTORE_HUMAN="$humanpt"
686 -
687 - debugcat 1 "$humanpt"
688 -
689 - sed -e 's/,//g; s/start=/start /; s/size=/size /' "${dump_out}" \
690 - >"${dump_mod}" ||
691 - fail "sed failed on dump output"
692 -
693 - dpart="${DISK}${PART}" # disk and partition number
694 - if [ -b "${DISK}p${PART}" -a "${DISK%[0-9]}" != "${DISK}" ]; then
695 - # for block devices that end in a number (/dev/nbd0)
696 - # the partition is "<name>p<partition_number>" (/dev/nbd0p1)
697 - dpart="${DISK}p${PART}"
698 - elif [ "${DISK#/dev/loop[0-9]}" != "${DISK}" ]; then
699 - # for /dev/loop devices, sfdisk output will be <name>p<number>
700 - # format also, even though there is not a device there.
701 - dpart="${DISK}p${PART}"
702 - fi
703 -
704 - pt_start=$(awk '$1 == pt { print $4 }' "pt=${dpart}" <"${dump_mod}") &&
705 - pt_size=$(awk '$1 == pt { print $6 }' "pt=${dpart}" <"${dump_mod}") &&
706 - [ -n "${pt_start}" -a -n "${pt_size}" ] &&
707 - pt_end=$((${pt_size}+${pt_start})) ||
708 - fail "failed to get start and end for ${dpart} in ${DISK}"
709 -
710 - # find the minimal starting location that is >= pt_end
711 - max_end=$(awk '$3 == "start" { if($4 >= pt_end && $4 < min)
712 - { min = $4 } } END { printf("%s\n",min); }' \
713 - min=${sector_num} pt_end=${pt_end} "${dump_mod}") &&
714 - [ -n "${max_end}" ] ||
715 - fail "failed to get max_end for partition ${PART}"
716 -
717 - mbr_max_sectors=$((mbr_max_512*$((sector_size/512))))
718 - if [ "$max_end" -gt "$mbr_max_sectors" ]; then
719 - max_end=$mbr_max_sectors
720 - fi
721 -
722 - if [ "$format" = "gpt" ]; then
723 - # sfdisk respects 'last-lba' in input, and complains about
724 - # partitions that go past that. without it, it does the right thing.
725 - sed -i '/^last-lba:/d' "$dump_out" ||
726 - fail "failed to remove last-lba from output"
727 - fi
728 -
729 - local gpt_second_size="33"
730 - if [ "${max_end}" -gt "$((${sector_num}-${gpt_second_size}))" ]; then
731 - # if mbr allow subsequent conversion to gpt without shrinking the
732 - # partition. safety net at cost of 33 sectors, seems reasonable.
733 - # if gpt, we can't write there anyway.
734 - debug 1 "padding ${gpt_second_size} sectors for gpt secondary header"
735 - max_end=$((${sector_num}-${gpt_second_size}))
736 - fi
737 -
738 - debug 1 "max_end=${max_end} tot=${sector_num} pt_end=${pt_end}" \
739 - "pt_start=${pt_start} pt_size=${pt_size}"
740 - [ $((${pt_end})) -eq ${max_end} ] &&
741 - nochange "partition ${PART} is size ${pt_size}. it cannot be grown"
742 - [ $((${pt_end}+(${FUDGE}/$sector_size))) -gt ${max_end} ] &&
743 - nochange "partition ${PART} could only be grown by" \
744 - "$((${max_end}-${pt_end})) [fudge=$((${FUDGE}/$sector_size))]"
745 -
746 - # now, change the size for this partition in ${dump_out} to be the
747 - # new size
748 - new_size=$((${max_end}-${pt_start}))
749 - sed "\|^\s*${dpart} |s/${pt_size},/${new_size},/" "${dump_out}" \
750 - >"${new_out}" ||
751 - fail "failed to change size in output"
752 -
753 - change_info="partition=${PART} start=${pt_start} old: size=${pt_size} end=${pt_end} new: size=${new_size},end=${max_end}"
754 - if [ ${DRY_RUN} -ne 0 ]; then
755 - echo "CHANGE: ${change_info}"
756 - {
757 - echo "# === old sfdisk -d ==="
758 - cat "${dump_out}"
759 - echo "# === new sfdisk -d ==="
760 - cat "${new_out}"
761 - } 1>&2
762 - exit 0
763 - fi
764 -
765 - MBR_BACKUP="${mbr_backup}"
766 - LANG=C sfdisk --no-reread "${DISK}" --force \
767 - -O "${mbr_backup}" <"${new_out}" >"${change_out}" 2>&1
768 - ret=$?
769 - [ $ret -eq 0 ] || RESTORE_FUNC="${restore_func}"
770 -
771 - if [ $ret -eq 0 ]; then
772 - :
773 - elif $PT_UPDATE &&
774 - sfdisk_worked_but_blkrrpart_failed "$ret" "${change_out}"; then
775 - # if the command failed, but it looks like only because
776 - # the device was busy and we have pt_update, then go on
777 - debug 1 "sfdisk failed, but likely only because of blkrrpart"
778 - else
779 - error "attempt to resize ${DISK} failed. sfdisk output below:"
780 - sed 's,^,| ,' "${change_out}" 1>&2
781 - fail "failed to resize"
782 - fi
783 -
784 - rq pt_update pt_update "$DISK" "$PART" ||
785 - fail "pt_resize failed"
786 -
787 - RESTORE_FUNC=""
788 -
789 - changed "${change_info}"
790 -
791 - # dump_out looks something like:
792 - ## partition table of /tmp/out.img
793 - #unit: sectors
794 - #
795 - #/tmp/out.img1 : start= 1, size= 48194, Id=83
796 - #/tmp/out.img2 : start= 48195, size= 963900, Id=83
797 - #/tmp/out.img3 : start= 1012095, size= 305235, Id=82
798 - #/tmp/out.img4 : start= 1317330, size= 771120, Id= 5
799 - #/tmp/out.img5 : start= 1317331, size= 642599, Id=83
800 - #/tmp/out.img6 : start= 1959931, size= 48194, Id=83
801 - #/tmp/out.img7 : start= 2008126, size= 80324, Id=83
802 -}
803 -
804 -gpt_restore() {
805 - sgdisk -l "${GPT_BACKUP}" "${DISK}"
806 -}
807 -
808 -resize_sgdisk() {
809 - GPT_BACKUP="${TEMP_D}/pt.backup"
810 -
811 - local pt_info="${TEMP_D}/pt.info"
812 - local pt_pretend="${TEMP_D}/pt.pretend"
813 - local pt_data="${TEMP_D}/pt.data"
814 - local out="${TEMP_D}/out"
815 -
816 - local dev="disk=${DISK} partition=${PART}"
817 -
818 - local pt_start pt_end pt_size last pt_max code guid name new_size
819 - local old new change_info sector_size
820 -
821 - # Dump the original partition information and details to disk. This is
822 - # used in case something goes wrong and human interaction is required
823 - # to revert any changes.
824 - rqe sgd_info sgdisk "--info=${PART}" --print "${DISK}" >"${pt_info}" ||
825 - fail "${dev}: failed to dump original sgdisk info"
826 - RESTORE_HUMAN="${pt_info}"
827 -
828 - sector_size=$(awk '$0 ~ /^Logical sector size:.*bytes/ { print $4 }' \
829 - "$pt_info") && [ -n "$sector_size" ] || {
830 - sector_size=512
831 - error "WARN: did not find sector size, assuming 512"
832 - }
833 -
834 - debug 1 "$dev: original sgdisk info:"
835 - debugcat 1 "${pt_info}"
836 -
837 - # Pretend to move the backup GPT header to the end of the disk and dump
838 - # the resulting partition information. We use this info to determine if
839 - # we have to resize the partition.
840 - rqe sgd_pretend sgdisk --pretend --move-second-header \
841 - --print "${DISK}" >"${pt_pretend}" ||
842 - fail "${dev}: failed to dump pretend sgdisk info"
843 -
844 - debug 1 "$dev: pretend sgdisk info"
845 - debugcat 1 "${pt_pretend}"
846 -
847 - # Extract the partition data from the pretend dump
848 - awk 'found { print } ; $1 == "Number" { found = 1 }' \
849 - "${pt_pretend}" >"${pt_data}" ||
850 - fail "${dev}: failed to parse pretend sgdisk info"
851 -
852 - # Get the start and end sectors of the partition to be grown
853 - pt_start=$(awk '$1 == '"${PART}"' { print $2 }' "${pt_data}") &&
854 - [ -n "${pt_start}" ] ||
855 - fail "${dev}: failed to get start sector"
856 - pt_end=$(awk '$1 == '"${PART}"' { print $3 }' "${pt_data}") &&
857 - [ -n "${pt_end}" ] ||
858 - fail "${dev}: failed to get end sector"
859 - pt_size="$((${pt_end} - ${pt_start}))"
860 -
861 - # Get the last usable sector
862 - last=$(awk '/last usable sector is/ { print $NF }' \
863 - "${pt_pretend}") && [ -n "${last}" ] ||
864 - fail "${dev}: failed to get last usable sector"
865 -
866 - # Find the minimal start sector that is >= pt_end
867 - pt_max=$(awk '{ if ($2 >= pt_end && $2 < min) { min = $2 } } END \
868 - { print min }' min="${last}" pt_end="${pt_end}" \
869 - "${pt_data}") && [ -n "${pt_max}" ] ||
870 - fail "${dev}: failed to find max end sector"
871 -
872 - debug 1 "${dev}: pt_start=${pt_start} pt_end=${pt_end}" \
873 - "pt_size=${pt_size} pt_max=${pt_max} last=${last}"
874 -
875 - # Check if the partition can be grown
876 - [ "${pt_end}" -eq "${pt_max}" ] &&
877 - nochange "${dev}: size=${pt_size}, it cannot be grown"
878 - [ "$((${pt_end} + ${FUDGE}/${sector_size}))" -gt "${pt_max}" ] &&
879 - nochange "${dev}: could only be grown by" \
880 - "$((${pt_max} - ${pt_end})) [fudge=$((${FUDGE}/$sector_size))]"
881 -
882 - # The partition can be grown if we made it here. Get some more info
883 - # about it so we can do it properly.
884 - # FIXME: Do we care about the attribute flags?
885 - code=$(awk '/^Partition GUID code:/ { print $4 }' "${pt_info}")
886 - guid=$(awk '/^Partition unique GUID:/ { print $4 }' "${pt_info}")
887 - name=$(awk '/^Partition name:/ { gsub(/'"'"'/, "") ; \
888 - if (NF >= 3) print substr($0, index($0, $3)) }' "${pt_info}")
889 - [ -n "${code}" -a -n "${guid}" ] ||
890 - fail "${dev}: failed to parse sgdisk details"
891 -
892 - debug 1 "${dev}: code=${code} guid=${guid} name='${name}'"
893 - local wouldrun=""
894 - [ "$DRY_RUN" -ne 0 ] && wouldrun="would-run"
895 -
896 - # Calculate the new size of the partition
897 - new_size=$((${pt_max} - ${pt_start}))
898 - old="old: size=${pt_size},end=${pt_end}"
899 - new="new: size=${new_size},end=${pt_max}"
900 - change_info="${dev}: start=${pt_start} ${old} ${new}"
901 -
902 - # Backup the current partition table, we're about to modify it
903 - rq sgd_backup $wouldrun sgdisk "--backup=${GPT_BACKUP}" "${DISK}" ||
904 - fail "${dev}: failed to backup the partition table"
905 -
906 - # Modify the partition table. We do it all in one go (the order is
907 - # important!):
908 - # - move the GPT backup header to the end of the disk
909 - # - delete the partition
910 - # - recreate the partition with the new size
911 - # - set the partition code
912 - # - set the partition GUID
913 - # - set the partition name
914 - rq sgdisk_mod $wouldrun sgdisk --move-second-header "--delete=${PART}" \
915 - "--new=${PART}:${pt_start}:${pt_max}" \
916 - "--typecode=${PART}:${code}" \
917 - "--partition-guid=${PART}:${guid}" \
918 - "--change-name=${PART}:${name}" "${DISK}" &&
919 - rq pt_update $wouldrun pt_update "$DISK" "$PART" || {
920 - RESTORE_FUNC=gpt_restore
921 - fail "${dev}: failed to repartition"
922 - }
923 -
924 - # Dry run
925 - [ "${DRY_RUN}" -ne 0 ] && change "${change_info}"
926 -
927 - changed "${change_info}"
928 -}
929 -
930 -kver_to_num() {
931 - local kver="$1" maj="" min="" mic="0"
932 - kver=${kver%%-*}
933 - maj=${kver%%.*}
934 - min=${kver#${maj}.}
935 - min=${min%%.*}
936 - mic=${kver#${maj}.${min}.}
937 - [ "$kver" = "$mic" ] && mic=0
938 - _RET=$(($maj*1000*1000+$min*1000+$mic))
939 -}
940 -
941 -kver_cmp() {
942 - local op="$2" n1="" n2=""
943 - kver_to_num "$1"
944 - n1="$_RET"
945 - kver_to_num "$3"
946 - n2="$_RET"
947 - [ $n1 $op $n2 ]
948 -}
949 -
950 -rq() {
951 - # runquieterror(label, command)
952 - # gobble stderr of a command unless it errors
953 - local label="$1" ret="" efile=""
954 - efile="$TEMP_D/$label.err"
955 - shift;
956 -
957 - local rlabel="running"
958 - [ "$1" = "would-run" ] && rlabel="would-run" && shift
959 -
960 - local cmd="" x=""
961 - for x in "$@"; do
962 - [ "${x#* }" != "$x" -o "${x#* \"}" != "$x" ] && x="'$x'"
963 - cmd="$cmd $x"
964 - done
965 - cmd=${cmd# }
966 -
967 - debug 2 "$rlabel[$label][$_capture]" "$cmd"
968 - [ "$rlabel" = "would-run" ] && return 0
969 -
970 - if [ "${_capture}" = "erronly" ]; then
971 - "$@" 2>"$TEMP_D/$label.err"
972 - ret=$?
973 - else
974 - "$@" >"$TEMP_D/$label.err" 2>&1
975 - ret=$?
976 - fi
977 - if [ $ret -ne 0 ]; then
978 - error "failed [$label:$ret]" "$@"
979 - cat "$efile" 1>&2
980 - fi
981 - return $ret
982 -}
983 -
984 -rqe() {
985 - local _capture="erronly"
986 - rq "$@"
987 -}
988 -
989 -verify_ptupdate() {
990 - local input="$1" found="" reason="" kver=""
991 -
992 - # we can always satisfy 'off'
993 - if [ "$input" = "off" ]; then
994 - _RET="false";
995 - return 0;
996 - fi
997 -
998 - if command -v partx >/dev/null 2>&1; then
999 - local out="" ret=0
1000 - out=$(partx --help 2>&1)
1001 - ret=$?
1002 - if [ $ret -eq 0 ]; then
1003 - echo "$out" | grep -q -- --update || {
1004 - reason="partx has no '--update' flag in usage."
1005 - found="off"
1006 - }
1007 - else
1008 - reason="'partx --help' returned $ret. assuming it is old."
1009 - found="off"
1010 - fi
1011 - else
1012 - reason="no 'partx' command"
1013 - found="off"
1014 - fi
1015 -
1016 - if [ -z "$found" ]; then
1017 - if [ "$(uname)" != "Linux" ]; then
1018 - reason="Kernel is not Linux per uname."
1019 - found="off"
1020 - fi
1021 - fi
1022 -
1023 - if [ -z "$found" ]; then
1024 - kver=$(uname -r) || debug 1 "uname -r failed!"
1025 -
1026 - if ! kver_cmp "${kver-0.0.0}" -ge 3.8.0; then
1027 - reason="Kernel '$kver' < 3.8.0."
1028 - found="off"
1029 - fi
1030 - fi
1031 -
1032 - if [ -z "$found" ]; then
1033 - _RET="true"
1034 - return 0
1035 - fi
1036 -
1037 - case "$input" in
1038 - on) error "$reason"; return 1;;
1039 - auto)
1040 - _RET="false";
1041 - debug 1 "partition update disabled: $reason"
1042 - return 0;;
1043 - force)
1044 - _RET="true"
1045 - error "WARNING: ptupdate forced on even though: $reason"
1046 - return 0;;
1047 - esac
1048 - error "unknown input '$input'";
1049 - return 1;
1050 -}
1051 -
1052 -pt_update() {
1053 - local dev="$1" part="$2" update="${3:-$PT_UPDATE}"
1054 - if ! $update; then
1055 - return 0
1056 - fi
1057 - # partx only works on block devices (do not run on file)
1058 - [ -b "$dev" ] || return 0
1059 - partx --update "$part" "$dev"
1060 -}
1061 -
1062 -has_cmd() {
1063 - command -v "${1}" >/dev/null 2>&1
1064 -}
1065 -
1066 -resize_sgdisk_gpt() {
1067 - resize_sgdisk gpt
1068 -}
1069 -
1070 -resize_sgdisk_dos() {
1071 - fail "unable to resize dos label with sgdisk"
1072 -}
1073 -
1074 -resize_sfdisk_gpt() {
1075 - resize_sfdisk gpt
1076 -}
1077 -
1078 -resize_sfdisk_dos() {
1079 - resize_sfdisk dos
1080 -}
1081 -
1082 -get_table_format() {
1083 - local out="" disk="$1"
1084 - if has_cmd blkid && out=$(blkid -o value -s PTTYPE "$disk") &&
1085 - [ "$out" = "dos" -o "$out" = "gpt" ]; then
1086 - _RET="$out"
1087 - return
1088 - fi
1089 - _RET="dos"
1090 - if [ ${SFDISK_VERSION} -lt ${SFDISK_2_26} ] &&
1091 - out=$(sfdisk --id --force "$disk" 1 2>/dev/null); then
1092 - if [ "$out" = "ee" ]; then
1093 - _RET="gpt"
1094 - else
1095 - _RET="dos"
1096 - fi
1097 - return
1098 - elif out=$(LANG=C sfdisk --list "$disk"); then
1099 - out=$(echo "$out" | sed -e '/Disklabel type/!d' -e 's/.*: //')
1100 - case "$out" in
1101 - gpt|dos) _RET="$out";;
1102 - *) error "WARN: unknown label $out";;
1103 - esac
1104 - fi
1105 -}
1106 -
1107 -get_resizer() {
1108 - local format="$1" user=${2:-"auto"}
1109 -
1110 - case "$user" in
1111 - sgdisk) _RET="resize_sgdisk_$format"; return;;
1112 - sfdisk) _RET="resize_sfdisk_$format"; return;;
1113 - auto) :;;
1114 - *) error "unexpected input: '$user'";;
1115 - esac
1116 -
1117 - if [ "$format" = "dos" ]; then
1118 - _RET="resize_sfdisk_dos"
1119 - return 0
1120 - fi
1121 -
1122 - if [ "${SFDISK_VERSION}" -ge ${SFDISK_2_26} ]; then
1123 - _RET="resize_sfdisk_gpt"
1124 - elif has_cmd sgdisk; then
1125 - _RET="resize_sgdisk_$format"
1126 - else
1127 - error "no tools available to resize disk with '$format'"
1128 - return 1
1129 - fi
1130 - return 0
1131 -}
1132 -
1133 -pt_update="auto"
1134 -resizer=${GROWPART_RESIZER:-"auto"}
1135 -while [ $# -ne 0 ]; do
1136 - cur=${1}
1137 - next=${2}
1138 - case "$cur" in
1139 - -h|--help)
1140 - Usage
1141 - exit 0
1142 - ;;
1143 - --fudge)
1144 - FUDGE=${next}
1145 - shift
1146 - ;;
1147 - -N|--dry-run)
1148 - DRY_RUN=1
1149 - ;;
1150 - -u|--update|--update=*)
1151 - if [ "${cur#--update=}" != "$cur" ]; then
1152 - next="${cur#--update=}"
1153 - else
1154 - shift
1155 - fi
1156 - case "$next" in
1157 - off|auto|force|on) pt_update=$next;;
1158 - *) fail "unknown --update option: $next";;
1159 - esac
1160 - ;;
1161 - -v|--verbose)
1162 - VERBOSITY=$(($VERBOSITY+1))
1163 - ;;
1164 - --)
1165 - shift
1166 - break
1167 - ;;
1168 - -*)
1169 - fail "unknown option ${cur}"
1170 - ;;
1171 - *)
1172 - if [ -z "${DISK}" ]; then
1173 - DISK=${cur}
1174 - else
1175 - [ -z "${PART}" ] || fail "confused by arg ${cur}"
1176 - PART=${cur}
1177 - fi
1178 - ;;
1179 - esac
1180 - shift
1181 -done
1182 -
1183 -[ -n "${DISK}" ] || bad_Usage "must supply disk and partition-number"
1184 -[ -n "${PART}" ] || bad_Usage "must supply partition-number"
1185 -
1186 -has_cmd "sfdisk" || fail "sfdisk not found"
1187 -get_sfdisk_version || fail
1188 -
1189 -[ -e "${DISK}" ] || fail "${DISK}: does not exist"
1190 -
1191 -[ "${PART#*[!0-9]}" = "${PART}" ] || fail "partition-number must be a number"
1192 -
1193 -verify_ptupdate "$pt_update" || fail
1194 -PT_UPDATE=$_RET
1195 -
1196 -debug 1 "update-partition set to $PT_UPDATE"
1197 -
1198 -mktemp_d && TEMP_D="${_RET}" || fail "failed to make temp dir"
1199 -trap cleanup 0 # EXIT - some shells may not like 'EXIT' but are ok with 0
1200 -
1201 -# get the ID of the first partition to determine if it's MBR or GPT
1202 -get_table_format "$DISK" || fail
1203 -format=$_RET
1204 -get_resizer "$format" "$resizer" ||
1205 - fail "failed to get a resizer for id '$id'"
1206 -resizer=$_RET
1207 -
1208 -debug 1 "resizing $PART on $DISK using $resizer"
1209 -"$resizer"
1210 -
1211 -# vi: ts=4 noexpandtab