build_bt5_from_svn.sh 1.85 KB
Newer Older
1 2 3 4 5 6 7 8 9
#! /bin/bash
#
# Usage: build_bt5_from_svn.sh [-p path] [-d dir]
#
# The path is the last part of the svn root, for example, tag/5.0 or trunk.
# By default, the path is "trunk".
#
# The dir is the destination directory where the repository is made.
# By default, the dir is the current directory.
10

11 12 13 14 15 16 17 18 19 20 21
set -e

path=trunk
repository=$(pwd)

while getopts "p:d:" opt; do
  case $opt in
    p) path="$OPTARG" ;;
    d) repository="$OPTARG" ;;
  esac
done
22 23

# Lock file name
24
LOCKFILE="/tmp/$(basename $0).lock"
25
# SVN paths
26
SVNROOT="https://svn.erp5.org/repos/public/erp5/$path"
27 28 29 30
# Relative svn paths to fetch
MODULES="bt5 products/ERP5/bootstrap"
# Script generating the business template repository index
GENBTLIST="products/ERP5/bin"
31
# Local directory to receive SVN copies
32
BASELOCALDIR="/tmp"
33
LOCALDIR="$BASELOCALDIR/$$"
34
# Local directory to receive butiness templates
Yoshinori Okuji's avatar
Yoshinori Okuji committed
35
BT5DIR="$repository"
36

37 38 39 40

function cleanup {
  rm -f "$LOCKFILE"
  rm -rf "$LOCALDIR"
41 42 43 44 45 46 47
}

if [ -e "$LOCKFILE" ]; then
  echo "Lock file '$LOCKFILE' exists, exiting..."
  exit 1
fi

48 49 50 51
trap "cleanup" ERR

touch "$LOCKFILE"
mkdir "$LOCALDIR"
52 53

for MODULE in $MODULES; do
54 55 56
  # Checkout the source code from svn
  cd "$LOCALDIR"
  svn co "$SVNROOT/$MODULE" > /dev/null
57 58 59 60 61 62
  BMODULE=`basename "$MODULE"`

  # Create one archive for each Business Template
  cd "$LOCALDIR/$BMODULE"
  for BT5 in `ls "$LOCALDIR/$BMODULE"`; do
    if [ -d "$LOCALDIR/$BMODULE/$BT5" ]; then
63
      tar -zcf "$LOCALDIR/$BT5.bt5" --exclude .svn "$BT5"
64 65 66 67 68
    fi
  done
done

# Get the latest version of the genbt5list and generate the index
69 70
cd "$LOCALDIR"
svn co "$SVNROOT/$GENBTLIST" > /dev/null
71 72 73 74 75

# Publish the repository
mv -f "$LOCALDIR/"*.bt5 "$BT5DIR"

# Generate the index from repository directory, in case there are BT5 manually added there
76
cd "$BT5DIR"
77 78 79 80
/usr/bin/python "$LOCALDIR/`basename $GENBTLIST`/genbt5list" > /dev/null
chmod go+r bt5list

# Clean up
81
cleanup