]> git.wh0rd.org - chrome-ext/web-power-switch.git/blame - makedist.sh
options: improve field handling
[chrome-ext/web-power-switch.git] / makedist.sh
CommitLineData
a98f3ef6
MF
1#!/bin/bash -e
2# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6case $1 in
7-h|--help)
8 echo "Usage: $0 [rev]"
9 exit 0
10 ;;
11esac
12
13json_value() {
14 local key=$1
cbf343ff
MF
15 python -c '
16import json, os, sys
17path, key = sys.argv[1:]
18with open(path) as fp:
19 data = json.load(fp)
20print(data[key])
21' "manifest.json" "${key}"
a98f3ef6
MF
22}
23
cbf343ff
MF
24PN=$(json_value name | sed 's:[[:space:]/]:_:g' | tr '[:upper:]' '[:lower:]')
25if [[ ${PN} == "__msg_name__" ]] ; then
26 PN=$(basename "$(pwd)")
27fi
a98f3ef6
MF
28PV=$(json_value version)
29rev=${1:-0}
30PVR="${PV}.${rev}"
31P="${PN}-${PVR}"
32
33rm -rf "${P}"
34mkdir "${P}"
35
36while read line ; do
37 [[ ${line} == */* ]] && mkdir -p "${P}/${line%/*}"
38 ln "${line}" "${P}/${line}"
39done < <(sed 's:#.*::' manifest.files)
594d1a6d
MF
40cp Makefile manifest.files manifest.json "${P}/"
41
9a46592d 42make -C "${P}" -j {css,js}-min
594d1a6d 43while read line ; do
cbf343ff
MF
44 mv "${line}" "${line%.min}"
45done < <(find "${P}" -name '*.min')
594d1a6d 46rm "${P}"/{manifest.files,Makefile}
a98f3ef6 47
cbf343ff
MF
48python -c '
49import json, os, sys
50path, ver = sys.argv[1:]
51with open(path) as fp:
52 data = json.load(fp)
53data.pop("key", None)
54data["version"] = ver
55with open(path, "w") as fp:
56 json.dump(data, fp, separators=(",", ":"))
57' "${P}/manifest.json" "${PVR}"
a98f3ef6
MF
58
59zip="${P}.zip"
9a46592d 60rm -f "${zip}"
a98f3ef6
MF
61zip -r "${zip}" "${P}"
62rm -rf "${P}"
63du -b "${zip}"