Commit | Line | Data |
---|---|---|
69ff4a4a | 1 | #!/bin/bash |
2 | ||
fa379693 | 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 | ||
69ff4a4a | 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 | |
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>... | |
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 | ||
1446640b TO |
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" | |
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> | |
64 | function dm_install_core() { | |
65 | local repo="$1" | |
66 | local to="$2" | |
67 | ||
784ab2f0 | 68 | for dir in ang css i js PEAR templates bin CRM api extern Reports install settings Civi partials release-notes xml setup ; 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 |
a8fadf7d | 73 | dm_install_files "$repo" "$to" composer.json composer.lock package.json Civi.php README.md release-notes.md extension-compatibility.json |
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 | |
c4f1d7e4 TO |
92 | ## Copy built-in extensions |
93 | ## usage: dm_install_core <core_repo_path> <to_path> <ext-dirs...> | |
94 | function dm_install_coreext() { | |
95 | local repo="$1" | |
96 | local to="$2" | |
97 | shift | |
98 | shift | |
99 | ||
100 | for relext in "$@" ; do | |
101 | [ ! -d "$to/$relext" ] && mkdir -p "$to/$relext" | |
102 | ${DM_RSYNC:-rsync} -avC $excludes_rsync --include=core "$repo/$relext/./" "$to/$relext/./" | |
103 | done | |
104 | } | |
105 | ||
106 | ## Get a list of default/core extension directories (space-delimited) | |
107 | ## reldirs=$(dm_core_exts) | |
108 | function dm_core_exts() { | |
109 | echo ext/sequentialcreditnotes | |
a7127202 | 110 | echo ext/flexmailer |
685bf3d2 | 111 | echo ext/eventcart |
c4f1d7e4 TO |
112 | } |
113 | ||
9f0ca23d | 114 | ## Copy all packages |
115 | ## usage: dm_install_packages <packages_repo_path> <to_path> | |
116 | function dm_install_packages() { | |
117 | local repo="$1" | |
118 | local to="$2" | |
119 | ||
120 | local excludes_rsync="" | |
4a0626d0 | 121 | for exclude in .git .svn _ORIGINAL_ SeleniumRC PHPUnit PhpDocumentor SymfonyComponents git-footnote PHP/CodeCoverage ; do |
9f0ca23d | 122 | excludes_rsync="--exclude=${exclude} ${excludes_rsync}" |
123 | done | |
124 | ||
e365b6e5 | 125 | ## Note: These small folders have items that previously were not published, |
126 | ## but there's no real cost to including them, and excluding them seems | |
127 | ## likely to cause confusion as the codebase evolves: | |
128 | ## packages/Files packages/PHP packages/Text | |
129 | ||
9f0ca23d | 130 | [ ! -d "$to" ] && mkdir "$to" |
e00b8b13 | 131 | ${DM_RSYNC:-rsync} -avC $excludes_rsync --include=core "$repo/./" "$to/./" |
9f0ca23d | 132 | } |
7082ee3c | 133 | |
134 | ## Copy Drupal-integration module | |
135 | ## usage: dm_install_drupal <drupal_repo_path> <to_path> | |
136 | function dm_install_drupal() { | |
137 | local repo="$1" | |
138 | local to="$2" | |
bf20507d | 139 | dm_install_dir "$repo" "$to" |
7082ee3c | 140 | |
0c5cbe3d | 141 | # Set full version in .info files. See CRM-15768. |
7082ee3c | 142 | local MODULE_DIRS=`find "$to" -type f -name "*.info"` |
143 | for INFO in $MODULE_DIRS; do | |
065248bd | 144 | dm_preg_edit '/version = ([0-9]*\.x)-[1-9.]*/m' "version = \$1-$DM_VERSION" "$INFO" |
7082ee3c | 145 | done |
08297720 TO |
146 | |
147 | for f in "$to/.gitignore" "$to/.toxic.json" ; do | |
148 | if [ -f "$f" ]; then | |
149 | rm -f "$f" | |
150 | fi | |
151 | done | |
7082ee3c | 152 | } |
30a50cd8 | 153 | |
274ebc9e | 154 | ## Copy Joomla-integration module |
155 | ## usage: dm_install_joomla <joomla_repo_path> <to_path> | |
156 | function dm_install_joomla() { | |
157 | local repo="$1" | |
158 | local to="$2" | |
bf20507d | 159 | dm_install_dir "$repo" "$to" |
80def6a8 | 160 | |
161 | ## Before this change, the zip file included the joomla-integration | |
162 | ## modules twice. The two were basically identical -- except that | |
163 | ## one included .gitignore and the omitted it. We'll now omit it | |
164 | ## consistently. | |
08297720 TO |
165 | |
166 | for f in "$to/.gitignore" "$to/.toxic.json" ; do | |
167 | if [ -f "$f" ]; then | |
168 | rm -f "$f" | |
169 | fi | |
170 | done | |
274ebc9e | 171 | } |
172 | ||
8d32d903 | 173 | ## usage: dm_install_l10n <l10n_repo_path> <to_path> |
174 | function dm_install_l10n() { | |
175 | local repo="$1" | |
176 | local to="$2" | |
177 | dm_install_dir "$repo" "$to" | |
178 | } | |
179 | ||
c84eb16e TO |
180 | ## Copy composer's "vendor" folder |
181 | ## usage: dm_install_vendor <from_path> <to_path> | |
182 | function dm_install_vendor() { | |
183 | local repo="$1" | |
184 | local to="$2" | |
185 | ||
186 | local excludes_rsync="" | |
af5c4d9f | 187 | ## CRM-21729 - .idea test-cases unit-test come from phpquery package. |
188 | for exclude in .git .svn {T,t}est{,s} {D,d}oc{,s} {E,e}xample{,s} .idea test-cases unit-test; do | |
c84eb16e TO |
189 | excludes_rsync="--exclude=${exclude} ${excludes_rsync}" |
190 | done | |
191 | ||
c84eb16e | 192 | [ ! -d "$to" ] && mkdir "$to" |
e00b8b13 | 193 | ${DM_RSYNC:-rsync} -avC $excludes_rsync "$repo/./" "$to/./" |
c84eb16e TO |
194 | } |
195 | ||
9003e8e1 | 196 | ## usage: dm_install_wordpress <wp_repo_path> <to_path> |
197 | function dm_install_wordpress() { | |
198 | local repo="$1" | |
199 | local to="$2" | |
d0f95878 | 200 | |
201 | if [ ! -d "$to" ]; then | |
202 | mkdir -p "$to" | |
203 | fi | |
e00b8b13 | 204 | ${DM_RSYNC:-rsync} -avC \ |
d0f95878 | 205 | --exclude=.git \ |
206 | --exclude=.svn \ | |
207 | --exclude=civicrm.config.php.wordpress \ | |
08297720 | 208 | --exclude=.toxic.json \ |
d0f95878 | 209 | --exclude=.gitignore \ |
210 | --exclude=civicrm \ | |
211 | "$repo/./" "$to/./" | |
212 | ## Need --exclude=civicrm for self-building on WP site | |
006e39e1 TO |
213 | |
214 | dm_preg_edit '/^Version: [0-9\.]+/m' "Version: $DM_VERSION" "$to/civicrm.php" | |
a68b918b | 215 | dm_preg_edit "/^define\( \'CIVICRM_PLUGIN_VERSION\',\W'[0-9\.]+/m" "define( 'CIVICRM_PLUGIN_VERSION', '$DM_VERSION" "$to/civicrm.php" |
9003e8e1 | 216 | } |
217 | ||
c84eb16e TO |
218 | ## Generate the composer "vendor" folder |
219 | ## usage: dm_generate_vendor <repo_path> | |
220 | function dm_generate_vendor() { | |
221 | local repo="$1" | |
222 | pushd "$repo" | |
1446640b | 223 | ${DM_COMPOSER:-composer} install |
c84eb16e TO |
224 | popd |
225 | } | |
226 | ||
30a50cd8 | 227 | ## Generate civicrm-version.php |
228 | ## usage: dm_generate_version <file> <ufname> | |
229 | function dm_generate_version() { | |
230 | local to="$1" | |
231 | local ufname="$2" | |
232 | ||
233 | # final touch | |
234 | echo "<?php | |
e78d5446 | 235 | /** @deprecated */ |
30a50cd8 | 236 | function civicrmVersion( ) { |
237 | return array( 'version' => '$DM_VERSION', | |
238 | 'cms' => '$ufname', | |
239 | 'revision' => '$DM_REVISION' ); | |
240 | } | |
241 | " > "$to" | |
242 | } | |
445009ec | 243 | |
244 | ## Perform a hard checkout on a given report | |
245 | ## usage: dm_git_checkout <repo_path> <tree-ish> | |
246 | function dm_git_checkout() { | |
247 | pushd "$1" | |
248 | git checkout . | |
249 | git checkout "$2" | |
250 | popd | |
251 | } | |
006e39e1 | 252 | |
3c7cc32e TO |
253 | ## Download a Civi extension |
254 | ## usage: dm_install_cvext <full-ext-key> <target-path> | |
255 | function dm_install_cvext() { | |
256 | # cv dl -b '@https://civicrm.org/extdir/ver=4.7.25|cms=Drupal/com.iatspayments.civicrm.xml' --destination=$PWD/iatspayments | |
257 | cv dl -b "@https://civicrm.org/extdir/ver=$DM_VERSION|cms=Drupal/$1.xml" --to="$2" | |
258 | } | |
259 | ||
006e39e1 TO |
260 | ## Edit a file by applying a regular expression. |
261 | ## Note: We'd rather just call "sed", but it differs on GNU+BSD. | |
262 | ## usage: dm_preg_edit <search-pattern> <replacement-pattern> <file> | |
263 | ## example: '/version = \([0-9]*\.x-\)[1-9.]*/' 'version = \1$DM_VERSION' | |
264 | function dm_preg_edit() { | |
265 | env RPAT="$1" RREPL="$2" RFILE="$3" \ | |
266 | php -r '$c = file_get_contents(getenv("RFILE")); $c = preg_replace(getenv("RPAT"), getenv("RREPL"), $c); file_put_contents(getenv("RFILE"), $c);' | |
267 | } |