]> git.wh0rd.org - chrome-ext/web-power-switch.git/blob - makedist.sh
options: improve field handling
[chrome-ext/web-power-switch.git] / makedist.sh
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
6 case $1 in
7 -h|--help)
8 echo "Usage: $0 [rev]"
9 exit 0
10 ;;
11 esac
12
13 json_value() {
14 local key=$1
15 python -c '
16 import json, os, sys
17 path, key = sys.argv[1:]
18 with open(path) as fp:
19 data = json.load(fp)
20 print(data[key])
21 ' "manifest.json" "${key}"
22 }
23
24 PN=$(json_value name | sed 's:[[:space:]/]:_:g' | tr '[:upper:]' '[:lower:]')
25 if [[ ${PN} == "__msg_name__" ]] ; then
26 PN=$(basename "$(pwd)")
27 fi
28 PV=$(json_value version)
29 rev=${1:-0}
30 PVR="${PV}.${rev}"
31 P="${PN}-${PVR}"
32
33 rm -rf "${P}"
34 mkdir "${P}"
35
36 while read line ; do
37 [[ ${line} == */* ]] && mkdir -p "${P}/${line%/*}"
38 ln "${line}" "${P}/${line}"
39 done < <(sed 's:#.*::' manifest.files)
40 cp Makefile manifest.files manifest.json "${P}/"
41
42 make -C "${P}" -j {css,js}-min
43 while read line ; do
44 mv "${line}" "${line%.min}"
45 done < <(find "${P}" -name '*.min')
46 rm "${P}"/{manifest.files,Makefile}
47
48 python -c '
49 import json, os, sys
50 path, ver = sys.argv[1:]
51 with open(path) as fp:
52 data = json.load(fp)
53 data.pop("key", None)
54 data["version"] = ver
55 with open(path, "w") as fp:
56 json.dump(data, fp, separators=(",", ":"))
57 ' "${P}/manifest.json" "${PVR}"
58
59 zip="${P}.zip"
60 rm -f "${zip}"
61 zip -r "${zip}" "${P}"
62 rm -rf "${P}"
63 du -b "${zip}"