├── ContainerBox.png ├── ContainerBox_logged.png ├── LICENSE ├── README.md ├── bin └── ContainerBox ├── configure_rootless_xorg.sh ├── doc └── screenshot │ ├── Screenshot from 2018-12-28 14-38-38.png │ ├── Screenshot from 2018-12-28 14-45-04.png │ ├── Screenshot from 2018-12-28 14-51-09.png │ ├── Screenshot from 2018-12-28 14-51-43.png │ ├── Screenshot from 2018-12-28 14-59-49 (edit).png │ ├── Screenshot from 2018-12-28 14-59-49.png │ ├── Screenshot from 2018-12-28 15-04-27.png │ ├── Screenshot from 2018-12-28 16-49-56.png │ ├── Screenshot from 2018-12-28 17-02-17.png │ ├── Screenshot from 2018-12-28 17-22-15.png │ ├── Screenshot from 2018-12-28 17-30-55.png │ ├── Screenshot from 2018-12-28 17-54-42.png │ ├── Screenshot from 2018-12-28 17-56-59.png │ ├── Screenshot_shed-server_2018-12-28_14:16:13.png │ ├── Screenshot_shed-server_2018-12-28_14:16:57.png │ ├── Screenshot_shed-server_2018-12-28_14:20:49.png │ ├── Screenshot_shed-server_2018-12-28_14:21:12.png │ ├── Screenshot_shed-server_2018-12-28_17:38:12.png │ ├── Screenshot_shed-server_2018-12-28_17:41:09.png │ ├── Screenshot_shed-server_2018-12-28_17:41:38.png │ └── Screenshot_shed-server_2018-12-28_18:08:08.png ├── etc ├── creator │ ├── create │ ├── import │ ├── resources │ │ └── 10_container_box.conf │ └── templates │ │ ├── debian │ │ ├── fedora │ │ ├── ubuntu │ │ ├── vanilla │ │ ├── xpra_fedora │ │ └── xpra_ubuntu └── host │ ├── config │ ├── runapp │ ├── snapshot │ └── start ├── example.cbox └── install.sh /ContainerBox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexandreDey/ContainerBox/92f196994cce08fd2fba64799c0d59aa8bd81f96/ContainerBox.png -------------------------------------------------------------------------------- /ContainerBox_logged.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexandreDey/ContainerBox/92f196994cce08fd2fba64799c0d59aa8bd81f96/ContainerBox_logged.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 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.md: -------------------------------------------------------------------------------- 1 | ContainerBox 2 | ============ 3 | 4 | What is it? 5 | ----------- 6 | A tool on top of LXD to easily create and use containers with full graphical capability (a display manager and a desktop environment) 7 | 8 | Why? 9 | ---- 10 | The main idea is to have the usability from virtualization tools like VirtualBox but without the overhead of running inside a VM. Unprivilleged LXC containers allow for near 0 overhead while still maintaining reasonnable isolation. 11 | 12 | How does it work? 13 | ----------------- 14 | The host managed resources are exposed to the container when the latter is not able to manage them (ex: starting a display server). 15 | Security is kept in mind so everything that needs to run on the host is isolated as much as possible (ex: nested Xorg server run as unprivilleged user) . 16 | 17 | Usage 18 | ----- 19 | - **Install** 20 | + Install *lxd* and *xephyr* (and *xpra* if you want) on your host 21 | + Run install.sh 22 | 23 | - **Create a container** 24 | + ContainerBox create -n NAME_OF_CONTAINER(required) -t DISTRO_TO_USE (ubuntu debian fedora -- default: fedora) -d DESKTOP_ENVIRONMENT(KDE GNOME XFCE MATE -- default: XFCE) --x yes|no (experimental xpra support -- default:no) 25 | 26 | - **Start a container** 27 | + ContainerBox start -n NAME -m DISPLAY_METHOD (xephyr xpra xorg[rootless Xorg] -- default: xephyr) -f yes|no (fullscreen ?) --c no|DISPLAY_NUMBER (share clipboard) 28 | 29 | - **GPU accelerated app in container** 30 | + ContainerBox runapp NAME "command arg1 arg2 ... argN" secure(default)|nested|insecure [WIDTHxHEIGHT] 31 | + NOTE: 'secure' requires to be running inside a wayland environment and 'nested' having kwin_wayland and XWayland installed 32 | 33 | - **Configure a container** 34 | + ContainerBox config network|system|shared_folder|sound NAME_OF_CONTAINER(required) [ OPTIONS ] 35 | 36 | - **Take Snapshot of a container** 37 | + ContainerBox snapshot NAME_OF_CONTAINER(required) create|restore|save_state|restore_state|export|import|list [OPTIONS] 38 | 39 | - **Show Usage** 40 | + ContainerBox create|config|runapp|snapshot help 41 | 42 | NOTES 43 | ----- 44 | 45 | + GNOME Can only work if the display has OpenGL. Possible options are: xorg, xspice, xpra 46 | 47 | + For security reasons, Xorg backend starts a Xorg server as the currently logged user (be sure to add this user to video and input groups). It also opens the first available tty, which requires root privileges, and thus the user must also be a sudoer. 48 | 49 | SCREENSHOTS 50 | ----------- 51 | 52 | ![LightDM ContainerBox](ContainerBox.png?raw=true "ContainerBox LightDM login screen") 53 | ![XFCE Debian ContainerBox](ContainerBox_logged.png?raw=true "ContainerBox XFCE session debian") 54 | 55 | TODO List (in order of priority) 56 | -------------------------------- 57 | - Improve install script (create .deb and .rpm packages ?) 58 | - Write user documentation 59 | - Create a nice GUI on top of the CLI (WIP) 60 | - Install from an ISO image (maybe use QEMU to perform the install the lxd-p2c) 61 | - Your suggestions (as long as it can be done through LXD/LXC) 62 | 63 | AUTHOR: 64 | ------- 65 | Alexandre Dey 66 | 67 | DISCLAIMER 68 | ---------- 69 | 70 | This is still experimental use at your own risk (no real reason for it to break anything, but still) -------------------------------------------------------------------------------- /bin/ContainerBox: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | A=($@) 5 | B="${A[@]:1}" 6 | CONFIG=/etc/ContainerBox 7 | BASH=/bin/bash 8 | 9 | 10 | function usage { 11 | echo "Create a new container:" 12 | echo "ContainerBox create -n NAME_OF_CONTAINER(required) -t DISTRO_TO_USE (ubuntu debian fedora -- default: fedora) -d DESKTOP_ENVIRONMENT(KDE GNOME XFCE MATE -- default: XFCE) -x yes|no (experimental xpra support -- default:no)" 13 | 14 | echo "-----------------------" 15 | echo "Create a container from a template file:" 16 | echo "ContainerBox import NAME_OF_CONTAINER(required) PATH_TO_TEMPLATE_FILE" 17 | 18 | echo "-----------------------" 19 | echo "Start a container: " 20 | echo "ContainerBox start -n NAME -m DISPLAY_METHOD (xephyr xpra xorg[!!! security concern !!!] -- default: xephyr) -f yes|no (fullscreen ?)" 21 | 22 | echo "-----------------------" 23 | echo "Run a single app inside container (NOTE: requires to either be running inside a wayland environment, or having kwin_wayland and XWayland installed): " 24 | echo "ContainerBox runapp NAME \"command arg1 arg2 ... argN\"" 25 | 26 | echo "-----------------------" 27 | echo "Configure a container: " 28 | echo "ContainerBox config network|system|shared_folder|sound NAME_OF_CONTAINER(required) [ OPTIONS ] " 29 | 30 | echo "-----------------------" 31 | echo "Take snapshots of containers:" 32 | echo "ContainerBox snapshot NAME_OF_CONTAINER(required) create|restore|save_state|restore_state|export|import|list [OPTIONS]" 33 | 34 | } 35 | 36 | if [ "$1" = "create" ]; then 37 | $BASH $CONFIG/creator/create $B 38 | elif [ "$1" = "import" ]; then 39 | $BASH $CONFIG/creator/import $B 40 | elif [ "$1" = "start" ]; then 41 | $BASH $CONFIG/host/start $B 42 | elif [ "$1" = "config" ]; then 43 | $BASH $CONFIG/host/config $B 44 | elif [ "$1" = "runapp" ]; then 45 | $BASH $CONFIG/host/runapp $2 "$3" $4 $5 46 | elif [ "$1" = "snapshot" ]; then 47 | $BASH $CONFIG/host/snapshot $B 48 | elif [ "$1" = "help" ]; then 49 | usage 50 | exit 51 | else 52 | echo "Unknown option $1" 53 | usage 54 | fi -------------------------------------------------------------------------------- /configure_rootless_xorg.sh: -------------------------------------------------------------------------------- 1 | USER=$1 2 | if [ "$UID" != "0" ];then 3 | echo "[ERROR]: You must run this script as root" 4 | exit 5 | fi 6 | if [ -z "$1" ];then 7 | echo "[ERROR]: Provide the username that can start Xorg" 8 | exit 9 | fi 10 | 11 | INPUT_EXISTS=$(grep input /etc/group) 12 | # If it does not exists 13 | if [ -z "$INPUT_EXISTS" ];then 14 | groupadd input 15 | cat > /etc/udev/rules.d/99-dev-input-group.rules << EOF 16 | SUBSYSTEM=="input", ACTION=="add", GROUP="input" 17 | EOF 18 | /etc/init.d/udev reload 19 | fi 20 | 21 | usermod -a -G input,video $USER -------------------------------------------------------------------------------- /doc/screenshot/Screenshot from 2018-12-28 14-38-38.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexandreDey/ContainerBox/92f196994cce08fd2fba64799c0d59aa8bd81f96/doc/screenshot/Screenshot from 2018-12-28 14-38-38.png -------------------------------------------------------------------------------- /doc/screenshot/Screenshot from 2018-12-28 14-45-04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexandreDey/ContainerBox/92f196994cce08fd2fba64799c0d59aa8bd81f96/doc/screenshot/Screenshot from 2018-12-28 14-45-04.png -------------------------------------------------------------------------------- /doc/screenshot/Screenshot from 2018-12-28 14-51-09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexandreDey/ContainerBox/92f196994cce08fd2fba64799c0d59aa8bd81f96/doc/screenshot/Screenshot from 2018-12-28 14-51-09.png -------------------------------------------------------------------------------- /doc/screenshot/Screenshot from 2018-12-28 14-51-43.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexandreDey/ContainerBox/92f196994cce08fd2fba64799c0d59aa8bd81f96/doc/screenshot/Screenshot from 2018-12-28 14-51-43.png -------------------------------------------------------------------------------- /doc/screenshot/Screenshot from 2018-12-28 14-59-49 (edit).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexandreDey/ContainerBox/92f196994cce08fd2fba64799c0d59aa8bd81f96/doc/screenshot/Screenshot from 2018-12-28 14-59-49 (edit).png -------------------------------------------------------------------------------- /doc/screenshot/Screenshot from 2018-12-28 14-59-49.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexandreDey/ContainerBox/92f196994cce08fd2fba64799c0d59aa8bd81f96/doc/screenshot/Screenshot from 2018-12-28 14-59-49.png -------------------------------------------------------------------------------- /doc/screenshot/Screenshot from 2018-12-28 15-04-27.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexandreDey/ContainerBox/92f196994cce08fd2fba64799c0d59aa8bd81f96/doc/screenshot/Screenshot from 2018-12-28 15-04-27.png -------------------------------------------------------------------------------- /doc/screenshot/Screenshot from 2018-12-28 16-49-56.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexandreDey/ContainerBox/92f196994cce08fd2fba64799c0d59aa8bd81f96/doc/screenshot/Screenshot from 2018-12-28 16-49-56.png -------------------------------------------------------------------------------- /doc/screenshot/Screenshot from 2018-12-28 17-02-17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexandreDey/ContainerBox/92f196994cce08fd2fba64799c0d59aa8bd81f96/doc/screenshot/Screenshot from 2018-12-28 17-02-17.png -------------------------------------------------------------------------------- /doc/screenshot/Screenshot from 2018-12-28 17-22-15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexandreDey/ContainerBox/92f196994cce08fd2fba64799c0d59aa8bd81f96/doc/screenshot/Screenshot from 2018-12-28 17-22-15.png -------------------------------------------------------------------------------- /doc/screenshot/Screenshot from 2018-12-28 17-30-55.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexandreDey/ContainerBox/92f196994cce08fd2fba64799c0d59aa8bd81f96/doc/screenshot/Screenshot from 2018-12-28 17-30-55.png -------------------------------------------------------------------------------- /doc/screenshot/Screenshot from 2018-12-28 17-54-42.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexandreDey/ContainerBox/92f196994cce08fd2fba64799c0d59aa8bd81f96/doc/screenshot/Screenshot from 2018-12-28 17-54-42.png -------------------------------------------------------------------------------- /doc/screenshot/Screenshot from 2018-12-28 17-56-59.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexandreDey/ContainerBox/92f196994cce08fd2fba64799c0d59aa8bd81f96/doc/screenshot/Screenshot from 2018-12-28 17-56-59.png -------------------------------------------------------------------------------- /doc/screenshot/Screenshot_shed-server_2018-12-28_14:16:13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexandreDey/ContainerBox/92f196994cce08fd2fba64799c0d59aa8bd81f96/doc/screenshot/Screenshot_shed-server_2018-12-28_14:16:13.png -------------------------------------------------------------------------------- /doc/screenshot/Screenshot_shed-server_2018-12-28_14:16:57.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexandreDey/ContainerBox/92f196994cce08fd2fba64799c0d59aa8bd81f96/doc/screenshot/Screenshot_shed-server_2018-12-28_14:16:57.png -------------------------------------------------------------------------------- /doc/screenshot/Screenshot_shed-server_2018-12-28_14:20:49.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexandreDey/ContainerBox/92f196994cce08fd2fba64799c0d59aa8bd81f96/doc/screenshot/Screenshot_shed-server_2018-12-28_14:20:49.png -------------------------------------------------------------------------------- /doc/screenshot/Screenshot_shed-server_2018-12-28_14:21:12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexandreDey/ContainerBox/92f196994cce08fd2fba64799c0d59aa8bd81f96/doc/screenshot/Screenshot_shed-server_2018-12-28_14:21:12.png -------------------------------------------------------------------------------- /doc/screenshot/Screenshot_shed-server_2018-12-28_17:38:12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexandreDey/ContainerBox/92f196994cce08fd2fba64799c0d59aa8bd81f96/doc/screenshot/Screenshot_shed-server_2018-12-28_17:38:12.png -------------------------------------------------------------------------------- /doc/screenshot/Screenshot_shed-server_2018-12-28_17:41:09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexandreDey/ContainerBox/92f196994cce08fd2fba64799c0d59aa8bd81f96/doc/screenshot/Screenshot_shed-server_2018-12-28_17:41:09.png -------------------------------------------------------------------------------- /doc/screenshot/Screenshot_shed-server_2018-12-28_17:41:38.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexandreDey/ContainerBox/92f196994cce08fd2fba64799c0d59aa8bd81f96/doc/screenshot/Screenshot_shed-server_2018-12-28_17:41:38.png -------------------------------------------------------------------------------- /doc/screenshot/Screenshot_shed-server_2018-12-28_18:08:08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexandreDey/ContainerBox/92f196994cce08fd2fba64799c0d59aa8bd81f96/doc/screenshot/Screenshot_shed-server_2018-12-28_18:08:08.png -------------------------------------------------------------------------------- /etc/creator/create: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | LXC=/snap/bin/lxc 3 | BASH=/bin/bash 4 | GREP=/bin/grep 5 | CB_CONF=/etc/ContainerBox 6 | 7 | CONFIG_DIR="$CB_CONF/creator" 8 | 9 | function usage { 10 | echo "ContainerBox create --template(-t) DISTRO_NAME --desktop_environment(-d) DE_NAME --name(-n) NAME_OF_BOX --xpra(-x) yes|no --user(-u) USERNAME --password(-p) PASSWORD" 11 | echo "" 12 | echo "--template [-t]: Ditribution template to use (debian, fedora[default], ubuntu or 'vanilla NAME_DISTRO')" 13 | echo "--desktop_environment [-d]: Desktop environment to install (MATE, XFCE[default], GNOME or KDE)" 14 | echo "--name [-n]: Name of the box to create" 15 | echo "--xpra [-x]: Install xpra support (yes or no)" 16 | echo "--user [-u]: Main user that will be created and granted admin access [default: 'main']" 17 | echo "--password [-p]: Password of the newly created user [default: random 16 char password]" 18 | echo "--help [-h]: show this help" 19 | } 20 | 21 | function generate_password { 22 | PWD=$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-16};echo;) 23 | echo $PWD 24 | } 25 | 26 | function finish_setup { 27 | # Passthrough gpu device 28 | $LXC config device add $1 gpu gpu 29 | 30 | # Create the user and set it as a sudoer 31 | $LXC exec $1 -- groupadd sudo 32 | $LXC exec $1 -- groupadd wheel 33 | $LXC exec $1 -- useradd -m $2 -G sudo 34 | $LXC exec $1 -- usermod -a -G wheel $2 35 | 36 | # Change password 37 | $LXC exec $1 -- bash -c "echo -e \"$3\n$3\n\" | passwd $2" 38 | 39 | # Disable autostart by default 40 | $LXC config set $1 boot.autostart false 41 | 42 | } 43 | 44 | if [ "$1" = "help" ]; then 45 | usage $0 46 | exit 47 | fi 48 | 49 | 50 | XPRA='no' 51 | TEMPLATE='fedora' 52 | DE='XFCE' 53 | USER='main' 54 | PASSWORD=$(generate_password) 55 | 56 | 57 | while [[ $# -gt 0 ]] 58 | do 59 | key="$1" 60 | 61 | case $key in 62 | -t|--template) 63 | TEMPLATE="$2" 64 | shift # past argument 65 | shift # past value 66 | ;; 67 | -d|--desktop_environment) 68 | DE="$2" 69 | shift # past argument 70 | shift # past value 71 | ;; 72 | -n|--name) 73 | NAME="$2" 74 | shift # past argument 75 | shift # past value 76 | ;; 77 | -x|--xpra) 78 | if [ "$2" = "yes" ] || [ "$2" = "no" ]; then 79 | XPRA="$2" 80 | else 81 | echo "Unknown value '$2' for parameter $key" 82 | exit 83 | fi 84 | shift # past argument 85 | shift # past value 86 | ;; 87 | -u|--user) 88 | USER="$2" 89 | shift # past argument 90 | shift # past value 91 | ;; 92 | -p|--password) 93 | PASSWORD="$2" 94 | shift # past argument 95 | shift # past value 96 | ;; 97 | *) # unknown option 98 | echo "Unknown parameter '$key' !" 99 | exit 100 | ;; 101 | esac 102 | done 103 | 104 | if [ -z $NAME ]; then 105 | echo "Provide at least the name of the box" 106 | exit 107 | fi 108 | 109 | if [ ! -f "$CONFIG_DIR/templates/$TEMPLATE" ]; then 110 | echo "Template '$TEMPLATE' does not exist. You can create it if you want and place the file in the '$(pwd)/$CONFIG_DIR' folder" 111 | fi 112 | 113 | if [ "$TEMPLATE" != "vanilla" ] && [ "$DE" != "XFCE" ] && [ "$DE" != "MATE" ] && [ "$DE" != "KDE" ] && [ "$DE" != "GNOME" ] && [ "$DE" != "none" ]; then 114 | echo "Desktop Environment $DE is not supported (yet?). You can contact me if you want it to be added." 115 | echo "In the meantime, you can set the Desktop Environment parameter to 'none' and install yours after" 116 | exit 117 | fi 118 | 119 | if [ "$XPRA" = "yes" ]; then 120 | if [ ! -f "$CONFIG_DIR/templates/xpra_$TEMPLATE" ]; then 121 | echo "XPRA is not possible for template $TEMPLATE" 122 | exit 123 | fi 124 | fi 125 | 126 | echo "Creating Box $NAME" 127 | echo "Using template '$TEMPLATE'" 128 | echo "Installing Desktop Environment '$DE'" 129 | echo "Setting $USER as the first user (and sudoer)" 130 | echo "Password will be set to: $PASSWORD" 131 | echo "Installing experimental Xpra support ? $XPRA" 132 | 133 | if [ "$XPRA" = "yes" ]; then 134 | CB_CONF=$CB_CONF $BASH $CONFIG_DIR/templates/xpra_$TEMPLATE $NAME $DE 135 | else 136 | CB_CONF=$CB_CONF $BASH $CONFIG_DIR/templates/$TEMPLATE $NAME $DE 137 | fi 138 | 139 | test=$($LXC list | $GREP " $NAME ") 140 | if [ "$test" = *"$NAME"* ] ; then 141 | echo "[ERROR] : Failed to create container $NAME" 142 | exit 143 | fi 144 | finish_setup $NAME $USER $PASSWORD -------------------------------------------------------------------------------- /etc/creator/import: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | LXC=/snap/bin/lxc 3 | BASH=/bin/bash 4 | GREP=/bin/grep 5 | CUT=/usr/bin/cut 6 | CB_CONF=/etc/ContainerBox 7 | CBOX=/usr/bin/ContainerBox 8 | 9 | CONFIG_DIR="$CB_CONF/creator" 10 | 11 | function generate_password { 12 | PWD=$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-16};echo;) 13 | echo $PWD 14 | } 15 | 16 | function finish_setup { 17 | # Passthrough gpu device 18 | $LXC config device add $1 gpu gpu 19 | 20 | # Create the user and set it as a sudoer 21 | $LXC exec $1 -- groupadd sudo 22 | $LXC exec $1 -- useradd -m $2 -G sudo 23 | 24 | # Change password 25 | $LXC exec $1 -- bash -c "echo -e \"$3\n$3\n\" | passwd $2" 26 | 27 | # Disable autostart by default 28 | $LXC config set $1 boot.autostart false 29 | 30 | } 31 | 32 | USER='admin' 33 | PASSWORD=$(generate_password) 34 | 35 | NAME=$1 36 | CONF=$2 37 | 38 | if [ -z $NAME ]; then 39 | echo "Provide least the name of the box" 40 | exit 41 | fi 42 | 43 | if [ ! -f "$CONF" ]; then 44 | echo "$CONF: No such file" 45 | fi 46 | 47 | XPRA=$($GREP "EnableXpra" $CONF | $CUT -d'=' -f2) 48 | TEMPLATE=$($GREP "Template" $CONF | $CUT -d'=' -f2) 49 | DE=$($GREP "DisplayEnvironment" $CONF | $CUT -d'=' -f2) 50 | 51 | 52 | if [ "$TEMPLATE" != "vanilla" ] && [ "$DE" != "XFCE" ] && [ "$DE" != "MATE" ] && [ "$DE" != "KDE" ] && [ "$DE" != "GNOME" ] && [ "$DE" != "none" ]; then 53 | echo "Desktop Environment $DE is not supported (yet?). You can contact me if you want it to be added." 54 | echo "In the meantime, you can set the Desktop Environment parameter to 'none' and install yours after" 55 | exit 56 | fi 57 | 58 | if [ "$XPRA" = "yes" ]; then 59 | if [ ! -f "$CONFIG_DIR/templates/xpra_$TEMPLATE" ]; then 60 | echo "XPRA is not possible for template $TEMPLATE" 61 | exit 62 | fi 63 | fi 64 | 65 | echo "Creating Box $NAME" 66 | echo "Using template '$TEMPLATE'" 67 | echo "Installing Desktop Environment '$DE'" 68 | echo "Setting $USER as the first user (and sudoer)" 69 | echo "Password will be set to: $PASSWORD" 70 | echo "Installing experimental Xpra support ? $XPRA" 71 | 72 | if [ "$XPRA" = "yes" ]; then 73 | CB_CONF=$CB_CONF $BASH $CONFIG_DIR/templates/xpra_$TEMPLATE $NAME $DE 74 | else 75 | CB_CONF=$CB_CONF $BASH $CONFIG_DIR/templates/$TEMPLATE $NAME $DE 76 | fi 77 | 78 | test=$($LXC list | $GREP " $NAME ") 79 | if [ "$test" = *"$NAME"* ] ; then 80 | echo "[ERROR] : Failed to create container $NAME" 81 | exit 82 | fi 83 | finish_setup $NAME $USER $PASSWORD 84 | 85 | IFS=$'\t\n' 86 | 87 | $CBOX config network $NAME remove eth0 88 | for NIC in $($GREP "NetworkInterface" $CONF | $CUT -d'=' -f2); do 89 | #echo $NIC 90 | IF_NAME=$(echo $NIC | $CUT -d':' -f1) 91 | TYPE=$(echo $NIC | $CUT -d':' -f2 | $CUT -d' ' -f2 | $CUT -d'>' -f2) 92 | HOST_IF=$(echo $NIC | $CUT -d':' -f2 | $CUT -d' ' -f4 | $CUT -d'>' -f2) 93 | ADDR=$(echo $NIC | $CUT -d':' -f2 | $CUT -d' ' -f6 | $CUT -d'>' -f2) 94 | 95 | $CBOX config network $NAME add $IF_NAME $HOST_IF $TYPE $ADDR 96 | done 97 | 98 | IFS=$' \t\n' 99 | 100 | -------------------------------------------------------------------------------- /etc/creator/resources/10_container_box.conf: -------------------------------------------------------------------------------- 1 | [Seat:*] 2 | type=xremote 3 | xserver-display-number=0 4 | -------------------------------------------------------------------------------- /etc/creator/templates/debian: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | LXC=/snap/bin/lxc 4 | CONF="$CB_CONF/creator/resources/10_container_box.conf" 5 | 6 | function create_container { 7 | $LXC launch images:debian/10 $1 8 | echo "Waiting for end of init" 9 | sleep 5 10 | $LXC exec $1 -- ip link set device eth0 up 11 | $LXC exec $1 -- dhclient eth0 12 | } 13 | 14 | function install_de_xfce { 15 | $LXC exec $1 -- apt update 16 | $LXC exec $1 -- apt install -yq task-xfce-desktop 17 | } 18 | 19 | function install_de_kde { 20 | $LXC exec $1 -- apt update 21 | $LXC exec $1 -- apt install -yq task-kde-desktop 22 | } 23 | 24 | function install_de_mate { 25 | $LXC exec $1 -- apt update 26 | $LXC exec $1 -- apt install -yq mate-desktop-environment 27 | } 28 | 29 | function install_de_gnome { 30 | $LXC exec $1 -- apt update 31 | $LXC exec $1 -- apt install -yq gnome 32 | } 33 | 34 | function install_de { 35 | if [ "$2" = "XFCE" ]; then 36 | install_de_xfce $1 37 | fi 38 | if [ "$2" = "KDE" ]; then 39 | install_de_kde $1 40 | fi 41 | if [ "$2" = "MATE" ]; then 42 | install_de_mate $1 43 | fi 44 | if [ "$2" = "GNOME" ]; then 45 | install_de_gnome $1 46 | fi 47 | } 48 | 49 | function finish_install { 50 | $LXC exec $1 -- apt install -yq lightdm 51 | $LXC exec $1 -- apt install -yq sudo 52 | 53 | $LXC exec $1 -- mkdir /etc/lightdm/lightdm.conf.d/ 54 | $LXC file push $CONF $1/etc/lightdm/lightdm.conf.d/ 55 | } 56 | 57 | create_container $1 58 | install_de $1 $2 59 | finish_install $1 -------------------------------------------------------------------------------- /etc/creator/templates/fedora: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | LXC=/snap/bin/lxc 4 | CONF="$CB_CONF/creator/resources/10_container_box.conf" 5 | 6 | function create_container { 7 | $LXC launch images:fedora/28 $1 8 | echo "Waiting for end of init" 9 | sleep 5 10 | $LXC exec $1 -- ip link set device eth0 up 11 | $LXC exec $1 -- dhclient eth0 12 | } 13 | 14 | function install_de_xfce { 15 | $LXC exec $1 -- dnf update -y 16 | $LXC exec $1 -- dnf groupinstall -y xfce 17 | } 18 | 19 | function install_de_kde { 20 | $LXC exec $1 -- dnf update -y 21 | $LXC exec $1 -- dnf groupinstall -y kde 22 | } 23 | 24 | function install_de_mate { 25 | $LXC exec $1 -- dnf update -y 26 | $LXC exec $1 -- dnf groupinstall -y mate 27 | } 28 | 29 | function install_de_gnome { 30 | $LXC exec $1 -- dnf update -y 31 | $LXC exec $1 -- dnf groupinstall -y gnome 32 | } 33 | 34 | function install_de { 35 | if [ "$2" = "XFCE" ]; then 36 | install_de_xfce $1 37 | fi 38 | if [ "$2" = "KDE" ]; then 39 | install_de_kde $1 40 | fi 41 | if [ "$2" = "MATE" ]; then 42 | install_de_mate $1 43 | fi 44 | if [ "$2" = "GNOME" ]; then 45 | install_de_gnome $1 46 | fi 47 | } 48 | 49 | function finish_install { 50 | $LXC exec $1 -- dnf install -y lightdm 51 | $LXC exec $1 -- dnf install -y sudo 52 | 53 | $LXC file push $CONF $1/etc/lightdm/lightdm.conf.d/ 54 | } 55 | 56 | create_container $1 57 | install_de $1 $2 58 | finish_install $1 -------------------------------------------------------------------------------- /etc/creator/templates/ubuntu: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | LXC=/snap/bin/lxc 4 | CONF="$CB_CONF/creator/resources/10_container_box.conf" 5 | 6 | function create_container { 7 | $LXC launch ubuntu:cosmic $1 8 | echo "Waiting for end of init" 9 | sleep 5 10 | $LXC exec $1 -- ip link set device eth0 up 11 | $LXC exec $1 -- dhclient eth0 12 | } 13 | 14 | function install_de_xfce { 15 | $LXC exec $1 -- apt update 16 | $LXC exec $1 -- apt install -yq xubuntu-desktop 17 | } 18 | 19 | function install_de_kde { 20 | $LXC exec $1 -- apt update 21 | $LXC exec $1 -- apt install -yq kubuntu-desktop 22 | } 23 | 24 | function install_de_mate { 25 | $LXC exec $1 -- apt update 26 | $LXC exec $1 -- apt install -yq ubuntu-mate-desktop 27 | } 28 | 29 | function install_de_gnome { 30 | $LXC exec $1 -- apt update 31 | $LXC exec $1 -- apt install -yq ubuntu-desktop 32 | } 33 | 34 | function install_de { 35 | if [ "$2" = "XFCE" ]; then 36 | install_de_xfce $1 37 | fi 38 | if [ "$2" = "KDE" ]; then 39 | install_de_kde $1 40 | fi 41 | if [ "$2" = "MATE" ]; then 42 | install_de_mate $1 43 | fi 44 | if [ "$2" = "GNOME" ]; then 45 | install_de_gnome $1 46 | fi 47 | } 48 | 49 | function finish_install { 50 | $LXC exec $1 -- apt install -yq lightdm lightdm-gtk-greeter 51 | $LXC exec $1 -- apt install -yq sudo 52 | 53 | # Bug with numlockx that crashes lighdm on startup 54 | $LXC exec $1 -- rm /usr/share/lightdm/lightdm.conf.d/50-xubuntu-numlock.conf 55 | 56 | $LXC exec $1 -- mkdir /etc/lightdm/lightdm.conf.d/ 57 | $LXC file push $CONF $1/etc/lightdm/lightdm.conf.d/ 58 | $LXC exec $1 -- bash -c "echo 'greeter-session=lightdm-gtk-greeter' >> /etc/lightdm/lightdm.conf.d/10_container_box.conf" 59 | 60 | } 61 | 62 | create_container $1 63 | install_de $1 $2 64 | finish_install $1 -------------------------------------------------------------------------------- /etc/creator/templates/vanilla: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | LXC=/snap/bin/lxc 4 | 5 | $LXC launch images:$2 $1 -------------------------------------------------------------------------------- /etc/creator/templates/xpra_fedora: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | LXC=/snap/bin/lxc 4 | TEMPLATES="templates" 5 | BASH=/bin/bash 6 | 7 | CB_CONF=$CB_CONF $BASH $TEMPLATES/fedora $@ 8 | 9 | $LXC exec $1 -- dnf install xpra -------------------------------------------------------------------------------- /etc/creator/templates/xpra_ubuntu: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | LXC=/snap/bin/lxc 4 | TEMPLATES="templates" 5 | BASH=/bin/bash 6 | 7 | $BASH $TEMPLATES/ubuntu $@ 8 | 9 | $LXC exec $1 -- apt install xpra -------------------------------------------------------------------------------- /etc/host/config: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | 3 | LXC=/snap/bin/lxc 4 | CUT=/usr/bin/cut 5 | WC=/usr/bin/wc 6 | AWK=/usr/bin/awk 7 | CAT=/bin/cat 8 | GREP=/bin/grep 9 | 10 | 11 | 12 | 13 | ######### NETWORK ######### 14 | 15 | function create_lxdNAT_network { 16 | DEVICE_HOST_NAME=$1 17 | IP=$2 18 | # device already exists ? 19 | test=$($LXC network show $DEVICE_HOST_NAME) 20 | if [ -z "$test" ]; then 21 | $LXC network create $DEVICE_HOST_NAME ipv4.address=$IP 22 | else 23 | test=$($LXC network show $DEVICE_HOST_NAME | $GREP "ipv4.nat: \"true\"") 24 | if [ -z "$test" ]; then 25 | echo "[ERROR] : network $DEVICE_HOST_NAME already exists but it's not a NATed interface, can't use it as a NATed bridge" 26 | return 27 | fi 28 | fi 29 | echo "New internal network bridge $DEVICE_HOST_NAME successfully created" 30 | } 31 | function create_lxd_network { 32 | DEVICE_HOST_NAME=$1 33 | IP=$2 34 | # device already exists ? 35 | test=$($LXC network show $DEVICE_HOST_NAME) 36 | if [ -z "$test" ]; then 37 | $LXC network create $DEVICE_HOST_NAME ipv4.address=$IP ipv4.nat=false 38 | else 39 | test=$($LXC network show $DEVICE_HOST_NAME | $GREP "ipv4.nat: \"false\"") 40 | if [ -z "$test" ]; then 41 | echo "[ERROR] : network $DEVICE_HOST_NAME already exists but it's a NATed interface, can't use it as an internal only bridge" 42 | return 43 | fi 44 | fi 45 | echo "New network bridge $DEVICE_HOST_NAME successfully created" 46 | } 47 | 48 | 49 | # Profile based not the preferred way 50 | function create_macvlan_interface { 51 | DEVICE_HOST_NAME=$1 52 | DEVICE_CONTAINER_NAME=$2 53 | PROFILE_NAME="$1_macvlan" 54 | # profile already exists ? 55 | test=$($LXC profile list | $GREP $PROFILE_NAME) 56 | if [ -z "$test" ]; then 57 | $LXC profile copy default $PROFILE_NAME 58 | test=$($LXC profile show $PROFILE_NAME | $GREP "$DEVICE_CONTAINER_NAME") 59 | if [ -z "$test" ]; then 60 | # The nic is not present in the config, create it 61 | $LXC profile device add $PROFILE_NAME $DEVICE_CONTAINER_NAME nic nictype=macvlan parent=$DEVICE_HOST_NAME 62 | else 63 | # It is there, update it 64 | $LXC profile device set $PROFILE_NAME $DEVICE_CONTAINER_NAME nictype macvlan 65 | $LXC profile device set $PROFILE_NAME $DEVICE_CONTAINER_NAME parent $DEVICE_HOST_NAME 66 | fi 67 | fi 68 | } 69 | 70 | function network_add { 71 | CONTAINER_NAME=$1 72 | DEVICE_CONTAINER_NAME="eth0" 73 | DEVICE_HOST_NAME="lxdbr0" 74 | TYPE="lxdNAT" 75 | IP="10.0.2.1/24" 76 | 77 | if [ -z "$1" ] || [ "none" = "$1" ]; then 78 | echo "[ERROR] : Container name mandatory" 79 | return 80 | fi 81 | if [ ! -z "$2" ] || [ "none" != "$2" ]; then 82 | DEVICE_CONTAINER_NAME=$2 83 | fi 84 | if [ ! -z "$3" ] || [ "none" != "$3" ]; then 85 | DEVICE_HOST_NAME=$3 86 | fi 87 | if [ ! -z "$4" ] || [ "none" != "$4" ]; then 88 | TYPE=$4 89 | fi 90 | if [ ! -z "$5" ] || [ "none" != "$5" ]; then 91 | IP=$5 92 | fi 93 | 94 | if [ "$TYPE" = "lxdNAT" ]; then 95 | 96 | create_lxdNAT_network $DEVICE_HOST_NAME $IP 97 | 98 | # Already attached ? 99 | test=$($LXC network show $DEVICE_HOST_NAME | $GREP "$CONTAINER_NAME") 100 | if [ -z "$test" ]; then 101 | $LXC network attach $DEVICE_HOST_NAME $CONTAINER_NAME $DEVICE_CONTAINER_NAME 102 | else 103 | echo "[ERROR] : $DEVICE_HOST_NAME already attached to $CONTAINER_NAME" 104 | fi 105 | 106 | fi 107 | 108 | if [ "$TYPE" = "lxd" ]; then 109 | create_lxd_network $DEVICE_HOST_NAME $IP 110 | 111 | # Already attached ? 112 | test=$($LXC network show $DEVICE_HOST_NAME | $GREP "$CONTAINER_NAME") 113 | if [ -z "$test" ]; then 114 | $LXC network attach $DEVICE_HOST_NAME $CONTAINER_NAME $DEVICE_CONTAINER_NAME 115 | fi 116 | fi 117 | 118 | # Create a macvlan on an existing interface 119 | if [ "$TYPE" = "macvlan" ]; then 120 | #create_macvlan_interface $DEVICE_HOST_NAME $DEVICE_CONTAINER_NAME 121 | #$LXC profile assign $CONTAINER_NAME "$DEVICE_HOST_NAME_macvlan" 122 | $LXC config device add $CONTAINER_NAME $DEVICE_CONTAINER_NAME nic nictype=macvlan parent=$DEVICE_HOST_NAME 123 | fi 124 | 125 | # Passthrough a NIC from the host (can be vETH or physical or anything) 126 | if [ "$TYPE" = "physical" ]; then 127 | $LXC config device add $CONTAINER_NAME $DEVICE_CONTAINER_NAME nic nictype=physical parent=$DEVICE_HOST_NAME 128 | fi 129 | 130 | network_get $CONTAINER_NAME $DEVICE_CONTAINER_NAME 131 | 132 | 133 | } 134 | 135 | function network_remove { 136 | CONTAINER_NAME=$1 137 | DEVICE_CONTAINER_NAME=$2 138 | if [ -z "$1" ] || [ "none" = "$1" ]; then 139 | echo "[ERROR] : Container name mandatory" 140 | return 141 | fi 142 | if [ -z "$2" ] || [ "none" = "$2" ]; then 143 | echo "[ERROR] : Device name in container mandatory" 144 | return 145 | fi 146 | 147 | NICTYPE=$($LXC config show $CONTAINER_NAME --expanded | $GREP "nictype:" -B1 -A2 | $GREP "$DEVICE_CONTAINER_NAME:" -A3 | $GREP "nictype:" | $CUT -d':' -f2 | $CUT -d' ' -f2 ) 148 | 149 | if [ -z "$NICTYPE" ]; then 150 | "[ERROR] : $DEVICE_CONTAINER_NAME is not attached to $CONTAINER_NAME" 151 | return 152 | fi 153 | 154 | if [ "$NICTYPE" = "physical" ] || [ "$NICTYPE" = "macvlan" ]; then 155 | $LXC config device remove $CONTAINER_NAME $DEVICE_CONTAINER_NAME 156 | else 157 | PARENT=$($LXC config show $CONTAINER_NAME --expanded | $GREP "nictype:" -B1 -A2 | $GREP "$DEVICE_CONTAINER_NAME:" -A3 | $GREP "parent:" | $CUT -d':' -f2 | $CUT -d' ' -f2 ) 158 | $LXC network detach $PARENT $CONTAINER_NAME 159 | echo "$DEVICE_CONTAINER_NAME removed from $CONTAINER_NAME" 160 | fi 161 | 162 | 163 | } 164 | 165 | function network_set { 166 | CONTAINER_NAME=$1 167 | DEVICE_CONTAINER_NAME=$2 168 | if [ -z "$1" ] || [ "none" = "$1" ]; then 169 | echo "[ERROR] : Container name mandatory" 170 | return 171 | fi 172 | if [ -z "$2" ] || [ "none" = "$2" ]; then 173 | echo "[ERROR] : Device name in container mandatory" 174 | return 175 | fi 176 | # first remove the old one 177 | network_remove $CONTAINER_NAME $DEVICE_CONTAINER_NAME 178 | 179 | # the add a new one 180 | network_add $@ 181 | } 182 | 183 | function network_get { 184 | if [ -z "$(echo $@)" ];then 185 | echo "- Done -" 186 | return 187 | fi 188 | CONTAINER_NAME=$1 189 | DEVICE_CONTAINER_NAME=$2 190 | if [ -z "$1" ] || [ "none" = "$1" ]; then 191 | echo "[ERROR] : Container name mandatory" 192 | return 193 | fi 194 | if [ -z "$2" ] || [ "none" = "$2" ]; then 195 | echo "[ERROR] : Device name in container mandatory" 196 | return 197 | fi 198 | rawNICTYPE=$($LXC config show $CONTAINER_NAME --expanded | $GREP "nictype:" -B1 -A2 | $GREP "$DEVICE_CONTAINER_NAME:" -A3 | $GREP "nictype:" | $CUT -d':' -f2 | $CUT -d' ' -f2 ) 199 | PARENT=$($LXC config show $CONTAINER_NAME --expanded | $GREP "nictype:" -B1 -A2 | $GREP "$DEVICE_CONTAINER_NAME:" -A3 | $GREP "parent:" | $CUT -d':' -f2 | $CUT -d' ' -f2 ) 200 | 201 | if [ -z "$rawNICTYPE" ]; then 202 | echo "[ERROR] : $DEVICE_CONTAINER_NAME is not attached to $CONTAINER_NAME" 203 | return 204 | fi 205 | 206 | NICTYPE=$rawNICTYPE 207 | IP="N/A" 208 | 209 | if [ "$rawNICTYPE" = "bridged" ];then 210 | 211 | test=$($LXC network show $PARENT | $GREP "ipv4.nat: \"true\"") 212 | if [ ! -z "$test" ]; then 213 | NICTYPE="lxdNAT" 214 | else 215 | NICTYPE="lxd" 216 | fi 217 | 218 | IP=$($LXC network show $PARENT | $GREP "ipv4.address: " | $CUT -d':' -f2 | $CUT -d' ' -f2) 219 | 220 | fi 221 | 222 | echo "$DEVICE_CONTAINER_NAME: type=$NICTYPE -- host_interface=$PARENT -- network_address=$IP" 223 | } 224 | 225 | function network_list { 226 | CONTAINER_NAME=$1 227 | if [ -z "$1" ] || [ "none" = "$1" ] ; then 228 | echo "[ERROR] : Container name mandatory" 229 | return 230 | fi 231 | raw=$($LXC config show $CONTAINER_NAME --expanded | $GREP "nictype:" -B1 | $GREP -v "nictype:") 232 | nb=$($LXC config show $CONTAINER_NAME --expanded | $GREP "nictype:" -B1 | $GREP -v "nictype:" | $WC -l) 233 | for i in $(seq 1 2 $nb); do 234 | NAME=$(echo $raw | $CUT -d' ' -f$i | $CUT -d':' -f1) 235 | network_get "$CONTAINER_NAME" "$NAME" 236 | done 237 | } 238 | 239 | function network_usage { 240 | echo "ContainerBox config network CONTAINER_NAME ACTION [OPTIONS]:" 241 | echo -e "\tlist: list all network interfaces for this container" 242 | echo "" 243 | echo -e "\tget: get information for a particular interface" 244 | echo -e "\t\tContainerBox config network get CONTAINER_NAME INTERFACE_NAME" 245 | echo "" 246 | echo -e "\tset: set configuration for a particular interface" 247 | echo -e "\t\tContainerBox config network set CONTAINER_NAME INTERFACE_NAME [OPTIONS]" 248 | echo "" 249 | echo -e "\tadd: add a new interface to the container" 250 | echo -e "\t\tContainerBox config network add CONTAINER_NAME INTERFACE_NAME HOSTSIDE_NAME INTERFACE_TYPE(-lxdNAT-|lxd|macvlan|physical) NETWORK_IP" 251 | echo -e "\t\t\tlxdNAT: a LXD managed network that is NATed" 252 | echo -e "\t\t\tlxd: a LXD managed network that is NOT NATed (can't communicate with host LAN)" 253 | echo -e "\t\t\tmacvlan: attach a virtual MAC address on a host interface" 254 | echo -e "\t\t\tphysical: passthrough a host interface" 255 | echo "" 256 | echo -e "\tremove: remove an existing interface from the container" 257 | } 258 | 259 | function network { 260 | ACTION=$1 261 | NAME=$2 262 | if [ -z "$1" ] || [ "none" = "$1" ] ; then 263 | network_usage 264 | exit 265 | fi 266 | if [ -z "$2" ] ; then 267 | echo "[ERROR] : Provide a container name" 268 | exit 269 | fi 270 | test=$($LXC list | $GREP " $2 ") 271 | if [ -z "$test" ] ; then 272 | echo "[ERROR] : unknown container $2" 273 | exit 274 | fi 275 | A=($@) 276 | B="${A[@]:2}" 277 | if [ "$ACTION" = "list" ];then 278 | network_list $NAME 279 | elif [ "$ACTION" = "get" ];then 280 | network_get $NAME $B 281 | elif [ "$ACTION" = "set" ];then 282 | network_set $NAME $B 283 | elif [ "$ACTION" = "add" ];then 284 | network_add $NAME $B 285 | elif [ "$ACTION" = "remove" ];then 286 | network_remove $NAME $B 287 | else 288 | echo "Unknown option $ACTION" 289 | fi 290 | 291 | } 292 | 293 | ######### NETWORK ######### 294 | 295 | 296 | ######### SYSTEM ######### 297 | 298 | function system_cpu_exec_cap { 299 | CONTAINER_NAME=$1 300 | LIMIT=$2 301 | if [ -z "$1" ] || [ "none" = "$1" ]; then 302 | echo "[ERROR] : Container name mandatory" 303 | return 304 | fi 305 | if [ -z "$2" ] || [ "none" = "$2" ]; then 306 | echo "[ERROR] : Provide a value to use as limit" 307 | return 308 | fi 309 | re='^[0-9]+$' 310 | if ! [[ $LIMIT =~ $re ]] ; then 311 | echo "[ERROR] : Limit should be a numerical value between 0-100" 312 | return 313 | fi 314 | 315 | $LXC config set $CONTAINER_NAME limits.cpu.allowance "$LIMIT%" 316 | echo "Execution cap of $CONTAINER_NAME set to $LIMIT%" 317 | } 318 | 319 | function system_cpu_cores { 320 | CONTAINER_NAME=$1 321 | LIMIT=$2 322 | if [ -z "$1" ] || [ "none" = "$1" ]; then 323 | echo "[ERROR] : Container name mandatory" 324 | return 325 | fi 326 | if [ -z "$2" ] || [ "none" = "$2" ]; then 327 | echo "[ERROR] : Provide a value to use as limit" 328 | return 329 | fi 330 | re='^[0-9]+$' 331 | if ! [[ $LIMIT =~ $re ]] ; then 332 | echo "[ERROR] : Limit should be a numerical value" 333 | return 334 | fi 335 | $LXC config set $CONTAINER_NAME limits.cpu $LIMIT 336 | echo "Number of cores of $CONTAINER_NAME set to $LIMIT" 337 | } 338 | 339 | function system_cpu_get { 340 | CONTAINER_NAME=$1 341 | if [ -z "$1" ] || [ "none" = "$1" ]; then 342 | echo "[ERROR] : Container name mandatory" 343 | return 344 | fi 345 | EXEC_CAP=$($LXC config show $CONTAINER_NAME | $GREP "limits.cpu.allowance:" | $CUT -d':' -f2 | $CUT -d' ' -f2) 346 | if [ -z "$EXEC_CAP" ];then 347 | EXEC_CAP="100%" 348 | fi 349 | CORES=$($LXC config show $CONTAINER_NAME | $GREP "limits.cpu:" | $CUT -d':' -f2 | $CUT -d' ' -f2) 350 | if [ -z "$CORES" ];then 351 | CORES=$($CAT /proc/cpuinfo | $GREP -e "^processor" | $WC -l) 352 | fi 353 | 354 | echo "$CONTAINER_NAME:" 355 | echo -e "\tNumber of Cores: $CORES" 356 | echo -e "\tExecution Cap: $EXEC_CAP" 357 | 358 | } 359 | 360 | function system_cpu { 361 | CONTAINER_NAME=$1 362 | ACTION=$2 363 | SUBJECT=$3 364 | LIMIT=$4 365 | 366 | if [ -z "$1" ] || [ "none" = "$1" ]; then 367 | echo "[ERROR] : Container name mandatory" 368 | return 369 | fi 370 | if [ -z "$2" ] || [ "none" = "$2" ]; then 371 | echo "[ERROR] : Action type mandatory" 372 | return 373 | fi 374 | 375 | if [ "set" = "$ACTION" ];then 376 | if [ "$SUBJECT" = "cores" ];then 377 | system_cpu_cores $CONTAINER_NAME $LIMIT 378 | elif [ "$SUBJECT" = "exec_cap" ]; then 379 | system_cpu_exec_cap $CONTAINER_NAME $LIMIT 380 | else 381 | echo "[ERROR] : Unknown property '$SUBJECT'" 382 | return 383 | fi 384 | elif [ "get" = "$ACTION" ]; then 385 | system_cpu_get $CONTAINER_NAME 386 | else 387 | echo "[ERROR] : Unknown action '$ACTION'" 388 | return 389 | fi 390 | 391 | } 392 | 393 | function system_memory_max { 394 | CONTAINER_NAME=$1 395 | let MAX="$($GREP MemTotal /proc/meminfo | $AWK '{print $2}') / 1024" 396 | LIMIT=$2 397 | if [ -z "$1" ] || [ "none" = "$1" ]; then 398 | echo "[ERROR] : Container name mandatory" 399 | return 400 | fi 401 | if [ -z "$2" ] || [ "none" = "$2" ]; then 402 | echo "[ERROR] : Provide a value to use as limit" 403 | return 404 | fi 405 | re='^[0-9]+$' 406 | if ! [[ $LIMIT =~ $re ]] ; then 407 | echo "[ERROR] : Limit should be a numerical value (in MB)" 408 | return 409 | fi 410 | if [ "$LIMIT" -gt "$MAX" ]; then 411 | LIMIT=$MAX 412 | fi 413 | $LXC config set $CONTAINER_NAME limits.memory "$LIMIT"MB 414 | echo "Max memory of $CONTAINER_NAME set to $LIMIT MB" 415 | } 416 | 417 | function system_memory_swap { 418 | CONTAINER_NAME=$1 419 | LIMIT=$2 420 | if [ -z "$1" ] || [ "none" = "$1" ]; then 421 | echo "[ERROR] : Container name mandatory" 422 | return 423 | fi 424 | if [ -z "$2" ] || [ "none" = "$2" ]; then 425 | echo "[ERROR] : Provide a value to use as limit" 426 | return 427 | fi 428 | if [ ! "$LIMIT" = "true" ] && [ ! "$LIMIT" = "false" ] ; then 429 | echo "[ERROR] : Value should be 'true' or 'false', not '$LIMIT'" 430 | return 431 | fi 432 | $LXC config set $CONTAINER_NAME limits.memory.swap $LIMIT 433 | echo "Swap for $CONTAINER_NAME set to $LIMIT" 434 | } 435 | 436 | function system_memory_get { 437 | CONTAINER_NAME=$1 438 | if [ -z "$1" ] || [ "none" = "$1" ]; then 439 | echo "[ERROR] : Container name mandatory" 440 | return 441 | fi 442 | MAX_MEM=$($LXC config show $CONTAINER_NAME | $GREP "limits.memory:" | $CUT -d':' -f2 | $CUT -d' ' -f2) 443 | if [ -z "$MAX_MEM" ];then 444 | let MAX_MEM="$($GREP MemTotal /proc/meminfo | $AWK '{print $2}') / 1024" 445 | fi 446 | SWAP=$($LXC config show $CONTAINER_NAME | $GREP "limits.memory.swap:" | $CUT -d':' -f2 | $CUT -d' ' -f2) 447 | if [ -z "$SWAP" ];then 448 | SWAP="true" 449 | fi 450 | 451 | echo "$CONTAINER_NAME:" 452 | echo -e "\tMaximum Memory: $MAX_MEM" 453 | echo -e "\tSwap Enabled: $SWAP" 454 | 455 | } 456 | 457 | function system_memory { 458 | CONTAINER_NAME=$1 459 | ACTION=$2 460 | SUBJECT=$3 461 | LIMIT=$4 462 | 463 | if [ -z "$1" ] || [ "none" = "$1" ]; then 464 | echo "[ERROR] : Container name mandatory" 465 | return 466 | fi 467 | if [ -z "$2" ] || [ "none" = "$2" ]; then 468 | echo "[ERROR] : Action type mandatory" 469 | return 470 | fi 471 | 472 | if [ "set" = "$ACTION" ];then 473 | if [ "$SUBJECT" = "max" ];then 474 | system_memory_max $CONTAINER_NAME $LIMIT 475 | elif [ "$SUBJECT" = "swap" ]; then 476 | system_memory_swap $CONTAINER_NAME $LIMIT 477 | else 478 | echo "[ERROR] : Unknown property '$SUBJECT'" 479 | return 480 | fi 481 | elif [ "get" = "$ACTION" ]; then 482 | system_memory_get $CONTAINER_NAME 483 | else 484 | echo "[ERROR] : Unknown action '$ACTION'" 485 | return 486 | fi 487 | } 488 | 489 | function system_usage { 490 | echo "ContainerBox config system CONTAINER_NAME CATEGORY(cpu|memory) ACTION [OPTIONS]:" 491 | echo 'ACTION:' 492 | echo -e "\tget: get current limits" 493 | echo "" 494 | echo -e "\tset: set new limit" 495 | echo -e "\t\tContainerBox config system CONTAINER_NAME CATEGORY(cpu|memory) set SUBJECT LIMIT" 496 | echo -e "\t\tSUBJECT for memory:" 497 | echo -e "\t\t\tmax: maximum amount of RAM in MB" 498 | echo -e "\t\t\tswap: enable (true) or disable(false) swap" 499 | echo -e "\t\tSUBJECT for cpu:" 500 | echo -e "\t\t\tcores: maximum number of cpu cores" 501 | echo -e "\t\t\texec_cap: max percentage of cpu usage if resources are required" 502 | } 503 | 504 | function system { 505 | CONTAINER_NAME=$1 506 | CATEGORY=$2 507 | ACTION=$3 508 | SUBJECT=$4 509 | LIMIT=$5 510 | 511 | if [ -z "$1" ] || [ "none" = "$1" ]; then 512 | system_usage 513 | return 514 | fi 515 | test=$($LXC list | $GREP "| $1 ") 516 | if [ -z "$test" ] ; then 517 | echo "[ERROR] : unknown container $1" 518 | return 519 | fi 520 | 521 | if [ "cpu" = "$CATEGORY" ];then 522 | system_cpu $CONTAINER_NAME $ACTION $SUBJECT $LIMIT 523 | elif [ "memory" = "$CATEGORY" ]; then 524 | system_memory $CONTAINER_NAME $ACTION $SUBJECT $LIMIT 525 | else 526 | echo "[ERROR] : Unknown category '$CATEGORY'" 527 | return 528 | fi 529 | } 530 | 531 | ######### SYSTEM ######### 532 | 533 | ######### SHARED FOLDER ######### 534 | MD5=/usr/bin/md5sum 535 | SETFACL=/usr/bin/setfacl 536 | SF_DIR=/home/$USER/.ContainerBox/shared_folder 537 | MKDIR=/bin/mkdir 538 | LXC_USER=$($GREP "lxd" /etc/subuid | $CUT -d':' -f2) 539 | 540 | function shared_folder_add { 541 | CONTAINER_NAME=$1 542 | FOLDER=$2 543 | CONTAINER_FOLDER=$3 544 | PERMS="rw-" 545 | 546 | if [ -z "$1" ] || [ "none" = "$1" ]; then 547 | echo "[ERROR] : Container name mandatory" 548 | return 549 | fi 550 | if [ -z "$2" ] || [ ! -d "$FOLDER" ]; then 551 | echo "[ERROR] : Cannot share '$FOLDER', no such directory" 552 | return 553 | fi 554 | if [ -z "$3" ];then 555 | echo "[ERROR] : Folder name inside container mandatory" 556 | return 557 | fi 558 | if [ ! -z "$4" ];then 559 | PERMS=$4 560 | fi 561 | if [ ! -z $($GREP "$CONTAINER_NAME:$FOLDER" "$SF_DIR/list") ];then 562 | echo "[ERROR] : Folder '$FOLDER' already shared with $CONTAINER_NAME" 563 | return 564 | fi 565 | 566 | NAME=$(echo "$FOLDER" | $MD5 | $CUT -d' ' -f1) 567 | 568 | 569 | # Set ACL so that root in container can use the directory 570 | $SETFACL -Rm user:lxd:rwx,default:user:lxd:rwx,user:$LXC_USER:$PERMS,default:group:$LXC_USER:$PERMS $FOLDER 571 | # keep track of all shared folders 572 | echo "$CONTAINER_NAME:$FOLDER:$PERMS" >> "$SF_DIR/list" 573 | 574 | $LXC config device add $CONTAINER_NAME $NAME disk source=$FOLDER path=$CONTAINER_FOLDER 575 | 576 | } 577 | 578 | function shared_folder_remove { 579 | CONTAINER_NAME=$1 580 | FOLDER=$2 581 | 582 | if [ -z "$1" ] || [ "none" = "$1" ]; then 583 | echo "[ERROR] : Container name mandatory" 584 | return 585 | fi 586 | if [ -z "$2" ] || [ ! -d "$FOLDER" ]; then 587 | echo "[ERROR] : Cannot share '$FOLDER', no such directory" 588 | return 589 | fi 590 | NAME=$(echo "$FOLDER" | $MD5 | $CUT -d' ' -f1) 591 | if [ -z $($LXC config device show $CONTAINER_NAME | $GREP "$NAME:") ];then 592 | echo "[ERROR] : '$FOLDER' is not shared with $CONTAINER_NAME" 593 | fi 594 | 595 | # keep track of all shared folders 596 | echo $($GREP -v "$CONTAINER_NAME:$FOLDER" "$SF_DIR/list") > "$SF_DIR/list" 597 | # remove ACL 598 | $SETFACL -bR $FOLDER 599 | # Remove device 600 | $LXC config device remove $CONTAINER_NAME $NAME 601 | 602 | } 603 | 604 | function shared_folder_list { 605 | CONTAINER_NAME=$1 606 | if [ -z "$1" ] || [ "none" = "$1" ]; then 607 | echo "[ERROR] : Container name mandatory" 608 | return 609 | fi 610 | 611 | for LINE in $($GREP "$CONTAINER_NAME:" "$SF_DIR/list"); do 612 | FOLDER=$(echo $LINE | $CUT -d':' -f2) 613 | PERMS=$(echo $LINE | $CUT -d':' -f3) 614 | 615 | echo "$FOLDER <- permissions: $PERMS" 616 | done 617 | } 618 | 619 | 620 | function shared_folder_usage { 621 | echo "ContainerBox config shared_folder CONTAINER_NAME ACTION [OPTIONS]:" 622 | echo 'ACTION:' 623 | echo -e "\tlist: list folders currently shared with container" 624 | echo "" 625 | echo -e "\tadd: share a new folder" 626 | echo -e "\t\tContainerBox config shared_folder CONTAINER_NAME add SOURCE_FOLDER CONTAINER_FOLDER_NAME PERMISSIONS" 627 | echo "" 628 | echo -e "\tremove: unshare a folder" 629 | echo -e "\t\tContainerBox config shared_folder CONTAINER_NAME remove SOURCE_FOLDER" 630 | } 631 | 632 | function shared_folder { 633 | CONTAINER_NAME=$1 634 | ACTION=$2 635 | FOLDER=$3 636 | CONTAINER_FOLDER=$4 637 | PERMS=$5 638 | 639 | if [ -z "$1" ] || [ "none" = "$1" ]; then 640 | shared_folder_usage 641 | return 642 | fi 643 | test=$($LXC list | $GREP "| $1 ") 644 | if [ -z "$test" ] ; then 645 | echo "[ERROR] : unknown container $1" 646 | return 647 | fi 648 | if [ "$ACTION" = "add" ];then 649 | shared_folder_add $CONTAINER_NAME $FOLDER $CONTAINER_FOLDER $PERMS 650 | elif [ "$ACTION" = "remove" ];then 651 | shared_folder_remove $CONTAINER_NAME $FOLDER 652 | elif [ "$ACTION" = "list" ];then 653 | shared_folder_list $CONTAINER_NAME 654 | else 655 | echo "[ERROR] : Unkown action '$ACTION'" 656 | return 657 | fi 658 | 659 | } 660 | 661 | 662 | ######### SHARED FOLDER ######### 663 | 664 | ######### SOUND CARD ######### 665 | 666 | function sound_snd_disable { 667 | CONTAINER_NAME=$1 668 | if [ -z "$1" ] || [ "none" = "$1" ]; then 669 | echo "[ERROR] : Container name mandatory" 670 | return 671 | fi 672 | 673 | for dev in $($LXC config device list $CONTAINER_NAME); do 674 | if [[ $dev = "dev_snd_"* ]]; then 675 | $LXC config device remove $CONTAINER_NAME $dev 676 | fi 677 | done 678 | } 679 | 680 | FIND=/usr/bin/find 681 | function sound_snd_enable { 682 | CONTAINER_NAME=$1 683 | if [ -z "$1" ] || [ "none" = "$1" ]; then 684 | echo "[ERROR] : Container name mandatory" 685 | return 686 | fi 687 | 688 | for dev in $($FIND /dev/snd -maxdepth 1 -type c | $CUT -d'/' -f4); do 689 | $LXC config device add $CONTAINER_NAME "dev_snd_$dev" unix-char source=/dev/snd/$dev path=/dev/snd/$dev 690 | done 691 | $LXC exec $CONTAINER_NAME -- chown -R root:audio /dev/snd/ 692 | } 693 | 694 | RM=/bin/rm 695 | function sound_pa_disable { 696 | CONTAINER_NAME=$1 697 | if [ -z "$1" ] || [ "none" = "$1" ]; then 698 | echo "[ERROR] : Container name mandatory" 699 | return 700 | fi 701 | 702 | PULSE_PATH=~/.ContainerBox/pulse-socket 703 | 704 | $LXC config device remove $1 pulse 705 | $RM $PULSE_PATH 706 | 707 | $LXC exec $CONTAINER_NAME -- sed -i '/PULSE_SERVER/d' /etc/profile 708 | } 709 | 710 | PACTL=/usr/bin/pactl 711 | function sound_pa_enable { 712 | CONTAINER_NAME=$1 713 | if [ -z "$1" ] || [ "none" = "$1" ]; then 714 | echo "[ERROR] : Container name mandatory" 715 | return 716 | fi 717 | 718 | PULSE_PATH=~/.ContainerBox/pulse-socket 719 | 720 | $PACTL load-module module-native-protocol-unix auth-anonymous=1 socket=$PULSE_PATH 721 | $LXC config device add $CONTAINER_NAME pulse proxy connect="unix:$PULSE_PATH" listen="unix:/tmp/pulse_socket" mode=0777 bind=container 722 | 723 | $LXC exec $CONTAINER_NAME -- bash -c "echo 'export PULSE_SERVER=/tmp/pulse_socket' >> /etc/profile" 724 | 725 | } 726 | 727 | 728 | function sound_usage { 729 | echo "ContainerBox config sound CONTAINER_NAME ACTION [OPTIONS]:" 730 | echo 'ACTION:' 731 | echo -e "\tpa_enable: Passthrough host PulseAudio socket to the container (/tmp/pulse_socket)" 732 | echo -e "\tpa_disable: Remove host PulseAudio socket from the container" 733 | echo "" 734 | echo -e "\tsnd_enable: Passthrough the sound cards inside container" 735 | echo -e "\tsnd_disable: Remove the sound cards from the container" 736 | } 737 | function sound { 738 | CONTAINER_NAME=$1 739 | ACTION=$2 740 | if [ -z "$1" ] || [ "none" = "$1" ]; then 741 | echo "[ERROR] : Container name mandatory" 742 | sound_usage 743 | return 744 | fi 745 | if [ -z "$2" ] || [ "none" = "$2" ]; then 746 | echo "[ERROR] : Action name mandatory" 747 | sound_usage 748 | return 749 | fi 750 | if [ "$2" = "snd_enable" ]; then 751 | sound_snd_enable $CONTAINER_NAME 752 | 753 | elif [ "$2" = "snd_disable" ]; then 754 | sound_snd_disable $CONTAINER_NAME 755 | 756 | elif [ "$2" = "pa_enable" ]; then 757 | sound_pa_enable $CONTAINER_NAME 758 | 759 | elif [ "$2" = "pa_disable" ]; then 760 | sound_pa_disable $CONTAINER_NAME 761 | 762 | else 763 | sound_usage 764 | fi 765 | } 766 | 767 | ######### SOUND CARD ######### 768 | 769 | 770 | ## MAIN ## 771 | 772 | function main_usage { 773 | echo "Usage for 'ContainerBox config network':" 774 | network_usage 775 | echo "-----------------------------------" 776 | echo "-----------------------------------" 777 | echo "" 778 | 779 | echo "Usage for 'ContainerBox config system':" 780 | system_usage 781 | echo "-----------------------------------" 782 | echo "-----------------------------------" 783 | echo "" 784 | 785 | echo "Usage for 'ContainerBox config shared_folder':" 786 | shared_folder_usage 787 | echo "-----------------------------------" 788 | echo "-----------------------------------" 789 | echo "" 790 | 791 | echo "Usage for 'ContainerBox config sound':" 792 | sound_usage 793 | echo "-----------------------------------" 794 | echo "-----------------------------------" 795 | echo "" 796 | } 797 | 798 | if [ ! -d "$SF_DIR" ]; then 799 | echo "ContainerBox configuration directory for this user does not exist, creating ..." 800 | $MKDIR -p "$SF_DIR" 801 | fi 802 | 803 | A=($@) 804 | B="${A[@]:1}" 805 | 806 | if [ "$1" = "network" ];then 807 | network $B 808 | elif [ "$1" = "system" ];then 809 | system $B 810 | elif [ "$1" = "shared_folder" ];then 811 | shared_folder $B 812 | elif [ "$1" = "sound" ];then 813 | sound $B 814 | elif [ "$1" = "help" ];then 815 | main_usage 816 | else 817 | echo "Unknown action $1" 818 | 819 | main_usage 820 | 821 | fi -------------------------------------------------------------------------------- /etc/host/runapp: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | KWIN='/usr/bin/kwin_wayland --windowed --xwayland' 4 | LXC=/snap/bin/lxc 5 | LS=/bin/ls 6 | GREP=/bin/grep 7 | CUT=/usr/bin/cut 8 | RM=/bin/rm 9 | TOUCH=/bin/touch 10 | CBOX=/etc/ContainerBox 11 | XWAYLAND=/usr/bin/Xwayland 12 | XHOST=/usr/bin/xhost 13 | LXC_USER=$($GREP "lxd" /etc/subuid | $CUT -d':' -f2) 14 | TAIL=/usr/bin/tail 15 | REV=/usr/bin/rev 16 | 17 | function get_last_display { 18 | str1=$(ls /tmp/.X11-unix/ | tail -n1) 19 | str2="" 20 | 21 | echo "${str1/X/$str2}" 22 | } 23 | 24 | function get_last_user_display { 25 | str1=$(ls -ln /tmp/.X11-unix/ | grep "$UID $UID" | $TAIL -n1 | $REV | $CUT -d' ' -f1 | $REV) 26 | str2="" 27 | 28 | echo "${str1/X/$str2}" 29 | } 30 | function get_main_display { 31 | str1=$DISPLAY 32 | str2="" 33 | 34 | echo "${str1/:/$str2}" 35 | } 36 | 37 | 38 | function check_display() { 39 | test=$($LS /run/user/$UID/wayland-$1) 40 | if [ -z "$test" ]; then 41 | echo "False" 42 | return 43 | fi 44 | echo "True" 45 | } 46 | 47 | function sync_clipboard { 48 | X_HOST=$1 49 | XGUEST=$2 50 | GUEST_NAME=$3 51 | APP=$4 52 | WRITE_CLIP="/usr/bin/xclip -selection clipboard -in" 53 | READ_CLIP="/usr/bin/xclip -selection clipboard -out" 54 | 55 | COMMON_CLIP=' ' 56 | CLIP_SYNC_PID=$PID 57 | echo "Starting Clipboard Sync" 58 | while [ -f ~/.clip_sync ]; do 59 | HOST_CLIP=$(DISPLAY=:$X_HOST $READ_CLIP) 60 | 61 | # Clipboard has been updated by host 62 | if [ ! -z "$HOST_CLIP" ] && [ "$HOST_CLIP" != "$COMMON_CLIP" ]; then 63 | COMMON_CLIP="$HOST_CLIP" 64 | # Update guest clipboard 65 | printf "$HOST_CLIP" | DISPLAY=:$XGUEST $WRITE_CLIP 66 | fi 67 | GUEST_CLIP=$(DISPLAY=:$XGUEST $READ_CLIP) 68 | # Clipboard has been updated by guest 69 | if [ ! -z "$GUEST_CLIP" ] && [ "$GUEST_CLIP" != "$COMMON_CLIP" ]; then 70 | COMMON_CLIP=$GUEST_CLIP 71 | # Update host clipboard 72 | printf "$GUEST_CLIP" | DISPLAY=:$X_HOST $WRITE_CLIP 73 | fi 74 | sleep 0.4 75 | done 76 | echo "Ending Clipboard Sync" 77 | } 78 | 79 | function launch_app() { 80 | EXPORT="export XDG_RUNTIME_DIR=/run/user/$UID/" 81 | # if Wayland is passed through 82 | if [[ "$3" == *"WL"* ]]; then 83 | EXPORT="$EXPORT && export XDG_SESSION_TYPE=wayland && export WAYLAND_DISPLAY=wayland-0" 84 | fi 85 | # if X is passed through 86 | if [[ "$3" == *"X"* ]]; then 87 | EXPORT="$EXPORT && export DISPLAY=:0" 88 | fi 89 | # check if uid exists in container 90 | test=$($LXC exec $1 -- getent passwd $UID) 91 | if [ -z "$test" ]; then 92 | # create user 93 | $LXC exec $UID -- useradd ephemeral$UID --uid $UID --create-home --groups video 94 | fi 95 | 96 | # Execute command 97 | $LXC exec $1 -- su --login "$(echo $test | $CUT -d':' -f1)" -c "$EXPORT && $2" 98 | 99 | 100 | if [ -z "$test" ]; then 101 | # Delete ephemeral user 102 | $LXC exec $UID -- userdel ephemeral$UID 103 | fi 104 | 105 | } 106 | 107 | function launch_insecure() { 108 | # if there is a host wayland, passthrough this one instead 109 | # This one is more secure, but Xwayland still is a X server, and thus any client can see whatever happens on the server 110 | if [ "$XDG_SESSION_TYPE" = "wayland" ] && [ ! -z $WAYLAND_DISPLAY ] ; then 111 | # Ensure XDG_RUNTIME_DIR is created and that user has access to it 112 | $LXC exec $1 -- mkdir -p /run/user/$UID/ 113 | $LXC exec $1 -- chown -R $UID:$UID /run/user/$UID/ 114 | 115 | # Passthrough host wayland 116 | $LXC config device add $1 wl0 proxy connect="unix:/run/user/$UID/$WAYLAND_DISPLAY" listen="unix:/run/user/$UID/wayland-0" uid=$UID gid=$UID bind=container 117 | # Passthrough host Xwayland screen 118 | lastX=$(get_main_display) 119 | $LXC config device add $1 Xwl proxy connect="unix:@/tmp/.X11-unix/X$lastX" listen="unix:@/tmp/.X11-unix/X0" bind=container 120 | 121 | launch_app $1 "$2" "XWL" 122 | # Cleanup 123 | $LXC config device remove $1 Xwl 124 | $LXC config device remove $1 wl0 125 | 126 | # No wayland session, passthrough X only. Vastly insecure, Xorg is not safe 127 | else 128 | # Passthrough host Xorg screen 129 | lastX=$(get_main_display) 130 | $LXC config device add $1 X$lastX proxy connect="unix:@/tmp/.X11-unix/X$lastX" listen="unix:@/tmp/.X11-unix/X0" bind=container 131 | 132 | launch_app $1 "$2" "X" 133 | 134 | # Cleanup 135 | $LXC config device remove $1 X$lastX 136 | fi 137 | } 138 | 139 | function launch_secure() { 140 | # Passthrough host wayland display. Wayland is reasonably safe, but not every program is compatible with it 141 | if [ "$XDG_SESSION_TYPE" = "wayland" ] && [ ! -z $WAYLAND_DISPLAY ] ; then 142 | # Ensure XDG_RUNTIME_DIR is created and that user has access to it 143 | $LXC exec $1 -- mkdir -p /run/user/$UID/ 144 | $LXC exec $1 -- chown -R $UID:$UID /run/user/$UID/ 145 | 146 | # Passthrough host wayland 147 | $LXC config device add $1 wl0 proxy connect="unix:/run/user/$UID/$WAYLAND_DISPLAY" listen="unix:/run/user/$UID/wayland-0" uid=$UID gid=$UID bind=container 148 | 149 | launch_app $1 "$2" "WL" 150 | 151 | # Cleanup 152 | $LXC config device remove $1 wl0 153 | 154 | else 155 | >&2 echo "[ERROR]: 'secure' mode requires to be running on a Wayland session. You can still run in 'nested' mode for maximal security" 156 | fi 157 | } 158 | 159 | function launch_nested() { 160 | WIDTH=1200 161 | HEIGHT=600 162 | # Specified width height 163 | if [ ! -z "$3" ];then 164 | WIDTH=$(echo $3 | $CUT -d'x' -f1) 165 | HEIGHT=$(echo $3 | $CUT -d'x' -f2) 166 | fi 167 | if [ "$(check_display $1)" != "True" ]; then 168 | $KWIN -s wayland-$1 --width $WIDTH --height $HEIGHT & 169 | sleep 2 170 | fi 171 | # has the device been created 172 | if [ "$(check_display $1)" != "True" ]; then 173 | >&2 echo "[ERROR]: Cannot create nested Wayland display wayland-$1" 174 | exit 175 | fi 176 | 177 | # Allow access to Xwayland 178 | lastX=$(get_last_user_display) 179 | DISPLAY=:$lastX $XHOST +SI:localuser:lxd 180 | # Ensure XDG_RUNTIME_DIR is created and that user has access to it 181 | $LXC exec $1 -- mkdir -p /run/user/$UID 182 | $LXC exec $1 -- chown -R $UID:$UID /run/user/$UID 183 | 184 | # Cleanup 185 | $LXC config device remove $1 Xwl 186 | $LXC config device remove $1 wl0 187 | 188 | # Passthrough wayland Display 189 | $LXC config device add $1 wl0 proxy connect="unix:/run/user/$UID/wayland-$1" listen="unix:/run/user/$UID/wayland-0" uid=$UID gid=$UID mode=775 bind=container 190 | # Passthrough Xwayland 191 | $LXC config device add $1 Xwl proxy connect="unix:@/tmp/.X11-unix/X$lastX" listen="unix:@/tmp/.X11-unix/X0"bind=container 192 | 193 | # Start clipboard sharing 194 | $TOUCH ~/.clip_sync 195 | sync_clipboard $(get_main_display) $lastX $1 & 196 | 197 | launch_app $1 "$2" "XWL" 198 | 199 | # Stop Clipboard sharing 200 | $RM ~/.clip_sync 201 | 202 | # Cleanup 203 | $LXC config device remove $1 Xwl 204 | $LXC config device remove $1 wl0 205 | KWIN_PID=$(pidof kwin_wayland) 206 | if [ ! -z $KWIN_PID ];then 207 | kill -9 $KWIN_PID 208 | fi 209 | } 210 | 211 | function launch() { 212 | if [ "$3" == "nested" ];then 213 | launch_nested $1 "$2" $4 214 | elif [ "$3" == "insecure" ];then 215 | launch_insecure $1 "$2" 216 | # default to secure 217 | else 218 | launch_secure $1 "$2" 219 | fi 220 | } 221 | 222 | function usage() { 223 | echo "ContainerBox runapp NAME_OF_BOX \"command arg1 arg2 ... argN\" secure(default)|nested|insecure [WIDTHxHEIGHT]" 224 | echo "secure = Passthrough only host Wayland. Requires running a wayland session" 225 | echo "nested = Passthrough a nested kwin_wayland and XWayland. Requires kwin_wayland" 226 | echo "insecure = Passthrough host Wayland (if available) and host Xorg server. Xorg is not secure, an attacker can spy on every input send to the xserver" 227 | echo "--help [-h]: show this help" 228 | } 229 | 230 | NAME=$1 231 | COM=$2 232 | MODE=$3 233 | SIZE=$4 234 | 235 | if [ -z $NAME ]; then 236 | echo "Provide at least the name of the box and the command to execute" 237 | usage $0 238 | exit 239 | fi 240 | 241 | if [ -z "$COM" ]; then 242 | echo "Provide the command to execute" 243 | exit 244 | fi 245 | 246 | if [ -z $MODE ]; then 247 | MODE="secure" 248 | fi 249 | if [ $MODE != "secure" ] && [ $MODE != "insecure" ] && [ $MODE != "nested" ]; then 250 | echo "Mode can only be 'secure', 'nested' or 'insecure', not '$MODE'. Defaulting to 'secure'" 251 | MODE="secure" 252 | fi 253 | 254 | if [ -z $SIZE ]; then 255 | SIZE="1200x600" 256 | fi 257 | if [[ "$SIZE" != *"x"* ]];then 258 | echo "Wrong format for size '$SIZE'. Should be WIDTHxHEIGHT. Defaulting to 1200x600" 259 | SIZE="1200x600" 260 | fi 261 | 262 | if [ "$NAME" = "--help" ] || [ "$NAME" = "-h" ] || [ "$NAME" = "help" ];then 263 | usage $0 264 | exit 265 | fi 266 | 267 | # Check if container exists 268 | testing_life=$($LXC list | $GREP "| $NAME ") 269 | if [ -z "$testing_life" ]; then 270 | echo "$NAME does not exist !" 271 | exit 272 | fi 273 | 274 | # Start container if not running 275 | testing_life=$($LXC list | $GREP "| $NAME " | $GREP "RUNNING") 276 | if [ -z "$testing_life" ]; then 277 | $LXC start $NAME 278 | fi 279 | testing_life=$($LXC list | $GREP "| $NAME " | $GREP "RUNNING") 280 | if [ -z "$testing_life" ]; then 281 | echo "[ERROR] : Unable to start container" 282 | exit 283 | fi 284 | 285 | echo "launch $NAME \"$COM\" $MODE $SIZE" 286 | launch $NAME "$COM" $MODE $SIZE -------------------------------------------------------------------------------- /etc/host/snapshot: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | LXC=/snap/bin/lxc 4 | CUT=/usr/bin/cut 5 | GREP=/bin/grep 6 | MV=/bin/mv 7 | SED=/bin/sed 8 | 9 | function save_state { 10 | CONTAINER_NAME=$1 11 | SNAP_NAME=$2 12 | 13 | if [ -z "$1" ] || [ "none" = "$1" ]; then 14 | echo "[ERROR] : Container name mandatory" 15 | return 16 | fi 17 | 18 | if [ -z "$2" ] || [ "none" = "$2" ]; then 19 | echo "[ERROR] : Snapshot name mandatory" 20 | return 21 | fi 22 | 23 | $LXC snapshot $CONTAINER_NAME $SNAP_NAME --stateful 24 | } 25 | 26 | function restore_state { 27 | CONTAINER_NAME=$1 28 | SNAP_NAME=$2 29 | 30 | if [ -z "$1" ] || [ "none" = "$1" ]; then 31 | echo "[ERROR] : Container name mandatory" 32 | return 33 | fi 34 | 35 | if [ -z "$2" ] || [ "none" = "$2" ]; then 36 | echo "[ERROR] : Snapshot name mandatory" 37 | return 38 | fi 39 | 40 | $LXC restore $CONTAINER_NAME $SNAP_NAME --stateful 41 | } 42 | 43 | function create { 44 | CONTAINER_NAME=$1 45 | SNAP_NAME=$2 46 | 47 | if [ -z "$1" ] || [ "none" = "$1" ]; then 48 | echo "[ERROR] : Container name mandatory" 49 | return 50 | fi 51 | 52 | if [ -z "$2" ] || [ "none" = "$2" ]; then 53 | echo "[ERROR] : Snapshot name mandatory" 54 | return 55 | fi 56 | 57 | $LXC snapshot $CONTAINER_NAME $SNAP_NAME 58 | } 59 | 60 | function restore { 61 | CONTAINER_NAME=$1 62 | SNAP_NAME=$2 63 | 64 | if [ -z "$1" ] || [ "none" = "$1" ]; then 65 | echo "[ERROR] : Container name mandatory" 66 | return 67 | fi 68 | 69 | if [ -z "$2" ] || [ "none" = "$2" ]; then 70 | echo "[ERROR] : Snapshot name mandatory" 71 | return 72 | fi 73 | 74 | $LXC restore $CONTAINER_NAME $SNAP_NAME 75 | } 76 | 77 | function tarball_export { 78 | CONTAINER_NAME=$1 79 | BACKUP_NAME=$2 80 | 81 | if [ -z "$1" ] || [ "none" = "$1" ]; then 82 | echo "[ERROR] : Container name mandatory" 83 | return 84 | fi 85 | 86 | if [ -z "$2" ] || [ "none" = "$2" ]; then 87 | echo "[ERROR] : Backup filename mandatory" 88 | return 89 | fi 90 | 91 | $LXC snapshot $CONTAINER_NAME backup 92 | $LXC publish $CONTAINER_NAME/backup --alias $CONTAINER_NAME-backup --compression none 93 | FINGERPRINT=$($LXC image export $CONTAINER_NAME-backup | $CUT -d' ' -f5) 94 | $lxc image delete $CONTAINER_NAME-backup 95 | $MV "$FINGERPRINT.tar.gz" $BACKUP_NAME 96 | 97 | } 98 | 99 | function import { 100 | CONTAINER_NAME=$1 101 | BACKUP_NAME=$2 102 | 103 | if [ -z "$1" ] || [ "none" = "$1" ]; then 104 | echo "[ERROR] : Container name mandatory" 105 | return 106 | fi 107 | 108 | if [ -z "$2" ] || [ "none" = "$2" ]; then 109 | echo "[ERROR] : Backup filename mandatory" 110 | return 111 | fi 112 | 113 | $LXC image import $BACKUP_NAME --alias $CONTAINER_NAME-backup 114 | $LXC launch $CONTAINER_NAME-backup $CONTAINER_NAME 115 | $LXC image delete $CONTAINER_NAME-backup 116 | } 117 | 118 | function list { 119 | CONTAINER_NAME=$1 120 | if [ -z "$1" ] || [ "none" = "$1" ]; then 121 | echo "[ERROR] : Container name mandatory" 122 | return 123 | fi 124 | LIST=$($LXC info $CONTAINER_NAME | $SED -n -e '/Snapshots:/,$p' | $GREP -v "Snapshots:") 125 | 126 | BACKUP_POINT=$(echo -e "$LIST" | $GREP "(stateless)") 127 | STATEFUL_POINT=$(echo -e "$LIST" | $GREP -v "(stateless)") 128 | 129 | IFS=$'\t\n' 130 | echo "Restore points for $CONTAINER_NAME:" 131 | for backup in $BACKUP_POINT; do 132 | BACK_NAME=$(echo $backup | $CUT -d'(' -f1) 133 | DATE=$(echo $backup | $CUT -d'(' -f2 | $CUT -d')' -f1) 134 | echo "$BACK_NAME - $DATE" 135 | done 136 | echo "Saved sessions for $CONTAINER_NAME:" 137 | for backup in $STATEFUL_POINT; do 138 | BACK_NAME=$(echo $backup | $CUT -d'(' -f1) 139 | DATE=$(echo $backup | $CUT -d'(' -f2 | $CUT -d')' -f1) 140 | echo "$BACK_NAME - $DATE" 141 | done 142 | IFS=$' \t\n' 143 | } 144 | 145 | if [ -z "$1" ] || [ "none" = "$1" ]; then 146 | echo "[ERROR] : Container name mandatory" 147 | return 148 | fi 149 | 150 | function usage { 151 | 152 | echo "ContainerBox snapshot CONTAINER_NAME ACTION [OPTIONS]:" 153 | echo 'ACTION:' 154 | echo -e "\tcreate: Create a backup of CONTAINER_NAME named OPTIONS" 155 | echo -e "\trestore: Restore a backup of CONTAINER_NAME named OPTIONS" 156 | echo "" 157 | echo -e "\tsave_state: Save the current session state of CONTAINER_NAME as OPTIONS" 158 | echo -e "\trestore_state: Restore current session state of CONTAINER_NAME from OPTIONS" 159 | echo "" 160 | echo -e "\texport: Export CONTAINER_NAME as a tarball named OPTIONS" 161 | echo -e "\timport: Import CONTAINER_NAME from a tarball named OPTIONS" 162 | echo "" 163 | echo -e "\tlist: List backup and saved states of CONTAINER_NAME" 164 | } 165 | 166 | if [ "$2" = "create" ]; then 167 | create $1 $3 168 | elif [ "$2" = "restore" ]; then 169 | restore $1 $3 170 | elif [ "$2" = "save_state" ]; then 171 | save_state $1 $3 172 | elif [ "$2" = "restore_state" ]; then 173 | restore_state $1 $3 174 | elif [ "$2" = "export" ]; then 175 | tarball_export $1 $3 176 | elif [ "$2" = "import" ]; then 177 | import $1 $3 178 | elif [ "$2" = "list" ]; then 179 | list $1 180 | else 181 | usage 182 | exit 183 | fi -------------------------------------------------------------------------------- /etc/host/start: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | OPENVT=/bin/openvt 3 | XEPHYR=/usr/bin/Xephyr 4 | XPRA=/usr/bin/xpra 5 | LXC=/snap/bin/lxc 6 | MKDIR=/bin/mkdir 7 | CHMOD=/bin/chmod 8 | CHOWN=/bin/chown 9 | XORG=/usr/bin/Xorg 10 | SUDO=/usr/bin/sudo 11 | CUT=/usr/bin/cut 12 | GREP=/bin/grep 13 | LS=/bin/ls 14 | TTY=/bin/tty 15 | WHOAMI=/bin/whoami 16 | REMOTE_VIEWER=/usr/bin/remote-viewer 17 | 18 | function usage { 19 | echo "ContainerBox start --name(-n) NAME_OF_BOX --fullscreen(-f) yes|no --method(-m) xephyr|xpra|xspice|cli --clipboard(-c) no|DISPLAY" 20 | echo "" 21 | echo "--name [-n]: Name of the box to launch" 22 | echo "--fullscreen [-f]: Launch fullscreen display" 23 | echo "--method [-m]: Share a xephyr display, forward display via xpra, forward display via spice, or open a new terminal window" 24 | echo "--clipboard [-c]: Synchronize guest clipboard and host clipboard specified by DISPLAY" 25 | echo "--help [-h]: show this help" 26 | } 27 | 28 | function get_last_display { 29 | str1=$(ls /tmp/.X11-unix/ | tail -n1) 30 | str2="" 31 | 32 | echo "${str1/X/$str2}" 33 | } 34 | 35 | function get_spice_port { 36 | PORT=5900 37 | while [ "$(nmap localhost -p $PORT | $GREP open)" ]; do 38 | PORT=$(($PORT+1)) 39 | done 40 | echo $PORT 41 | } 42 | function create_xspice { 43 | PORT=$2 44 | # Launch xspice server 45 | $LXC exec $1 -- Xspice --disable-ticketing :0 &>0 & 46 | 47 | echo "Waiting for server creation" 48 | $LXC config device remove $1 spice 49 | $LXC config device add $1 spice proxy listen="tcp:localhost:$PORT" connect="tcp:localhost:5900" bind=host 50 | sleep 2 51 | while [ -z "$(nmap localhost -p $PORT | $GREP open)" ]; do 52 | echo "still closed" 53 | sleep 1 54 | done 55 | } 56 | 57 | function launch_xspice { 58 | PORT=$(get_spice_port) 59 | create_xspice $1 $PORT 60 | $REMOTE_VIEWER spice://localhost:$PORT -t "ContainerBox -- $1" & 61 | } 62 | 63 | function launch_xspice_fullscreen { 64 | PORT=$(get_spice_port) 65 | create_xspice $1 $PORT 66 | $REMOTE_VIEWER spice://localhost:$PORT --full-screen -t "ContainerBox -- $1" & 67 | } 68 | 69 | function sync_clipboard { 70 | XHOST=$1 71 | XGUEST=$2 72 | GUEST_NAME=$3 73 | WRITE_CLIP="/usr/bin/xclip -selection clipboard -in" 74 | READ_CLIP="/usr/bin/xclip -selection clipboard -out" 75 | 76 | COMMON_CLIP=' ' 77 | KEEP_RUNNING=$($LXC exec $GUEST_NAME -- systemctl status lightdm | grep "active (running)") 78 | while [ -z "$KEEP_RUNNING" ]; do 79 | # Wait for lightdm to be started 80 | sleep 0.2 81 | KEEP_RUNNING=$($LXC exec $GUEST_NAME -- systemctl status lightdm | grep "active (running)") 82 | done 83 | echo "Starting Clipboard Sync" 84 | while [ ! -z "$KEEP_RUNNING" ]; do 85 | HOST_CLIP=$(DISPLAY=:$XHOST $READ_CLIP) 86 | 87 | # Clipboard has been updated by host 88 | if [ ! -z "$HOST_CLIP" ] && [ "$HOST_CLIP" != "$COMMON_CLIP" ]; then 89 | COMMON_CLIP="$HOST_CLIP" 90 | # Update guest clipboard 91 | printf "$HOST_CLIP" | DISPLAY=:$XGUEST $WRITE_CLIP 92 | fi 93 | GUEST_CLIP=$(DISPLAY=:$XGUEST $READ_CLIP) 94 | # Clipboard has been updated by guest 95 | if [ ! -z "$GUEST_CLIP" ] && [ "$GUEST_CLIP" != "$COMMON_CLIP" ]; then 96 | COMMON_CLIP=$GUEST_CLIP 97 | # Update host clipboard 98 | printf "$GUEST_CLIP" | DISPLAY=:$XHOST $WRITE_CLIP 99 | fi 100 | sleep 0.4 101 | KEEP_RUNNING=$($LXC exec $GUEST_NAME -- systemctl status lightdm | grep "active (running)") 102 | done 103 | echo "Ending Clipboard Sync" 104 | } 105 | 106 | function check_display() { 107 | test=$($LS /run/user/$UID/ContainerBox-$1) 108 | if [ -z "$test" ]; then 109 | echo "False" 110 | return 111 | fi 112 | echo "True" 113 | } 114 | 115 | function get_first_vt() { 116 | VT=7 117 | CHECK=$(sudo $OPENVT -c $VT -- clear 2>&1 | grep "in use") 118 | while [ ! -z "$CHECK" ];do 119 | VT=$(($VT + 1)) 120 | CHECK=$(sudo $OPENVT -c $VT -- clear 2>&1 | grep "in use") 121 | done 122 | echo $VT 123 | } 124 | 125 | 126 | function create_xorg { 127 | USER=$($WHOAMI) 128 | $SUDO $OPENVT -c $3 -- su --login $USER -c "$XORG :$2 vt$3 -noreset -terminate +extension GLX +extension RANDR +extension RENDER" 129 | 130 | KEEP_RUNNING=$($LXC exec $GUEST_NAME -- systemctl status lightdm | grep "active (running)") 131 | while [ ! -z "$KEEP_RUNNING" ]; do 132 | # Wait for lightdm to be stopped 133 | sleep 0.5 134 | KEEP_RUNNING=$($LXC exec $GUEST_NAME -- systemctl status lightdm | grep "active (running)") 135 | done 136 | $LXC config device remove $1 X$2 137 | } 138 | 139 | function launch_xorg { 140 | last=$(get_last_display) 141 | display=$((last +1)) 142 | VT=$(get_first_vt) 143 | create_xorg $1 $display "$VT" & 144 | sleep 2 145 | 146 | # Ensure it is not already passed through 147 | $LXC config device remove $1 "X$display" 148 | $LXC config device add $1 "X$display" proxy listen="unix:@/tmp/.X11-unix/X0" connect="unix:@/tmp/.X11-unix/X$display" bind=container 149 | 150 | # Start shared clipboard 151 | if [ "$2" != "no" ]; then 152 | sync_clipboard $2 $display $1 & 153 | fi 154 | 155 | echo "Display :$display socket passed to $1" 156 | } 157 | 158 | function create_xephyr { 159 | $XEPHYR ":$2" $3 -glamor -title "ContainerBox -- $1" -screen 1200x800 -br -terminate -noreset +extension GLX +extension RANDR +extension RENDER 160 | wait 161 | # Remove the device once host is disconnected 162 | $LXC config device remove $1 "X$2" 163 | } 164 | 165 | function launch_xephyr { 166 | last=$(get_last_display) 167 | display=$((last +1)) 168 | 169 | create_xephyr $1 $display & 170 | sleep 1 171 | 172 | # Ensure it is not already passed through 173 | $LXC config device remove $1 "X$display" 174 | $LXC config device add $1 "X$display" proxy listen="unix:@/tmp/.X11-unix/X0" connect="unix:@/tmp/.X11-unix/X$display" bind=container 175 | 176 | # Start shared clipboard 177 | if [ "$2" != "no" ]; then 178 | sync_clipboard $2 $display $1 & 179 | fi 180 | 181 | echo "Display :$display socket passed to $1" 182 | } 183 | 184 | function launch_xephyr_fullscreen { 185 | last=$(get_last_display) 186 | display=$((last +1)) 187 | 188 | create_xephyr $1 $display "-fullscreen" & 189 | sleep 1 190 | 191 | # Ensure it is not already passed through 192 | $LXC config device remove $1 "X$display" 193 | $LXC config device add $1 "X$display" proxy listen="unix:@/tmp/.X11-unix/X0" connect="unix:@/tmp/.X11-unix/X$display" bind=container 194 | 195 | # Start shared clipboard 196 | if [ "$2" != "no" ]; then 197 | sync_clipboard $2 $display $1 & 198 | fi 199 | 200 | echo "Display :$display socket passed to $1" 201 | } 202 | 203 | function create_xpra { 204 | # Launch xpra server 205 | $LXC exec $1 -- xpra start-desktop --xvfb="Xorg -noreset +extension GLX +extension RANDR +extension RENDER -logfile ./0.log -config /etc/xpra/xorg.conf :0" --bind-tcp=0.0.0.0:10000 206 | 207 | echo "Waiting for server creation" 208 | $LXC config device remove $1 xpra 209 | $LXC config device add $1 xpra proxy listen="tcp:localhost:10000" connect="tcp:localhost:10000" bind=host 210 | lxdip=$($LXC list | $GREP "| $1 " | $CUT -d'|' -f4 | $CUT -d' ' -f2) 211 | while [ -z "$(nmap $lxdip -p 10000 | $GREP open)" ]; do 212 | echo "still closed" 213 | sleep 1 214 | done 215 | } 216 | 217 | function launch_xpra { 218 | create_xpra $1 219 | lxdip=$($LXC list | $GREP "| $1 " | $CUT -d'|' -f4 | $CUT -d' ' -f2) 220 | xpra attach tcp/localhost:10000 --encoding=rgb --speed=100 & 221 | } 222 | 223 | function launch_xpra_fullscreen { 224 | create_xpra $1 225 | lxdip=$($LXC list | $GREP "| $1 " | $CUT -d'|' -f4 | $CUT -d' ' -f2) 226 | xpra attach tcp/localhost:10000 --encoding=rgb --speed=100 --desktop-fullscreen=True & 227 | } 228 | 229 | function start_lightdm { 230 | $LXC exec $1 -- systemctl start lightdm 231 | } 232 | 233 | function launch_terminal { 234 | if [ -f "/usr/bin/gnome-terminal" ]; then 235 | /usr/bin/gnome-terminal -- /bin/bash -c "lxc exec $1HOST -- bash || sh" 236 | elif [ -f "/usr/bin/tilix" ]; then 237 | /usr/bin/tilix -e lxc exec $1 -- bash || sh 238 | elif [ -f "/usr/bin/konsole" ]; then 239 | /usr/bin/konsole -e lxc exec $1 -- bash || sh 240 | elif [ -f "/usr/bin/xterm" ]; then 241 | /usr/bin/xterm -e lxc exec $1 -- bash || sh 242 | else 243 | echo "[ERROR]: cannot find a supported terminal emulator" 244 | echo "Possible options are gnome-terminal, tilix, konsole and xterm" 245 | echo "If you want the one you are using to be available, please feel free to open an issue" 246 | fi 247 | } 248 | 249 | function launch { 250 | # Ensure Xorg has been stopped 251 | if [ "$2" = "xpra" ]; then 252 | $LXC exec $1 -- killall Xorg 253 | fi 254 | # Ensure Xspice has been stopped 255 | if [ "$2" = "xspice" ]; then 256 | $LXC exec $1 -- killall Xspice 257 | fi 258 | # fullscreen 259 | if [ "$3" = "yes" ] && [ "$2" = "xephyr" ]; then 260 | launch_xephyr_fullscreen $1 $4 261 | fi 262 | if [ "$3" = "yes" ] && [ "$2" = "xpra" ]; then 263 | launch_xpra_fullscreen $1 264 | fi 265 | if [ "$3" = "yes" ] && [ "$2" = "xspice" ]; then 266 | launch_xspice_fullscreen $1 267 | fi 268 | if [ "$3" = "yes" ] && [ "$2" = "xorg" ]; then 269 | launch_xorg $1 $4 270 | fi 271 | # Resizeable window 272 | if [ "$3" = "no" ] && [ "$2" = "xephyr" ]; then 273 | launch_xephyr $1 $4 274 | fi 275 | if [ "$3" = "no" ] && [ "$2" = "xpra" ]; then 276 | launch_xpra $1 277 | fi 278 | if [ "$3" = "no" ] && [ "$2" = "xspice" ]; then 279 | launch_xspice $1 280 | fi 281 | if [ "$3" = "no" ] && [ "$2" = "xorg" ]; then 282 | launch_xorg $1 $4 283 | fi 284 | 285 | if [ "$2" = "cli" ]; then 286 | launch_terminal $1 287 | else 288 | # launch lightdm 289 | start_lightdm $1 290 | fi 291 | 292 | 293 | 294 | } 295 | 296 | METHOD="xephyr" 297 | FULLSCREEN="no" 298 | SHARE_CLIP="no" 299 | 300 | CMD=$0 301 | 302 | while [[ $# -gt 0 ]] 303 | do 304 | key="$1" 305 | 306 | if [ "$1" = "help" ]; then 307 | usage $0 308 | exit 309 | fi 310 | 311 | case $key in 312 | -m|--method) 313 | METHOD="$2" 314 | if [ "$2" = "xephyr" ] || [ "$2" = "xpra" ] || [ "$2" = "xspice" ] || [ "$2" = "xorg" ] || [ "$2" = "cli" ]; then 315 | METHOD="$2" 316 | else 317 | echo "Unknown value '$2' for parameter $key" 318 | exit 319 | fi 320 | shift # past argument 321 | shift # past value 322 | ;; 323 | -f|--fullscreen) 324 | if [ "$2" = "yes" ] || [ "$2" = "no" ]; then 325 | FULLSCREEN="$2" 326 | else 327 | echo "Unknown value '$2' for parameter $key" 328 | exit 329 | fi 330 | shift # past argument 331 | shift # past value 332 | ;; 333 | -c|--clipboard) 334 | SHARE_CLIP="$2" 335 | shift # past argument 336 | shift # past value 337 | ;; 338 | -n|--name) 339 | NAME="$2" 340 | shift # past argument 341 | shift # past value 342 | ;; 343 | -h|--help) 344 | usage $CMD 345 | exit 346 | shift # past argument 347 | shift # past value 348 | ;; 349 | *) # unknown option 350 | usage $CMD 351 | exit 352 | ;; 353 | esac 354 | done 355 | 356 | if [ -z $NAME ]; then 357 | echo "Provide at least the name of the box" 358 | exit 359 | fi 360 | 361 | # Check if container exists 362 | testing_life=$($LXC list | $GREP "| $NAME ") 363 | if [ -z "$testing_life" ]; then 364 | echo "$NAME does not exist !" 365 | exit 366 | fi 367 | 368 | # Start container if not running 369 | testing_life=$($LXC list | $GREP "| $NAME " | $GREP "RUNNING") 370 | if [ -z "$testing_life" ]; then 371 | $LXC start $NAME 372 | fi 373 | testing_life=$($LXC list | $GREP "| $NAME " | $GREP "RUNNING") 374 | if [ -z "$testing_life" ]; then 375 | echo "[ERROR] : Unable to start container" 376 | exit 377 | fi 378 | 379 | launch $NAME $METHOD $FULLSCREEN $SHARE_CLIP 380 | -------------------------------------------------------------------------------- /example.cbox: -------------------------------------------------------------------------------- 1 | Template=vanilla 2 | DisplayEnvironment=alpine/edge 3 | EnableXpra=no 4 | 5 | NetworkInterface=eth0: type>lxdNAT -- host_interface>lxdbr0 -- network_address>10.238.125.1/24 6 | NetworkInterface=eth1: type>lxd -- host_interface>internalbr0 -- network_address>10.10.10.1/24 -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | current_user=$USER 4 | 5 | # Copying wrapper 6 | sudo cp ./bin/ContainerBox /usr/bin/ 7 | sudo chmod 755 /usr/bin/ContainerBox 8 | 9 | # Creating config dir 10 | sudo mkdir -p /etc/ContainerBox/ 11 | sudo cp -R ./etc/creator /etc/ContainerBox/ 12 | sudo cp -R ./etc/host /etc/ContainerBox/ 13 | sudo chmod 755 -R /etc/ContainerBox/ 14 | 15 | 16 | # Add current user to the container box group 17 | sudo groupadd containerbox 18 | sudo usermod -a -G containerbox $current_user --------------------------------------------------------------------------------