Bash build script

From MozillaZine Knowledge Base

(Difference between revisions)

Revision as of 03:17, 18 September 2004

Here is a bash script I'm using to package my extensions.

# build JAR and XPI files from source
# based on Nathan Yergler's build script

#### editable items (none of these can be blank)
APP_NAME=menuedit    # short-name, jar and xpi files name.
HAS_DEFAULTS=1       # whether the ext. provides default values for user prefs etc.
HAS_COMPONENTS=0     # whether the ext. includes any components
HAS_LOCALE=1         # package APP_NAME.jar/locale/ ?
HAS_SKIN=0           # package APP_NAME.jar/skin/ ?
KEEP_JAR=1           # leave the jar when done?
ROOT_FILES="license.txt install.rdf" # put these files in root of xpi
#### editable items end


#uncomment to debug
#set -x

# remove any left-over files
rm $APP_NAME.jar
rm $APP_NAME.xpi
rm -rf $TMP_DIR

# create xpi directory layout and populate it
mkdir $TMP_DIR
mkdir $TMP_DIR/chrome

if [ $HAS_COMPONENTS = 1 ]; then
  mkdir $TMP_DIR/components
  cp components/* $TMP_DIR/components

if [ $HAS_DEFAULTS = 1 ]; then
  DEFAULT_FILES="`find ./defaults -path './*CVS*' -prune -o -type f -print | grep -v \~`"
  cp --parents $DEFAULT_FILES $TMP_DIR

# Copy other files to the root of future XPI.

# generate the JAR file, excluding CVS and temporary files
zip -0 -r $TMP_DIR/chrome/$APP_NAME.jar `find ./content -path './*CVS*' -prune -o -type f -print | grep -v \~`
if [ $HAS_LOCALE = 1 ]; then
  zip -0 -r $TMP_DIR/chrome/$APP_NAME.jar `find ./locale -path './*CVS*' -prune -o -type f -print | grep -v \~`
if [ $HAS_SKIN = 1 ]; then
  zip -0 -r $TMP_DIR/chrome/$APP_NAME.jar `find ./skin -path './*CVS*' -prune -o -type f -print | grep -v \~`

# generate the XPI file
zip -r ../$APP_NAME.xpi *
cd ..

if [ $KEEP_JAR = 1 ]; then
  # save the jar file
  mv $TMP_DIR/chrome/$APP_NAME.jar .

# remove the working files
rm -rf $TMP_DIR