8
Usage: ${0##*/} uec-tarball [output]
10
Supports converting from uec tarball or raw unpartitioned disk image.
13
error() { echo "$(date -R):" "$@" 1>&2; }
14
fail() { [ $# -eq 0 ] || error "$@"; exit 1; }
16
[ -z "$MP" ] || umount "$MP"
17
[ -z "$TEMP_D" -o ! -d "$TEMP_D" ] || rm -Rf "${TEMP_D}";
20
[ "$1" = "-h" -o "$1" = "--help" ] && { Usage; exit 0; }
21
[ $# -eq 1 -o $# -eq 2 ] || { Usage 1>&2; exit 1; }
22
[ -f "$1" ] || { Usage 1>&2; error "$1: not a file"; exit 1; }
24
[ "$(id -u)" = "0" ] || fail "must be root"
26
TEMP_D=$(mktemp -d "${TMPDIR:-/tmp}/${0##*/}.XXXXXX") || fail "failed mktemp"
32
if $(LANG=C file "$uec" | grep -qi "filesystem data"); then
33
[ -n "$output" ] || output="${uec%.img}-root.tar.gz";
36
[ -n "$output" ] || output="${uec%.tar.gz}-root.tar.gz";
37
error "extracting *.img from ${uec}"
38
tar -C ${TEMP_D} --wildcards "*.img" -Sxvzf "$uec" ||
39
fail "failed extract $uec"
42
for cand in "${TEMP_D}/"*.img; do
43
[ -z "$img" ] || fail "multiple .img files in $uec"
44
[ -f "$cand" ] && img="$cand"
47
[ -n "$img" ] || fail "failed to find image in $uec"
50
error "converting ${img} to ${output}"
51
mkdir "${TEMP_D}/mp" && mount -o ro "$img" "${TEMP_D}/mp" &&
52
MP="$TEMP_D/mp" || fail "failed to mount $img"
54
error "copying contents of ${img#${TEMP_D}/} in ${uec} to ${output}"
55
tar -C "$MP" -cpSzf "${output}" --numeric-owner . ||
56
fail "failed to create ${output}"
58
error "finished. wrote to ${output}"
1
#!/usr/bin/env python2.7
2
# Copyright 2014 Canonical Ltd. This software is licensed under the
3
# GNU Affero General Public License version 3 (see the file LICENSE).
5
"""Convert a "UEC" root image file to a root tarball.
7
This requires root privileges, because it needs to loop-mount the image file
8
in order to read its contents.
11
from __future__ import (
21
from provisioningserver.import_images import uec2roottar
24
if __name__ == "__main__":
25
parser = uec2roottar.make_argparser(__doc__)
26
args = parser.parse_args()
27
uec2roottar.main(args)