├── .gitignore
├── .travis.yml
├── .vimrc
├── COPYING
├── README.md
├── deliver.sh
├── deliver_ssh_wrapper.sh
├── lib
└── shunit2
├── logo
└── logo.svg
├── presets
├── core
│ ├── info
│ └── pre-delivery
│ │ └── 01-disk-space.sh
├── drupal
│ ├── info
│ ├── init-remote
│ │ └── 01-drupal-install.sh
│ └── post-symlink
│ │ └── 01-drupal-cc.sh
├── js
│ └── info
├── php
│ ├── info
│ └── pre-delivery
│ │ └── 01-syntax-check.sh
├── puppet
│ ├── info
│ ├── post-symlink
│ │ └── 01-start-puppetmaster.remote.sh
│ └── pre-symlink
│ │ └── 01-stop-puppetmaster.remote.sh
├── symfony
│ ├── info
│ └── post-symlink
│ │ ├── 01-symfony-cc
│ │ └── 02-symfony-doctrine
└── yisti
│ ├── info
│ ├── post-checkout
│ ├── 01-start.sh
│ └── 02-deploy.remote.sh
│ └── post-symlink
│ └── 01-varnish-switch.remote.sh
├── tests.sh
└── tests_travis.sh
/.gitignore:
--------------------------------------------------------------------------------
1 | .*.swp
2 | *~
3 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: bash
2 |
3 | script:
4 | - bash tests_travis.sh
5 |
6 | os:
7 | - linux
8 | - osx
9 |
--------------------------------------------------------------------------------
/.vimrc:
--------------------------------------------------------------------------------
1 | set tabstop=4
2 | set shiftwidth=4
3 | set softtabstop=4
4 |
--------------------------------------------------------------------------------
/COPYING:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | Introduction
4 | ============
5 |
6 | Git-deliver is a GPL licensed delivery system based on Git.
7 |
8 | It uses "git push" combined with SSH as a way of delivering a project (as of a specific Git commit) to various environments (Git remotes) simply and securely. It also helps keeping track of what is delivered on which server.
9 |
10 | Compared to a regular Git push/checkout, Git-deliver :
11 | * makes the delivery atomic
12 | * structures the delivery process in stages and handles errors while maintaining availability
13 | * archives delivered versions and automates rollback
14 | * logs everything
15 | * provides an easy way of knowing what is delivered where, checking integrity and knowing when and by whom a version was delivered.
16 | * intends to provide pre-baked delivery recipes for common development environments
17 |
18 | Each delivery remote is a bare Git repository, in the root of which Git-deliver creates a "delivered" folder. This folder will contain one non-bare clone of the base repository for each delivery.
19 |
20 | The git clones share their metadata with the main repository for the remote, to avoid excessive space usage / copy time.
21 |
22 | The current version's clone is used through a "current" symlink, which is switched once the new version is ready, to make the delivery "atomic".
23 |
24 | A delivery is done in stages. At each stage, Bash scripts can be run, that can be tailored to the project. Commonly used script sets can be shared in the form of "presets".
25 |
26 |
27 | Installation
28 | ============
29 |
30 | All platforms
31 | -------------
32 |
33 | Clone this repository in the directory of your choice.
34 |
35 | In your .gitconfig, add this line in the `[alias]` section:
36 |
37 | deliver = "!bash /deliver.sh"
38 |
39 | Where `` is the path to the root of the git clone you just made.
40 |
41 | If you receive an error such as:
42 |
43 | fatal: cannot exec 'git-deliver': Permission denied
44 |
45 | Then Git has found a file or directory in your PATH called 'git-deliver' that it cannot execute.
46 | Note that cloning this repo into your PATH will result in the above error, so either move it to outside of your PATH or rename it.
47 |
48 | Windows
49 | -------
50 |
51 | To use Git-deliver on Windows, you'll most likely want to setup SSH public key authentication with your remotes to avoid typing your SSH password multiple times. See http://stackoverflow.com/questions/7260/how-do-i-setup-public-key-authentication for instructions. This is because the SSH client bundled with msys does not support connection multiplexing (at least not with privilege separation enabled on the server).
52 |
53 | A simple example (TL;DR)
54 | ========================
55 |
56 | Let's assume for this example that you have a simple project for which a delivery just means copying files.
57 |
58 | The example below assumes that the server is accessible with SSH.
59 |
60 | To setup your project for Git-deliver, in your project directory, run:
61 |
62 | git deliver --init
63 |
64 | Create a bare repository on the server where you want the project delivered, and add it as a remote in your local Git project, or ask Git-deliver to do it:
65 |
66 | git deliver --init-remote test_server user@test_server.example.com:/project_files
67 |
68 | You can then perform your first delivery (here, of your local "master"):
69 |
70 | git deliver test_server master
71 |
72 | Your project is now accessible on test_server.example.com at /project_files/delivered/current
73 |
74 | Let's deliver another version (tagged "v1.0"):
75 |
76 | git deliver test_server v1.0
77 |
78 | You can ask Git-deliver what the current version on test_server is, who delivered it and when:
79 |
80 | git deliver --status test_server
81 |
82 |
83 | Usage
84 | =====
85 |
86 | git deliver
87 |
88 | deliver `` (sha1, tag, branch) on ``.
89 |
90 |
91 | git deliver --status [REMOTE]
92 |
93 | Returns the version delivered (if any) on `[REMOTE]`, or on all remotes if `[REMOTE]` is not specified.
94 |
95 | git deliver --rollback [PREVIOUSLY_DELIVERED_FOLDER]
96 |
97 | Switches back to a previously delivered version on ``. This is like a regular delivery, except we reuse an already delivered folder and use it to start the process at stage pre-symlink. You can give the name of a previous delivery folder; if you don't, the "previous" version is used.
98 |
99 | git deliver --gc
100 |
101 | "garbage collection": remove all previously delivered versions on ``, except the last three ("current", "previous", "preprevious"), run `git gc` on the remote's main repository if needed
102 |
103 | git deliver --init [presets]
104 |
105 | Initialise this repository for git-deliver, optionally including stage scripts for `[presets]`
106 |
107 | git deliver --init-remote [--shared=...] [REMOTE_URL]
108 |
109 | Initialize Git remote `` for git-deliver. The remote needs to be bare. If it does not exist yet, it can be created at `[REMOTE_URL]`. If the remote exists but does not point to a bare repository, the repository will be created. The shared parameter, if supplied, is then passed as is to git init (see "man git-init").
110 |
111 | git deliver --list-presets
112 |
113 | List available presets for --init
114 |
115 |
116 | How it works
117 | ============
118 |
119 | To get started, you'd run `git deliver --init` in your Git working folder. This would create an empty ".deliver" folder next to the ".git" one. You'd then be able to create scripts in this folder to customize the delivery process should you want to. You could keep the .deliver folder under version control and share it with your team that way.
120 |
121 | If you wanted to start with presets for a given environment, you'd give init a list of preset names: something like `git deliver --init rails` would copy the "rails" scripts, which might depend on others which will be automatically copied as well. The list of available presets can be viewed by running `git deliver --list-presets`.
122 |
123 | Note that although the mechanisms are there, presets themselves are pretty much inexistent right now; I very much welcome contributions in this area.
124 |
125 | Once our working copy is ready, if you have "init-remote" scripts, you'll need to run `git deliver --init-remote ` to run those. They might be used to install external dependencies on the remote. If you don't have "init-remote" scripts, remote initialization is not needed (Git-deliver will warn you at the first delivery, if you forget to initialize a remote that requires it).
126 |
127 | A delivery is initiated by running `git deliver `. Here's the timeline of what happens:
128 |
129 | * We run preliminary checks. By default, we just check the available disk space on the remote, but you can create "pre-delivery" scripts to add checks.
130 |
131 | * The commit to deliver is pushed to the remote, and the remote repository cloned in the delivered folder. "post-checkout" scripts are then run.
132 |
133 | * Your scripts might change the delivered files. We therefore do a commit in the clone repository, to save the delivered state. If the repository you are delivering to is a shared one, the files are given group write permissions and made to belong to the same group as the "objetcs" folder in the repository. We then run the "pre-symlink" scripts.
134 |
135 | * We change the "current", "previous" and "preprevious" symlinks atomically to point to the corresponding new folders, and run the "post-symlink" scripts. During the symlink update, the "current" symlink always exists and always points to a version of your software, unless you try to deliver to a system having neither GNU mv nor Python installed, in which case there will be a short time during which the "current" symlink will be missing (Git-deliver will warn you of this).
136 |
137 | * If any of the run scripts fails (has a non zero exit status) or if an internal git-deliver step fails, we'll stop the delivery there and initiate a rollback. To do this, we'll run the "rollback-pre-symlink" scripts, switch the symlinks back if necessary (if we went as far in the process as to change them in the first place), then run the "rollback-post-symlink" scripts.
138 |
139 | Stage scripts
140 | =============
141 |
142 | Stage scripts are Bash scripts that can be run at the various stages of a delivery.
143 |
144 | At a specific stage, git-deliver will run everything in `.deliver/scripts/` that has a name ending in `.sh`. Scripts with a name ending in `.remote.sh` will be executed entirely on the remote.
145 |
146 | Stage scripts can read a few environment variables to gather information about the delivery process.
147 |
148 | All stages have access to:
149 |
150 | $VERSION the ref being delivered, as it was specified on the command line
151 | $VERSION_SHA sha1 of the ref being delivered
152 | $PREVIOUS_VERSION_SHA sha1 of the previously delivered ref
153 | $GIT_DELIVER_PATH path to where git-deliver is stored
154 | $REPO_ROOT root of the local git repo
155 | $DELIVERY_DATE date and time the delivery was initiated (using date +'%F_%H-%M-%S')
156 | $REMOTE_SERVER hostname or IP of the server we are delivering to, empty if doing a local delivery
157 | $REMOTE_PATH path to the bare remote repository we are delivering to
158 | $REMOTE name of the Git remote we are delivering to
159 | $DELIVERY_PATH path where the version will be delivered on the remote ($REMOTE_PATH/delivered/$VERSION_$DELIVERY_DATE)
160 | $IS_ROLLBACK boolean, true if this delivery is a rollback to a previously installed version
161 | $DELIVER_GIT_SSH ssh command used by git-deliver to talk to the remote server
162 |
163 | Scripts for stages rollback-pre-symlink and rollback-post-symlink have access to:
164 |
165 | $LAST_STAGE_REACHED The last stage the delivery reached before rollback had to be called. This allows the rollback stage scripts to know what needs to be undone to perform the rollback. Empty if delivery stopped before stage "pre-delivery".
166 | $FAILED_SCRIPT Name of the stage script that failed, triggering the rollback. Empty if the rollback was caused by an error in the standard Git-deliver process.
167 | $FAILED_SCRIPT_EXIT_STATUS Exit status of the stage script that failed, triggering the rollback. 0 if the rollback was caused by a SIGINT (CTRL+C).
168 |
169 | Stage scripts can use the `run_remote` bash function to run commands on the remote through SSH (as the SSH user setup for the remote in Git). `run_remote` also works for "local" remotes, the command will then be run as the user running git-deliver.
170 |
171 | Note that while you can of course call external programs from your stage scripts, you can use Bash heredocs to inline other script languages. Here's an example with Ruby :
172 |
173 | #!/bin/bash
174 | ruby <
5 | #
6 | # This file is a part of Git-deliver.
7 | #
8 | # The program in this file is free software: you can redistribute it
9 | # and/or modify it under the terms of the GNU General Public License
10 | # as published by the Free Software Foundation, either version 3 of
11 | # the License, or (at your option) any later version.
12 | #
13 | # This program is distributed in the hope that it will be useful,
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | # GNU General Public License for more details.
17 | #
18 | # You should have received a copy of the GNU General Public License
19 | # along with this program. If not, see .
20 | #
21 |
22 | set -o nounset
23 |
24 | USECOLOR=true;
25 | if [[ -t 1 ]]; then
26 | if [[ ! "$OSTYPE" == "msys" ]]; then
27 | nb=`tput colors 2>&1`
28 | if [[ -n "$nb" ]] && [[ $nb -lt 8 ]]; then
29 | USECOLOR=false;
30 | fi
31 | fi
32 | else
33 | USECOLOR=false;
34 | fi
35 |
36 |
37 | function echo_green
38 | {
39 | local msg="$1"
40 | [[ $USECOLOR == true ]] && { if [[ $OSTYPE == "msys" ]]; then echo -ne "\E[32m"; else tput setaf 2; fi }
41 | echo "$msg"
42 | [[ $USECOLOR == true ]] && { if [[ $OSTYPE == "msys" ]]; then echo -ne "\033[0m"; else tput sgr0; fi }
43 | }
44 |
45 | function echo_red
46 | {
47 | local msg="$1"
48 | [[ $USECOLOR == true ]] && { if [[ $OSTYPE == "msys" ]]; then echo -ne "\E[31m"; else tput setaf 1; fi }
49 | echo "$msg"
50 | [[ $USECOLOR == true ]] && { if [[ $OSTYPE == "msys" ]]; then echo -ne "\033[0m"; else tput sgr0; fi }
51 | }
52 |
53 | function exit_with_error
54 | {
55 | local code=$1
56 | local msg="$2"
57 | echo_red "$msg" >&2
58 | exit $code
59 | }
60 |
61 | REPO_ROOT=`git rev-parse --git-dir 2> /dev/null` # for some reason, --show-toplevel returns nothing
62 |
63 | if [[ $? -gt 0 ]]; then
64 | exit_with_error 1 "ERROR : not a git repo"
65 | fi
66 | if [[ "$REPO_ROOT" = ".git" ]]; then
67 | REPO_ROOT=`pwd`
68 | else
69 | REPO_ROOT="${REPO_ROOT%/.git}"
70 | fi
71 |
72 | function path2unix
73 | {
74 | local source_path="$1"
75 | if [[ "${source_path:0:1}" = "/" ]]; then
76 | echo $source_path
77 | return
78 | fi
79 | local drive_letter=$(echo "${source_path:0:1}" | tr '[A-Z]' '[a-z]')
80 | echo "/$drive_letter${source_path:2}"
81 | }
82 |
83 | if [[ "$OSTYPE" == "msys" ]]; then
84 | REPO_ROOT=`path2unix "$REPO_ROOT"`
85 | fi
86 |
87 | PRG="$BASH_SOURCE"
88 |
89 | while [ -h "$PRG" ] ; do
90 | ls=`ls -ld "$PRG"`
91 | link=`expr "$ls" : '.*-> \(.*\)$'`
92 | if expr "$link" : '/.*' > /dev/null; then
93 | PRG="$link"
94 | else
95 | PRG=`dirname "$PRG"`"/$link"
96 | fi
97 | done
98 |
99 | GIT_DELIVER_PATH=$(dirname "$PRG")
100 |
101 | function confirm_or_exit
102 | {
103 | local msg="$1"
104 | local question=""
105 | [[ $# -gt 1 ]] && question=$2
106 | local exit_if_batch=true
107 | [[ $# -gt 2 ]] && exit_if_batch=$3
108 |
109 | echo "$msg" >&2
110 | if [[ $FLAGS_batch == true ]]; then
111 | if [[ $exit_if_batch == true ]]; then
112 | exit 2
113 | else
114 | return
115 | fi
116 | fi
117 | if [[ "$question" = "" ]]; then
118 | question="Continue ?"
119 | fi
120 | read -p "$question (y/n) " -n 1 reply >&2
121 | if [[ ! $reply = "Y" ]] && [[ ! $reply = "y" ]]; then
122 | exit 1
123 | fi
124 | }
125 |
126 | function exit_if_error
127 | {
128 | if [[ $? -gt 0 ]]; then
129 | local code=$1
130 | local msg="$2"
131 | exit_with_error $code "$msg"
132 | fi
133 | }
134 |
135 | function exit_with_help
136 | {
137 | [[ $# -gt 0 ]] && local code=$1
138 |
139 | echo "Usage : "
140 | echo " git deliver "
141 | echo " git deliver --rollback [DELIVERY]"
142 | echo " git deliver --gc "
143 | echo " git deliver --init [PRESETS]"
144 | echo " git deliver --init-remote [--shared=...] "
145 | echo " git deliver --list-presets"
146 | echo " git deliver --status [REMOTE]"
147 |
148 | if [[ -n ${code+defined} ]]; then
149 | exit $code
150 | else
151 | exit 1;
152 | fi
153 | }
154 |
155 | function indent
156 | {
157 | local level=$1
158 | local prefix=""
159 | for (( i=0; $i < $level; i=$i+1 )); do
160 | prefix="$prefix "
161 | done
162 | sed -e "s/^/$prefix/"
163 | }
164 |
165 | function remote_status
166 | {
167 | local remote
168 | local short=0
169 | [[ $# -gt 1 ]] && short="$2"
170 | [[ $# -gt 0 ]] && remote="$1"
171 | if [[ ! -n ${remote+defined} ]]; then
172 | local first_remote=true
173 | for R in `git remote`; do
174 | if $first_remote; then
175 | first_remote=false
176 | else
177 | echo ""
178 | fi
179 | echo "Remote $R :"
180 | remote_status "$R" 1
181 | done
182 | else
183 | remote_info "$remote"
184 | if [[ "$REMOTE_PROTO" != "ssh" ]] && [[ "$REMOTE_PROTO" != "local" ]]; then
185 | echo "Not a Git-deliver remote"
186 | return 1
187 | fi
188 |
189 | run_remote "bash" <<-EOS
190 | function indent
191 | {
192 | local level=\$1
193 | local prefix=""
194 | for (( i=0; \$i < \$level; i=\$i+1 )); do
195 | prefix="\$prefix "
196 | done
197 | sed -e "s/^/\$prefix/"
198 | }
199 |
200 | if [[ ! -d "$REMOTE_PATH"/delivered ]]; then
201 | echo "Not a Git-deliver remote" | indent $short
202 | exit 1
203 | fi
204 |
205 | function version_info () {
206 | local dir=\`basename "\$1"\`
207 | local dir_resolved
208 | dir_resolved=\`cd "$REMOTE_PATH/delivered/\$dir" &> /dev/null && pwd -P && cd - &> /dev/null\`
209 | if [[ \$? -gt 0 ]]; then
210 | return 2
211 | fi
212 |
213 | dir_resolved=\`basename "\$dir_resolved"\`
214 |
215 | if [[ "$short" != "1" ]]; then
216 | if ! \$first_delivery; then
217 | echo ""
218 | fi
219 | echo -n "\$dir"
220 | if [[ "\$dir" = "\$dir_resolved" ]]; then
221 | echo ""
222 | else
223 | echo " (\$dir_resolved)"
224 | fi
225 | fi
226 |
227 | local short_sha=\${dir_resolved:22:6}
228 | local latest_sha
229 | cd "$REMOTE_PATH/delivered/\$dir"
230 | latest_sha=\`git --git-dir=.git log --pretty=format:%H -n 1 2>&1\`
231 | if [[ \$? -gt 0 ]]; then
232 | delivery_info="Unknown"
233 | return=4
234 | else
235 | if [[ \`git log -n 1 --pretty=format:%B --skip=1\` = "git-deliver local-build commit" ]]; then
236 | local previous_sha=\`git log --pretty=format:%H -n 1 --skip=2 2>&1\`
237 | else
238 | local previous_sha=\`git log --pretty=format:%H -n 1 --skip=1 2>&1\`
239 | fi
240 | local branch=\`git rev-parse --symbolic-full-name --abbrev-ref HEAD 2>&1\`
241 | if [[ "\$branch" = "_delivered" ]] && [[ \${previous_sha:0:6} = \$short_sha ]]; then
242 | local version=\$previous_sha
243 | local delivery_info=\`git show --pretty=format:'delivered %aD%nby %aN <%aE>' _delivered 2>&1 | head -n 2\`
244 | return=3
245 | else
246 | local version=\$latest_sha
247 | local delivery_info="* not delivered with git-deliver *"
248 | return=4
249 | fi
250 |
251 | local tags=\`git show-ref --tags -d | grep ^\$version | sed -e 's,.* refs/tags/,,' -e 's/\^{}//g' | grep -v '^delivered-' | tr "\\n" "," | sed -e 's/,/, /g' -e 's/, $//g'\`
252 |
253 | if [[ "\$tags" = "" ]]; then
254 | echo "\$version" | indent 1
255 | else
256 | echo "\$version (\$tags)" | indent 1
257 | fi
258 |
259 | git diff-index HEAD --quiet --exit-code
260 | if [[ \$? -gt "0" ]]; then
261 | echo "* plus uncommitted changes *" | indent 1
262 | fi
263 |
264 | fi
265 |
266 | echo "\$delivery_info" | indent 1
267 | return \$return
268 | }
269 |
270 | first_delivery=true
271 | curinfo=\`version_info "current"\`
272 | RETURN=\$?
273 | if [[ \$RETURN -lt 3 ]]; then
274 | echo "No version currently delivered" | indent $short
275 | else
276 | echo "\$curinfo"
277 | fi
278 | first_delivery=false
279 |
280 | if [[ "$short" != "1" ]]; then
281 | version_info "previous"
282 | version_info "preprevious"
283 | curver=\`{ cd "$REMOTE_PATH/delivered/current" && pwd -P && cd - > /dev/null ; } 2> /dev/null\`
284 | prever=\`{ cd "$REMOTE_PATH/delivered/previous" && pwd -P && cd - > /dev/null ; } 2> /dev/null\`
285 | preprever=\`{ cd "$REMOTE_PATH/delivered/preprevious" && pwd -P && cd - > /dev/null ; } 2> /dev/null\`
286 | for rep in "$REMOTE_PATH/delivered/"*; do
287 | if [ ! -L "\$rep" ]; then
288 | rep=\`{ cd "\$rep" && pwd -P && cd - > /dev/null ; } 2> /dev/null\`
289 | if [ "\$rep" != "\$curver" ] &&
290 | [ "\$rep" != "\$prever" ] &&
291 | [ "\$rep" != "\$preprever" ]; then
292 | version_info "\$rep"
293 | fi
294 | fi
295 | done
296 | fi
297 |
298 | exit \$RETURN
299 | EOS
300 | return $?
301 | fi
302 | }
303 |
304 | function list_presets
305 | {
306 | for preset_path in "$GIT_DELIVER_PATH"/presets/*; do
307 | local preset=`basename "$preset_path"`
308 | if [[ -f "$preset_path/info" ]]; then
309 | local DEPENDECIES;
310 | local DESCRIPTION;
311 | source "$preset_path/info"
312 | echo "$preset : $DESCRIPTION [$DEPENDENCIES]"
313 | fi
314 | done
315 | }
316 |
317 | function check_preset
318 | {
319 | local preset="$1"
320 | if [[ -d "$GIT_DELIVER_PATH/presets/$preset" ]]; then
321 | local DEPENDENCIES=""
322 | local DESCRIPTION="ERROR"
323 | local info_path="$GIT_DELIVER_PATH/presets/$preset/info"
324 | if [[ ! -f "$info_path" ]]; then
325 | exit_with_error 21 "ERROR : Info file for preset $preset not found."
326 | fi
327 | source "$info_path"
328 | if [[ "$DESCRIPTION" = "ERROR" ]] || [[ "$DESCRIPTION" = "" ]]; then
329 | exit_with_error 20 "ERROR : Missing description for preset $PRESET"
330 | fi
331 | local oldifs=$IFS
332 | if [[ "$DEPENDENCIES" != "" ]]; then
333 | IFS=',' read -ra dependencies <<< "$DEPENDENCIES"
334 | for dep in "${dependencies[@]}"; do
335 | check_preset "$dep"
336 | done
337 | fi
338 | else
339 | exit_with_error 19 "ERROR : could not find preset $preset"
340 | fi
341 | }
342 |
343 | # Copies the files for preset $1 to the repo's .deliver/scripts directory
344 | function init_preset
345 | {
346 | local preset="$1"
347 | if echo "$INIT_PRESETS" | grep ",$preset," > /dev/null; then
348 | return
349 | fi
350 | [ -d "$GIT_DELIVER_PATH"/presets/"$preset" ] || exit_with_error 10 "Preset not found : $preset"
351 | [ -d "$GIT_DELIVER_PATH"/presets/"$preset"/dependencies ] && cp -ri "$GIT_DELIVER_PATH"/presets/"$preset"/dependencies "$REPO_ROOT"/.deliver/scripts/dependencies/"$preset"
352 | for preset_stage_dir in "$GIT_DELIVER_PATH/presets/$preset"/*; do
353 | [ -d "$preset_stage_dir" ] || continue
354 | local preset_stage=`basename "$preset_stage_dir"`
355 | [ "$preset_stage" = "dependencies" ] && continue
356 | for script_file in "$preset_stage_dir"/*; do
357 | local script_name=`basename "$script_file"`
358 | local script_seqnum=${script_name%%-*}
359 | local script_label="${script_name:$((${#script_seqnum}+1))}"
360 | cp -i "$script_file" "$REPO_ROOT"/.deliver/scripts/$preset_stage/"$script_seqnum-$preset-$script_label"
361 | done
362 | done
363 | INIT_PRESETS="$INIT_PRESETS$preset,"
364 | local DEPENDENCIES=""
365 | local DESCRIPTION=""
366 | source "$GIT_DELIVER_PATH/presets/$preset"/info
367 | if [[ -n ${DEPENDENCIES+defined} ]] && [[ "$DEPENDENCIES" != "" ]]; then
368 | IFS=',' read -ra dependencies <<< "$DEPENDENCIES"
369 | for dep in "${dependencies[@]}"; do
370 | init_preset "$dep"
371 | done
372 | fi
373 | }
374 |
375 | function init
376 | {
377 | [[ $# -gt 0 ]] && local presets="$1"
378 |
379 | if [[ -n ${presets+defined} ]]; then
380 | IFS=',' read -ra presets <<< "$presets"
381 | for preset_dir in "${presets[@]}"; do
382 | local preset=`basename "$preset_dir"`
383 | check_preset $preset
384 | done
385 | fi
386 | mkdir -p "$REPO_ROOT/.deliver/scripts"
387 | for stage in dependencies init-remote local-build pre-delivery post-checkout pre-symlink post-symlink rollback-pre-symlink rollback-post-symlink; do
388 | mkdir -p "$REPO_ROOT/.deliver/scripts/$stage"
389 | echo -e "Put your $stage Bash scripts in this folder with a .sh extension.\n\nSee https://github.com/arnoo/git-deliver for help." >> "$REPO_ROOT/.deliver/scripts/$stage/README"
390 | done
391 | echo "Setting up core preset" >&2
392 | INIT_PRESETS=","
393 | init_preset core
394 | if [[ -n ${presets+defined} ]]; then
395 | for preset_dir in "${presets[@]}"; do
396 | local preset=`basename "$preset_dir"`
397 | echo "Setting up $preset preset" >&2
398 | init_preset $preset
399 | done
400 | fi
401 | }
402 |
403 | function run_stage_scripts
404 | {
405 | if test -n "$(find "$REPO_ROOT/.deliver/scripts/$DELIVERY_STAGE" -maxdepth 1 -name '*.sh' -print 2> /dev/null)"
406 | then
407 | echo "Running scripts for stage $DELIVERY_STAGE" >&2
408 | for SCRIPT_PATH in "$REPO_ROOT/.deliver/scripts/$DELIVERY_STAGE"/*.sh; do
409 | local script=`basename "$SCRIPT_PATH"`
410 | CURRENT_STAGE_SCRIPT="$script"
411 | echo "$DELIVERY_STAGE/$script" | indent 1 >&2
412 | local shell
413 | if [[ "${script: -10}" = ".remote.sh" ]]; then
414 | shell='run_remote bash'
415 | else
416 | shell='bash'
417 | fi
418 | local script_result
419 | { $shell | indent 2 >&2; script_result=${PIPESTATUS[0]}; } <<-EOS
420 | export GIT_DELIVER_PATH="$GIT_DELIVER_PATH"
421 | export REPO_ROOT="$REPO_ROOT"
422 | export DELIVERY_DATE="${DELIVERY_DATE:-}"
423 | export DELIVERY_PATH="${DELIVERY_PATH:-}"
424 | export VERSION="${VERSION:-}"
425 | export VERSION_SHA="${VERSION_SHA:-}"
426 | export PREVIOUS_VERSION_SHA="${PREVIOUS_VERSION_SHA:-}"
427 | export REMOTE_SERVER="$REMOTE_SERVER"
428 | export REMOTE_PATH="$REMOTE_PATH"
429 | export REMOTE="$REMOTE"
430 | export LAST_STAGE_REACHED="${LAST_STAGE_REACHED:-}"
431 | export IS_ROLLBACK="$IS_ROLLBACK"
432 | export FAILED_SCRIPT="${FAILED_SCRIPT:-}"
433 | export FAILED_SCRIPT_EXIT_STATUS="${FAILED_SCRIPT_EXIT_STATUS:-}"
434 | export DELIVER_GIT_SSH="${GIT_SSH:-}"
435 | unset GIT_SSH
436 |
437 | function run_remote
438 | {
439 | local command="\$*"
440 | if [[ "$REMOTE_SERVER" = "" ]]; then
441 | bash -c "\$command"
442 | else
443 | "${GIT_SSH:-}" "$REMOTE_SERVER" bash -c "\$command"
444 | fi
445 | }
446 |
447 | export -f run_remote
448 |
449 | `cat "$SCRIPT_PATH"`
450 | EOS
451 | if [[ $script_result -gt 0 ]]; then
452 | echo_red "Script returned with status $script_result" | indent 1 >&2
453 | if [[ "$DELIVERY_STAGE" != "rollback-pre-symlink" ]] && [[ "$DELIVERY_STAGE" != "rollback-post-symlink" ]] && [[ "$DELIVERY_STAGE" != "init-remote" ]]; then
454 | LAST_STAGE_REACHED="$DELIVERY_STAGE"
455 | FAILED_SCRIPT="$CURRENT_STAGE_SCRIPT"
456 | FAILED_SCRIPT_EXIT_STATUS="$script_result"
457 | rollback
458 | exit 3
459 | elif [[ "$DELIVERY_STAGE" == "init-remote" ]]; then
460 | echo_red "A script failed during init-remote, manual intervention is likely necessary"
461 | exit 30
462 | else
463 | echo_red "A script failed during rollback, manual intervention is likely necessary"
464 | echo_red "Delivery log : $LOG_TEMPFILE"
465 | exit 23
466 | fi
467 | exit
468 | fi
469 | CURRENT_STAGE_SCRIPT=""
470 | done
471 | else
472 | echo "No scripts for stage $DELIVERY_STAGE" >&2
473 | fi
474 | }
475 |
476 | function ssh_cleanup
477 | {
478 | # Call the ssh wrapper with only our PID as argument to kill the master SSH connection
479 | "$GIT_SSH"
480 | rm -f "$GIT_SSH"
481 | }
482 |
483 | function ssh_init
484 | {
485 | local remote=$1
486 | export GIT_SSH="/tmp/git_deliver_ssh_wrapper_$$_$remote.sh"
487 | [[ -e "$GIT_SSH" ]] && return # init has already been done for this remote
488 | echo -e "#!/bin/bash\n\n\"$GIT_DELIVER_PATH\"/deliver_ssh_wrapper.sh $$_$remote \"\$@\"" > "$GIT_SSH"
489 | chmod +x "$GIT_SSH"
490 | trap ssh_cleanup EXIT
491 | }
492 |
493 | function remote_info
494 | {
495 | local remote="$1"
496 | [[ $# -gt 1 ]] && local init="$2"
497 | [[ $# -gt 2 ]] && local init_url="$3"
498 |
499 | if echo "$remote" | grep -vE '^[A-Za-z0-9\./_-]+$'; then
500 | echo "Not a valid remote name : $remote"
501 | exit_with_help 22
502 | fi
503 |
504 | git remote -v | grep '^'"$remote"' ' | grep '(push)' &> /dev/null
505 | if [[ $? -gt 0 ]]; then
506 | if [[ -n ${init+defined} ]]; then
507 | if [[ ! -n ${init_url+defined} ]]; then
508 | confirm_or_exit "Remote $remote not found." "Create it ?"
509 | echo ""
510 | read -p "URL for remote :" INIT_URL
511 | fi
512 | git remote add "$remote" "$init_url"
513 | exit_if_error 8 "Error adding remote in local Git config"
514 | if [[ ! -n ${IN_INIT+defined} ]] || [[ ! $IN_INIT ]]; then
515 | init_remote "$remote" "$init_url"
516 | fi
517 | else
518 | exit_with_error 29 "Remote $remote not found."
519 | fi
520 | fi
521 |
522 | REMOTE_URL=`git config --get "remote.$remote.url"`
523 | if echo "$REMOTE_URL" | grep "://" > /dev/null; then
524 | REMOTE_PROTO=`echo "$REMOTE_URL" | cut -d: -f 1`
525 | REMOTE_PROTO=`echo "${REMOTE_PROTO}" | tr '[A-Z]' '[a-z]'`
526 | REMOTE_SERVER=`echo "$REMOTE_URL" | cut -d/ -f 3`
527 | REMOTE_PATH=`echo "$REMOTE_URL" | cut -d/ -f 4-`
528 | if [[ "${REMOTE_PATH:0:1}" != "~" ]]; then
529 | REMOTE_PATH="/$REMOTE_PATH"
530 | fi
531 | elif echo "$REMOTE_URL" | grep ':' > /dev/null; then
532 | if [[ "$OSTYPE" == "msys" ]] && [[ "${REMOTE_URL:1:1}" == ":" ]]; then
533 | REMOTE_PROTO='local'
534 | REMOTE_PATH=`path2unix "$REMOTE_URL"`
535 | REMOTE_SERVER=""
536 | else
537 | REMOTE_PROTO='ssh'
538 | REMOTE_SERVER=`echo "$REMOTE_URL" | cut -d: -f 1`
539 | REMOTE_PATH=`echo "$REMOTE_URL" | cut -d: -f 2`
540 | fi
541 | else
542 | REMOTE_PROTO='local'
543 | REMOTE_SERVER=""
544 | REMOTE_PATH="$REMOTE_URL"
545 | fi
546 | REMOTE_PATH=`echo "$REMOTE_PATH" | sed 's#//#/#g'`
547 | if [[ "$REMOTE_PROTO" == "ssh" ]]; then
548 | ssh_init $remote
549 | fi
550 | if [[ "${REMOTE_PATH:0:1}" = "~" ]]; then
551 | local home_part=${REMOTE_PATH%%[ /]*}
552 | REMOTE_PATH=`run_remote "echo $home_part"`${REMOTE_PATH:${#home_part}}
553 | fi
554 | if [[ "$REMOTE_PROTO" == "local" ]] && [[ "${REMOTE_PATH:0:1}" != "/" ]]; then
555 | REMOTE_PATH="$REPO_ROOT/$REMOTE_PATH"
556 | fi
557 | }
558 |
559 | function run
560 | {
561 | local command="$*"
562 | echo "running $command" >> "$LOG_TEMPFILE"
563 | bash -c "$command"
564 | }
565 |
566 | function run_remote
567 | {
568 | local command="cd /tmp && { $* ; }"
569 | if [[ -n ${REMOTE_SERVER+defined} ]] && [[ "$REMOTE_SERVER" != "" ]]; then
570 | if [[ -n ${LOG_TEMPFILE+defined} ]]; then
571 | echo "running "$GIT_SSH" \"$REMOTE_SERVER\" \"$command\"" >> "$LOG_TEMPFILE"
572 | fi
573 | "$GIT_SSH" "$REMOTE_SERVER" "$command"
574 | else
575 | if [[ -n ${LOG_TEMPFILE+defined} ]]; then
576 | echo "running bash -c \"$command\"" >> "$LOG_TEMPFILE"
577 | fi
578 | bash -c "$command"
579 | fi
580 | }
581 |
582 | function init_remote
583 | {
584 | if [[ $# -gt 3 ]]; then
585 | exit_with_help
586 | fi
587 | IN_INIT=true
588 | INIT_URL=""
589 | [[ $# -gt 1 ]] && INIT_URL="$2"
590 | REMOTE="$1"
591 | remote_info "$REMOTE" true "$INIT_URL"
592 |
593 | if [[ "$REMOTE_PROTO" != "ssh" ]] && [[ "$REMOTE_PROTO" != "local" ]]; then
594 | exit_with_error 17 "Git-deliver can only work with ssh or 'local' remotes"
595 | fi
596 |
597 | run_remote "{ test -d \"$REMOTE_PATH\"/refs && test -d \"$REMOTE_PATH\"/delivered ; } &> /dev/null"
598 | if [[ $? = 0 ]]; then
599 | exit_with_error 18 "This remote looks like it has already been setup for git-deliver."
600 | fi
601 |
602 |
603 | NEED_INIT=true
604 | run_remote "test -e \"$REMOTE_PATH\" &> /dev/null"
605 | if [[ $? = 0 ]]; then
606 | run_remote "test -d \"$REMOTE_PATH\" &> /dev/null"
607 | if [[ $? -gt 0 ]]; then
608 | exit_with_error 10 "ERROR: Remote path points to a file"
609 | else
610 | if [[ `run_remote "ls -1 \"$REMOTE_PATH\" | wc -l | tr -d ' '"` != "0" ]]; then
611 | git fetch "$REMOTE" &> /dev/null
612 | if [[ $? -gt 0 ]]; then
613 | exit_with_error 9 "ERROR : Remote directory is not empty and does not look like a valid Git remote for this repo"
614 | else
615 | NEED_INIT=false
616 | fi
617 | fi
618 | fi
619 | else
620 | run_remote "mkdir -p \"$REMOTE_PATH\" &> /dev/null"
621 | exit_if_error 12 "Error creating root directory on remote"
622 | fi
623 | if $NEED_INIT; then
624 | run_remote "cd \"$REMOTE_PATH\" && \
625 | git init --shared=$FLAGS_shared --bare \"$REMOTE_PATH\" && \
626 | git config --bool receive.autogc false"
627 | exit_if_error 10 "Error initializing repository on remote"
628 | fi
629 |
630 | create_delivered_dir_if_needed
631 |
632 | DELIVERY_STAGE="init-remote"
633 | run_stage_scripts
634 | echo_green "Remote is ready to receive deliveries"
635 | IN_INIT=""
636 | }
637 |
638 | function create_delivered_dir_if_needed
639 | {
640 | run_remote "if [[ ! -d \"$REMOTE_PATH\"/delivered ]]; then
641 | mkdir \"$REMOTE_PATH\"/delivered || exit 1
642 | ls -ld \"$REMOTE_PATH/objects\" | cut -c 6 | grep 'w' ;
643 | if [[ \$? = 0 ]]; then
644 | chgrp \`ls -gd \"$REMOTE_PATH/objects\" | awk '{print \$3}'\` \"$REMOTE_PATH/delivered\" && \
645 | chmod g+w \"$REMOTE_PATH/delivered\" ;
646 | fi ;
647 | fi"
648 | exit_if_error 11 "Error creating 'delivered' directory in remote root"
649 | }
650 |
651 | function remote_gc
652 | {
653 | if [[ $# -gt 1 ]] || [[ $# -lt 1 ]]; then
654 | exit_with_help
655 | fi
656 | local remote="$1"
657 | remote_info "$remote"
658 | if [[ "$REMOTE_PROTO" != "ssh" ]] && [[ "$REMOTE_PROTO" != "local" ]]; then
659 | exit_with_error 17 "$remote is not a Git-deliver remote"
660 | fi
661 | LOG_TEMPFILE=`make_temp_file`
662 | local gc_script="
663 | CURVER=\`{ cd \"$REMOTE_PATH/delivered/current\" && pwd -P && cd - > /dev/null ; } 2> /dev/null\` ;
664 | PREVER=\`{ cd \"$REMOTE_PATH/delivered/previous\" && pwd -P && cd - > /dev/null ; } 2> /dev/null\`;
665 | PREPREVER=\`{ cd \"$REMOTE_PATH/delivered/preprevious\" && pwd -P && cd - > /dev/null ; } 2> /dev/null\`;
666 | DELETED=0 ;
667 | FREED_BYTES=0 ;
668 | STATUS=0 ;
669 | for rep in \"$REMOTE_PATH/delivered/\"* ; do
670 | if [ ! -L \"\$rep\" ]; then
671 | rep=\`{ cd \"\$rep\" && pwd -P && cd - > /dev/null ; } 2> /dev/null\` ;
672 | if [ \"\$rep\" != \"\$CURVER\" ] &&
673 | [ \"\$rep\" != \"\$PREVER\" ] &&
674 | [ \"\$rep\" != \"\$PREPREVER\" ]; then
675 | echo \"Removing \$rep\" ;
676 | if ( du --version 2>/dev/null | grep -q GNU\ ) ; then
677 | FREED_BYTES_NEW=\`du -sb \"\$rep\" | cut -f1\` ;
678 | else
679 | FREED_BYTES_NEW=\`du -s \"\$rep\" | awk '{printf \"%d\", \$1/512}'\` ;
680 | fi ;
681 | rm -rf \"\$rep\" && \
682 | DELETED=\$((\$DELETED + 1)) && \
683 | FREED_BYTES=\$((\$FREED_BYTES + \$FREED_BYTES_NEW)) || \
684 | STATUS=27 ;
685 | fi ;
686 | fi ;
687 | done ;
688 | if [[ \$FREED_BYTES = 0 ]]; then
689 | HUMAN_FREED_BYTES=\"0 B\" ;
690 | else
691 | HUMAN_FREED_BYTES=\`echo \$FREED_BYTES | awk '{x = \$0;
692 | split(\"B KB MB GB TB PB\", type);
693 | for(i=5;y < 1;i--)
694 | y = x / (2^(10*i));
695 | print y \" \" type[i+2];
696 | }'\` ;
697 | fi ;
698 | echo \"\$DELETED version(s) removed, \$HUMAN_FREED_BYTES freed\" ;
699 | cd \"$REMOTE_PATH\"/delivered && git gc --auto ;
700 | exit \$STATUS"
701 | run_remote "$gc_script"
702 | local status=$?
703 | rm -f "$LOG_TEMPFILE"
704 | exit $status
705 | }
706 |
707 | function make_temp_file
708 | {
709 | local tempdir
710 | local tempfile
711 | if [[ -n ${TMPDIR+defined} ]] && [[ "$TMPDIR" != "" ]]; then
712 | tempdir="$TMPDIR"
713 | else
714 | tempdir="/tmp"
715 | fi
716 | which mktemp &> /dev/null
717 | if [[ $? = 0 ]]; then
718 | mktemp "$tempdir/git-deliver-XXXXXXXXXX"
719 | else
720 | tempfile="$tempdir"/git-deliver-$$.$RANDOM
721 | touch "$tempfile"
722 | echo "$tempfile"
723 | fi
724 | }
725 |
726 | function get_branch_for_version
727 | {
728 | # branches containing version
729 | local eligible_branches=`git branch -a --contains $1 | grep -v '(no branch)' | tr -d '^ *' | tr -d '^ ' | sed 's/^remotes\///'`
730 |
731 | # if version is a branch, picks it
732 | local branch=`echo "$eligible_branches" | grep "^$1$" | head -n 1`
733 |
734 | # else, tries currently checked-out branch if eligible
735 | local current_branch=`git rev-parse --symbolic-full-name --abbrev-ref HEAD`
736 | if [[ "$branch" == "" ]]; then
737 | branch=`echo "$eligible_branches" | grep "^$current_branch$" | head -n 1`
738 | fi
739 |
740 | # else, tries master if eligible
741 | if [[ "$branch" == "" ]]; then
742 | branch=`echo "$eligible_branches" | grep "^master$" | head -n 1`
743 | fi
744 |
745 | # else, picks first eligible branch
746 | if [[ "$branch" == "" ]]; then
747 | branch=`echo "$eligible_branches" | head -n 1`
748 | fi
749 |
750 | echo "$branch"
751 | }
752 |
753 | function deliver
754 | {
755 | if [[ $# -gt 2 ]] || [[ $# -lt 1 ]]; then
756 | exit_with_help
757 | fi
758 | REMOTE="$1"
759 |
760 | if [[ $IS_ROLLBACK == false ]] && [[ $# -lt 2 ]]; then
761 | exit_with_help
762 | fi
763 | [[ $# -gt 1 ]] && VERSION="$2"
764 |
765 | CURRENT_STAGE_SCRIPT=""
766 | LAST_STAGE_REACHED=""
767 | LOG_TEMPFILE=`make_temp_file`
768 |
769 | echo "#" > "$LOG_TEMPFILE"
770 | echo "# This is the log of your delivery" >> "$LOG_TEMPFILE"
771 | echo "# It will be added as a note on the delivery tag" >> "$LOG_TEMPFILE"
772 | echo "# You can customize the note now, before the tag is created" >> "$LOG_TEMPFILE"
773 | echo "# Lines starting with # will be ignored" >> "$LOG_TEMPFILE"
774 | echo "#" >> "$LOG_TEMPFILE"
775 | echo "" >> "$LOG_TEMPFILE"
776 |
777 | if [[ -n ${VERSION+defined} ]]; then
778 | if [[ $IS_ROLLBACK == "false" ]]; then
779 | echo -en "Delivery of ref \"$VERSION\" to" >> "$LOG_TEMPFILE"
780 | else
781 | echo -en "Rollback to \"$VERSION\" on" >> "$LOG_TEMPFILE"
782 | fi
783 | else
784 | echo -en "Rollback to previous version on" >> "$LOG_TEMPFILE"
785 | fi
786 |
787 | echo -e " remote \"$REMOTE\"\n\n" >> "$LOG_TEMPFILE"
788 |
789 | if [[ ! -d "$REPO_ROOT/.deliver" ]]; then
790 | confirm_or_exit ".deliver not found." "Run init ?"
791 | init
792 | fi
793 |
794 | remote_info "$REMOTE"
795 |
796 | if [[ "$REMOTE_PROTO" != "ssh" ]] && [[ "$REMOTE_PROTO" != "local" ]]; then
797 | exit_with_error 17 "Git-deliver can only work with ssh or 'local' remotes"
798 | fi
799 |
800 | check_git_version_and_ssh_connectivity "$REMOTE"
801 |
802 | local remote_dir_list=`run_remote "cd \"$REMOTE_PATH\" 2> /dev/null && ls -1 2> /dev/null"`
803 | if [[ "$remote_dir_list" = "" ]]; then
804 | init_remote "$REMOTE"
805 | else
806 | local remote_dir_git_count=`echo "$remote_dir_list" | grep "^objects\|refs$" | wc -l | tr -d ' '`
807 | if [[ "$remote_dir_git_count" -lt "2" ]]; then
808 | exit_with_error 1 "ERROR : Remote does not look like a bare git repo"
809 | fi
810 | fi
811 |
812 | # If this projet has init-remote scripts, check that the remote has been init. Otherwise, we don't really care, as it's just a matter of creating the 'delivered' directory
813 |
814 | if [[ -e "$REPO_ROOT"/.deliver/scripts/init-remote ]] && test -n "$(find "$REPO_ROOT/.deliver/scripts/init-remote" -maxdepth 1 -name '*.sh' -print)"; then
815 | run_remote "test -d \"$REMOTE_PATH\"/delivered"
816 | if [[ $? -gt 0 ]]; then
817 | exit_with_error 22 "ERROR : Remote has not been init"
818 | fi
819 | fi
820 |
821 | if [[ $IS_ROLLBACK == false ]]; then
822 | VERSION_SHA=`git rev-parse --revs-only $VERSION 2> /dev/null`
823 |
824 | if [[ "$VERSION_SHA" = "" ]]; then
825 | confirm_or_exit "Ref $VERSION not found." "Tag current HEAD ?"
826 | VERSION_SHA=`git rev-parse HEAD`
827 | echo "Tagging current HEAD" >&2
828 | git tag $VERSION
829 | local tag_to_push=$VERSION
830 | fi
831 | fi
832 |
833 | local rstatus
834 | rstatus=`remote_status "$REMOTE" 1`
835 |
836 | local rstatus_code=$?
837 | if [[ $rstatus_code -lt 3 ]]; then
838 | echo "No version delivered yet on $REMOTE" >&2
839 | if [[ $IS_ROLLBACK == true ]]; then
840 | exit_with_error 24 "Cannot rollback"
841 | fi
842 | else
843 | local version_line=`echo "$rstatus" | head -n +2 | tail -n 1`
844 | PREVIOUS_VERSION_SHA="${version_line:3:43}"
845 | echo "Current version on $REMOTE:"
846 | echo "$rstatus" >&2
847 | fi
848 |
849 | DELIVERY_DATE=`( date --version 2>/dev/null | grep -q GNU\ && date +'%F_%H-%M-%S%N' ) || ( which gdate &>/dev/null && gdate +'%F_%H-%M-%S%N' ) || ( which python &> /dev/null && python -c 'import datetime; print datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S%f")' ) || ( date +'%F_%H-%M-%S' )`
850 | DELIVERY_DATE=${DELIVERY_DATE:0:21}
851 |
852 | local delivered_by_name=`git config --get user.name`
853 | local delivered_by_email=`git config --get user.email`
854 |
855 | run_remote "mv --version 2>/dev/null | grep -q GNU\ || which python &> /dev/null"
856 | if [[ $? -ne 0 ]]; then
857 | confirm_or_exit "Warning: remote has neither GNU mv nor Python installed. Delivery will not be atomic : for a very short time, the 'current' symlink will not exist." "" false
858 | fi
859 |
860 | trap delivery_sigint_handler SIGINT
861 |
862 | if [[ $IS_ROLLBACK == true ]]; then
863 | local rollback_to_version;
864 | if [[ -n ${VERSION+defined} ]]; then
865 | rollback_to_version="$VERSION"
866 | else
867 | rollback_to_version="previous"
868 | fi
869 | DELIVERY_PATH=`run_remote "cd \"$REMOTE_PATH/delivered/$rollback_to_version\" && pwd -P" 2>&1`
870 | if [[ $? -gt 0 ]]; then
871 | if [[ -n ${VERSION+defined} ]]; then
872 | exit_with_error 25 "Delivery $VERSION not found on remote. Use 'git deliver --status ' to list available previous deliveries."
873 | else
874 | exit_with_error 25 "No previous version found; cannot rollback"
875 | fi
876 | fi
877 | local delivery_infos
878 | delivery_infos=`run_remote "cd \"$DELIVERY_PATH\" && git log -n 1 --skip=1 --pretty=format:%H && echo "" && git show --pretty=format:'%aD by %aN <%aE>' _delivered | head -n 1" 2>&1`
879 | exit_if_error 26 "Error getting information on version to rollback to."
880 | VERSION_SHA=`echo "$delivery_infos" | head -n 1`
881 | local rollback_target_info=`echo "$delivery_infos" | tail -n 1`
882 | DELIVERY_BASENAME=`basename "$DELIVERY_PATH"`
883 | SYMLINK_MSG="Rolling back the 'current' symlink to the delivery $DELIVERY_BASENAME ($VERSION_SHA), delivered $rollback_target_info"
884 | else
885 | local human_version="${VERSION_SHA:0:6}"
886 | if [[ $VERSION != $VERSION_SHA ]]; then
887 | human_version="$human_version"_"${VERSION/\//_}"
888 | fi
889 | DELIVERY_BASENAME="$DELIVERY_DATE"_"$human_version"
890 | DELIVERY_PATH="$REMOTE_PATH/delivered/$DELIVERY_BASENAME"
891 |
892 | local branch=`get_branch_for_version $VERSION`
893 | if [[ "$branch" == "" ]]; then
894 | exit_with_error 16 "No branch found for ref $VERSION, commit must belong to a branch to be deliverable"
895 | fi
896 |
897 | DELIVERY_STAGE="local-build"
898 | LBVERSION="$VERSION"
899 | if test -n "$(find "$REPO_ROOT/.deliver/scripts/$DELIVERY_STAGE" -maxdepth 1 -name '*.sh' -print 2> /dev/null)"; then
900 | local lbclone="$REPO_ROOT/.deliver/tmp/lbclone"
901 | if [[ -d "$lbclone/.git" ]]; then
902 | run "cd \"$lbclone\" && git fetch origin && git reset --hard origin/$branch; cd -" 2>&1 | indent 1
903 | else
904 | run "git clone --recursive \"$REPO_ROOT\" \"$lbclone\"" 2>&1 | indent 1
905 | fi
906 | exit_if_error 32 "Cannot create local-build clone"
907 | cd "$lbclone"
908 | run "git checkout \"$VERSION\"" 2>&1 | indent 1
909 | exit_if_error 33 "Cannot checkout in local-build clone"
910 | run "cd \"$lbclone\" && git submodule update --init --recursive; cd -" 2>&1 | indent 1
911 | exit_if_error 34 "Cannot update submodules in local-build clone"
912 | cd "$lbclone"
913 | run_stage_scripts
914 | run "git commit -am \"git-deliver local-build commit\"" 2>&1 | indent 1
915 | [[ $? -eq 0 ]] && LBVERSION=`git log --pretty=format:%H -n 1`
916 | cd "$REPO_ROOT"
917 | fi
918 |
919 | DELIVERY_STAGE="pre-delivery"
920 | run_stage_scripts
921 |
922 | echo "Pushing necessary commits to remote"
923 | local delivery_branch=`echo $branch | cut -d"/" -f2`
924 | [[ $FLAGS_force == true ]] && local force="--force" || local force=""
925 | run "git push $force \"$REMOTE\" $branch:$delivery_branch" 2>&1 | indent 1
926 | if [[ ${PIPESTATUS[0]} -gt 0 ]]; then
927 | exit 14 ;
928 | fi
929 |
930 | local tags=$(git show-ref --tags -d | grep "^$VERSION_SHA" | sed -e 's,.* refs/tags/,,' -e 's/\^{}//g' | grep -v '^delivered-' | tr "\\n" " ")
931 | if [[ "$tags" != "" ]]; then
932 | run "git push $force \"$REMOTE\" tag $tags"
933 | exit_if_error 13
934 | fi
935 |
936 | create_delivered_dir_if_needed
937 |
938 | # Checkout the files in a new directory. We actually do a full clone of the remote's bare repository in a new directory for each delivery. Using a working copy instead of just the files allows the status of the files to be checked easily. The git objects are shared with the base repository.
939 |
940 | echo "Creating new delivery clone"
941 | run_remote "git clone --shared --no-checkout \"$REMOTE_PATH\" \"$DELIVERY_PATH\" && echo '../../../../objects' > \"$DELIVERY_PATH\"/.git/objects/info/alternates"
942 | if [[ ${PIPESTATUS[0]} -gt 0 ]]; then
943 | exit_with_error 5 "Error cloning repo to delivered folder on remote" ;
944 | fi
945 |
946 | echo "Checking out files..." | indent 1
947 | run_remote "cd \"$DELIVERY_PATH\" && git branch _delivered $VERSION_SHA" 2>&1 | indent 1
948 | if [[ ${PIPESTATUS[0]} -gt 0 ]]; then
949 | exit_with_error 15 "Error creating tracking branch on remote clone" ;
950 | fi
951 |
952 | if [[ "$LBVERSION" != "$VERSION" ]]; then
953 | echo "Pushing local build files to delivery clone"
954 | run "cd \"$lbclone\" && git push $force \"$REMOTE_SERVER\":\"$DELIVERY_PATH\" $LBVERSION:_delivered ; cd \"$REPO_ROOT\"" 2>&1
955 | fi
956 |
957 | run_remote "cd \"$DELIVERY_PATH\" && git checkout _delivered" 2>&1 | indent 1
958 | if [[ ${PIPESTATUS[0]} -gt 0 ]]; then
959 | exit_with_error 6 "Error checking out remote clone"
960 | fi
961 |
962 | run_remote "cd \"$DELIVERY_PATH\" && git submodule update --init --recursive" 2>&1 | indent 1
963 | if [[ ${PIPESTATUS[0]} -gt 0 ]]; then
964 | exit_with_error 7 "Error initializing submodules"
965 | fi
966 |
967 | DELIVERY_STAGE="post-checkout"
968 | run_stage_scripts
969 |
970 | # Commit after the post-checkouts have run and might have changed a few things (added production database passwords for instance).
971 | # This guarantees the integrity of our delivery from then on. The commit can also be signed to authenticate the delivery.
972 |
973 | run_remote "cd \"$DELIVERY_PATH\" && GIT_COMMITTER_NAME=\"$delivered_by_name\" GIT_COMMITTER_EMAIL=\"$delivered_by_email\" git commit --author \"$delivered_by_name <$delivered_by_email>\" --allow-empty -a -m \"Git-deliver automated commit\""
974 |
975 | run_remote "ls -ld \"$REMOTE_PATH/objects\" | cut -c 6 | grep 'w' && chgrp -R \`ls -gd \"$REMOTE_PATH/objects\" | awk '{print \$3}'\` \"$DELIVERY_PATH\" && chmod -R g+w \"$DELIVERY_PATH\""
976 |
977 |
978 | SYMLINK_MSG="Switching the 'current' symlink to the newly delivered version."
979 | # Using a symlink makes our delivery atomic.
980 | fi
981 |
982 | DELIVERY_STAGE="pre-symlink"
983 | run_stage_scripts
984 |
985 | echo "$SYMLINK_MSG"
986 |
987 | run_remote "test -L \"$REMOTE_PATH/delivered/preprevious\" && { rm -f \"$REMOTE_PATH/delivered/prepreprevious\"; mv \"$REMOTE_PATH/delivered/preprevious\" \"$REMOTE_PATH/delivered/prepreprevious\" || exit 5 ; } ; \
988 | test -L \"$REMOTE_PATH/delivered/previous\" && { mv \"$REMOTE_PATH/delivered/previous\" \"$REMOTE_PATH/delivered/preprevious\" || exit 4 ; } ; \
989 | test -L \"$REMOTE_PATH/delivered/current\" && { cp -d \"$REMOTE_PATH/delivered/current\" \"$REMOTE_PATH/delivered/previous\" || exit 3 ; } ; \
990 | cd \"$REMOTE_PATH\"/delivered ; \
991 | if ( mv --version 2>/dev/null | grep -q GNU\ ) ; then \
992 | { ln -sfn \"$DELIVERY_BASENAME\" \"new\" || exit 2 ; } && { mv -Tf \"$REMOTE_PATH/delivered/new\" \"$REMOTE_PATH/delivered/current\" || exit 1 ; } ; \
993 | elif ( which python &> /dev/null ) ; then \
994 | { ln -sfn \"$DELIVERY_BASENAME\" \"new\" || exit 2 ; } && { python -c 'import os; os.rename(\"$REMOTE_PATH/delivered/new\",\"$REMOTE_PATH/delivered/current\");' || exit 1 ; } ; \
995 | else \
996 | ln -sfn \"$DELIVERY_BASENAME\" \"current\" || exit 2 ; \
997 | fi ; \
998 | exit 0"
999 |
1000 | SYMLINK_SWITCH_STATUS=$?
1001 |
1002 | if [[ $SYMLINK_SWITCH_STATUS -gt 0 ]]; then
1003 | echo "Error switching symlinks"
1004 | rollback "pre-symlink"
1005 | fi
1006 |
1007 | DELIVERY_STAGE="post-symlink"
1008 | run_stage_scripts
1009 |
1010 | run_remote "test -L \"$REMOTE_PATH/delivered/prepreprevious\" && rm \"$REMOTE_PATH/delivered/prepreprevious\""
1011 |
1012 | if [[ $FLAGS_batch == false ]]; then
1013 | local geditor=`git var GIT_EDITOR`
1014 | if [[ "$geditor" = "" ]]; then
1015 | geditor="vi"
1016 | fi
1017 | bash -c "$geditor \"$LOG_TEMPFILE\""
1018 | fi
1019 |
1020 | # TAG the delivered version
1021 | local tag_name="delivered-$REMOTE-$DELIVERY_DATE"
1022 | echo "Tagging delivery commit"
1023 | git tag -F "$LOG_TEMPFILE" "$tag_name" "$VERSION_SHA" 2>&1 | indent 1
1024 | run "git push \"$REMOTE\" refs/tags/\"$tag_name\"" 2>&1 | indent 1
1025 | rm -f "$LOG_TEMPFILE"
1026 | local tag_to_push_msg=""
1027 | if [[ -n ${tag_to_push+defined} ]] && [[ "$tag_to_push" != "" ]]; then
1028 | tag_to_push_msg=" and tag $tag_to_push (git push origin $tag_to_push ?)"
1029 | fi
1030 | echo_green "Delivery complete."
1031 | echo "You might want to publish tag $tag_name (git push origin $tag_name ?)${tag_to_push_msg:-}"
1032 | }
1033 |
1034 | function delivery_sigint_handler
1035 | {
1036 | echo "Caught SIGINT"
1037 | if [[ "$DELIVERY_STAGE" != "rollback-pre-symlink" ]] && [[ "$DELIVERY_STAGE" != "rollback-post-symlink" ]]; then
1038 | LAST_STAGE_REACHED="$DELIVERY_STAGE"
1039 | FAILED_SCRIPT="$CURRENT_STAGE_SCRIPT"
1040 | FAILED_SCRIPT_EXIT_STATUS=0
1041 | rollback
1042 | else
1043 | exit_with_error 23 "Delivery aborted during rollback, manual intervention is likely necessary\nDelivery log : $LOG_TEMPFILE"
1044 | fi
1045 | }
1046 |
1047 | function check_git_version_and_ssh_connectivity
1048 | {
1049 | local remote_git_version
1050 | remote_git_version=`run_remote "git --version 2> /dev/null"`
1051 | local code=$?
1052 |
1053 | if [[ $code = 127 ]]; then
1054 | exit_with_error 11 "ERROR: Git needs to be installed and in \$PATH on the remote"
1055 | elif [[ $code = 255 ]]; then
1056 | exit_with_error 28 "ERROR: Could not open SSH connection"
1057 | fi
1058 | }
1059 |
1060 | function rollback
1061 | {
1062 | echo "Rolling back"
1063 | DELIVERY_STAGE="rollback-pre-symlink"
1064 | run_stage_scripts "$DELIVERY_STAGE"
1065 |
1066 | if [[ -n ${SYMLINK_SWITCH_STATUS+defined} ]] && [[ $SYMLINK_SWITCH_STATUS -lt 5 ]]; then
1067 | local symlink_rollback
1068 | if [[ $SYMLINK_SWITCH_STATUS = 0 ]]; then
1069 | symlink_rollback="if test -L \"$REMOTE_PATH/delivered/previous\"; then \
1070 | if ( mv --version 2>/dev/null | grep -q GNU\ ) ; then \
1071 | mv -Tf \"$REMOTE_PATH/delivered/previous\" \"$REMOTE_PATH/delivered/current\"; \
1072 | elif ( which python &> /dev/null ) ; then \
1073 | python -c 'import os; os.rename(\"$REMOTE_PATH/delivered/previous\",\"$REMOTE_PATH/delivered/current\");'; \
1074 | else \
1075 | rm -f \"$REMOTE_PATH/delivered/current\" && mv \"$REMOTE_PATH/delivered/previous\" \"$REMOTE_PATH/delivered/current\" ; \
1076 | fi ; \
1077 | else rm -f \"$REMOTE_PATH/delivered/current\"; fi"
1078 | elif [[ $SYMLINK_SWITCH_STATUS = 1 ]]; then
1079 | symlink_rollback="rm -f \"$REMOTE_PATH/delivered/new\""
1080 | fi
1081 | if [[ $SYMLINK_SWITCH_STATUS -lt 3 ]]; then
1082 | symlink_rollback="$symlink_rollback ; rm -f \"$REMOTE_PATH/delivered/previous\"; test -L \"$REMOTE_PATH/delivered/preprevious\" && mv \"$REMOTE_PATH/delivered/preprevious\" \"$REMOTE_PATH/delivered/previous\""
1083 | fi
1084 | symlink_rollback="$symlink_rollback ; test -L \"$REMOTE_PATH/delivered/prepreprevious\" && mv \"$REMOTE_PATH/delivered/prepreprevious\" \"$REMOTE_PATH/delivered/preprevious\""
1085 |
1086 | run_remote "$symlink_rollback"
1087 | fi
1088 |
1089 | DELIVERY_STAGE="rollback-post-symlink"
1090 | run_stage_scripts "$DELIVERY_STAGE"
1091 | }
1092 |
1093 | function validate_command
1094 | {
1095 | if [[ "$COMMAND" -ne "" ]]; then
1096 | echo_red "Unknown option : $COMMAND"
1097 | exit_with_help
1098 | fi
1099 | COMMAND="$OPTARG"
1100 | }
1101 |
1102 | function validate_option
1103 | {
1104 | if [[ $OPTIND = 2 ]]; then
1105 | echo_red "Unknown command : $OPTARG"
1106 | exit_with_help
1107 | fi
1108 | }
1109 |
1110 | FLAGS_batch=false
1111 | FLAGS_force=false
1112 | FLAGS_shared="false"
1113 | IS_ROLLBACK=false
1114 |
1115 | COMMAND=""
1116 | FN=""
1117 |
1118 | optspec=":h-:"
1119 | while getopts "$optspec" optchar; do
1120 | case "${optchar}" in
1121 | -)
1122 | case "${OPTARG}" in
1123 | help)
1124 | exit_with_help
1125 | ;;
1126 | batch)
1127 | FLAGS_batch=true
1128 | ;;
1129 | color)
1130 | USECOLOR=true
1131 | ;;
1132 | force)
1133 | FLAGS_force=true
1134 | ;;
1135 | nocolor)
1136 | USECOLOR=false
1137 | ;;
1138 | shared)
1139 | validate_option
1140 | if [[ "$COMMAND" -ne "--init" ]]; then
1141 | exit_with_error 27 "Uknown option '--shared' for command $COMMAND"
1142 | fi
1143 | FLAGS_shared="false"
1144 | ;;
1145 | shared=*)
1146 | validate_option
1147 | if [[ "$COMMAND" -ne "--init" ]]; then
1148 | exit_with_error 27 "Uknown option '--shared' for command $COMMAND"
1149 | fi
1150 | FLAGS_shared=${OPTARG#*=}
1151 | ;;
1152 | # COMMANDS
1153 | source)
1154 | validate_command
1155 | return
1156 | ;;
1157 | init)
1158 | validate_command
1159 | FN="init"
1160 | ;;
1161 | init-remote)
1162 | validate_command
1163 | FN="init_remote"
1164 | ;;
1165 | list-presets)
1166 | validate_command
1167 | FN="list_presets"
1168 | ;;
1169 | status)
1170 | validate_command
1171 | FN="remote_status"
1172 | ;;
1173 | gc)
1174 | validate_command
1175 | FN="remote_gc"
1176 | ;;
1177 | rollback)
1178 | validate_command
1179 | IS_ROLLBACK=true
1180 | FN="deliver"
1181 | ;;
1182 | *)
1183 | if [[ $OPTIND -gt 1 ]]; then
1184 | echo_red "Unknown option : $OPTARG"
1185 | else
1186 | echo_red "Unknown command : $OPTARG"
1187 | fi
1188 | exit_with_help
1189 | ;;
1190 | esac;;
1191 | h)
1192 | exit_with_help
1193 | ;;
1194 | esac
1195 | done
1196 |
1197 | shift "$((OPTIND - 1))"
1198 |
1199 | if [[ "$FN" = "" ]]; then
1200 | deliver "$@"
1201 | else
1202 | $FN "$@"
1203 | fi
1204 |
1205 |
--------------------------------------------------------------------------------
/deliver_ssh_wrapper.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | #
4 | # Copyright 2012-2015 Arnaud Betremieux
5 | #
6 | # This file is a part of Git-deliver.
7 | #
8 | # Adapted with authorization from Ross Patterson's SSH wrapper
9 | # (http://ratterson.net/blog/re-using-and-multiplexing-ssh)
10 | #
11 | # The program in this file is free software: you can redistribute it
12 | # and/or modify it under the terms of the GNU General Public License
13 | # as published by the Free Software Foundation, either version 3 of
14 | # the License, or (at your option) any later version.
15 | #
16 | # This program is distributed in the hope that it will be useful,
17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | # GNU General Public License for more details.
20 | #
21 | # You should have received a copy of the GNU General Public License
22 | # along with this program. If not, see .
23 | #
24 |
25 | ## This is a Wrapper script for ssh that creates a control master
26 | ## in the background if one isn't already started.
27 |
28 |
29 | master_id=$1
30 | shift
31 |
32 | if [[ $# == 0 ]]; then
33 | ssh -q -S ${master_id} -O exit not_used &> /dev/null
34 | exit
35 | fi
36 |
37 | ## OpenSSH as included in the current msys or cygwin installs does not support
38 | ## multiplexing with privilege separation -> forget it
39 | if [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "cygwin" ]]; then
40 | exec ssh "$@"
41 | fi
42 |
43 | ## optstring assembled from `man ssh`
44 | optstring="+1246AaCfgKkMNnqsTtVvXxYb:c:D:e:F:i:L:l:m:O:o:p:R:S:w:z"
45 | ## get ssh options
46 | while getopts "$optstring" optchar; do
47 | true
48 | done
49 |
50 | ## the host is the first non-option arg
51 | host="${!OPTIND}"
52 |
53 | ## if the master isn't running, start it in the background
54 | ssh -S $master_id -q -O check not_used 2>/dev/null || { SSH_OPTION=`ssh -V 2>&1 | awk 'BEGIN {FS="_"} $2>=5.6 { print "-o ControlPersist=5m"}'` ; ssh $SSH_OPTION -S $master_id -MNf $host > /dev/null || exit 255; }
55 |
56 | ## replace ourselves with the reall ssh call
57 | exec ssh -S $master_id "$@"
58 |
--------------------------------------------------------------------------------
/lib/shunit2:
--------------------------------------------------------------------------------
1 | # $Id: shunit2 93 2007-07-12 22:44:31Z sfsetse $
2 | # vim:syntax=sh:sts=2
3 | # vim:foldmethod=marker:foldmarker=/**,*/
4 | #
5 | #/**
6 | #
7 | #
8 | #
9 | # shUnit 2.0.3
10 | # Shell Unit Test Framework
11 | #
12 | # http://shunit2.sourceforge.net/
13 | #
14 | # written by Kate Ward <kate.ward@forestent.com>
15 | # released under the LGPL
16 | #
17 | # this module implements a xUnit based unit test framework similar to JUnit
18 | #
19 | #*/
20 |
21 | # shell flags for shunit:
22 | # u - treat unset variables as an error when performing parameter expansion
23 | __SHUNIT_SHELL_FLAGS='u'
24 |
25 | # save the current set of shell flags, and then set some for ourselves
26 | __shunit_oldShellFlags="$-"
27 | for _shunit_shellFlag in `echo "${__SHUNIT_SHELL_FLAGS}" |sed 's/\(.\)/\1 /g'`
28 | do
29 | set -${_shunit_shellFlag}
30 | done
31 |
32 | # constants
33 |
34 | __SHUNIT_VERSION='2.0.3'
35 |
36 | __SHUNIT_TRUE=0
37 | __SHUNIT_FALSE=1
38 |
39 | __SHUNIT_ASSERT_MSG_PREFIX='ASSERT:'
40 |
41 | for _su_const in `set |grep "^__SHUNIT_" |cut -d= -f1`; do
42 | readonly ${_su_const}
43 | done
44 | unset _su_const
45 |
46 | # variables
47 | __shunit_suite=''
48 |
49 | __shunit_testsPassed=0
50 | __shunit_testsFailed=0
51 | __shunit_testsTotal=0
52 |
53 | #-----------------------------------------------------------------------------
54 | # assert functions
55 | #
56 |
57 | #/**
58 | #
59 | #
60 | # void
61 | #
62 | #
63 | #
64 | #
65 | # assertEquals
66 | # string [message]
67 | # string expected
68 | # string actual
69 | #
70 | #
71 | # Asserts that expected and
72 | # actual are equal to one another. The message is
73 | # optional.
74 | #
75 | #
76 | #*/
77 | assertEquals()
78 | {
79 | _su_message=''
80 | if [ $# -eq 3 ]; then
81 | _su_message=$1
82 | shift
83 | fi
84 | _su_expected=${1:-}
85 | _su_actual=${2:-}
86 |
87 | shunit_return=${__SHUNIT_TRUE}
88 | if [ "${_su_expected}" = "${_su_actual}" ]; then
89 | _shunit_testPassed
90 | else
91 | failNotEquals "${_su_message}" "${_su_expected}" "${_su_actual}"
92 | shunit_return=${__SHUNIT_FALSE}
93 | fi
94 |
95 | unset _su_message _su_expected _su_actual
96 | return ${shunit_return}
97 | }
98 |
99 | #/**
100 | #
101 | #
102 | # void
103 | #
104 | #
105 | #
106 | #
107 | # assertNull
108 | # string [message]
109 | # string value
110 | #
111 | #
112 | # Asserts that value is null,
113 | # or in shell terms a zero-length string. The message is optional.
114 | #
115 | #
116 | #*/
117 | assertNull()
118 | {
119 | if [ $# -eq 2 ]; then
120 | assertTrue "$1" "[ -z '$2' ]"
121 | else
122 | assertTrue "[ -z '${1:-}' ]"
123 | fi
124 | }
125 |
126 | #/**
127 | #
128 | #
129 | # void
130 | #
131 | #
132 | #
133 | #
134 | # assertNotNull
135 | # string [message]
136 | # string value
137 | #
138 | #
139 | # Asserts that value is notnull, or in shell terms not
141 | # a zero-length string. The message is optional.
142 | #
143 | #
144 | #*/
145 | assertNotNull()
146 | {
147 | if [ $# -eq 2 ]; then
148 | assertTrue "$1" "[ -n '$2' ]"
149 | else
150 | assertTrue "[ -n '${1:-}' ]"
151 | fi
152 | }
153 |
154 | #/**
155 | #
156 | #
157 | # void
158 | #
159 | #
160 | #
161 | #
162 | # assertSame
163 | # string [message]
164 | # string expected
165 | # string actual
166 | #
167 | #
168 | # This function is functionally equivalent to
169 | # assertEquals.
170 | #
171 | #
172 | #*/
173 | assertSame()
174 | {
175 | assertEquals "${@:-}"
176 | }
177 |
178 | #/**
179 | #
180 | #
181 | # void
182 | #
183 | #
184 | #
185 | #
186 | # assertNotSame
187 | # string [message]
188 | # string unexpected
189 | # string actual
190 | #
191 | #
192 | # Asserts that unexpected and
193 | # actual are not
194 | # equal to one another. The message is optional.
195 | #
196 | #
197 | #*/
198 | assertNotSame()
199 | {
200 | _su_message=''
201 | if [ $# -eq 3 ]; then
202 | _su_message=$1
203 | shift
204 | fi
205 | _su_unexpected=${1:-}
206 | _su_actual=${2:-}
207 |
208 | shunit_return=${__SHUNIT_TRUE}
209 | if [ "${_su_unexpected}" != "${_su_actual}" ]; then
210 | _shunit_testPassed
211 | else
212 | failSame "${_su_message}"
213 | shunit_return=${__SHUNIT_FALSE}
214 | fi
215 |
216 | unset _su_message _su_unexpected _su_actual
217 | return ${shunit_return}
218 | }
219 |
220 | #/**
221 | #
222 | #
223 | # void
224 | #
225 | #
226 | #
227 | #
228 | # assertTrue
229 | # string [message]
230 | # string condition
231 | #
232 | #
233 | # Asserts that a given shell test condition is true. The message is
234 | # optional.
235 | # Testing whether something is true or false is easy enough by using
236 | # the assertEquals/assertNotSame functions. Shell supports much more
237 | # complicated tests though, and a means to support them was needed. As such,
238 | # this function tests that conditions are true or false through evaluation
239 | # rather than just looking for a true or false.
240 | #
241 | # The following test will succeed: assertTrue "[ 34 -gt 23 ]"
242 | # The folloing test will fail with a message: assertTrue "test failed" "[ -r '/non/existant/file' ]"
243 | #
244 | #
245 | #
246 | #*/
247 | assertTrue()
248 | {
249 | _su_message=''
250 | if [ $# -eq 2 ]; then
251 | _su_message=$1
252 | shift
253 | fi
254 | _su_condition=${1:-}
255 |
256 | shunit_return=${__SHUNIT_TRUE}
257 |
258 | # see if condition is an integer, i.e. a return value
259 | _su_match=`expr "${_su_condition}" : '\([0-9]*\)'`
260 | if [ -z "${_su_condition}" ]; then
261 | # null condition
262 | shunit_return=${__SHUNIT_FALSE}
263 | elif [ "${_su_condition}" = "${_su_match}" ]; then
264 | # possible return value. treating 0 as true, and non-zero as false.
265 | [ ${_su_condition} -ne 0 ] && shunit_return=${__SHUNIT_FALSE}
266 | else
267 | # (hopefully) a condition
268 | ( eval ${_su_condition} ) >/dev/null 2>&1
269 | [ $? -ne 0 ] && shunit_return=${__SHUNIT_FALSE}
270 | fi
271 |
272 | # record the test
273 | if [ ${shunit_return} -eq ${__SHUNIT_TRUE} ]; then
274 | _shunit_testPassed
275 | else
276 | _shunit_testFailed "${_su_message}"
277 | fi
278 |
279 | unset _su_message _su_condition _su_match
280 | return ${shunit_return}
281 | }
282 |
283 | #/**
284 | #
285 | #
286 | # void
287 | #
288 | #
289 | #
290 | #
291 | # assertFalse
292 | # string [message]
293 | # string condition
294 | #
295 | #
296 | # Asserts that a given shell test condition is false. The message is
297 | # optional.
298 | # Testing whether something is true or false is easy enough by using
299 | # the assertEquals/assertNotSame functions. Shell supports much more
300 | # complicated tests though, and a means to support them was needed. As such,
301 | # this function tests that conditions are true or false through evaluation
302 | # rather than just looking for a true or false.
303 | #
304 | # The following test will succeed: assertFalse "[ 'apples' = 'oranges' ]"
305 | # The folloing test will fail with a message: assertFalse "test failed" "[ 1 -eq 1 -a 2 -eq 2 ]"
306 | #
307 | #
308 | #
309 | #*/
310 | assertFalse()
311 | {
312 | _su_message=''
313 | if [ $# -eq 2 ]; then
314 | _su_message=$1
315 | shift
316 | fi
317 | _su_condition=${1:-}
318 |
319 | shunit_return=${__SHUNIT_TRUE}
320 |
321 | # see if condition is an integer, i.e. a return value
322 | _su_match=`expr "${_su_condition}" : '\([0-9]*\)'`
323 | if [ -z "${_su_condition}" ]; then
324 | # null condition
325 | shunit_return=${__SHUNIT_FALSE}
326 | elif [ "${_su_condition}" = "${_su_match}" ]; then
327 | # possible return value. treating 0 as true, and non-zero as false.
328 | [ ${_su_condition} -eq 0 ] && shunit_return=${__SHUNIT_FALSE}
329 | else
330 | # (hopefully) a condition
331 | ( eval ${_su_condition} ) >/dev/null 2>&1
332 | [ $? -eq 0 ] && shunit_return=${__SHUNIT_FALSE}
333 | fi
334 |
335 | # record the test
336 | if [ ${shunit_return} -eq ${__SHUNIT_TRUE} ]; then
337 | _shunit_testPassed
338 | else
339 | _shunit_testFailed "${_su_message}"
340 | fi
341 |
342 | unset _su_message _su_condition _su_match
343 | return ${shunit_return}
344 | }
345 |
346 | #-----------------------------------------------------------------------------
347 | # failure functions
348 | #
349 |
350 | #/**
351 | #
352 | #
353 | # void
354 | #
355 | #
356 | #
357 | #
358 | # fail
359 | # string [message]
360 | #
361 | #
362 | # Fails the test immediately, with the optional message.
363 | #
364 | #
365 | #*/
366 | fail()
367 | {
368 | _su_message=${1:-}
369 |
370 | _shunit_testFailed "${_su_message}"
371 |
372 | unset _su_message
373 | }
374 |
375 | #/**
376 | #
377 | #
378 | # void
379 | #
380 | #
381 | #
382 | #
383 | # failNotEquals
384 | # string [message]
385 | # string unexpected
386 | # string actual
387 | #
388 | #
389 | # Fails the test if unexpected and
390 | # actual are not
391 | # equal to one another. The message is optional.
392 | #
393 | #
394 | #*/
395 | failNotEquals()
396 | {
397 | _su_message=''
398 | if [ $# -eq 3 ]; then
399 | _su_message=$1
400 | shift
401 | fi
402 | _su_unexpected=${1:-}
403 | _su_actual=${2:-}
404 |
405 | _shunit_testFailed "${_su_message:+${_su_message} }expected:<${_su_unexpected}> but was:<${_su_actual}>"
406 |
407 | unset _su_message _su_unexpected _su_actual
408 | }
409 |
410 | #/**
411 | #
412 | #
413 | # void
414 | #
415 | #
416 | #
417 | #
418 | # failSame
419 | # string [message]
420 | #
421 | #
422 | # Indicate test failure because arguments were not the same. The
423 | # message is optional.
424 | #
425 | #
426 | #*/
427 | failSame()
428 | {
429 | _su_message=${1:-}
430 |
431 | _shunit_testFailed "${_su_message:+${_su_message} }expected not same"
432 |
433 | unset _su_message
434 | }
435 |
436 | #/**
437 | #
438 | #
439 | # void
440 | #
441 | #
442 | #
443 | #
444 | # failNotSame
445 | # string [message]
446 | # string expected
447 | # string actual
448 | #
449 | #
450 | # Fails the test if expected and
451 | # actual are equal to one another. The message is
452 | # optional.
453 | #
454 | #
455 | #*/
456 | failNotSame()
457 | {
458 | failNotEquals "${@:-}"
459 | }
460 |
461 | #-----------------------------------------------------------------------------
462 | # suite functions
463 | #
464 |
465 | #/**
466 | #
467 | #
468 | # void
469 | #
470 | #
471 | #
472 | #
473 | # suite
474 | #
475 | #
476 | #
477 | # This function can be optionally overridden by the user in their test
478 | # suite.
479 | # If this function exists, it will be called when
480 | # shunit2 is sourced. If it does not exist, shUnit2 will
481 | # search the parent script for all functions beginning with the word
482 | # test, and they will be added dynamically to the test
483 | # suite.
484 | #
485 | #
486 | #*/
487 | # Note: see _shunit_mktempFunc() for actual implementation
488 | # suite() { :; }
489 |
490 | #/**
491 | #
492 | #
493 | # void
494 | #
495 | #
496 | #
497 | #
498 | # suite_addTest
499 | # string function
500 | #
501 | #
502 | # This function adds a function name to the list of tests scheduled for
503 | # execution as part of this test suite. This function should only be called
504 | # from within the suite() function.
505 | #
506 | #
507 | #*/
508 | suite_addTest()
509 | {
510 | _su_func=${1:-}
511 |
512 | __shunit_suite="${__shunit_suite:+${__shunit_suite} }${_su_func}"
513 |
514 | unset _su_func
515 | }
516 |
517 | #/**
518 | #
519 | #
520 | # void
521 | #
522 | #
523 | #
524 | #
525 | # oneTimeSetUp
526 | #
527 | #
528 | #
529 | # This function can be be optionally overridden by the user in their
530 | # test suite.
531 | # If this function exists, it will be called once before any tests are
532 | # run. It is useful to prepare a common environment for all tests.
533 | #
534 | #
535 | #*/
536 | # Note: see _shunit_mktempFunc() for actual implementation
537 | # oneTimeSetUp() { :; }
538 |
539 | #/**
540 | #
541 | #
542 | # void
543 | #
544 | #
545 | #
546 | #
547 | # oneTimeTearDown
548 | #
549 | #
550 | #
551 | # This function can be be optionally overridden by the user in their
552 | # test suite.
553 | # If this function exists, it will be called once after all tests are
554 | # completed. It is useful to clean up the environment after all tests.
555 | #
556 | #
557 | #*/
558 | # Note: see _shunit_mktempFunc() for actual implementation
559 | # oneTimeTearDown() { :; }
560 |
561 | #/**
562 | #
563 | #
564 | # void
565 | #
566 | #
567 | #
568 | #
569 | # setUp
570 | #
571 | #
572 | #
573 | # This function can be be optionally overridden by the user in their
574 | # test suite.
575 | # If this function exists, it will be called before each test is run.
576 | # It is useful to reset the environment before each test.
577 | #
578 | #
579 | #*/
580 | # Note: see _shunit_mktempFunc() for actual implementation
581 | # setUp() { :; }
582 |
583 | #/**
584 | #
585 | #
586 | # void
587 | #
588 | #
589 | #
590 | #
591 | # tearDown
592 | #
593 | #
594 | #
595 | # This function can be be optionally overridden by the user in their
596 | # test suite.
597 | # If this function exists, it will be called after each test completes.
598 | # It is useful to clean up the environment after each test.
599 | #
600 | #
601 | #*/
602 | # Note: see _shunit_mktempFunc() for actual implementation
603 | # tearDown() { :; }
604 |
605 | #------------------------------------------------------------------------------
606 | # internal shUnit2 functions
607 | #
608 |
609 | _shunit_cleanup()
610 | {
611 | name=$1
612 |
613 | case ${name} in
614 | EXIT) signal=0 ;;
615 | INT) signal=2 ;;
616 | TERM) signal=15 ;;
617 | esac
618 |
619 | # do our work
620 | rm -fr "${__shunit_tmpDir}"
621 |
622 | # exit for all non-EXIT signals
623 | if [ ${name} != 'EXIT' ]; then
624 | echo "trapped and now handling the ${name} signal" >&2
625 | _shunit_generateReport
626 | # disable EXIT trap
627 | trap 0
628 | # add 127 to signal and exit
629 | signal=`expr ${signal} + 127`
630 | exit ${signal}
631 | fi
632 | }
633 |
634 | _shunit_execSuite()
635 | {
636 | echo '#'
637 | echo '# Performing tests'
638 | echo '#'
639 | for _su_func in ${__shunit_suite}; do
640 | # execute the per-test setup function
641 | setUp
642 |
643 | # execute the test
644 | echo "${_su_func}"
645 | eval ${_su_func}
646 |
647 | # execute the per-test tear-down function
648 | tearDown
649 | done
650 |
651 | unset _su_func
652 | }
653 |
654 | _shunit_functionExists()
655 | {
656 | _su__func=$1
657 | type ${_su__func} 2>/dev/null |grep "is a function$" >/dev/null
658 | _su__return=$?
659 | unset _su__func
660 | return ${_su__return}
661 | }
662 |
663 | _shunit_generateReport()
664 | {
665 | _su__awkPercent='{printf("%0.0f%%", $1*100/$2)}'
666 | if [ ${__shunit_testsTotal} -gt 0 ]; then
667 | _su__success=`echo ${__shunit_testsPassed} ${__shunit_testsTotal} |\
668 | awk "${_su__awkPercent}"`
669 | else
670 | _su__success=0
671 | fi
672 |
673 | cat </dev/null ) && return
693 |
694 | # the standard mktemp didn't work. doing our own.
695 | if [ -r '/dev/urandom' ]; then
696 | _su__random=`od -vAn -N4 -tx4 &2
709 | exit 1
710 | }
711 |
712 | echo ${_su__tmpDir}
713 | unset _su__date _su__random _su__tmpDir
714 | }
715 |
716 | # this function is here to work around issues in Cygwin
717 | _shunit_mktempFunc()
718 | {
719 | for _su__func in oneTimeSetUp oneTimeTearDown setUp tearDown suite; do
720 | _su__file="${__shunit_tmpDir}/${_su__func}"
721 | cat <"${_su__file}"
722 | #! /bin/sh
723 | exit 0
724 | EOF
725 | chmod +x "${_su__file}"
726 | done
727 |
728 | unset _su__file
729 | }
730 |
731 | _shunit_testPassed()
732 | {
733 | __shunit_testsPassed=`expr ${__shunit_testsPassed} + 1`
734 | __shunit_testsTotal=`expr ${__shunit_testsTotal} + 1`
735 | }
736 |
737 | _shunit_testFailed()
738 | {
739 | _su__msg=$1
740 |
741 | __shunit_testsFailed=`expr ${__shunit_testsFailed} + 1`
742 | __shunit_testsTotal=`expr ${__shunit_testsTotal} + 1`
743 | echo "${__SHUNIT_ASSERT_MSG_PREFIX}${_su__msg}" >&2
744 |
745 | unset _su__msg
746 | }
747 |
748 | #------------------------------------------------------------------------------
749 | # main
750 | #
751 |
752 | # create a temporary storage location
753 | __shunit_tmpDir=`_shunit_mktempDir`
754 |
755 | # setup traps to clean up after ourselves
756 | trap '_shunit_cleanup EXIT' 0
757 | trap '_shunit_cleanup INT' 2
758 | trap '_shunit_cleanup TERM' 15
759 |
760 | # create phantom functions to work around issues with Cygwin
761 | _shunit_mktempFunc
762 | PATH="${__shunit_tmpDir}:${PATH}"
763 |
764 | # execute the oneTimeSetUp function (if it exists)
765 | #_shunit_functionExists oneTimeSetUp && oneTimeSetUp
766 | oneTimeSetUp
767 |
768 | # deprecated: execute the suite function defined in the parent test script
769 | suite
770 |
771 | # if no suite function was defined, dynamically build a list of functions
772 | if [ -z "${__shunit_suite}" ]; then
773 | funcs=`grep "^[ \t]*test[A-Za-z0-9_]* *()" $0 |sed 's/[^A-Za-z0-9_]//g'`
774 | for func in ${funcs}; do
775 | suite_addTest ${func}
776 | done
777 | fi
778 |
779 | # execute the tests
780 | _shunit_execSuite
781 |
782 | # execute the oneTimeTearDown function (if it exists)
783 | oneTimeTearDown
784 |
785 | # generate report
786 | _shunit_generateReport
787 |
788 | # restore the previous set of shell flags
789 | for _shunit_shellFlag in ${__SHUNIT_SHELL_FLAGS}; do
790 | echo ${__shunit_oldShellFlags} |grep ${_shunit_shellFlag} >/dev/null \
791 | || set +${_shunit_shellFlag}
792 | done
793 | unset _shunit_shellFlag
794 |
795 | #/**
796 | #
797 | #*/
798 |
--------------------------------------------------------------------------------
/logo/logo.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/presets/core/info:
--------------------------------------------------------------------------------
1 | DEPENDENCIES=
2 | DESCRIPTION="Core git deliver scripts"
3 |
--------------------------------------------------------------------------------
/presets/core/pre-delivery/01-disk-space.sh:
--------------------------------------------------------------------------------
1 | SAFETY_MARGIN=$(( 10 * 1024 * 1024 )) # in bytes
2 |
3 | FREE_KBYTES=`run_remote "df -k \"$REMOTE_PATH\" | awk '/[0-9]%/{print \\\$(NF-2)}'"`
4 | [[ $? -gt 0 ]] && exit 1
5 | FREE_BYTES=$(($FREE_KBYTES * 1024))
6 |
7 | NECESSARY_BYTES=$(( `git archive --format=tar $VERSION | wc -c` + $SAFETY_MARGIN ))
8 | #TODO: ajouter la taille du diff entre le .git de la remote (donc toute la remote sauf le delivered) et le .git a livrer ?
9 |
10 | AWK_FORMAT='{x = $0
11 | split("B KB MB GB TB PB", type)
12 | for(i=5;y < 1;i--)
13 | y = x / (2**(10*i))
14 | print y " " type[i+2]
15 | }'
16 |
17 | HUMAN_FREE_BYTES=`echo "$FREE_BYTES" | awk "$AWK_FORMAT"`
18 | HUMAN_NECESSARY_BYTES=`echo "$NECESSARY_BYTES" | awk "$AWK_FORMAT"`
19 |
20 | echo "Delivery will require $HUMAN_NECESSARY_BYTES on remote, $HUMAN_FREE_BYTES available"
21 |
22 | if [[ $FREE_BYTES -gt $NECESSARY_BYTES ]]; then
23 | exit 0
24 | else
25 | echo "Not enough disk space abvailable on remote"
26 | exit 1
27 | fi
28 |
--------------------------------------------------------------------------------
/presets/drupal/info:
--------------------------------------------------------------------------------
1 | DEPENDENCIES=php,js
2 | DESCRIPTION="Base delivery hooks for a Drupal project (dummy)"
3 |
--------------------------------------------------------------------------------
/presets/drupal/init-remote/01-drupal-install.sh:
--------------------------------------------------------------------------------
1 | apt-get install drush
2 |
--------------------------------------------------------------------------------
/presets/drupal/post-symlink/01-drupal-cc.sh:
--------------------------------------------------------------------------------
1 | drush cc && drush cron
2 |
--------------------------------------------------------------------------------
/presets/js/info:
--------------------------------------------------------------------------------
1 | DEPENDENCIES=
2 | DESCRIPTION="Generic git-deliver hooks for Javascript projects (dummy)"
3 |
--------------------------------------------------------------------------------
/presets/php/info:
--------------------------------------------------------------------------------
1 | DEPENDENCIES=
2 | DESCRIPTION="Generic git-deliver hooks for PHP projects (dummy)"
3 |
--------------------------------------------------------------------------------
/presets/php/pre-delivery/01-syntax-check.sh:
--------------------------------------------------------------------------------
1 | PHPL=`find ./ -type f -name \*.php -exec php -l {} \; 2>&1`
2 | echo "$PHPL" | grep "Parse error"
3 | if [[ $? -gt 0 ]]; then
4 | exit 0;
5 | else
6 | exit 1;
7 | fi
8 |
--------------------------------------------------------------------------------
/presets/puppet/info:
--------------------------------------------------------------------------------
1 | DEPENDENCIES=""
2 | DESCRIPTION="Puppet hooks"
3 |
--------------------------------------------------------------------------------
/presets/puppet/post-symlink/01-start-puppetmaster.remote.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | IS=/etc/init.d/puppetmaster
4 | STOP="$IS stop"
5 | START="$IS start"
6 |
7 | if [ -f /var/run/puppet/master.pid ];
8 | then
9 | ps -p `cat /var/run/puppet/master.pid` >/dev/null
10 | if [ $? -eq 0 ]; then
11 | echo "Puppetmaster is running, and should not. Aborting."
12 | exit 2
13 | fi
14 | fi
15 |
16 | /usr/bin/sudo -n $START >/dev/null
17 |
18 | res=$?
19 | if [ $res -ne 0 ]; then
20 | echo "Error running $START (status $res), aborting."
21 | exit 3
22 | fi
23 |
24 | echo "Puppetmaster is now started."
25 |
26 | exit 0
27 |
28 |
--------------------------------------------------------------------------------
/presets/puppet/pre-symlink/01-stop-puppetmaster.remote.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | IS=/etc/init.d/puppetmaster
4 | STATUS="$IS status"
5 | STOP="$IS stop"
6 | START="$IS start"
7 |
8 | if [ ! -f /var/run/puppet/master.pid ];
9 | then
10 | echo "Puppetmaster is not running."
11 | exit 0
12 | fi
13 |
14 | /usr/bin/sudo -n /bin/ps 2>&1 >/dev/null
15 | if [ $? -ne 0 ]; then
16 | echo "You don't have the proper rights to run \"/usr/bin/sudo -n ps\". Add something like \"yourlogin ALL=(ALL:ALL) NOPASSWD: /bin/ps\" to your sudoers file"
17 | exit 3
18 | fi
19 |
20 | # test service pid (sudo init.d
21 | # 1 = not running
22 | # 0 = running
23 | /usr/bin/sudo -n /bin/ps -p `cat /var/run/puppet/master.pid` >/dev/null
24 | res=$?
25 | case $res in
26 | 1)
27 | echo "Puppetmaster is not running."
28 | exit 0
29 | ;;
30 | 0)
31 | echo "Puppetmaster is running. Try to stop it..."
32 | ;;
33 | *)
34 | echo "Unexpected return code from ps ($res), aborting."
35 | exit 2
36 | ;;
37 | esac
38 |
39 | /usr/bin/sudo -n $STOP >/dev/null
40 | res=$?
41 |
42 | case $res in
43 | 1)
44 | echo "You don't have to proper rights to run $IS. Add something like \"yourlogin ALL=(ALL:ALL) NOPASSWD: $IS\" to your sudoers file"
45 | exit 1
46 | ;;
47 | 0)
48 | echo "Puppetmaster is now stopped."
49 | exit 0
50 | ;;
51 | *)
52 | echo "Unexpected return code from $STOP ($res), aborting."
53 | exit 2
54 | ;;
55 | esac
--------------------------------------------------------------------------------
/presets/symfony/info:
--------------------------------------------------------------------------------
1 | DEPENDENCIES=php,js,css
2 | DESCRIPTION="Hooks for the Symfony PHP framework (dummy)"
3 |
--------------------------------------------------------------------------------
/presets/symfony/post-symlink/01-symfony-cc:
--------------------------------------------------------------------------------
1 | $EXEC_REMOTE cd $REMOTE_PATH && ./symfony cc
2 |
--------------------------------------------------------------------------------
/presets/symfony/post-symlink/02-symfony-doctrine:
--------------------------------------------------------------------------------
1 | $EXEC_REMOTE cd $REMOTE_PATH && ./symfony doctrine:build-all
2 |
--------------------------------------------------------------------------------
/presets/yisti/info:
--------------------------------------------------------------------------------
1 | DEPENDENCIES=""
2 | DESCRIPTION="Yisti SBCL hooks"
3 |
--------------------------------------------------------------------------------
/presets/yisti/post-checkout/01-start.sh:
--------------------------------------------------------------------------------
1 | source "yisti.conf"
2 |
3 | DB_DIFF=`git diff $RUNNING_GIT $NEW_GIT $DB_FILES`
4 | LISP_DIFF_LINES=`git diff $RUNNING_GIT $NEW_GIT *.lisp | wc -l`
5 | if [[ `echo "$DB_DIFF" | wc -l` != "1" ]]; then
6 | echo " Warning : there are database changes."
7 | echo "$DB_DIFF"
8 | echo " You'll have to apply them manually, either now or when the new Lisp is ready"
9 | read -p " Press any key to continue"
10 | fi
11 | exit 0
12 |
--------------------------------------------------------------------------------
/presets/yisti/post-checkout/02-deploy.remote.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$DELIVERY_PATH"
4 | source yisti.conf
5 |
6 | if [[ ! -f `which lessc 2> /dev/null` ]]; then
7 | echo " ERROR : lessc not found."
8 | exit 1
9 | fi
10 |
11 | if [[ ! -f `which uglifyjs 2> /dev/null` ]]; then
12 | echo " ERROR : uglifyjs not found."
13 | exit 2
14 | fi
15 |
16 | if [[ ! -f `which java 2> /dev/null` ]]; then
17 | echo " ERROR : java not found (for CSS minification)."
18 | exit 3
19 | fi
20 |
21 | if [[ `ps -C varnishd | wc -l` == 1 ]]; then
22 | echo " ERROR : Varnish is not running"
23 | exit 4
24 | fi
25 |
26 | if [[ ! -f $NAME.vcl ]]; then
27 | echo " $NAME.vcl not found"
28 | exit 5
29 | fi
30 |
31 | if [[ ! -f ../../../yisti/start.sh ]]; then
32 | echo " ../../../yisti/start.sh not found"
33 | exit 6
34 | fi
35 |
36 |
37 | mkdir log
38 |
39 | SCREENS=`screen -ls | grep \\\-$NAME`
40 | NB_SCREENS=`screen -ls | grep -c \\\-$NAME`
41 | if [[ $NB_SCREENS -gt 1 ]]; then
42 | echo " More than one ($NB_SCREENS) screens found... you're on your own."
43 | screen -ls
44 | exit 6
45 | fi
46 | if [[ $NB_SCREENS -gt 0 ]]; then
47 | RUNNING_SCREEN_PID=`echo "$SCREENS" | awk -F\. '{sub(/^\s+/,"",$1); print $1}'`
48 | RUNNING_SERVER_PID=$RUNNING_SCREEN_PID
49 | while [[ $PNAME != 'sbcl' ]]; do
50 | INFO=`ps --ppid $RUNNING_SERVER_PID | tail -n +2`
51 | PNAME=`echo "$INFO" | awk '{sub(/CMD /,"",$4); print $4}'`
52 | RUNNING_SERVER_PID=`echo "$INFO" | awk '{print $1}'`
53 | done
54 | NETCOMMAND="netstat -apn 2>/dev/null | awk '/$RUNNING_SERVER_PID\// && /LISTEN/ {sub(/^.*:/,\"\",\$4); print \$4}'"
55 | OLD_PORT=`echo "$NETCOMMAND" | bash`
56 | echo " Found running server (Screen PID : $RUNNING_SCREEN_PID, Server PID : $RUNNING_SERVER_PID, port $OLD_PORT)"
57 | else
58 | echo " No running server found"
59 | fi
60 |
61 | echo ""
62 |
63 | MAINCACHEDIR=`ls -1dr ~/.cache/common-lisp/sbcl* | head -n 1`
64 | echo "MAINCACHEDIR : $MAINCACHEDIR"
65 | echo "TENTATIVE FASL DIR : $MAINCACHEDIR$DELIVERY_PATH/$PREVIOUS_VERSION"
66 | [ -d "$MAINCACHEDIR$DELIVERY_PATH/$PREVIOUS_VERSION" ] && echo "Copying FASL cache from previous version" && cp -r --preserve=all "$MAINCACHEDIR$DELIVERY_PATH/$PREVIOUS_VERSION" "$MAINCACHEDIR$DELIVERY_PATH/$CURRENT_VERSION"
67 |
68 | echo -n " Starting new Lisp"
69 | NEW_SCREEN_PID=`../../../yisti/start.sh | awk -F\. '/[0-9]\./ {print $1}'`
70 | echo -n " (screen : $NAME.$NEW_SCREEN_PID) "
71 |
72 | NEW_SCREEN_LOG="log/screen_$NEW_SCREEN_PID"
73 | truncate -s 0 $NEW_SCREEN_LOG
74 | screen -rd $NEW_SCREEN_PID -p 0 -X log off
75 | screen -rd $NEW_SCREEN_PID -p 0 -X logfile $NEW_SCREEN_LOG
76 | screen -rd $NEW_SCREEN_PID -p 0 -X log on
77 | STARTING=true
78 | while $STARTING; do
79 | sleep 2
80 | if (grep "\"Server ready\"" $NEW_SCREEN_LOG > /dev/null); then
81 | echo " done"
82 | STARTING=false
83 | elif (grep -q "ENOMEM" $NEW_SCREEN_LOG) || (grep -q "Heap exhausted" $NEW_SCREEN_LOG); then
84 | echo ""
85 | echo -n " Memory error, restarting compilation"
86 | kill $NEW_SCREEN_PID
87 | NEW_SCREEN_PID=`../../../yisti/start.sh | awk -F\. '/[0-9]\./ {print $1}'`
88 | NEW_SCREEN_LOG="log/screen_$NEW_SCREEN_PID"
89 | truncate -s 0 $NEW_SCREEN_LOG
90 | screen -rd $NEW_SCREEN_PID -p 0 -X log off
91 | screen -rd $NEW_SCREEN_PID -p 0 -X logfile $NEW_SCREEN_LOG
92 | screen -rd $NEW_SCREEN_PID -p 0 -X log on
93 | else
94 | echo -n "."
95 | fi
96 | done
97 |
98 | NEW_SERVER_PID=$NEW_SCREEN_PID
99 | PNAME=""
100 | while [[ $PNAME != 'sbcl' ]]; do
101 | INFO=`ps --ppid $NEW_SERVER_PID | tail -n +2`
102 | PNAME=`echo "$INFO" | awk '{print $4}'`
103 | NEW_SERVER_PID=`echo "$INFO" | awk '{print $1}'`
104 | done
105 |
106 | echo " New Lisp started (Screen PID : $NEW_SCREEN_PID, Server PID : $NEW_SERVER_PID)"
107 | echo ""
108 |
109 | NETCOMMAND="netstat -apn 2>/dev/null | awk '/$NEW_SERVER_PID\// && /LISTEN/ {sub(/^.*:/,\"\",\$4); print \$4}'"
110 | NEW_PORT=`echo "$NETCOMMAND" | bash`
111 |
112 | echo " Checking HTTP access to new Lisp on port $NEW_PORT"
113 | wget -q http://localhost:$NEW_PORT
114 | if [[ $? != 0 ]]; then
115 | echo " ERROR : Could not do HTTP request to new Lisp on port $NEW_PORT"
116 | exit 7
117 | fi
118 |
119 | echo " New Lisp is online"
120 | echo " NEW_PORT=\"$NEW_PORT\" \
121 | OLD_PORT=\"$OLD_PORT\" \
122 | NAME=\"$NAME\" \
123 | NB_SCREENS=\"$NB_SCREENS\" \
124 | RUNNING_SERVER_PID=\"$RUNNING_SERVER_PID\" \
125 | RUNNING_SCREEN_PID=\"$RUNNING_SCREEN_PID\"" > /tmp/delivery_vars.sh
126 |
127 | echo " You need to clear the CDN cache manually"
128 |
--------------------------------------------------------------------------------
/presets/yisti/post-symlink/01-varnish-switch.remote.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cd "$DELIVERY_PATH"
4 | source "yisti.conf"
5 |
6 | function exit_if_error
7 | {
8 | [[ $? -eq 0 ]] || exit $1
9 | }
10 |
11 | [[ -f "/tmp/delivery_vars.sh" ]] || exit 1
12 | source "/tmp/delivery_vars.sh"
13 |
14 | echo " Setting new Lisp as active Varnish backend"
15 |
16 | echo "Setting Varnish backend port to $NEW_PORT"
17 | sed 's/port = "[0-9]\+"/port = "'$NEW_PORT'"/' "$DELIVERY_PATH/$NAME.vcl" > /tmp/$NAME.vcl
18 | mv "$DELIVERY_PATH/$NAME.vcl"{,.bak}
19 | cp /tmp/$NAME.vcl "$DELIVERY_PATH/$NAME.vcl"
20 | exit_if_error 2
21 |
22 | if (varnishadm -T localhost:6082 vcl.list | grep yisti2 | grep -q active); then
23 | NEWCONF="yisti"
24 | OLDCONF="yisti2"
25 | else
26 | NEWCONF="yisti2"
27 | OLDCONF="yisti"
28 | fi
29 | varnishadm -T localhost:6082 vcl.discard $NEWCONF 2>&1 > /dev/null
30 | echo -n " "
31 | varnishadm -T localhost:6082 vcl.load $NEWCONF /etc/varnish/yisti.vcl
32 | exit_if_error 3
33 | varnishadm -T localhost:6082 vcl.use $NEWCONF
34 | exit_if_error 4
35 | varnishadm -T localhost:6082 vcl.discard $OLDCONF 2>&1 > /dev/null
36 | mv "$DELIVERY_PATH/$NAME".vcl{.bak,}
37 |
38 | echo " Purging cache"
39 | varnishadm -T localhost:6082 ban obj.http.X-vhost == "'"$NAME"'"
40 |
41 | if [[ $NB_SCREENS -gt 0 ]]; then
42 | echo -n " Waiting for last connections to obsolete Lisp to close"
43 | while [[ `netstat --tcpip -pn 2>/dev/null | grep \:$OLD_PORT | grep \ $RUNNING_SERVER_PID\/ | wc -l` -gt 0 ]]; do
44 | echo -n "."
45 | sleep 2
46 | done
47 | echo ""
48 | echo " No connections remaining, killing obsolete Lisp"
49 | kill $RUNNING_SCREEN_PID
50 | fi
51 |
52 | #rm /tmp/delivery_vars.sh
53 |
54 | exit 0
55 |
--------------------------------------------------------------------------------
/tests.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | #
4 | # Copyright 2012-2015 Arnaud Betremieux
5 | #
6 | # This file is a part of Git-deliver.
7 | #
8 | # The program in this file is free software: you can redistribute it
9 | # and/or modify it under the terms of the GNU General Public License
10 | # as published by the Free Software Foundation, either version 3 of
11 | # the License, or (at your option) any later version.
12 | #
13 | # This program is distributed in the hope that it will be useful,
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | # GNU General Public License for more details.
17 | #
18 | # You should have received a copy of the GNU General Public License
19 | # along with this program. If not, see .
20 | #
21 |
22 | set -o nounset
23 |
24 | SSH_TEST_USER=$USER
25 | SSH_TEST_HOST="localhost"
26 | SSH_TEST_GROUP=git
27 | SSH_TEST_USER_SAME_GROUP=bob
28 | SSH_TEST_USER_NOT_SAME_GROUP=alice
29 | SSH_TEST_PATH="/tmp/deliver test/"
30 |
31 | assertTrueEcho()
32 | {
33 | $1 || { echo "$1" ; assertTrue false ; }
34 | }
35 |
36 | initDeliver()
37 | {
38 | cd "$ROOT_DIR/test_repo"
39 | "$ROOT_DIR"/deliver.sh --init --batch $* #> /dev/null 2>&1
40 | }
41 |
42 | initWithOrigin()
43 | {
44 | cd "$ROOT_DIR"
45 | git clone --bare "$ROOT_DIR/test_repo" "$ROOT_DIR/test_remote" > /dev/null 2>&1
46 | cd "$ROOT_DIR/test_repo"
47 | git remote add origin "$ROOT_DIR/test_remote"
48 | initDeliver $*
49 | }
50 |
51 | initWithSshOrigin()
52 | {
53 | local shared=""
54 | if [[ $# = 0 ]]; then
55 | shared="false"
56 | else
57 | shared="$1"
58 | fi
59 | shift
60 | cd "$ROOT_DIR/test_repo"
61 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "rm -rf \"$SSH_TEST_PATH\"/test_remote ; mkdir -p \"$SSH_TEST_PATH\"/test_remote && cd \"$SSH_TEST_PATH\"/test_remote && git init --bare --shared=$shared && chgrp -R $SSH_TEST_GROUP \"$SSH_TEST_PATH\"/test_remote"
62 | git remote add origin "$SSH_TEST_USER@$SSH_TEST_HOST:$SSH_TEST_PATH/test_remote"
63 | initDeliver $*
64 | }
65 |
66 | oneTimeSetUp()
67 | {
68 | ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
69 | OLD_PWD=`pwd`
70 |
71 | rm -rf "$ROOT_DIR/test_repo"
72 | rm -rf "$ROOT_DIR/test_remote"
73 | ssh $SSH_TEST_USER@$SSH_TEST_HOST rm -rf "$SSH_TEST_PATH"/test_remote
74 |
75 | mkdir "$ROOT_DIR/test_repo"
76 | cd "$ROOT_DIR/test_repo"
77 | git init
78 | echo "blah blah" > a
79 | git add a
80 | git commit -m "test commit"
81 | git tag older master
82 | echo "blblublublu" > x
83 | git add x
84 | git commit -m "test commit 2"
85 | git checkout -b "branch"
86 | echo "ssss" >> a
87 | git commit -am "branch commit 1"
88 | echo "ssss" >> a
89 | git commit -am "branch commit 2"
90 | git checkout master
91 | echo "ssss" >> a
92 | git commit -am "test commit 3"
93 | git tag branch_non_head branch^
94 | git tag branch_head branch
95 | cd "$ROOT_DIR"
96 | }
97 |
98 | oneTimeTearDown()
99 | {
100 | rm -rf "$ROOT_DIR/test_repo"
101 | rm -rf "$ROOT_DIR/test_remote"
102 | cd "$OLD_PWD"
103 | }
104 |
105 | tearDown()
106 | {
107 | rm -rf "$ROOT_DIR/test_repo/.deliver"
108 | cd "$ROOT_DIR/test_repo"
109 | git remote rm origin 2> /dev/null
110 |
111 | rm -rf "$ROOT_DIR/test_remote"
112 | ssh $SSH_TEST_USER@$SSH_TEST_HOST rm -rf "$SSH_TEST_PATH"/test_remote
113 | cd "$ROOT_DIR"
114 | }
115 |
116 | testPath2Unix()
117 | {
118 | A=`echo 'source deliver.sh --source > /dev/null 2>&1 ; path2unix "c:/a/b/c"' | bash`
119 | assertEquals "/c/a/b/c" "$A"
120 | A=`echo 'source deliver.sh --source > /dev/null 2>&1 ; path2unix "C:/A/b/C"' | bash`
121 | assertEquals "/c/A/b/C" "$A"
122 | A=`echo 'source deliver.sh --source > /dev/null 2>&1 ; path2unix "/C/A/b/C"' | bash`
123 | assertEquals "/C/A/b/C" "$A"
124 | }
125 |
126 | testExitIfError()
127 | {
128 | A=`echo 'source deliver.sh --source; bash -c "exit 2"; exit_if_error 1 "test" 2>&1' | bash`
129 | assertEquals 1 $?
130 | echo "$A" | grep "test" &> /dev/null
131 | assertEquals 0 $?
132 | }
133 |
134 | testDefaultcolor()
135 | {
136 | A=`echo 'source deliver.sh --source; echo_red "test"' | bash`
137 | echo "$A" | cat -v | grep -F "^[[31m" &> /dev/null
138 | assertNotSame 0 $?
139 | echo "$A" | cat -v | grep -F "^[[31m" &> /dev/null
140 | assertNotSame 0 $?
141 | }
142 |
143 | testExplicitcolor()
144 | {
145 | A=`echo 'source deliver.sh --color --source; echo_red "test"' | bash`
146 | echo "$A" | cat -v | grep -F "^[[31m" &> /dev/null
147 | assertEquals 0 $?
148 | echo "$A" | cat -v | grep -F "^[[31m" &> /dev/null
149 | assertEquals 0 $?
150 | }
151 |
152 | testRunRemoteLocal()
153 | {
154 | cd "$ROOT_DIR"
155 | A=`echo 'source deliver.sh --source > /dev/null 2>&1 ; REMOTE_PATH="'$ROOT_DIR'" run_remote "pwd"' | bash`
156 | assertEquals "/tmp" "$A"
157 | }
158 |
159 | testRunRemoteSsh()
160 | {
161 | cd "$ROOT_DIR"
162 | A=$(echo 'source deliver.sh --source > /dev/null 2>&1 ; GIT_SSH="ssh" REMOTE_SERVER="'$SSH_TEST_USER@$SSH_TEST_HOST'" run_remote "test \"\$SSH_CONNECTION\" = \"\" || echo -n \"OK\""' | bash)
163 | assertEquals "OK" "$A"
164 | }
165 |
166 | testRemoteInfoNonExistentRemote()
167 | {
168 | cd "$ROOT_DIR"/test_repo
169 | A=`echo 'source ../deliver.sh --source > /dev/null 2>&1 ; remote_info nonexistentremote 2>&1' | bash`
170 | assertEquals "Remote nonexistentremote not found." "$A"
171 | }
172 |
173 | testRemoteInfo()
174 | {
175 | initWithOrigin
176 | cd "$ROOT_DIR"/test_repo
177 | git remote add unix /path/a/b
178 | git remote add relative ../path/a/b
179 | git remote add win c:/path/a/b
180 | git remote add ssh ssh://user@host/path/a/b
181 | git remote add git GIT://user@host/path/a/b
182 | git remote add scp user@host:/path/a/b
183 | git remote add scp_no_user host:/path/a/b
184 | git remote add http http://user@host/path/a/b
185 | git remote add space "/path/a b c"
186 | git remote add tilde "~/path/a b"
187 | git remote add tilde_user "~bob/path/a b"
188 | if [[ "$OSTYPE" != "msys" ]]; then
189 | A=`echo 'source ../deliver.sh --source > /dev/null 2>&1 ; remote_info unix ; echo "$REMOTE_PROTO+++$REMOTE_SERVER+++$REMOTE_PATH"' | bash`
190 | assertEquals "local++++++/path/a/b" "$A"
191 | fi
192 | A=`echo 'source ../deliver.sh --source > /dev/null 2>&1 ; remote_info relative ; echo "$REMOTE_PROTO+++$REMOTE_SERVER+++$REMOTE_PATH"' | bash`
193 | assertEquals "local++++++$ROOT_DIR/test_repo/../path/a/b" "$A"
194 | A=`echo 'source ../deliver.sh --source > /dev/null 2>&1 ; OSTYPE="linux" remote_info win ; echo "$REMOTE_PROTO+++$REMOTE_SERVER+++$REMOTE_PATH"' | bash`
195 | assertEquals "ssh+++c+++/path/a/b" "$A"
196 | A=`echo 'source ../deliver.sh --source > /dev/null 2>&1 ; OSTYPE="msys" remote_info win ; echo "$REMOTE_PROTO+++$REMOTE_SERVER+++$REMOTE_PATH"' | bash`
197 | assertEquals "local++++++/c/path/a/b" "$A"
198 | A=`echo 'source ../deliver.sh --source > /dev/null 2>&1 ; remote_info ssh ; echo "$REMOTE_PROTO+++$REMOTE_SERVER+++$REMOTE_PATH"' | bash`
199 | assertEquals "ssh+++user@host+++/path/a/b" "$A"
200 | A=`echo 'source ../deliver.sh --source > /dev/null 2>&1 ; remote_info git ; echo "$REMOTE_PROTO+++$REMOTE_SERVER+++$REMOTE_PATH"' | bash`
201 | assertEquals "git+++user@host+++/path/a/b" "$A"
202 | A=`echo 'source ../deliver.sh --source > /dev/null 2>&1 ; remote_info scp ; echo "$REMOTE_PROTO+++$REMOTE_SERVER+++$REMOTE_PATH"' | bash`
203 | assertEquals "ssh+++user@host+++/path/a/b" "$A"
204 | A=`echo 'source ../deliver.sh --source > /dev/null 2>&1 ; remote_info scp_no_user ; echo "$REMOTE_PROTO+++$REMOTE_SERVER+++$REMOTE_PATH"' | bash`
205 | assertEquals "ssh+++host+++/path/a/b" "$A"
206 | A=`echo 'source ../deliver.sh --source > /dev/null 2>&1 ; remote_info http ; echo "$REMOTE_PROTO+++$REMOTE_SERVER+++$REMOTE_PATH"' | bash`
207 | assertEquals "http+++user@host+++/path/a/b" "$A"
208 | if [[ "$OSTYPE" != "msys" ]]; then
209 | A=`echo 'source ../deliver.sh --source > /dev/null 2>&1 ; remote_info space ; echo "$REMOTE_PROTO+++$REMOTE_SERVER+++$REMOTE_PATH"' | bash`
210 | assertEquals "local++++++/path/a b c" "$A"
211 | fi
212 | A=`echo 'source ../deliver.sh --source > /dev/null 2>&1 ; remote_info tilde ; echo "$REMOTE_PROTO+++$REMOTE_SERVER+++$REMOTE_PATH"' | bash`
213 | assertEquals "local++++++$HOME/path/a b" "$A"
214 | A=`echo 'source ../deliver.sh --source > /dev/null 2>&1 ; remote_info tilde_user ; echo "$REMOTE_PROTO+++$REMOTE_SERVER+++$REMOTE_PATH"' | bash`
215 | HOMEBOB=`echo ~bob`
216 | assertEquals "local++++++$HOMEBOB/path/a b" "$A"
217 | git remote rm unix
218 | git remote rm relative
219 | git remote rm win
220 | git remote rm ssh
221 | git remote rm git
222 | git remote rm scp
223 | git remote rm scp_no_user
224 | git remote rm http
225 | git remote rm space
226 | git remote rm tilde
227 | git remote rm tilde_user
228 | }
229 |
230 | testRunScripts()
231 | {
232 | cd "$ROOT_DIR/test_repo"
233 | mkdir -p ".deliver/scripts/foo"
234 | echo "test \"\$SSH_CONNECTION\" = \"\" && echo 'L:OK' ; exit 0" > "$ROOT_DIR/test_repo/.deliver/scripts/foo/01-bar.sh"
235 | echo "test \"\$SSH_CONNECTION\" = \"\" || echo 'R:OK' ; exit 0" > "$ROOT_DIR/test_repo/.deliver/scripts/foo/02-bar.remote.sh"
236 | A=`echo 'source ../deliver.sh --source > /dev/null 2>&1 ; set +o nounset ; GIT_SSH="ssh" REMOTE_SERVER="'$SSH_TEST_USER@$SSH_TEST_HOST'" REMOTE_PROTO="ssh" DELIVERY_STAGE="foo" run_stage_scripts' | bash 2>&1 | grep OK`
237 | echo "$A" | grep "L:OK" &> /dev/null
238 | assertEquals 0 $?
239 | echo "$A" | grep "R:OK" &> /dev/null
240 | assertEquals 0 $?
241 | }
242 |
243 | testHelp1()
244 | {
245 | cd "$ROOT_DIR/test_repo"
246 | "$ROOT_DIR"/deliver.sh | grep "git deliver " > /dev/null
247 | assertEquals 0 $?
248 | }
249 |
250 | testListPresets()
251 | {
252 | cd "$ROOT_DIR/test_repo"
253 | local RESULT=`"$ROOT_DIR"/deliver.sh --list-presets`
254 | echo "$RESULT" | grep "Core git deliver scripts" > /dev/null
255 | assertEquals 0 $?
256 | }
257 |
258 | testInit()
259 | {
260 | initDeliver
261 | assertTrueEcho "[ -d .deliver ]"
262 | assertTrueEcho "[ -d .deliver/scripts ]"
263 | assertTrueEcho "[ -d .deliver/scripts/pre-delivery ]"
264 | assertTrueEcho "[ -f .deliver/scripts/pre-delivery/01-core-disk-space.sh ]"
265 | assertTrueEcho "[ -d .deliver/scripts/init-remote ]"
266 | assertTrueEcho "[ -d .deliver/scripts/post-checkout ]"
267 | assertTrueEcho "[ -d .deliver/scripts/post-symlink ]"
268 | assertTrueEcho "[ -d .deliver/scripts/rollback-pre-symlink ]"
269 | assertTrueEcho "[ -d .deliver/scripts/rollback-post-symlink ]"
270 | }
271 |
272 | testInitPreset()
273 | {
274 | initDeliver php
275 | assertTrueEcho "[ -f .deliver/scripts/pre-delivery/01-php-syntax-check.sh ]"
276 | }
277 |
278 | testInitBadPreset()
279 | {
280 | cd "$ROOT_DIR/test_repo"
281 | A=`"$ROOT_DIR"/deliver.sh --init --batch foo 2>&1`
282 | assertEquals 19 $?
283 | echo "$A" | grep "could not find preset" > /dev/null 2>&1
284 | assertEquals 0 $?
285 | }
286 |
287 | testUninitedDir()
288 | {
289 | cd "$ROOT_DIR/test_repo"
290 | local RESULT=`"$ROOT_DIR"/deliver.sh --batch non_existent_remote master 2>&1`
291 | assertEquals ".deliver not found." "$RESULT"
292 | }
293 |
294 | testUnknownRemote()
295 | {
296 | initDeliver
297 | local RESULT=`"$ROOT_DIR"/deliver.sh --batch non_existent_remote master 2>&1`
298 | assertEquals "Remote non_existent_remote not found." "$RESULT"
299 | }
300 |
301 | testUnknownRef()
302 | {
303 | initWithOrigin
304 | local RESULT=`"$ROOT_DIR"/deliver.sh --batch origin non_existent_ref 2>&1 | tail -n1`
305 | assertEquals "Ref non_existent_ref not found." "$RESULT"
306 | }
307 |
308 | testInitNonExistingRemoteLocal()
309 | {
310 | if [[ "$OSTYPE" != "msys" ]]; then
311 | initDeliver
312 | cd "$ROOT_DIR"/test_repo
313 | "$ROOT_DIR"/deliver.sh --init-remote --batch new_remote "$ROOT_DIR"/test_new_remote_dir
314 | cd "$ROOT_DIR"/test_new_remote_dir
315 | assertEquals 0 $?
316 | assertTrueEcho "[ -d delivered ]"
317 | assertTrueEcho "[ -d refs ]"
318 | cd "$ROOT_DIR"/test_repo
319 | rm -rf "$ROOT_DIR"/test_new_remote_dir
320 | git remote rm new_remote
321 | else
322 | echo "Test won't be run (msys)"
323 | fi
324 | }
325 |
326 | testInitNonExistingRemoteSsh()
327 | {
328 | initDeliver
329 | cd "$ROOT_DIR"/test_repo
330 | "$ROOT_DIR"/deliver.sh --init-remote --batch new_remote $SSH_TEST_USER@$SSH_TEST_HOST:"$SSH_TEST_PATH"/test_new_remote_dir
331 | A=`ssh $SSH_TEST_USER@$SSH_TEST_HOST ls -1d \"$SSH_TEST_PATH\"/{test_new_remote_dir,test_new_remote_dir/delivered,test_new_remote_dir/refs} | wc -l`
332 | assertEquals 3 $A
333 | ssh $SSH_TEST_USER@$SSH_TEST_HOST rm -rf "$SSH_TEST_PATH"/test_new_remote_dir
334 | git remote rm new_remote
335 | }
336 |
337 | testInitNonExistingRemoteSsh2()
338 | {
339 | initDeliver
340 | cd "$ROOT_DIR"/test_repo
341 | "$ROOT_DIR"/deliver.sh --init-remote --batch new_remote $SSH_TEST_USER@$SSH_TEST_HOST:"$SSH_TEST_PATH"/test_new_remote_dir 2>&1 > /dev/null
342 | A=`ssh $SSH_TEST_USER@$SSH_TEST_HOST ls -1d \"$SSH_TEST_PATH\"/{test_new_remote_dir,test_new_remote_dir/delivered,test_new_remote_dir/refs} | wc -l`
343 | assertEquals 3 $A
344 | ssh $SSH_TEST_USER@$SSH_TEST_HOST rm -rf "$SSH_TEST_PATH"/test_new_remote_dir
345 | git remote rm new_remote
346 | }
347 |
348 | testInitNonExistingRemoteSsh3()
349 | {
350 | initDeliver
351 | cd "$ROOT_DIR"/test_repo
352 | "$ROOT_DIR"/deliver.sh --init-remote --batch new_remote sSh://$SSH_TEST_USER@$SSH_TEST_HOST"$SSH_TEST_PATH"/test_new_remote_dir 2>&1 > /dev/null
353 | A=`ssh $SSH_TEST_USER@$SSH_TEST_HOST ls -1d \"$SSH_TEST_PATH\"/{test_new_remote_dir,test_new_remote_dir/delivered,test_new_remote_dir/refs} | wc -l`
354 | assertEquals 3 $A
355 | ssh $SSH_TEST_USER@$SSH_TEST_HOST rm -rf "$SSH_TEST_PATH"/test_new_remote_dir
356 | git remote rm new_remote
357 | }
358 |
359 | testInitAlreadyInitRemoteSsh()
360 | {
361 | initDeliver
362 | cd "$ROOT_DIR"/test_repo
363 | "$ROOT_DIR"/deliver.sh --init-remote --batch new_remote sSh://$SSH_TEST_USER@$SSH_TEST_HOST"$SSH_TEST_PATH"/test_new_remote_dir 2>&1 > /dev/null
364 | A=`ssh $SSH_TEST_USER@$SSH_TEST_HOST ls -1d \"$SSH_TEST_PATH\"/{test_new_remote_dir,test_new_remote_dir/delivered,test_new_remote_dir/refs} | wc -l`
365 | assertEquals 3 $A
366 | "$ROOT_DIR"/deliver.sh --init-remote --batch new_remote sSh://$SSH_TEST_USER@$SSH_TEST_HOST"$SSH_TEST_PATH"/test_new_remote_dir 2>&1 > /dev/null
367 | assertEquals 18 $?
368 | ssh $SSH_TEST_USER@$SSH_TEST_HOST rm -rf "$SSH_TEST_PATH"/test_new_remote_dir
369 | git remote rm new_remote
370 | }
371 |
372 | testInitNonSshRemote()
373 | {
374 | initDeliver
375 | cd "$ROOT_DIR"/test_repo
376 | git remote add git git://user@host/path/a/b
377 | "$ROOT_DIR"/deliver.sh --init-remote --batch git 2>&1 > /dev/null
378 | assertEquals 17 $?
379 | }
380 |
381 | testInitNonExistingRemoteDirExisting()
382 | {
383 | if [[ "$OSTYPE" != "msys" ]]; then
384 | initDeliver
385 | cd "$ROOT_DIR"/test_repo
386 | mkdir "$ROOT_DIR/test_new_remote_dir"
387 | "$ROOT_DIR"/deliver.sh --init-remote --batch new_remote "$ROOT_DIR"/test_new_remote_dir 2>&1 > /dev/null
388 | cd "$ROOT_DIR"/test_new_remote_dir
389 | assertEquals 0 $?
390 | assertTrueEcho "[ -d delivered ]"
391 | assertTrueEcho "[ -d refs ]"
392 | rm -rf "$ROOT_DIR"/test_new_remote_dir
393 | cd "$ROOT_DIR"/test_repo
394 | git remote rm new_remote
395 | else
396 | echo "Test won't be run (msys)"
397 | fi
398 | }
399 |
400 | testInitNonExistingRemoteDirExistingSsh()
401 | {
402 | initDeliver
403 | cd "$ROOT_DIR"/test_repo
404 | SSH_NEW_DIR="$SSH_TEST_PATH/test_new_remote_dir"
405 |
406 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "mkdir \"$SSH_NEW_DIR\""
407 | "$ROOT_DIR"/deliver.sh --init-remote --batch new_remote $SSH_TEST_USER@$SSH_TEST_HOST:"$SSH_NEW_DIR" 2>&1 > /dev/null
408 |
409 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "cd \"$SSH_NEW_DIR\" && test -d delivered && test -d refs"
410 | assertEquals 0 $?
411 |
412 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "rm -rf \"$SSH_NEW_DIR\""
413 | git remote rm new_remote
414 | }
415 |
416 | testInitNonExistingRemoteDirFileExisting()
417 | {
418 | if [[ "$OSTYPE" != "msys" ]]; then
419 | initDeliver
420 | cd "$ROOT_DIR"/test_repo
421 | touch "$ROOT_DIR/test_new_remote_dir"
422 | "$ROOT_DIR"/deliver.sh --init-remote --batch new_remote "$ROOT_DIR"/test_new_remote_dir
423 | assertEquals 10 $?
424 | assertFalse "[ -d \"$ROOT_DIR\"/test_new_remote_dir/delivered ]"
425 | rm -rf "$ROOT_DIR"/test_new_remote_dir
426 | git remote rm new_remote
427 | else
428 | echo "Test won't be run (msys)"
429 | fi
430 | }
431 |
432 | testInitNonExistingRemoteDirFileExistingSsh()
433 | {
434 | initDeliver
435 |
436 | SSH_NEW_DIR="$SSH_TEST_PATH/test_new_remote_dir"
437 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "touch \"$SSH_NEW_DIR\""
438 |
439 | "$ROOT_DIR"/deliver.sh --init-remote --batch new_remote $SSH_TEST_USER@$SSH_TEST_HOST:"$SSH_NEW_DIR" 2>&1 > /dev/null
440 |
441 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "test -d \"$SSH_NEW_DIR/delivered\""
442 | assertEquals 1 $?
443 |
444 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "rm -f \"$SSH_NEW_DIR\""
445 | git remote rm new_remote
446 | }
447 |
448 | testInitNonExistingRemoteDirExistingNonEmpty()
449 | {
450 | if [[ "$OSTYPE" != "msys" ]]; then
451 | initDeliver
452 | cd "$ROOT_DIR"/test_repo
453 | mkdir "$ROOT_DIR/test_new_remote_dir"
454 | touch "$ROOT_DIR/test_new_remote_dir/file1"
455 | "$ROOT_DIR"/deliver.sh --init-remote --batch new_remote "$ROOT_DIR"/test_new_remote_dir 2>&1 > /dev/null
456 | assertEquals 9 $?
457 | assertFalse "[ -d \"$ROOT_DIR\"/test_new_remote_dir/delivered ]"
458 | rm -rf "$ROOT_DIR"/test_new_remote_dir
459 | git remote rm new_remote
460 | else
461 | echo "Test won't be run (msys)"
462 | fi
463 | }
464 |
465 | testInitNonExistingRemoteDirExistingNonEmptySsh()
466 | {
467 | initDeliver
468 | cd "$ROOT_DIR"/test_repo
469 |
470 | SSH_NEW_DIR="$SSH_TEST_PATH/test_new_remote_dir"
471 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "mkdir \"$SSH_NEW_DIR\" && touch \"$SSH_NEW_DIR/file1\""
472 |
473 |
474 | "$ROOT_DIR"/deliver.sh --init-remote --batch new_remote $SSH_TEST_USER@$SSH_TEST_HOST:"$SSH_NEW_DIR" 2>&1 > /dev/null
475 | assertEquals 9 $?
476 |
477 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "test -d \"$SSH_NEW_DIR/delivered\""
478 | assertEquals 1 $?
479 |
480 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "rm -rf \"$SSH_NEW_DIR\""
481 | git remote rm new_remote
482 | }
483 |
484 | testDeliverNonSshRemote()
485 | {
486 | initDeliver
487 | cd "$ROOT_DIR"/test_repo
488 | git remote add git git://user@host/path/a/b
489 | "$ROOT_DIR"/deliver.sh --batch git master 2>&1 > /dev/null
490 | assertEquals 17 $?
491 | }
492 |
493 | testDeliverInvalidRemoteName()
494 | {
495 | initDeliver
496 | cd "$ROOT_DIR"/test_repo
497 | "$ROOT_DIR"/deliver.sh --batch +++ master 2>&1 > /dev/null
498 | assertEquals 22 $?
499 | }
500 |
501 | testBasicDeliverMaster()
502 | {
503 | if [[ "$OSTYPE" != "msys" ]]; then
504 | initWithOrigin
505 | "$ROOT_DIR"/deliver.sh --init-remote --batch origin > /dev/null
506 | A=`"$ROOT_DIR"/deliver.sh --batch origin master 2>&1`
507 | echo "$A"
508 | echo "$A" | grep "No version delivered yet on origin" &> /dev/null
509 | assertEquals 0 $?
510 | echo "$A" | grep "Running scripts for stage pre-delivery" &> /dev/null
511 | assertEquals 0 $?
512 | echo "$A" | grep "No scripts for stage post-checkout" &> /dev/null
513 | assertEquals 0 $?
514 | echo "$A" | grep "No scripts for stage post-symlink" &> /dev/null
515 | assertEquals 0 $?
516 | echo "$A" | grep "No scripts for stage rollback-pre-symlink" &> /dev/null
517 | assertNotSame 0 $?
518 | echo "$A" | grep "No scripts for stage rollback-post-symlink" &> /dev/null
519 | assertNotSame 0 $?
520 | cd "$ROOT_DIR"/test_remote
521 | assertEquals 0 $?
522 | assertTrueEcho "[ -d delivered ]"
523 | assertTrueEcho "[ -L delivered/current ]"
524 | assertTrueEcho "[ -d delivered/`readlink \"$ROOT_DIR\"/test_remote/delivered/current` ]"
525 | cd "$ROOT_DIR"/test_repo
526 | assertEquals `git rev-parse master` `git --git-dir="$ROOT_DIR"/test_remote/delivered/current/.git log -n 1 --skip=1 --pretty=format:%H`;
527 | else
528 | echo "Test won't be run (msys)"
529 | fi
530 | }
531 |
532 | testDeliverNotFastForwardSsh()
533 | {
534 | initWithSshOrigin
535 | "$ROOT_DIR"/deliver.sh --init-remote --batch origin &> /dev/null
536 | "$ROOT_DIR"/deliver.sh --batch origin master &> /dev/null
537 | git reset master^
538 | echo "asdsdf" >> a
539 | git commit -am "new master"
540 | A=`"$ROOT_DIR"/deliver.sh --batch origin master 2>&1`
541 | assertEquals 14 $?
542 | echo "$A" | grep "failed to push"
543 | assertEquals 0 $?
544 | }
545 |
546 | testDeliverNotFastForwardForcedSsh()
547 | {
548 | initWithSshOrigin
549 | "$ROOT_DIR"/deliver.sh --init-remote --batch origin &> /dev/null
550 | "$ROOT_DIR"/deliver.sh --batch origin master &> /dev/null
551 | git reset master^
552 | echo "asdsdf" >> a
553 | git commit -am "new master"
554 | A=`"$ROOT_DIR"/deliver.sh --batch --force origin master 2>&1`
555 | assertEquals 0 $?
556 | echo "$A" | grep "forced update"
557 | assertEquals 0 $?
558 | }
559 |
560 | testBasicDeliverMasterSsh()
561 | {
562 | initWithSshOrigin
563 | "$ROOT_DIR"/deliver.sh --init-remote --batch origin > /dev/null
564 | A=`"$ROOT_DIR"/deliver.sh --batch origin master 2>&1`
565 | echo "$A"
566 | echo "$A" | grep "No version delivered yet on origin" > /dev/null
567 | assertEquals 0 $?
568 |
569 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "cd \"$SSH_TEST_PATH/test_remote\" && test -d delivered && test -L delivered/current && test -d delivered/\`readlink \"$SSH_TEST_PATH\"/test_remote/delivered/current\`"
570 | assertEquals 0 $?
571 |
572 | SSH_SHA1=`ssh $SSH_TEST_USER@$SSH_TEST_HOST "git --git-dir=\"$SSH_TEST_PATH\"/test_remote/delivered/current/.git log -n 1 --skip=1 --pretty=format:%H"`
573 |
574 | cd "$ROOT_DIR"/test_repo
575 | assertEquals `git rev-parse master` $SSH_SHA1;
576 | }
577 |
578 | testBasicDeliverMasterFromDetachedHeadSsh()
579 | {
580 | initWithSshOrigin
581 | git checkout master^
582 | "$ROOT_DIR"/deliver.sh --init-remote --batch origin > /dev/null
583 | A=`"$ROOT_DIR"/deliver.sh --batch origin master 2>&1`
584 | echo "$A"
585 | echo "$A" | grep "No version delivered yet on origin" > /dev/null
586 | assertEquals 0 $?
587 |
588 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "cd \"$SSH_TEST_PATH/test_remote\" && test -d delivered && test -L delivered/current && test -d delivered/\`readlink \"$SSH_TEST_PATH\"/test_remote/delivered/current\`"
589 | assertEquals 0 $?
590 |
591 | SSH_SHA1=`ssh $SSH_TEST_USER@$SSH_TEST_HOST "git --git-dir=\"$SSH_TEST_PATH\"/test_remote/delivered/current/.git log -n 1 --skip=1 --pretty=format:%H"`
592 |
593 | cd "$ROOT_DIR"/test_repo
594 | assertEquals `git rev-parse master` $SSH_SHA1;
595 | }
596 |
597 | testDeliverMasterSshBadSubmodule()
598 | {
599 | initWithSshOrigin
600 | git checkout master
601 | MASTER=`git rev-parse master`
602 | git submodule add "$ROOT_DIR"/.git badsub
603 | sed -ie 's/url\s*=.*$/url = \/sdfswds/' .gitmodules
604 | git commit -am "Submodule with bad URL"
605 |
606 | "$ROOT_DIR"/deliver.sh --init-remote --batch origin > /dev/null
607 | A=`"$ROOT_DIR"/deliver.sh --batch origin master 2>&1`
608 | assertEquals 7 $?
609 |
610 | git config -f .git/config --remove-section submodule.badsub
611 | git config -f .gitmodules --remove-section submodule.badsub
612 | rm -rf badsub
613 | rm -rf .git/modules/badsub
614 |
615 | git reset --hard $MASTER
616 | }
617 |
618 | testDeliverMasterSshDeliveredNotWritable()
619 | {
620 | initWithSshOrigin
621 |
622 | "$ROOT_DIR"/deliver.sh --init-remote --batch origin > /dev/null
623 | SSH_SHA1=`ssh $SSH_TEST_USER@$SSH_TEST_HOST "chmod -w \"$SSH_TEST_PATH\"/test_remote/delivered/"`
624 |
625 | A=`"$ROOT_DIR"/deliver.sh --batch origin master 2>&1`
626 | assertEquals 5 $?
627 |
628 | SSH_SHA1=`ssh $SSH_TEST_USER@$SSH_TEST_HOST "chmod +w \"$SSH_TEST_PATH\"/test_remote/delivered/"`
629 | }
630 |
631 | testBasicDeliverNonHeadSha1OnMaster()
632 | {
633 | if [[ "$OSTYPE" != "msys" ]]; then
634 | initWithOrigin
635 | "$ROOT_DIR"/deliver.sh --init-remote --batch origin > /dev/null
636 | "$ROOT_DIR"/deliver.sh --batch origin `git rev-parse master^` 2>&1 > /dev/null
637 | cd "$ROOT_DIR"/test_remote
638 | assertEquals 0 $?
639 | assertTrueEcho "[ -d delivered ]"
640 | assertTrueEcho "[ -L delivered/current ]"
641 | assertTrueEcho "[ -d delivered/`readlink "$ROOT_DIR"/test_remote/delivered/current` ]"
642 | cd "$ROOT_DIR"/test_repo
643 | assertEquals `git rev-parse master^` `git --git-dir="$ROOT_DIR"/test_remote/delivered/current/.git log -n 1 --skip=1 --pretty=format:%H`;
644 | else
645 | echo "Test won't be run (msys)"
646 | fi
647 | }
648 |
649 | testBasicDeliverNonHeadSha1OnMasterSsh()
650 | {
651 | initWithSshOrigin
652 | "$ROOT_DIR"/deliver.sh --init-remote --batch origin > /dev/null
653 | "$ROOT_DIR"/deliver.sh --batch origin `git rev-parse master^` 2>&1 > /dev/null
654 |
655 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "cd \"$SSH_TEST_PATH\"/test_remote && test -d delivered && test -L delivered/current && test -d delivered/\`readlink \"$SSH_TEST_PATH\"/test_remote/delivered/current\`"
656 | assertEquals 0 $?
657 |
658 | SSH_SHA1=`ssh $SSH_TEST_USER@$SSH_TEST_HOST "git --git-dir=\"$SSH_TEST_PATH\"/test_remote/delivered/current/.git log -n 1 --skip=1 --pretty=format:%H"`
659 |
660 | cd "$ROOT_DIR"/test_repo
661 | assertEquals `git rev-parse master^` $SSH_SHA1;
662 | }
663 |
664 | testBasicDeliverNonHeadTag()
665 | {
666 | if [[ "$OSTYPE" != "msys" ]]; then
667 | initWithOrigin
668 | "$ROOT_DIR"/deliver.sh --init-remote --batch origin > /dev/null
669 | "$ROOT_DIR"/deliver.sh --batch origin older 2>&1 > /dev/null
670 | cd "$ROOT_DIR"/test_remote
671 | assertEquals 0 $?
672 | assertTrueEcho "[ -d delivered ]"
673 | assertTrueEcho "[ -L delivered/current ]"
674 | assertTrueEcho "[ -d delivered/`readlink "$ROOT_DIR"/test_remote/delivered/current` ]"
675 | cd "$ROOT_DIR"/test_repo
676 | assertEquals `git rev-parse older` `git --git-dir="$ROOT_DIR"/test_remote/delivered/current/.git log -n 1 --skip=1 --pretty=format:%H`;
677 | else
678 | echo "Test won't be run (msys)"
679 | fi
680 | }
681 |
682 | testBasicDeliverNonHeadTagSsh()
683 | {
684 | initWithSshOrigin
685 | "$ROOT_DIR"/deliver.sh --init-remote --batch origin > /dev/null
686 | "$ROOT_DIR"/deliver.sh --batch origin older 2>&1 > /dev/null
687 |
688 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "cd \"$SSH_TEST_PATH\"/test_remote && test -d delivered && test -L delivered/current && test -d delivered/\`readlink \"$SSH_TEST_PATH\"/test_remote/delivered/current\`"
689 | assertEquals 0 $?
690 |
691 | SSH_SHA1=`ssh $SSH_TEST_USER@$SSH_TEST_HOST "git --git-dir=\"$SSH_TEST_PATH\"/test_remote/delivered/current/.git log -n 1 --skip=1 --pretty=format:%H"`
692 |
693 | cd "$ROOT_DIR"/test_repo
694 | assertEquals `git rev-parse older` $SSH_SHA1;
695 | }
696 |
697 | testBasicDeliverNonMasterBranch()
698 | {
699 | if [[ "$OSTYPE" != "msys" ]]; then
700 | initWithOrigin
701 | "$ROOT_DIR"/deliver.sh --init-remote --batch origin > /dev/null
702 | "$ROOT_DIR"/deliver.sh --batch origin branch 2>&1 > /dev/null
703 | cd "$ROOT_DIR"/test_remote
704 | assertEquals 0 $?
705 | assertTrueEcho "[ -d delivered ]"
706 | assertTrueEcho "[ -L delivered/current ]"
707 | assertTrueEcho "[ -d delivered/`readlink "$ROOT_DIR"/test_remote/delivered/current` ]"
708 | cd "$ROOT_DIR"/test_repo
709 | assertEquals `git rev-parse branch` `git --git-dir="$ROOT_DIR"/test_remote/delivered/current/.git log -n 1 --skip=1 --pretty=format:%H`;
710 | else
711 | echo "Test won't be run (msys)"
712 | fi
713 | }
714 |
715 | testBasicDeliverNonMasterBranchSsh()
716 | {
717 | initWithSshOrigin
718 | "$ROOT_DIR"/deliver.sh --init-remote --batch origin > /dev/null
719 | "$ROOT_DIR"/deliver.sh --batch origin branch 2>&1 > /dev/null
720 |
721 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "cd \"$SSH_TEST_PATH\"/test_remote && test -d delivered && test -L delivered/current && test -d delivered/\`readlink \"$SSH_TEST_PATH\"/test_remote/delivered/current\`"
722 | assertEquals 0 $?
723 |
724 | SSH_SHA1=`ssh $SSH_TEST_USER@$SSH_TEST_HOST "git --git-dir=\"$SSH_TEST_PATH\"/test_remote/delivered/current/.git log -n 1 --skip=1 --pretty=format:%H"`
725 |
726 | cd "$ROOT_DIR"/test_repo
727 | assertEquals `git rev-parse branch` $SSH_SHA1;
728 | }
729 |
730 | testBasicDeliverNonHeadSha1OtherBranch()
731 | {
732 | if [[ "$OSTYPE" != "msys" ]]; then
733 | initWithOrigin
734 | "$ROOT_DIR"/deliver.sh --init-remote --batch origin > /dev/null
735 | "$ROOT_DIR"/deliver.sh --batch origin `git rev-parse branch^` 2>&1 > /dev/null
736 | cd "$ROOT_DIR"/test_remote
737 | assertEquals 0 $?
738 | assertTrueEcho "[ delivered ]"
739 | assertTrueEcho "[ delivered/current ]"
740 | assertTrueEcho "[ delivered/`readlink "$ROOT_DIR"/test_remote/delivered/current` ]"
741 | cd "$ROOT_DIR"/test_repo
742 | assertEquals `git rev-parse branch^` `git --git-dir="$ROOT_DIR"/test_remote/delivered/current/.git log -n 1 --skip=1 --pretty=format:%H`;
743 | else
744 | echo "Test won't be run (msys)"
745 | fi
746 | }
747 |
748 | testBasicDeliverNonHeadSha1OtherBranchSsh()
749 | {
750 | initWithSshOrigin
751 | "$ROOT_DIR"/deliver.sh --init-remote --batch origin > /dev/null
752 | "$ROOT_DIR"/deliver.sh --batch origin `git rev-parse branch^` 2>&1 > /dev/null
753 |
754 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "cd \"$SSH_TEST_PATH\"/test_remote && test -d delivered && test -L delivered/current && test -d delivered/\`readlink \"$SSH_TEST_PATH\"/test_remote/delivered/current\`"
755 | assertEquals 0 $?
756 |
757 | SSH_SHA1=`ssh $SSH_TEST_USER@$SSH_TEST_HOST "git --git-dir=\"$SSH_TEST_PATH\"/test_remote/delivered/current/.git log -n 1 --skip=1 --pretty=format:%H"`
758 |
759 | assertEquals `git rev-parse branch^` "$SSH_SHA1";
760 |
761 | }
762 |
763 | testBasicDeliverNonHeadTagOtherBranch()
764 | {
765 | if [[ "$OSTYPE" != "msys" ]]; then
766 | initWithOrigin
767 | "$ROOT_DIR"/deliver.sh --init-remote --batch origin > /dev/null
768 | "$ROOT_DIR"/deliver.sh --batch origin branch_non_head 2>&1 > /dev/null
769 | cd "$ROOT_DIR"/test_remote
770 | assertEquals 0 $?
771 | assertTrueEcho "[ delivered ]"
772 | assertTrueEcho "[ delivered/current ]"
773 | assertTrueEcho "[ delivered/`readlink "$ROOT_DIR"/test_remote/delivered/current` ]"
774 | cd "$ROOT_DIR"/test_repo
775 | assertEquals `git rev-parse branch_non_head` `git --git-dir="$ROOT_DIR"/test_remote/delivered/current/.git log -n 1 --skip=1 --pretty=format:%H`;
776 | else
777 | echo "Test won't be run (msys)"
778 | fi
779 | }
780 |
781 | testBasicDeliverNonHeadTagOtherBranch()
782 | {
783 | initWithSshOrigin
784 | "$ROOT_DIR"/deliver.sh --init-remote --batch origin > /dev/null
785 | "$ROOT_DIR"/deliver.sh --batch origin branch_non_head 2>&1 > /dev/null
786 |
787 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "cd \"$SSH_TEST_PATH\"/test_remote && test -d delivered && test -L delivered/current && test -d delivered/\`readlink \"$SSH_TEST_PATH\"/test_remote/delivered/current\`"
788 | assertEquals 0 $?
789 |
790 | SSH_SHA1=`ssh $SSH_TEST_USER@$SSH_TEST_HOST "git --git-dir=\"$SSH_TEST_PATH\"/test_remote/delivered/current/.git log -n 1 --skip=1 --pretty=format:%H"`
791 |
792 | assertEquals `git rev-parse branch_non_head` "$SSH_SHA1";
793 | }
794 |
795 | testDeliverExistingRemoteNoInitSsh()
796 | {
797 | initDeliver
798 | cd "$ROOT_DIR"/test_repo
799 | git remote add new_remote $SSH_TEST_USER@$SSH_TEST_HOST:"$SSH_TEST_PATH"/test_new_remote_dir
800 | "$ROOT_DIR"/deliver.sh --batch new_remote master
801 | A=`ssh $SSH_TEST_USER@$SSH_TEST_HOST ls -1d \"$SSH_TEST_PATH\"/test_new_remote_dir/delivered/current | wc -l`
802 | assertEquals 0 $?
803 | assertEquals 1 $A
804 | ssh $SSH_TEST_USER@$SSH_TEST_HOST rm -rf "$SSH_TEST_PATH"/test_new_remote_dir
805 | git remote rm new_remote
806 | }
807 |
808 | testBasicDeliverStatus()
809 | {
810 | if [[ "$OSTYPE" != "msys" ]]; then
811 | initWithOrigin
812 | "$ROOT_DIR"/deliver.sh --init-remote --batch origin > /dev/null
813 | "$ROOT_DIR"/deliver.sh --batch origin master 2>&1 > /dev/null
814 | STATUS=`"$ROOT_DIR"/deliver.sh --status origin 2>&1 | head -n +2 | tail -n 1`
815 | assertEquals `git rev-parse master` "${STATUS:3:43}"
816 | else
817 | echo "Test won't be run (msys)"
818 | fi
819 | }
820 |
821 | testStatusModifiedOrNot()
822 | {
823 | initWithSshOrigin
824 | "$ROOT_DIR"/deliver.sh --init-remote --batch origin > /dev/null
825 | "$ROOT_DIR"/deliver.sh --batch origin master 2>&1 > /dev/null
826 | STATUS=`"$ROOT_DIR"/deliver.sh --status origin`
827 | echo "$STATUS" | grep "uncommitted changes" > /dev/null
828 | assertEquals 1 $?
829 |
830 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "echo 'new_line' >> \"$SSH_TEST_PATH\"/test_remote/delivered/current/a"
831 | STATUS=`"$ROOT_DIR"/deliver.sh --status origin`
832 | echo "$STATUS" | grep "uncommitted changes" > /dev/null
833 | assertEquals 0 $?
834 | }
835 |
836 | testBasicDeliverStatusSsh()
837 | {
838 | initWithSshOrigin
839 | "$ROOT_DIR"/deliver.sh --init-remote --batch origin > /dev/null
840 | git tag testtag
841 | "$ROOT_DIR"/deliver.sh --batch origin master 2>&1 > /dev/null
842 | STATUS=`"$ROOT_DIR"/deliver.sh --status origin | head -n +2 | tail -n 1`
843 | assertEquals `git rev-parse master` "${STATUS:3:40}"
844 | echo "$STATUS" | grep \(testtag\) > /dev/null
845 | assertEquals 0 $?
846 | git tag -d testtag
847 | }
848 |
849 | testBasicDeliverAnnotatedTagStatusSsh()
850 | {
851 | initWithSshOrigin
852 | "$ROOT_DIR"/deliver.sh --init-remote --batch origin > /dev/null
853 | git tag -a testtag -m "Annotated tag"
854 | "$ROOT_DIR"/deliver.sh --batch origin master 2>&1 > /dev/null
855 | STATUS=`"$ROOT_DIR"/deliver.sh --status origin | head -n +2 | tail -n 1`
856 | assertEquals `git rev-parse master` "${STATUS:3:40}"
857 | echo "$STATUS" | grep \(testtag\) > /dev/null
858 | assertEquals 0 $?
859 | git tag -d testtag
860 | }
861 |
862 | testBasicDeliverMultipleTagsStatusSsh()
863 | {
864 | initWithSshOrigin
865 | "$ROOT_DIR"/deliver.sh --init-remote --batch origin > /dev/null
866 | git tag testtag1
867 | git tag testtag2
868 | "$ROOT_DIR"/deliver.sh --batch origin master 2>&1 > /dev/null
869 | STATUS=`"$ROOT_DIR"/deliver.sh --status origin | head -n +2 | tail -n 1`
870 | assertEquals `git rev-parse master` "${STATUS:3:40}"
871 | echo "$STATUS" | grep "(testtag1, testtag2)" > /dev/null
872 | assertEquals 0 $?
873 | git tag -d testtag1 testtag2
874 | }
875 |
876 | testStatusNonSshRemote()
877 | {
878 | initDeliver
879 | git remote add git git://user@host/path/a/b
880 | STATUS=`"$ROOT_DIR"/deliver.sh --status git`
881 | assertEquals "Not a Git-deliver remote" "$STATUS"
882 | }
883 |
884 | testStatusNonGit()
885 | {
886 | initWithSshOrigin
887 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "mkdir -p \"$SSH_TEST_PATH\"/test_remote/delivered && cd \"$SSH_TEST_PATH\"/test_remote/delivered && rm -rf * && mkdir a && ln -s a current"
888 | local status=`"$ROOT_DIR"/deliver.sh --status origin`
889 | local expected=`echo -e "current (a)\n Unknown"`
890 | assertEquals "$expected" "$status"
891 | }
892 |
893 | testLocalGC()
894 | {
895 | if [[ "$OSTYPE" != "msys" ]]; then
896 | initWithOrigin
897 | cd "$ROOT_DIR"/test_repo
898 | rm -rf "$ROOT_DIR"/test_remote/delivered/*
899 | mkdir -p "$ROOT_DIR"/test_remote/delivered/a
900 | echo "ABCDEFG" >> "$ROOT_DIR"/test_remote/delivered/a/f
901 | echo "ABCDEFG" >> "$ROOT_DIR"/test_remote/delivered/a/g
902 | cp -r "$ROOT_DIR"/test_remote/delivered/a "$ROOT_DIR"/test_remote/delivered/b
903 | cp -r "$ROOT_DIR"/test_remote/delivered/a "$ROOT_DIR"/test_remote/delivered/c
904 | cp -r "$ROOT_DIR"/test_remote/delivered/a "$ROOT_DIR"/test_remote/delivered/d
905 | ln -s "$ROOT_DIR"/test_remote/delivered/a "$ROOT_DIR"/test_remote/delivered/current
906 | ln -s "$ROOT_DIR"/test_remote/delivered/b "$ROOT_DIR"/test_remote/delivered/previous
907 | ln -s "$ROOT_DIR"/test_remote/delivered/c "$ROOT_DIR"/test_remote/delivered/preprevious
908 | GC=`"$ROOT_DIR"/deliver.sh --gc --batch origin`
909 | echo "$GC" | grep "1 version(s) removed" > /dev/null
910 | assertEquals 0 $?
911 | echo "GC: $GC"
912 | cd "$ROOT_DIR"/test_remote/delivered
913 | assertTrueEcho "[ -d a ]"
914 | assertTrueEcho "[ -d b ]"
915 | assertTrueEcho "[ -d c ]"
916 | assertTrueEcho "[ ! -d d ]"
917 | cd "$ROOT_DIR"/test_repo
918 | GC=`"$ROOT_DIR"/deliver.sh --gc --batch origin`
919 | echo "$GC" | grep "0 version(s) removed" > /dev/null
920 | assertEquals 0 $?
921 | echo "$GC" | grep '0 B freed' > /dev/null
922 | assertEquals 0 $?
923 | echo "GC: $GC"
924 | cd "$ROOT_DIR"/test_remote/delivered
925 | assertTrueEcho "[ -d a ]"
926 | assertTrueEcho "[ -d b ]"
927 | assertTrueEcho "[ -d c ]"
928 | assertTrueEcho "[ ! -d d ]"
929 | else
930 | echo "Test won't be run (msys)"
931 | fi
932 | }
933 |
934 | testSshGC()
935 | {
936 | initWithSshOrigin
937 | cd "$ROOT_DIR"/test_repo
938 |
939 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "mkdir -p \"$SSH_TEST_PATH\"/test_remote/delivered && cd \"$SSH_TEST_PATH\"/test_remote/delivered && rm -rf * && mkdir a && echo \"ABCDEFG\" >> a/f && echo \"ABCDEFG\" >> a/g && cp -r a b && cp -r a c && cp -r a d && ln -s a current && ln -s b previous && ln -s c preprevious"
940 |
941 | GC=`"$ROOT_DIR"/deliver.sh --gc --batch origin`
942 | echo "$GC" | grep "1 version(s) removed" > /dev/null
943 | assertEquals 0 $?
944 | echo "GC: $GC"
945 |
946 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "cd \"$SSH_TEST_PATH\"/test_remote/delivered && test -d a && test -d b && test -d c && test ! -d d"
947 | assertEquals 0 $?
948 |
949 | GC=`"$ROOT_DIR"/deliver.sh --gc --batch origin`
950 | echo "$GC" | grep "0 version(s) removed" > /dev/null
951 | assertEquals 0 $?
952 | echo "$GC" | grep '0 B freed' > /dev/null
953 | assertEquals 0 $?
954 | echo "GC: $GC"
955 |
956 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "cd \"$SSH_TEST_PATH\"/test_remote/delivered && test -d a && test -d b && test -d c && test ! -d d"
957 | assertEquals 0 $?
958 |
959 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "rm -rf \"$SSH_TEST_PATH\"/test_remote"
960 | }
961 |
962 | testFailedInitSsh()
963 | {
964 | initWithSshOrigin
965 | cd "$ROOT_DIR/test_repo"
966 | echo "exit 1" > "$ROOT_DIR/test_repo/.deliver/scripts/init-remote/00-fail.sh"
967 | A=`"$ROOT_DIR"/deliver.sh --init-remote origin 2>&1`
968 | assertEquals 30 $?
969 | echo "$A" | grep "Script returned with status 1" &> /dev/null
970 | assertEquals 0 $?
971 | echo "$A" | grep "Rolling back" &> /dev/null
972 | assertEquals 1 $?
973 | }
974 |
975 | testRollbackPreDeliverySsh()
976 | {
977 | initWithSshOrigin
978 | cd "$ROOT_DIR/test_repo"
979 | echo "exit 1" > "$ROOT_DIR/test_repo/.deliver/scripts/pre-delivery/00-fail.sh"
980 | echo "echo \"PRE_FAILED_SCRIPT:\$FAILED_SCRIPT\"" > "$ROOT_DIR/test_repo/.deliver/scripts/rollback-pre-symlink/00-info.sh"
981 | echo "echo \"PRE_FAILED_SCRIPT_EXIT_STATUS:\$FAILED_SCRIPT_EXIT_STATUS\"" >> "$ROOT_DIR/test_repo/.deliver/scripts/rollback-pre-symlink/00-info.sh"
982 | A=`"$ROOT_DIR"/deliver.sh --batch origin master 2>&1`
983 | assertEquals 3 $?
984 | echo "$A"
985 | echo "$A" | grep "Script returned with status 1" &> /dev/null
986 | assertEquals 0 $?
987 | echo "$A" | grep "PRE_FAILED_SCRIPT:00-fail" &> /dev/null
988 | assertEquals 0 $?
989 | echo "$A" | grep "PRE_FAILED_SCRIPT_EXIT_STATUS:1" &> /dev/null
990 | assertEquals 0 $?
991 | echo "$A" | grep "No scripts for stage rollback-post-symlink" &> /dev/null
992 | assertEquals 0 $?
993 | echo "$A" | grep "No scripts for stage post-checkout" &> /dev/null
994 | assertNotSame 0 $?
995 | echo "$A" | grep "Rolling back" &> /dev/null
996 | assertEquals 0 $?
997 |
998 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "test ! -e \"$SSH_TEST_PATH\"/test_remote/delivered/current"
999 | assertEquals 0 $?
1000 | }
1001 |
1002 | testRollbackPostCheckoutSsh()
1003 | {
1004 | initWithSshOrigin
1005 | cd "$ROOT_DIR/test_repo"
1006 | echo "exit 22" > "$ROOT_DIR/test_repo/.deliver/scripts/post-checkout/00-fail.sh"
1007 | echo "echo \"POST_FAILED_SCRIPT:\$FAILED_SCRIPT\"" > "$ROOT_DIR/test_repo/.deliver/scripts/rollback-post-symlink/00-info.sh"
1008 | echo "echo \"POST_FAILED_SCRIPT_EXIT_STATUS:\$FAILED_SCRIPT_EXIT_STATUS\"" >> "$ROOT_DIR/test_repo/.deliver/scripts/rollback-post-symlink/00-info.sh"
1009 | A=`"$ROOT_DIR"/deliver.sh --batch origin master 2>&1`
1010 | assertEquals 3 $?
1011 | echo "$A" | grep "Script returned with status 22" &> /dev/null
1012 | assertEquals 0 $?
1013 | echo "$A" | grep "POST_FAILED_SCRIPT:00-fail" &> /dev/null
1014 | assertEquals 0 $?
1015 | echo "$A" | grep "POST_FAILED_SCRIPT_EXIT_STATUS:22" &> /dev/null
1016 | assertEquals 0 $?
1017 | echo "$A" | grep "No scripts for stage rollback-pre-symlink" &> /dev/null
1018 | assertEquals 0 $?
1019 | echo "$A" | grep "Running scripts for stage post-checkout" &> /dev/null
1020 | assertEquals 0 $?
1021 | echo "$A" | grep "No scripts for stage post-symlink" &> /dev/null
1022 | assertNotSame 0 $?
1023 | echo "$A" | grep "Rolling back" &> /dev/null
1024 | assertEquals 0 $?
1025 |
1026 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "cd \"$SSH_TEST_PATH\"/test_remote/delivered && test ! -e current"
1027 | assertEquals 0 $?
1028 | }
1029 |
1030 | testRollbackPostSymlinkNoPreviousSsh()
1031 | {
1032 | initWithSshOrigin
1033 | cd "$ROOT_DIR/test_repo"
1034 | echo "exit 22" > "$ROOT_DIR/test_repo/.deliver/scripts/post-symlink/00-fail.sh"
1035 | echo "echo \"POST_FAILED_SCRIPT:\$FAILED_SCRIPT\"" > "$ROOT_DIR/test_repo/.deliver/scripts/rollback-post-symlink/00-info.sh"
1036 | echo "echo \"POST_FAILED_SCRIPT_EXIT_STATUS:\$FAILED_SCRIPT_EXIT_STATUS\"" >> "$ROOT_DIR/test_repo/.deliver/scripts/rollback-post-symlink/00-info.sh"
1037 | A=`"$ROOT_DIR"/deliver.sh --batch origin master 2>&1`
1038 | assertEquals 3 $?
1039 | echo "$A"
1040 | echo "$A" | grep "Script returned with status 22" &> /dev/null
1041 | assertEquals 0 $?
1042 | echo "$A" | grep "POST_FAILED_SCRIPT:00-fail" &> /dev/null
1043 | assertEquals 0 $?
1044 | echo "$A" | grep "POST_FAILED_SCRIPT_EXIT_STATUS:22" &> /dev/null
1045 | assertEquals 0 $?
1046 | echo "$A" | grep "No scripts for stage rollback-pre-symlink" &> /dev/null
1047 | assertEquals 0 $?
1048 | echo "$A" | grep "No scripts for stage post-checkout" &> /dev/null
1049 | assertEquals 0 $?
1050 | echo "$A" | grep "Running scripts for stage post-symlink" &> /dev/null
1051 | assertEquals 0 $?
1052 | echo "$A" | grep "Rolling back" &> /dev/null
1053 | assertEquals 0 $?
1054 |
1055 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "cd \"$SSH_TEST_PATH\"/test_remote/delivered && test ! -e current"
1056 | assertEquals 0 $?
1057 | }
1058 |
1059 | testRollbackPostSymlinkWithPreviousSsh()
1060 | {
1061 | initWithSshOrigin
1062 | cd "$ROOT_DIR/test_repo"
1063 | echo "exit 22" > "$ROOT_DIR/test_repo/.deliver/scripts/post-symlink/00-fail.sh"
1064 |
1065 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "mkdir -p \"$SSH_TEST_PATH\"/test_remote/delivered/a && ln -s \"$SSH_TEST_PATH\"/test_remote/delivered/a \"$SSH_TEST_PATH\"/test_remote/delivered/current && touch \"$SSH_TEST_PATH\"/test_remote/delivered/a/f"
1066 |
1067 | "$ROOT_DIR"/deliver.sh --batch origin master 2>&1
1068 |
1069 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "cd \"$SSH_TEST_PATH\"/test_remote/delivered && test -e current/f && test ! -e previous"
1070 | assertEquals 0 $?
1071 | }
1072 |
1073 | testRollbackPostSymlinkWith2PreviousSsh()
1074 | {
1075 | initWithSshOrigin
1076 | cd "$ROOT_DIR/test_repo"
1077 | echo "exit 22" > "$ROOT_DIR/test_repo/.deliver/scripts/post-symlink/00-fail.sh"
1078 |
1079 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "bash" <<-EOS
1080 | mkdir -p "$SSH_TEST_PATH/test_remote/delivered/a"
1081 | ln -s "$SSH_TEST_PATH/test_remote/delivered/a" "$SSH_TEST_PATH/test_remote/delivered/current"
1082 | touch "$SSH_TEST_PATH/test_remote/delivered/a/f"
1083 | mkdir -p "$SSH_TEST_PATH/test_remote/delivered/b"
1084 | ln -s "$SSH_TEST_PATH/test_remote/delivered/b" "$SSH_TEST_PATH/test_remote/delivered/previous"
1085 | touch "$SSH_TEST_PATH/test_remote/delivered/b/g"
1086 | EOS
1087 |
1088 | "$ROOT_DIR"/deliver.sh --batch origin master 2>&1
1089 |
1090 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "bash" <<-EOS
1091 | cd "$SSH_TEST_PATH"/test_remote/
1092 | test -e delivered/current/f && \
1093 | test -e delivered/previous/g && \
1094 | test ! -e delivered/preprevious
1095 | EOS
1096 |
1097 | assertEquals 0 $?
1098 | }
1099 |
1100 | testRollbackPostSymlinkWith3PreviousSsh()
1101 | {
1102 | initWithSshOrigin
1103 | cd "$ROOT_DIR/test_repo"
1104 | echo "exit 22" > "$ROOT_DIR/test_repo/.deliver/scripts/post-symlink/00-fail.sh"
1105 |
1106 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "bash" <<-EOS
1107 | mkdir -p "$SSH_TEST_PATH/test_remote/delivered/a"
1108 | ln -s "$SSH_TEST_PATH/test_remote/delivered/a" "$SSH_TEST_PATH/test_remote/delivered/current"
1109 | touch "$SSH_TEST_PATH/test_remote/delivered/a/f"
1110 | mkdir -p "$SSH_TEST_PATH/test_remote/delivered/b"
1111 | ln -s "$SSH_TEST_PATH/test_remote/delivered/b" "$SSH_TEST_PATH/test_remote/delivered/previous"
1112 | touch "$SSH_TEST_PATH/test_remote/delivered/b/g"
1113 | mkdir -p "$SSH_TEST_PATH/test_remote/delivered/c"
1114 | ln -s "$SSH_TEST_PATH/test_remote/delivered/c" "$SSH_TEST_PATH/test_remote/delivered/preprevious"
1115 | touch "$SSH_TEST_PATH/test_remote/delivered/c/h"
1116 | EOS
1117 |
1118 | "$ROOT_DIR"/deliver.sh --batch origin master 2>&1
1119 |
1120 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "bash" <<-EOS
1121 | cd "$SSH_TEST_PATH"/test_remote/
1122 | test -e delivered/current/f && \
1123 | test -e delivered/previous/g && \
1124 | test -e delivered/preprevious/h && \
1125 | test ! -e delivered/prepreprevious
1126 | EOS
1127 | assertEquals 0 $?
1128 | }
1129 |
1130 | testFullRollbackNoRemoteSsh()
1131 | {
1132 | initWithSshOrigin
1133 | cd "$ROOT_DIR/test_repo"
1134 | "$ROOT_DIR"/deliver.sh --rollback &> /dev/null
1135 | assertEquals 1 $?
1136 | }
1137 |
1138 | testFullRollbackNoPreviousSsh()
1139 | {
1140 | initWithSshOrigin
1141 | cd "$ROOT_DIR/test_repo"
1142 | "$ROOT_DIR"/deliver.sh --rollback --batch origin
1143 | assertEquals 24 $?
1144 | "$ROOT_DIR"/deliver.sh --batch origin master
1145 | "$ROOT_DIR"/deliver.sh --rollback --batch origin
1146 | assertEquals 25 $?
1147 | }
1148 |
1149 | testFullRollbackSsh()
1150 | {
1151 | initWithSshOrigin
1152 | cd "$ROOT_DIR/test_repo"
1153 | "$ROOT_DIR"/deliver.sh --batch origin master^
1154 |
1155 | SSH_SHA1=`ssh $SSH_TEST_USER@$SSH_TEST_HOST "git --git-dir=\"$SSH_TEST_PATH\"/test_remote/delivered/current/.git log -n 1 --skip=1 --pretty=format:%H"`
1156 | assertEquals `git rev-parse master^` "$SSH_SHA1";
1157 |
1158 | "$ROOT_DIR"/deliver.sh --batch origin master
1159 |
1160 | SSH_SHA1=`ssh $SSH_TEST_USER@$SSH_TEST_HOST "git --git-dir=\"$SSH_TEST_PATH\"/test_remote/delivered/current/.git log -n 1 --skip=1 --pretty=format:%H"`
1161 | assertEquals `git rev-parse master` "$SSH_SHA1";
1162 |
1163 | SSH_SHA1=`ssh $SSH_TEST_USER@$SSH_TEST_HOST "git --git-dir=\"$SSH_TEST_PATH\"/test_remote/delivered/previous/.git log -n 1 --skip=1 --pretty=format:%H"`
1164 | assertEquals `git rev-parse master^` "$SSH_SHA1";
1165 |
1166 | "$ROOT_DIR"/deliver.sh --rollback --batch origin
1167 |
1168 | SSH_SHA1=`ssh $SSH_TEST_USER@$SSH_TEST_HOST "git --git-dir=\"$SSH_TEST_PATH\"/test_remote/delivered/current/.git log -n 1 --skip=1 --pretty=format:%H"`
1169 | assertEquals `git rev-parse master^` "$SSH_SHA1";
1170 |
1171 | SSH_SHA1=`ssh $SSH_TEST_USER@$SSH_TEST_HOST "git --git-dir=\"$SSH_TEST_PATH\"/test_remote/delivered/previous/.git log -n 1 --skip=1 --pretty=format:%H"`
1172 | assertEquals `git rev-parse master` "$SSH_SHA1";
1173 | }
1174 |
1175 | testFullRollbackNonExistentVersionSsh()
1176 | {
1177 | initWithSshOrigin
1178 | cd "$ROOT_DIR/test_repo"
1179 | "$ROOT_DIR"/deliver.sh --rollback --batch origin foo
1180 | assertEquals 24 $?
1181 | "$ROOT_DIR"/deliver.sh --batch origin master
1182 | "$ROOT_DIR"/deliver.sh --rollback --batch origin foo
1183 | assertEquals 25 $?
1184 | }
1185 |
1186 | testFullRollbackVersionSsh()
1187 | {
1188 | initWithSshOrigin
1189 | cd "$ROOT_DIR/test_repo"
1190 | "$ROOT_DIR"/deliver.sh --batch origin master^^
1191 | local ROLLBACK_TO=`ssh $SSH_TEST_USER@$SSH_TEST_HOST "cd \"$SSH_TEST_PATH\"/test_remote/delivered/current && pwd -P"`
1192 | ROLLBACK_TO=`basename "$ROLLBACK_TO"`
1193 |
1194 | "$ROOT_DIR"/deliver.sh --batch origin master^
1195 | "$ROOT_DIR"/deliver.sh --batch origin master
1196 |
1197 | SSH_SHA1=`ssh $SSH_TEST_USER@$SSH_TEST_HOST "git --git-dir=\"$SSH_TEST_PATH\"/test_remote/delivered/current/.git log -n 1 --skip=1 --pretty=format:%H"`
1198 | assertEquals `git rev-parse master` "$SSH_SHA1";
1199 |
1200 | SSH_SHA1=`ssh $SSH_TEST_USER@$SSH_TEST_HOST "git --git-dir=\"$SSH_TEST_PATH\"/test_remote/delivered/previous/.git log -n 1 --skip=1 --pretty=format:%H"`
1201 | assertEquals `git rev-parse master^` "$SSH_SHA1";
1202 |
1203 | SSH_SHA1=`ssh $SSH_TEST_USER@$SSH_TEST_HOST "git --git-dir=\"$SSH_TEST_PATH\"/test_remote/delivered/preprevious/.git log -n 1 --skip=1 --pretty=format:%H"`
1204 | assertEquals `git rev-parse master^^` "$SSH_SHA1";
1205 |
1206 | "$ROOT_DIR"/deliver.sh --rollback --batch origin "$ROLLBACK_TO"
1207 |
1208 | SSH_SHA1=`ssh $SSH_TEST_USER@$SSH_TEST_HOST "git --git-dir=\"$SSH_TEST_PATH\"/test_remote/delivered/current/.git log -n 1 --skip=1 --pretty=format:%H"`
1209 | assertEquals `git rev-parse master^^` "$SSH_SHA1";
1210 |
1211 | SSH_SHA1=`ssh $SSH_TEST_USER@$SSH_TEST_HOST "git --git-dir=\"$SSH_TEST_PATH\"/test_remote/delivered/previous/.git log -n 1 --skip=1 --pretty=format:%H"`
1212 | assertEquals `git rev-parse master` "$SSH_SHA1";
1213 | }
1214 |
1215 | testGroupPermissionsNotShared()
1216 | {
1217 | initWithSshOrigin
1218 | "$ROOT_DIR"/deliver.sh --batch origin master
1219 | assertEquals 0 $?
1220 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "ls -ld $SSH_TEST_GROUP \"$SSH_TEST_PATH\"/test_remote" | cut -c 6 | grep 'w'
1221 | assertEquals 1 $?
1222 | }
1223 |
1224 | testGroupPermissions()
1225 | {
1226 | initWithSshOrigin "group"
1227 | ssh $SSH_TEST_USER@$SSH_TEST_HOST "chgrp $SSH_TEST_GROUP \"$SSH_TEST_PATH\"/test_remote"
1228 | cd "$ROOT_DIR/test_repo"
1229 | git remote add origin_same_group "$SSH_TEST_USER_SAME_GROUP@$SSH_TEST_HOST:$SSH_TEST_PATH/test_remote"
1230 | git remote add origin_not_same_group "$SSH_TEST_USER_NOT_SAME_GROUP@$SSH_TEST_HOST:$SSH_TEST_PATH/test_remote"
1231 | "$ROOT_DIR"/deliver.sh --batch origin master
1232 | assertEquals 0 $?
1233 | "$ROOT_DIR"/deliver.sh --batch origin master
1234 | assertEquals 0 $?
1235 | "$ROOT_DIR"/deliver.sh --batch origin master
1236 | assertEquals 0 $?
1237 | "$ROOT_DIR"/deliver.sh --batch origin_same_group master
1238 | assertEquals 0 $?
1239 | "$ROOT_DIR"/deliver.sh --batch origin_not_same_group master
1240 | assertEquals 5 $?
1241 | GC=`"$ROOT_DIR"/deliver.sh --gc --batch origin_not_same_group`
1242 | assertEquals 27 $?
1243 | echo "$GC"
1244 | echo "$GC" | grep "0 version(s) removed" > /dev/null
1245 | assertEquals 0 $?
1246 | GC=`"$ROOT_DIR"/deliver.sh --gc --batch origin_same_group`
1247 | assertEquals 0 $?
1248 | echo "$GC"
1249 | echo "$GC" | grep "1 version(s) removed" > /dev/null
1250 | assertEquals 0 $?
1251 | "$ROOT_DIR"/deliver.sh --batch origin master
1252 | assertEquals 0 $?
1253 | "$ROOT_DIR"/deliver.sh --batch origin_same_group master
1254 | assertEquals 0 $?
1255 | GC=`"$ROOT_DIR"/deliver.sh --gc origin`
1256 | assertEquals 0 $?
1257 | echo "$GC"
1258 | echo "$GC" | grep "2 version(s) removed" > /dev/null
1259 | assertEquals 0 $?
1260 | }
1261 |
1262 | . lib/shunit2
1263 |
--------------------------------------------------------------------------------
/tests_travis.sh:
--------------------------------------------------------------------------------
1 | sudo groupadd git
2 | sudo usermod -a -G git $USER
3 |
4 | ssh-keygen
5 | cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
6 |
7 | ssh-keyscan -H localhost >> ~/.ssh/known_hosts
8 |
9 | sudo useradd -g git bob
10 | sudo cp ~$USER/.ssh/authorized_keys ~bob/.ssh/
11 | sudo chown bob ~bob/.ssh/authorized_keys
12 | sudo su bob -c "ssh-keyscan -H localhost >> ~/.ssh/known_hosts"
13 |
14 | sudo useradd alice
15 | sudo cp ~$USER/.ssh/authorized_keys ~alice/.ssh/
16 | sudo chown alice ~alice/.ssh/authorized_keys
17 | sudo su alice -c "ssh-keyscan -H localhost >> ~/.ssh/known_hosts"
18 |
19 | ./tests.sh
20 |
--------------------------------------------------------------------------------