fixed generated data for CRM-15934
[civicrm-core.git] / distmaker / dists / common.sh
1 #!/bin/bash
2
3 ## Delete/create a dir
4 ## usage: dm_reset_dirs <path1> <path2> ...
5 function dm_reset_dirs() {
6 for d in "$@" ; do
7 [ -d "$d" ] && rm -rf "$d"
8 done
9
10 mkdir -p "$@"
11 }
12
13 ## Copy files from one dir into another dir
14 ## usage: dm_install_dir <from-dir> <to-dir>
15 function dm_install_dir() {
16 local from="$1"
17 local to="$2"
18
19 if [ ! -d "$to" ]; then
20 mkdir -p "$to"
21 fi
22 ${DM_RSYNC:-rsync} -avC --exclude=.git --exclude=.svn "$from/./" "$to/./"
23 }
24
25 ## Copy listed files
26 ## usage: dm_install_files <from-dir> <to-dir> <file1> <file2>...
27 function dm_install_files() {
28 local from="$1"
29 shift
30 local to="$1"
31 shift
32
33 for file in "$@" ; do
34 [ -f "$from/$file" ] && cp -f "$from/$file" "$to/$file"
35 done
36 }
37
38 ## usage: dm_remove_files <directory> <file1> <file2>...
39 function dm_remove_files() {
40 local tgt="$1"
41 shift
42
43 for file in "$@" ; do
44 [ -f "$tgt/$file" ] && rm -f "$tgt/$file"
45 done
46 }
47
48 ## Copy all bower dependencies
49 function dm_install_bower() {
50 local repo="$1"
51 local to="$2"
52
53 local excludes_rsync=""
54 for exclude in .git .svn {T,t}est{,s} {D,d}oc{,s} {E,e}xample{,s} ; do
55 excludes_rsync="--exclude=${exclude} ${excludes_rsync}"
56 done
57
58 [ ! -d "$to" ] && mkdir "$to"
59 ${DM_RSYNC:-rsync} -avC $excludes_rsync "$repo/./" "$to/./"
60 }
61
62 ## Copy all core files
63 ## usage: dm_install_core <core_repo_path> <to_path>
64 function dm_install_core() {
65 local repo="$1"
66 local to="$2"
67
68 for dir in css i js PEAR templates bin CRM api extern Reports install settings Civi partials ; do
69 [ -d "$repo/$dir" ] && dm_install_dir "$repo/$dir" "$to/$dir"
70 done
71
72 dm_install_files "$repo" "$to" {agpl-3.0,agpl-3.0.exception,gpl,README,CONTRIBUTORS}.txt
73 dm_install_files "$repo" "$to" composer.json composer.lock bower.json package.json
74
75 mkdir -p "$to/sql"
76 pushd "$repo" >> /dev/null
77 dm_install_files "$repo" "$to" sql/civicrm*.mysql sql/case_sample*.mysql
78 ## TODO: for master, remove counties.US.SQL.gz
79 popd >> /dev/null
80
81 if [ -d $to/bin ] ; then
82 rm -f $to/bin/setup.sh
83 rm -f $to/bin/setup.php4.sh
84 rm -f $to/bin/setup.bat
85 fi
86
87 set +e
88 rm -rf $to/sql/civicrm_*.??_??.mysql
89 set -e
90 }
91
92 ## Copy all packages
93 ## usage: dm_install_packages <packages_repo_path> <to_path>
94 function dm_install_packages() {
95 local repo="$1"
96 local to="$2"
97
98 local excludes_rsync=""
99 for exclude in .git .svn _ORIGINAL_ SeleniumRC PHPUnit PhpDocumentor SymfonyComponents amavisd-new git-footnote ; do
100 excludes_rsync="--exclude=${exclude} ${excludes_rsync}"
101 done
102
103 ## Note: These small folders have items that previously were not published,
104 ## but there's no real cost to including them, and excluding them seems
105 ## likely to cause confusion as the codebase evolves:
106 ## packages/Files packages/PHP packages/Text
107
108 [ ! -d "$to" ] && mkdir "$to"
109 ${DM_RSYNC:-rsync} -avC $excludes_rsync --include=core "$repo/./" "$to/./"
110 }
111
112 ## Copy Drupal-integration module
113 ## usage: dm_install_drupal <drupal_repo_path> <to_path>
114 function dm_install_drupal() {
115 local repo="$1"
116 local to="$2"
117 dm_install_dir "$repo" "$to"
118
119 # set full version in .info files
120 local MODULE_DIRS=`find "$to" -type f -name "*.info"`
121 for INFO in $MODULE_DIRS; do
122 if [ $(uname) = "Darwin" ]; then
123 ## BSD sed
124 sed -i '' "s/version = [1-9.]*/version = $DM_VERSION/g" $INFO
125 else
126 ## GNU sed
127 sed -i'' "s/version = [1-9.]*/version = $DM_VERSION/g" $INFO
128 fi
129 done
130 }
131
132 ## Copy Joomla-integration module
133 ## usage: dm_install_joomla <joomla_repo_path> <to_path>
134 function dm_install_joomla() {
135 local repo="$1"
136 local to="$2"
137 dm_install_dir "$repo" "$to"
138
139 ## Before this change, the zip file included the joomla-integration
140 ## modules twice. The two were basically identical -- except that
141 ## one included .gitignore and the omitted it. We'll now omit it
142 ## consistently.
143 rm -f "$to/.gitignore"
144 }
145
146 ## usage: dm_install_l10n <l10n_repo_path> <to_path>
147 function dm_install_l10n() {
148 local repo="$1"
149 local to="$2"
150 dm_install_dir "$repo" "$to"
151 }
152
153 ## Copy composer's "vendor" folder
154 ## usage: dm_install_vendor <from_path> <to_path>
155 function dm_install_vendor() {
156 local repo="$1"
157 local to="$2"
158
159 local excludes_rsync=""
160 for exclude in .git .svn {T,t}est{,s} {D,d}oc{,s} {E,e}xample{,s} ; do
161 excludes_rsync="--exclude=${exclude} ${excludes_rsync}"
162 done
163
164 [ ! -d "$to" ] && mkdir "$to"
165 ${DM_RSYNC:-rsync} -avC $excludes_rsync "$repo/./" "$to/./"
166 }
167
168 ## usage: dm_install_wordpress <wp_repo_path> <to_path>
169 function dm_install_wordpress() {
170 local repo="$1"
171 local to="$2"
172
173 if [ ! -d "$to" ]; then
174 mkdir -p "$to"
175 fi
176 ${DM_RSYNC:-rsync} -avC \
177 --exclude=.git \
178 --exclude=.svn \
179 --exclude=civicrm.config.php.wordpress \
180 --exclude=.gitignore \
181 --exclude=civicrm \
182 "$repo/./" "$to/./"
183 ## Need --exclude=civicrm for self-building on WP site
184 }
185
186
187 ## Generate the "bower_components" folder.
188 ## usage: dm_generate_bower <repo_path>
189 function dm_generate_bower() {
190 local repo="$1"
191 pushd "$repo"
192 ${DM_NPM:-npm} install
193 ${DM_NODE:-node} node_modules/bower/bin/bower install
194 popd
195 }
196
197 ## Generate the composer "vendor" folder
198 ## usage: dm_generate_vendor <repo_path>
199 function dm_generate_vendor() {
200 local repo="$1"
201 pushd "$repo"
202 ${DM_COMPOSER:-composer} install
203 popd
204 }
205
206 ## Generate civicrm-version.php
207 ## usage: dm_generate_version <file> <ufname>
208 function dm_generate_version() {
209 local to="$1"
210 local ufname="$2"
211
212 # final touch
213 echo "<?php
214 function civicrmVersion( ) {
215 return array( 'version' => '$DM_VERSION',
216 'cms' => '$ufname',
217 'revision' => '$DM_REVISION' );
218 }
219 " > "$to"
220 }
221
222 ## Perform a hard checkout on a given report
223 ## usage: dm_git_checkout <repo_path> <tree-ish>
224 function dm_git_checkout() {
225 pushd "$1"
226 git checkout .
227 git checkout "$2"
228 popd
229 }