Merge pull request #11528 from mukeshcompucorp/fix-page-structure
[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
69ff4a4a 13## Copy files from one dir into another dir
14## usage: dm_install_dir <from-dir> <to-dir>
15function dm_install_dir() {
16 local from="$1"
17 local to="$2"
18
19 if [ ! -d "$to" ]; then
20 mkdir -p "$to"
21 fi
e00b8b13 22 ${DM_RSYNC:-rsync} -avC --exclude=.git --exclude=.svn "$from/./" "$to/./"
69ff4a4a 23}
24
25## Copy listed files
26## usage: dm_install_files <from-dir> <to-dir> <file1> <file2>...
27function 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>...
39function 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
1446640b
TO
48## Copy all bower dependencies
49function 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"
e00b8b13 59 ${DM_RSYNC:-rsync} -avC $excludes_rsync "$repo/./" "$to/./"
1446640b
TO
60}
61
69ff4a4a 62## Copy all core files
63## usage: dm_install_core <core_repo_path> <to_path>
64function dm_install_core() {
65 local repo="$1"
66 local to="$2"
67
3120e843 68 for dir in ang css i js PEAR templates bin CRM api extern Reports install settings Civi partials release-notes ; do
69ff4a4a 69 [ -d "$repo/$dir" ] && dm_install_dir "$repo/$dir" "$to/$dir"
70 done
71
62da8665 72 dm_install_files "$repo" "$to" {agpl-3.0,agpl-3.0.exception,gpl,CONTRIBUTORS}.txt
3120e843 73 dm_install_files "$repo" "$to" composer.json composer.lock bower.json package.json Civi.php README.md release-notes.md
69ff4a4a 74
75 mkdir -p "$to/sql"
76 pushd "$repo" >> /dev/null
61101c01 77 dm_install_files "$repo" "$to" sql/civicrm*.mysql sql/case_sample*.mysql
69ff4a4a 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}
9f0ca23d 91
92## Copy all packages
93## usage: dm_install_packages <packages_repo_path> <to_path>
94function dm_install_packages() {
95 local repo="$1"
96 local to="$2"
97
98 local excludes_rsync=""
acbec2da 99 for exclude in .git .svn _ORIGINAL_ SeleniumRC PHPUnit PhpDocumentor SymfonyComponents amavisd-new git-footnote PHP/CodeCoverage ; do
9f0ca23d 100 excludes_rsync="--exclude=${exclude} ${excludes_rsync}"
101 done
102
e365b6e5 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
9f0ca23d 108 [ ! -d "$to" ] && mkdir "$to"
e00b8b13 109 ${DM_RSYNC:-rsync} -avC $excludes_rsync --include=core "$repo/./" "$to/./"
9f0ca23d 110}
7082ee3c 111
112## Copy Drupal-integration module
113## usage: dm_install_drupal <drupal_repo_path> <to_path>
114function dm_install_drupal() {
115 local repo="$1"
116 local to="$2"
bf20507d 117 dm_install_dir "$repo" "$to"
7082ee3c 118
0c5cbe3d 119 # Set full version in .info files. See CRM-15768.
7082ee3c 120 local MODULE_DIRS=`find "$to" -type f -name "*.info"`
121 for INFO in $MODULE_DIRS; do
065248bd 122 dm_preg_edit '/version = ([0-9]*\.x)-[1-9.]*/m' "version = \$1-$DM_VERSION" "$INFO"
7082ee3c 123 done
08297720
TO
124
125 for f in "$to/.gitignore" "$to/.toxic.json" ; do
126 if [ -f "$f" ]; then
127 rm -f "$f"
128 fi
129 done
7082ee3c 130}
30a50cd8 131
274ebc9e 132## Copy Joomla-integration module
133## usage: dm_install_joomla <joomla_repo_path> <to_path>
134function dm_install_joomla() {
135 local repo="$1"
136 local to="$2"
bf20507d 137 dm_install_dir "$repo" "$to"
80def6a8 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.
08297720
TO
143
144 for f in "$to/.gitignore" "$to/.toxic.json" ; do
145 if [ -f "$f" ]; then
146 rm -f "$f"
147 fi
148 done
274ebc9e 149}
150
8d32d903 151## usage: dm_install_l10n <l10n_repo_path> <to_path>
152function dm_install_l10n() {
153 local repo="$1"
154 local to="$2"
155 dm_install_dir "$repo" "$to"
156}
157
c84eb16e
TO
158## Copy composer's "vendor" folder
159## usage: dm_install_vendor <from_path> <to_path>
160function dm_install_vendor() {
161 local repo="$1"
162 local to="$2"
163
164 local excludes_rsync=""
165 for exclude in .git .svn {T,t}est{,s} {D,d}oc{,s} {E,e}xample{,s} ; do
166 excludes_rsync="--exclude=${exclude} ${excludes_rsync}"
167 done
168
c84eb16e 169 [ ! -d "$to" ] && mkdir "$to"
e00b8b13 170 ${DM_RSYNC:-rsync} -avC $excludes_rsync "$repo/./" "$to/./"
c84eb16e
TO
171}
172
9003e8e1 173## usage: dm_install_wordpress <wp_repo_path> <to_path>
174function dm_install_wordpress() {
175 local repo="$1"
176 local to="$2"
d0f95878 177
178 if [ ! -d "$to" ]; then
179 mkdir -p "$to"
180 fi
e00b8b13 181 ${DM_RSYNC:-rsync} -avC \
d0f95878 182 --exclude=.git \
183 --exclude=.svn \
184 --exclude=civicrm.config.php.wordpress \
08297720 185 --exclude=.toxic.json \
d0f95878 186 --exclude=.gitignore \
187 --exclude=civicrm \
188 "$repo/./" "$to/./"
189 ## Need --exclude=civicrm for self-building on WP site
006e39e1
TO
190
191 dm_preg_edit '/^Version: [0-9\.]+/m' "Version: $DM_VERSION" "$to/civicrm.php"
9003e8e1 192}
193
1446640b
TO
194
195## Generate the "bower_components" folder.
196## usage: dm_generate_bower <repo_path>
197function dm_generate_bower() {
198 local repo="$1"
199 pushd "$repo"
200 ${DM_NPM:-npm} install
201 ${DM_NODE:-node} node_modules/bower/bin/bower install
202 popd
203}
204
c84eb16e
TO
205## Generate the composer "vendor" folder
206## usage: dm_generate_vendor <repo_path>
207function dm_generate_vendor() {
208 local repo="$1"
209 pushd "$repo"
1446640b 210 ${DM_COMPOSER:-composer} install
c84eb16e
TO
211 popd
212}
213
30a50cd8 214## Generate civicrm-version.php
215## usage: dm_generate_version <file> <ufname>
216function dm_generate_version() {
217 local to="$1"
218 local ufname="$2"
219
220 # final touch
221 echo "<?php
222function civicrmVersion( ) {
223 return array( 'version' => '$DM_VERSION',
224 'cms' => '$ufname',
225 'revision' => '$DM_REVISION' );
226}
227" > "$to"
228}
445009ec 229
230## Perform a hard checkout on a given report
231## usage: dm_git_checkout <repo_path> <tree-ish>
232function dm_git_checkout() {
233 pushd "$1"
234 git checkout .
235 git checkout "$2"
236 popd
237}
006e39e1
TO
238
239## Edit a file by applying a regular expression.
240## Note: We'd rather just call "sed", but it differs on GNU+BSD.
241## usage: dm_preg_edit <search-pattern> <replacement-pattern> <file>
242## example: '/version = \([0-9]*\.x-\)[1-9.]*/' 'version = \1$DM_VERSION'
243function dm_preg_edit() {
244 env RPAT="$1" RREPL="$2" RFILE="$3" \
245 php -r '$c = file_get_contents(getenv("RFILE")); $c = preg_replace(getenv("RPAT"), getenv("RREPL"), $c); file_put_contents(getenv("RFILE"), $c);'
246}