~ubuntu-branches/ubuntu/wily/simplestreams/wily

« back to all changes in this revision

Viewing changes to tools/hook-ec2-id

  • Committer: Package Import Robot
  • Author(s): Scott Moser
  • Date: 2013-03-26 01:10:01 UTC
  • Revision ID: package-import@ubuntu.com-20130326011001-342bcgb65worw4r8
Tags: upstream-0.1.0~bzr191
ImportĀ upstreamĀ versionĀ 0.1.0~bzr191

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
set -f
 
3
 
 
4
RC_FILTER_INCLUDE=0
 
5
RC_FILTER_EXCLUDE=1
 
6
RC_FAIL=2
 
7
VERBOSITY=${VERBOSITY:-0}
 
8
 
 
9
MAP=(
 
10
 ARCH:arch RELEASE:release REGION:cloud VIRT:virt STORE:root_store
 
11
)
 
12
 
 
13
error() { echo "$@" 1>&2; }
 
14
fail() { [ $# -eq 0 ] || error "$@"; exit "$RC_FAIL"; }
 
15
debug() {
 
16
    [ "${VERBOSITY}" -lt "$1" ] && return
 
17
    shift
 
18
    error "$@"
 
19
}
 
20
 
 
21
Usage() {
 
22
   cat <<EOF
 
23
Usage: ${0##*/}
 
24
  This program is expected to be called by sstream-sync.
 
25
 
 
26
  sstream-sync "--hook=$0" \\
 
27
     http://cloud-images.ubuntu.com/eightprotons/ streams/v1/index.js
 
28
 
 
29
  It filters output based on environment variables:
 
30
$(for m in ${MAP[@]}; do echo "   ${m}"; done)
 
31
 
 
32
  Example:
 
33
   * VIRT=hvm REGION=us-east-1 ./tools/tenv sstream-sync --max=1 \\
 
34
      "--hook=$0" http://cloud-images.ubuntu.com/eightprotons/ \\
 
35
      streams/v1/index.js
 
36
EOF
 
37
}
 
38
 
 
39
is_excluded() {
 
40
    local ename iname pair
 
41
    for pair in "${MAP[@]}"; do
 
42
        ename=${pair%:*}
 
43
        iname=${pair#*:}
 
44
        [ -n "${!ename}" -a -n "${!iname}" -a "${!ename}" != "${!iname}" ] &&
 
45
            return 0
 
46
    done
 
47
    return 1
 
48
}
 
49
 
 
50
noop() {
 
51
    return 0;
 
52
}
 
53
 
 
54
 
 
55
main() {
 
56
    [ "$1" = "--help" -o "$1" = "-h" -o "$1" = "usage" ] &&
 
57
        { Usage; exit 0; }
 
58
 
 
59
    [ $# -eq 0 ] || fail "Unexpected arguments.  See --help" 
 
60
 
 
61
    [ -n "$HOOK" ] ||
 
62
        { Usage 1>&2; fail "HOOK not available in environment"; }
 
63
   
 
64
    # we only operate on
 
65
    case "$HOOK" in
 
66
        filter_item|filter_product)
 
67
            is_excluded && return "${RC_FILTER_EXCLUDE}"
 
68
            return "${RC_FILTER_INCLUDE}"
 
69
            ;;
 
70
        filter_index_entry)
 
71
            case "${content_id}" in
 
72
                *:aws) return "${RC_FILTER_INCLUDE}";;
 
73
                *) return "${RC_FILTER_EXCLUDE}";;
 
74
            esac
 
75
            ;;
 
76
        insert_item)
 
77
            echo "$cloud ${id} ${root_store}/${virt}/${pubname}";;
 
78
        filter_*) return "${RC_FILTER_INCLUDE}";;
 
79
        *) noop;;
 
80
    esac
 
81
}
 
82
main "$@"
 
83
exit $?
 
84
 
 
85
# vi: ts=4 expandtab