├── .github └── ISSUE_TEMPLATE │ └── bug_report.md ├── .gitignore ├── LICENSE ├── README.md ├── bwrapinfo.json ├── config ├── example.webp ├── flatpak-info ├── open.sh ├── portable-helper.sh ├── portable-pools └── portable.sh /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: "[Bug] " 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | - [ ] I have updated to the latest commit of portable and the issue still presents. 11 | 12 | **Describe the bug** 13 | A clear and concise description of what the bug is. 14 | 15 | **To Reproduce** 16 | Steps to reproduce the behavior: 17 | 1. Go to '...' 18 | 2. Click on '....' 19 | 3. Scroll down to '....' 20 | 4. See error 21 | 22 | **Expected behavior** 23 | A clear and concise description of what you expected to happen. 24 | 25 | **Screenshots** 26 | If applicable, add screenshots to help explain your problem. 27 | 28 | **Desktop (please complete the following information):** 29 | - Desktop Environment or WM: 30 | - Compositor: 31 | - Portal Implementation: 32 | 33 | **Additional context** 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pkg.tar.zst 2 | src/ 3 | pkg/ 4 | portable/ 5 | -------------------------------------------------------------------------------- /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 | # What is this 2 | Portable is a sandbox framework targeted for Desktop usage and offers ease of use for distro packagers, which should work on any FHS compliant system. It offers many useful features for users and packagers: 3 | 4 | - Background Portal support. 5 | - Wayland Security Context support. 6 | - Access Control: Limits what the application can see, write and modify. Sandboxed applications are self-contained. 7 | - Sharing files with the application, even if it doesn't support portals. portable creates a directory within the sandbox home to contain shared files. 8 | - D-Bus filtering & accessibility support: Cuts off unneeded D-Bus messages thus eliminates the possibility to locate, spawn a process outside of the sandbox, mess with the host system and other possible exploits. 9 | - Process Management: Monitors running processes and quit them with one click. 10 | - Packaging Friendly as portable only requires a config file to function. 11 | - Storage efficient compared to Flatpak: Using host system as the "runtime". 12 | - Hybrid GPU workarounds are automatically applied to prevent waking up discrete GPUs, often caused by Vulkan and Electron applications. 13 | - Input Method automatic detection. 14 | 15 | ## Available for 16 | 17 | - [Minecraft](https://github.com/Kimiblock/moeOS.config/blob/master/usr/bin/mcLaunch) 18 | - AUR 19 | - WeChat (aur/wechat) 20 | - Wemeet (aur/wemeet-bwrap) 21 | - Prism Launcher (aur/prismlauncher-bwrap) 22 | - Obsidian (aur/obsidian-bwrap) 23 | - Z-Library (aur/z-library-bwrap) 24 | - Wiliwili (aur/wiliwili-wayland) 25 | - WPS (aur/wps-office-cn-bwrap) 26 | - Genshin Impact Launcher 27 | - Bottles (aur/bottles-bwrap) 28 | - QQ (aur/linuxqq-portable) 29 | - Discord (aur/discord-bwrap) 30 | - Larksuite (aur/larksuite-portable) 31 | - Firefox (aur/firefox-portable) 32 | 33 | # Limitations: 34 | 35 | 1. **Running untrusted code is never safe, sandboxing does not change this.** 36 | 2. WebKitGTK on a hybrid graphics laptop may require `gameMode=on`, otherwise may display a blank screen. 37 | 3. Steam will not work due to the requirement of Flatpak spawn portal. 38 | 4. ~~Some applications directly calling the open file portal or `FileManager1` will not be path-translated by portable, resulting in broken open function.~~ 39 | 5. On KDE Plasma window grouping may not work properly unless your desktop file name exactly matches certain arguments. 40 | 6. The USB Portal is not fully tested, it may fail on some devices. 41 | 7. Due to some desktop portal implementations being insecure (without requiring user consent), some features will only be available on GNOME 42 | - The Screenshot and Global Shortcuts portals are only available on GNOME 43 | 44 | Discuss Development at [#portable-dev:matrix.org](https://matrix.to/#/#portable-dev:matrix.org) 45 | 46 |

47 | The Portable Project 48 |
49 | Demo 50 |
51 |

