REF migrate Payflow Pro code into a core Extension
[civicrm-core.git] / distmaker / dists / common.sh
CommitLineData
69ff4a4a 1#!/bin/bash
2
fa379693 3## Delete/create a dir
4## usage: dm_reset_dirs <path1> <path2> ...
5function dm_reset_dirs() {
6 for d in "$@" ; do
7 [ -d "$d" ] && rm -rf "$d"
8 done
9
10 mkdir -p "$@"
11}
12
8a5f52de
TO
13## Assert that a folder contains no symlinks
14##
15## ex: dev/core#1393, dev/core#1990
16## usage: dm_assert_no_symlinks <basedir>
17function dm_assert_no_symlinks() {
18 local SYMLINKS=$( find "$1" -type l )
19 if [ -n "$SYMLINKS" ]; then
20 echo "ERROR: Folder $1 contains unexpected symlink(s): $SYMLINKS"
21 exit 10
22 fi
23}
24
69ff4a4a 25## Copy files from one dir into another dir
26## usage: dm_install_dir <from-dir> <to-dir>
27function dm_install_dir() {
28 local from="$1"
29 local to="$2"
30
31 if [ ! -d "$to" ]; then
32 mkdir -p "$to"
33 fi
e00b8b13 34 ${DM_RSYNC:-rsync} -avC --exclude=.git --exclude=.svn "$from/./" "$to/./"
69ff4a4a 35}
36
37## Copy listed files
38## usage: dm_install_files <from-dir> <to-dir> <file1> <file2>...
39function dm_install_files() {
40 local from="$1"
41 shift
42 local to="$1"
43 shift
44
45 for file in "$@" ; do
46 [ -f "$from/$file" ] && cp -f "$from/$file" "$to/$file"
47 done
48}
49
50## usage: dm_remove_files <directory> <file1> <file2>...
51function dm_remove_files() {
52 local tgt="$1"
53 shift
54
55 for file in "$@" ; do
e0dcd057 56 [ -f "$tgt/$file" -o -L "$tgt/$file" ] && rm -f "$tgt/$file"
69ff4a4a 57 done
58}
59
1446640b
TO
60## Copy all bower dependencies
61function dm_install_bower() {
62 local repo="$1"
63 local to="$2"
64
65 local excludes_rsync=""
66 for exclude in .git .svn {T,t}est{,s} {D,d}oc{,s} {E,e}xample{,s} ; do
67 excludes_rsync="--exclude=${exclude} ${excludes_rsync}"
68 done
69
70 [ ! -d "$to" ] && mkdir "$to"
e00b8b13 71 ${DM_RSYNC:-rsync} -avC $excludes_rsync "$repo/./" "$to/./"
1446640b
TO
72}
73
69ff4a4a 74## Copy all core files
75## usage: dm_install_core <core_repo_path> <to_path>
76function dm_install_core() {
77 local repo="$1"
78 local to="$2"
79
784ab2f0 80 for dir in ang css i js PEAR templates bin CRM api extern Reports install settings Civi partials release-notes xml setup ; do
69ff4a4a 81 [ -d "$repo/$dir" ] && dm_install_dir "$repo/$dir" "$to/$dir"
82 done
83
62da8665 84 dm_install_files "$repo" "$to" {agpl-3.0,agpl-3.0.exception,gpl,CONTRIBUTORS}.txt
a8fadf7d 85 dm_install_files "$repo" "$to" composer.json composer.lock package.json Civi.php README.md release-notes.md extension-compatibility.json
69ff4a4a 86
87 mkdir -p "$to/sql"
88 pushd "$repo" >> /dev/null
61101c01 89 dm_install_files "$repo" "$to" sql/civicrm*.mysql sql/case_sample*.mysql
69ff4a4a 90 ## TODO: for master, remove counties.US.SQL.gz
91 popd >> /dev/null
92
93 if [ -d $to/bin ] ; then
94 rm -f $to/bin/setup.sh
95 rm -f $to/bin/setup.php4.sh
96 rm -f $to/bin/setup.bat
97 fi
98
99 set +e
100 rm -rf $to/sql/civicrm_*.??_??.mysql
101 set -e
102}
9f0ca23d 103
c4f1d7e4
TO
104## Copy built-in extensions
105## usage: dm_install_core <core_repo_path> <to_path> <ext-dirs...>
106function dm_install_coreext() {
107 local repo="$1"
108 local to="$2"
109 shift
110 shift
111
112 for relext in "$@" ; do
113 [ ! -d "$to/$relext" ] && mkdir -p "$to/$relext"
114 ${DM_RSYNC:-rsync} -avC $excludes_rsync --include=core "$repo/$relext/./" "$to/$relext/./"
115 done
116}
117
118## Get a list of default/core extension directories (space-delimited)
119## reldirs=$(dm_core_exts)
120function dm_core_exts() {
86d0e749 121 echo ext/search
c4f1d7e4 122 echo ext/sequentialcreditnotes
a7127202 123 echo ext/flexmailer
685bf3d2 124 echo ext/eventcart
ae1baeec 125 echo ext/ewaysingle
e7339d59 126 echo ext/financialacls
978e5e1d 127 echo ext/afform
b482c194 128 echo ext/authx
978e5e1d 129 echo ext/greenwich
643910b0 130 echo ext/contributioncancelactions
77d8692e 131 echo ext/payflowpro
ac05e32a 132 echo ext/oauth-client
0f19d48f 133 echo ext/recaptcha
c4f1d7e4
TO
134}
135
9f0ca23d 136## Copy all packages
137## usage: dm_install_packages <packages_repo_path> <to_path>
138function dm_install_packages() {
139 local repo="$1"
140 local to="$2"
141
142 local excludes_rsync=""
4a0626d0 143 for exclude in .git .svn _ORIGINAL_ SeleniumRC PHPUnit PhpDocumentor SymfonyComponents git-footnote PHP/CodeCoverage ; do
9f0ca23d 144 excludes_rsync="--exclude=${exclude} ${excludes_rsync}"
145 done
146
e365b6e5 147 ## Note: These small folders have items that previously were not published,
148 ## but there's no real cost to including them, and excluding them seems
149 ## likely to cause confusion as the codebase evolves:
150 ## packages/Files packages/PHP packages/Text
151
9f0ca23d 152 [ ! -d "$to" ] && mkdir "$to"
e00b8b13 153 ${DM_RSYNC:-rsync} -avC $excludes_rsync --include=core "$repo/./" "$to/./"
9f0ca23d 154}
7082ee3c 155
156## Copy Drupal-integration module
157## usage: dm_install_drupal <drupal_repo_path> <to_path>
158function dm_install_drupal() {
159 local repo="$1"
160 local to="$2"
bf20507d 161 dm_install_dir "$repo" "$to"
7082ee3c 162
0c5cbe3d 163 # Set full version in .info files. See CRM-15768.
7082ee3c 164 local MODULE_DIRS=`find "$to" -type f -name "*.info"`
165 for INFO in $MODULE_DIRS; do
065248bd 166 dm_preg_edit '/version = ([0-9]*\.x)-[1-9.]*/m' "version = \$1-$DM_VERSION" "$INFO"
7082ee3c 167 done
08297720
TO
168
169 for f in "$to/.gitignore" "$to/.toxic.json" ; do
170 if [ -f "$f" ]; then
171 rm -f "$f"
172 fi
173 done
7082ee3c 174}
30a50cd8 175
274ebc9e 176## Copy Joomla-integration module
177## usage: dm_install_joomla <joomla_repo_path> <to_path>
178function dm_install_joomla() {
179 local repo="$1"
180 local to="$2"
bf20507d 181 dm_install_dir "$repo" "$to"
80def6a8 182
183 ## Before this change, the zip file included the joomla-integration
184 ## modules twice. The two were basically identical -- except that
185 ## one included .gitignore and the omitted it. We'll now omit it
186 ## consistently.
08297720
TO
187
188 for f in "$to/.gitignore" "$to/.toxic.json" ; do
189 if [ -f "$f" ]; then
190 rm -f "$f"
191 fi
192 done
274ebc9e 193}
194
8d32d903 195## usage: dm_install_l10n <l10n_repo_path> <to_path>
196function dm_install_l10n() {
197 local repo="$1"
198 local to="$2"
199 dm_install_dir "$repo" "$to"
200}
201
c84eb16e
TO
202## Copy composer's "vendor" folder
203## usage: dm_install_vendor <from_path> <to_path>
204function dm_install_vendor() {
205 local repo="$1"
206 local to="$2"
207
208 local excludes_rsync=""
af5c4d9f 209 ## CRM-21729 - .idea test-cases unit-test come from phpquery package.
48cd94bb 210 for exclude in .git .svn {T,t}est{,s} {D,d}oc{,s} {E,e}xample{,s} .idea test-cases unit-test README.rst; do
c84eb16e
TO
211 excludes_rsync="--exclude=${exclude} ${excludes_rsync}"
212 done
213
c84eb16e 214 [ ! -d "$to" ] && mkdir "$to"
e00b8b13 215 ${DM_RSYNC:-rsync} -avC $excludes_rsync "$repo/./" "$to/./"
e0dcd057 216 ## We don't this use CLI script in production, and the symlink breaks D7/BD URL installs
9c9e7406 217 dm_remove_files "$to" "bin/pscss" "bin/cssmin"
c84eb16e
TO
218}
219
9003e8e1 220## usage: dm_install_wordpress <wp_repo_path> <to_path>
221function dm_install_wordpress() {
222 local repo="$1"
223 local to="$2"
d0f95878 224
225 if [ ! -d "$to" ]; then
226 mkdir -p "$to"
227 fi
e00b8b13 228 ${DM_RSYNC:-rsync} -avC \
d0f95878 229 --exclude=.git \
230 --exclude=.svn \
231 --exclude=civicrm.config.php.wordpress \
08297720 232 --exclude=.toxic.json \
d0f95878 233 --exclude=.gitignore \
234 --exclude=civicrm \
235 "$repo/./" "$to/./"
236 ## Need --exclude=civicrm for self-building on WP site
006e39e1 237
cadf8ce2
TO
238 dm_preg_edit '/^([ \*]*)Version: [0-9\.]+/m' "\1Version: $DM_VERSION" "$to/civicrm.php"
239 dm_preg_edit "/^define\( *\'CIVICRM_PLUGIN_VERSION\', *'[0-9\.]+/m" "define('CIVICRM_PLUGIN_VERSION', '$DM_VERSION" "$to/civicrm.php"
9003e8e1 240}
241
c84eb16e
TO
242## Generate the composer "vendor" folder
243## usage: dm_generate_vendor <repo_path>
244function dm_generate_vendor() {
245 local repo="$1"
246 pushd "$repo"
1446640b 247 ${DM_COMPOSER:-composer} install
c84eb16e
TO
248 popd
249}
250
30a50cd8 251## Generate civicrm-version.php
252## usage: dm_generate_version <file> <ufname>
253function dm_generate_version() {
254 local to="$1"
255 local ufname="$2"
256
257 # final touch
258 echo "<?php
e78d5446 259/** @deprecated */
30a50cd8 260function civicrmVersion( ) {
261 return array( 'version' => '$DM_VERSION',
262 'cms' => '$ufname',
263 'revision' => '$DM_REVISION' );
264}
265" > "$to"
266}
445009ec 267
268## Perform a hard checkout on a given report
269## usage: dm_git_checkout <repo_path> <tree-ish>
270function dm_git_checkout() {
271 pushd "$1"
272 git checkout .
273 git checkout "$2"
274 popd
275}
006e39e1 276
3c7cc32e
TO
277## Download a Civi extension
278## usage: dm_install_cvext <full-ext-key> <target-path>
279function dm_install_cvext() {
280 # cv dl -b '@https://civicrm.org/extdir/ver=4.7.25|cms=Drupal/com.iatspayments.civicrm.xml' --destination=$PWD/iatspayments
281 cv dl -b "@https://civicrm.org/extdir/ver=$DM_VERSION|cms=Drupal/$1.xml" --to="$2"
282}
283
cd0432e8 284## Export a list of patch files from a git repo
22e9ee71 285## usage: dm_export_patches <src-repo> <out-dir> <range>
cd0432e8 286## ex: dm_export_patches "$HOME/src/somerepo" "/tmp/export" 5.1.2..5.1.6
22e9ee71
TO
287function dm_export_patches() {
288 if [ ! -d "$1" ]; then
289 echo "ignore: $1"
290 return
291 fi
292 echo "Export \"$1\" ($3) to \"$2\""
293 pushd "$1" >> /dev/null
294 git format-patch "$3" -o "$2"
295 popd >> /dev/null
296}
297
298
006e39e1
TO
299## Edit a file by applying a regular expression.
300## Note: We'd rather just call "sed", but it differs on GNU+BSD.
301## usage: dm_preg_edit <search-pattern> <replacement-pattern> <file>
302## example: '/version = \([0-9]*\.x-\)[1-9.]*/' 'version = \1$DM_VERSION'
303function dm_preg_edit() {
304 env RPAT="$1" RREPL="$2" RFILE="$3" \
305 php -r '$c = file_get_contents(getenv("RFILE")); $c = preg_replace(getenv("RPAT"), getenv("RREPL"), $c); file_put_contents(getenv("RFILE"), $c);'
306}