~j-harbott/cirros/dev

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
set -f

source "${0%/*}/common-functions.sh"

Usage() {
   cat <<EOF
Usage: ${0##*/} mirror_dir

    write tab delimited data for simple streams 'tab2streams' input.

    Example:

      bzr branch lp:simplestreams simplestreams
      bzr branch lp:cirros cirros

      ./cirros/bin/mirror-dump-sstream-data "\$mirror_d" > mdata.txt
      ./simplestreams/tools/tenv tab2streams mdata.txt cirros-streams.d

      ./simplestreams/tools/tenv env -u GNUPGHOME \
         SS_GPG_BATCH=1 SS_GPG_DEFAULT_KEY=A5DDB840  \
         js2signed cirros-streams.d
EOF
}

datefortag() {
    local loginfo ts out repo="${CIRROS_BZR:-.}"
    local spec="$1" fmt="${2:-+%Y%m%d}"
    loginfo=$(bzr log "$repo" --log-format=long --revision "$spec") ||
        { error "couldn't bzr log tag:$i"; return 1; }
    ts=$(echo "$loginfo" | sed -n '/^timestamp:/s,.*: ,,p') &&
        [ -n "$ts" ] || {
            error "failed to get timestamp from log for $spec";
            return 1;
    }
    out=$(date --date="$ts" "$fmt") ||
        { error "failed convert of '$ts' to format=$fmt"; return 1; }
    _RET="$out"
}

[ "$1" = "-h" -o "$1" = "--help" ] && { Usage; exit 0; }
[ "$#" -eq 1 ] || { Usage 1>&2; fail "must give mirror dir"; }

if [ -z "$CIRROS_BZR" ]; then
   CIRROS_BZR=$(t=$(readlink -f "$0") && cd "${t%/*}/.." && pwd)
fi

OIFS="$IFS"
declare -A VERSION2SERIAL
VERSION2SERIAL=(
    [0.3.0]="20111020" [0.3.1]="20130207"
    [0.3.1~pre1]="20120611" [0.3.1~pre3]="20120827"
    [0.3.1~pre4]="20130111" [0.3.2~pre1]="20130513"
    [0.3.2~pre2]="20131218" [0.3.2~pre3]="20140315"
    [0.3.2]="20140317"
)

#content-id product_name version_name img_name [key=value [key=value]]
content_id_base="net.cirros-cloud:%(stream)s:download"

tab="$(printf '\t')"

top_d="${1:-.}"
cd "$top_d"
IFS=$'\n'; files=( $(find . -type f -printf "%p|%s\n") ); IFS="$OIFS"

for ent in "${files[@]}"; do
    IFS="|"; set -- $ent; IFS="$OIFS"
    path=${1#./}
    size=${2}

    case "$path" in
        *-uec.tar.gz|*-disk.img|*-rootfs.img|*-lxc.tar.gz) :;;
        *) continue;;
    esac
    IFS="/"; set -- $path; IFS=$OIFS
    version="$1"; fname="$2";
    serial="${VERSION2SERIAL[$version]}"
    if [ -z "$serial" ]; then
        datefortag "tag:$version" ||
            fail "serial not found for $version!"
        serial="$_RET"
        VERSION2SERIAL[$version]="$serial"
    fi

    # tokenize cirros-0.3.1~pre4-x86_64-lxc.tar.gz, baseproduct gets 'cirros'
    IFS="-"; set -- $fname; IFS="$OIFS"
    baseproduct="$1"; _version="$2"; arch="$3"; ftype="$4"

    # tokenize 0.3.1~pre1 or 0.3.0
    extra=${version#*~}; [ "$extra" = "$version" ] && extra=""
    tmp=${version%$extra}
    IFS="."; set -- ${version%$extra}; IFS="$IOFS"
    vmaj="$1"; vmin="$2"; vmic="$3"

    [ -z "$extra" ] && stream="released" || stream="devel"

    # productname is "net.cirros-cloud[.devel]:standard:0.3:arch"
    rdns="net.cirros-cloud"
    [ "$stream" = "released" ] || rdns="${rdns}.${stream}"
    product_name="$rdns:standard:$vmaj.$vmin:$arch"
    content_id="${content_id_base//%(stream)s/${stream}}"

    req_out=""
    for item in "$content_id" "$product_name" "$serial" "$ftype"; do
        req_out="${req_out}${tab}${item}"
    done
    req_out=${req_out#${tab}}

    md5=$(md5sum "${path}") && md5="${md5%%  ${path}}"
    sha256=$(sha256sum "${path}") && sha256="${sha256%%  ${path}}"
    pubname="${baseproduct}-${version}-${arch}"

    out=""
    for i in ftype path arch version size sha256 md5 pubname stream; do
        out="${out}${tab}${i}=${!i}"
    done
    out=${out#${tab}}
    printf "%s\n" "${req_out}${tab}${out}"
    #printf "
    #echo "$content_id
    #echo "version=$version fname=$fname stream=$stream product_name=$product_name"
done

# vi: tabstop=4 expandtab