dh-exec-0.12/0000755000000000000000000000000012236132554007642 5ustar dh-exec-0.12/COPYING0000644000000000000000000010451312026641012010670 0ustar GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . dh-exec-0.12/src/0000755000000000000000000000000012235432677010441 5ustar dh-exec-0.12/src/dh-exec.lib.c0000644000000000000000000000747412235222103012660 0ustar /* dh-exec.lib.c -- Wrapper around dh-exec-* commands. * Copyright (C) 2011-2013 Gergely Nagy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #define _GNU_SOURCE #include #include #include #include #include #include #include #include "dh-exec.lib.h" #define DH_EXEC_SCRIPTDIR "/usr/share/dh-exec" #define DH_EXEC_LIBDIR "/usr/lib/dh-exec" #ifndef DH_EXEC_CMD_ALWAYS #define DH_EXEC_CMD_ALWAYS 0 #endif static const char *DH_EXEC_CMD_PREFIX; const char * dh_exec_scriptdir (void) { char *e; e = getenv ("DH_EXEC_SCRIPTDIR"); if (e) return e; return DH_EXEC_SCRIPTDIR; } const char * dh_exec_libdir (void) { char *e; e = getenv ("DH_EXEC_LIBDIR"); if (e) return e; return DH_EXEC_LIBDIR; } const char * dh_exec_source (int argc, int optind, char *argv[]) { if (argc - optind >= 1) return argv[optind]; return getenv ("DH_EXEC_SOURCE"); } char * dh_exec_cmd_path (const char *dir, const char *cmd) { char *path; if (asprintf (&path, "%s/%s", dir, cmd) <= 0) { perror ("asprintf"); exit (1); } return path; } static int dh_exec_script_allowed (const char *fn) { char *e; char *needle; if (DH_EXEC_CMD_ALWAYS) return 0; e = getenv ("DH_EXEC_SCRIPTS"); if (!e) return 0; if (asprintf (&needle, "%s|", fn + strlen ("dh-exec-")) <= 0) { perror ("asprintf"); exit (1); } if (strstr (e, needle) == NULL) { free (needle); return 1; } free (needle); return 0; } int dh_exec_cmd_filter (const struct dirent *entry) { char *path; int r; if (strncmp (entry->d_name, DH_EXEC_CMD_PREFIX, strlen (DH_EXEC_CMD_PREFIX)) != 0) return 0; if (dh_exec_script_allowed (entry->d_name) != 0) return 0; path = dh_exec_cmd_path (dh_exec_scriptdir (), entry->d_name); r = access (path, X_OK); free (path); return !r; } int dh_exec_main (const char *cmd_prefix, int argc, char *argv[]) { pipeline *p; int status, n; struct dirent **cmdlist; if (argc > 2) { fprintf (stderr, "%s: Need an input file argument, or no argument at all!\n", argv[0]); exit (1); } DH_EXEC_CMD_PREFIX = cmd_prefix; n = scandir (dh_exec_scriptdir (), &cmdlist, dh_exec_cmd_filter, alphasort); if (n < 0) { fprintf (stderr, "%s: scandir(\"%s\"): %s\n", argv[0], dh_exec_scriptdir(), strerror (errno)); exit (1); } p = pipeline_new (); if (argc == 2) { setenv ("DH_EXEC_SOURCE", argv[1], 1); pipeline_want_infile (p, argv[1]); } while (n--) { char *cmd = dh_exec_cmd_path (dh_exec_scriptdir (), cmdlist[n]->d_name); pipeline_command_args (p, cmd, NULL); free (cmd); free (cmdlist[n]); } free (cmdlist); if (pipeline_get_ncommands (p) == 0) pipeline_command_args (p, "cat", NULL); pipeline_start (p); status = pipeline_wait (p); pipeline_free (p); return status; } int dh_exec_ignore (void) { pipeline *p; int status; p = pipeline_new (); pipeline_command_args (p, "cat", NULL); pipeline_start (p); status = pipeline_wait (p); pipeline_free (p); return status; } dh-exec-0.12/src/dh-exec-install.10000644000000000000000000000502612026641012013466 0ustar .TH "DH\-EXEC\-INSTALL" "1" "2012-05-03" "" "dh-exec" .ad l .nh .SH "NAME" dh\-exec\-install \- Install (and possibly rename) files. .SH "SYNOPSIS" \fB#! /usr/bin/dh\-exec\fR .br debian/default.conf => /etc/my\-package/start.conf .br usr/bin/* .SH "DESCRIPTION" Being a sub\-command of \fIdh\-exec\fR(1), this program must not be ran directly, but through \fIdh\-exec\fR, which automatically runs all available sub\-commands if run bare; or explicitly with \fBdh\-exec \-\-with=install\fR. It is meant to be used for \fIdh_install\fR(1) files, and those alone. If it finds that its input is not such a file, it will do nothing, but echo back the contents. The purpose of the program is to extend \fIdh_install\fR(1)'s functionality, by allowing to specify a destination filename. This can be accomplished by a special syntax: the \fI" => "\fR mark between a source and a destination means that the source file should be installed with the specified destination name. For obvious reasons, the source \fBmust not\fR be a wildcard, and the destination in this case \fBmust\fR be a file, and not a directory. All other non\-comment lines are left alone. .SH "RESTRICTIONS" Due to the way executable scripts are called from \fIdebhelper\fR(1), there is no way to know what options were used for the original \fIdh_install\fR(1). This means, that the \fB\-\-sourcedir\fR option of \fIdh_install\fR(1) will not work correctly when \fIdh\-exec\-install\fR is in use. .SH "IMPLEMENTATION" Internally, the renaming happens by creating a temporary directory under \fIdebian/tmp/\fR, and copying (or moving, if the source was under \fIdebian/tmp/\fR to begin with) the file there, with the new name. This is done this way to allow \fIdh_install\fR(1) to do the real copying, and allow its options to continue working, even when renaming is involved. The temporary directory is put under \fIdebian/tmp\fR so that it will be cleaned by \fIdh_prep\fR(1) when the \fBclean\fR target gets to run. Thus, no extra code is needed anywhere to clean up the renamed files. .SH "ENVIRONMENT" .PP \fIDH_EXEC_SCRIPTDIR\fR .RS 4 Indicates which directory the command\-specific scripts should be sought for. If not specified, scripts will be searched for in \fI/usr/share/dh\-exec/\fR. .RE .SH "FILES" .PP \fI$DH_EXEC_SCRIPTDIR/dh\-exec\-install\-*\fR .RS 4 The various scripts for the higher\-level program. .RE .SH "SEE ALSO" \fIdebhelper\fR(1), \fIdh\-exec\fR(1), \fIdh_install\fR(1) .SH "AUTHOR" dh\-exec\-install is copyright \(co 2011-2012 by Gergely Nagy . dh-exec-0.12/src/dh-exec-illiterate.10000644000000000000000000000606612026641012014163 0ustar .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .TH "DH\-EXEC\-ILLITERATE" "1" "2012-05-03" "" "dh-exec" .ad l .nh .SH "NAME" dh\-exec\-illiterate \- Write literate debhelper config files! .SH "SYNOPSIS .Vb 3 \fB#! /usr/bin/dh\-exec \-\-with=illiterate,subst,install\fR Greetings, my dear reader, and welcome to the awesome world of literate programming! Today, we're going to explore how to write a debhelper install file in a literate manner. Trust me, it's going to be lots and lots of fun! So, what exactly are we trying to accomplish? We're going to try installing a file from `src/this\-file' in the source tree, to a multi\-arched path in the binary file. Lets say, to `/usr/lib/foo/${DEB_HOST_MULTIARCH}/'. Of course, ${DEB_HOST_MULTIARCH} is a variable, and will be expanded later in the dh\-exec pipeline. It'll be something like x86_64\-linux\-gnu. Furthermore, we want to install all files from the 'usr/lib' directory under debian/tmp. If we were writing an illiteral install file, we'd write this rule as: usr/lib But the above description is much easier to understand, isn't it? We're almost finished! One thing left to do, is to install a script named \`rename\-me', to \`/usr/share/foo/new\-name' \- we renamed it in the process! .Ve .SH "DESCRIPTION" The dh\-exec\-illiterate sub\-command, unlike the others, does not serve any particular case, except to serve as a warning to all, that things can be taken to an extreme, even with dh\-exec. On the other hand, it is just like the other sub\-commands in that it must not be called directly, but through \fIdh\-exec\fR(1), which automatically runs all available sub\-commands if run bare; or explicitly with \fBdh\-exec \-\-with=illiterate\fR. It is a program that will translate its input from pretty much free-form text into something that resembles an install file. At least, that's the only supported output format for now. Everything that's not recognised, will be ignored, and not printed. The recognised constructs are: .IP "\fB`source'\fR \fI...\fR \fB`destination'\fR" The first string between a backtick and a single quote will be treated as the source file, the next such string will be the destination. If the destination ends with a slash, dh\-exec\-illiterate will consider it a directory, otherwise it will output a construct that dh\-exec\-install can recognise as a rename operation. .IP "\fB'source'\fR" A string, without whitespace, between two single quotes is treated as a source, whose destination is unspecified, and is left up to \fIdh_install\fR(1) to figure out. .SH "ENVIRONMENT" .PP \fIDH_EXEC_SCRIPTDIR\fR .RS 4 Indicates which directory the command\-specific scripts should be sought for. If not specified, scripts will be searched for in \fI/usr/share/dh\-exec/\fR. .RE .SH "FILES" .PP \fI$DH_EXEC_SCRIPTDIR/dh\-exec\-illiterate\-*\fR .RS 4 The various scripts for the higher\-level program. .RE .SH "SEE ALSO" \fIdebhelper\fR(1), \fIdh\-exec\fR(1) .SH "AUTHOR" dh\-exec\-illiterate is copyright \(co 2011-2012 by Gergely Nagy . dh-exec-0.12/src/dh-exec.simple.c0000644000000000000000000000206412235156156013407 0ustar /* dh-exec.simple.c -- Simple wrapper around dh-exec-* commands. * Copyright (C) 2011, 2013 Gergely Nagy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "dh-exec.lib.h" #ifndef dh_exec_simple_preamble #define dh_exec_simple_preamble(argc,argv) 0 #endif int main (int argc, char *argv[]) { int r; if ((r = dh_exec_simple_preamble (argc, argv)) != 0) return r; return dh_exec_main ("dh-exec-" DH_EXEC_CMD "-", argc, argv); } dh-exec-0.12/src/dh-exec-install.c0000644000000000000000000000346212235432677013573 0ustar /* dh-exec-install.c -- Wrapper around dh-exec-install-magic. * Copyright (C) 2011, 2013 Gergely Nagy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #define _GNU_SOURCE #include #include #include #include #include #include "dh-exec.lib.h" static int preamble(int argc, char *argv[]) { const char *src = dh_exec_source (argc, 1, argv); if (!src) { fprintf (stderr, "%s: Need an input file argument, stdin not acceptable!\n", argv[0]); return EXIT_FAILURE; } /* Handle cases where the source is not an .install file */ if (strcmp (src, "install") != 0 && fnmatch ("*[./]install", src, 0) != 0) { /* Source is stdin, we're piped, ignore it. */ if (argc < 2) return (dh_exec_ignore ()); else { /* Source is from the command-line directly, raise an error. */ fprintf (stderr, "%s: Only .install filename extensions are allowed: %s\n", argv[0], src); return EXIT_FAILURE; } } return 0; } #define dh_exec_simple_preamble preamble #include "dh-exec.simple.c" dh-exec-0.12/src/dh-exec.10000644000000000000000000000753012026641012012024 0ustar .TH "DH\-EXEC" "1" "2012-05-03" "" "dh-exec" .ad l .nh .SH "NAME" dh\-exec \- Debhelper executable file helpers .SH "SYNOPSIS" \fB#! /usr/bin/dh\-exec\fR .br src/libfoo-*.so.* debian/foo-plugins/usr/lib/foo/${DEB_HOST_MULTIARCH}/ .br etc/example.conf => debian/foo/etc/foo/foo.conf .SH "DESCRIPTION" dh\-exec is a simple program, meant to be used as the interpreter for executable debhelper config files. It is a wrapper around the various other sub\-commands (see below), and will pipe the input file through all of them in turn, using an ordering that makes most sense in the vast majority of cases. The order as of now is \fIdh\-exec\-subst\fR gets run first, followed by \fIdh\-exec\-install\fR, so that variable expansion happens before files need to be copied. .SH "ARCHITECTURE" dh\-exec is built up from three layers: there is the \fBdh-exec\fR utility, its single entry point, the only thing one will need to call. Below that, there are the various \fIsub\-commands\fR, such as \fIdh\-exec\-subst\fR, \fIdh\-exec\-installs\fR and \fIdh\-exec\-illiterate\fR, which are thin wrappers around the various dh\-exec scripts, that make sure they only run those that need to be run. And the lowest layer are the various scripts that do the actual work. One can control which sub\-commands to run, or if even more granularity is desired, one can limit which scripts shall be run, too. See below for the options! .SH "OPTIONS" .IP "\fB\-\-with\fR=\fIcommand\fR[\fB,\fR\fIcommand\fR ...]" 4 Replace the list of sub\-commands to run the input through with a custom list (where entries are separated by whitespace or commas). This option will always replace the existing list with whatever is specified. This can be used to explicitly set which sub\-commands to use. The list \fBmust not\fR include the \fIdh\-exec\-\fR prefix. Defaults to \fIsubst,install\fR. .IP "\fB\-\-without\fR=\fIcommand\fR[\fB,\fR\fIcommand\fR ...]" 4 Inversely to the option above, this lists all the sub\-commands which should not be used. The list \fBmust not\fR include the \fIdh\-exec\-\fR prefix. .IP "\fB\-\-with\-scripts=\fIscript\fR[\fB,\fR\fIscript\fR ...]" 4 Replace the list of scripts to run the input through with a custom list (where entries are separated by whitespace or commas). This option will always replace the existing list with whatever is specified. This can be used to explicitly specify which scripts to use, limiting even beyond what the \fB\-\-with\fR option is capable of. The list \fBmust not\fR include the \fIdh\-exec\-\fR prefix. By default it is empty, meaning there is no filtering done, and whatever scripts the sub\-commands find, will be run. .IP "\fB\-\-no\-act" 4 Do not really do anything, but print the pipeline that would have been run instead. .IP "\fB\-\-list" 4 List the available sub\-commands and scripts, grouped by sub\-command. .IP "\fB\-\-help\fR, \fB\-\-version\fR" 4 Display a short help or the package version, respectively. .SH "SUB\-COMMANDS" .TP .B dh\-exec\-subst Substitutes various variables (either from the environment, or from \fIdpkg\-architecture\fR(1)). .TP .B dh\-exec\-install An extension to \fIdh_install\fR(1), that supports renaming files during the copy process, using a special syntax. .SH "ENVIRONMENT" .PP \fIDH_EXEC_LIBDIR\fR .RS 4 The directory in which the wrapped sub\-commands reside. Defaults to \fI/usr/lib/dh\-exec/\fR. .RE .PP \fIDH_EXEC_SCRIPTDIR\fR .RS 4 The directory in which the scripts that do the heavy work live. Defaults to \fI/usr/share/dh\-exec/\fR. .RE .SH "FILES" .PP \fI$DH_EXEC_LIBDIR/dh\-exec\-*\fR .RS 4 The various sub\-commands. .RE .PP \fI$DH_EXEC_SCRIPTDIR/dh\-exec\-*\fR .RS 4 The various scripts ran by the sub\-commands. .RE .SH "SEE ALSO" \fIdebhelper\fR(1), \fIdh\-exec\-subst\fR(1), \fIdh\-exec\-install\fR(1) .SH "AUTHOR" dh\-exec is copyright \(co 2011-2012 by Gergely Nagy . dh-exec-0.12/src/dh-exec.c0000644000000000000000000002176212235257645012132 0ustar /* dh-exec.c -- Wrapper around dh-exec-* commands. * Copyright (C) 2011-2013 Gergely Nagy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #define _GNU_SOURCE #include #include #include #include #include #include #include #include "config.h" #include "dh-exec.lib.h" const char *DH_EXEC_CMD_PREFIX = "dh-exec-"; #define DH_EXEC_CMD_SEPARATORS ",; \t" static void dh_exec_pipeline_add (pipeline *p, const char *cmd) { char *path = dh_exec_cmd_path (dh_exec_libdir (), cmd); pipeline_command_args (p, path, NULL); free (path); } static void dh_exec_cmdlist_free (char **cmdlist) { int i = 0; if (!cmdlist) return; while (cmdlist[i]) { free (cmdlist[i]); i++; } free (cmdlist); } static char ** dh_exec_with (char **cmdlist, const char *prglist) { int i = 0; char *t, *orig, *curr; orig = strdup (prglist); t = orig; while (strsep (&t, DH_EXEC_CMD_SEPARATORS)) i++; free (orig); orig = strdup (prglist); t = orig; dh_exec_cmdlist_free (cmdlist); cmdlist = (char **)calloc (i + 1, sizeof (char *)); i = 0; while ((curr = strsep (&t, DH_EXEC_CMD_SEPARATORS)) != NULL) cmdlist[i++] = strdup (curr); free (orig); cmdlist[i] = NULL; return cmdlist; } static char ** dh_exec_without (char **cmdlist, const char *prglist) { char *t, *orig, *prg; orig = strdup (prglist); t = orig; while ((prg = strsep (&t, DH_EXEC_CMD_SEPARATORS)) != NULL) { int i = 0; while (cmdlist[i]) { if (strcmp (cmdlist[i], prg) == 0) { free (cmdlist[i]); cmdlist[i] = strdup (""); } i++; } } free (orig); return cmdlist; } static int dh_exec_help (void) { printf ("dh-exec - Scripts to help with executable debhelper files.\n" "\n" "Usage: dh-exec [OPTION...] [FILE]\n" "\n" " --with=[command,...] Run with the specified sub-commands only.\n" " --without=[command,...] Run without the specified sub-commands.\n" " --with-scripts=[script,...] Run with the specified scripts only.\n" " --no-act Do not run, just print the pipeline.\n" " --list List the available sub-commands and scripts.\n" " --help Display this help screen.\n" " --version Output version information and exit.\n" "\n" "When listing helpers, the list needs to be comma separated.\n" "\n" "For complete documentation, see the dh-exec(1) manual page.\n"); return EXIT_SUCCESS; } static int dh_exec_version (void) { printf ("dh-exec " PACKAGE_VERSION "\n" "\n" "Copyright (C) 2011-2013 Gergely Nagy \n" "This is free software; see the source for copying conditions. There is NO\n" "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" "\n" "Written by Gergely Nagy \n"); return EXIT_SUCCESS; } static int dh_exec_list_filter (const struct dirent *entry) { if (strncmp (entry->d_name, DH_EXEC_CMD_PREFIX, strlen (DH_EXEC_CMD_PREFIX)) != 0 || strncmp (entry->d_name + strlen (DH_EXEC_CMD_PREFIX), "strip", strlen ("strip")) == 0) return 0; return 1; } static int dh_exec_list (char *argv[]) { struct dirent **cmdlist; int n; int cplen = strlen (DH_EXEC_CMD_PREFIX); printf ("dh-exec - Available sub-commands and scripts\n" "\n"); n = scandir (dh_exec_libdir (), &cmdlist, dh_exec_list_filter, alphasort); if (n < 0) { fprintf (stderr, "%s: scandir(\"%s\"): %s\n", argv[0], dh_exec_libdir (), strerror (errno)); return 1; } while (n--) { struct dirent **scriptlist; int sn; printf (" %s:\n", cmdlist[n]->d_name + cplen); sn = scandir (dh_exec_scriptdir (), &scriptlist, dh_exec_list_filter, alphasort); if (sn < 0) { fprintf (stderr, "%s: scandir(\"%s\"): %s\n", argv[0], dh_exec_scriptdir (), strerror (errno)); free (cmdlist); return 1; } while (sn--) { if (strncmp (scriptlist[sn]->d_name, cmdlist[n]->d_name, strlen (cmdlist[n]->d_name)) != 0) { free (scriptlist[sn]); continue; } printf (" \t%s\n", scriptlist[sn]->d_name + cplen); free (scriptlist[sn]); } free (cmdlist[n]); free (scriptlist); } free (cmdlist); return 0; } int main (int argc, char *argv[]) { pipeline *p; int status, n = 0, no_act = 0, do_list = 0; const char *src; char **dhe_commands, **dhe_scripts = NULL; static struct option dhe_options[] = { {"with", required_argument, NULL, 'I'}, {"with-scripts", required_argument, NULL, 'i'}, {"without", required_argument, NULL, 'X'}, {"help", no_argument , NULL, 'h'}, {"version", no_argument , NULL, 'v'}, {"no-act", no_argument , NULL, 'n'}, {"list", no_argument , NULL, 'l'}, {NULL, 0 , NULL, 0 }, }; dhe_commands = dh_exec_with (NULL, "subst,install"); while (1) { int option_index, c; c = getopt_long (argc, argv, "hI:i:X:vnl", dhe_options, &option_index); if (c == -1) break; switch (c) { case 'I': dhe_commands = dh_exec_with (dhe_commands, optarg); break; case 'X': dhe_commands = dh_exec_without (dhe_commands, optarg); break; case 'i': dhe_scripts = dh_exec_with (dhe_scripts, optarg); break; case 'h': dh_exec_cmdlist_free (dhe_commands); dh_exec_cmdlist_free (dhe_scripts); return dh_exec_help (); case 'v': dh_exec_cmdlist_free (dhe_commands); dh_exec_cmdlist_free (dhe_scripts); return dh_exec_version (); case 'n': no_act = 1; break; case 'l': do_list = 1; break; default: dh_exec_help (); dh_exec_cmdlist_free (dhe_commands); dh_exec_cmdlist_free (dhe_scripts); return (EXIT_FAILURE); } } if (do_list) { dh_exec_cmdlist_free (dhe_commands); dh_exec_cmdlist_free (dhe_scripts); return dh_exec_list (argv); } src = dh_exec_source (argc, optind, argv); p = pipeline_new (); if (src) { pipeline_want_infile (p, src); setenv ("DH_EXEC_SOURCE", src, 1); } if (dhe_scripts) { int i = 0; int size = 0, pos = 0; char *env; while (dhe_scripts[i]) { size += strlen (dhe_scripts[i]) + 1; i++; } env = (char *)malloc (size + 1); i = 0; while (dhe_scripts[i]) { char *path; if (asprintf (&path, "%s/dh-exec-%s", dh_exec_scriptdir (), dhe_scripts[i]) <= 0) { perror ("asprintf"); exit (1); } if (access (path, R_OK | X_OK) != 0) { fprintf (stderr, "%s: script '%s' is not valid!\n", argv[0], dhe_scripts[i]); exit (1); } free (path); memcpy (env + pos, dhe_scripts[i], strlen (dhe_scripts[i])); pos += strlen (dhe_scripts[i]); env[pos++] = '|'; i++; } env[pos] = '\0'; setenv ("DH_EXEC_SCRIPTS", env, 1); free (env); dh_exec_cmdlist_free (dhe_scripts); } while (dhe_commands[n]) { char *cmd; if (dhe_commands[n][0] == '\0') { n++; continue; } if (asprintf (&cmd, "%s%s", DH_EXEC_CMD_PREFIX, dhe_commands[n]) <= 0) { perror ("asprintf"); exit (EXIT_FAILURE); } dh_exec_pipeline_add (p, cmd); free (cmd); n++; } dh_exec_cmdlist_free (dhe_commands); dh_exec_pipeline_add (p, "dh-exec-strip"); if (no_act) { pipeline_dump (p, stdout); pipeline_free (p); return EXIT_SUCCESS; } pipeline_start (p); status = pipeline_wait (p); pipeline_free (p); return status; } dh-exec-0.12/src/dh-exec.lib.h0000644000000000000000000000225012235222076012661 0ustar /* dh-exec.lib.h -- Wrapper around dh-exec-* commands. * Copyright (C) 2011, 2013 Gergely Nagy * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef DH_EXEC_LIB_H #define DH_EXEC_LIB_H #include const char *dh_exec_scriptdir (void); const char *dh_exec_libdir (void); const char *dh_exec_source (int argc, int optind, char *argv[]); char *dh_exec_cmd_path (const char *dir, const char *cmd); int dh_exec_cmd_filter (const struct dirent *entry); int dh_exec_main (const char *cmd_prefix, int argc, char *argv[]); int dh_exec_ignore (void); #endif dh-exec-0.12/src/dh-exec-subst.10000644000000000000000000000364412026641012013164 0ustar .TH "DH\-EXEC\-SUBST" "1" "2012-05-03" "" "dh-exec" .ad l .nh .SH "NAME" dh\-exec\-subst \- Debhelper executable file substition scripts .SH "SYNOPSIS" \fB#! /usr/bin/dh\-exec\fR .br src/libfoo-*.so.* debian/foo-plugins/usr/lib/foo/${DEB_HOST_MULTIARCH}/ .SH "DESCRIPTION" Being a sub\-command of \fIdh\-exec\fR(1), this program must not be ran directly, but through \fIdh\-exec\fR, which automatically runs all available sub\-commands if run bare; or explicitly with \fBdh\-exec \-\-with=subst\fR. It is a wrapper around the various other substitution helpers, and will pipe the input file through all the available substitution helpers. It is up to these scripts to do the actual work. When a helper fails to expand a variable within its input, it will leave it as-is, so that later in the pipeline it can perhaps be expanded by another program. .SH "SCRIPTS" .TP .B dh\-exec\-subst\-env Substitutes any of the available, exported environment variables into its input. It does not do any kind of filtering: whatever is available in the environment, will be available for substitution, however unsafe that may be. .TP .B dh\-exec\-subst\-multiarch Attempts to expand any of the variables known to \fIdpkg\-architecture\fR(1), mostly useful for multi\-arch support. The command will query \fIdpkg\-architecture\fR(1) directly, and does not rely on environment variables set (as the called program will prefer already set environment variables anyway). .SH "ENVIRONMENT" .PP \fIDH_EXEC_SCRIPTDIR\fR .RS 4 Indicates which directory the command\-specific scripts should be sought for. If not specified, scripts will be searched for in \fI/usr/share/dh\-exec/\fR. .RE .SH "FILES" .PP \fI$DH_EXEC_SCRIPTDIR/dh\-exec\-subst\-*\fR .RS 4 The various scripts for the higher\-level program. .RE .SH "SEE ALSO" \fIdebhelper\fR(1), \fIdh\-exec\fR(1) .SH "AUTHOR" dh\-exec\-subst is copyright \(co 2011-2012 by Gergely Nagy . dh-exec-0.12/configure.ac0000644000000000000000000000113212236132314012117 0ustar # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. AC_INIT([dh-exec], [0.12], [algernon@debian.org]) AM_INIT_AUTOMAKE([foreign subdir-objects]) m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([no])]) AC_CONFIG_SRCDIR([src/dh-exec.simple.c]) AC_CONFIG_HEADERS([config.h]) AC_PROG_CC AC_PROG_CC_C_O PKG_PROG_PKG_CONFIG PKG_CHECK_MODULES(LIBPIPELINE, libpipeline >= 1.2.0,,) AC_CHECK_HEADERS([stdlib.h string.h unistd.h]) AC_CHECK_FUNCS([setenv strdup strerror strstr]) AC_FUNC_MALLOC AC_CONFIG_FILES([Makefile]) AC_OUTPUT dh-exec-0.12/t/0000755000000000000000000000000012235212767010111 5ustar dh-exec-0.12/t/test_strip.bats0000755000000000000000000000274612235150507013171 0ustar ## -*- shell-script -*- load "test.lib" @test "dh-exec-strip: the she-bang gets removed from the output" { run_dh_exec src/dh-exec --without=install <${pkgfile} < /var/lib/dh-exec/new-file ${pkgfile} /usr/lib/dh-exec/\${DEB_HOST_MULTIARCH}/ ${pkgfile} => /usr/lib/dh-exec/\${DEB_HOST_MULTIARCH}/new-file EOF chmod +x ${pkgfile} } teardown () { cd .. rm -rf "${td}" } @test "combined: Copying to dir gets passed on, no expansions" { run_dh_exec ${td}/${pkgfile} expect_output "${pkgfile} /var/lib/dh-exec/" } @test "combined: copying a file with a rename gets acted upon" { run_dh_exec ${td}/${pkgfile} expect_file "/var/lib/dh-exec/new-file" } @test "combined: multi-arch variable gets expanded, and copied" { run_dh_exec ${td}/${pkgfile} expect_output "${pkgfile} /usr/lib/dh-exec/$(dpkg-architecture -qDEB_HOST_MULTIARCH)/" } @test "combined: multi-arch variables get expanded before copying" { run_dh_exec ${td}/${pkgfile} expect_file "/usr/lib/dh-exec/$(dpkg-architecture -qDEB_HOST_MULTIARCH)/new-file" } @test "combined: dh-exec --without works" { run_dh_exec_with_input .install </dev/null) PATH=${BINDIR}:${PATH} \ dpkg-buildpackage -us -uc -b -d ${arch} 2>/dev/null debian/rules clean rm -f dh-exec run dpkg-deb -c ../pkg-test_0_all.deb expect_output "./usr/bin/bin-foo" run dpkg-deb -c ../pkg-test_0_all.deb expect_output "./usr/bin/bin-arch" run dpkg-deb -c ../pkg-test_0_all.deb expect_output "./usr/lib/pkg-test/${DEB_HOST_MULTIARCH}/plugin-multiarch" run dpkg-deb -c ../pkg-test_0_all.deb expect_output "./usr/lib/pkg-test/${DEB_HOST_MULTIARCH}/another-plugin\$" run dpkg-deb -c ../pkg-test-illiterate_0_all.deb expect_output "./usr/bin/bin-foo" run dpkg-deb -c ../pkg-test-illiterate_0_all.deb expect_output "./usr/bin/bin-arch" run dpkg-deb -c ../pkg-test-illiterate_0_all.deb expect_output "./usr/lib/pkg-test/${DEB_HOST_MULTIARCH}/plugin-multiarch" run dpkg-deb -c ../pkg-test-illiterate_0_all.deb expect_output "./usr/lib/pkg-test/${DEB_HOST_MULTIARCH}/another-plugin\$" } setup () { td=$(mktemp -d --tmpdir=$(pwd) tmpXXXXXX) tar -C ${SRCDIR} -c pkg-test | tar -C ${td} -x chmod -R ugo+rX,u+w ${td} cd ${td}/pkg-test unset MAKEFLAGS MFLAGS } teardown () { cd ../.. rm -rf ${td} } @test "dh: running on the native architecture" { run_dh_exec_dh_tests } @test "dh: linux-powerpc cross-build" { run_dh_exec_dh_tests linux-powerpc } @test "dh: kfreebsd-i386 cross-build" { run_dh_exec_dh_tests kfreebsd-i386 } dh-exec-0.12/t/test_illiterate.bats0000755000000000000000000000325212235150507014157 0ustar ## -*- shell-script -*- load "test.lib" run_dh_exec_illiterate () { run_dh_exec_with_input < /usr/share/foo/new-name" } @test "illiterate: normal file copy is recognised" { run_dh_exec_illiterate expect_output "src/this-file /usr/lib/foo/\${DEB_HOST_MULTIARCH}/" } dh-exec-0.12/t/test_dh_exec.bats0000755000000000000000000000524412235166352013430 0ustar ## -*- shell-script -*- load "test.lib" setup () { test_tmpdir=$(mktemp -d --tmpdir=.) } teardown () { rm -rf "${test_tmpdir}" } @test "calling dh-exec --help works" { run_dh_exec src/dh-exec --help expect_output "Scripts to help with executable debhelper files" } @test "calling dh-exec --version works" { run_dh_exec src/dh-exec --version expect_output "This is free software" } @test "dh-exec --no-act works" { run_dh_exec src/dh-exec --no-act random.install expect_output \ "^[^\|]*/dh-exec-subst | [^\|]*/dh-exec-install |" \ "[^\|]*/dh-exec-strip \[input: {0, random.install}," \ "output: {0, NULL}\]\$" } @test "dh-exec --list works" { run_dh_exec src/dh-exec --list expect_output " illiterate-tangle" } @test "dh-exec --list skips dh-exec-strip" { run_dh_exec src/dh-exec --list ! expect_output "strip" } @test "dh-exec: calling with invalid DH_EXEC_LIBDIR fails gracefully" { DH_EXEC_LIBDIR=$(pwd)/non-existent run_dh_exec src/dh-exec --list ! expect_error "subst:" expect_error "scandir(.*): No such file or directory" } @test "dh-exec: calling with invalid DH_EXEC_SCRIPTDIR fails gracefully" { DH_EXEC_SCRIPTDIR=$(pwd)/non-existent run_dh_exec src/dh-exec --list expect_error "subst.*:" ! expect_error "install.*:" expect_error "scandir(.*): No such file or directory" } @test "dh-exec: An invalid option produces an error" { run_dh_exec src/dh-exec --invalid-option expect_error "unrecognized option '--invalid-option'" } @test "dh-exec: Non-executable scripts produce an error" { touch "${test_tmpdir}/dh-exec-subst-foo" DH_EXEC_SCRIPTDIR="${test_tmpdir}" run_dh_exec src/dh-exec --with-scripts=subst-foo expect_error "script 'subst-foo' is not valid" } @test "dh-exec: Non-existing scripts produce an error" { run_dh_exec src/dh-exec --with-scripts=subst-something-else expect_error "script 'subst-something-else' is not valid" } @test "dh-exec: non-existing helper produces an error" { run_dh_exec src/dh-exec --with=something expect_error "can't execute .*/dh-exec-something" } @test "dh-exec: running bare works" { unset DH_EXEC_SCRIPTDIR unset DH_EXEC_LIBDIR run_dh_exec src/dh-exec --list expect_anything "dh-exec - Available sub-commands and scripts" } @test "dh-exec-subst: Running with an empty scriptdir fails" { DH_EXEC_SCRIPTDIR=$(pwd)/non-existent run_dh_exec src/dh-exec-subst < /var/lib/dh-exec/test-output foo/bar /tmp/foo baz/quux # This is an empty line: EOF expect_output "debian/tmp/dh-exec\." } @test "install: trailing whitespace gets correctly stripped" { run_dh_exec_with_input .install < /var/lib/dh-exec/test-output-2 EOF expect_output "debian/tmp/dh-exec\..*/var/lib/dh-exec/test-output-2 /var/lib/dh-exec/$" } @test "install: calling with an unqualified debian/install works" { run_dh_exec src/dh-exec-install debian/install expect_error "No such file or directory" } @test "install: calling with an unqualified install works" { run_dh_exec src/dh-exec-install install expect_error "No such file or directory" } @test "install: using an invalid filename fails, even if the file exists" { run_dh_exec_with_input .invalid < /var/lib/dh-exec/test-output-2 EOF expect_output "=>" } dh-exec-0.12/t/pkg-test/0000755000000000000000000000000012235261524011642 5ustar dh-exec-0.12/t/pkg-test/data/0000755000000000000000000000000012026641012012543 5ustar dh-exec-0.12/t/pkg-test/data/bin-foo0000755000000000000000000000002412026641012014016 0ustar #! /bin/sh echo foo dh-exec-0.12/t/pkg-test/data/bin-arch0000755000000000000000000000002012026641012014144 0ustar #! /bin/sh arch dh-exec-0.12/t/pkg-test/data/plugin-multiarch0000644000000000000000000000006712026641012015755 0ustar # This is a file to be installed on a multi-arch path. dh-exec-0.12/t/pkg-test/GNUMakefile0000644000000000000000000000002512026641012013641 0ustar all install clean: ; dh-exec-0.12/t/pkg-test/debian/0000755000000000000000000000000012236132554013065 5ustar dh-exec-0.12/t/pkg-test/debian/pkg-test.install0000755000000000000000000000032312076466666016234 0ustar #! /usr/bin/env dh-exec data/bin-arch /usr/bin data/bin-foo /usr/bin data/plugin-multiarch /usr/lib/pkg-test/${DEB_HOST_MULTIARCH} data/plugin-multiarch => /usr/lib/pkg-test/${DEB_HOST_MULTIARCH}/another-plugin dh-exec-0.12/t/pkg-test/debian/copyright0000644000000000000000000000221412026641012015006 0ustar Format: http://anonscm.debian.org/viewvc/dep/web/deps/dep5.mdwn?revision=174&view=co&pathrev=174 Upstream-Name: pkg-test Upstream-Contact: Gergely Nagy Source: This is part of dh-exec. Duh. Copyright: Copyright (C) 2011 Gergely Nagy License: GPL-3+ Files: * Copyright: Copyright (C) 2011 Gergely Nagy License: GPL-3+ License: GPL-3+ This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. . This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. . You should have received a copy of the GNU General Public License along with this program. If not, see . . On Debian systems, the complete text of the GNU General Public License can be found in the file `/usr/share/common-licenses/GPL-3'. dh-exec-0.12/t/pkg-test/debian/source/0000755000000000000000000000000012026641012014354 5ustar dh-exec-0.12/t/pkg-test/debian/source/format0000644000000000000000000000001512026641012015563 0ustar 3.0 (native) dh-exec-0.12/t/pkg-test/debian/compat0000644000000000000000000000000212026641012014252 0ustar 9 dh-exec-0.12/t/pkg-test/debian/pkg-test-illiterate.dirs0000755000000000000000000000043712076467065017663 0ustar #! ./dh-exec --with=illiterate,subst Dear $DEITY, who art in heaven, please hear our prayer, and create the 'usr/bin' and 'usr/lib/pkg-test/${DEB_HOST_MULTIARCH}' directories, where ${DEB_HOST_MULTIARCH} shall be queried from dpkg-architecture, and the return value substituted. Amen. dh-exec-0.12/t/pkg-test/debian/control0000644000000000000000000000142512026641012014461 0ustar Source: pkg-test Section: devel Priority: extra Maintainer: Gergely Nagy Build-Depends: debhelper (>= 8.9.13~), dh-exec Standards-Version: 3.9.2 Package: pkg-test Architecture: all Description: A test package, for dh-exec testing. This package has no use at all, does nothing, contains random files, and the single purpose of its existence is to test the behaviour of dh-exec. Package: pkg-test-illiterate Architecture: all Description: A test package, for dh-exec testing (illiterate) This package has no use at all, does nothing, contains random files, and the single purpose of its existence is to test the behaviour of dh-exec-illiterate. . The illiterate tool is a solution to allow one to write debhelper config files in a literate manner. dh-exec-0.12/t/pkg-test/debian/rules0000755000000000000000000000003712026641012014134 0ustar #! /usr/bin/make -f %: dh $@ dh-exec-0.12/t/pkg-test/debian/pkg-test-illiterate.install0000755000000000000000000000236412076466271020367 0ustar #! dh-exec --with=illiterate,subst,install Ladies and gentlemen! I present you, the first - and hopefully only - debhelper config file written in a literate manner. there is no code examples here, as we have no code to run at all. We just want to install a few files from here and there. For example, we want to install everyting from `data/bin-*' to `/usr/bin/' - so lets just do that, ok? But alas, that's not enough. We need more stuff in the package, because it's modern, multi-archified and all that buzz. Unfortunately, upstream is, well.. not the top of his game, if you get the drift. He can't write Makefiles. Therefore, we need to install the `data/plugin-multiarch' plugin, which is essential for our program, to a multi-archified private library directory, `/usr/lib/pkg-test/${DEB_HOST_MULTIARCH}/'. And while I could prepare another plugin to test whether renaming works, I'm way too lazy - so apologies, but this example will install the same `data/plugin-multiarch' to `/usr/lib/pkg-test/${DEB_HOST_MULTIARCH}/another-plugin'. Such is life. And this pretty much marks the end of the literate script, there is nothing left to do. We can write all kinds of clever stuff here, but none of that matters now. It's the end of the world as we know it. dh-exec-0.12/t/pkg-test/debian/changelog0000644000000000000000000000021412026641012014723 0ustar pkg-test (0) none; urgency=low * Initial non-release. -- Gergely Nagy Tue, 13 Dec 2011 15:25:58 +0100 dh-exec-0.12/t/pkg-test/debian/pkg-test.dirs0000755000000000000000000000010712076466647015526 0ustar #! /usr/bin/env dh-exec usr/bin usr/lib/pkg-test/${DEB_HOST_MULTIARCH} dh-exec-0.12/t/test_install_copy.bats0000755000000000000000000000201512235150507014515 0ustar ## -*- shell-script -*- load "test.lib" setup () { td=$(mktemp -d --tmpdir=.) cd "${td}" nullfile=$(mktemp --tmpdir=.) touch ${nullfile} } teardown () { cd .. rm -rf "${td}" } @test "install: copying works" { run_dh_exec_with_input .install < /var/lib/dh-exec/test-output EOF expect_file "/var/lib/dh-exec/test-output" } @test "install: copying from debian/tmp works" { install -d debian/tmp touch debian/tmp/foo.test run_dh_exec_with_input .install < /var/lib/dh-exec/test-output.foo EOF expect_file "/var/lib/dh-exec/test-output.foo" } @test "install: renaming preserves permissions" { chmod +x "${nullfile}" run_dh_exec_with_input .install < /var/lib/dh-exec/test-executable EOF expect_file -x "/var/lib/dh-exec/test-executable" } dh-exec-0.12/t/bats/0000755000000000000000000000000012235075732011041 5ustar dh-exec-0.12/t/bats/bin/0000755000000000000000000000000012235071651011605 5ustar dh-exec-0.12/t/bats/bin/bats0000777000000000000000000000000012235071651015160 2../libexec/batsustar dh-exec-0.12/t/bats/test/0000755000000000000000000000000012235071651012014 5ustar dh-exec-0.12/t/bats/test/fixtures/0000755000000000000000000000000012235071651013665 5ustar dh-exec-0.12/t/bats/test/fixtures/bats/0000755000000000000000000000000012235071651014616 5ustar dh-exec-0.12/t/bats/test/fixtures/bats/intact.bats0000644000000000000000000000013512235071651016752 0ustar @test "dash-e on beginning of line" { run cat - <> "$LOG" } @test "one" { true } @test "two" { false } @test "three" { true } dh-exec-0.12/t/bats/test/fixtures/bats/setup.bats0000644000000000000000000000036712235071651016637 0ustar LOG="$TMP/setup.log" setup() { echo "$BATS_TEST_NAME" >> "$LOG" } @test "one" { [ "$(tail -n 1 "$LOG")" = "test_one" ] } @test "two" { [ "$(tail -n 1 "$LOG")" = "test_two" ] } @test "three" { [ "$(tail -n 1 "$LOG")" = "test_three" ] } dh-exec-0.12/t/bats/test/fixtures/bats/dos_line.bats0000644000000000000000000000004312235071651017262 0ustar @test "foo" { echo "foo" } dh-exec-0.12/t/bats/test/fixtures/bats/load.bats0000644000000000000000000000016612235071651016413 0ustar [ -n "$HELPER_NAME" ] || HELPER_NAME="test_helper" load "$HELPER_NAME" @test "calling a loaded helper" { help_me } dh-exec-0.12/t/bats/test/fixtures/bats/output.bats0000644000000000000000000000051312235071651017030 0ustar @test "success writing to stdout" { echo "success stdout 1" echo "success stdout 2" } @test "success writing to stderr" { echo "success stderr" >&2 } @test "failure writing to stdout" { echo "failure stdout 1" echo "failure stdout 2" false } @test "failure writing to stderr" { echo "failure stderr" >&2 false } dh-exec-0.12/t/bats/test/fixtures/bats/empty.bats0000644000000000000000000000000012235071651016615 0ustar dh-exec-0.12/t/bats/test/fixtures/bats/passing.bats0000644000000000000000000000004212235071651017131 0ustar @test "a passing test" { true } dh-exec-0.12/t/bats/test/fixtures/bats/skipped.bats0000644000000000000000000000013612235071651017130 0ustar @test "a skipped test" { skip } @test "a skipped test with a reason" { skip "a reason" } dh-exec-0.12/t/bats/test/fixtures/bats/test_helper.bash0000644000000000000000000000006312235071651017772 0ustar help_me() { true } failing_helper() { false } dh-exec-0.12/t/bats/test/fixtures/bats/invalid_tap.bats0000644000000000000000000000011712235071651017762 0ustar echo "This isn't TAP!" echo "Good day to you" exit 1 @test "truth" { true } dh-exec-0.12/t/bats/test/fixtures/suite/0000755000000000000000000000000012235071651015016 5ustar dh-exec-0.12/t/bats/test/fixtures/suite/single/0000755000000000000000000000000012235071651016277 5ustar dh-exec-0.12/t/bats/test/fixtures/suite/single/test.bats0000644000000000000000000000004212235071651020125 0ustar @test "a passing test" { true } dh-exec-0.12/t/bats/test/fixtures/suite/multiple/0000755000000000000000000000000012235071651016651 5ustar dh-exec-0.12/t/bats/test/fixtures/suite/multiple/b.bats0000644000000000000000000000011112235071651017736 0ustar @test "more truth" { true } @test "quasi-truth" { [ -z "$FLUNK" ] } dh-exec-0.12/t/bats/test/fixtures/suite/multiple/a.bats0000644000000000000000000000003112235071651017736 0ustar @test "truth" { true } dh-exec-0.12/t/bats/test/fixtures/suite/empty/0000755000000000000000000000000012235071651016154 5ustar dh-exec-0.12/t/bats/test/fixtures/suite/empty/.gitkeep0000644000000000000000000000000012235071651017573 0ustar dh-exec-0.12/t/bats/test/suite.bats0000755000000000000000000000330712235071651014026 0ustar #!/usr/bin/env bats load test_helper fixtures suite @test "running a suite with no test files" { run bats "$FIXTURE_ROOT/empty" [ $status -eq 0 ] [ $output = "1..0" ] } @test "running a suite with one test file" { run bats "$FIXTURE_ROOT/single" [ $status -eq 0 ] [ ${lines[0]} = "1..1" ] [ ${lines[1]} = "ok 1 a passing test" ] } @test "counting tests in a suite" { run bats -c "$FIXTURE_ROOT/single" [ $status -eq 0 ] [ $output -eq 1 ] run bats -c "$FIXTURE_ROOT/multiple" [ $status -eq 0 ] [ $output -eq 3 ] } @test "aggregated output of multiple tests in a suite" { run bats "$FIXTURE_ROOT/multiple" [ $status -eq 0 ] [ ${lines[0]} = "1..3" ] echo "$output" | grep "^ok . truth" echo "$output" | grep "^ok . more truth" echo "$output" | grep "^ok . quasi-truth" } @test "a failing test in a suite results in an error exit code" { FLUNK=1 run bats "$FIXTURE_ROOT/multiple" [ $status -eq 1 ] [ ${lines[0]} = "1..3" ] echo "$output" | grep "^not ok . quasi-truth" } @test "running an ad-hoc suite by specifying multiple test files" { run bats "$FIXTURE_ROOT/multiple/a.bats" "$FIXTURE_ROOT/multiple/b.bats" [ $status -eq 0 ] [ ${lines[0]} = "1..3" ] echo "$output" | grep "^ok . truth" echo "$output" | grep "^ok . more truth" echo "$output" | grep "^ok . quasi-truth" } @test "extended syntax in suite" { FLUNK=1 run bats-exec-suite -x "$FIXTURE_ROOT/multiple/"*.bats [ $status -eq 1 ] [ "${lines[0]}" = "1..3" ] [ "${lines[1]}" = "begin 1 truth" ] [ "${lines[2]}" = "ok 1 truth" ] [ "${lines[3]}" = "begin 2 more truth" ] [ "${lines[4]}" = "ok 2 more truth" ] [ "${lines[5]}" = "begin 3 quasi-truth" ] [ "${lines[6]}" = "not ok 3 quasi-truth" ] } dh-exec-0.12/t/bats/test/tmp/0000755000000000000000000000000012235071651012614 5ustar dh-exec-0.12/t/bats/test/bats.bats0000755000000000000000000001055612235071651013632 0ustar #!/usr/bin/env bats load test_helper fixtures bats @test "no arguments prints usage instructions" { run bats [ $status -eq 1 ] [ $(expr "${lines[1]}" : "Usage:") -ne 0 ] } @test "-v and --version print version number" { run bats -v [ $status -eq 0 ] [ $(expr "$output" : "Bats [0-9][0-9.]*") -ne 0 ] } @test "-h and --help print help" { run bats -h [ $status -eq 0 ] [ "${#lines[@]}" -gt 3 ] } @test "invalid filename prints an error" { run bats nonexistent [ $status -eq 1 ] [ $(expr "$output" : ".*does not exist") -ne 0 ] } @test "empty test file runs zero tests" { run bats "$FIXTURE_ROOT/empty.bats" [ $status -eq 0 ] [ $output = "1..0" ] } @test "one passing test" { run bats "$FIXTURE_ROOT/passing.bats" [ $status -eq 0 ] [ ${lines[0]} = "1..1" ] [ ${lines[1]} = "ok 1 a passing test" ] } @test "one failing test" { run bats "$FIXTURE_ROOT/failing.bats" [ $status -eq 1 ] [ ${lines[0]} = "1..1" ] [ ${lines[1]} = "not ok 1 a failing test" ] [ ${lines[2]} = "# (in test file $FIXTURE_ROOT/failing.bats, line 4)" ] } @test "one failing and one passing test" { run bats "$FIXTURE_ROOT/failing_and_passing.bats" [ $status -eq 1 ] [ ${lines[0]} = "1..2" ] [ ${lines[1]} = "not ok 1 a failing test" ] [ ${lines[2]} = "# (in test file $FIXTURE_ROOT/failing_and_passing.bats, line 2)" ] [ ${lines[3]} = "ok 2 a passing test" ] } @test "test environments are isolated" { run bats "$FIXTURE_ROOT/environment.bats" [ $status -eq 0 ] } @test "setup is run once before each test" { rm -f "$TMP/setup.log" run bats "$FIXTURE_ROOT/setup.bats" [ $status -eq 0 ] run cat "$TMP/setup.log" [ ${#lines[@]} -eq 3 ] } @test "teardown is run once after each test, even if it fails" { rm -f "$TMP/teardown.log" run bats "$FIXTURE_ROOT/teardown.bats" [ $status -eq 1 ] run cat "$TMP/teardown.log" [ ${#lines[@]} -eq 3 ] } @test "load sources scripts relative to the current test file" { run bats "$FIXTURE_ROOT/load.bats" [ $status -eq 0 ] } @test "load aborts if the specified script does not exist" { HELPER_NAME="nonexistent" run bats "$FIXTURE_ROOT/load.bats" [ $status -eq 1 ] } @test "output is discarded for passing tests and printed for failing tests" { run bats "$FIXTURE_ROOT/output.bats" [ $status -eq 1 ] [ "${lines[5]}" = "# failure stdout 1" ] [ "${lines[6]}" = "# failure stdout 2" ] [ "${lines[9]}" = "# failure stderr" ] } @test "-c prints the number of tests" { run bats -c "$FIXTURE_ROOT/empty.bats" [ $status -eq 0 ] [ "$output" = "0" ] run bats -c "$FIXTURE_ROOT/output.bats" [ $status -eq 0 ] [ "$output" = "4" ] } @test "dash-e is not mangled on beginning of line" { run bats "$FIXTURE_ROOT/intact.bats" [ $status -eq 0 ] [ "${lines[1]}" = "ok 1 dash-e on beginning of line" ] } @test "dos line endings are stripped before testing" { run bats "$FIXTURE_ROOT/dos_line.bats" [ $status -eq 0 ] } @test "test file without trailing newline" { run bats "$FIXTURE_ROOT/without_trailing_newline.bats" [ $status -eq 0 ] [ "${lines[1]}" = "ok 1 truth" ] } @test "skipped tests" { run bats "$FIXTURE_ROOT/skipped.bats" [ $status -eq 0 ] [ "${lines[1]}" = "ok 1 # skip a skipped test" ] [ "${lines[2]}" = "ok 2 # skip (a reason) a skipped test with a reason" ] } @test "extended syntax" { run bats-exec-test -x "$FIXTURE_ROOT/failing_and_passing.bats" [ $status -eq 1 ] [ "${lines[1]}" = "begin 1 a failing test" ] [ "${lines[2]}" = "not ok 1 a failing test" ] [ "${lines[4]}" = "begin 2 a passing test" ] [ "${lines[5]}" = "ok 2 a passing test" ] } @test "pretty and tap formats" { run bats --tap "$FIXTURE_ROOT/passing.bats" tap_output="$output" [ $status -eq 0 ] run bats --pretty "$FIXTURE_ROOT/passing.bats" pretty_output="$output" [ $status -eq 0 ] [ "$tap_output" != "$pretty_output" ] } @test "pretty formatter bails on invalid tap" { run bats --tap "$FIXTURE_ROOT/invalid_tap.bats" [ $status -eq 1 ] [ "${lines[0]}" = "This isn't TAP!" ] [ "${lines[1]}" = "Good day to you" ] } @test "failing helper function logs the test case's line number" { run bats "$FIXTURE_ROOT/failing_helper.bats" [ $status -eq 1 ] [ "${lines[1]}" = "not ok 1 failing helper function" ] [ "${lines[2]}" = "# (from function \`failing_helper' in file $FIXTURE_ROOT/test_helper.bash, line 6," ] [ "${lines[3]}" = "# in test file $FIXTURE_ROOT/failing_helper.bats, line 5)" ] } dh-exec-0.12/t/bats/test/test_helper.bash0000644000000000000000000000022312235071651015166 0ustar fixtures() { FIXTURE_ROOT="$BATS_TEST_DIRNAME/fixtures/$1" } setup() { export TMP="$BATS_TEST_DIRNAME/tmp" } teardown() { rm -f "$TMP"/* } dh-exec-0.12/t/bats/LICENSE0000644000000000000000000000204212235071651012040 0ustar Copyright (c) 2013 Sam Stephenson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. dh-exec-0.12/t/bats/install.sh0000755000000000000000000000114112235071651013037 0ustar #!/usr/bin/env bash set -e resolve_link() { $(type -p greadlink readlink | head -1) "$1" } abs_dirname() { local cwd="$(pwd)" local path="$1" while [ -n "$path" ]; do cd "${path%/*}" local name="${path##*/}" path="$(resolve_link "$name" || true)" done pwd cd "$cwd" } PREFIX="$1" if [ -z "$1" ]; then { echo "usage: $0 " echo " e.g. $0 /usr/local" } >&2 exit 1 fi BATS_ROOT="$(abs_dirname "$0")" mkdir -p "$PREFIX"/{bin,libexec} cp -R "$BATS_ROOT"/bin/* "$PREFIX"/bin cp -R "$BATS_ROOT"/libexec/* "$PREFIX"/libexec echo "Installed Bats to $PREFIX/bin/bats" dh-exec-0.12/t/bats/.travis.yml0000644000000000000000000000012612235071651013145 0ustar language: c script: bin/bats --tap test notifications: email: on_success: never dh-exec-0.12/t/bats/README.md0000644000000000000000000002144312235071651012320 0ustar # Bats: Bash Automated Testing System Bats is a [TAP](http://testanything.org/)-compliant testing framework for Bash. It provides a simple way to verify that the UNIX programs you write behave as expected. A Bats test file is a Bash script with special syntax for defining test cases. Under the hood, each test case is just a function with a description. ```bash #!/usr/bin/env bats @test "addition using bc" { result="$(echo 2+2 | bc)" [ "$result" -eq 4 ] } @test "addition using dc" { result="$(echo 2 2+p | dc)" [ "$result" -eq 4 ] } ``` Bats is most useful when testing software written in Bash, but you can use it to test any UNIX program. Test cases consist of standard shell commands. Bats makes use of Bash's `errexit` (`set -e`) option when running test cases. If every command in the test case exits with a `0` status code (success), the test passes. In this way, each line is an assertion of truth. ## Running tests To run your tests, invoke the `bats` interpreter with a path to a test file. The file's test cases are run sequentially and in isolation. If all the test cases pass, `bats` exits with a `0` status code. If there are any failures, `bats` exits with a `1` status code. When you run Bats from a terminal, you'll see output as each test is performed, with a check-mark next to the test's name if it passes or an "X" if it fails. $ bats addition.bats ✓ addition using bc ✓ addition using dc 2 tests, 0 failures If Bats is not connected to a terminal—in other words, if you run it from a continuous integration system or redirect its output to a file—the results are displayed in human-readable, machine-parsable [TAP format](http://testanything.org/wiki/index.php/TAP_specification#THE_TAP_FORMAT). You can force TAP output from a terminal by invoking Bats with the `--tap` option. $ bats --tap addition.bats 1..2 ok 1 addition using bc ok 2 addition using dc ### Test suites You can invoke the `bats` interpreter with multiple test file arguments, or with a path to a directory containing multiple `.bats` files. Bats will run each test file individually and aggregate the results. If any test case fails, `bats` exits with a `1` status code. ## Writing tests Each Bats test file is evaulated n+1 times, where _n_ is the number of test cases in the file. The first run counts the number of test cases, then iterates over the test cases and executes each one in its own process. For details about exactly how Bats evaluates test files, see [Bats Evaluation Process](https://github.com/sstephenson/bats/wiki/Bats-Evaluation-Process) on the wiki. ### The _run_ helper Many Bats tests need to run a command and then make assertions about its exit status and output. Bats includes a `run` helper that invokes its arguments as a command, saves the exit status and output into special global variables, and then returns with a `0` status code so you can continue to make assertions in your test case. For example, let's say you're testing that the `foo` command, when passed a nonexistent filename, exits with a `1` status code and prints an error message. ```bash @test "invoking foo with a nonexistent file prints an error" { run foo nonexistent_filename [ "$status" -eq 1 ] [ "$output" = "foo: no such file 'nonexistent_filename'" ] } ``` The `$status` variable contains the status code of the command, and the `$output` variable contains the combined contents of the command's standard output and standard error streams. A third special variable, the `$lines` array, is available for easily accessing individual lines of output. For example, if you want to test that invoking `foo` without any arguments prints usage information on the first line: ```bash @test "invoking foo without arguments prints usage" { run foo [ "$status" -eq 1 ] [ "${lines[0]}" = "usage: foo " ] } ``` ### The _load_ command You may want to share common code across multiple test files. Bats includes a convenient `load` command for sourcing a Bash source file relative to the location of the current test file. For example, if you have a Bats test in `test/foo.bats`, the command ```bash load test_helper ``` will source the script `test/test_helper.bash` in your test file. This can be useful for sharing functions to set up your environment or load fixtures. ### The _skip_ command Tests can be skipped by using the `skip` command at the point in a test you wish to skip. ```bash @test "A test I don't want to execute for now" { skip run foo [ "$status" -eq 0 ] } ``` Optionally, you may include a reason for skipping: ```bash @test "A test I don't want to execute for now" { skip "This command will return zero soon, but not now" run foo [ "$status" -eq 0 ] } ``` Or you can skip conditionally: ```bash @test "A test which should run" { if [ foo != bar ]; then skip "foo isn't bar" fi run foo [ "$status" -eq 0 ] } ``` ### Setup and teardown functions You can define special `setup` and `teardown` functions which run before and after each test case, respectively. Use these to load fixtures, set up your environment, and clean up when you're done. ### Code outside of test cases You can include code in your test file outside of `@test` functions. For example, this may be useful if you want to check for dependencies and fail immediately if they're not present. However, any output that you print in code outside of `@test`, `setup` or `teardown` functions must be redirected to `stderr` (`>&2`). Otherwise, the output may cause Bats to fail by polluting the TAP stream on `stdout`. ### Special variables There are several global variables you can use to introspect on Bats tests: * `$BATS_TEST_FILENAME` is the fully expanded path to the Bats test file. * `$BATS_TEST_DIRNAME` is the directory in which the Bats test file is located. * `$BATS_TEST_NAMES` is an array of function names for each test case. * `$BATS_TEST_NAME` is the name of the function containing the current test case. * `$BATS_TEST_DESCRIPTION` is the description of the current test case. * `$BATS_TEST_NUMBER` is the (1-based) index of the current test case in the test file. * `$BATS_TMPDIR` is the location to a directory that may be used to store temporary files. ## Installing Bats from source Check out a copy of the Bats repository. Then, either add the Bats `bin` directory to your `$PATH`, or run the provided `install.sh` command with the location to the prefix in which you want to install Bats. For example, to install Bats into `/usr/local`, $ git clone https://github.com/sstephenson/bats.git $ cd bats $ ./install.sh /usr/local Note that you may need to run `install.sh` with `sudo` if you do not have permission to write to the installation prefix. ## Support The Bats source code repository is [hosted on GitHub](https://github.com/sstephenson/bats). There you can file bugs on the issue tracker or submit tested pull requests for review. For real-world examples from open-source projects using Bats, see [Projects Using Bats](https://github.com/sstephenson/bats/wiki/Projects-Using-Bats) on the wiki. To learn how to set up your editor for Bats syntax highlighting, see [Syntax Highlighting](https://github.com/sstephenson/bats/wiki/Syntax-Highlighting) on the wiki. ### Version history *0.3.1* (October 28, 2013) * Fixed an incompatibility with the pretty formatter in certain environments such as tmux. * Fixed a bug where the pretty formatter would crash if the first line of a test file's output was invalid TAP. *0.3.0* (October 21, 2013) * Improved formatting for tests run from a terminal. Failing tests are now colored in red, and the total number of failing tests is displayed at the end of the test run. When Bats is not connected to a terminal (e.g. in CI runs), or when invoked with the `--tap` flag, output is displayed in standard TAP format. * Added the ability to skip tests using the `skip` command. * Added a message to failing test case output indicating the file and line number of the statement that caused the test to fail. * Added "ad-hoc" test suite support. You can now invoke `bats` with multiple filename or directory arguments to run all the specified tests in aggregate. * Added support for test files with Windows line endings. * Fixed regular expression warnings from certain versions of Bash. * Fixed a bug running tests containing lines that begin with `-e`. *0.2.0* (November 16, 2012) * Added test suite support. The `bats` command accepts a directory name containing multiple test files to be run in aggregate. * Added the ability to count the number of test cases in a file or suite by passing the `-c` flag to `bats`. * Preprocessed sources are cached between test case runs in the same file for better performance. *0.1.0* (December 30, 2011) * Initial public release. --- © 2013 Sam Stephenson. Bats is released under an MIT-style license; see `LICENSE` for details. dh-exec-0.12/t/bats/libexec/0000755000000000000000000000000012235071651012450 5ustar dh-exec-0.12/t/bats/libexec/bats-format-tap-stream0000755000000000000000000000505012235071651016670 0ustar #!/usr/bin/env bash set -e # Just stream the TAP output (sans extended syntax) if tput is missing command -v tput >/dev/null || exec grep -v "^begin " header_pattern='[0-9]+\.\.[0-9]+' IFS= read -r header if [[ "$header" =~ $header_pattern ]]; then count="${header:3}" index=0 failures=0 name="" count_column_width=$(( ${#count} * 2 + 2 )) else # If the first line isn't a TAP plan, print it and pass the rest through printf "%s\n" "$header" exec cat fi update_screen_width() { screen_width="$(tput cols)" count_column_left=$(( $screen_width - $count_column_width )) } trap update_screen_width WINCH update_screen_width begin() { go_to_column 0 printf_with_truncation $(( $count_column_left - 1 )) " %s" "$name" clear_to_end_of_line go_to_column $count_column_left printf "%${#count}s/${count}" "$index" go_to_column 1 } pass() { go_to_column 0 printf " ✓ %s" "$name" advance } skip() { local reason="$1" [ -z "$reason" ] || reason=": $reason" go_to_column 0 printf " - %s (skipped%s)" "$name" "$reason" advance } fail() { go_to_column 0 set_color 1 bold printf " ✗ %s" "$name" advance } log() { set_color 1 printf " %s\n" "$1" clear_color } summary() { printf "\n%d test%s, %d failure%s\n" \ "$count" "$(plural "$count")" \ "$failures" "$(plural "$failures")" } printf_with_truncation() { local width="$1" shift local string="$(printf "$@")" if [ "${#string}" -gt "$width" ]; then printf "%s..." "${string:0:$(( $width - 4 ))}" else printf "%s" "$string" fi } go_to_column() { local column="$1" printf "\x1B[%dG" $(( $column + 1 )) } clear_to_end_of_line() { printf "\x1B[K" } advance() { clear_to_end_of_line echo clear_color } set_color() { local color="$1" local weight="$2" printf "\x1B[%d;%dm" $(( 30 + $color )) "$( [ "$weight" = "bold" ] && echo 1 || echo 22 )" } clear_color() { printf "\x1B[0m" } plural() { [ "$1" -eq 1 ] || echo "s" } _buffer="" buffer() { _buffer="${_buffer}$("$@")" } flush() { printf "%s" "$_buffer" _buffer="" } finish() { flush printf "\n" } trap finish EXIT while IFS= read -r line; do case "$line" in "begin "* ) let index+=1 name="${line#* $index }" buffer begin flush ;; "ok "* ) skip_expr="ok $index # skip (\(([^)]*)\))?" if [[ "$line" =~ $skip_expr ]]; then buffer skip "${BASH_REMATCH[2]}" else buffer pass fi ;; "not ok "* ) let failures+=1 buffer fail ;; "# "* ) buffer log "${line:2}" ;; esac done buffer summary dh-exec-0.12/t/bats/libexec/bats-exec-suite0000755000000000000000000000175112235071651015404 0ustar #!/usr/bin/env bash set -e count_only_flag="" if [ "$1" = "-c" ]; then count_only_flag=1 shift fi extended_syntax_flag="" if [ "$1" = "-x" ]; then extended_syntax_flag="-x" shift fi trap "kill 0; exit 1" int count=0 for filename in "$@"; do let count+="$(bats-exec-test -c "$filename")" done if [ -n "$count_only_flag" ]; then echo "$count" exit fi echo "1..$count" status=0 offset=0 for filename in "$@"; do index=0 { IFS= read -r # 1..n while IFS= read -r line; do case "$line" in "begin "* ) let index+=1 echo "${line/ $index / $(($offset + $index)) }" ;; "ok "* | "not ok "* ) [ -n "$extended_syntax_flag" ] || let index+=1 echo "${line/ $index / $(($offset + $index)) }" [ "${line:0:6}" != "not ok" ] || status=1 ;; * ) echo "$line" ;; esac done } < <( bats-exec-test $extended_syntax_flag "$filename" ) offset=$(($offset + $index)) done exit "$status" dh-exec-0.12/t/bats/libexec/bats-preprocess0000755000000000000000000000204012235071651015506 0ustar #!/usr/bin/env bash set -e encode_name() { local name="$1" local result="test_" if [[ ! "$name" =~ [^[:alnum:]\ _-] ]]; then name="${name//_/-5f}" name="${name//-/-2d}" name="${name// /_}" result+="$name" else local length="${#name}" local char i for ((i=0; i" >&2 exit 1 elif [ ! -f "$BATS_TEST_FILENAME" ]; then echo "bats: $BATS_TEST_FILENAME does not exist" >&2 exit 1 else shift fi BATS_TEST_DIRNAME="$(dirname "$BATS_TEST_FILENAME")" BATS_TEST_NAMES=() load() { local filename="$BATS_TEST_DIRNAME/$1.bash" [ -f "$filename" ] || { echo "bats: $filename does not exist" >&2 exit 1 } source "$BATS_TEST_DIRNAME/$1.bash" } run() { local e E T [[ ! "$-" =~ e ]] || e=1 [[ ! "$-" =~ E ]] || E=1 [[ ! "$-" =~ T ]] || T=1 set +e set +E set +T output="$("$@" 2>&1)" status="$?" IFS=$'\n' lines=($output) [ -z "$e" ] || set -e [ -z "$E" ] || set -E [ -z "$T" ] || set -T } setup() { true } teardown() { true } skip() { BATS_TEST_SKIPPED=${1:-1} BATS_TEST_COMPLETED=1 exit 0 } bats_test_begin() { BATS_TEST_DESCRIPTION="$1" if [ -n "$BATS_EXTENDED_SYNTAX" ]; then echo "begin $BATS_TEST_NUMBER $BATS_TEST_DESCRIPTION" >&3 fi setup } bats_test_function() { local test_name="$1" BATS_TEST_NAMES["${#BATS_TEST_NAMES[@]}"]="$test_name" } bats_capture_stack_trace() { if [ "$BASH_SOURCE" != "$1" ]; then BATS_STACK_TRACE=() BATS_LINE_NUMBER="$BATS_LINE_NUMBER_" BATS_LINE_NUMBER_="$2" local test_pattern=" $BATS_TEST_NAME $BATS_TEST_SOURCE" local index=0 local frame while frame="$(caller "$index")"; do BATS_STACK_TRACE[$index]="$frame" if [[ "$frame" = *"$test_pattern" ]]; then break else let index+=1 fi done fi } bats_print_stack_trace() { local index=1 local count="${#BATS_STACK_TRACE[@]}" local line for frame in "${BATS_STACK_TRACE[@]}"; do if [ $index -eq 1 ]; then line="$BATS_LINE_NUMBER" echo -n "# (" else line="$(bats_frame_line "$frame")" echo -n "# " fi if [ $index -eq $count ]; then echo "in test file $BATS_TEST_FILENAME, line $line)" else local fn="$(bats_frame_function "$frame")" local filename="$(bats_frame_filename "$frame")" echo "from function \`$fn' in file $filename, line $line," fi let index+=1 done } bats_frame_line() { local frame="$1" local line="${frame%% *}" echo "$line" } bats_frame_function() { local frame="$1" local rest="${frame#* }" local fn="${rest%% *}" echo "$fn" } bats_frame_filename() { local frame="$1" local rest="${frame#* }" local filename="${rest#* }" if [ "$filename" = "$BATS_TEST_SOURCE" ]; then echo "$BATS_TEST_FILENAME" else echo "$filename" fi } bats_error_trap() { trap - debug } bats_teardown_trap() { trap bats_exit_trap exit teardown >>"$BATS_OUT" 2>&1 bats_exit_trap } bats_exit_trap() { local status local skipped trap - err exit skipped="" if [ -n "$BATS_TEST_SKIPPED" ]; then skipped=" # skip" if [ "1" != "$BATS_TEST_SKIPPED" ]; then skipped+=" ($BATS_TEST_SKIPPED)" fi fi if [ -z "$BATS_TEST_COMPLETED" ]; then echo "not ok $BATS_TEST_NUMBER $BATS_TEST_DESCRIPTION" >&3 bats_print_stack_trace >&3 sed -e "s/^/# /" < "$BATS_OUT" >&3 status=1 else echo "ok ${BATS_TEST_NUMBER}${skipped} ${BATS_TEST_DESCRIPTION}" >&3 status=0 fi rm -f "$BATS_OUT" exit "$status" } bats_perform_tests() { echo "1..$#" test_number=1 status=0 for test_name in "$@"; do "$0" $BATS_EXTENDED_SYNTAX "$BATS_TEST_FILENAME" "$test_name" "$test_number" || status=1 let test_number+=1 done exit "$status" } bats_perform_test() { BATS_TEST_NAME="$1" if [ "$(type -t "$BATS_TEST_NAME" || true)" = "function" ]; then BATS_TEST_NUMBER="$2" if [ -z "$BATS_TEST_NUMBER" ]; then echo "1..1" BATS_TEST_NUMBER="1" fi BATS_TEST_COMPLETED="" BATS_ERROR_LINE="" trap "bats_capture_stack_trace \"\$BASH_SOURCE\" \$LINENO" debug trap "bats_error_trap" err trap "bats_teardown_trap" exit "$BATS_TEST_NAME" >>"$BATS_OUT" 2>&1 BATS_TEST_COMPLETED=1 else echo "bats: unknown test name \`$BATS_TEST_NAME'" >&2 exit 1 fi } if [ -z "$TMPDIR" ]; then BATS_TMPDIR="/tmp" else BATS_TMPDIR="${TMPDIR%/}" fi BATS_TMPNAME="$BATS_TMPDIR/bats.$$" BATS_PARENT_TMPNAME="$BATS_TMPDIR/bats.$PPID" BATS_OUT="${BATS_TMPNAME}.out" bats_preprocess_source() { BATS_TEST_SOURCE="${BATS_TMPNAME}.src" { tr -d '\r' < "$BATS_TEST_FILENAME"; echo; } | bats-preprocess > "$BATS_TEST_SOURCE" trap bats_cleanup_preprocessed_source err exit trap "bats_cleanup_preprocessed_source; exit 1" int } bats_cleanup_preprocessed_source() { rm -f "$BATS_TEST_SOURCE" } bats_evaluate_preprocessed_source() { if [ -z "$BATS_TEST_SOURCE" ]; then BATS_TEST_SOURCE="${BATS_PARENT_TMPNAME}.src" fi source "$BATS_TEST_SOURCE" } exec 3<&1 if [ "$#" -eq 0 ]; then bats_preprocess_source bats_evaluate_preprocessed_source if [ -n "$BATS_COUNT_ONLY" ]; then echo "${#BATS_TEST_NAMES[@]}" else bats_perform_tests "${BATS_TEST_NAMES[@]}" fi else bats_evaluate_preprocessed_source bats_perform_test "$@" fi dh-exec-0.12/t/bats/libexec/bats0000755000000000000000000000532312235071651013332 0ustar #!/usr/bin/env bash set -e version() { echo "Bats 0.3.1" } usage() { version echo "Usage: bats [-c] [-p | -t] [ ...]" } help() { usage echo echo " is the path to a Bats test file, or the path to a directory" echo " containing Bats test files." echo echo " -c, --count Count the number of test cases without running any tests" echo " -h, --help Display this help message" echo " -p, --pretty Show results in pretty format (default for terminals)" echo " -t, --tap Show results in TAP format" echo " -v, --version Display the version number" echo echo " For more information, see https://github.com/sstephenson/bats" echo } resolve_link() { $(type -p greadlink readlink | head -1) "$1" } abs_dirname() { local cwd="$(pwd)" local path="$1" while [ -n "$path" ]; do cd "${path%/*}" local name="${path##*/}" path="$(resolve_link "$name" || true)" done pwd cd "$cwd" } expand_path() { { cd "$(dirname "$1")" 2>/dev/null local dirname="$PWD" cd "$OLDPWD" echo "$dirname/$(basename "$1")" } || echo "$1" } BATS_LIBEXEC="$(abs_dirname "$0")" export BATS_PREFIX="$(abs_dirname "$BATS_LIBEXEC")" export PATH="$BATS_LIBEXEC:$PATH" options=() arguments=() for arg in "$@"; do if [ "${arg:0:1}" = "-" ]; then if [ "${arg:1:1}" = "-" ]; then options[${#options[*]}]="${arg:2}" else index=1 while option="${arg:$index:1}"; do [ -n "$option" ] || break options[${#options[*]}]="$option" let index+=1 done fi else arguments[${#arguments[*]}]="$arg" fi done unset count_flag pretty [ -t 0 ] && [ -t 1 ] && pretty="1" for option in "${options[@]}"; do case "$option" in "h" | "help" ) help exit 0 ;; "v" | "version" ) version exit 0 ;; "c" | "count" ) count_flag="-c" ;; "t" | "tap" ) pretty="" ;; "p" | "pretty" ) pretty="1" ;; * ) usage >&2 exit 1 ;; esac done if [ "${#arguments[@]}" -eq 0 ]; then usage >&2 exit 1 fi filenames=() for filename in "${arguments[@]}"; do if [ -d "$filename" ]; then shopt -s nullglob for suite_filename in "$(expand_path "$filename")"/*.bats; do filenames["${#filenames[@]}"]="$suite_filename" done shopt -u nullglob else filenames["${#filenames[@]}"]="$(expand_path "$filename")" fi done if [ "${#filenames[@]}" -eq 1 ]; then command="bats-exec-test" else command="bats-exec-suite" fi if [ -n "$pretty" ]; then extended_syntax_flag="-x" formatter="bats-format-tap-stream" else extended_syntax_flag="" formatter="cat" fi set -o pipefail execfail exec "$command" $count_flag $extended_syntax_flag "${filenames[@]}" | "$formatter" dh-exec-0.12/t/test.lib.bash0000644000000000000000000000227112235156610012470 0ustar ## -*- shell-script -*- cd ${srcdir} SRCDIR=$(pwd) cd - >/dev/null cd ${DH_EXEC_BINDIR} BINDIR=$(pwd) cd - >/dev/null cd ${DH_EXEC_SCRIPTDIR} SCRIPTDIR=$(pwd) cd - >/dev/null cd ${DH_EXEC_LIBDIR} LIBDIR=$(pwd) cd - >/dev/null cd ${top_builddir} top_builddir=$(pwd) cd - >/dev/null export top_builddir export DH_EXEC_BINDIR="${BINDIR}" export DH_EXEC_SCRIPTDIR="${SCRIPTDIR}" export DH_EXEC_LIBDIR="${LIBDIR}" run_dh_exec () { script=$1 shift run ${top_builddir}/${script} $@ } run_dh_exec_with_input () { t=$(mktemp --tmpdir=. tmpXXXXXXXX${1}) cat >"${t}" chmod +x "${t}" run "${t}" rm -f "${t}" } expect_anything () { echo "${output}" | grep -q "$(echo $@)" } expect_output () { [ "$status" -eq 0 ] expect_anything "$@" } expect_error () { [ "$status" -ne 0 ] expect_anything "$@" } expect_file () { if [ $# -eq 1 ]; then file=$1 check="-f" else check=$1 file=$2 fi dtmpdir=$(echo "$output" | sed -n 's#\(debian/tmp/dh-exec\.[^/]*\).*#\1#gp' | sort -u) [ $check "${dtmpdir}${file}" ] } dh-exec-0.12/t/test_subst_env.bats0000755000000000000000000000155512235150507014035 0ustar ## -*- shell-script -*- load "test.lib" setup () { dh_subst_test_empty_var="" dh_subst_test_var="foo" unset dh_subst_test_novar export dh_subst_test_var export dh_subst_test_empty_var } run_dh_exec_subst () { run_dh_exec src/dh-exec-subst < dh-exec-0.12/Makefile.am0000644000000000000000000000676412235213013011700 0ustar # --- Programs & scripts --- bin_PROGRAMS = src/dh-exec pkglibexec_PROGRAMS = src/dh-exec-subst \ src/dh-exec-install \ src/dh-exec-illiterate \ src/dh-exec-strip man1_MANS = src/dh-exec-subst.1 \ src/dh-exec-install.1 \ src/dh-exec-illiterate.1 \ src/dh-exec.1 pkgdata_SCRIPTS = lib/dh-exec-subst-env \ lib/dh-exec-subst-multiarch \ lib/dh-exec-install-rename \ lib/dh-exec-illiterate-tangle \ lib/dh-exec-strip-output # --- Sources & flags --- AM_CFLAGS = ${LIBPIPELINE_CFLAGS} AM_MAKEFLAGS = --no-print-directory LDADD = ${LIBPIPELINE_LIBS} src_dh_exec_SOURCES = \ src/dh-exec.c \ src/dh-exec.lib.c \ src/dh-exec.lib.h src_dh_exec_subst_SOURCES = \ src/dh-exec.simple.c \ src/dh-exec.lib.c \ src/dh-exec.lib.h src_dh_exec_subst_CFLAGS = -DDH_EXEC_CMD=\"subst\" src_dh_exec_install_SOURCES = \ src/dh-exec-install.c \ src/dh-exec.lib.c \ src/dh-exec.lib.h src_dh_exec_install_CFLAGS = -DDH_EXEC_CMD=\"install\" src_dh_exec_illiterate_SOURCES = \ src/dh-exec.simple.c \ src/dh-exec.lib.c \ src/dh-exec.lib.h src_dh_exec_illiterate_CFLAGS = -DDH_EXEC_CMD=\"illiterate\" src_dh_exec_strip_SOURCES = \ src/dh-exec.simple.c \ src/dh-exec.lib.c \ src/dh-exec.lib.h src_dh_exec_strip_CFLAGS = -DDH_EXEC_CMD=\"strip\" \ -DDH_EXEC_CMD_ALWAYS=1 # --- Test suite --- TESTCASES_SUBST = test_subst_syntax.bats \ test_subst_env.bats \ test_subst_multiarch.bats TESTCASES_INSTALL = test_install_syntax.bats \ test_install_copy.bats TESTCASES_ILLITERATE = test_illiterate.bats TESTCASES_DH = test_dh.bats TESTCASES_MISC = test_combined.bats \ test_dh_exec.bats \ test_strip.bats TESTCASES = ${TESTCASES_SUBST} ${TESTCASES_INSTALL} \ ${TESTCASES_MISC} ${TESTCASES_DH} \ ${TESTCASES_ILLITERATE} TESTS_ENVIRONMENT = DH_EXEC_SCRIPTDIR="${top_srcdir}/lib" \ DH_EXEC_LIBDIR="${top_builddir}/src" \ DH_EXEC_BINDIR="${top_builddir}/src" \ top_builddir="${top_builddir}/" \ srcdir="${srcdir}/t" \ NO_PKG_MANGLE=1 pkgtest_FILES = t/pkg-test/data/bin-arch \ t/pkg-test/data/bin-foo \ t/pkg-test/data/plugin-multiarch \ t/pkg-test/debian/changelog \ t/pkg-test/debian/compat \ t/pkg-test/debian/control \ t/pkg-test/debian/copyright \ t/pkg-test/debian/pkg-test.dirs \ t/pkg-test/debian/pkg-test-illiterate.dirs \ t/pkg-test/debian/pkg-test-illiterate.install \ t/pkg-test/debian/pkg-test.install \ t/pkg-test/debian/rules \ t/pkg-test/debian/source/format \ t/pkg-test/GNUMakefile check: all ${TESTS} $(AM_V_GEN) ${TESTS_ENVIRONMENT} \ prove -e "${top_srcdir}/t/bats/libexec/bats --tap" -f \ -o ${PROVE_OPTIONS} \ $(addprefix ${top_srcdir}/t/,${TESTCASES}) bats: all ${TESTS} ${AM_V_GEN} ${TESTS_ENVIRONMENT} \ ${top_srcdir}/t/bats/libexec/bats \ $(addprefix ${top_srcdir}/t/,${TESTCASES}) # -- Custom targets -- coverage: coverage.info.html coverage.info.html: coverage.info $(AM_V_GEN)genhtml --quiet $^ --output-directory $@ coverage.info: check $(AM_V_GEN)lcov --quiet --capture --directory ${top_builddir}/src --output $@ -b ${top_builddir} .PHONY: coverage CLEANFILES = coverage.info clean-local: rm -rf coverage.info.html find ${top_builddir} -name '*.gcda' -or -name '*.gcno' | xargs rm -f # --- Extra files to distribute --- EXTRA_DIST = README.md HACKING.md \ ${man1_MANS} ${pkgdata_SCRIPTS} \ t/test.lib.bash \ $(addprefix t/,${TESTCASES}) \ ${pkgtest_FILES} \ ${disabled_TESTCASES} \ ${top_srcdir}/t/bats dh-exec-0.12/.travis.yml0000644000000000000000000000047012126064412011747 0ustar language: c install: - sudo apt-get update -qq - sudo apt-get install -qq debhelper fakeroot libpipeline-dev pkg-config perl before_script: - autoreconf -i script: - ./configure --enable-silent-rules --disable-dependency-tracking - make all - make check PROVE_OPTIONS=-j4 compiler: - gcc - clang dh-exec-0.12/debian/0000755000000000000000000000000012236134301011054 5ustar dh-exec-0.12/debian/copyright0000644000000000000000000000436612235150507013025 0ustar Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: dh-exec Upstream-Contact: Gergely Nagy Source: git://github.com/algernon/dh-exec.git Copyright: Copyright (C) 2011-2013 Gergely Nagy License: GPL-3+ Files: * Copyright: Copyright (C) 2011-2013 Gergely Nagy License: GPL-3+ Files: t/bats/* Copyright: Copyright (C) 2013 Sam Stephenson License: Expat License: GPL-3+ This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. . This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. . You should have received a copy of the GNU General Public License along with this program. If not, see . . On Debian systems, the complete text of the GNU General Public License can be found in the file `/usr/share/common-licenses/GPL-3'. License: Expat Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: . The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. . THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. dh-exec-0.12/debian/source/0000755000000000000000000000000012126351574012367 5ustar dh-exec-0.12/debian/source/format0000644000000000000000000000001512126351574013576 0ustar 3.0 (native) dh-exec-0.12/debian/dh-exec.docs0000644000000000000000000000001212126351574013247 0ustar README.md dh-exec-0.12/debian/compat0000644000000000000000000000000212126351574012265 0ustar 9 dh-exec-0.12/debian/control0000644000000000000000000000221612236131750012465 0ustar Source: dh-exec Section: devel Priority: extra Maintainer: Gergely Nagy Build-Depends: debhelper (>= 9~), dh-autoreconf, automake (>= 1:1.11), fakeroot, libpipeline-dev, pkg-config, perl Standards-Version: 3.9.5 Homepage: https://github.com/algernon/dh-exec Vcs-Git: git://git.madhouse-project.org/debian/dh-exec.git Vcs-Browser: http://git.madhouse-project.org/debian/dh-exec/ Package: dh-exec Multi-Arch: foreign Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends}, ${perl:Depends}, perl (>= 5.14.2~), debhelper (>= 8.9.13~) Description: Scripts to help with executable debhelper files Debhelper (in compat level 9 and above) allows its config files to be executable, and uses the output of suchs scripts as if it was the content of the config file. . To ease and standardize the most common tasks, this package provides a few solutions to help constructing such executable scripts: . * A way to ease variable substitution, from environment variables or dpkg-architecture. * An extension to dh_install, with the ability to rename files. dh-exec-0.12/debian/rules0000755000000000000000000000024612235073242012143 0ustar #! /usr/bin/make -f export DH_OPTIONS += -O-Bdebian/build-tree override_dh_auto_configure: dh_auto_configure -- --libexecdir=/usr/lib %: dh $@ --with autoreconf dh-exec-0.12/debian/gbp.conf0000644000000000000000000000007212126351574012505 0ustar [default] upstream-branch = master debian-branch = master dh-exec-0.12/debian/changelog0000644000000000000000000001046712236132215012740 0ustar dh-exec (0.12) unstable; urgency=low * The test suite was cleaned up and migrated from a custom solution to BATS. * Fixed a possible crash when DH_EXEC_SCRIPTDIR pointed to a non-existing directory. * Handle --help and unknown arguments separately, for better error reporting in the latter case. * Depend on perl instead of perl-modules. * Standards-Version bumped to 3.9.5 (no changes necessary). -- Gergely Nagy Tue, 05 Nov 2013 10:04:13 +0100 dh-exec (0.11) unstable; urgency=low * Do not allow spaces in neither source nor destination when renaming files via dh-exec-install. That would make the syntax far more complicated, and this way, we can just disallow whitespace and get rid of the trailing ones too. Thanks to Chow Loong Jin for the patch. * Strip the output of any comment or whitespace-only lines, even when dh-exec was called with the --with-scripts option. Thanks to Dann Frazier and Daniel Schepler for reporting the issue. (Closes: #711937) -- Gergely Nagy Sun, 25 Aug 2013 09:40:39 +0200 dh-exec (0.10) unstable; urgency=low * Build-Depend on automake (>= 1:1.11), to force a suitable automake version into unclean environments too. -- Gergely Nagy Tue, 25 Jun 2013 12:50:39 +0200 dh-exec (0.9) unstable; urgency=low * Strip the output of any comment or whitespace-only lines, because debhelper does not do that for executable scripts. Thanks to Chow Loong Jin for noticing! * Removed the debian/watch file, it is fairly useless for a native package. Thanks lintian & the PTS. -- Gergely Nagy Mon, 10 Jun 2013 11:36:25 +0200 dh-exec (0.8) unstable; urgency=low * Handle empty variables correctly in dh-exec-subst-env: use their empty value, instead of opting for the fallback. Thanks Chow Loong Jin for the patch! (Closes: #711643) -- Gergely Nagy Sat, 08 Jun 2013 16:33:59 +0200 dh-exec (0.7) unstable; urgency=medium * Preserve permissions when renaming files. Many thanks to Axel Beckert for the report & help in tracking this down. (Closes: #706939). * Since we're using File::Copy::cp, depend on perl-modules >= 5.14.2~, which is in wheezy (the File::Copy in Squeeze doesn't have cp). Also thanks to Axel Beckert for the note. * Urgency medium, because not preserving permissions is a serious regression. -- Gergely Nagy Mon, 06 May 2013 23:44:43 +0200 dh-exec (0.6) unstable; urgency=low * Make dh-exec-install work on bare debian/install files, without the package name. Thanks, Axel Beckert for the report! (Closes: #698017). -- Gergely Nagy Sun, 13 Jan 2013 01:08:02 +0100 dh-exec (0.5) unstable; urgency=low * Drop the AC_PREREQ from configure.ac, to make backporting easier. (Closes: #696199) -- Gergely Nagy Fri, 21 Dec 2012 12:46:40 +0100 dh-exec (0.4) unstable; urgency=low * Add Vcs-* fields, thanks Wookey for the report! * Improved the sub-command man pages based on Wookey's suggestions. * Bump build-depends on debhelper to >= 9~, and remove the Lintian override. -- Gergely Nagy Sat, 30 Jun 2012 12:24:48 +0200 dh-exec (0.3) unstable; urgency=low * Implement a --with-scripts= option for dh-exec, to allow the user to limit what scripts get run. Thanks to Wookey for the suggestion! * Bump Standards-Version to 3.9.3 (no changes required). * Add a rationale explaining the advantages of dh-exec and a few examples to the README. (Closes: #664698) * Add a --list option to dh-exec, to list the available sub-commands and scripts. -- Gergely Nagy Thu, 03 May 2012 12:51:32 +0200 dh-exec (0.2) unstable; urgency=low * Disable pkgbinarymangler for tests, to fix FTBFS on Ubuntu. Patch from Felix Geyer . (Closes: #657966) -- Gergely Nagy Tue, 31 Jan 2012 14:55:31 +0100 dh-exec (0.1) unstable; urgency=low * Initial release. (Closes: #651393) -- Gergely Nagy Wed, 21 Dec 2011 00:51:28 +0100 dh-exec-0.12/README.md0000644000000000000000000001231112155317246011122 0ustar dh-exec ======= [![Build Status](https://secure.travis-ci.org/algernon/dh-exec.png?branch=master)](http://travis-ci.org/algernon/dh-exec) [Debhelper][1] (in compat level 9 and above) allows its config files to be executable, and uses the output of suchs scripts as if it was the content of the config file. This is a collection of scripts and programs to help creating such scripts in a standardised and easy to understand fashion. This collection provides solutions for the following tasks: * Expanding variables in various [debhelper][1] files (either from the environment, or variables known to **dpkg-architecture**(1) - including multi-arch ones) * An extension to dh_install, that supports renaming files during the copy process, using an extended syntax. [1]: http://kitenet.net/~joey/code/debhelper/ Usage ===== The recommended way to use dh-exec is through the **dh-exec**(1) wrapper, which will bind all the other tools together. That is, when adding a she-bang line to an executable debhelper config file, use `/usr/bin/dh-exec`. Using dh-exec means one will need to use debhelper compat level 9 or above and executable debhelper config files: there is no extra support needed in `debian/rules` or elsewhere, just an executable file with an appropriate she-bang line. Advantages ========== One may of course question the existence of a seemingly complicated tool, all for achieving some variable substitution, something one could do with a here-doc and a shell script. However, one would be gravely mistaken thinking that it's all dh-exec does and what it is good for. A few major advantages dh-exec has over custom here-doc or sed magic tricks: * Compared to using sed or similar to generate debhelper control files, dh-exec does not require any changes in `debian/rules`, nor anywhere else but the scripts themselves. In most cases, it only needs a she-bang and an executable bit, and the former input file becomes a valid debhelper control file. This, in turn, makes the packaging simpler, as there is no package-specific magic involved anymore. * Compared to the here-doc method, dh-exec provides consistency and safety. The most useful part of dh-exec (apart from adding rename support to .install files) is probably its support for expanding multiarch variables. dh-exec does this so that even if said variables are not set in the environment, it will query **dpkg-architecture**(1), so one can test the scripts without further setup. Of course, that is also doable with here-docs, but using variables seems more natural. dh-exec can also be asked to only substitute multiarch variables, not every environment variable, which makes it somewhat safer. It can't execute random shell commands either, which is another safety guard. * dh-exec is one controlled tool in one place, as opposed to any number of diverse, package-specific hacks. Even if one does not need much from what dh-exec provides, using it instead of inventing one's own still has the advantage of being consistent accross packages. While it may be less powerful than a complete shell at ones command, it is also safer, and being a separate solution, not a package-specific hack, it does help overall, archive-wide consistency: if one knows what to expect from dh-exec, one will understand all dh-exec using packages. Package-specific hacks will always need a little bit extra work to understand and verify, while one only needs to understand dh-exec once. Examples ======== One of the most simple cases is expanding multi-arch variables in an install file: #! /usr/bin/dh-exec usr/lib/*.so.* /usr/lib/${DEB_HOST_MULTIARCH}/libsomething.so.* Of course, this has the disadvantage of running all dh-exec scripts, so it will also try to expand any environment variables too. For safety, one can turn that off, and explicitly request that only multi-arch expansion shall be done: #! /usr/bin/dh-exec --with-scripts=subst-multiarch usr/lib/*.so.* /usr/lib/${DEB_HOST_MULTIARCH}/libsomething.so.* /usr/share/doc/my-package/${HOME}-sweet-home In this second case, the *${HOME}* variable will not be expanded, even if such an environment variable is present when dh-exec runs. Do note that dh-exec is not required at all if all you want to do is mark a multi-arch path as belonging to a package: debhelper itself supports wildcards! So if your install script would look like the following: #! /usr/bin/dh-exec /usr/lib/${DEB_HOST_MULTIARCH}/libsomething.so.* Then most likely, you do not need dh-exec, and you can replace the above with this simple line: /usr/lib/*/libsomething.so.* But variable expansion is not all that dh-exec is able to perform! Suppose we want to install a file, under a different name: with dh-exec, that is also possible: #! /usr/bin/dh-exec --with=install debian/default.conf => /etc/my-package/start.conf These can, of course, be combined. One can even limit scripts to multiarch substitution and install-time renaming only, skipping everything else dh-exec might try: #! /usr/bin/dh-exec --with-scripts=subst-multiarch,install-rename configs/config-${DEB_HOST_GNU_TYPE}.h => /usr/include/${DEB_HOST_MULTIARCH}/package/config.h -- Gergely Nagy dh-exec-0.12/lib/0000755000000000000000000000000012174740244010412 5ustar dh-exec-0.12/lib/dh-exec-install-rename0000755000000000000000000000242412174740244014570 0ustar #! /usr/bin/perl -wnp ## ## This script looks for SOURCE => DEST lines in its input, and copies ## SOURCE to a temporary directory under debian/tmp, with the desired ## DEST name. It will create directories appropriately. ## ## It is done this way, so that we leave the boring work to ## dh_install, and all of its options will continue to work. And we ## put this under debian/tmp, because that gets cleaned up by dh_prep. BEGIN { use File::Spec; use File::Temp qw/tempdir/; use File::Copy qw/cp move/; use File::Path qw/make_path/; make_path("debian/tmp"); our $tempdir = tempdir ("debian/tmp/dh-exec.XXXXXXXX"); } if (/([^\s]*)\s+=>\s+([^\s]*)/) { my ($src, $dst) = ($1, $2); my (undef, $srcpath, undef) = File::Spec->splitpath ($src); my (undef, $dstpath, $dstfile) = File::Spec->splitpath ($dst); my $debpath = File::Spec->catdir ($tempdir, $dstpath); make_path($debpath); cp ($src, File::Spec->catfile ($debpath, $dstfile)) or move (File::Spec->catfile ("debian/tmp", $src), File::Spec->catfile ($debpath, $dstfile)) or die "Copy failed: $!"; $_ = File::Spec->catfile ($debpath, $dstfile) . " " . $dstpath . "\n"; } dh-exec-0.12/lib/dh-exec-illiterate-tangle0000755000000000000000000000222112026641012015243 0ustar #! /usr/bin/perl -w use strict; # The first line is the she-bang, always ignore it. <>; my @files; my $last_file; while (<>) { next unless /[\`']/; # Find `...' constructs. The first is always the source, the # second is the destination. while (/\`([^']+)'/) { if ($last_file) { push (@files, {src => $last_file, dst => $1}); $last_file = undef; } else { $last_file = $1; } s/\`([^']+)'//; } # Once done, find the '...' constructs, which is always a # directory, no second stuff. while (/'([^' ]+)'/) { push (@files, {src => $1, solo => 1}); s/'([^' ]+)'//; } }; # Great, we got the stuff extracted, now turn it into something # illiterate. foreach (@files) { if (defined ($_->{solo})) { print $_->{src} . "\n"; } elsif ($_->{dst} =~ /\/$/) { print $_->{src} . " " . $_->{dst} . "\n"; } else { print $_->{src} . " => " . $_->{dst} . "\n"; } } dh-exec-0.12/lib/dh-exec-subst-multiarch0000755000000000000000000000067412154647164015015 0ustar #! /usr/bin/perl -wnp ## ## Akin to dh_subst_env, this one will try to expand variables within ## its input, but only certain ones, and will fall back to querying ## dpkg-architecture first, before finally giving up. BEGIN { sub qarch { my $arch = `dpkg-architecture -q$_[0] 2>/dev/null`; chomp ($arch); return $arch; } } s#(\$\{(DEB_(HOST|BUILD)_[^\}]+)\})#qarch($2) || $1#eg; dh-exec-0.12/lib/dh-exec-strip-output0000755000000000000000000000021212154645652014352 0ustar #! /usr/bin/perl -wnp ## ## This script removes commented and empty (or whitespace-only) lines ## from its input. $_ = "" if /^\#|^\s*$/; dh-exec-0.12/lib/dh-exec-subst-env0000755000000000000000000000035312154647160013603 0ustar #! /usr/bin/perl -wnp ## ## This does nothing else, but substitute ${...} with the ## corresponding environment variable, or the original ${...} if the ## env. var does not exist. s/(\$\{([^\}]+)\})/exists $ENV{$2} ? $ENV{$2} : $1/eg;