Merge pull request #8037 from jitendrapurohit/CRM-18284
[civicrm-core.git] / distmaker / distmaker.sh
CommitLineData
01ad1437 1#!/bin/bash -v
6a488035
TO
2set -e
3
4# This is distmaker script for CiviCRM
5# Author: michau
6# "Protected by an electric fence and copyright control."
7# Thanks to Kleptones for moral support when writing this.
8
8eb76391 9# You need to ensure the following variables are defined. They are traditionally defined
10# in distmaker.conf but you can also defined them as an environment variable or by
11# calling the script with env DM_REF_CORE=4.7 (for example).
6a488035
TO
12#
13# DM_SOURCEDIR=/home/user/svn/civicrm <- sources
14# DM_GENFILESDIR=/home/user/generated <- generated files
15# DM_TMPDIR=/tmp <- temporary files (will be deleted afterwards)
16# DM_TARGETDIR=/tmp/outdir <- target dir for tarballs
8eb76391 17# DM_REF_CORE=master <- Git branch/tag name
18#
19# Optional variables
6a488035
TO
20# DM_PHP=/opt/php5/bin/php <- php5 binary
21# DM_RSYNC=/usr/bin/rsync <- rsync binary
22# DM_VERSION=trunk.r1234 <- what the version number should be
23# DM_ZIP=/usr/bin/zip <- zip binary
24#
25#
26# ========================================================
27# DO NOT MODIFY BELOW
28# ========================================================
29
30
31# Where are we called from?
32P=`dirname $0`
33# Current dir
34ORIGPWD=`pwd`
445009ec 35source "$P/dists/common.sh"
6a488035
TO
36
37# Set no actions by default
f07f92fa 38BPACK=0
6a488035
TO
39D5PACK=0
40D56PACK=0
8eb76391 41D7DIR=0
6a488035
TO
42J5PACK=0
43WP5PACK=0
44SK5PACK=0
45L10NPACK=0
46
47# Display usage
48display_usage()
49{
bcd9e9f5
EM
50 echo
51 echo "Usage: "
52 echo " distmaker.sh OPTION"
53 echo
54 echo "Options available:"
f07f92fa
TO
55 echo " all - generate all available tarballs"
56 echo " l10n - generate internationalization data"
57 echo " Backdrop - generate Backdrop PHP5 module"
58 echo " Drupal|d5 - generate Drupal7 PHP5 module"
59 echo " Drupal6|d5.6 - generate Drupal6 PHP5 module"
8eb76391 60 echo " d7_dir - generate Drupal7 PHP5 module, but output to a directory, no tarball"
f07f92fa
TO
61 echo " Joomla|j5 - generate Joomla PHP5 module"
62 echo " WordPress|wp5 - generate Wordpress PHP5 module"
63 echo " sk - generate Drupal StarterKit module"
bcd9e9f5
EM
64 echo
65 echo "You also need to have distmaker.conf file in place."
66 echo "See distmaker.conf.dist for example contents."
8eb76391 67 echo "Alternatively you can set the required variables as "
68 echo "environment variables, eg. for your machine or by calling "
69 echo "this script using "
70 echo
71 echo "env DM_TARGETDIR=/path/to/output/dir/for/files/or/tarball distmaker.sh all"
bcd9e9f5 72 echo
8eb76391 73 echo "optional environmentals:"
74 echo " DM_SOURCEDIR "
75 echo " DM_GENFILESDIR (default $TMPDIR/genfiles)"
76 echo " DM_TARGETDIR= (default $TMPDIR/civicrm)"
77 echo " DM_OUTPUTDIR= (default $DM_TARGETDIR/civicrm_files)"
78 echo
79
6a488035
TO
80}
81
8eb76391 82THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )";
6a488035
TO
83
84# Check if config is ok.
85check_conf()
86{
8eb76391 87 if [ -f $P/distmaker.conf ] ; then
88 source "$P/distmaker.conf"
89 fi
90
91 if [ -z $DM_SOURCEDIR ] ; then
92 DM_SOURCEDIR="$THIS_DIR/..";
93 echo "Setting source dir to $DM_SOURCEDIR";
94 fi
95
96 if [ -z $DM_TMPDIR ] && [ -e $TMPDIR ] ; then
97 DM_TMPDIR=$TMPDIR/civicrm
98 fi
99
100 if [ -z $DM_GENFILESDIR ] && [ -e $TMPDIR ] ; then
101 DM_GENFILESDIR=$TMPDIR/genfiles
102 fi
103
104 if [ -z $DM_PACKAGESDIR ] ; then
105 DM_PACKAGESDIR="$DM_SOURCEDIR/packages"
106 fi
107
108 if [ -z $DM_OUTPUTDIR ] ; then
109 DM_OUTPUTDIR="$DM_TARGETDIR/civicrm_files"
110 fi
111
bcd9e9f5 112 # Test for distmaker.conf file availability, cannot proceed without it anyway
8eb76391 113 if [ -z $DM_GENFILESDIR ] || [ -z $DM_TMPDIR ] || [ -z $DM_TARGETDIR ]; then
114 echo; echo "Required variables not defined!"; echo;
bcd9e9f5 115 display_usage
8eb76391 116 echo "your variables"
117 echo "DM_SOURCEDIR : $DM_SOURCEDIR";
118 echo "DM_TARGETDIR : $DM_TARGETDIR (required)";
119 echo "DM_TMPDIR : $DM_TMPDIR";
120 echo "DM_GENFILESDIR : $DM_GENFILESDIR";
121 echo "DM_PACKAGESDIR : $DM_PACKAGESDIR";
122 echo "Current directory is : $THIS_DIR";
bcd9e9f5
EM
123 exit 1
124 else
bcd9e9f5
EM
125 export DM_SOURCEDIR DM_GENFILESDIR DM_TMPDIR DM_TARGETDIR DM_PHP DM_RSYNC DM_ZIP DM_VERSION DM_REF_CORE DM_REF_DRUPAL DM_REF_DRUPAL6 DM_REF_JOOMLA DM_REF_WORDPRESS DM_REF_PACKAGES
126 if [ ! -d "$DM_SOURCEDIR" ]; then
127 echo; echo "ERROR! " DM_SOURCEDIR "directory not found!"; echo "(if you get empty directory name, it might mean that one of necessary variables is not set)"; echo;
128 fi
129 for k in "$DM_GENFILESDIR" "$DM_TARGETDIR" "$DM_TMPDIR"; do
130 if [ -z "$k" ] ; then
131 echo; echo "ERROR! " $k "directory not found!"; echo "(if you get empty directory name, it might mean that one of necessary variables is not set)"; echo;
132 exit 1
133 fi
134 if [ ! -d "$k" ]; then
135 mkdir -p "$k"
136 fi
137 done
138 fi
6a488035
TO
139}
140
6a488035
TO
141# Let's go.
142
143check_conf
144
145# Figure out what to do
146case $1 in
bcd9e9f5
EM
147 # L10N PHP5
148 l10n)
149 echo; echo "Generating L10N module"; echo;
150 L10NPACK=1
151 ;;
152
f07f92fa
TO
153 # BACKDROP PHP5
154 Backdrop)
155 echo; echo "Generating Backdrop PHP5 module"; echo;
156 BPACK=1
157 ;;
158
bcd9e9f5 159 # DRUPAL7 PHP5
f07f92fa 160 d5|Drupal)
bcd9e9f5
EM
161 echo; echo "Generating Drupal7 PHP5 module"; echo;
162 D5PACK=1
163 ;;
164
8eb76391 165 # Drupal 7 - Output to directory
166 d7_dir)
167 echo; echo "Generating Drupal7 Directory"; echo;
168 D7DIR=1
169 ;;
170
bcd9e9f5
EM
171 # DRUPAL7 PHP5 StarterKit package
172 sk)
173 echo; echo "Generating Drupal7 PHP5 starter kit minimal module"; echo;
174 SKPACK=1
175 ;;
176
177 # DRUPAL6 PHP5
f07f92fa 178 d5.6|Drupal6)
bcd9e9f5
EM
179 echo; echo "Generating Drupal6 PHP5 module"; echo;
180 D56PACK=1
181 ;;
182
183 # JOOMLA PHP5
f07f92fa 184 j5|Joomla)
bcd9e9f5
EM
185 echo; echo "Generating Joomla PHP5 module"; echo;
186 J5PACK=1
187 ;;
188
189 # WORDPRESS PHP5
f07f92fa 190 wp5|WordPress)
bcd9e9f5
EM
191 echo; echo "Generating Wordpress PHP5 module"; echo;
192 WP5PACK=1
193 ;;
194
195 # ALL
196 all)
8eb76391 197 echo; echo "Generating all the tarballs we've got (not the directories). "; echo;
f07f92fa 198 BPACK=1
bcd9e9f5
EM
199 D5PACK=1
200 D56PACK=1
201 J5PACK=1
202 WP5PACK=1
203 SKPACK=1
204 L10NPACK=1
205 ;;
206
207 # USAGE
208 *)
209 display_usage
210 exit 0
211 ;;
6a488035
TO
212
213esac
214
bed96570 215## Make sure we have the right branch or tag
445009ec 216dm_git_checkout "$DM_SOURCEDIR" "$DM_REF_CORE"
8eb76391 217dm_git_checkout "$DM_PACKAGESDIR" "$DM_REF_PACKAGES"
445009ec 218
bed96570 219## in theory, this shouldn't matter, but GenCode is CMS-dependent, and we've been doing our past builds based on D7
c0e8d80b
TO
220GENCODE_CMS=
221if [ -d "$DM_SOURCEDIR/backdrop" ]; then
222 dm_git_checkout "$DM_SOURCEDIR/backdrop" "$DM_REF_BACKDROP"
223 GENCODE_CMS=Backdrop
224fi
225if [ -d "$DM_SOURCEDIR/drupal" ]; then
226 dm_git_checkout "$DM_SOURCEDIR/drupal" "$DM_REF_DRUPAL"
227 GENCODE_CMS=Drupal
228fi
6a488035 229
c84eb16e
TO
230## Get latest dependencies
231dm_generate_vendor "$DM_SOURCEDIR"
1446640b 232dm_generate_bower "$DM_SOURCEDIR"
c84eb16e 233
6a488035
TO
234# Before anything - regenerate DAOs
235
236cd $DM_SOURCEDIR/xml
c0e8d80b 237${DM_PHP:-php} GenCode.php schema/Schema.xml $DM_VERSION $GENCODE_CMS
6a488035
TO
238
239cd $ORIGPWD
240
241if [ "$L10NPACK" = 1 ]; then
bcd9e9f5
EM
242 echo; echo "Packaging for L10N"; echo;
243 bash $P/dists/l10n.sh
6a488035
TO
244fi
245
f07f92fa
TO
246if [ "$BPACK" = 1 ]; then
247 echo; echo "Packaging for Backdrop, PHP5 version"; echo;
c0e8d80b 248 dm_git_checkout "$DM_SOURCEDIR/backdrop" "$DM_REF_BACKDROP"
f07f92fa
TO
249 bash $P/dists/backdrop_php5.sh
250fi
251
6a488035 252if [ "$D56PACK" = 1 ]; then
bcd9e9f5
EM
253 echo; echo "Packaging for Drupal6, PHP5 version"; echo;
254 dm_git_checkout "$DM_SOURCEDIR/drupal" "$DM_REF_DRUPAL6"
255 bash $P/dists/drupal6_php5.sh
6a488035
TO
256fi
257
258if [ "$D5PACK" = 1 ]; then
bcd9e9f5
EM
259 echo; echo "Packaging for Drupal7, PHP5 version"; echo;
260 dm_git_checkout "$DM_SOURCEDIR/drupal" "$DM_REF_DRUPAL"
261 bash $P/dists/drupal_php5.sh
6a488035
TO
262fi
263
8eb76391 264if [ "$D7DIR" = 1 ]; then
265 echo; echo "Packaging for Drupal7, Directory not tarball, PHP5 version"; echo;
266 dm_git_checkout "$DM_SOURCEDIR/drupal" "$DM_REF_DRUPAL"
267 bash $P/dists/drupal7_dir_php5.sh
268fi
269
6a488035 270if [ "$SKPACK" = 1 ]; then
bcd9e9f5
EM
271 echo; echo "Packaging for Drupal7, PHP5 StarterKit version"; echo;
272 dm_git_checkout "$DM_SOURCEDIR/drupal" "$DM_REF_DRUPAL"
273 bash $P/dists/drupal_sk_php5.sh
6a488035
TO
274fi
275
276if [ "$J5PACK" = 1 ]; then
bcd9e9f5
EM
277 echo; echo "Packaging for Joomla, PHP5 version"; echo;
278 dm_git_checkout "$DM_SOURCEDIR/joomla" "$DM_REF_JOOMLA"
279 bash $P/dists/joomla_php5.sh
6a488035
TO
280fi
281
282if [ "$WP5PACK" = 1 ]; then
bcd9e9f5
EM
283 echo; echo "Packaging for Wordpress, PHP5 version"; echo;
284 dm_git_checkout "$DM_SOURCEDIR/WordPress" "$DM_REF_WORDPRESS"
285 bash $P/dists/wordpress_php5.sh
6a488035
TO
286fi
287
288unset DM_SOURCEDIR DM_GENFILESDIR DM_TARGETDIR DM_TMPDIR DM_PHP DM_RSYNC DM_VERSION DM_ZIP
289echo;echo "DISTMAKER Done.";echo;