Mercurial > hg > FirefoxAddon
annotate firefoxaddon/template/build.sh @ 0:9869cf47fcf8 default tip
initial commit of Firefox addon template
author | k0s <k0scist@gmail.com> |
---|---|
date | Sun, 28 Mar 2010 16:25:58 -0400 |
parents | |
children |
rev | line source |
---|---|
0
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
1 #!/bin/bash |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
2 # build.sh -- builds JAR and XPI files for mozilla extensions |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
3 # by Nickolay Ponomarev <asqueella@gmail.com> |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
4 # (original version based on Nathan Yergler's build script) |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
5 # Most recent version is at <http://kb.mozillazine.org/Bash_build_script> |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
6 |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
7 # This script assumes the following directory structure: |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
8 # ./ |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
9 # chrome.manifest (optional - for newer extensions) |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
10 # install.rdf |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
11 # (other files listed in $ROOT_FILES) |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
12 # |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
13 # content/ | |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
14 # locale/ |} these can be named arbitrary and listed in $CHROME_PROVIDERS |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
15 # skin/ | |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
16 # |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
17 # defaults/ | |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
18 # components/ |} these must be listed in $ROOT_DIRS in order to be packaged |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
19 # ... | |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
20 # |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
21 # It uses a temporary directory ./build when building; don't use that! |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
22 # Script's output is: |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
23 # ./$APP_NAME.xpi |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
24 # ./$APP_NAME.jar (only if $KEEP_JAR=1) |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
25 # ./files -- the list of packaged files |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
26 # |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
27 # Note: It modifies chrome.manifest when packaging so that it points to |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
28 # chrome/$APP_NAME.jar!/* |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
29 |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
30 # |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
31 # default configuration file is ./config_build.sh, unless another file is |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
32 # specified in command-line. Available config variables: |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
33 APP_NAME= # short-name, jar and xpi files name. Must be lowercase with no spaces |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
34 CHROME_PROVIDERS= # which chrome providers we have (space-separated list) |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
35 CLEAN_UP= # delete the jar / "files" when done? (1/0) |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
36 ROOT_FILES= # put these files in root of xpi (space separated list of leaf filenames) |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
37 ROOT_DIRS= # ...and these directories (space separated list) |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
38 BEFORE_BUILD= # run this before building (bash command) |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
39 AFTER_BUILD= # ...and this after the build (bash command) |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
40 |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
41 if [ -z $1 ]; then |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
42 . ./config_build.sh |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
43 else |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
44 . $1 |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
45 fi |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
46 |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
47 if [ -z $APP_NAME ]; then |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
48 echo "You need to create build config file first!" |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
49 echo "Read comments at the beginning of this script for more info." |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
50 exit; |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
51 fi |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
52 |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
53 ROOT_DIR=`pwd` |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
54 TMP_DIR=build |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
55 |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
56 #uncomment to debug |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
57 #set -x |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
58 |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
59 # remove any left-over files from previous build |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
60 rm -f $APP_NAME.jar $APP_NAME.xpi files |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
61 rm -rf $TMP_DIR |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
62 |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
63 $BEFORE_BUILD |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
64 |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
65 mkdir --parents --verbose $TMP_DIR/chrome |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
66 |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
67 # generate the JAR file, excluding CVS and temporary files |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
68 JAR_FILE=$TMP_DIR/chrome/$APP_NAME.jar |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
69 echo "Generating $JAR_FILE..." |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
70 for CHROME_SUBDIR in $CHROME_PROVIDERS; do |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
71 find $CHROME_SUBDIR -path '*CVS*' -prune -o -type f -print | grep -v \~ >> files |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
72 done |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
73 |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
74 zip -0 -r $JAR_FILE `cat files` |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
75 # The following statement should be used instead if you don't wish to use the JAR file |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
76 #cp --verbose --parents `cat files` $TMP_DIR/chrome |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
77 |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
78 # prepare components and defaults |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
79 echo "Copying various files to $TMP_DIR folder..." |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
80 for DIR in $ROOT_DIRS; do |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
81 mkdir $TMP_DIR/$DIR |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
82 FILES="`find $DIR -path '*CVS*' -prune -o -type f -print | grep -v \~`" |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
83 echo $FILES >> files |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
84 cp --verbose --parents $FILES $TMP_DIR |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
85 done |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
86 |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
87 # Copy other files to the root of future XPI. |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
88 for ROOT_FILE in $ROOT_FILES install.rdf chrome.manifest; do |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
89 cp --verbose $ROOT_FILE $TMP_DIR |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
90 if [ -f $ROOT_FILE ]; then |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
91 echo $ROOT_FILE >> files |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
92 fi |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
93 done |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
94 |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
95 cd $TMP_DIR |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
96 |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
97 if [ -f "chrome.manifest" ]; then |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
98 echo "Preprocessing chrome.manifest..." |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
99 # You think this is scary? |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
100 #s/^(content\s+\S*\s+)(\S*\/)$/\1jar:chrome\/$APP_NAME\.jar!\/\2/ |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
101 #s/^(skin|locale)(\s+\S*\s+\S*\s+)(.*\/)$/\1\2jar:chrome\/$APP_NAME\.jar!\/\3/ |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
102 # |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
103 # Then try this! (Same, but with characters escaped for bash :) |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
104 sed -i -r s/^\(content\\s+\\S*\\s+\)\(\\S*\\/\)$/\\1jar:chrome\\/$APP_NAME\\.jar!\\/\\2/ chrome.manifest |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
105 sed -i -r s/^\(skin\|locale\)\(\\s+\\S*\\s+\\S*\\s+\)\(.*\\/\)$/\\1\\2jar:chrome\\/$APP_NAME\\.jar!\\/\\3/ chrome.manifest |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
106 |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
107 # (it simply adds jar:chrome/whatever.jar!/ at appropriate positions of chrome.manifest) |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
108 fi |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
109 |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
110 # generate the XPI file |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
111 echo "Generating $APP_NAME.xpi..." |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
112 zip -r ../$APP_NAME.xpi * |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
113 |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
114 cd "$ROOT_DIR" |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
115 |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
116 echo "Cleanup..." |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
117 if [ $CLEAN_UP = 0 ]; then |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
118 # save the jar file |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
119 mv $TMP_DIR/chrome/$APP_NAME.jar . |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
120 else |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
121 rm ./files |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
122 fi |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
123 |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
124 # remove the working files |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
125 rm -rf $TMP_DIR |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
126 echo "Done!" |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
127 |
9869cf47fcf8
initial commit of Firefox addon template
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
128 $AFTER_BUILD |