~ubuntu-branches/ubuntu/utopic/maas/utopic-security

« back to all changes in this revision

Viewing changes to scripts/uec2roottar

  • Committer: Package Import Robot
  • Author(s): Julian Edwards, Julian Edwards, Andres Rodriguez
  • Date: 2014-08-21 18:38:27 UTC
  • mfrom: (1.2.34)
  • Revision ID: package-import@ubuntu.com-20140821183827-9xyb5u2o4l8g3zxj
Tags: 1.6.1+bzr2550-0ubuntu1
* New upstream bugfix release:
  - Auto-link node MACs to Networks (LP: #1341619)

[ Julian Edwards ]
* debian/maas-region-controller.postinst: Don't restart RabbitMQ on
  upgrades, just ensure it's running.  Should prevent a race with the
  cluster celery restarting.
* debian/rules: Pull upstream branch from the right place.

[ Andres Rodriguez ]
* debian/maas-region-controller.postinst: Ensure cluster celery is
  started if it also runs on the region.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
 
3
 
TEMP_D=""
4
 
MP=""
5
 
 
6
 
Usage() {
7
 
cat <<EOF
8
 
   Usage: ${0##*/} uec-tarball [output]
9
 
 
10
 
   Supports converting from uec tarball or raw unpartitioned disk image.
11
 
EOF
12
 
}
13
 
error() { echo "$(date -R):" "$@" 1>&2; }
14
 
fail() { [ $# -eq 0 ] || error "$@"; exit 1; }
15
 
cleanup() { 
16
 
  [ -z "$MP" ] || umount "$MP"
17
 
  [ -z "$TEMP_D" -o ! -d "$TEMP_D" ] || rm -Rf "${TEMP_D}";
18
 
}
19
 
 
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; }
23
 
 
24
 
[ "$(id -u)" = "0" ] || fail "must be root"
25
 
 
26
 
TEMP_D=$(mktemp -d "${TMPDIR:-/tmp}/${0##*/}.XXXXXX") || fail "failed mktemp"
27
 
trap cleanup EXIT
28
 
 
29
 
uec="$1"
30
 
output=${2}
31
 
 
32
 
if $(LANG=C file "$uec" | grep -qi "filesystem data"); then
33
 
   [ -n "$output" ] || output="${uec%.img}-root.tar.gz"; 
34
 
   img="$uec"
35
 
else
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"
40
 
 
41
 
   img=""
42
 
   for cand in "${TEMP_D}/"*.img; do
43
 
      [ -z "$img" ] || fail "multiple .img files in $uec"
44
 
      [ -f "$cand" ] && img="$cand"
45
 
   done
46
 
 
47
 
   [ -n "$img" ] || fail "failed to find image in $uec"
48
 
fi
49
 
 
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"
53
 
 
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}"
57
 
 
58
 
error "finished. wrote to ${output}"
59
 
exit 0
 
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).
 
4
 
 
5
"""Convert a "UEC" root image file to a root tarball.
 
6
 
 
7
This requires root privileges, because it needs to loop-mount the image file
 
8
in order to read its contents.
 
9
"""
 
10
 
 
11
from __future__ import (
 
12
    absolute_import,
 
13
    print_function,
 
14
    unicode_literals,
 
15
    )
 
16
 
 
17
str = None
 
18
 
 
19
__metaclass__ = type
 
20
 
 
21
from provisioningserver.import_images import uec2roottar
 
22
 
 
23
 
 
24
if __name__ == "__main__":
 
25
    parser = uec2roottar.make_argparser(__doc__)
 
26
    args = parser.parse_args()
 
27
    uec2roottar.main(args)