├── .gitignore ├── .mailmap ├── COPYING ├── README ├── README.rst └── dotfiles.sh /.gitignore: -------------------------------------------------------------------------------- 1 | patched-src 2 | local-patch 3 | updated.* 4 | -------------------------------------------------------------------------------- /.mailmap: -------------------------------------------------------------------------------- 1 | W. Trevor King 2 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | This package provides automatic synchronization of assorted dotfiles, 2 | simplifying the maintenance of a uniform configuration across several 3 | hosts. 4 | 5 | The `original implementation`_ was by Steve Kemp. 6 | 7 | .. _original implementation: http://dotfiles.repository.steve.org.uk 8 | 9 | This package only contains the ``dotfiles.sh`` script which manages the 10 | dotfiles framework. The files that are being managed live in separate 11 | repositories. A stand-alone framework has two goals: 12 | 13 | 1. Allow others to reuse the framework with their own dotfile 14 | repositories. 15 | 2. Allow several concurrent repositories (e.g. public and private). 16 | 17 | Installation 18 | ------------ 19 | 20 | To install the distribution framework, just drop ``dotfiles.sh`` into 21 | your ``PATH``. Also check that you have already installed the utilities 22 | listed in the ``External utilities`` section of ``dotfiles.sh``. 23 | 24 | Setting up managed repositories will look something like this:: 25 | 26 | $ mkdir ~/src/dotfiles 27 | $ cd ~/src/dotfiles 28 | $ dotfiles.sh clone public wget http://example.com/public-dotfiles.tar.gz 29 | $ dotfiles.sh patch public 30 | $ dotfiles.sh link --force-file --dry-run public 31 | $ dotfiles.sh link --force-file public 32 | 33 | Maintenance 34 | ----------- 35 | 36 | Once you've got your repository installed, just run:: 37 | 38 | $ dotfiles.sh --dotfiles-dir ~/src/dotfiles update 39 | 40 | to fetch any new developments from the central source, apply local 41 | patches, and link to any new files from your target directory. In 42 | order to automate this, you may want to add this line to your 43 | ``.bashrc``, which will update your dotfiles every time you start a new 44 | Bash shell. Since dotfiles are not expected to change rapidly, the 45 | ``update`` command remembers the last time it ran and only actually 46 | performs the update if it has been at least a week since the last 47 | update. 48 | 49 | If you're using Git, you may have a choice of transport protocols for 50 | accessing the central repository. Some protocols (e.g. SSH) often 51 | require you to authenticate before you are allowed access. Because 52 | dotfiles will try and update your local repository as you log in, make 53 | sure you set up your authentication mechanism (e.g. SSH agent) before 54 | running ``dotfiles.sh``. If you don't want to bother authenticating, 55 | use a protocol that does not require authentication (e.g. HTTP) in 56 | your default pull URL. 57 | 58 | Local differences 59 | ----------------- 60 | 61 | After syncing with the central server, any local patches 62 | (``${DOTFILES_DIR}/${REPO}/local-patch/*.patch``) are applied and 63 | filenames ``${DOTFILES_DIR}/${REPO}/local-patch/*.remove`` are removed 64 | to adapt to the local system. As with installation, symlinks are 65 | automatically created for any dotfile 66 | (``${DOTFILES_DIR}/${REPO}/patched-src/XXX``) that does not already 67 | have a locally installed version (``${TARGET}/XXX``). 68 | 69 | If you followed the installation instructions above, you may have 70 | received warnings about files that you already have that dotfiles 71 | wants to control. You have two options for dealing with these 72 | collisions: 73 | 74 | 1. Control the file yourself. In this case, you should add the 75 | filename to a ``local-patch/*.remove`` file, so that dotfiles knows 76 | you've assumed control. 77 | 2. Delegate control to dotfiles. In this case, you should remove your 78 | local version of the file. Dotfiles will symlink in its version 79 | the next time you run ``dotfiles.sh``. If you have many such files, 80 | ``dotfiles.sh link --force`` will overwrite all of them at once. 81 | 82 | You can use the ``diff`` command in ``dotfiles.sh`` to browse the 83 | differences between your checked out source and installed targets. 84 | The ``--local-patch`` option will record all such differences in the 85 | ``local-patch`` directory for editing. 86 | 87 | Additional repositories 88 | ----------------------- 89 | 90 | Some dotfiles contain passwords, hostnames, or other personal 91 | information. You may want to synchronize these files, but placing 92 | them in a globally readable repository would not be a good idea. A 93 | simple solution would be to distribute *all* your dotfiles through 94 | secure channels (e.g. Git over SSH), but then nobody would benefit 95 | from the cool tricks you've used in your non-sensitive dotfiles. A 96 | better solution is to run two (or more) dotfiles repositories 97 | concurrently, one for sensitive files and the other for public files. 98 | Of course, you might also want to run concurrent repositories reason 99 | besides privacy. Whatever your motivation, installing another 100 | repository is the same as installing the first:: 101 | 102 | $ cd ~/src/dotfiles 103 | $ dotfiles.sh clone private git ssh://example.com/~/private-dotfiles.git 104 | $ dotfiles.sh patch private 105 | $ dotfiles.sh link --force-file private 106 | 107 | Future calls to ``dotfiles.sh update`` will update all of your 108 | repositories in turn. 109 | 110 | Dependencies 111 | ------------ 112 | 113 | ``dotfiles.sh`` is a script, so there are no compilation dependencies. 114 | However, you will need sufficiently modern versions of the external 115 | utilities it uses. They are listed at the beginning of 116 | ``dotfiles.sh``, which should make it easy to select alternative 117 | implementations if the version installed in your ``PATH`` is not up to 118 | standard. For example, I just set things up on my university's archaic 119 | SunOS 5.10 server (circa 2005), and I needed to install current 120 | versions of ``bash``, ``ln`` (in the coreutils_ package), and ``tar`` 121 | to succesfully run a ``wget``-based dotfile repository. 122 | 123 | .. _coreutils: http://www.gnu.org/software/coreutils/ 124 | 125 | Help 126 | ---- 127 | 128 | This ``README`` is designed to get you started with this dotfiles 129 | framework and give you a feel for the overall structure. For more 130 | details, browse through the ``dotfiles.sh`` documentation, starting 131 | with:: 132 | 133 | $ dotfiles.sh --help 134 | 135 | Homepage 136 | -------- 137 | 138 | http://blog.tremily.us/posts/dotfiles/ 139 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | README -------------------------------------------------------------------------------- /dotfiles.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Dotfiles management script. For details, run 4 | # $ dotfiles.sh --help 5 | # 6 | # Copyright (C) 2011-2015 W. Trevor King 7 | # 8 | # This program is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # This program is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with this program. If not, see . 20 | 21 | VERSION='0.4' 22 | DOTFILES_DIR="${PWD}" 23 | TARGET=~ 24 | CHECK_WGET_TYPE_AND_ENCODING='no' 25 | 26 | ##### 27 | # External utilities 28 | 29 | DIFF=${DOTFILES_DIFF:-$(command -v diff)} 30 | GIT=${DOTFILES_GIT:-$(command -v git)} 31 | LN=${DOTFILES_LN:-$(command -v ln)} 32 | MV=${DOTFILES_MV:-$(command -v mv)} 33 | PATCH=${DOTFILES_PATCH:-$(command -v patch)} 34 | SED=${DOTFILES_SED:-$(command -v sed)} 35 | RM=${DOTFILES_RM:-$(command -v rm)} 36 | RSYNC=${DOTFILES_RSYNC:-$(command -v rsync)} 37 | TAR=${DOTFILES_TAR:-$(command -v tar)} 38 | TOUCH=${DOTFILES_TOUCH:-$(command -v touch)} 39 | WGET=${DOTFILES_WGET:-$(command -v wget)} 40 | 41 | ##### 42 | # Compatibility checks 43 | 44 | BASH="${BASH_VERSION%.*}" 45 | BASH_MAJOR="${BASH%.*}" 46 | BASH_MINOR="${BASH#*.}" 47 | 48 | if [ "${BASH_MAJOR}" -eq 3 ] && [ "${BASH_MINOR}" -eq 0 ]; then 49 | echo "ERROR: ${0} requires Bash version >= 3.1" >&2 50 | echo "you're running ${BASH}, which doesn't support += array assignment" >&2 51 | exit 1 52 | fi 53 | 54 | ##### 55 | # Utility functions 56 | 57 | # usage: nonempty_option LOC NAME VALUE 58 | function nonempty_option() 59 | { 60 | LOC="${1}" 61 | NAME="${2}" 62 | VALUE="${3}" 63 | if [ -z "${VALUE}" ]; then 64 | echo "ERROR: empty value for ${NAME} in ${LOC}" >&2 65 | return 1 66 | fi 67 | echo "${VALUE}" 68 | } 69 | 70 | # usage: maxargs LOC MAX "${@}" 71 | # 72 | # Print and error and return 1 if there are more than MAX arguments. 73 | function maxargs() 74 | { 75 | LOC="${1}" 76 | MAX="${2}" 77 | shift 2 78 | if [ "${#}" -gt "${MAX}" ]; then 79 | echo "ERROR: too many arguments (${#} > ${MAX}) in ${LOC}" >&2 80 | return 1 81 | fi 82 | } 83 | 84 | # usage: get_selection CHOICE OPTION ... 85 | # 86 | # Check that CHOICE is one of the valid options listed in OPTION. If 87 | # it is, echo the choice and return 0, otherwise print an error to 88 | # stderr and return 1. 89 | function get_selection() 90 | { 91 | CHOICE="${1}" 92 | shift 93 | for OPT in "${@}"; do 94 | if [ "${OPT}" = "${CHOICE}" ]; then 95 | echo "${OPT}" 96 | return 0 97 | fi 98 | done 99 | echo "ERROR: invalid selection (${CHOICE})" >&2 100 | echo "valid choices: ${@}" >&2 101 | return 1 102 | } 103 | 104 | function run_on_all_repos() 105 | { 106 | COMMAND="${1}" 107 | shift 108 | if [ -z "${REPO}" ]; then # run on all repositories 109 | for REPO in *; do 110 | if [ "${REPO}" = '*' ]; then 111 | break # no known repositories 112 | elif [ -f "${REPO}" ]; then 113 | continue # repositories are directories 114 | fi 115 | "${COMMAND}" "${@}" "${REPO}" || return 1 116 | done 117 | return 118 | fi 119 | } 120 | 121 | function list_files() 122 | { 123 | DIR=$(nonempty_option 'list_files' 'DIR' "${1}") || return 1 124 | while read FILE; do 125 | if [ "${FILE}" = '.' ]; then 126 | continue 127 | fi 128 | FILE="${FILE:2}" # strip the leading './' 129 | echo "${FILE}" 130 | done < <(cd "${DIR}" && find .) 131 | } 132 | 133 | # Global variable to allow passing associative arrays between functions 134 | 135 | if [ "${BASH_MAJOR}" -ge 4 ]; then 136 | declare -A REPO_SOURCE_DATA 137 | fi 138 | 139 | function set_repo_source() 140 | { 141 | if [ "${BASH_MAJOR}" -lt 4 ]; then 142 | echo "ERROR: ${0}'s set_repo_source requires Bash version >= 4.0" >&2 143 | echo "you're running ${BASH}, which doesn't support associative arrays" >&2 144 | return 1 145 | fi 146 | REPO=$(nonempty_option 'set_repo_source' 'REPO' "${1}") || return 1 147 | > "${REPO}/source_cache" || return 1 148 | for KEY in "${!REPO_SOURCE_DATA[@]}"; do 149 | echo "${KEY}=${REPO_SOURCE_DATA[${KEY}]}" >> "${REPO}/source_cache" || return 1 150 | done 151 | } 152 | 153 | # usage: get_repo_source REPO 154 | function get_repo_source() 155 | { 156 | if [ "${BASH_MAJOR}" -lt 4 ]; then 157 | echo "ERROR: ${0}'s get_repo_source() requires Bash version >= 4.0" >&2 158 | echo "you're running ${BASH}, which doesn't support associative arrays" >&2 159 | return 1 160 | fi 161 | REPO=$(nonempty_option 'get_repo_source' 'REPO' "${1}") || return 1 162 | REPO_SOURCE_DATA=() 163 | if [ -f "${REPO}/source_cache" ]; then 164 | while read LINE; do 165 | KEY="${LINE%%=*}" 166 | VALUE="${LINE#*=}" 167 | REPO_SOURCE_DATA["${KEY}"]="${VALUE}" 168 | done < "${REPO}/source_cache" 169 | else 170 | # autodetect verson control system 171 | REPO_SOURCE_DATA=() 172 | REPO_SOURCE_DATA['repo']="${REPO}" 173 | if [ -d "${REPO}/.git" ]; then 174 | REPO_SOURCE_DATA['transfer']='git' 175 | REPO_SOURCE_DATA['url']=$( 176 | git --git-dir "${REPO}/.git/" config remote.origin.url) 177 | else 178 | echo "ERROR: no source location found for ${REPO}" >&2 179 | return 1 180 | fi 181 | # no need to get further fields for these transfer mechanisms 182 | fi 183 | } 184 | 185 | function git_fetch() 186 | { 187 | REPO=$(nonempty_option 'git_fetch' 'REPO' "${1}") || return 1 188 | REMOTES=$(cd "${REPO}" && "${GIT}" remote) || return 1 189 | if [ -n "${REMOTES}" ]; then 190 | (cd "${REPO}" && "${GIT}" pull) || return 1 191 | else 192 | echo "no remote repositories found for ${REPO}" 193 | fi 194 | } 195 | 196 | function wget_fetch() 197 | { 198 | REPO=$(nonempty_option 'wget_fetch' 'REPO' "${1}") || return 1 199 | # get_repo_source() was just called on this repo in fetch() 200 | TRANSFER=$(nonempty_option 'wget_fetch' 'TRANSFER' "${REPO_SOURCE_DATA['transfer']}") || return 1 201 | URL=$(nonempty_option 'wget_fetch' 'URL' "${REPO_SOURCE_DATA['url']}") || return 1 202 | ETAG="${REPO_SOURCE_DATA['etag']}" 203 | BUNDLE="${REPO}.tgz" 204 | HEAD=$("${WGET}" --server-response --spider "${URL}" 2>&1) || return 1 205 | SERVER_ETAG=$(echo "${HEAD}" | "${SED}" -n 's/^ *etag: *"\(.*\)"/\1/ip') || return 1 206 | if [ "${CHECK_WGET_TYPE_AND_ENCODING}" = 'yes' ]; then 207 | TYPE=$(echo "${HEAD}" | "${SED}" -n 's/^ *content-type: *//ip') || return 1 208 | ENCODING=$(echo "${HEAD}" | "${SED}" -n 's/^ *content-encoding: *//ip') || return 1 209 | if [ "${TYPE}" != 'application/x-gzip' ] || [ "${ENCODING}" != 'x-gzip' ]; then 210 | echo "ERROR: invalid content type (${TYPE}) or encoding (${ENCODING})." >&2 211 | echo "while fetching ${URL}" >&2 212 | return 1 213 | fi 214 | fi 215 | if [ -z "${ETAG}" ] || [ "${SERVER_ETAG}" != "${ETAG}" ]; then 216 | # Previous ETag not known, or ETag changed. Download new copy. 217 | "${WGET}" --output-document "${BUNDLE}" "${URL}" || return 1 218 | if [ -n "${SERVER_ETAG}" ]; then # store new ETag 219 | REPO_SOURCE_DATA['etag']="${SERVER_ETAG}" 220 | set_repo_source "${REPO}" || return 1 221 | elif [ -n "${ETAG}" ]; then # clear old ETag 222 | unset "${REPO_SOURCE_DATA['etag']}" 223 | set_repo_source "${REPO}" || return 1 224 | fi 225 | echo "extracting ${BUNDLE} to ${REPO}" 226 | "${TAR}" -xf "${BUNDLE}" -C "${REPO}" --strip-components 1 --overwrite || return 1 227 | "${RM}" -f "${BUNDLE}" || return 1 228 | else 229 | echo "already downloaded the ETag=${ETAG} version of ${URL}" 230 | fi 231 | } 232 | 233 | 234 | # usage: link_file REPO FILE 235 | # 236 | # Create the symbolic link to the version of FILE in the REPO 237 | # repository, overriding the target if it exists. If you want to 238 | # override the options passed to ${LN}, set LINK_OPTS. 239 | function link_file() 240 | { 241 | REPO=$(nonempty_option 'link_file' 'REPO' "${1}") || return 1 242 | FILE=$(nonempty_option 'link_file' 'FILE' "${2}") || return 1 243 | LINK_OPTS="${LINK_OPTS:--sv}" # default to `-sv` 244 | if [ "${BACKUP}" = 'yes' ]; then 245 | if [ -e "${TARGET}/${FILE}" ] || [ -h "${TARGET}/${FILE}" ]; then 246 | if [ "${DRY_RUN}" = 'yes' ]; then 247 | echo "move ${TARGET}/${FILE} to ${TARGET}/${FILE}.bak" 248 | else 249 | echo -n 'move ' 250 | mv -v "${TARGET}/${FILE}" "${TARGET}/${FILE}.bak" || return 1 251 | fi 252 | fi 253 | else 254 | if [ "${DRY_RUN}" = 'yes' ]; then 255 | echo "rm ${TARGET}/${FILE}" 256 | else 257 | "${RM}" -fv "${TARGET}/${FILE}" 258 | fi 259 | fi 260 | if [ "${DRY_RUN}" = 'yes' ]; then 261 | echo "link ${TARGET}/${FILE} to ${DOTFILES_DIR}/${REPO}/patched-src/${FILE}" 262 | else 263 | SOURCE="${DOTFILES_DIR}/${REPO}/patched-src/${FILE}" 264 | echo -n 'link ' 265 | "${LN}" ${LINK_OPTS} "${SOURCE}" "${TARGET}/${FILE}" || return 1 266 | fi 267 | } 268 | 269 | ##### 270 | # Top-level commands 271 | 272 | # An array of available commands 273 | COMMANDS=() 274 | 275 | ### 276 | # clone command 277 | 278 | COMMANDS+=('clone') 279 | 280 | CLONE_TRANSFERS=('git' 'wget') 281 | 282 | function clone_help() 283 | { 284 | echo 'Create a new dotfiles repository.' 285 | if [ "${1}" = '--one-line' ]; then return; fi 286 | 287 | cat <<-EOF 288 | 289 | usage: $0 ${COMMAND} REPO TRANSFER URL 290 | 291 | Where 'REPO' is the name the dotfiles repository to create, 292 | 'TRANSFER' is the transfer mechanism, and 'URL' is the URL for the 293 | remote repository. Valid TRANSFERs are: 294 | 295 | ${CLONE_TRANSFERS[@]} 296 | 297 | Examples: 298 | 299 | $0 clone public wget http://example.com/public-dotfiles.tar.gz 300 | $0 clone private git ssh://example.com/~/private-dotfiles.git 301 | EOF 302 | } 303 | 304 | function clone() 305 | { 306 | REPO=$(nonempty_option 'clone' 'REPO' "${1}") || return 1 307 | TRANSFER=$(nonempty_option 'clone' 'TRANSFER' "${2}") || return 1 308 | URL=$(nonempty_option 'clone' 'URL' "${3}") || return 1 309 | maxargs 'clone' 3 "${@}" || return 1 310 | TRANSFER=$(get_selection "${TRANSFER}" "${CLONE_TRANSFERS[@]}") || return 1 311 | if [ -e "${REPO}" ]; then 312 | echo "ERROR: destination path (${REPO}) already exists." >&2 313 | return 1 314 | fi 315 | CACHE_SOURCE='yes' 316 | FETCH='yes' 317 | case "${TRANSFER}" in 318 | 'git') 319 | CACHE_SOURCE='no' 320 | FETCH='no' 321 | "${GIT}" clone "${URL}" "${REPO}" || return 1 322 | ;; 323 | 'wget') 324 | mkdir -p "${REPO}" 325 | ;; 326 | *) 327 | echo "PROGRAMMING ERROR: add ${TRANSFER} support to clone command" >&2 328 | return 1 329 | esac 330 | if [ "${CACHE_SOURCE}" = 'yes' ]; then 331 | REPO_SOURCE_DATA=(['transfer']="${TRANSFER}" ['url']="${URL}") 332 | set_repo_source "${REPO}" || return 1 333 | fi 334 | if [ "${FETCH}" = 'yes' ]; then 335 | fetch "${REPO}" || return 1 336 | fi 337 | } 338 | 339 | ### 340 | # list command 341 | 342 | COMMANDS+=('list') 343 | 344 | function list_help() 345 | { 346 | echo 'List current dotfiles repositories.' 347 | if [ "${1}" = '--one-line' ]; then return; fi 348 | 349 | cat <<-EOF 350 | 351 | usage: $0 ${COMMAND} [REPO] 352 | 353 | List information for 'REPO' in a form simular to the 'clone' 354 | command's arguments. If 'REPO' is not give, all repositories will 355 | be listed. Examples: 356 | 357 | $0 list public 358 | public wget http://example.com/public-dotfiles.tar.gz 359 | $0 list 360 | public wget http://example.com/public-dotfiles.tar.gz 361 | private git ssh://example.com/~/private-dotfiles.git 362 | EOF 363 | } 364 | 365 | function list() 366 | { 367 | # multi-repo case handled in main() by run_on_all_repos() 368 | REPO=$(nonempty_option 'list' 'REPO' "${1}") || return 1 369 | maxargs 'list' 1 "${@}" || return 1 370 | if [ "${BASH_MAJOR}" -ge 4 ]; then 371 | get_repo_source "${REPO}" || return 1 372 | TRANSFER=$(nonempty_option 'list' 'TRANSFER' "${REPO_SOURCE_DATA['transfer']}") || return 1 373 | URL=$(nonempty_option 'list' 'URL' "${REPO_SOURCE_DATA['url']}") || return 1 374 | else 375 | echo "WARNING: Bash version < 4.0, cannot use assuming all repos use git transfer" >&2 376 | TRANSFER='git' 377 | URL=$(git --git-dir "${REPO}/.git/" config remote.origin.url) 378 | fi 379 | echo "${REPO} ${TRANSFER} ${URL}" 380 | } 381 | 382 | ### 383 | # fetch command 384 | 385 | COMMANDS+=('fetch') 386 | 387 | function fetch_help() 388 | { 389 | echo 'Get the current dotfiles from the server.' 390 | if [ "${1}" = '--one-line' ]; then return; fi 391 | 392 | cat <<-EOF 393 | 394 | usage: $0 ${COMMAND} [REPO] 395 | 396 | Where 'REPO' is the name the dotfiles repository to fetch. If it 397 | is not given, all repositories will be fetched. 398 | EOF 399 | } 400 | 401 | function fetch() 402 | { 403 | # multi-repo case handled in main() by run_on_all_repos() 404 | REPO=$(nonempty_option 'fetch' 'REPO' "${1}") || return 1 405 | maxargs 'fetch' 1 "${@}" || return 1 406 | if [ "${BASH_MAJOR}" -ge 4 ]; then 407 | get_repo_source "${REPO}" || return 1 408 | TRANSFER=$(nonempty_option 'fetch' 'TRANSFER' "${REPO_SOURCE_DATA['transfer']}") || return 1 409 | else 410 | echo "WARNING: Bash version < 4.0, assuming all repos use git transfer" >&2 411 | TRANSFER='git' 412 | fi 413 | if [ "${TRANSFER}" = 'git' ]; then 414 | git_fetch "${REPO}" || return 1 415 | elif [ "${TRANSFER}" = 'wget' ]; then 416 | wget_fetch "${REPO}" || return 1 417 | else 418 | echo "PROGRAMMING ERROR: add ${TRANSFER} support to fetch command" >&2 419 | return 1 420 | fi 421 | } 422 | 423 | ### 424 | # diff command 425 | 426 | COMMANDS+=('diff') 427 | 428 | function diff_help() 429 | { 430 | echo 'Show differences between targets and dotfiles repositories.' 431 | if [ "${1}" = '--one-line' ]; then return; fi 432 | 433 | cat <<-EOF 434 | 435 | usage: $0 ${COMMAND} [--removed|--local-patch] [REPO] 436 | 437 | Where 'REPO' is the name the dotfiles repository to query. If it 438 | is not given, all repositories will be queried. 439 | 440 | By default, ${COMMAND} will list differences between files that 441 | exist in both the target location and the dotfiles repository (as 442 | a patch that could be applied to the dotfiles source). 443 | 444 | With the '--removed' option, ${COMMAND} will list files that 445 | should be removed from the dotfiles source in order to match the 446 | target. 447 | 448 | With the '--local-patch' option, ${COMMAND} will create files in 449 | list files that should be removed from the dotfiles source in 450 | order to match the target. 451 | EOF 452 | } 453 | 454 | function diff() 455 | { 456 | MODE='standard' 457 | while [ "${1::2}" = '--' ]; do 458 | case "${1}" in 459 | '--removed') 460 | MODE='removed' 461 | ;; 462 | '--local-patch') 463 | MODE='local-patch' 464 | ;; 465 | *) 466 | echo "ERROR: invalid option to diff (${1})" >&2 467 | return 1 468 | esac 469 | shift 470 | done 471 | # multi-repo case handled in main() by run_on_all_repos() 472 | REPO=$(nonempty_option 'diff' 'REPO' "${1}") || return 1 473 | maxargs 'diff' 1 "${@}" || return 1 474 | 475 | if [ "${MODE}" = 'local-patch' ]; then 476 | mkdir -p "${REPO}/local-patch" || return 1 477 | 478 | exec 3<&1 # save stdout to file descriptor 3 479 | echo "save local patches to ${REPO}/local-patch/000-local.patch" 480 | exec 1>"${REPO}/local-patch/000-local.patch" # redirect stdout 481 | diff "${REPO}" 482 | exec 1<&3 # restore old stdout 483 | exec 3<&- # close temporary fd 3 484 | 485 | exec 3<&1 # save stdout to file descriptor 3 486 | echo "save local removed to ${REPO}/local-patch/000-local.remove" 487 | exec 1>"${REPO}/local-patch/000-local.remove" # redirect stdout 488 | diff --removed "${REPO}" 489 | exec 1<&3 # restore old stdout 490 | exec 3<&- # close temporary fd 3 491 | return 492 | fi 493 | 494 | while read FILE; do 495 | if [ "${MODE}" = 'removed' ]; then 496 | if [ ! -e "${TARGET}/${FILE}" ]; then 497 | echo "${FILE}" 498 | fi 499 | elif [ -f "${TARGET}/${FILE}" ]; then 500 | (cd "${REPO}/src" && "${DIFF}" -u "${FILE}" "${TARGET}/${FILE}") 501 | fi 502 | done <<-EOF 503 | $(list_files "${REPO}/src") 504 | EOF 505 | } 506 | 507 | ### 508 | # patch command 509 | 510 | COMMANDS+=('patch') 511 | 512 | function patch_help() 513 | { 514 | echo 'Patch a fresh checkout with local adjustments.' 515 | if [ "${1}" = '--one-line' ]; then return; fi 516 | 517 | cat <<-EOF 518 | 519 | usage: $0 ${COMMAND} [REPO] 520 | 521 | Where 'REPO' is the name the dotfiles repository to patch. If it 522 | is not given, all repositories will be patched. 523 | EOF 524 | } 525 | 526 | function patch() 527 | { 528 | # multi-repo case handled in main() by run_on_all_repos() 529 | REPO=$(nonempty_option 'patch' 'REPO' "${1}") || return 1 530 | maxargs 'patch' 1 "${@}" || return 1 531 | 532 | echo "copy clean checkout into ${REPO}/patched-src" 533 | "${RSYNC}" -avz --delete "${REPO}/src/" "${REPO}/patched-src/" || return 1 534 | 535 | # apply all the patches in local-patch/ 536 | for FILE in "${REPO}/local-patch"/*.patch; do 537 | if [ -f "${FILE}" ]; then 538 | echo "apply ${FILE}" 539 | pushd "${REPO}/patched-src/" > /dev/null || return 1 540 | "${PATCH}" -p1 < "../../${FILE}" || return 1 541 | popd > /dev/null || return 1 542 | fi 543 | done 544 | 545 | # remove any files marked for removal in local-patch 546 | for REMOVE in "${REPO}/local-patch"/*.remove; do 547 | if [ -f "${REMOVE}" ]; then 548 | echo "apply ${FILE}" 549 | while read LINE; do 550 | if [ -z "${LINE}" ] || [ "${LINE:0:1}" = '#' ]; then 551 | continue # ignore blank lines and comments 552 | fi 553 | if [ -e "${REPO}/patched-src/${LINE}" ]; then 554 | echo "remove ${LINE}" 555 | "${RM}" -rf "${REPO}/patched-src/${LINE}" 556 | fi 557 | done < "${REMOVE}" 558 | fi 559 | done 560 | } 561 | 562 | ### 563 | # link command 564 | 565 | COMMANDS+=('link') 566 | 567 | function link_help() 568 | { 569 | echo 'Link a fresh checkout with local adjustments.' 570 | if [ "${1}" = '--one-line' ]; then return; fi 571 | 572 | cat <<-EOF 573 | 574 | usage: $0 ${COMMAND} [--force] [--force-dir] [--force-file] [--force-link] 575 | [--dry-run] [--no-backup] [--relative] [REPO] 576 | 577 | Where 'REPO' is the name the dotfiles repository to link. If it 578 | is not given, all repositories will be linked. 579 | 580 | By default, ${COMMAND} only replaces missing directories, files, 581 | simlinks. You can optionally overwrite any local stuff by passing 582 | the --force option. If you only want to overwrite a particular 583 | type, use the more granular --force-dir, etc. 584 | 585 | If you have coreutils 8.16 (2012-03-26) or greater, you can set 586 | the --relative option to create symlinks that use relative paths. 587 | EOF 588 | } 589 | 590 | function link() 591 | { 592 | FORCE_DIR='no' # If 'yes', overwrite existing directories. 593 | FORCE_FILE='no' # If 'yes', overwrite existing files. 594 | FORCE_LINK='no' # If 'yes', overwrite existing symlinks. 595 | DRY_RUN='no' # If 'yes', disable any actions that change the filesystem 596 | BACKUP_OPT='yes' 597 | LINK_OPTS='-sv' 598 | while [ "${1::2}" = '--' ]; do 599 | case "${1}" in 600 | '--force') 601 | FORCE_DIR='yes' 602 | FORCE_FILE='yes' 603 | FORCE_LINK='yes' 604 | ;; 605 | '--force-dir') 606 | FORCE_DIR='yes' 607 | ;; 608 | '--force-file') 609 | FORCE_FILE='yes' 610 | ;; 611 | '--force-link') 612 | FORCE_LINK='yes' 613 | ;; 614 | '--dry-run') 615 | DRY_RUN='yes' 616 | ;; 617 | '--no-backup') 618 | BACKUP_OPT='no' 619 | ;; 620 | '--relative') 621 | LINK_OPTS="${LINK_OPTS} --relative" 622 | ;; 623 | *) 624 | echo "ERROR: invalid option to link (${1})" >&2 625 | return 1 626 | esac 627 | shift 628 | done 629 | # multi-repo case handled in main() by run_on_all_repos() 630 | REPO=$(nonempty_option 'link' 'REPO' "${1}") || return 1 631 | maxargs 'link' 1 "${@}" || return 1 632 | DOTFILES_SRC="${DOTFILES_DIR}/${REPO}/patched-src" 633 | 634 | while read FILE; do 635 | BACKUP="${BACKUP_OPT}" 636 | if [ "${DOTFILES_SRC}/${FILE}" -ef "${TARGET}/${FILE}" ]; then 637 | if [ "${FORCE_LINK}" = 'no' ]; then 638 | # don't prompt about --force-link, because this will happen a lot 639 | continue # already simlinked 640 | elif [ ! -h "${TARGET}/${FILE}" ]; then 641 | # target file/dir underneath an already symlinked dir 642 | continue 643 | else 644 | # don't backup links that already point to the right place 645 | BACKUP='no' 646 | fi 647 | else 648 | if [ -d "${DOTFILES_SRC}/${FILE}" ] && [ -d "${TARGET}/${FILE}" ] && \ 649 | [ "${FORCE_DIR}" = 'no' ]; then 650 | echo "use --force-dir to override the existing directory: ${TARGET}/${FILE}" 651 | continue # allow unlinked directories 652 | elif [ -f "${TARGET}/${FILE}" ] && [ "${FORCE_FILE}" = 'no' ]; then 653 | echo "use --force-file to override the existing target: ${TARGET}/${FILE}" 654 | continue # target already exists 655 | fi 656 | fi 657 | link_file "${REPO}" "${FILE}" || return 1 658 | done <<-EOF 659 | $(list_files "${DOTFILES_SRC}") 660 | EOF 661 | } 662 | 663 | ### 664 | # disconnect command 665 | 666 | COMMANDS+=('disconnect') 667 | 668 | function disconnect_help() 669 | { 670 | echo 'Freeze dotfiles at their current state.' 671 | if [ "${1}" = '--one-line' ]; then return; fi 672 | 673 | cat <<-EOF 674 | 675 | usage: $0 ${COMMAND} [REPO] 676 | 677 | Where 'REPO' is the name the dotfiles repository to disconnect. 678 | If it is not given, all repositories will be disconnected. 679 | 680 | You're about to give your sysadmin account to some newbie, and 681 | they'd just be confused by all this efficiency. This script 682 | freezes your dotfiles in their current state and makes everthing 683 | look normal. Note that this will delete your dotfiles repository 684 | and strip the dotfiles portion from your ~/.bashrc file. 685 | EOF 686 | } 687 | 688 | function disconnect() 689 | { 690 | # multi-repo case handled in main() by run_on_all_repos() 691 | REPO=$(nonempty_option 'disconnect' 'REPO' "${1}") || return 1 692 | maxargs 'disconnect' 1 "${@}" || return 1 693 | DOTFILES_SRC="${DOTFILES_DIR}/${REPO}/patched-src" 694 | 695 | # See if we've constructed any patched source files that might be 696 | # possible link targets 697 | if [ ! -d "${DOTFILES_SRC}" ]; then 698 | echo 'no installed dotfiles to disconnect' 699 | return 700 | fi 701 | 702 | # See if the bashrc file is involved with dotfiles at all 703 | BASHRC='no' 704 | 705 | while read FILE; do 706 | if [ "${FILE}" = '.bashrc' ] && [ "${TARGET}" -ef "${HOME}" ]; then 707 | BASHRC='yes' 708 | fi 709 | if [ "${DOTFILES_SRC}/${FILE}" -ef "${TARGET}/${FILE}" ] && [ -h "${TARGET}/${FILE}" ]; then 710 | # break simlink 711 | echo "de-symlink ${TARGET}/${FILE}" 712 | "${RM}" -f "${TARGET}/${FILE}" 713 | "${MV}" "${DOTFILES_SRC}/${FILE}" "${TARGET}/${FILE}" 714 | fi 715 | done <<-EOF 716 | $(list_files "${REPO}/patched-src") 717 | EOF 718 | 719 | if [ "${BASHRC}" == 'yes' ]; then 720 | echo 'strip dotfiles section from ~/.bashrc' 721 | "${SED}" '/DOTFILES_DIR/d' ~/.bashrc > bashrc_stripped 722 | 723 | # see if the stripped file is any different 724 | DIFF_OUTPUT=$("${DIFF}" ~/.bashrc bashrc_stripped) 725 | DIFF_RC="${?}" 726 | if [ "${DIFF_RC}" -eq 0 ]; then 727 | echo "no dotfiles section found in ~/.bashrc" 728 | "${RM}" -f bashrc_stripped 729 | elif [ "${DIFF_RC}" -eq 1 ]; then 730 | echo "replace ~/.bashrc with stripped version" 731 | "${RM}" -f ~/.bashrc 732 | "${MV}" bashrc_stripped ~/.bashrc 733 | else 734 | return 1 # diff failed, bail 735 | fi 736 | fi 737 | 738 | if [ -d "${DOTFILES_DIR}/${REPO}" ]; then 739 | echo "remove the ${REPO} repository" 740 | "${RM}" -rf "${DOTFILES_DIR}/${REPO}" 741 | fi 742 | } 743 | 744 | ### 745 | # update command 746 | 747 | COMMANDS+=('update') 748 | 749 | function update_help() 750 | { 751 | echo 'Utility command that runs fetch, patch, and link.' 752 | if [ "${1}" = '--one-line' ]; then return; fi 753 | 754 | cat <<-EOF 755 | 756 | usage: $0 ${COMMAND} [options] [REPO] 757 | 758 | Where 'REPO' is the name the dotfiles repository to update. 759 | If it is not given, all repositories will be updateed. 760 | 761 | Run 'fetch', 'patch', and 'link' sequentially on each repository 762 | to bring them in sync with the central repositories. Keeps track 763 | of the last update time to avoid multiple fetches in the same 764 | week. 765 | 766 | ${COMMAND} passes any options it receives through to the link 767 | command. 768 | EOF 769 | } 770 | 771 | function update() 772 | { 773 | LINK_OPTS='' 774 | while [ "${1::2}" = '--' ]; do 775 | LINK_OPTS="${LINK_FN_OPTS} ${1}" 776 | shift 777 | done 778 | # multi-repo case handled in main() by run_on_all_repos() 779 | REPO=$(nonempty_option 'update' 'REPO' "${1}") || return 1 780 | maxargs 'disconnect' 1 "${@}" || return 1 781 | 782 | # Update once a week from our remote repository. Mark updates by 783 | # touching this file. 784 | UPDATE_FILE="${REPO}/updated.$(date +%U)" 785 | 786 | if [ ! -e "${UPDATE_FILE}" ]; then 787 | echo "update ${REPO} dotfiles" 788 | "${RM}" -f "${REPO}"/updated.* || return 1 789 | "${TOUCH}" "${UPDATE_FILE}" || return 1 790 | fetch "${REPO}" || return 1 791 | patch "${REPO}" || return 1 792 | link ${LINK_OPTS} "${REPO}" || return 1 793 | echo "${REPO} dotfiles updated" 794 | fi 795 | } 796 | 797 | ##### 798 | # Main entry-point 799 | 800 | function main_help() 801 | { 802 | echo 'Dotfiles management script.' 803 | if [ "${1}" = '--one-line' ]; then return; fi 804 | 805 | cat <<-EOF 806 | 807 | usage: $0 [OPTIONS] COMMAND [ARGS] 808 | 809 | Options: 810 | --help Print this help message and exit. 811 | --version Print the $0 version and exit. 812 | --dotfiles-dir DIR Directory containing the dotfiles reposotories. Defaults to '.'. 813 | --target DIR Directory to install dotfiles into. Defaults to '~'. 814 | 815 | Commands: 816 | EOF 817 | for COMMAND in "${COMMANDS[@]}"; do 818 | echo -en "${COMMAND}\t" 819 | "${COMMAND}_help" --one-line 820 | done 821 | cat <<-EOF 822 | 823 | To get help on any command, pass the '--help' as the first option 824 | to the command. For example: 825 | 826 | ${0} ${COMMANDS[0]} --help 827 | EOF 828 | } 829 | 830 | function main() 831 | { 832 | COMMAND='' 833 | while [ "${1::2}" = '--' ]; do 834 | case "${1}" in 835 | '--help') 836 | main_help || return 1 837 | return 838 | ;; 839 | '--version') 840 | echo "${VERSION}" 841 | return 842 | ;; 843 | '--dotfiles-dir') 844 | DOTFILES_DIR="${2}" 845 | shift 846 | ;; 847 | '--target') 848 | TARGET="${2}" 849 | shift 850 | ;; 851 | *) 852 | echo "ERROR: invalid option to ${0} (${1})" >&2 853 | return 1 854 | esac 855 | shift 856 | done 857 | COMMAND=$(get_selection "${1}" "${COMMANDS[@]}") || return 1 858 | shift 859 | 860 | cd "${DOTFILES_DIR}" || return 1 861 | 862 | if [ "${1}" = '--help' ]; then 863 | "${COMMAND}_help" || return 1 864 | elif [ "${COMMAND}" = 'clone' ]; then 865 | "${COMMAND}" "${@}" || return 1 866 | else 867 | OPTIONS=() 868 | while [ "${1::2}" = '--' ]; do 869 | OPTIONS+=("${1}") 870 | shift 871 | done 872 | if [ "${#}" -eq 0 ]; then 873 | run_on_all_repos "${COMMAND}" "${OPTIONS[@]}" || return 1 874 | else 875 | maxargs "${0}" 1 "${@}" || return 1 876 | "${COMMAND}" "${OPTIONS[@]}" "${1}" || return 1 877 | fi 878 | fi 879 | } 880 | 881 | main "${@}" || exit 1 882 | --------------------------------------------------------------------------------