52 | 53 | --- 54 | 55 | # File installment 56 | 57 | ## Portable 58 | 59 | Install aur/portable-git, aur/portable or install the following files directly 60 | 61 | ``` 62 | install -Dm755 portable.sh /usr/bin/portable 63 | install -Dm755 open.sh /usr/lib/portable/open 64 | install -Dm755 portable-pools /usr/bin/portable-pools 65 | install -Dm755 flatpak-info /usr/lib/portable/flatpak-info 66 | install -Dm755 bwrapinfo.json /usr/lib/portable/bwrapinfo.json 67 | install -Dm755 portable-helper.sh /usr/lib/portable/helper 68 | ``` 69 | 70 | ## Configurations 71 | 72 | 1. Download the config file from [here](https://raw.githubusercontent.com/Kraftland/portable/refs/heads/master/config) and modify it. 73 | 74 | 2. Install the config file: 75 | 76 | ```bash 77 | # Modify before installing 78 | install -Dm755 config /usr/lib/portable/info/${appID}/config 79 | ``` 80 | 81 | ### Modifying the .desktop entry 82 | 83 | - The file name of your .desktop file **must** match the appID, like `top.kimiblock.example.desktop` 84 | 85 | - Your .desktop file *should* contain the following entries: 86 | 87 | ``` 88 | X-Flatpak-Tags=aTag; 89 | X-Flatpak=appID; 90 | X-Flatpak-RenamedFrom=previousName.desktop; 91 | ``` 92 | 93 | ## Environment Variables 94 | 95 | Environment variables are sourced from `XDG_DATA_HOME/stateDirectory/portable.env`. 96 | 97 | You can also specify environment variables in the config file. 98 | 99 | ## Starting portable 100 | 101 | Start portable with environment variable `_portableConfig`, which can be 1) the appID of the sandbox, 2) an absolute path (if exists), 3) a file name interpreted as `$(pwd)/${_portableConfig}`. It searches for each of them respectively. 102 | 103 | - Debugging output can be enabled using a environment variable `PORTABLE_LOGGING=debug` 104 | 105 | ### Launching multiple instances 106 | 107 | Portable itself allows multiple instances. It automatically creates an identical sandbox and launches the application. Application itself may or may not support waking up itself. It is advised to set `SingleMainWindow=true` for applications that doesn't have well multi-instance support. 108 | 109 | ### CLI arguments 110 | 111 | `--actions f5aaebc6-0014-4d30-beba-72bce57e0650`: Toggle Sandbox, requires user confirmation. 112 | 113 | `--actions opendir`: Open the sandbox's home directory. 114 | 115 | `--actions share-files`: Choose multiple files to share with the sandbox. The file will be temporarily stored in `XDG_DATA_HOME/stateDirectory/Shared`, which will be purged each launch. 116 | 117 | `--actions reset-documents`: Resets XDG Desktop Portal's documents portal and other permissions, causing an instant redaction the permission to read & write for sandboxed apps. **Pleased be advised that this is suggested not to be included in desktop actions made by packagers or be executed when there are applications using the documents portal**! 118 | 119 | `--actions quit`: Stop sandbox and D-Bus proxy. If the app fails to stop after 20s, it'll be killed. 120 | 121 | `--actions debug-shell`: Start a debugging bash shell inside the sandbox. This works regardless whether the app is running. 122 | 123 | Arguments for the application can be passed by putting your arguments in the end of the list of arguments and separate it with `--` 124 | 125 | ### Debugging 126 | 127 | #### Entering sandbox 128 | 129 | To manually execute programs instead of following the `launchTarget` config, start portable with argument `--actions debug-shell`. This will open a bash prompt and gives you full control of the sandbox environment. 130 | 131 | 132 | --- 133 | 134 | # Pools 135 | 136 | Pools is a user friendly sandbox generator. To create and enter a user sandbox, simply execute portable-pools with your sandbox name. 137 | 138 | Example: Create a test sandbox: 139 | 140 | ```bash 141 | portable-pools test 142 | 143 | ╰─>Portable Sandbox·top.kimiblock.test·🧐⤔ 144 | ``` 145 | 146 | # Code of Conduct 147 | 148 | Portable and any of its social environment follows the [Kraftland Code of Conduct](https://blog.kimiblock.top/notice/#Code-of-Conduct). Please be sure not to violate such ruleset. 149 | -------------------------------------------------------------------------------- /bwrapinfo.json: -------------------------------------------------------------------------------- 1 | { 2 | "child-pid": placeholderChildPid, 3 | "mnt-namespace": placeholderMntId, 4 | "pid-namespace": placeholderPidId 5 | } 6 | -------------------------------------------------------------------------------- /config: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | 3 | # This is your Application ID, avoid conflict 4 | appID="top.kimiblock.example111" 5 | 6 | # This is a friendly name of an application. It should only contain ASCII characters and not spaces. 7 | friendlyName="Portable_Test" 8 | 9 | # This is the state directory of your application, which is located under "XDG_DATA_HOME" 10 | stateDirectory="Portable_Test_Data" 11 | 12 | # This is the target executable to launch 13 | launchTarget="gtk4-demo" 14 | 15 | # Takes a boolean value or string "adaptive". When true, do not process XAuth files and forces wayland input method. "adaptive" enables this option on Wayland and vice versa. Generally this should be adaptive when possible. 16 | waylandOnly="false" 17 | 18 | # Takes boolean value. 19 | bindInputDevices="false" 20 | 21 | # Takes boolean value. Binds /dev/video* into the sandbox. Required if target application uses /dev/video* interfaces directly instead of v4l2. 22 | bindCameras="false" 23 | 24 | # Takes boolean value. Binds PipeWire socket into the sandbox. Required if target application doesn't use Portals. Please be aware that such operation may impact the integrity of host. 25 | bindPipewire="false" 26 | 27 | # Expose all GPUs. Takes boolean value, usually used in games. 28 | gameMode="false" 29 | 30 | # Wake the application using D-Bus calls towards StatusNotifiers. 31 | dbusWake="false" 32 | 33 | # Enables Network access within the sandbox. Defaults to true. 34 | bindNetwork="true" 35 | 36 | # Use pipewire-v4l2 to replace v4l2. Requires bindPipewire=true! 37 | pwCam="false" 38 | 39 | # Use zink for GL -> Vulkan translation 40 | useZink="false" 41 | 42 | # Enable compatibility workarounds for Qt5. Defaults to true. 43 | qt5Compat="true" 44 | 45 | # Below you can set envs that will be imported into the application sandbox 46 | -------------------------------------------------------------------------------- /example.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kraftland/portable/c4dc8a17f6ecf80a955ecda8c269598b7b3f66ca/example.webp -------------------------------------------------------------------------------- /flatpak-info: -------------------------------------------------------------------------------- 1 | [Application] 2 | name=placeHolderAppName 3 | runtime=runtime/org.kraftland.host/x86_64/1145141919810 4 | 5 | [Instance] 6 | instance-id=placeholderInstanceId 7 | instance-path=placeholderPath 8 | app-path=/usr 9 | app-commit=e894d778d380b02cce56cd42e326b244df8bbf298f06a1e3573a2f32754a0207 10 | runtime-path=/ 11 | runtime-commit=6087f25c76665f35dc9790e60a89f1af2481de9b5c35ee71b9b16a86f388bf3c 12 | runtime-extensions=org.freedesktop.Platform.GL.default=0417ef24351ecbb9208216510d7190ce94aa483f812b713b9b00e4ff5987b968; 13 | branch=stable 14 | arch=x86_64 15 | flatpak-version=1.16.0 16 | session-bus-proxy=true 17 | system-bus-proxy=true 18 | extra-args=--usb-list=;--usb-list=; 19 | 20 | [Context] 21 | shared=network;ipc; 22 | sockets=x11;wayland; 23 | devices=dri; 24 | 25 | [Environment] 26 | IBUS_USE_PORTAL=1 27 | 28 | [USB Devices] 29 | enumerable-devices=all; -------------------------------------------------------------------------------- /open.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function procOpen() { 4 | export link="/proc/$(cat ~/mainPid)/root${origReq}" 5 | } 6 | 7 | if [[ "$@" =~ "https://" ]] || [[ "$@" =~ "http://" ]]; then 8 | echo "[Info] Received a request: $@, interpreting as link" 9 | /usr/lib/flatpak-xdg-utils/xdg-open "$@" 10 | exit $? 11 | fi 12 | 13 | if [[ -e "$1" ]] || [[ -e "$(echo "$1" | sed 's|file:///|/|g')" ]]; then 14 | echo "Arg1: $1" 15 | export origReq="$1" 16 | fi 17 | 18 | if [[ -e "$2" ]] || [[ -e "$(echo "$2" | sed 's|file:///|/|g')" ]]; then 19 | echo "Arg2: $2" 20 | export origReq="$2" 21 | fi 22 | 23 | if [ ${trashAppUnsafe} ]; then 24 | link="${origReq}" 25 | xdg-open "${origReq}" 26 | exit $? 27 | fi 28 | 29 | if [[ $(echo ${origReq} | cut -c '1-8') =~ 'file://' ]]; then 30 | echo "Received a request with file://: ${origReq}" 31 | export origReq="$(echo ${origReq} | sed 's|file:///|/|g')" 32 | echo "Decoding path as: ${origReq}" 33 | else 34 | export origReq=$(realpath "${origReq}") 35 | echo "Interpreting origReq as ${origReq}" 36 | fi 37 | 38 | if [[ "${origReq}" =~ "/tmp" ]]; then 39 | echo "[Info] Detected /tmp!" 40 | procOpen 41 | elif [[ "${origReq}" =~ "/run/user" ]]; then 42 | echo "[Info] Detected run path!" 43 | procOpen 44 | elif [[ "$(dirname "${origReq}")" =~ "${HOME}" ]]; then 45 | echo "[Info] Detected sandbox home" 46 | link="${origReq}" 47 | else 48 | link="${HOME}/Shared/$(basename "${origReq}")" 49 | ln \ 50 | -sfr \ 51 | "${origReq}" ~/Shared/ 52 | fi 53 | 54 | echo "[Info] received a request: $@, translated to ${link}" 55 | echo "[Info] Initiating D-Bus call..." 56 | dbus-send --print-reply --dest=org.freedesktop.FileManager1 \ 57 | /org/freedesktop/FileManager1 \ 58 | org.freedesktop.FileManager1.ShowItems \ 59 | array:string:"file://${link}" \ 60 | string:fake-dde-show-items 61 | 62 | if [[ $? = 0 ]]; then 63 | exit 0 64 | fi 65 | 66 | /usr/lib/flatpak-xdg-utils/xdg-open $(dirname "${link}") 67 | 68 | if [[ $? = 0 ]]; then 69 | exit 0 70 | fi 71 | 72 | 73 | if [ -f /usr/bin/dolphin ] && [ ${XDG_CURRENT_DESKTOP} = KDE ]; then 74 | /usr/bin/dolphin --select "${link}" 75 | elif [ -f /usr/bin/nautilus ] && [ ${XDG_CURRENT_DESKTOP} = GNOME ]; then 76 | /usr/bin/nautilus $(dirname "${link}") 77 | else 78 | xdg-open $(dirname "${link}") 79 | fi 80 | fi 81 | -------------------------------------------------------------------------------- /portable-helper.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | 3 | function waitForStart() { 4 | inotifywait \ 5 | -e modify \ 6 | --quiet \ 7 | /run/startSignal 1>/dev/null 8 | } 9 | 10 | function startLoop() { 11 | while true; do 12 | inotifywait \ 13 | -e modify \ 14 | --quiet \ 15 | /run/startSignal 1>/dev/null 16 | _launch="$(cat /run/startSignal)" 17 | if [[ ${_launch} = terminate ]]; then 18 | break 19 | fi 20 | echo "Starting application" 21 | $(cat /run/startSignal) & 22 | done 23 | } 24 | 25 | echo "app-started" >/run/startSignal 26 | 27 | startLoop & 28 | 29 | waitForStart 30 | 31 | $@ 32 | 33 | if [ $(ps aux | wc -l) = "7" ]; then 34 | echo "No more application running, terminating..." 35 | #kill %1 36 | echo terminate >/run/startSignal 37 | exit 0 38 | else 39 | echo "Warning! There're still processes running in the background." 40 | 41 | _state=$(notify-send --wait --action="kill"="Gracefully Terminate" --action="ignore"="Ignore" "Application running in background!" "Terminate as required") 42 | if [[ ${_state} = "kill" ]]; then 43 | echo "User opted to kill processes" 44 | kill %1 45 | for pid in /proc/[0-9]*; do 46 | pid="${pid#/proc/}" 47 | echo "Terminating process ${pid}" & 48 | if [[ $(cat /proc/${pid}/cmdline | tr '\000' ' ') =~ "/usr/lib/portable/helper" ]] || [[ ${pid} = 1 ]]; then 49 | echo "Skipping self..." 50 | continue 51 | fi 52 | kill "${pid}" & 53 | done 54 | sleep 1s 55 | exit 0 56 | else 57 | echo "User denied termination" 58 | fi 59 | fi -------------------------------------------------------------------------------- /portable-pools: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | 3 | function pecho() { 4 | if [[ $1 =~ debug ]] && [[ ${PORTABLE_LOGGING} = "debug" ]]; then 5 | echo "[Debug] $2" 6 | elif [[ $1 =~ info ]] && [[ ${PORTABLE_LOGGING} = "info" ]] || [[ ${PORTABLE_LOGGING} = "debug" ]]; then 7 | echo "[Info] $2" 8 | elif [[ $1 =~ warn ]]; then 9 | echo "[Warn] $2" 10 | elif [[ $1 =~ crit ]]; then 11 | echo "[Critical] $2" 12 | fi 13 | } 14 | 15 | function cmdlineDispatcher() { 16 | if [ -z "$1" ]; then 17 | pecho crit "Usage: portable-pools [Container Name, only ASCII characters without space allowed]" 18 | fi 19 | } 20 | 21 | function sourceXDG() { 22 | if [[ ! ${XDG_CONFIG_HOME} ]]; then 23 | export XDG_CONFIG_HOME="${HOME}"/.config 24 | pecho debug "Guessing XDG Config Home @ ${XDG_CONFIG_HOME}" 25 | else 26 | source "${XDG_CONFIG_HOME}"/user-dirs.dirs 27 | pecho debug "XDG Config Home defined @ ${XDG_CONFIG_HOME}" 28 | fi 29 | if [[ ! ${XDG_DATA_HOME} ]]; then 30 | export XDG_DATA_HOME="${HOME}"/.local/share 31 | fi 32 | export XDG_DOCUMENTS_DIR="$(xdg-user-dir DOCUMENTS)" 33 | } 34 | 35 | function initialStart() { 36 | sourceXDG 37 | if [ ! -d "${XDG_CONFIG_HOME}"/portable-pools ]; then 38 | pecho info "Welcome to portable-pools" 39 | mkdir -p "${XDG_CONFIG_HOME}"/portable-pools 40 | fi 41 | } 42 | 43 | function generatePortableInfo() { 44 | if [ -f "${XDG_CONFIG_HOME}"/portable-pools/"$1"/config ]; then 45 | pecho debug "Skipping generation" 46 | return 0 47 | fi 48 | pecho debug "Starting generation..." 49 | mkdir -p "${XDG_CONFIG_HOME}"/portable-pools/"$1" 50 | echo '''#!/usr/bin/bash 51 | appID="top.kimiblock.placeHolder" 52 | friendlyName="placeHolder" 53 | stateDirectory="placeHolder_Data" 54 | launchTarget="/usr/bin/bash" 55 | waylandOnly="adaptive" 56 | ''' >"${XDG_CONFIG_HOME}"/portable-pools/"$1"/config 57 | sed -i "s|placeHolder|$1|g" "${XDG_CONFIG_HOME}"/portable-pools/"$1"/config 58 | pecho debug "Generation Done!" 59 | } 60 | 61 | function invokePortable() { 62 | _portableConfig="${XDG_CONFIG_HOME}"/portable-pools/"$1"/config portable 63 | } 64 | 65 | initialStart $@ 66 | cmdlineDispatcher $@ 67 | generatePortableInfo $@ 68 | invokePortable $@ -------------------------------------------------------------------------------- /portable.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function pecho() { 4 | if [[ $1 =~ debug ]] && [[ ${PORTABLE_LOGGING} = "debug" ]]; then 5 | echo "[Debug] $2" & 6 | elif [[ $1 =~ info ]] && [[ ${PORTABLE_LOGGING} = "info" ]] || [[ ${PORTABLE_LOGGING} = "debug" ]]; then 7 | echo "[Info] $2" & 8 | elif [[ $1 =~ warn ]]; then 9 | echo "[Warn] $2" & 10 | elif [[ $1 =~ crit ]]; then 11 | echo "[Critical] $2" & 12 | fi 13 | } 14 | 15 | if [[ ${_portalConfig} ]] && [[ "${_portableConfig}" ]]; then 16 | pecho crit "No portable config specified!" 17 | exit 1 18 | fi 19 | 20 | if [ ${_portalConfig} ]; then 21 | export _portableConfig="${_portalConfig}" 22 | pecho warn "Using legacy configuration variable!" 23 | fi 24 | 25 | if [ -f "${_portableConfig}" ]; then 26 | pecho \ 27 | info \ 28 | "Configuration specified as absolute path: ${_portableConfig}" 29 | source "${_portableConfig}" 30 | else 31 | if [[ -f "/usr/lib/portable/info/${_portableConfig}/config" ]]; then 32 | pecho \ 33 | info \ 34 | "Configuration specified as global name /usr/lib/portable/info/${_portableConfig}/config" 35 | source "/usr/lib/portable/info/${_portableConfig}/config" 36 | export _portableConfig="/usr/lib/portable/info/${_portableConfig}/config" 37 | elif [[ -f "$(pwd)/${_portableConfig}" ]]; then 38 | pecho \ 39 | info \ 40 | "Configuration specified as relative path ${_portableConfig}" 41 | source "$(pwd)/${_portableConfig}" 42 | export _portableConfig="$(pwd)/${_portableConfig}" 43 | else 44 | pecho \ 45 | crit \ 46 | "Specified config cannot be found!" 47 | exit 1 48 | fi 49 | fi 50 | 51 | busName="${appID}" 52 | busDir="${XDG_RUNTIME_DIR}/app/${busName}" 53 | busDirAy="${XDG_RUNTIME_DIR}/app/${busName}-a11y" 54 | unitName="${friendlyName}" 55 | proxyName="${friendlyName}-dbus" 56 | 57 | function sourceXDG() { 58 | if [[ ! ${XDG_CONFIG_HOME} ]]; then 59 | export XDG_CONFIG_HOME="${HOME}"/.config 60 | pecho info "Guessing XDG Config Home @ ${XDG_CONFIG_HOME}" 61 | else 62 | source "${XDG_CONFIG_HOME}"/user-dirs.dirs 63 | pecho info "XDG Config Home defined @ ${XDG_CONFIG_HOME}" 64 | fi 65 | if [[ ! ${XDG_DATA_HOME} ]]; then 66 | export XDG_DATA_HOME="${HOME}"/.local/share 67 | fi 68 | export XDG_DOCUMENTS_DIR="$(xdg-user-dir DOCUMENTS)" 69 | } 70 | 71 | function manageDirs() { 72 | createWrapIfNotExist "${XDG_DATA_HOME}"/${stateDirectory} 73 | rm -r "${XDG_DATA_HOME}/${stateDirectory}/Shared" 74 | mkdir -p "${XDG_DATA_HOME}/${stateDirectory}/Shared" & 75 | ln -sfr \ 76 | "${XDG_DATA_HOME}/${stateDirectory}/Shared" \ 77 | "${XDG_DATA_HOME}/${stateDirectory}/共享文件" & 78 | } 79 | 80 | function genXAuth() { 81 | rm "${XDG_DATA_HOME}/${stateDirectory}/.XAuthority" 2>/dev/null 82 | if [ ${waylandOnly} = "true" ]; then 83 | touch "${XDG_DATA_HOME}/${stateDirectory}/.XAuthority" & 84 | return $? 85 | elif [ ${waylandOnly} = "adaptive" ] && [ ${XDG_SESSION_TYPE} = "wayland" ]; then 86 | touch "${XDG_DATA_HOME}/${stateDirectory}/.XAuthority" & 87 | return $? 88 | fi 89 | pecho debug "Processing X Server security restriction..." 90 | touch "${XDG_DATA_HOME}/${stateDirectory}/.XAuthority" 91 | pecho debug "Detecting display as ${DISPLAY}" 92 | if [[ $(xauth list ${DISPLAY} | head -n 1) =~ "$(hostnamectl --static)/unix: " ]]; then 93 | pecho warn "Adding new display..." 94 | export authHash="$(xxd -p -l 16 /dev/urandom)" 95 | xauth \ 96 | add \ 97 | "${DISPLAY}" \ 98 | . \ 99 | "${authHash}" 100 | xauth -f \ 101 | "${XDG_DATA_HOME}/${stateDirectory}/.XAuthority" \ 102 | add $(xauth list ${DISPLAY} | head -n 1) 103 | else 104 | xauth -f \ 105 | "${XDG_DATA_HOME}/${stateDirectory}/.XAuthority" \ 106 | add $(xauth list ${DISPLAY} | head -n 1) 107 | fi 108 | if [ ! -f "${HOME}/.XAuthority" ] && [ -z "${XAUTHORITY}" ]; then 109 | pecho warn "Could not determine XAuthority file path" 110 | xhost +localhost 111 | fi 112 | xauth \ 113 | -f "${XDG_DATA_HOME}/${stateDirectory}/.XAuthority" \ 114 | list >/dev/null 115 | if [ $? = 0 ]; then 116 | return 0 117 | else 118 | pecho warn "Turning off X access control for localhost" 119 | xauth +localhost 120 | fi 121 | } 122 | 123 | function waylandDisplay() { 124 | if [ ${XDG_SESSION_TYPE} = x11 ]; then 125 | pecho warn "Running on X11, be warned!" 126 | wayDisplayBind="/$(uuidgen)/$(uuidgen)" 127 | return 0 128 | fi 129 | if [ -z ${WAYLAND_DISPLAY} ]; then 130 | pecho debug "WAYLAND_DISPLAY not set, defaulting to wayland-0" 131 | wayDisplayBind="${XDG_RUNTIME_DIR}/wayland-0" 132 | fi 133 | if [ -f "${WAYLAND_DISPLAY}" ]; then 134 | pecho debug "Wayland display is specified as an absolute path" 135 | export wayDisplayBind="${WAYLAND_DISPLAY}" 136 | elif [[ "${WAYLAND_DISPLAY}" =~ 'wayland-' ]]; then 137 | pecho debug "Detected Wayland display as ${WAYLAND_DISPLAY}" 138 | export wayDisplayBind="${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY}" 139 | fi 140 | waylandContext 141 | } 142 | 143 | function waylandContext() { 144 | if [ -x /usr/bin/wayland-info ] && [ -x /usr/bin/way-secure ]; then 145 | if [[ "${XDG_SESSION_TYPE}" = wayland ]] && [[ "$(/usr/bin/wayland-info)" =~ "wp_security_context_manager_v1" ]]; then 146 | pecho debug "Wayland security context available" 147 | export securityContext=1 148 | export wayDisplayBind="${XDG_RUNTIME_DIR}/portable/${appID}/wayland.sock" 149 | else 150 | pecho warn "Wayland security context not available" 151 | fi 152 | else 153 | pecho warn "Security Context is not available due to missing dependencies" 154 | fi 155 | } 156 | 157 | function createWrapIfNotExist() { 158 | if [ -d "$@" ]; then 159 | return 0 160 | else 161 | mkdir -p "$@" 162 | fi 163 | } 164 | 165 | function inputMethod() { 166 | if [ ${waylandOnly} = true ]; then 167 | pecho debug "Using Wayland Input Method" 168 | export QT_IM_MODULE=wayland 169 | export GTK_IM_MODULE=wayland 170 | IBUS_USE_PORTAL=1 171 | return 0 172 | elif [[ ${waylandOnly} =~ "adaptive" ]] && [[ ${XDG_SESSION_TYPE} =~ "wayland" ]]; then 173 | pecho debug "Using Wayland Input Method" 174 | export QT_IM_MODULE=wayland 175 | export GTK_IM_MODULE=wayland 176 | IBUS_USE_PORTAL=1 177 | return 0 178 | fi 179 | if [[ ${XMODIFIERS} =~ fcitx ]] || [[ ${QT_IM_MODULE} =~ fcitx ]] || [[ ${GTK_IM_MODULE} =~ fcitx ]]; then 180 | export QT_IM_MODULE=fcitx 181 | export GTK_IM_MODULE=fcitx 182 | elif [[ ${XMODIFIERS} =~ ibus ]] || [[ ${QT_IM_MODULE} =~ ibus ]] || [[ ${GTK_IM_MODULE} =~ ibus ]]; then 183 | export QT_IM_MODULE=ibus 184 | export GTK_IM_MODULE=ibus 185 | IBUS_USE_PORTAL=1 186 | elif [[ ${XMODIFIERS} =~ gcin ]]; then 187 | export QT_IM_MODULE=ibus 188 | export GTK_IM_MODULE=gcin 189 | export LC_CTYPE=zh_TW.UTF-8 190 | else 191 | pecho warn 'Input Method potentially broken! Please set $XMODIFIERS properly' 192 | # Guess the true IM based on running processes 193 | runningProcess=$(ps -U $(whoami)) 194 | if [[ ${runningProcess} =~ "ibus-daemon" ]]; then 195 | pecho warn "Guessing Input Method as iBus" 196 | export QT_IM_MODULE=ibus 197 | export GTK_IM_MODULE=ibus 198 | export XMODIFIERS=@im=ibus 199 | elif [[ ${runningProcess} =~ "fcitx" ]]; then 200 | pecho warn "Guessing Input Method as Fcitx" 201 | export QT_IM_MODULE=fcitx 202 | export GTK_IM_MODULE=fcitx 203 | export XMODIFIERS=@im=fcitx 204 | fi 205 | fi 206 | } 207 | 208 | function importEnv() { 209 | inputMethod 210 | genXAuth 211 | cat "${_portableConfig}" >"${XDG_DATA_HOME}/${stateDirectory}/portable-generated.env" 212 | printf "\n\n" >>"${XDG_DATA_HOME}/${stateDirectory}/portable-generated.env" 213 | addEnv "XDG_CONFIG_HOME=$(echo ${XDG_CONFIG_HOME} | pathTranslation)" & 214 | addEnv "XDG_DOCUMENTS_DIR=${XDG_DATA_HOME}/${stateDirectory}/Documents" & 215 | addEnv "XDG_DATA_HOME=${XDG_DATA_HOME}/${stateDirectory}/.local/share" & 216 | addEnv "XDG_STATE_HOME=${XDG_DATA_HOME}/${stateDirectory}/.local/state" & 217 | addEnv "XDG_CACHE_HOME=${XDG_DATA_HOME}/${stateDirectory}/cache" & 218 | addEnv "XDG_DESKTOP_DIR=${XDG_DATA_HOME}/${stateDirectory}/Desktop" & 219 | addEnv "XDG_DOWNLOAD_DIR=${XDG_DATA_HOME}/${stateDirectory}/Downloads" & 220 | addEnv "XDG_TEMPLATES_DIR=${XDG_DATA_HOME}/${stateDirectory}/Templates" & 221 | addEnv "XDG_PUBLICSHARE_DIR=${XDG_DATA_HOME}/${stateDirectory}/Public" & 222 | addEnv "XDG_MUSIC_DIR=${XDG_DATA_HOME}/${stateDirectory}/Music" & 223 | addEnv "XDG_PICTURES_DIR=${XDG_DATA_HOME}/${stateDirectory}/Pictures" & 224 | addEnv "XDG_VIDEOS_DIR=${XDG_DATA_HOME}/${stateDirectory}/Videos" & 225 | if [[ "${pwCam}" = "true" ]]; then 226 | pecho debug "Enabling pw-v4l2 preload..." 227 | addEnv "LD_PRELOAD=${LD_PRELOAD} $(ls /usr/lib/pipewire-* -d | head -n 1)/v4l2/libpw-v4l2.so" & 228 | else 229 | addEnv "LD_PRELOAD=${LD_PRELOAD}" & 230 | fi 231 | if [[ "${qt5Compat}" = "false" ]]; then 232 | pecho debug "Skipping Qt 5 compatibility workarounds" & 233 | else 234 | pecho debug "Enabling Qt 5 compatibility workarounds" & 235 | addEnv "QT_QPA_PLATFORMTHEME=xdgdesktopportal" & 236 | fi 237 | if [[ "${useZink}" = "true" ]]; then 238 | addEnv "__GLX_VENDOR_LIBRARY_NAME=mesa" & 239 | addEnv "MESA_LOADER_DRIVER_OVERRIDE=zink" & 240 | addEnv "GALLIUM_DRIVER=zink" & 241 | addEnv "LIBGL_KOPPER_DRI2=1" & 242 | addEnv "__EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/50_mesa.json" & 243 | fi 244 | addEnv 'GDK_DEBUG=portals' & 245 | addEnv 'GTK_USE_PORTAL=1' & 246 | addEnv 'QT_AUTO_SCREEN_SCALE_FACTOR=1' & 247 | addEnv "GTK_IM_MODULE=${GTK_IM_MODULE}" & 248 | addEnv "QT_IM_MODULE=${QT_IM_MODULE}" & 249 | addEnv "QT_ENABLE_HIGHDPI_SCALING=1" & 250 | addEnv "PATH=/sandbox:${PATH}" & 251 | addEnv "DISPLAY=${DISPLAY}" & 252 | addEnv "QT_SCALE_FACTOR=${QT_SCALE_FACTOR}" & 253 | addEnv "PS1='╰─>Portable Sandbox·${appID}·🧐⤔ '" & 254 | printf "\n\n" >>"${XDG_DATA_HOME}/${stateDirectory}/portable-generated.env" 255 | if [ -e "${XDG_DATA_HOME}"/${stateDirectory}/portable.env ]; then 256 | pecho info "${XDG_DATA_HOME}/${stateDirectory}/portable.env exists" 257 | else 258 | touch "${XDG_DATA_HOME}"/${stateDirectory}/portable.env 259 | fi 260 | if [ -s "${XDG_DATA_HOME}"/${stateDirectory}/portable.env ]; then 261 | cat "${XDG_DATA_HOME}"/${stateDirectory}/portable.env >>"${XDG_DATA_HOME}/${stateDirectory}/portable-generated.env" 262 | else 263 | echo "# Envs" >>"${XDG_DATA_HOME}"/${stateDirectory}/portable.env 264 | echo "isPortableEnvPresent=1" >>"${XDG_DATA_HOME}"/${stateDirectory}/portable.env 265 | fi 266 | echo "source ~/portable-generated.env" >"${XDG_DATA_HOME}"/${stateDirectory}/.bashrc 267 | } 268 | 269 | function getChildPid() { 270 | cGroup=$(systemctl --user show "${unitName}" -p ControlGroup | cut -c '14-') 271 | pecho debug "Getting PID from unit ${unitName}'s control group $(systemctl --user show "${unitName}" -p ControlGroup | cut -c '14-')" 272 | for childPid in $(pgrep --cgroup "${cGroup}"); do 273 | pecho debug "Trying PID ${childPid}" 274 | cmdlineArg=$(cat /proc/${childPid}/cmdline | tr '\000' ' ') 275 | if [[ ${cmdlineArg} =~ '/usr/lib/portable/helper' ]]; then 276 | if [[ $(echo "${cmdlineArg}" | cut -c '-14') =~ "bwrap" ]]; then 277 | pecho debug "Detected bwrap" 278 | else 279 | pecho debug "Detected helper" 280 | export childPid=${childPid} 281 | return 0 282 | fi 283 | fi 284 | done 285 | } 286 | 287 | # Function used to escape paths for sed processing. 288 | function pathEscape() { 289 | local str="$@" 290 | local delimiter="|" 291 | # Escape the delimiter and & 292 | str="${str//${delimiter}/\\${delimiter}}" 293 | str="${str//&/\\&}" 294 | echo "$str" 295 | } 296 | 297 | # Translates path based on ~ to state directory 298 | function pathTranslation() { 299 | sed "s|$(pathEscape ${HOME})|$(pathEscape ${XDG_DATA_HOME}/${stateDirectory})|g" 300 | } 301 | 302 | function defineRunPath() { 303 | if [ ! -d ${XDG_RUNTIME_DIR}/portable/${appID} ]; then 304 | mkdir -p ${XDG_RUNTIME_DIR}/portable/${appID} 305 | fi 306 | } 307 | 308 | function execApp() { 309 | desktopWorkaround & 310 | importEnv 311 | deviceBinding 312 | mkdir -p "${XDG_DATA_HOME}"/"${stateDirectory}"/.config 313 | if [ -z ${bwBindPar} ] && [ -f ${bwBindPar} ]; then 314 | bwBindPar="" 315 | else 316 | export bwBindPar="--dev-bind "${bwBindPar}" "${bwBindPar}"" 317 | pecho warn "bwBindPar is ${bwBindPar}" 318 | fi 319 | echo "false" >"${XDG_RUNTIME_DIR}/portable/${appID}"/startSignal 320 | sync "${XDG_RUNTIME_DIR}/portable/${appID}"/startSignal 321 | passPid & 322 | termExec 323 | systemd-run \ 324 | --user \ 325 | ${sdOption} \ 326 | -u "${unitName}" \ 327 | -p BindsTo="${proxyName}.service" \ 328 | -p Description="Portable Sandbox for ${appID}" \ 329 | -p Documentation="https://github.com/Kraftland/portable" \ 330 | -p Slice="portable-${friendlyName}.slice" \ 331 | -p ExitType=cgroup \ 332 | -p OOMPolicy=stop \ 333 | -p KillMode=control-group \ 334 | -p LimitCORE=0 \ 335 | -p CPUAccounting=yes \ 336 | -p StartupCPUWeight=idle \ 337 | -p StartupIOWeight=1 \ 338 | -p MemoryHigh=90% \ 339 | -p ManagedOOMSwap=kill \ 340 | -p ManagedOOMMemoryPressure=kill \ 341 | -p IPAccounting=yes \ 342 | -p EnvironmentFile="${XDG_DATA_HOME}/${stateDirectory}/portable-generated.env" \ 343 | -p SystemCallFilter=~@clock \ 344 | -p SystemCallFilter=~@cpu-emulation \ 345 | -p SystemCallFilter=~@debug \ 346 | -p SystemCallFilter=~@module \ 347 | -p SystemCallFilter=~@obsolete \ 348 | -p SystemCallFilter=~@resources \ 349 | -p SystemCallFilter=~@raw-io \ 350 | -p SystemCallFilter=~@reboot \ 351 | -p SystemCallFilter=~@swap \ 352 | -p SystemCallErrorNumber=EPERM \ 353 | -p PrivateIPC=yes \ 354 | -p ProtectClock=yes \ 355 | -p CapabilityBoundingSet= \ 356 | -p ProtectKernelModules=yes \ 357 | -p RestrictSUIDSGID=yes \ 358 | -p LockPersonality=yes \ 359 | -p RestrictRealtime=yes \ 360 | -p ProtectSystem=full \ 361 | -p ProtectProc=invisible \ 362 | -p ProcSubset=pid \ 363 | -p ProtectHome=no \ 364 | -p PrivateUsers=yes \ 365 | -p UMask=077 \ 366 | -p DevicePolicy=strict \ 367 | -p NoNewPrivileges=yes \ 368 | -p ProtectControlGroups=yes \ 369 | -p PrivateMounts=yes \ 370 | -p KeyringMode=private \ 371 | -p TimeoutStopSec=20s \ 372 | -p BindReadOnlyPaths=/usr/bin/true:/usr/bin/lsblk \ 373 | -p Environment=XAUTHORITY="${HOME}/.XAuthority" \ 374 | -p Environment=instanceId="${instanceId}" \ 375 | -p Environment=busDir=${busDir} \ 376 | -p "${sdNetArg}" \ 377 | -p Environment=HOME="${XDG_DATA_HOME}/${stateDirectory}" \ 378 | -p WorkingDirectory="${XDG_DATA_HOME}/${stateDirectory}" \ 379 | -p Environment=WAYLAND_DISPLAY="${wayDisplayBind}" \ 380 | -- \ 381 | bwrap --new-session \ 382 | --unshare-cgroup-try \ 383 | --unshare-ipc \ 384 | --unshare-uts \ 385 | --unshare-pid \ 386 | --unshare-user \ 387 | --ro-bind "${XDG_DATA_HOME}/${stateDirectory}"/flatpak-info \ 388 | /.flatpak-info \ 389 | --dir /tmp \ 390 | --bind-try /tmp/.X11-unix /tmp/.X11-unix \ 391 | --bind-try /tmp/.XIM-unix /tmp/.XIM-unix \ 392 | --dev /dev \ 393 | --mqueue /dev/mqueue \ 394 | --dev-bind /dev/dri /dev/dri \ 395 | ${bwInputArg} \ 396 | ${bwSwitchableGraphicsArg} \ 397 | --dev-bind-try /dev/udmabuf /dev/udmabuf \ 398 | --tmpfs /sys \ 399 | --ro-bind /sys/module/ /sys/module/ \ 400 | --ro-bind /sys/dev/char /sys/dev/char \ 401 | --ro-bind /sys/devices /sys/devices \ 402 | --tmpfs /sys/devices/virtual/dmi \ 403 | --dir /sys/class \ 404 | --symlink /dev/dri/ /sys/class/drm \ 405 | --dir /sandbox \ 406 | --ro-bind /usr/bin/true \ 407 | /sandbox/sudo \ 408 | --ro-bind /usr/lib/portable/open \ 409 | /sandbox/chromium \ 410 | --ro-bind /usr/lib/portable/open \ 411 | /sandbox/firefox \ 412 | --ro-bind /usr/lib/portable/open \ 413 | /sandbox/dde-file-manager \ 414 | --ro-bind /usr/lib/portable/open \ 415 | /sandbox/xdg-open \ 416 | --ro-bind /usr/lib/portable/open \ 417 | /sandbox/open \ 418 | --ro-bind /usr/lib/portable/open \ 419 | /sandbox/nautilus \ 420 | --ro-bind /usr/lib/portable/open \ 421 | /sandbox/dolphin \ 422 | --proc /proc \ 423 | --ro-bind-try /dev/null /proc/uptime \ 424 | --ro-bind-try /dev/null /proc/modules \ 425 | --ro-bind-try /dev/null /proc/cmdline \ 426 | --ro-bind-try /dev/null /proc/diskstats \ 427 | --ro-bind-try /dev/null /proc/devices \ 428 | --ro-bind-try /dev/null /proc/config.gz \ 429 | --ro-bind-try /dev/null /proc/version \ 430 | --tmpfs /proc/1 \ 431 | --bind-try /dev/null /proc/cpuinfo \ 432 | --bind /usr /usr \ 433 | --tmpfs /usr/share/applications \ 434 | --ro-bind /etc /etc \ 435 | --tmpfs /etc/kernel \ 436 | --symlink /usr/lib /lib \ 437 | --symlink /usr/lib /lib64 \ 438 | --ro-bind-try /bin /bin \ 439 | --ro-bind-try /sbin /sbin \ 440 | --ro-bind-try /opt /opt \ 441 | --bind "${XDG_RUNTIME_DIR}/portable/${appID}" /run \ 442 | --bind "${XDG_RUNTIME_DIR}/portable/${appID}" \ 443 | "${XDG_RUNTIME_DIR}/portable/${appID}" \ 444 | --bind "${busDir}" "${XDG_RUNTIME_DIR}" \ 445 | --bind "${busDirAy}" "${XDG_RUNTIME_DIR}/at-spi" \ 446 | --dir /run/host \ 447 | --ro-bind "${XDG_DATA_HOME}/${stateDirectory}"/flatpak-info \ 448 | "${XDG_RUNTIME_DIR}/.flatpak-info" \ 449 | --ro-bind-try "${XDG_RUNTIME_DIR}/pulse" \ 450 | "${XDG_RUNTIME_DIR}/pulse" \ 451 | ${pipewireBinding} \ 452 | --bind "${XDG_RUNTIME_DIR}/doc/by-app/${appID}" \ 453 | "${XDG_RUNTIME_DIR}"/doc \ 454 | --ro-bind /dev/null \ 455 | "${XDG_RUNTIME_DIR}"/.flatpak/"${instanceId}-private/run-environ" \ 456 | --ro-bind "${XDG_RUNTIME_DIR}/.flatpak/${instanceId}" \ 457 | "${XDG_RUNTIME_DIR}/.flatpak/${instanceId}" \ 458 | --ro-bind "${XDG_RUNTIME_DIR}/.flatpak/${instanceId}" \ 459 | "${XDG_RUNTIME_DIR}/flatpak-runtime-directory" \ 460 | --bind "${XDG_DATA_HOME}/${stateDirectory}" "${HOME}" \ 461 | --bind "${XDG_DATA_HOME}/${stateDirectory}" \ 462 | "${XDG_DATA_HOME}/${stateDirectory}" \ 463 | --ro-bind-try "${XDG_DATA_HOME}"/icons \ 464 | "${XDG_DATA_HOME}"/icons \ 465 | --ro-bind-try "${XDG_DATA_HOME}"/icons \ 466 | "$(echo "${XDG_DATA_HOME}" | pathTranslation)/icons" \ 467 | --ro-bind-try "${wayDisplayBind}" \ 468 | "${wayDisplayBind}" \ 469 | --ro-bind-try "${XDG_CONFIG_HOME}"/fontconfig \ 470 | "${XDG_CONFIG_HOME}"/fontconfig \ 471 | --ro-bind-try "${XDG_CONFIG_HOME}"/fontconfig \ 472 | "$(echo "${XDG_CONFIG_HOME}" | pathTranslation)/fontconfig" \ 473 | --ro-bind-try "${XDG_DATA_HOME}/fonts" \ 474 | "${XDG_DATA_HOME}/fonts" \ 475 | --ro-bind-try "${XDG_DATA_HOME}/fonts" \ 476 | "$(echo "${XDG_DATA_HOME}" | pathTranslation)/fonts" \ 477 | --ro-bind-try "/run/systemd/resolve/stub-resolv.conf" \ 478 | "/run/systemd/resolve/stub-resolv.conf" \ 479 | --tmpfs "${HOME}"/options \ 480 | ${bwBindPar} \ 481 | --tmpfs "${XDG_DATA_HOME}/${stateDirectory}"/options \ 482 | ${bwCamPar} \ 483 | -- \ 484 | /usr/lib/portable/helper ${launchTarget} ${targetArgs} 485 | } 486 | 487 | function execAppExistDirect() { 488 | echo "${launchTarget} ${targetArgs}" >"${XDG_RUNTIME_DIR}/portable/${appID}/startSignal" 489 | } 490 | 491 | function termExec() { 492 | trap "stopApp force" SIGTERM SIGINT SIGHUP SIGQUIT 493 | } 494 | 495 | function execAppExist() { 496 | export unitName="${unitName}-subprocess-$(uuidgen)" 497 | export instanceId=$(cat "${XDG_DATA_HOME}/${stateDirectory}"/flatpak-info | grep instance-id | cut -c '13-') 498 | execApp 499 | stopApp 500 | if [[ $? = 0 ]]; then 501 | exit 0 502 | fi 503 | } 504 | 505 | function shareFile() { 506 | if [[ ${trashAppUnsafe} = 1 ]]; then 507 | zenity \ 508 | --error \ 509 | --title "Sandbox disabled" \ 510 | --text "Feature is intended for sandbox users" 511 | pecho crit "Sandbox is disabled" 512 | exit 1 513 | fi 514 | fileList=$(zenity --file-selection --multiple | tail -n 1) 515 | IFS='|' read -r -a filePaths <<< "${fileList}" 516 | for filePath in "${filePaths[@]}"; do 517 | pecho info "User selected path: ${filePath}" 518 | cp -a \ 519 | "${filePath}" \ 520 | "${XDG_DATA_HOME}/${stateDirectory}/Shared" 521 | done 522 | exit 0 523 | } 524 | 525 | function addEnv() { 526 | echo "$@" >>"${XDG_DATA_HOME}/${stateDirectory}/portable-generated.env" 527 | } 528 | 529 | function desktopWorkaround() { 530 | dbus-send --session \ 531 | --dest=org.freedesktop.impl.portal.PermissionStore \ 532 | /org/freedesktop/impl/portal/PermissionStore \ 533 | org.freedesktop.impl.portal.PermissionStore.SetPermission \ 534 | string:"background" boolean:true string:"background" string:"${appID}" array:string:"yes" & 535 | } 536 | 537 | function deviceBinding() { 538 | if [[ ${gameMode} = true ]]; then 539 | bwSwitchableGraphicsArg="" 540 | pecho debug "Binding all GPUs in Game Mode" 541 | ls /dev/nvidia* 2>/dev/null 1>/dev/null 542 | lsStatus=$? 543 | if [ "${lsStatus}" = 0 ]; then 544 | pecho debug "Binding NVIDIA GPUs" 545 | for _card in $(ls /dev/nvidia*); do 546 | if [ -e ${_card} ]; then 547 | bwSwitchableGraphicsArg="${bwSwitchableGraphicsArg} --dev-bind ${_card} ${_card}" 548 | fi 549 | done 550 | pecho debug "Specifying environment variables for dGPU utilization" 551 | addEnv '__NV_PRIME_RENDER_OFFLOAD=1' 552 | addEnv '__VK_LAYER_NV_optimus=NVIDIA_only' 553 | addEnv '__GLX_VENDOR_LIBRARY_NAME=nvidia' 554 | addEnv 'VK_LOADER_DRIVERS_SELECT=nvidia_icd.json' 555 | addEnv 'DRI_PRIME=1' 556 | else 557 | pecho info "No NVIDIA GPU could be found!" 558 | pecho info "Using mesa feature... unsetting all related environment variables" 559 | addEnv 'VK_LOADER_DRIVERS_DISABLE=' 560 | addEnv 'DRI_PRIME=1' 561 | fi 562 | else 563 | pecho debug "Detecting GPU..." 564 | bwSwitchableGraphicsArg="" 565 | videoMod=$(lsmod) 566 | if [ $(ls /dev/dri/renderD* -la | wc -l) = 1 ] && [[ ${videoMod} =~ nvidia ]]; then 567 | pecho info "Using single NVIDIA GPU" 568 | addEnv 'GSK_RENDERER=ngl' 569 | for _card in $(ls /dev/nvidia*); do 570 | if [ -e ${_card} ]; then 571 | bwSwitchableGraphicsArg="${bwSwitchableGraphicsArg} --dev-bind ${_card} ${_card}" 572 | fi 573 | done 574 | elif [[ ${videoMod} =~ i915 ]] || [[ ${videoMod} =~ xe ]] || [[ ${videoMod} =~ amdgpu ]]; then 575 | if [[ ${videoMod} =~ nvidia ]]; then 576 | pecho debug "Activating hybrid GPU detection" 577 | bwSwitchableGraphicsArg="--tmpfs /dev/dri" 578 | for device in $(ls /sys/class/drm/renderD12* -d); do 579 | if [[ $(cat "${device}/device/vendor") = 0x10de ]]; then 580 | pecho debug "Device $(basename ${device}) detected as NVIDIA GPU" 581 | else 582 | bwSwitchableGraphicsArg="${bwSwitchableGraphicsArg} --dev-bind /dev/dri/$(basename ${device}) /dev/dri/$(basename ${device})" 583 | pecho debug "Device $(basename ${device}) binded" 584 | fi 585 | done 586 | else 587 | pecho debug "Not using NVIDIA GPU" 588 | fi 589 | addEnv 'VK_LOADER_DRIVERS_DISABLE="nvidia_icd.json"' 590 | elif [[ ${videoMod} =~ nvidia ]]; then 591 | pecho debug "Using NVIDIA GPU" 592 | addEnv 'GSK_RENDERER=ngl' 593 | for _card in $(ls /dev/nvidia*); do 594 | if [ -e ${_card} ]; then 595 | bwSwitchableGraphicsArg="${bwSwitchableGraphicsArg} --dev-bind ${_card} ${_card}" 596 | fi 597 | done 598 | fi 599 | fi 600 | pecho debug "Generated GPU bind parameter: ${bwSwitchableGraphicsArg}" 601 | bwCamPar="" 602 | if [[ ${bindCameras} = "true" ]]; then 603 | pecho debug "Detecting Camera..." 604 | for camera in $(ls /dev/video*); do 605 | if [ -e ${camera} ]; then 606 | bwCamPar="${bwCamPar} --dev-bind ${camera} ${camera}" 607 | fi 608 | done 609 | fi 610 | pecho debug "Generated Camera bind parameter: ${bwCamPar}" 611 | if [[ ${bindInputDevices} = "true" ]]; then 612 | bwInputArg="--dev-bind-try /dev/input /dev/input --dev-bind-try /dev/uinput /dev/uinput" 613 | ls /dev/hidraw* 2>/dev/null 1>/dev/null 614 | lsStatus=$? 615 | if [ "${lsStatus}" = 0 ]; then 616 | for _device in $(ls /dev/hidraw*); do 617 | if [ -e ${_card} ]; then 618 | bwInputArg="${bwInputArg} --dev-bind ${_device} ${_device}" 619 | fi 620 | done 621 | fi 622 | pecho warn "Detected input preference as expose, setting arg: ${bwInputArg}" 623 | else 624 | bwInputArg="" 625 | pecho debug "Not exposing input devices" 626 | fi 627 | if [[ ${bindNetwork} = "false" ]]; then 628 | pecho info "Network access disabled via config" 629 | export sdNetArg="PrivateNetwork=yes" 630 | else 631 | export sdNetArg="PrivateNetwork=no" 632 | pecho debug "Network access allowed" 633 | fi 634 | if [[ ${bindPipewire} = "true" ]]; then 635 | pipewireBinding="--ro-bind-try ${XDG_RUNTIME_DIR}/pipewire-0 ${XDG_RUNTIME_DIR}/pipewire-0" 636 | fi 637 | } 638 | 639 | function appANR() { 640 | if [[ "${LANG}" =~ 'zh_CN' ]]; then 641 | zenity --title "程序未响应" --icon=utilities-system-monitor-symbolic --default-cancel --question --text="是否结束正在运行的进程?" 642 | else 643 | zenity --title "Application is not responding" --icon=utilities-system-monitor-symbolic --default-cancel --question --text="Do you wish to terminate the running session?" 644 | fi 645 | } 646 | 647 | function warnMulRunning() { 648 | if [ "${dbusWake}" = true ]; then 649 | id=$(dbus-send \ 650 | --bus=unix:path="${busDir}/bus" \ 651 | --dest=org.kde.StatusNotifierWatcher \ 652 | --type=method_call \ 653 | --print-reply=literal /StatusNotifierWatcher \ 654 | org.freedesktop.DBus.Properties.Get \ 655 | string:org.kde.StatusNotifierWatcher \ 656 | string:RegisteredStatusNotifierItems | grep -oP 'org.kde.StatusNotifierItem-\d+-\d+') 657 | pecho debug "Unique ID: ${id}" 658 | dbus-send \ 659 | --print-reply \ 660 | --session \ 661 | --dest=${id} \ 662 | --type=method_call \ 663 | /StatusNotifierItem \ 664 | org.kde.StatusNotifierItem.Activate \ 665 | int32:114514 \ 666 | int32:1919810 667 | status=$? 668 | if [[ ${status} = 1 ]]; then 669 | appANR 670 | elif [[ ${status} -gt 0 ]]; then 671 | appANR 672 | exit ${status} 673 | else 674 | exit ${status} 675 | fi 676 | else 677 | pecho info "Skipping D-Bus wake" 678 | fi 679 | source "${_portableConfig}" 680 | if [[ $@ =~ "--actions" ]] && [[ $@ =~ "debug-shell" ]]; then 681 | export launchTarget="/usr/bin/bash" 682 | execAppExist 683 | else 684 | execAppExistDirect ${launchTarget} ${targetArgs} 685 | exit $? 686 | fi 687 | appANR 688 | if [ $? = 0 ]; then 689 | stopApp force 690 | else 691 | pecho crit "User denied session termination" 692 | exit $? 693 | fi 694 | } 695 | 696 | function generateFlatpakInfo() { 697 | pecho debug "Installing flatpak-info..." 698 | install /usr/lib/portable/flatpak-info \ 699 | "${XDG_DATA_HOME}/${stateDirectory}"/flatpak-info 700 | pecho debug "Generating flatpak-info..." 701 | export instanceId=$(head -c 4 /dev/urandom | xxd -p | tr -d '\n' | awk '{print strtonum("0x"$1)}') 702 | sed -i "s|placeHolderAppName|${appID}|g" \ 703 | "${XDG_DATA_HOME}/${stateDirectory}"/flatpak-info 704 | sed -i "s|placeholderInstanceId|${instanceId}|g" \ 705 | "${XDG_DATA_HOME}/${stateDirectory}"/flatpak-info 706 | sed -i "s|placeholderPath|${XDG_DATA_HOME}/${stateDirectory}|g" \ 707 | "${XDG_DATA_HOME}/${stateDirectory}"/flatpak-info 708 | 709 | mkdir -p "${XDG_RUNTIME_DIR}/.flatpak/${instanceId}" 710 | install /usr/lib/portable/bwrapinfo.json \ 711 | "${XDG_RUNTIME_DIR}/.flatpak/${instanceId}/bwrapinfo.json" 712 | install "${XDG_DATA_HOME}/${stateDirectory}"/flatpak-info \ 713 | "${XDG_RUNTIME_DIR}/.flatpak/${instanceId}/info" 714 | pecho debug "Successfully installed bwrapinfo @${XDG_RUNTIME_DIR}/.flatpak/${instanceId}/bwrapinfo.json" 715 | mkdir -p "${XDG_RUNTIME_DIR}/.flatpak/${appID}/xdg-run" 716 | mkdir -p "${XDG_RUNTIME_DIR}/.flatpak/${appID}/tmp" 717 | touch "${XDG_RUNTIME_DIR}/.flatpak/${appID}/.ref" 718 | if [ -f "/usr/share/applications/${appID}.desktop" ]; then 719 | pecho debug "Application desktop file detected" 720 | else 721 | pecho warn ".desktop file missing!" 722 | echo '''[Desktop Entry] 723 | Name=placeholderName 724 | Exec=env _portableConfig=placeholderConfig portable 725 | Terminal=false 726 | Type=Application 727 | Icon=image-missing 728 | Comment=Application info missing 729 | Categories=Utility;''' >"${XDG_RUNTIME_DIR}/portable/${appID}/desktop.file" 730 | sed -i \ 731 | "s|placeholderConfig|$(pathEscape "${_portableConfig}")|g" \ 732 | "${XDG_RUNTIME_DIR}/portable/${appID}/desktop.file" 733 | sed -i \ 734 | "s|placeholderName|$(pathEscape "${appID}")|g" \ 735 | "${XDG_RUNTIME_DIR}/portable/${appID}/desktop.file" 736 | install -Dm600 \ 737 | "${XDG_RUNTIME_DIR}/portable/${appID}/desktop.file" \ 738 | "${XDG_DATA_HOME}/applications/${appID}.desktop" 739 | fi 740 | } 741 | 742 | function resetUnit() { 743 | if [[ $(systemctl --user is-failed ${1}.service) = failed ]]; then 744 | pecho warn "${1} failed last time" 745 | systemctl --user reset-failed ${1}.service 746 | fi 747 | } 748 | 749 | function dbusProxy() { 750 | defineRunPath 751 | generateFlatpakInfo 752 | waylandDisplay 753 | resetUnit "${proxyName}" 754 | resetUnit "${friendlyName}" 755 | resetUnit "${proxyName}-a11y" 756 | resetUnit "${friendlyName}-wayland-proxy" 757 | systemctl --user clean "${friendlyName}*" & 758 | systemctl --user clean "${proxyName}*".service & 759 | systemctl --user clean "${proxyName}*"-a11y.service & 760 | systemctl --user clean "${friendlyName}*"-wayland-proxy.service & 761 | systemctl --user clean "${friendlyName}-subprocess*".service & 762 | mkdir -p "${busDir}" 763 | mkdir -p "${busDirAy}" 764 | pecho info "Starting D-Bus Proxy @ ${busDir}..." 765 | if [[ ${PORTABLE_LOGGING} = "debug" ]]; then 766 | proxyArg="--log" 767 | fi 768 | if [ ${XDG_CURRENT_DESKTOP} = "GNOME" ]; then 769 | local featureSet="GlobalShortcuts ScreenShot" 770 | pecho info "Enabling GNOME exclusive features: ${featureSet}" 771 | export extraDbusArgs="--call=org.freedesktop.portal.Desktop=org.freedesktop.portal.Screenshot --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.Screenshot.Screenshot --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.GlobalShortcuts --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.GlobalShortcuts.*" 772 | else 773 | pecho info "Disabling GNOME exclusive features" 774 | export extraDbusArgs="--see=org.freedesktop.portal.Flatpak" 775 | fi 776 | mkdir -p "${XDG_RUNTIME_DIR}/doc/by-app/${appID}" 777 | systemd-run \ 778 | --user \ 779 | -p Slice="portable-${friendlyName}.slice" \ 780 | -u ${proxyName} \ 781 | -p KillMode=control-group \ 782 | -p Wants='xdg-document-portal.service xdg-desktop-portal.service' \ 783 | -p After='xdg-document-portal.service xdg-desktop-portal.service' \ 784 | -p SuccessExitStatus=SIGKILL \ 785 | -- bwrap \ 786 | --symlink /usr/lib64 /lib64 \ 787 | --ro-bind /usr/lib /usr/lib \ 788 | --ro-bind /usr/lib64 /usr/lib64 \ 789 | --ro-bind /usr/bin /usr/bin \ 790 | --ro-bind-try /usr/share /usr/share \ 791 | --bind "${XDG_RUNTIME_DIR}" "${XDG_RUNTIME_DIR}" \ 792 | --ro-bind "${XDG_DATA_HOME}/${stateDirectory}"/flatpak-info \ 793 | "${XDG_RUNTIME_DIR}/.flatpak-info" \ 794 | --ro-bind "${XDG_DATA_HOME}/${stateDirectory}"/flatpak-info \ 795 | /.flatpak-info \ 796 | -- /usr/bin/xdg-dbus-proxy \ 797 | "${DBUS_SESSION_BUS_ADDRESS}" \ 798 | "${busDir}/bus" \ 799 | ${proxyArg} \ 800 | --filter \ 801 | --own=org.kde.StatusNotifierItem-2-1 \ 802 | --own=org.kde.StatusNotifierItem-3-1 \ 803 | --own=org.kde.StatusNotifierItem-4-1 \ 804 | --own=org.kde.StatusNotifierItem-5-1 \ 805 | --own=org.kde.StatusNotifierItem-6-1 \ 806 | --own=org.kde.StatusNotifierItem-7-1 \ 807 | --own=org.kde.StatusNotifierItem-8-1 \ 808 | --own=org.kde.StatusNotifierItem-9-1 \ 809 | --own=org.kde.StatusNotifierItem-10-1 \ 810 | --own=org.kde.StatusNotifierItem-11-1 \ 811 | --own=com.belmoussaoui.ashpd.demo \ 812 | --own="${appID}" \ 813 | --own="${appID}".* \ 814 | --own="org.mpris.MediaPlayer2.${appID##*.}" \ 815 | --own="org.mpris.MediaPlayer2.${appID##*.}".* \ 816 | --talk=org.freedesktop.Notifications \ 817 | --talk=org.kde.StatusNotifierWatcher \ 818 | --call=org.freedesktop.Notifications.*=* \ 819 | --see=org.a11y.Bus \ 820 | --call=org.a11y.Bus=org.a11y.Bus.GetAddress@/org/a11y/bus \ 821 | --call=org.a11y.Bus=org.freedesktop.DBus.Properties.Get@/org/a11y/bus \ 822 | --see=org.freedesktop.portal.Flatpak \ 823 | --see=org.freedesktop.portal.Request \ 824 | --call=org.freedesktop.portal.Flatpak=org.freedesktop.DBus.Peer.Ping \ 825 | --call=org.freedesktop.portal.Desktop=org.freedesktop.DBus.Properties.GetAll \ 826 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.Session.Close \ 827 | --call=org.freedesktop.portal.Flatpak=*@/org/freedesktop/portal/Flatpak \ 828 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.Settings.ReadAll \ 829 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.Email.ComposeEmail \ 830 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.Usb \ 831 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.Usb.* \ 832 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.ProxyResolver.Lookup \ 833 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.ProxyResolver.Lookup.* \ 834 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.ScreenCast \ 835 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.ScreenCast.* \ 836 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.Account.GetUserInformation \ 837 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.Camera.* \ 838 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.Camera \ 839 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.RemoteDesktop.* \ 840 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.RemoteDesktop \ 841 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.Settings.Read \ 842 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.Request \ 843 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.Documents.* \ 844 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.Documents \ 845 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.FileChooser.* \ 846 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.FileChooser \ 847 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.FileTransfer.* \ 848 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.FileTransfer \ 849 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.Notification.* \ 850 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.Notification \ 851 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.Print.* \ 852 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.Print \ 853 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.NetworkMonitor.* \ 854 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.NetworkMonitor \ 855 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.OpenURI.* \ 856 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.OpenURI \ 857 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.Fcitx.* \ 858 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.Fcitx \ 859 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.IBus.* \ 860 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.IBus \ 861 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.IBus \ 862 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.Secret \ 863 | --call=org.freedesktop.portal.Desktop=org.freedesktop.portal.Secret.RetrieveSecret \ 864 | ${extraDbusArgs} \ 865 | --call=org.freedesktop.portal.Desktop=org.freedesktop.DBus.Properties.Get@/org/freedesktop/portal/desktop \ 866 | --talk=org.freedesktop.portal.Documents \ 867 | --call=org.freedesktop.portal.Documents=* \ 868 | --talk=org.freedesktop.portal.FileTransfer \ 869 | --call=org.freedesktop.portal.FileTransfer=* \ 870 | --talk=org.freedesktop.portal.FileTransfer.* \ 871 | --call=org.freedesktop.portal.FileTransfer.*=* \ 872 | --talk=org.freedesktop.portal.Notification \ 873 | --call=org.freedesktop.portal.Notification=* \ 874 | --talk=org.freedesktop.portal.Print \ 875 | --call=org.freedesktop.portal.Print=* \ 876 | --talk=org.freedesktop.FileManager1 \ 877 | --call=org.freedesktop.FileManager1=* \ 878 | --talk=org.freedesktop.portal.OpenURI \ 879 | --call=org.freedesktop.portal.OpenURI=* \ 880 | --talk=org.freedesktop.portal.OpenURI.OpenURI \ 881 | --call=org.freedesktop.portal.OpenURI.OpenURI=* \ 882 | --talk=org.freedesktop.portal.OpenURI.OpenFile \ 883 | --call=org.freedesktop.portal.OpenURI.OpenFile=* \ 884 | --talk=org.freedesktop.portal.Fcitx \ 885 | --call=org.freedesktop.portal.Fcitx=* \ 886 | --talk=org.freedesktop.portal.Fcitx.* \ 887 | --call=org.freedesktop.portal.Fcitx.*=* \ 888 | --talk=org.freedesktop.portal.IBus \ 889 | --call=org.freedesktop.portal.IBus=* \ 890 | --talk=org.freedesktop.portal.IBus.* \ 891 | --call=org.freedesktop.portal.IBus.*=* \ 892 | --call=org.freedesktop.portal.Request=* \ 893 | --broadcast=org.freedesktop.portal.*=@/org/freedesktop/portal/* 894 | 895 | if [[ "${securityContext}" = 1 ]] || [[ ${allowSecurityContext} = 1 ]]; then 896 | rm -rf "${XDG_RUNTIME_DIR}/portable/${appID}/wayland.sock" 897 | systemd-run \ 898 | --user \ 899 | -p Slice="portable-${friendlyName}.slice" \ 900 | -u "${friendlyName}"-wayland-proxy \ 901 | -p BindsTo="${proxyName}.service" \ 902 | -p Environment=WAYLAND_DISPLAY="${WAYLAND_DISPLAY}" \ 903 | -- \ 904 | way-secure \ 905 | -e top.kimiblock.portable \ 906 | -a ${appID} \ 907 | -i ${instanceId} \ 908 | --socket-path "${XDG_RUNTIME_DIR}/portable/${appID}/wayland.sock" 909 | fi 910 | 911 | if [ ! -S ${XDG_RUNTIME_DIR}/at-spi/bus ]; then 912 | pecho warn "No at-spi bus detected!" 913 | touch "${busDirAy}/bus" 914 | return 0 915 | fi 916 | systemd-run \ 917 | --user \ 918 | -p Slice="portable-${friendlyName}.slice" \ 919 | -u ${proxyName}-a11y \ 920 | -p RestartMode=direct \ 921 | -p BindsTo="${proxyName}.service" \ 922 | -- bwrap \ 923 | --symlink /usr/lib64 /lib64 \ 924 | --ro-bind /usr/lib /usr/lib \ 925 | --ro-bind /usr/lib64 /usr/lib64 \ 926 | --ro-bind /usr/bin /usr/bin \ 927 | --ro-bind-try /usr/share /usr/share \ 928 | --bind "${XDG_RUNTIME_DIR}" "${XDG_RUNTIME_DIR}" \ 929 | --ro-bind "${XDG_DATA_HOME}/${stateDirectory}"/flatpak-info \ 930 | "${XDG_RUNTIME_DIR}/.flatpak-info" \ 931 | --ro-bind "${XDG_DATA_HOME}/${stateDirectory}"/flatpak-info \ 932 | /.flatpak-info \ 933 | -- /usr/bin/xdg-dbus-proxy \ 934 | unix:path="${XDG_RUNTIME_DIR}/at-spi/bus" \ 935 | "${busDirAy}/bus" \ 936 | --filter \ 937 | --sloppy-names \ 938 | --call=org.a11y.atspi.Registry=org.a11y.atspi.Socket.Embed@/org/a11y/atspi/accessible/root \ 939 | --call=org.a11y.atspi.Registry=org.a11y.atspi.Socket.Unembed@/org/a11y/atspi/accessible/root \ 940 | --call=org.a11y.atspi.Registry=org.a11y.atspi.Registry.GetRegisteredEvents@/org/a11y/atspi/registry \ 941 | --call=org.a11y.atspi.Registry=org.a11y.atspi.DeviceEventController.GetKeystrokeListeners@/org/a11y/atspi/registry/deviceeventcontroller \ 942 | --call=org.a11y.atspi.Registry=org.a11y.atspi.DeviceEventController.GetDeviceEventListeners@/org/a11y/atspi/registry/deviceeventcontroller \ 943 | --call=org.a11y.atspi.Registry=org.a11y.atspi.DeviceEventController.NotifyListenersSync@/org/a11y/atspi/registry/deviceeventcontroller \ 944 | --call=org.a11y.atspi.Registry=org.a11y.atspi.DeviceEventController.NotifyListenersAsync@/org/a11y/atspi/registry/deviceeventcontroller 945 | 946 | 947 | } 948 | 949 | function execAppUnsafe() { 950 | #importEnv 951 | inputMethod 952 | source "${XDG_DATA_HOME}/${stateDirectory}/portable-generated.env" 953 | pecho info "GTK_IM_MODULE is ${GTK_IM_MODULE}" 954 | pecho info "QT_IM_MODULE is ${QT_IM_MODULE}" 955 | systemd-run --user \ 956 | -p Slice="portable-${friendlyName}.slice" \ 957 | -p Environment=QT_AUTO_SCREEN_SCALE_FACTOR="${QT_AUTO_SCREEN_SCALE_FACTOR}" \ 958 | -p Environment=QT_ENABLE_HIGHDPI_SCALING="${QT_ENABLE_HIGHDPI_SCALING}" \ 959 | -p Environment=GTK_IM_MODULE="${GTK_IM_MODULE}" \ 960 | -p Environment=QT_IM_MODULE="${QT_IM_MODULE}" \ 961 | -p Environment=XMODIFIERS="${XMODIFIERS}" \ 962 | -p EnvironmentFile=-"${XDG_DATA_HOME}/${stateDirectory}/portable.env" \ 963 | -u ${unitName} \ 964 | --tty \ 965 | ${launchTarget} 966 | } 967 | 968 | function enableSandboxFunc() { 969 | pecho info "Sandboxing confirmed" 970 | mkdir -p "${XDG_DATA_HOME}"/${stateDirectory}/options 971 | touch "${XDG_DATA_HOME}"/${stateDirectory}/options/sandbox 972 | return 0 973 | } 974 | 975 | function questionFirstLaunch() { 976 | if [ ! -f "${XDG_DATA_HOME}"/${stateDirectory}/options/sandbox ]; then 977 | if [[ "${LANG}" =~ 'zh_CN' ]]; then 978 | /usr/bin/zenity \ 979 | --title "${friendlyName}" \ 980 | --icon=security-medium-symbolic \ 981 | --question \ 982 | --text="对应用程序 ${appID} 启用沙盒?" 983 | else 984 | /usr/bin/zenity \ 985 | --title "${friendlyName}" \ 986 | --icon=security-medium-symbolic \ 987 | --question \ 988 | --text="Enable sandbox for: ${appID}?" 989 | fi 990 | if [[ $? = 1 ]]; then 991 | if [[ "${LANG}" =~ 'zh_CN' ]]; then 992 | zenity \ 993 | --question \ 994 | --default-cancel \ 995 | --title "确认操作" \ 996 | --icon=security-low-symbolic \ 997 | --text "用户数据将不再被保护" 998 | else 999 | zenity \ 1000 | --question \ 1001 | --default-cancel \ 1002 | --title "Confirm action" \ 1003 | --icon=security-low-symbolic \ 1004 | --text "User data may be compromised" 1005 | fi 1006 | if [[ $? = 1 ]]; then 1007 | pecho info "User enabled sandbox late" 1008 | enableSandboxFunc & 1009 | return 0 1010 | else 1011 | pecho warn "User disabled sandbox!" 1012 | mkdir \ 1013 | -p \ 1014 | "${XDG_DATA_HOME}"/${stateDirectory}/options 1015 | echo \ 1016 | disableSandbox \ 1017 | >>"${XDG_DATA_HOME}"/${stateDirectory}/options/sandbox & 1018 | export \ 1019 | trashAppUnsafe=1 1020 | fi 1021 | else 1022 | enableSandboxFunc & 1023 | return 0 1024 | fi 1025 | elif [[ $(cat "${XDG_DATA_HOME}"/${stateDirectory}/options/sandbox) =~ "disableSandbox" ]]; then 1026 | export trashAppUnsafe=1 1027 | fi 1028 | } 1029 | 1030 | function launch() { 1031 | export sdOption="-P" 1032 | if [[ $(systemctl --user is-failed ${unitName}.service) = failed ]]; then 1033 | pecho warn "${appID} failed last time" 1034 | systemctl --user reset-failed ${unitName}.service & 1035 | fi 1036 | if [[ $(systemctl --user is-active ${unitName}.service) = active ]]; then 1037 | warnMulRunning $@ 1038 | fi 1039 | if [[ $@ =~ "--actions" ]] && [[ $@ =~ "debug-shell" ]]; then 1040 | launchTarget="/usr/bin/bash" 1041 | #export startType=subprocess 1042 | fi 1043 | if [[ ${trashAppUnsafe} = 1 ]]; then 1044 | pecho warn "Launching ${appID} (unsafe)..." 1045 | execAppUnsafe 1046 | else 1047 | dbusProxy 1048 | pecho info "Launching ${appID}..." 1049 | execApp 1050 | stopApp 1051 | fi 1052 | } 1053 | 1054 | function passPid() { 1055 | if [[ $(cat "${XDG_RUNTIME_DIR}/portable/${appID}/startSignal") = "app-started" ]]; then 1056 | pecho warn "Application started before passPid()" 1057 | else 1058 | inotifywait \ 1059 | -e modify \ 1060 | --quiet \ 1061 | "${XDG_RUNTIME_DIR}/portable/${appID}/startSignal" 1>/dev/null 1062 | fi 1063 | getChildPid 1064 | echo "${childPid}" >"${XDG_DATA_HOME}/${stateDirectory}/mainPid" 1065 | unset childPid 1066 | local childPid=$(systemctl --user show "${friendlyName}-dbus" -p MainPID | cut -c '9-') 1067 | sed -i \ 1068 | "s|placeholderChildPid|${childPid}|g" \ 1069 | "${XDG_RUNTIME_DIR}/.flatpak/${instanceId}/bwrapinfo.json" 1070 | 1071 | sed -i \ 1072 | "s|placeholderMntId|$(readlink /proc/${childPid}/ns/mnt | sed 's/[^0-9]//g')|g" \ 1073 | "${XDG_RUNTIME_DIR}/.flatpak/${instanceId}/bwrapinfo.json" 1074 | sed -i \ 1075 | "s|placeholderPidId|$(readlink /proc/${childPid}/ns/pid | sed 's/[^0-9]//g')|g" \ 1076 | "${XDG_RUNTIME_DIR}/.flatpak/${instanceId}/bwrapinfo.json" 1077 | echo "finish" >"${XDG_RUNTIME_DIR}/portable/${appID}/startSignal" 1078 | } 1079 | 1080 | function stopApp() { 1081 | pecho info "Stopping application..." 1082 | if [[ $@ =~ "force" ]]; then 1083 | pecho info "Stopping the application on user request" 1084 | else 1085 | sleep 1s 1086 | if [[ $(systemctl --user list-units --state active --no-pager "${friendlyName}*") =~ '-subprocess-' ]] || [[ $(systemctl --user list-units --state active --no-pager "${friendlyName}*") =~ "${friendlyName}.service" ]]; then 1087 | pecho warn "Not stopping the slice because one or more instance are still running" 1088 | return 0 1089 | fi 1090 | fi 1091 | systemctl \ 1092 | --user stop \ 1093 | "portable-${friendlyName}.slice" 1094 | rm -rf "${XDG_RUNTIME_DIR}/.flatpak/${instanceId}" 1095 | rm -rf "${XDG_RUNTIME_DIR}/.flatpak/${appID}" 1096 | rm -rf "${busDir}" 1097 | rm -rf "${XDG_RUNTIME_DIR}/portable/${appID}" 1098 | rm -rf "${busDirAy}" 1099 | rm -rf \ 1100 | "${XDG_DATA_HOME}/applications/${appID}.desktop"\ 1101 | 2>/dev/null 1102 | } 1103 | 1104 | function resetDocuments() { 1105 | flatpak permission-reset "${appID}" 1106 | } 1107 | 1108 | function cmdlineDispatcher() { 1109 | local cmdlineArgs=("$@") 1110 | local indexSep=-1 1111 | 1112 | for i in "${!cmdlineArgs[@]}"; do 1113 | if [[ "${cmdlineArgs[${i}]}" == "--" ]]; then 1114 | indexSep=${i} 1115 | break # break the loop at separater 1116 | fi 1117 | continue 1118 | done 1119 | 1120 | local appArgs=() 1121 | if [[ ${indexSep} -ge 0 ]]; then 1122 | appArgs=("${cmdlineArgs[@]:$((indexSep + 1))}") 1123 | fi 1124 | export targetArgs="${appArgs[@]}" 1125 | pecho info "Application argument interpreted as: ${targetArgs}" 1126 | 1127 | if [[ $@ =~ "f5aaebc6-0014-4d30-beba-72bce57e0650" ]] && [[ $@ =~ "--actions" ]]; then 1128 | rm -f \ 1129 | "${XDG_DATA_HOME}"/${stateDirectory}/options/sandbox 1130 | questionFirstLaunch 1131 | fi 1132 | if [[ $@ =~ "--actions" ]] && [[ $@ =~ "opendir" ]]; then 1133 | /usr/lib/flatpak-xdg-utils/xdg-open "${XDG_DATA_HOME}"/${stateDirectory} 1134 | exit $? 1135 | fi 1136 | if [[ $@ =~ "--actions" ]] && [[ $@ =~ "share-files" ]]; then 1137 | shareFile 1138 | fi 1139 | if [[ $@ =~ "--actions" ]] && [[ $@ =~ "reset-documents" ]]; then 1140 | resetDocuments 1141 | fi 1142 | } 1143 | 1144 | if [[ $@ = "--actions quit" ]]; then 1145 | stopApp force 1146 | exit $? 1147 | fi 1148 | 1149 | sourceXDG 1150 | questionFirstLaunch 1151 | manageDirs 1152 | cmdlineDispatcher $@ 1153 | launch $@ 1154 | 1155 | --------------------------------------------------------------------------------