├── .editorconfig ├── .gitattributes ├── .github └── workflows │ └── CI.yml ├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── build.ps1 ├── doc ├── REFERENCES.md ├── TODO.md ├── faq.md ├── junk │ └── garbage.txt ├── next.md ├── security.md └── tunic-logo.svg ├── files ├── distros.ps1 ├── grub.cfg ├── preseed.cfg └── tunic-logo.ico ├── main.go ├── run.py ├── setup.py ├── test.mk ├── test ├── allow.ps1 ├── test-loop.sh ├── test-setup.bat ├── test-setup.ps1 └── tunic.bat ├── tunic.nsi └── tunic.ps1 /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | insert_final_newline = true 6 | indent_size = 4 7 | trim_trailing_whitespace = true 8 | end_of_line = lf 9 | 10 | [*.{cmd,bat,ps1,psm1,psd1,nsi}] 11 | end_of_line = crlf 12 | 13 | [*.{ps1xml,props,xml.yaml,yml}] 14 | indent_size = 2 15 | 16 | [*.sh] 17 | indent_size = 2 18 | 19 | [*.md] 20 | indent_size = undef 21 | 22 | [*.go] 23 | indent_style = tab 24 | 25 | [{LICENSE,garbage.txt}] 26 | indent_size = undef 27 | trim_trailing_whitespace = undef 28 | 29 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | 3 | *.nsi text eof=crlf 4 | *.ps1 text eol=crlf 5 | *.psm1 text eol=crlf 6 | *.psd1 text eol=crlf 7 | *.cmd text eol=crlf 8 | *.bat text eol=crlf 9 | 10 | -------------------------------------------------------------------------------- /.github/workflows/CI.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | runs-on: windows-2019 8 | steps: 9 | - name: Checkout 10 | uses: actions/checkout@v2 11 | - name: Test 12 | run: make utest 13 | 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | tunic.exe 2 | tunic 3 | tmp 4 | *.ova 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 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | include test.mk 2 | 3 | default: utest 4 | 5 | tunic.exe: main.go 6 | GOOS=windows GOARCH=amd64 go build -o tunic.exe 7 | 8 | tunic: main.go 9 | GOOS=linux GOARCH=amd64 go build 10 | 11 | # public aliases (phony) 12 | 13 | clean: 14 | go clean 15 | rm -f tunic.exe tunic 16 | 17 | build: tunic.exe tunic 18 | 19 | run: main.go 20 | go run main.go 21 | 22 | all: clean unittest tunic tunic.exe 23 | 24 | #TODO: 25 | # aliases: https://stackoverflow.com/questions/23135840/alias-target-name-in-makefile/33594470#33594470 26 | # 27 | 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tunic 2 | 3 | Install Linux over or alongside an existing Windows install, straight from Windows, 4 | without requiring to boot from external media like a flash drive or making BIOS configuration changes. 5 | 6 | ![Alt text](https://i.imgur.com/VOhRiGh.png) 7 | ![Alt text](https://i.imgur.com/YNNt4HZ.png) 8 | ![Alt text](https://i.imgur.com/9P8auhO.png) 9 | 10 | ### What Tunic Does 11 | 12 | * Validates your system meets Tunic requirements. 13 | * Asks all questions at beginning (so you don't have to babysit the install). 14 | * Offers full disk overwrite or dual boot arrangement. 15 | * If dual boot, shrink C: volume to make space for Linux. 16 | * Provides tools to assist with freeing up space for Linux. 17 | * Disables Windows fast start. 18 | * Provides Linux Mint, Ubuntu and most official Ubuntu flavors. 19 | * Downloads the Linux .iso file for you. 20 | * Installs Grub with Secure Boot support. 21 | * Calculates Linux equivalent values for your Windows locale and user account. 22 | * Reboots and runs the Ubiquity installer, automated, (fully in RAM with mounts to the iso removed). 23 | * If custom install type choosen, will provide Ubuntu's Ubiquity disk partiton GUI. 24 | * Reboots into your final installed Linux! 25 | 26 | See the [TODO](doc/TODO.md) for ideas for future versions. 27 | 28 | ### Requirements 29 | 30 | * Windows 10, 64 bit 31 | * Single drive hosting the C: volume 32 | * At least 4 GB RAM 33 | * At least 15 GB of free disk space 34 | * UEFI 35 | * Administrator user permissions 36 | * Internet access 37 | * AC Wall Power 38 | 39 | ### Limitations 40 | 41 | * Currently, Tunic only installs official flavors of Ubuntu and Linux Mint. 42 | * We are working on Windows 7 and 8, MBR, and support for other Debian/Ubuntu based Linux distros. 43 | * Error handling needs improvement. 44 | * Due to the nature of what Tunic does, it may show up as a false positive on some malware scans. 45 | 46 | ### More information 47 | 48 | See the [doc](doc) directory for more information. 49 | 50 | ## Getting Started 51 | 52 | ### Preparation 53 | 54 | * Backup your data! 55 | 56 | Before you start, make sure to backup up an image of your entire disk(s). 57 | Tunic does not assist with full disk backup. 58 | Read disclaimer for more information. 59 | 60 | No, really. Backup your data. 61 | 62 | * Close all other running applications. 63 | 64 | ### Usage 65 | 66 | 1. Download and run the 67 | [latest executable file](https://github.com/mikeslattery/tunic/releases/latest/download/tunic.exe) 68 | from releases. 69 | 1. Answer questions. 70 | 1. Let it run. It may take a long time. 71 | 1. Enjoy your new Linux OS! 72 | 73 | If you were able to install Linux with Tunic, please 74 | add a comment to [Success Stories](https://github.com/mikeslattery/tunic/issues/12), 75 | or send a message [to the author](https://www.reddit.com/message/compose/?to=funbike). 76 | 77 | See the [FAQ](doc/faq.md) if you need further help. 78 | 79 | ## Legal Stuff 80 | 81 | ### License 82 | 83 | Copyright (c) 2020 Michael Slattery. See commit history for list of other authors. 84 | 85 | Distributed under the [GNU General Public License, version 3](https://www.gnu.org/licenses/gpl-3.0.html). 86 | 87 | ### Disclaimer 88 | 89 | This software could inadvertantly and permanently destroy all data, leave a computer unbootable, 90 | or otherwise leave a computer in an undesirable state. 91 | This software comes as-is with absolutely no warranty. 92 | Read sections [15, 16, and 17](https://www.gnu.org/licenses/gpl-3.0.html#section15) 93 | of the GNU GPL version 3 license for more information. 94 | 95 | -------------------------------------------------------------------------------- /build.ps1: -------------------------------------------------------------------------------- 1 | # Tunic Linux Installer for Windows 2 | # Copyright (c) Michael Slattery under GPLv3 with NO warranty. 3 | # For more info see https://www.gnu.org/licenses/gpl-3.0.html#section15 4 | 5 | # Automated install of an ISO file 6 | # Windows build script 7 | 8 | # This is only for packaging a convenient, self-extracting .exe. 9 | # tunic.ps1 is usable without packaging. 10 | 11 | # Strict mode 12 | 13 | Set-StrictMode -version 1.0 14 | $ErrorActionPreference = 'Stop' 15 | 16 | # Install tools 17 | 18 | function addToPath($dir) { 19 | $path=(Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).path 20 | $path="$path;$dir" 21 | Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $path 22 | 23 | $env:PATH = "${env:PATH};$dir" 24 | } 25 | 26 | if( ! ( Get-Command "choco" -ErrorAction SilentlyContinue ) ) { 27 | $web = (New-Object System.Net.WebClient) 28 | iex $web.DownloadString('https://chocolatey.org/install.ps1') 29 | } 30 | 31 | if( ! ( Get-Command "makensis" -ErrorAction SilentlyContinue ) ) { 32 | choco install -y nsis 33 | addToPath 'C:\Program Files (x86)\NSIS' 34 | } 35 | 36 | # Syntax check 37 | 38 | .\tunic.ps1 noop 39 | 40 | # Clean 41 | 42 | Remove-Item tunic.exe -ErrorAction Ignore 43 | 44 | # Convert tunic.ps1 to tunic.exe 45 | 46 | makensis /V2 tunic.nsi 47 | 48 | copy tunic.exe ~/Desktop/. -force 49 | 50 | -------------------------------------------------------------------------------- /doc/REFERENCES.md: -------------------------------------------------------------------------------- 1 | # Reseach and References 2 | 3 | ## References 4 | 5 | ### Backup and Recovery 6 | 7 | * 8 | * 9 | * 10 | * 11 | * 12 | * 13 | * 14 | 15 | ### Cleanup 16 | 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | 25 | ### Install Linux 26 | 27 | * 28 | * 29 | 30 | ### Downloads 31 | 32 | * 33 | 34 | ### ISO 35 | 36 | * 37 | * 38 | * 39 | 40 | ### VM 41 | 42 | * 43 | * 44 | * 45 | * 46 | * 47 | * 48 | * 49 | 50 | ### Testing and Support 51 | 52 | * 53 | * 54 | 55 | ### Boot Menu 56 | 57 | #### Repartitioning 58 | 59 | * 60 | * 61 | 62 | #### Swap file 63 | * 64 | * 65 | 66 | #### MBR 67 | 68 | * 69 | * 70 | * 71 | 72 | #### EFI 73 | 74 | * 75 | * 76 | * 77 | * 78 | * 79 | * 80 | * 81 | * 82 | * 83 | * 84 | * 85 | * 86 | 87 | ### Automated Install 88 | 89 | #### Ubiquity 90 | 91 | * 92 | * 93 | * 94 | * 95 | * 96 | 97 | #### Preseeding 98 | 99 | * 100 | * 101 | * 102 | * 103 | * 104 | * 105 | * 106 | * 107 | * 108 | * 109 | * 110 | * 111 | * 112 | * 113 | * 114 | * 115 | * 116 | 117 | ### Keyboard 118 | * 119 | * 120 | * 121 | 122 | #### Kickstart 123 | 124 | * 125 | * 126 | 127 | #### Migration 128 | 129 | * 130 | 131 | ### Post Install 132 | 133 | These are things that can be used after the install for better integration between the partitions. 134 | 135 | * 136 | * 137 | * 138 | * 139 | 140 | ### Powershell 141 | 142 | * 143 | 144 | #### GUI 145 | * [Go native Windows toolkit](https://github.com/lxn/walk) 146 | * 147 | * 148 | * 149 | * 150 | * 151 | 152 | #### 7Zip 153 | * 154 | * 155 | * 156 | 157 | #### Timezone 158 | * 159 | * 160 | * 161 | * 162 | 163 | -------------------------------------------------------------------------------- /doc/TODO.md: -------------------------------------------------------------------------------- 1 | # Roadmap and TODOs 2 | 3 | ## Goals 4 | 5 | * As easily and as robustly as possible, convert a standard Windows system 6 | to dual boot with Linux without the need for a USB drive or firmware changes. 7 | * Linux to be configured the same as Windows with similar applications. 8 | 9 | ## Technology 10 | 11 | This is subject to change over time. 12 | 13 | * Runs from Windows as exe file 14 | * Written in Powershell and Python 15 | * YAML configured 16 | 17 | ## Versions 18 | 19 | ### MVP 20 | 21 | * Opinionated, limited, non-robust 22 | * Requires: Powershell 1.0, Win 10 64bit, Single OS(win), single disk, C:, EFI 23 | * Installs: Dual boot, Linux Mint 64bit w/Cinnamon 24 | * Auto-Configure basics: user account, locale, lang 25 | * No support: XP/7/8, MBR, Bitlocker, AD, 32bit, LVM 26 | * Run as exe as administrator (ps2exe) 27 | 28 | ### MVP 2 29 | 30 | * Add Support: Other Ubuntu variants, Full disk, MBR convertion 31 | * Port config: wifi passwords, locale, Chrome/Firefox settings 32 | * Limited efi backup/restore/revert functionality. before.cfg, after.cfg 33 | 34 | ### 1.0 35 | 36 | * Add support: Windows 7/8, MBR, flexible partitioning, 32 bit Windows, Bitlocker, Full disk 37 | * Choice of several Debian/Ubuntu based distros 38 | * Port settings and apps 39 | * Plugins and flexible configuration to make it easy for others to help 40 | * Buttons to go to web sites for help: google search, ubuntu support 41 | * LVM and/or partition util? 42 | * Desktop icons: efi recover, OS in VM, reboot, browse files 43 | * VirtualBox Linux host runs Windows partition. 44 | * Keyboard layout preseed/import 45 | * Detect accidental Linux MBR install. Fix and/or replace. 46 | * Nvidia options: restrict distro list, install driver, disable nvidia, do nothing. 47 | * Laptop specific packages and settings 48 | * Add useful secondary repos and other common distro tweaks 49 | * Autoupdates checkbox 50 | * Tunic welcome app 51 | * `nomodeset` checkbox. 52 | * Detect SATA mode RAID. Inform user to set to AHCI. 53 | * Troubleshooting screen, if tunic was used before (to completion). 54 | 55 | ## Other Possible Use Cases and sub-components 56 | 57 | ### Spins 58 | 59 | * USB/PXE Tunic. Meant for multiple machines. Can save inputs to USB file for use on subsequent machines. 60 | * OEM Tunic. Useful as initial installed launchpad OS. Wifi required. Pi spin. 61 | * Enterprise Tunic. Uniform PXE/USB installations. 62 | * Distro Tunic. Regular app for specific distro. 63 | * Tunic for MacOS/Linux/RaspPi/ChromeOS. 64 | * Tunic for Android. Similar to Termux. 65 | * Evil Tunic. Auto-install. No user password. iso and exe variants. 66 | 67 | ### Windows 68 | 69 | * Import apps from Windows to OSS Windows 70 | * Cleanup disk 71 | * Install Linux in a VM 72 | * Full convert from Windows to Linux 73 | * Install existing Linux partition as VM 74 | * Uninstall Linux dual boot 75 | * Install WSL to partition. Boots Ubuntu and chroot to WSL. 76 | * Convert Linux VM to a partition 77 | * Run Linux in file on ntfs/ext4 loopback 78 | * Auto-repair Linux nvram entry. Auto-reboot, if linux was default and last booted OS. 79 | * "Reboot to Linux" shortcut 80 | 81 | ### Windows and Linux 82 | 83 | * EFI/Grub/boot menu restore or repair 84 | * Make persistent USB 85 | * Shrink/Split/merge/move partitions. 86 | * Shrink windows/expand Linux 87 | * Backup/Restore MBR/EFI 88 | * Make Live USB 89 | * Live USB with multiple distros 90 | 91 | ### Linux 92 | 93 | * Convert Windows Partition to VM and delete from grub/nvram 94 | * Distro hop switcher 95 | * Import settings/apps from Windows to Linux 96 | * Remove Windows 97 | * Install Windows after Linux 98 | * Install Windows into VM 99 | * Install another Linux distro over current. 100 | * Recovery partition/chroot. Non-LVM. Alpine. Grub, LVM tools and scripts. 101 | * Convert to LVM 102 | * Fast EFI boot (fwbootmgr -> efistub w/ ext4,lvm efi drivers) 103 | * Decimate Windows. Delete all except user files. defrag, shrink. 104 | * access WSL from Linux. /mnt/wsl. v1 read only. v2 mount the VM disk. 105 | * "Reboot to Windows" shortcut 106 | 107 | ### Stability and Robustness 108 | 109 | * Before start of install, remove custom grub by Tunic. 110 | * Grub timeout. Boot back to windows and remove tunic's grub. 111 | * Windows Task on boot that reinstalls Grub's NVRAM entry, if missing. 112 | * Windows Task on boot that removes custom grub by Tunic. 113 | * NVidia warning. Recommend PopOS. Disable opt-out. Driver package. 114 | * Model/Vendor specific workarounds for various issues. 115 | 116 | ### Far Future 117 | 118 | * Theming/ricing 119 | * Support for: Windows Vista/XP, 32bit w/MBR, MBR 120 | * AD domain login 121 | * Fully remove Windows with option to convert to VM 122 | * Minimal distro default if <=2GB. 123 | * Non-debian distros. 124 | * Distro switcher. Add multiple distros into menu. 125 | * Assist with backup 126 | * Warnings/help for known problematic hardware 127 | * MacOS to Elementary OS 128 | 129 | ## TODOs 130 | 131 | ### Development 132 | 133 | #### Short-term Challenges 134 | * Install grub from single source (ubuntu 18.04 + grub-for-windows) 135 | * Re-enable swap. fix caption 136 | 137 | ### Medium term challenges 138 | * Auto-Resume from reboot 139 | * Disable swap without reboot 140 | 141 | #### Long Term Challenges 142 | * Install powershell if not available 143 | * Help with backup/clone 144 | 145 | #### Testing setup 146 | * Vagrant 147 | * Linux host. Possible WSL/Cygwin support. 148 | * Download ISO and place in a cache directory. 149 | 150 | ### Documentation 151 | * Plugins how-to 152 | * contribute.md 153 | * support 154 | * how to write a ticket: .log file 155 | 156 | #### Contributing doc 157 | * Work in branch 158 | * Suggest: ticket first with "thumbs up" from me. 159 | * Follow standards 160 | 161 | #### standards 162 | * .editorconfig 163 | * lint check 164 | * grub syntax checker 165 | 166 | ### User Warnings and Errors 167 | 168 | #### Checks 169 | 170 | * Administrator 171 | * enough space 172 | * 64 bit 173 | * Not on battery 174 | * EFI/GPT/MBR, no secure boot 175 | * Windows 10 176 | * Powershell libs available 177 | * Command line apps available 178 | * Bitlocker 179 | * Compatibility (some day) 180 | 181 | #### Hardware warnings and help 182 | 183 | * Detect nvidia. Give options with caveats. 184 | 185 | #### Warnings 186 | 187 | * Backup 188 | * Upgrade firmware 189 | * Might brick your machine 190 | * Limited support 191 | 192 | #### Uninstallers 193 | 194 | * grub.cfg + initrd.lz - Undo installation (up to this point) 195 | 196 | ## Support and Testing 197 | 198 | ### Manual Testing 199 | 200 | * MBR vs EFI 201 | * Test on Windows 7 202 | * Bitlocker 203 | * Secure boot 204 | 205 | ### Automated Testing 206 | * VirtualBox in VirtualBox. Nested VBox only supports 32bit OSes 207 | * Download VMs from Microsoft 208 | * Install apps in Windows 209 | * Cache file downloads (option) 210 | * Scenarios: MBR/EFI, Win 7/10 211 | * Scripted. 212 | * Limit phases. Use snapshots for start phase. 213 | 214 | ## Basic Flow 215 | 1. Clean 216 | 2. Create new parition 217 | 3. Copy ISO to partition (not including MBR) 218 | 4. Modify ISO partition to include seed files 219 | 5. Copy grub files to efi partition 220 | 6. Reboot to Linux 221 | 222 | ## Safety and Qualtiy 223 | 224 | * If Windows VM, disable ignore flush, enable host cache. https://www.virtualbox.org/ticket/4651 225 | * Immediately uninstall tunic grub during start of install 226 | * Disable nouveau 227 | 228 | -------------------------------------------------------------------------------- /doc/faq.md: -------------------------------------------------------------------------------- 1 | # FAQ 2 | 3 | ### Tunic ran and then rebooted back to Windows 4 | 5 | Sometimes Windows updates removes Tunic's grub menu entry. 6 | Install Windows updates, reboot, and try again. 7 | 8 | ### How can I remove Tunic? 9 | 10 | If anything goes wrong during the use of Tunic, you can fully uninstall it 11 | with the following commands in a PowerShell window as an Administrator. 12 | 13 | To remove the boot menu and the downloaded files: 14 | 15 | ``` 16 | bcdedit /delete $(cat C:\ProgramData\tunic\bcd.id) 17 | rm C:\ProgramData\tunic -recurse -force 18 | rm ~/Downloads/*.iso 19 | ``` 20 | 21 | To remove grub files. 22 | Don't run this after you have successfully installed Linux or it won't boot. 23 | 24 | ``` 25 | mountvol S: /s 26 | rm S:\boot -recurse -force 27 | mountvol S: /d 28 | ``` 29 | If you had attempted dual boot, you may want to expand your C: 30 | partition back to full size with this tool: 31 | ``` 32 | diskmgmt.msc 33 | ``` 34 | 35 | ### I get the Tunic boot menu but nothing works. 36 | 37 | You many want to uninstall tunic and try again. 38 | Use the "Microsoft Windows" menu item to boot into Windows 39 | and follow the "How can I remove Tunic?" instructions in this FAQ. 40 | 41 | If you can't boot into Windows, you'll have to go into your BIOS and 42 | [change the boot order](https://www.lifewire.com/change-the-boot-order-in-bios-2624528). 43 | 44 | ### When I download tunic.exe it disappears 45 | 46 | Some malware falsely treats Tunic as malware. 47 | Tunic replaces your bootloader which can look suspicious. 48 | 49 | See how to whitelist Tunic at: 50 | [Windows Defender](https://www.addictivetips.com/windows-tips/whitelist-apps-in-the-smartscreen-on-windows-10/). 51 | 52 | For more information see [security](security.md). 53 | 54 | ### How can I contact the author of Tunic? 55 | 56 | * [Enter an issue](https://github.com/mikeslattery/tunic/issues/new) in Github. 57 | * [Send a message](https://www.reddit.com/message/compose/?to=funbike). 58 | 59 | -------------------------------------------------------------------------------- /doc/junk/garbage.txt: -------------------------------------------------------------------------------- 1 | This file is for brain-storming. It's full of junk and garbage. 2 | WINDOWS TO LINUX 3 | 4 | architecture: 5 | powershell with System.Windows.Forms 6 | powershell core for Linux. MVP GUI pattern. 7 | powershell as DSL for config 8 | bundle as exe with elevated privs 9 | monkeypatching by plugins to fix issues. 10 | Automated testing 11 | Can't really do this until we have pre-MVP 12 | Test hardware uses HDD 13 | Triggered by push to master 14 | Everything will be set up to use an http proxy that will cache downloads. 15 | Start with full drive image backup, and separate C: partition image backup. 16 | Create report of config of partitions and bootmgr 17 | Windows script runs on boot. 18 | Waits for network trigger to start install. 19 | Auto start script downloads current code and runs it with default settings. 20 | Any error or warning is recorded. 21 | At end, reboot to Linux 22 | Linux post-install script 23 | chroot into tmpfs file system 24 | repartition C: + linux back to original 25 | recover backup image to partition 26 | Inject auto-run script 27 | Change boot manager to original 28 | verify partiion table and bootmgr is idential to start 29 | reboot 30 | 31 | documentation: 32 | plugins: how to write a plugin, include external repos. 33 | contribute: rules, licensing, todo, roadmap 34 | manually.md: how to install manually 35 | reference.md: research and background. 36 | manually.md: how to do everything it does on the command line, with links and images. 37 | support.md 38 | include .log file 39 | partition table 40 | systeminfo 41 | boot menu entries. bcdedit /list 42 | errors 43 | virtualbox VM report 44 | hyper-v status, if any 45 | readme.md: 46 | support and disclaimers 47 | 48 | 49 | 50 | 51 | repositories: 52 | - https://github.com/user/project 53 | winfs: /mnt/ntfs 54 | distros: 55 | # Only Ubuntu-based distros allowed 56 | ubuntu: 57 | description: ... 58 | iso: ... 59 | xubuntu: 60 | debian: 61 | mint: 62 | name: Linux Mint with Cinnamon 63 | iso: 64 | xmint: 65 | name: Linux Mint with Xfce 66 | importers: 67 | wine: 68 | vm: 69 | 70 | RootPlugins: 71 | - ScannerPlugin 72 | 73 | distro record 74 | description 75 | version 76 | distro template (e.g. ubuntu-flavors) 77 | download URLs or file (metalink, .torrent) 78 | flags: secure boot, 32 bit, MBR/EFI, beginner 79 | bootloader: grub, systemd-boot 80 | nvidia post-install script 81 | pre/post install scripts 82 | 83 | distro filters 84 | if os=64, only show 64 bit 85 | if hw=32, only show 32 bit 86 | if efi=64, only show 64 bit 87 | if efi=32, only show 32 bit 88 | if >4GB only show 64 bit 89 | else show both (mbr, hw=64, <=4GB RAM) 90 | 91 | legacy systems 92 | Windows XP < SP2 - download and install SP2 93 | Windows XP SP2 94 | Windows 95/98/ME - loadlin 95 | Only full disk replacement 96 | 97 | Testing cominations: 98 | Windows 98, XP, 7, 8.1, 10 99 | 32, 64 bit 100 | MBR, EFI 101 | combos: 98/32/MBR, XP/32/MBR, 7/(32/64)/MBR, (8/10)/(32-MBR/64-EFI), 10/32/EFI = 1+1+2+4+1 = 9 102 | base on marketshare: 10/64/EFI, 7/64/EFI, 8/64/EFI, 7/32/MBR 103 | mitigations: upgrade to 10, mbr2efi 104 | 105 | distro URLs and grub 106 | https://github.com/mbusb/multibootusb/tree/devel/data/multibootusb/grub/menus 107 | https://github.com/unetbootin/unetbootin/blob/master/src/unetbootin/distrolst.cpp 108 | https://github.com/bwnickle/YUMI/blob/master/srcLinux/.src/Add.module 109 | https://www.pendrivelinux.com/downloads/Universal-USB-Installer/Universal-USB-Installer-1.9.9.3.src.zip 110 | 111 | ----- 112 | grub for tunic 113 | 114 | * Instal Grub for Windows, 32 or 64 bit, MBR or UEFI 115 | * Boot to tunic grub only once using bcdedit /bootsequence 116 | * During install, remove tunic grub nvram and files 117 | 118 | ----- 119 | 120 | name: base 121 | description: Required by all other plugins 122 | priority: 0 123 | packages: [git,ansible,pip,snap] 124 | status: hidden,always 125 | 126 | 127 | name: Pictures 128 | usercopy: [Pictures, Documents, Videos] 129 | 130 | name: MozillaMaintenanceService 131 | match: 'Mozilla Maintenance Service' 132 | status: ignore 133 | 134 | ----- 135 | golang 136 | 137 | * Start out with unit tests, GHA, functional tests, packaging 138 | * fyne gui library 139 | * embed files into executable 140 | * github actions for builds 141 | * uac - https://gist.github.com/jerblack/d0eb182cc5a1c1d92d92a4c4fcc416c6 142 | 143 | pipeline 144 | * pandoc 145 | - github markdown 146 | - plantuml 147 | * makefiles and targets 148 | - vagrant to build Windows 7/10 VM 149 | - build tunic.exe (x-compile) 150 | - test on GHA Windows 151 | - test ubiquity on GHA ubuntu 152 | - markdown gfm to pandoc 153 | * testing 154 | - GHA ubuntu or linux desktop - headless fyne unit testing 155 | - GHA Windows or VB-shell - partial functional testing (just not reboot) 156 | - in-between - change /proc/cmdline reading in ubuiquity as output from previous step's grub.cfg 157 | - GHA Ubuntu or docker - partial functional testing - grub-emu, ubiquity, xvfb 158 | - not GHA but linux/VB/Windows - functional testing 159 | 160 | Specific checks 161 | * grub2-script-check 162 | * shellcheck -s ksh grub.cfg 163 | * override value of /proc/cmdline 164 | * See if unetbootin distro list updated. Compile just enough C++ code to generate a config file. 165 | * mvp 0 - --help --no-run 166 | 167 | * MVP 0 - Download and run last powershell version of tunic.exe. Manual build. 168 | * Github actions: Windows-based build and test script for Go. 169 | * release draft versions after `git push tag` on “develop” branch 170 | * MVP 1 171 | - Download Mint Cinnamon latest. 172 | - Copy .iso argument to efi 173 | - install grub and reboot. 174 | * secure boot support. 175 | * UAC elevate - https://github.com/mozey/run-as-admin 176 | * disable Windows fastboot. 177 | * validations  (e.g. UEFI, WIndows 10 64 bit, etc). 178 | * MVP 2 milestone - Hassle free.  No extra steps by users. 179 | - switch to master branch 180 | - start deploying releases (instead of drafts) 181 | * refactor 182 | - Go “best practice” project structure 183 | - static checkers 184 | - Vagrant 185 | - Makefiles 186 | * GUI - "Are you sure?"  pop-up 187 | * Single page GUI: ok, quit, progress  (no cancel) 188 | * mint and ubuntu flavors pulldown 189 | * progress %, cancel 190 | - Retries. Continue on failure. (HEAD, Range) 191 | * MVP 3 milestone - Nice GUI. 192 | * Refactor 193 | - Unstrangle. 194 | - 32 bit .exe on 64 bit OS 195 | * preseed basics (locale, TZ, kb) 196 | * Install types 197 | - install type field and preseed 198 | - free space pane w/o utilities 199 | * user fields pane 200 | * auto reboot into linux (if no user input required from ubiquity) 201 | * free space pane w/utilities 202 | * LUKS. Password 203 | * MVP 4 milestone - Feature parity with powershell Tunic 204 | * Windows Task - in powershell 205 | - Delete Tunic's custom grub 206 | - Fix missing Grub 207 | * Win 7, 32 bit, MBR support. 208 | * Win XP 32 bit support (64 bit in future) 209 | - "Install alongside..." not provided. 210 | * Testing matrix: Win XP/7/10, 32/64, MBR/EFI, BIOS/GPT 211 | * More distros and means for download 212 | - Embed Grub For Windows 213 | - kickstart support 214 | - iso list from unetbootin, multibootusb 215 | - aria2 or similar, metalink 216 | * distro filters 217 | - 32 Bit 218 | - Supports secure boot 219 | - Author's choice: Lightweight 220 | - Author's choice: Beginner Friendly 221 | 222 | 223 | References 224 | * https://github.com/anacrolix/torrent 225 | * aria2 - https://github.com/zyxar/argo 226 | * https://github.com/golang-standards/project-layout 227 | * example app - https://github.com/Jacalz/sparta 228 | * example app - https://github.com/airplayx/gormat 229 | * iso fs - https://github.com/diskfs/go-diskfs 230 | * repl - https://stackoverflow.com/questions/8513609/does-go-provide-repl 231 | 232 | Research 233 | * username, computername 234 | * diskspace `disableSwap(), clean(), defrag()` 235 | * `checks()` 236 | 237 | 238 | 239 | 240 | ----- 241 | 242 | # Core properties. 243 | name: git-bash 244 | is_ok_dupliate: false 245 | status: disabled # disable,always,ignore,backup,primary,hidden. 246 | # Must be installed. Similar 247 | # backup=don't install if a dup is available 248 | # primary=don't install any dups. This is best fit. 249 | # hidden=do not show in the list of apps. auto-select. 250 | time: 12 # Estimated minutes to install 251 | # Plugin properites 252 | match: #file path, or registry, or app name pattern 253 | - "$PROGRAMFILE/git" 254 | match-script: | 255 | ... 256 | wine: [] 257 | # Always install, even if a duplicate. 258 | match-expr: "python-expression" 259 | duplicate-of: [git] 260 | packages: [git] 261 | snaps: [] 262 | pip: [] 263 | copyhome: [.ssh, .gitconfig, .gitignore] 264 | #copy: ["from:to"] # if dest not in $HOME, root:root 644 265 | # Variables for scripts. populated by UIs 266 | environment: 267 | name: 'value' 268 | pre-install: 'bash' 269 | post-install: | 270 | #!/bin/bash 271 | if [ -f ~/.ssh/idrsa ]; then chmod 600 ~/.ssh/idrsa; fi 272 | form: 273 | #http://docs.yafowil.info/yaml.html 274 | ansible: 275 | ... 276 | 277 | 278 | * Ask: 279 | - I already have Linux installed in a partition 280 | - I Only have Windows installed. 281 | - This is a second attempt to use this program 282 | * scan 283 | - load all plugins into array 284 | - for each profile, scan all plugins. Remember duplicate matches. 285 | * ask questions 286 | - Questions for installers 287 | - User file tree to copy 288 | * Prepare HD: checkpoint, clean up, backup, defrag, repartition 289 | * start linux VM: install virtualbox, extensions, download iso, automate install, install VM, launch 290 | * Installs with progress 291 | - apt-get update + upgrade 292 | - Copy files 293 | - Install packages 294 | 295 | Use cases 296 | * Windows to dual-boot Ubuntu (default goal) 297 | * Ubuntu VM install. Install Ubuntu into a VM. 298 | * Ubuntu is already installed in a partition. Export Windows config. 299 | * Ubuntu is on a remote machine. Export Windows config over ssh. 300 | 301 | Post-Install use cases 302 | * Clean: Re-run clean, and restore pagefile, hiberfil.sys, etc. 303 | * Sync: Sync changes from Windows to Ubuntu 304 | * Hop: Change distro, reinstall apps. 305 | * Revert: Remove Ubuntu and go back to original configuration. 306 | * Commit: Delete C: partition, grow linux to fill its space. 307 | 308 | 309 | 310 | class PathMatchPlugin 311 | is_match() 312 | path:$PROGRAMFILE/git 313 | class RegistryMatchPlugin 314 | REG:... 315 | class DisplayNameRegexMatchPlugin 316 | match: 'NAME:^Greenshot' 317 | HKLM/HKCU:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall 318 | ignore if no UninstallString 319 | 320 | Plugin 321 | # Estimated time in minutes to complete task 322 | estimate(config) 323 | # Does this plugin match this app profile? 324 | is_match(profile) 325 | # User files that should be copied. 326 | user_files(profile) 327 | # Workflow Phases 328 | # Do any pre-install cleaning or backup. 329 | preclean(profile) 330 | before_questions(ui, profile) 331 | # Ask any questions. Can modify profile as necessary. 332 | gui(ui, profile) 333 | # Run before any installs 334 | pre_install(profile) 335 | # Install this app profile 336 | install(profile) 337 | # Run after all installs 338 | post_install(profile) 339 | 340 | computers/model/brand 341 | name: 342 | laptop: true 343 | (files) 344 | 345 | 346 | UI tabs 347 | 348 | Install - main ui 349 | Script - currently running scripts and progress bar. 350 | Past is white, current is yellow, future is gray. 351 | Log - past script + output 352 | buttons: save, files (brower temp files) 353 | 354 | 355 | Steps 356 | 357 | [x] Backup 358 | [x] Clean 359 | [x] Defrag 360 | [x] Repartition 361 | [x] Install 362 | [x] ... 363 | 364 | [MCüç[MCMMCûCÛMC 365 | 366 | Advice 367 | 368 | Best models for Linux 369 | * Dell 370 | * Lenovo 371 | * IBM Thinkpad 372 | 373 | [Abort] [Back] {Continue] 374 | 375 | Backup 376 | 377 | You should do full backup before continuing. 378 | Click Abort if you'd like to stop and do a backu. 379 | 380 | [Abort] [Back] {Continue] 381 | [Backup Manager] 382 | 383 | Cleanup 384 | 385 | We recommend cleaning your hard drive to free up space for the install 386 | and to temporarily get unmoveable files out of the way. 387 | 388 | [x] Disable swap file 389 | [x] Disable hibernate file 390 | [x] Remove restore points 391 | [x] Remove dumps 392 | [x] Clean temp 393 | [x] Defragment drive 394 | 395 | Swap and hibernate will be reset to their original values after the install is complete. 396 | 397 | [Abort] [Back] [Continue] 398 | 399 | Preparation steps. 400 | 401 | * Cleaning... 402 | * Checking prerequisites... 403 | (64bit, win10, not on battery, not fast boot, enough free space on Windows after clean) 404 | 405 | [Abort] [Back] {Continue] 406 | 407 | We suggest you back up your system before you being. 408 | 409 | Would you like us to perform a backup for you? ( ) Yes ( ) No 410 | Would you like us to removed unnecessary files? (*) Yes ( ) No 411 | Would you like us to defragment your drive? (*) Yes ( ) No 412 | Would you like us to create a new partition for Linux (*) Yes ( ) No 413 | 414 | [Abort] [Back] {Continue] 415 | 416 | Backup 417 | 418 | ???? 419 | 420 | 421 | [Abort] [Back] [Continue] 422 | 423 | Repartition 424 | 425 | C: partition size: 120GB 426 | 427 | $windows = Resize-Partition -size 70GB -disknumber 0 -partition 5 428 | $system = New-Partition -size 30GB -disknumber 0 -offset after-partition($windows) 429 | $home = New-Partition -usemaximumsize -disknumber 0 -offset after-partition($system) 430 | 431 | 432 | [Partition Table] 433 | [Abort] [Back] [Continue] 434 | 435 | Distro choice 436 | 437 | (*) Mint Cinnamon 438 | ( ) Mint Xfce (make default if low mem,cpu) 439 | ( ) Ubuntu 440 | ( ) XUbuntu 441 | ( ) KUbuntu 442 | 443 | [Abort] [Back] [Continue] 444 | 445 | Configurations 446 | 447 | [ ] Wallpaper 448 | [ ] Lock screen 449 | [ ] Screen saver 450 | [x] Wifi 451 | [x] Mouse sensitivity 452 | [ ] Sounds 453 | [x] Keyboard 454 | [x] 455 | [ ] VPN 456 | 457 | [Abort] [Back] [Continue] 458 | 459 | Applications 460 | 461 | 7 Zip [^] 462 | Evolution[^] 463 | Thunderbird 464 | 465 | [Abort] [Back] [Continue] 466 | 467 | Wine Applications. 468 | 469 | These applications are installed but have no Linux counterparts. They can be run with WINE. 470 | 471 | [ ] Photoshop 472 | 473 | [Abort] [Back] [Continue] 474 | 475 | Additional Applications 476 | 477 | [x] Laptop power management (detect if a laptop) 478 | [x] Automatic security updates 479 | [ ] SSH server 480 | [ ] TeamViewer 481 | [ ] Steam 482 | [ ] Synaptec 483 | [x] MS Fonts 484 | [x] VLC Media Player 485 | [ ] zram 486 | [ ] topgrade 487 | 488 | [Abort] [Back] [Continue] 489 | 490 | These files user files will be copied to /home/$USER. 491 | 492 | Source: C:\Users\$USER Dest: /home/$USER Owner: $USER:$USER Mode: 644 493 | [ ] AppData 494 | [x] Photos 495 | [x] .ssh 496 | [x] id_rsa 497 | 498 | Source: C:\git Dest: /home/$USER/git Owner: $USER:$USER Mode: 644 499 | 500 | (when adding, any dirs, check Windows file ownership and try to mimic) 501 | 502 | 503 | [Abort] [Back] [Continue] 504 | 505 | Unmatched Applications 506 | 507 | No match was found for these applications, but an application icon was found. Select which you would like to run inside of the Windows VM. 508 | 509 | [ ] Photoshop 510 | [x] Microsoft Office 511 | 512 | [Abort] [Back] [Continue] 513 | 514 | Unmatched Applications 515 | 516 | No match was found nor was any desktop icon. No action will be taken to install these applications. 517 | 518 | C++ Runtime 519 | 520 | [Abort] [Back] [Continue] 521 | 522 | Size. 523 | C: is using ____ GB with ____ GB of free space. 524 | Linux is estimaged to require ___ GB of space. 525 | 526 | How much space do you want to allocate for Linux? ____ GB 527 | Windows will retain ___ GB of free space. 528 | 529 | [x] Install Linux on newly from free space. 530 | 531 | [Manage Partitions] [Skip] 532 | [Abort] [Back] [Continue] 533 | 534 | Linux will be installed on drive _0_ partition _6_. 535 | 536 | Any data on the partition will be lost. 537 | 538 | [Manage Partitions] 539 | [Abort] [Back] [Continue] 540 | 541 | Disclaimer 542 | 543 | yada yada yada yada yada 544 | Not liable 545 | Won't move everything 546 | 547 | [Abort] [Back] [Agree] [Disagree] 548 | 549 | Click Continue to start install. 550 | 551 | [x] Reboot into Linux after successful install. 552 | 553 | [Abort] [Back] [Continue] 554 | 555 | Progress 556 | 557 | 11:35:32 Creating restore point... complete. 558 | 11:35:32 Cleaning up... complete. 559 | 11:35:32 Backing up... complete. 560 | 11:35:32 Defragmenting... 561 | 11:35:32 Repartitioning... 562 | 11:35:32 Installing Libreoffice... complete. 563 | 11:35:32 Copying user files... 564 | 565 | [%%%%%%%%%%%%%%%............] 566 | [%%%%.......................] 567 | Estiamated completion time: 3:40pm 568 | 569 | Done! 570 | 571 | You may now reboot to your Linux system. 572 | 573 | [Abort] [Back] 574 | [Exit] [Linux VM] [Reboot] 575 | 576 | Detect Secure Boot 577 | https://www.iceflatline.com/2009/09/how-to-dual-boot-windows-7-and-linux-using-bcdedit/ 578 | 579 | 580 | 581 | 582 | Version 0.1 583 | * Many assumptions: Win 10, single C:, virtualbox, dual boot, Mint cinnamon 584 | * If no "linux" partition, create it with powershell and bcdedit 585 | * Download and Install ISO to partition. 586 | * Launch in VM and then force launch of installer. 587 | * Bash script for installing windows apps and transfering data. 588 | 589 | Side idea: ultimate distro hopper 590 | * Tiny linux distro boots 591 | * Grub like menu to choose which distro 592 | * Menu Option to add one. 593 | * Common home partition. contains info on packages to install. 594 | * Other options: manage partitions, create recovery usb, recover windows. 595 | 596 | 597 | 598 | 599 | ------ FIRST TRY TO INSTLAL LINUX 600 | Full image backup using Clonezilla 601 | Full backup of all partitions from within Windows and do a test restore. 602 | Defrag and Repartition using Powershell. Shrink C: and create linux-system and linux-home partitions. 603 | Install Linux in VirtualBox on the Linux partitions. Automate the whole thing with powershell and Ubuntu kickstart. 604 | Use Windows boot manager instead of Grub2 for boot menu. 605 | Boot to Ubuntu and replace Win boot manager with Grub2 (if possible) 606 | And then wipe it all and install Void Linux as that's what I want to use. I might buy another cheap laptop for these experiments. 607 | 608 | On Linux, create VirtualBox VM image using WIndows' raw partition. 609 | 610 | Final testing: 611 | Reboot to test all scenarios: Linux w/Windows VM, Windows w/Linux VM. 612 | Restore back to beginning. 613 | 614 | You can first disable System Protection, System restore files, Fast startup, Hibernation mode, kernel memory dump, and page files as least temporarily. 615 | https://www.disk-partition.com/articles/size-of-available-shrink-space-in-mb-0-4348.html 616 | 617 | 618 | Install Linux from Windows? 619 | 620 | Looking for feedback. 621 | 622 | For fun, I'm going to experiment with installing dual-boot Linux on a Windows Laptop. I know it's generally considered not possible due to such a thing, but I'd like to at least try. Where do you think I'd have the biggest issues with this plan?: 623 | 624 | ------ 625 | Fix 626 | Quick clean (not hiber,swap) 627 | Questions (incl. password) 628 | Clean 629 | Defrag 630 | Reboot and Continue (w/o user intervention) 631 | Defrag 632 | Questions 633 | Repartition 634 | Download io 635 | Download/install VirtualBox 636 | Create VM 637 | Installing 638 | App installation 639 | grub 640 | Reboot to Linux w/auto-login 641 | Disable auto-login 642 | Alarm and notice of completion 643 | 644 | ---- RECENT 645 | 646 | Testing: 647 | * ./install-tools 648 | * use vagrant build of windows VMs 649 | * install stuff into the VM 650 | * include a very simple http server and modify hosts file 651 | * use as a snapshot from there 652 | * mapping to linux home dir 653 | * script to tell vagrant to use snapshot 654 | 655 | 0.0.1 - not reliable, but usable. 656 | +NSIS installer 657 | +check freespace. tell user they need to free up space. 658 | +mbr2gpt + ISO partition 659 | +download ISO 660 | +reboot (to ubiquity) 661 | 662 | 0.0.2 663 | +enable swap (if previously disabled) 664 | clear space 665 | /check freespace. disable swap and tell user to reboot and try again. 666 | mbr2gpt + ISO partition 667 | download ISO 668 | reboot (to ubiquity) 669 | 670 | 0.1.0 - MVP 671 | enable swap (if previously disabled) 672 | clear space 673 | +ask user: disk space 674 | check freespace. disable swap and tell user to reboot and try again. 675 | mbr2gpt + ISO partition 676 | +shrink C: 677 | +generate preseed values for simple install. No auto-approve 678 | download ISO 679 | reboot (to ubiquity) 680 | 681 | 0.1.1 682 | enable swap (if previously disabled) 683 | +skip to partition step if this is 2nd run. 684 | clear space. 685 | +checkpoint. 686 | ask user: disk space. 687 | mbr2gpt + ISO partition 688 | +shrink C: 689 | /generate preseed values. Will auto-approve, reboot, delete ISO post-install 690 | download ISO 691 | reboot (to ubiquity) 692 | 693 | * Pull down list of mirrors from site 694 | * Ping each with timeout. 695 | * use random 4 for download. use aria2 for download 696 | * separate fat32 partition: no other files. 697 | * run in background 698 | * resume as needed (reboots) 699 | 700 | TOP TODO: preseed 701 | # https://help.ubuntu.com/lts/installation-guide/example-preseed.txt 702 | d-i partman-auto/init_automatically_partition select biggest_free 703 | d-i partman-auto/choose_recipe select atomic 704 | 705 | ps1 tempalte - https://gist.github.com/9to5IT/9620683 706 | template engine - $ExecutionContext.InvokeCommand.ExpandString((get-content "preseed.cfg.tpl")) 707 | 708 | clean 709 | disable-swap 710 | defrag 711 | mbr2gpt 712 | download-iso 713 | iso part 714 | mount-iso 715 | install-grub 716 | - grub files 717 | - grub.cfg 718 | - preseed.cfg 719 | - bcdedit 720 | umount-iso 721 | repartition 722 | enable-swap 723 | cleanup 724 | - delete iso 725 | - delete iso part 726 | 727 | ---- 728 | windows.ps1 729 | controller.ps1 730 | api.ps1 731 | main.ps1 732 | 733 | -------------------------------------------------------------------------------- /doc/next.md: -------------------------------------------------------------------------------- 1 | # Tunic Linux Installer for Windows 2 | # Copyright (c) Michael Slattery under GPLv3 with NO warranty. 3 | # For more info see https://www.gnu.org/licenses/gpl-3.0.html#section15 4 | 5 | # 'Elementary OS - 5.1' = ''; 6 | # 'Zorin OS - 15.1' = ''; 7 | # 'Debian - 10/buster' = ''; 8 | # 'Debian - Testing' = ''; 9 | # 'AntiX - 19.1' = ''; 10 | # 'KDE Neon' 11 | 12 | 13 | ``` 14 | ``` 15 | ### tunic.ps1 16 | - test full install 17 | * windows 7 18 | - disable updates 19 | * Windows 7 / Python 20 | - new branch 21 | - python3, gtk, 32 bit, no choco 22 | - python linter 23 | - github actions 24 | - vim: editorconfig check 25 | - hello world - show hi/hello.txt 26 | - deploy with subdirs to windows 7 32 bit 27 | - arch: unit tests, MVP, mock OS 28 | - classes: powershell, wmi, exec 29 | - versions 30 | - defer to ubiquity, [x] disclaimer, static cfg 31 | - download iso, progress page 32 | - checks 33 | - locale/dynamic preseed 34 | - distro picker 35 | - user 36 | - install type, disk sizing 37 | * Downloads 38 | - If pwsh<3, install .NET 4.5. Check for and download 39 | https://docs.microsoft.com/en-us/powershell/scripting/wmf/setup/install-configure?view=powershell-7 40 | `Start-Process -FilePath D:\path\to\dotnetfx45_full_x86_x64.exe -ArgumentList "/q /norestart" -Wait -Verb RunAs` 41 | `echo $?` 42 | - If pwsh<3, install Powershell 3 for Windows 7 w/WMI, WinRM. 43 | * Check pending updates on restart 44 | * Require 6.1.7601 (64 bit) 45 | * $mount test 46 | * distros 47 | $vmlinux = (dir 'D:\' -file -filter '*vmlinu*' -recurse).FullName.toLower() -replace '^\w:','' -replace '\\','/' 48 | $initrd = (dir 'D:\' -file -filter '*initrd*' -recurse).FullName.toLower() -replace '^\w:','' -replace '\\','/' 49 | 50 | # only work if a single hit. otherwise use default, even if it doesn't exist 51 | #$global:data.iso_url = 'ubuntu-18.04.3-desktop-amd64.iso' 52 | #$global:data.iso_url = 'deepin-15.11-amd64.iso' 53 | import and modify grub /boot/grub/grub.cfg 54 | prefix (usb) to all paths 55 | grep linux grub.cfg | sed -r 's|([ \t=])/|\1(usb)/|g; s| file=[^ ]+ | |g s|iso-scan/filename=[^ ]+||g' 56 | add "kernel-params" to distros.ps1 - e.g. automatic-ubiquity 57 | inject preseed: file=, iso-scan/filename= 58 | reduce timeout or add if not exists. 3s 59 | * distro test - debug mode 60 | - preseed on success command that writes to a shared folder to let host know it all worked! 61 | - install vbox additions 62 | - log files 63 | - snapshot 64 | - shut down VM after startup 65 | - copy .iso back to host, if not exists 66 | - test waits for shutdown of VM and moves to next distro 67 | - on a very long timeout, kill it and mark as failure. 68 | - check that a snapshot was created 69 | * Ubuntu 19.10 errors - can't umount /cdrom 70 | * Download all dependencies and package, if compatible 71 | - grub-for-windows.zip 72 | - 18.04's grubx64.efi 73 | - PopOS's shimx64.efi 74 | - windowsZones.xml 75 | - 7z.exe (may not need it) 76 | - THIRDPARTYLICENSE 77 | * List of legal Qs 78 | - best way to list 3rd party licenses 79 | - license for shimx64? 80 | - gpl2 usable? 81 | * nvidia R&D 82 | * keyboard 83 | * full-disk: wait X min, screenshot 84 | - branch 85 | - checkout various commit-id's or stashes 86 | * debug boolean in $data 87 | - branch 88 | - fast - skip extra packages 89 | - install vbox guest additions 90 | - install openssh-server 91 | * How to help doc 92 | - relax risk 93 | * tesserat 94 | * MBR 95 | * Win 7. VM. Test 96 | * Win 7, EFI/MBR, 32/64 bit (hardware) testing 97 | * reboot-continue (to delete swap) 98 | * Advanced options 99 | * icons: os-uninstall, Windows files, 100 | * 1.0 101 | * abort.sh (also before.sh, after.sh) 102 | * bitlocker 103 | - get recovery key and tell user to write it down. 104 | - GRUB_TERMINAL=console 105 | - requires secure boot. 106 | - https://www.ctrl.blog/entry/dual-boot-bitlocker-device.html 107 | * uninstall - bcd import, delete part2, expand C:, delete tunic grub 108 | * log dump 109 | * pre-install: bit-torrent client seeding ubuntu installs 110 | * 32 bit 111 | * if laptop install TLP http://www.techcrafters.com/scripts/windows-system-management/determine-whether-a-machine-is-laptop-or-not.html 112 | ### Testing 113 | ### Bling 114 | * ico 115 | * Spash (during free space calc) 116 | * screenshot(s) 117 | ### tech debt 118 | * download to temp file and move 119 | * hash password 120 | * distros: key, sig url 121 | * nsis - ico 122 | * grub protection task 123 | * test bcd restore 124 | * grub-installer update-grub workaround in preseed.cfg 125 | * grub move to $ESP/tunic 126 | * after.sh 127 | * refactor - squash + hide, cli api, globals 128 | --- 129 | * keyboard select - https://github.com/linuxmint/ubiquity/blob/master/ubiquity/misc.py#L672 130 | * detect pending updates. refuse to install 131 | 132 | Help me 133 | * GPL headers 134 | * shim 135 | * screenshot 136 | 137 | 138 | * calc avilable as partition gap + sizemin - 2.1 139 | * required vs supported 140 | 141 | cards: checks, input, advanced, progress 142 | 143 | ## Check 144 | * Always show (even if briefly) 145 | * if all succeed, go to next 146 | * if fail, exit, re-check buttons. 147 | 148 | ## Basic questions 149 | * C: size, free 150 | * disk number: 1 151 | * Shrink Windows by: 10 GB 152 | * available space 153 | * "Tunic will use available space." 154 | * [Clean] button 155 | * Username(current) + Password + Password 156 | * Computer name 157 | * Distro: [Linux Mint, Cinnamon, 64 bit] 158 | * [ ] Advanced 159 | * [ ] Agree 160 | * Continue 161 | 162 | # Advanced options 163 | * ISO URL or file: https://... 164 | * Browse Config files (dir of generated preseed.cfg, grub.cfg, ks.cfg) 165 | * [ ] Skip shrink partition (clean, disable swap, defrag, reboot-cont) 166 | * [ ] Skip Ubiquity UI 167 | * [x] Reboot now 168 | 169 | # validation 170 | * https://stackoverflow.com/questions/4645126/looking-for-regex-code-for-hostname-machine-name-validation 171 | * https://stackoverflow.com/questions/1221985/how-to-validate-a-user-name-with-regex 172 | * everything is non null 173 | * shrink <= available 174 | * either: shrink size or unused space is > ubuntu requirement + iso + new-efi 175 | * accept = checked 176 | 177 | ## Basic questions - progress 178 | 179 | * PSJob in background 180 | * Abort button 181 | * if, MBR unhide Continue button 182 | * Converting to EFI n/a (don't auto-reboot if this is done) 183 | * Remove swap 184 | * Defragmenting Done 185 | * Add swap 186 | * Partitioning In Progress 187 | * Downloading To do 188 | * enable Continue 189 | 190 | # preseed values 191 | (Get-WinSystemLocale).name -eq 'en-US' 192 | (Get-WinSystemLocale).textInfo.culturename -eq 'en' 193 | (Get-Culture).TwoLetterISOLanguageName -eq 'en' 194 | (Get-Culture).Name -eq 'en-US' 195 | (New-Object System.Globalization.RegionInfo (Get-Culture).Name).TwoLetterISORegionName -eq 'US' 196 | 197 | 198 | # loop 199 | $form = None 200 | while($true) { 201 | if(! $form ) $form.close() 202 | source view.ps1 203 | $form.show() 204 | } 205 | 206 | https://imgur.com/a/4xC0xsa 207 | <# Failed testing, usu. because of paths. 208 | @{ 209 | name='Pop!_OS - 19.10'; 210 | url='https://pop-iso.sfo2.cdn.digitaloceanspaces.com/19.10/amd64/intel/11/pop-os_19.10_amd64_intel_11.iso'; 211 | } 212 | @{ 213 | name='Pop!_OS - 18.04/LTS'; 214 | url='https://pop-iso.sfo2.cdn.digitaloceanspaces.com/18.04/amd64/intel/58/pop-os_18.04_amd64_intel_58.iso'; 215 | }, 216 | @{ 217 | name='Deepin 15.11'; 218 | url='https://osdn.net/projects/deepin/storage/15.11/deepin-15.11-amd64.iso'; 219 | } 220 | #> 221 | 222 | insmod ntfs 223 | insmod part_gpt 224 | 225 | # get iso_path, real_iso_path and preseed_path 226 | source /boot/grub/grub.var.cfg 227 | source /boot/grub/grub.params.cfg 228 | 229 | set iso_path="$real_iso_path automatic-ubiquity" 230 | 231 | # Load distro's cfg with iso root 232 | ``` 233 | set efi="$root" 234 | search --set=ntfs --file "$real_iso_path" 235 | loopback loop ($ntfs)"$real_iso_path" 236 | set root=(loop) 237 | source /boot/grub/grub.cfg 238 | set root="$efi" 239 | 240 | set timeout=3 241 | 242 | #TODO: win menu goes there 243 | linux /casper/vmlinuz file=/cdrom/preseed/linuxmint.seed boot=casper iso-scan/filename=${iso_path} quiet splash -- 244 | initrd /casper/initrd.lz 245 | 246 | linux (loop)/casper/vmlinuz file=/isodevice${tunic_dir}/preseed.cfg automatic-ubiquity boot=casper iso-scan/filename=${iso_path} toram noprompt -- 247 | initrd (loop)/casper/initrd.lz 248 | ----- 249 | pip install pyinstaller 250 | pip install pywin32 wmi 251 | pip install wmi 252 | 253 | --- windows7 254 | sed -rn '/^\s*+#/d; /\{/d; s/remove-item//i; s/new-object//i; s/start-process//i; s/write-host//i; s/out-null//i; s/[gs]et-content//i; s/test-path//i; s/where-object//i; s/^.*\b(\w+-\w+).*$/\1/p' tunic.ps1 | tr '[A-Z]' '[a-z]' | grep -Ev 'as-is|import-module|new-itemproperty|pop-os|re-part|set-loca|windirstat|xfce|7-zip|desktop-amd|remove-item|restart-computer|re-enabl' | sort | uniq -c | sort 255 | ``` 256 | r!xsel -o 257 | 258 | /disable-windowserrorreporting 259 | /enable-windowserrorreporting 260 | enable-computerrestore 261 | disable-computerrestore 262 | 263 | get-culture 264 | /get-timezone 265 | 266 | /complete-bitstransfer 267 | /resume-bitstransfer 268 | /start-bitstransfer 269 | 270 | add-type 271 | 272 | /get-bitlockervolume 273 | 274 | /confirm-securebootuefi 275 | /optimize-volume 276 | /get-partitionsupportedsize 277 | /resize-partition 278 | /get-volume 279 | /get-disk 280 | /dismount-diskimage 281 | /get-partition 282 | 283 | -------------------------------------------------------------------------------- /doc/security.md: -------------------------------------------------------------------------------- 1 | # Security and Malware 2 | 3 | Tunic makes deep changes your system. This has several security implications. 4 | 5 | ## Anti-Malware Detections 6 | 7 | Some anit-malware products falsely detect Tunic as malware. 8 | There can be various reasons for this, but mainly it's because of bootloader changes. 9 | Tunic is making deep changes to your system that aren't typical of user application software 10 | but is typical of malware. 11 | It's not surprising that this can occur. 12 | 13 | #### Verifying Tunic is Safe Code 14 | 15 | Probably the best way is to audit Tunic. The main file, tunic.ps1, is only 1200 lines as of this writing. 16 | It wouldn't take much effort to review it completely. 17 | 18 | To check that tunic.exe only contains files from the github project, 7zip can be used to extract the contents: 19 | 20 | ``` 21 | 7z x tunic.exe 22 | ``` 23 | 28 | -------------------------------------------------------------------------------- /doc/tunic-logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /files/distros.ps1: -------------------------------------------------------------------------------- 1 | @( 2 | @{ 3 | name='Linux Mint 19.3 - Cinnamon'; 4 | url='http://mirrors.gigenet.com/linuxmint/iso/stable/19.3/linuxmint-19.3-cinnamon-64bit.iso'; 5 | }, 6 | @{ 7 | name='Linux Mint 19.3 - MATE'; 8 | url='http://mirrors.gigenet.com/linuxmint/iso/stable/19.3/linuxmint-19.3-mate-64bit.iso'; 9 | }, 10 | @{ 11 | name='Linux Mint 19.3 - Xfce'; 12 | url='http://mirrors.gigenet.com/linuxmint/iso/stable/19.3/linuxmint-19.3-xfce-64bit.iso'; 13 | }, 14 | 15 | @{ 16 | name='Ubuntu 18.04/LTS'; 17 | url='http://releases.ubuntu.com/18.04.4/ubuntu-18.04.4-desktop-amd64.iso'; 18 | }, 19 | @{ 20 | name='Ubuntu 19.10'; 21 | url='http://releases.ubuntu.com/19.10/ubuntu-19.10-desktop-amd64.iso'; 22 | }, 23 | 24 | @{ 25 | name='Xubuntu 18.04/LTS'; 26 | url='http://cdimage.ubuntu.com/xubuntu/releases/18.04.3/release/xubuntu-18.04-desktop-amd64.iso'; 27 | }, 28 | @{ 29 | name='Xubuntu 19.10'; 30 | url='http://cdimage.ubuntu.com/xubuntu/releases/19.10/release/xubuntu-19.10-desktop-amd64.iso'; 31 | }, 32 | 33 | @{ 34 | name='Kubuntu 18.04/LTS'; 35 | url='http://cdimage.ubuntu.com/kubuntu/releases/18.04.3/release/kubuntu-18.04-desktop-amd64.iso'; 36 | }, 37 | @{ 38 | name='Kubuntu 19.10'; 39 | url='http://cdimage.ubuntu.com/kubuntu/releases/19.10/release/kubuntu-19.10-desktop-amd64.iso'; 40 | }, 41 | 42 | @{ 43 | name='Lubuntu 18.04/LTS'; 44 | url='http://cdimage.ubuntu.com/lubuntu/releases/18.04.3/release/lubuntu-18.04-desktop-amd64.iso'; 45 | }, 46 | @{ 47 | name='Lubuntu 19.10'; 48 | url='http://cdimage.ubuntu.com/lubuntu/releases/19.10/release/lubuntu-19.10-desktop-amd64.iso'; 49 | }, 50 | 51 | @{ 52 | name='Ubuntu Budgie 18.04/LTS'; 53 | url='http://cdimage.ubuntu.com/ubuntu-budgie/releases/18.04.3/release/ubuntu-budgie-18.04-desktop-amd64.iso'; 54 | }, 55 | @{ 56 | name='Ubuntu Budgie 19.10'; 57 | url='http://cdimage.ubuntu.com/ubuntu-budgie/releases/19.10/release/ubuntu-budgie-19.10-desktop-amd64.iso'; 58 | }, 59 | 60 | @{ 61 | name='Ubuntu Mate 18.04/LTS'; 62 | url='http://cdimage.ubuntu.com/ubuntu-mate/releases/18.04.3/release/ubuntu-mate-18.04-desktop-amd64.iso'; 63 | }, 64 | @{ 65 | name='Ubuntu Mate 19.10'; 66 | url='http://cdimage.ubuntu.com/ubuntu-mate/releases/19.10/release/ubuntu-mate-19.10-desktop-amd64.iso'; 67 | } 68 | ) 69 | 70 | -------------------------------------------------------------------------------- /files/grub.cfg: -------------------------------------------------------------------------------- 1 | # Tunic Linux Installer for Windows 2 | # Copyright (c) Michael Slattery under GPLv3 with NO warranty. 3 | # For more info see https://www.gnu.org/licenses/gpl-3.0.html#section15 4 | 5 | # get values for iso_file 6 | source '/boot/grub/grub.var.cfg' 7 | 8 | set ALLUSERSPROFILE='/ProgramData' 9 | set tunic_dir="${ALLUSERSPROFILE}/tunic" 10 | 11 | set timeout=2 12 | 13 | insmod part_gpt 14 | insmod ntfs 15 | insmod all_video 16 | 17 | menuentry "Tunic Automatic Linux Installer" { 18 | search --set=root --no-floppy --file $iso_path 19 | loopback loop ($root)$iso_path 20 | 21 | ls 22 | ls ($root) 23 | echo '' 24 | echo "ISO: ${root} ${iso_path}" 25 | echo '' 26 | 27 | echo 'Loading Linux kernel...' 28 | linux (loop)/casper/vmlinuz file=/isodevice${tunic_dir}/preseed.cfg automatic-ubiquity boot=casper iso-scan/filename=${iso_path} nomodeset toram noprompt -- 29 | 30 | echo 'Loading ramdisk...' 31 | if [ -f (loop)/casper/initrd.lz ]; then 32 | initrd (loop)/casper/initrd.lz 33 | else 34 | initrd (loop)/casper/initrd 35 | fi 36 | 37 | echo 'Booting Linux...' 38 | } 39 | 40 | menuentry "Try out Linux without install" { 41 | search --set=root --no-floppy --file $iso_path 42 | loopback loop ($root)$iso_path 43 | 44 | ls 45 | ls ($root) 46 | echo '' 47 | echo "ISO: ${root} ${iso_path}" 48 | echo '' 49 | 50 | echo 'Loading Linux kernel...' 51 | linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=${iso_path} nomodeset toram noprompt -- 52 | echo 'Loading ramdisk...' 53 | if [ -f (loop)/casper/initrd.lz ]; then 54 | initrd (loop)/casper/initrd.lz 55 | else 56 | initrd (loop)/casper/initrd 57 | fi 58 | 59 | echo 'Booting Linux...' 60 | } 61 | 62 | # TODO: menuentry "Abort Tunic Linux Installer" 63 | # checkboxes for: remove grub files+nvram, expand C:, delete .iso 64 | 65 | menuentry 'Microsoft Windows' { 66 | insmod fat 67 | set loader=/EFI/Microsoft/Boot/bootmgfw.efi 68 | search --set=root --file $loader 69 | chainloader ($root)$loader 70 | } 71 | 72 | menuentry 'Firmware Configuration' { 73 | fwsetup 74 | } 75 | 76 | -------------------------------------------------------------------------------- /files/preseed.cfg: -------------------------------------------------------------------------------- 1 | # Tunic Linux Installer for Windows 2 | # Copyright (c) Michael Slattery under GPLv3 with NO warranty. 3 | # For more info see https://www.gnu.org/licenses/gpl-3.0.html#section15 4 | 5 | d-i partman/early_command string \ 6 | losetup -d /dev/loop0 || true; \ 7 | umount /isodevice || true; 8 | 9 | ubiquity ubiquity/success_command string \ 10 | in-target sed 's/^\(GRUB_CMDLINE_LINUX="\).*$/\1" #tunic/' /etc/default/grub || true; 11 | 12 | d-i preseed/late_command string \ 13 | in-target sed 's/^\(GRUB_CMDLINE_LINUX="\).*$/\1" #tunic/' /etc/default/grub || true; 14 | 15 | # Partition 16 | 17 | #d-i ubiquity/partman-skip-unmount boolean true 18 | d-i partman/unmount_active boolean true 19 | #d-i partman/filter_mounted boolean false 20 | 21 | d-i partman-auto/disk string /dev/sd$( [char]((Get-Partition -driveletter $global:letter).diskNumber + 97) ) 22 | d-i partman-auto/choose_recipe select atomic 23 | $( if( $global:data.installType -eq $DUALBOOT ) { "d-i partman-auto/init_automatically_partition select biggest_free" } else { "" }) 24 | $( if( $global:data.installType -eq $FULLBOOT ) { "d-i partman-auto/init_automatically_partition select Guided - use entire disk" } else { "" }) 25 | $( if( $global:data.installType -eq $FULLBOOT ) { "d-i partman-auto/method string regular" } else { "" }) 26 | 27 | $( if( $global:data.installType -ne $CUSTOMBOOT ) { "d-i partman-partitioning/confirm_write_new_label boolean true" } else { "" }) 28 | $( if( $global:data.installType -ne $CUSTOMBOOT ) { "d-i partman/choose_partition select finish" } else { "" }) 29 | $( if( $global:data.installType -ne $CUSTOMBOOT ) { "d-i partman/confirm boolean true" } else { "" }) 30 | $( if( $global:data.installType -ne $CUSTOMBOOT ) { "d-i partman/confirm_nooverwrite boolean true" } else { "" }) 31 | 32 | # Locale 33 | 34 | d-i debian-installer/locale string $( (get-culture).ietfLanguageTag.replace('-','_') ).UTF-8 35 | d-i debian-installer/language string $( (get-culture).TwoLetterISOLanguageName ) 36 | d-i debian-installer/country string $( (New-Object System.Globalization.RegionInfo (Get-Culture).Name).TwoLetterISORegionName.toLower() ) 37 | d-i time/zone string $( getLinuxTimezone ) 38 | d-i clock-setup/utc boolean $( ($global:data.installType -ne $DUALBOOT).toString().toLower() ) 39 | 40 | # Keyboard 41 | 42 | d-i keyboard-configuration/xkb-keymap select us 43 | d-i keyboard-configuration/layoutcode select us 44 | d-i console-setup/ask_detect boolean false 45 | 46 | # User 47 | 48 | d-i passwd/user-fullname string $( $global:data.fullname ) 49 | d-i passwd/username string $( $global:data.username ) 50 | d-i passwd/user-password password $( $global:data.password ) 51 | d-i passwd/user-password-again password $( $global:data.password ) 52 | d-i user-setup/allow-password-weak boolean true 53 | d-i netcfg/get_hostname string $( $global:data.hostname ) 54 | 55 | # Packages 56 | 57 | #TODO: fast/slow modes - for extra packages 58 | #d-i base-installer/install-recommends boolean false 59 | d-i apt-setup/non-free boolean true 60 | d-i apt-setup/contrib boolean true 61 | d-i apt-setup/extras boolean true 62 | 63 | # Reboot 64 | 65 | #TODO: debug mode - don't reboot 66 | d-i finish-install/reboot_in_progress note 67 | d-i ubiquity/reboot boolean true 68 | 69 | -------------------------------------------------------------------------------- /files/tunic-logo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikeslattery/tunic/2e6b687b6d1a4dba8815d0749368a6d7f344eef0/files/tunic-logo.ico -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "net/http" 6 | "io" 7 | "os" 8 | "os/exec" 9 | ) 10 | 11 | /** 12 | * Tunic Linux Installer 13 | * 14 | * This is just something to get us started with very minimal MVP. 15 | * The MVP just downloads the old Tunic and runs it. 16 | */ 17 | func Download() error { 18 | resp, err := http.Get("https://github.com/mikeslattery/tunic/releases/download/0.2.4/tunic.exe") 19 | if err != nil { 20 | return err 21 | } 22 | defer resp.Body.Close() 23 | 24 | out, err := os.Create("tunic024.exe") 25 | if err != nil { 26 | return err 27 | } 28 | defer out.Close() 29 | 30 | _, err = io.Copy(out, resp.Body) 31 | return err 32 | } 33 | 34 | func Run() error { 35 | cmd := exec.Command("tunic024.exe") 36 | err := cmd.Run() 37 | return err 38 | } 39 | 40 | func main() { 41 | err := Download() 42 | if err != nil { 43 | err = Run() 44 | } 45 | if err != nil { 46 | log.Fatal(err) 47 | os.Exit(1) 48 | } 49 | } 50 | 51 | -------------------------------------------------------------------------------- /run.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import gi 4 | import sys 5 | import os 6 | import platform 7 | import pwd 8 | import psutil 9 | 10 | gi.require_version('Gtk', '3.0') 11 | from gi.repository import Gtk 12 | 13 | class MainWindow(Gtk.Window): 14 | 15 | class FieldBox(Gtk.Frame): 16 | def __init__(self, title): 17 | Gtk.Frame.__init__(self) 18 | self.set_label(title) 19 | 20 | self.grid = Gtk.Grid(row_spacing=5, column_spacing=5) 21 | self.row = 0 22 | 23 | self.add(self.grid) 24 | self.grid.set_border_width(15) 25 | 26 | def field(self, label_text, field): 27 | label = Gtk.Label(label=label_text) 28 | self.grid.attach(label, 0, self.row, 1, 1) 29 | self.grid.attach(field, 1, self.row, 1, 1) 30 | self.row = self.row + 1 31 | return field 32 | 33 | def entry(self, label_text): 34 | return self.field(label_text, Gtk.Entry()) 35 | 36 | class ButtonBox(Gtk.FlowBox): 37 | def __init__(self): 38 | Gtk.FlowBox.__init__(self) 39 | 40 | def field(self, field): 41 | self.add(field) 42 | return field 43 | 44 | def button(self, label_text): 45 | button = Gtk.Button.new_with_label(label_text) 46 | self.add(button) 47 | return button 48 | 49 | def __init__(self): 50 | Gtk.Window.__init__(self, title="Tunic Linux Installer") 51 | 52 | self.set_border_width(15) 53 | 54 | self.stack = Gtk.Stack() 55 | 56 | outer = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=2) 57 | 58 | column = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=2) 59 | 60 | typeFrame = Gtk.Frame(label='Installation Type') 61 | typeBox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=2) 62 | erase = Gtk.RadioButton(label='Install Linux alongside Windows') 63 | dual = Gtk.RadioButton.new_with_label_from_widget(erase, 'Erase entire disk and install Linux') 64 | custom = Gtk.RadioButton.new_with_label_from_widget(erase, 'Custom/Advanced') 65 | typeBox.add(erase) 66 | typeBox.add(dual) 67 | typeBox.add(custom) 68 | typeFrame.add(typeBox) 69 | column.add(typeFrame) 70 | 71 | box = self.FieldBox('') 72 | self.distro = box.field('Distro', Gtk.ComboBoxText()) 73 | self.distro.append('1', 'Ubuntu 20.04') 74 | self.distro.append('2', 'Linux Mint 19.3') 75 | self.distro.set_active(0) 76 | column.add(box) 77 | 78 | box = self.FieldBox('Identification') 79 | self.username = box.entry('Username') 80 | self.password = box.entry('Password') 81 | self.password.set_visibility(False) 82 | self.password2 = box.entry('Password, again') 83 | self.password2.set_visibility(False) 84 | self.full_name = box.entry('Full Name') 85 | self.hostname = box.entry('Computer Name') 86 | column.add(box) 87 | 88 | box = self.ButtonBox() 89 | box.field(Gtk.LinkButton(uri='https://www.gnu.org/licenses/gpl-3.0.en.html#section15', label='Read GNU GPL v3 license')) 90 | box.field(Gtk.CheckButton.new_with_label("I have read the GNU GPL v3 license\nand agree to its terms.")) 91 | column.add(box) 92 | 93 | self.fieldPage = column 94 | self.stack.add(column) 95 | 96 | column = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=2) 97 | 98 | box = self.FieldBox('C: Drive') 99 | box.field('Total Size', Gtk.Label(label='40GB')) 100 | box.field('Used by Windows', Gtk.Label(label='16GB')) 101 | box.field('Free', Gtk.Label(label='24GB')) 102 | box.field('Available', Gtk.Label(label='24GB')) 103 | box.field('Linux Size', Gtk.Entry()) 104 | column.add(box) 105 | 106 | box = self.ButtonBox() 107 | box.button('Clean') 108 | box.button('Disk Use') 109 | box.button('Partitions') 110 | box.button('Disable Swap') 111 | box.button('Defrag') 112 | column.add(box) 113 | 114 | self.diskPage = column 115 | self.stack.add(column) 116 | 117 | column = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=2) 118 | 119 | box = self.FieldBox('Progress') 120 | box.field('Repartion', Gtk.ProgressBar(fraction = 1.0)) 121 | box.field('Download', Gtk.ProgressBar(fraction = 0.4)) 122 | box.field('Install Grub', Gtk.ProgressBar(fraction = 0.0)) 123 | column.add(box) 124 | 125 | self.progressPage = column 126 | self.stack.add(column) 127 | 128 | outer.add(self.stack) 129 | 130 | box = self.ButtonBox() 131 | quit = box.button('Quit') 132 | self.cont = box.button('Continue') 133 | outer.add(box) 134 | 135 | self.add(outer) 136 | 137 | #TODO: move to presenter 138 | self.connect("destroy", self.on_quit) 139 | quit.connect('clicked', self.on_quit) 140 | 141 | def set_presenter(self, presenter): 142 | self.presenter = presenter 143 | 144 | def init(self): 145 | self.cont.connect('clicked', self.on_continue_click) 146 | self.show_all() 147 | 148 | def close(self): 149 | Gtk.main_quit(self, self) 150 | 151 | def warn(self, message): 152 | dialog = Gtk.MessageDialog( 153 | parent = self, 154 | flags = 0, 155 | message_type = Gtk.MessageType.WARNING, 156 | buttons = Gtk.ButtonsType.OK, 157 | text = message) 158 | dialog.run() 159 | dialog.destroy() 160 | 161 | def error(self, message): 162 | dialog = Gtk.MessageDialog( 163 | parent = self, 164 | flags = 0, 165 | message_type = Gtk.MessageType.ERROR, 166 | buttons = Gtk.ButtonsType.OK, 167 | text = message) 168 | dialog.run() 169 | dialog.destroy() 170 | 171 | def on_quit(self, widget): 172 | presenter.on_quit() 173 | 174 | def on_continue_click(self, widget): 175 | if self.stack.get_visible_child() == self.fieldPage: 176 | self.stack.set_visible_child(self.diskPage) 177 | else: 178 | self.stack.set_visible_child(self.progressPage) 179 | self.cont.set_visible(False) 180 | 181 | def set_system_info(self, system_info): 182 | self.username.set_text(system_info['username']) 183 | self.hostname.set_text(system_info['hostname']) 184 | self.full_name.set_text(system_info['full_name']) 185 | 186 | # OS specific functionality 187 | class LinuxSystem: 188 | 189 | # Must be checked before get_system_info 190 | def is_admin(self): 191 | return os.geteuid() == 0 192 | 193 | def get_system_info(self): 194 | uid = int(os.getenv('SUDO_UID')) 195 | return { 196 | 'username': pwd.getpwuid( uid ).pw_name, 197 | 'full_name': pwd.getpwuid( uid ).pw_gecos.split(',')[0], 198 | 'hostname': platform.node(), 199 | 'memory': psutil.virtual_memory().total, 200 | 'on_battery': not psutil.sensors_battery().power_plugged, 201 | 'architecture': platform.machine(), 202 | # These are the only os-specific iems 203 | 'timezone': '/'.join(os.path.realpath('/etc/localtime').split('/')[-2:]), 204 | 'is_efi': os.path.isdir('/sys/firmware/efi'), 205 | } 206 | 207 | # Separate from system_info as it can change. 208 | def get_disk_info(self): 209 | usage = psutil.disk_usage('/') 210 | return { 211 | 'size': usage.total, 212 | 'used': usage.used, 213 | 'free': usage.free, 214 | 'available': usage.free, 215 | } 216 | 217 | # Checks for conditions specific to current OS. 218 | # Throws exception if Tunic not compatible. 219 | def special_checks(self): 220 | # updates, update pending boot 221 | print('Not implemented') 222 | 223 | def reboot(self): 224 | os.system('shutdown -r now') 225 | 226 | def grub_install(self, efi_directory): 227 | os.system("grub-install --boot-directory /boot --efi-directory /boot/{}".efi_directory) 228 | 229 | def resize_partition(self, size): 230 | print('Not implemented') 231 | 232 | # Buttons available to reduce disk usage 233 | # for use from dual boot disk page. 234 | # Can be dynamic as buttons are refreshed after use. 235 | # Example: Disable/Enable Swap. 236 | # Returns an array. Even items are names, odd are functions 237 | def get_disk_utilities(self): 238 | return () 239 | 240 | # View logic. 241 | # No app logic should go here. 242 | class Presenter: 243 | def __init__(self, view, system): 244 | self.view = view 245 | self.system = system 246 | 247 | # Load system values 248 | def init(self): 249 | view.set_presenter(self) 250 | view.set_sensitive(False) 251 | try: 252 | view.init() 253 | if not self.system.is_admin(): 254 | self.die('Must be run as administator') 255 | system_info = self.system.get_system_info() 256 | view.set_system_info(system_info) 257 | self.checks(system_info) 258 | finally: 259 | view.set_sensitive(True) 260 | 261 | def die(self, message): 262 | view.error(message) 263 | sys.exit(1) 264 | 265 | def checks(self, system_info): 266 | if system_info['on_battery']: 267 | view.warn('It is not safe to run on battery') 268 | 269 | def on_quit(self): 270 | view.close() 271 | 272 | if len(sys.argv) == 1: 273 | view = MainWindow() 274 | presenter = Presenter(view, LinuxSystem()) 275 | view.set_presenter(presenter) 276 | presenter.init() 277 | Gtk.main() 278 | else: 279 | if sys.argv[1] == 'noop': 280 | print('noop') 281 | 282 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from setuptools import setup 4 | 5 | #from halo.settings import DEBUG, VERSION 6 | 7 | if DEBUG: 8 | print("You cannot build or install in debug mode.") 9 | exit(1) 10 | 11 | 12 | def get_long_description(): 13 | description = [] 14 | with open('README.md') as f: 15 | description.append(f.read()) 16 | 17 | 18 | setup(name='tunic', 19 | version=VERSION, 20 | description='Install Linux from Windows', 21 | long_description=get_long_description(), 22 | author='Mike Slattery', 23 | license='GNU GPL v3', 24 | packages=[], 25 | url='https://github.com/mikeslattery/tunic', 26 | entry_points={ 27 | "gui_scripts": [ 28 | "halo-weather = halo.__main__:main", 29 | ] 30 | }, 31 | install_requires=[ 32 | "requests", 33 | ], 34 | data_files=[ 35 | # (os.getenv('HOME') + '/.local/share/applications', ['halo.desktop']), 36 | # (os.getenv('HOME') + '/.local/share/icons', ['halo/assets/halo.svg']), 37 | ], 38 | package_data={ 39 | # '': ['*.css', 'assets/*.*', 'assets/icon/*'] 40 | }, 41 | zip_safe=False) 42 | 43 | -------------------------------------------------------------------------------- /test.mk: -------------------------------------------------------------------------------- 1 | download-vm10: 2 | # Found at https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/ 3 | #TODO: https://app.vagrantup.com/Microsoft/boxes/EdgeOnWindows10 4 | curl -L 'https://az792536.vo.msecnd.net/vms/VMBuild_20190311/VirtualBox/MSEdge/MSEdge.Win10.VirtualBox.zip' 5 | unzip MSEdge.Win10.VirtualBox.zip 6 | rm MSEdge.Win10.VirtualBox.zip 7 | #TODO: create 'MSEdge - Win10.ova' 8 | 9 | utest: main.go 10 | go test 11 | 12 | loop: 13 | # TODO: recusrive on all source input: .go, resources, images, etc 14 | while :; do inotifywait -qq -r -e create,close_write,modify,move,delete ./ && go test ./...; done 15 | 16 | -------------------------------------------------------------------------------- /test/allow.ps1: -------------------------------------------------------------------------------- 1 | # Usage: . test\allow.ps1 2 | Set-ExecutionPolicy Bypass -Scope Process -Force 3 | -------------------------------------------------------------------------------- /test/test-loop.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Tunic Linux Installer for Windows 3 | # Copyright (c) Michael Slattery under GPLv3 with NO warranty. 4 | # For more info see https://www.gnu.org/licenses/gpl-3.0.html#section15 5 | 6 | usage() { cat >&2 < [] 8 | 9 | ${docs} 10 | USAGE 11 | } 12 | docs=""; use() { docs="${docs}${1}"$'\n'; } 13 | 14 | set -euo pipefail 15 | 16 | vm_url='https://az792536.vo.msecnd.net/vms/VMBuild_20190311/VirtualBox/MSEdge/MSEdge.Win10.VirtualBox.zip' 17 | VMBASE="MSEdge - Win10" 18 | VMPARENT="tunic-parent-test" 19 | VM="tunic-test" 20 | SNAPSHOT="init" 21 | SSHPORT=5222 22 | #TODO: remove: SIZE=51200 23 | user=IEUser 24 | password='Passw0rd!' 25 | 26 | # Echo commands as they run 27 | se() {( 28 | set -x 29 | "$@" 30 | )} 31 | 32 | vboxmanage() {( 33 | set -x 34 | VBoxManage -q "$@" 35 | )} 36 | 37 | _vmexists() { 38 | vm="${1:-${VM}}" 39 | VBoxManage -q list vms | grep -sq "\"${vm}\"" 40 | } 41 | _vmrunning() { 42 | vm="${1:-${VM}}" 43 | VBoxManage -q list runningvms | grep -sq "\"${vm}\"" 44 | } 45 | 46 | use 'install-tools Install packages required for testing on Ubuntu' 47 | install-tools() { 48 | sudo apt install -y virtualbox openssh-client 49 | } 50 | 51 | use 'build-vm Create a Windows VM image' 52 | build-vm() { 53 | echo "This builds 2 VMs:" 54 | echo " $VMBASE : The stock one from Microsoft" 55 | echo " $VMPARENT : THe parent VM of testing" 56 | echo "Both will have a snapshoed called $SNAPSHOT" 57 | echo "When tests are run, a VM named $VM will be created" 58 | echo "" 59 | echo 'Building VM...' 60 | 61 | if ! _vmexists "$VMBASE"; then 62 | echo 'Downloading and extracting VM...' 63 | if [[ ! -f "${VMBASE}.ova" ]]; then 64 | se curl -f -o msvbox.tmp.zip -L "$vm_url" 65 | mv msvbox.zip.tmp msvbox.zip 66 | se unzip msvbox.zip 67 | rm msvbox.zip 68 | fi 69 | 70 | # create new VirtualBox VM 71 | vboxmanage import "${VMBASE}.ova" 72 | #TODO: rm "${VMBASE}.ova" 73 | fi 74 | 75 | # Delete if exists 76 | if _vmexists "$VMPARENT"; then 77 | vboxmanage unregistervm "$VMPARENT" --delete 78 | vboxmanage snapshot "$VMBASE" delete "$SNAPSHOT" 79 | fi 80 | 81 | # Create $VMPARENT template clone 82 | vboxmanage snapshot "$VMBASE" take "$SNAPSHOT" 83 | vboxmanage clonevm "$VMBASE" --name "$VMPARENT" --snapshot "$SNAPSHOT" \ 84 | --options link --register 85 | vboxmanage modifyvm "$VMPARENT" \ 86 | --memory 4096 --cpus 2 \ 87 | --clipboard bidirectional 88 | vboxmanage modifyvm "$VMPARENT" --natpf1 "guestssh,tcp,,${SSHPORT},,22" 89 | vboxmanage sharedfolder add "$VMPARENT" --name linux \ 90 | -hostpath "$HOME" -automount 91 | 92 | # Change size 93 | #TODO: remove: storage="$(vboxmanage showvminfo "$VMPARENT" --machinereadable | grep 'IDE Controller-0-0' | cut -d= -f2 | sed 's/"//g')" 94 | #TODO: remove: vboxmanage modifymedium disk "$storage" --resize "$SIZE" 95 | 96 | # Run test-setup 97 | vboxmanage startvm "$VMPARENT" --type gui 98 | se sleep 10 99 | while ! VBoxManage guestcontrol "$VMPARENT" run \ 100 | --username "$user" --password "$password" \ 101 | 'C:\Windows\System32\cmd.exe' /c -- rem &>/dev/null; do 102 | se sleep 5 103 | done 104 | vboxmanage guestcontrol "$VMPARENT" copyto \ 105 | --username "$user" --password "$password" \ 106 | --target-directory "C:\Users\$user\Desktop" \ 107 | test-setup.ps1 108 | vboxmanage guestcontrol "$VMPARENT" copyto \ 109 | --username "$user" --password "$password" \ 110 | --target-directory "C:\Users\$user\Desktop" \ 111 | test-setup.bat 112 | #TODO: run test-setup.ps1 as admin shortcut on desktop 113 | 114 | echo 'VM created. Now do these steps:' 115 | echo ' From the desktop run as administrator test-setup.ps1' 116 | echo -n ' Hit enter to continue: ' 117 | read -r 118 | 119 | vboxmanage modifyvm "$VMPARENT" --firmware efi 120 | } 121 | 122 | use "create-vm Creates the test VM '$VM'" 123 | use " from VM '$VMPARENT' snapshot '$SNAPSHOT'" 124 | create-vm() { 125 | if ! _vmexists; then 126 | vboxmanage snapshot "$VMPARENT" take "$SNAPSHOT" 127 | vboxmanage clonevm "$VMPARENT" --name "$VM" --snapshot "$SNAPSHOT" --options link --register 128 | fi 129 | } 130 | 131 | use "delete-vm Deletes VM" 132 | delete-vm() { 133 | if _vmexists; then 134 | vboxmanage unregistervm "$VM" --delete 135 | vboxmanage snapshot "$VMPARENT" delete "$SNAPSHOT" 136 | while _vmexists; do sleep 2; done 137 | fi 138 | } 139 | 140 | use "start-vm Starts the test VM" 141 | start-vm() { 142 | if ! _vmrunning; then 143 | vboxmanage startvm "$VM" --type gui 144 | while ! nc -z localhost "$SSHPORT"; do sleep 2; done 145 | sleep 30 146 | fi 147 | echo 'Started VM.' 148 | } 149 | 150 | use "stop-vm Stop running VM" 151 | stop-vm() { 152 | if _vmrunning; then 153 | vboxmanage controlvm "$VM" poweroff 154 | while _vmrunning; do sleep 2; done 155 | sleep 2 156 | fi 157 | } 158 | 159 | use "shell Run a shell command in the VM" 160 | shell() { 161 | sshpass -p "$password" ssh "$user"@localhost -p "$SSHPORT" "$@" 162 | } 163 | 164 | use "power-up Recycle VM and start shell" 165 | power-up() { 166 | power-down 167 | create-vm 168 | start-vm 169 | shell "$@" 170 | } 171 | 172 | full-disk() { 173 | power-up 'z:src\tunic\tunic.ps1 full-disk' 174 | } 175 | 176 | use "power-down Stop and delete VM" 177 | power-down() { 178 | stop-vm 179 | delete-vm 180 | } 181 | 182 | mirror() { 183 | docker run --name nginx \ 184 | -d \ 185 | -p 80:80 \ 186 | -v "$HOME/Downloads:/usr/share/nginx/html/linuxmint/stable/19.3" \ 187 | nginx:alpine 188 | } 189 | 190 | use "install-iso A complete test" 191 | install-iso() { 192 | #shell 'Z: && cd src/tunic && powershell -executionpolicy bypass -command .\tunic.ps1' 193 | power-up 'Z: && cd src/tunic && powershell -executionpolicy bypass -command .\tunic.ps1 install' 194 | } 195 | 196 | main() { 197 | [[ "$#" -gt 0 ]] || usage 198 | "$@" || usage 199 | } 200 | 201 | main "$@" 202 | 203 | -------------------------------------------------------------------------------- /test/test-setup.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | cd "%~dp0" 4 | 5 | powershell -executionpolicy bypass -nologo -noninteractive -file test-setup.ps1 -args %* 6 | -------------------------------------------------------------------------------- /test/test-setup.ps1: -------------------------------------------------------------------------------- 1 | # Tunic Linux Installer for Windows 2 | # Copyright (c) Michael Slattery under GPLv3 with NO warranty. 3 | # For more info see https://www.gnu.org/licenses/gpl-3.0.html#section15 4 | 5 | # Configure VM for testing purposes 6 | 7 | # Parts were copied from ./tunic.ps1 8 | 9 | 10 | If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) 11 | { 12 | Write-Host 'Escalating' 13 | # Relaunch as an elevated process: 14 | Start-Process powershell.exe "-File",('"{0}"' -f $MyInvocation.MyCommand.Path) -Verb RunAs 15 | exit 16 | } 17 | 18 | Write-host "Started." 19 | $iso_url='http://mirrors.gigenet.com/linuxmint/iso/stable/19.3/linuxmint-19.3-cinnamon-64bit.iso' 20 | 21 | $letter = $env:HOMEDRIVE[0] 22 | $tunic_dir="${env:ALLUSERSPROFILE}\tunic" 23 | $iso = "${tunic_dir}\linux.iso" 24 | # This is for testing only, so s'ok 25 | $user = 'IEUser' 26 | $password='Passw0rd!' 27 | 28 | # Disable Auto Updates 29 | 30 | $WindowsUpdatePath = "HKLM:SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" 31 | $AutoUpdatePath = "HKLM:SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" 32 | 33 | Remove-Item -Path $WindowsUpdatePath -Recurse -errorAction ignore 34 | 35 | New-Item -Path $WindowsUpdatePath 36 | New-Item -Path $AutoUpdatePath 37 | 38 | Set-ItemProperty -Path $AutoUpdatePath -Name NoAutoUpdate -Value 1 39 | 40 | # Disable Defender 41 | 42 | New-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows Defender" -Name DisableAntiSpyware -Value 1 -PropertyType DWORD -Force 43 | New-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows Defender\Spynet" -Name SpyNetReporting -Value 0 -Force 44 | New-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows Defender\Spynet" -Name SubmitSamplesConsent -Value 2 -Force 45 | 46 | # Disable Telemetry 47 | 48 | Set-Service -Name DiagTrack -StartupType Disabled 49 | Set-Service -Name dmwappushservice -StartupType Disabled 50 | New-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows\OneDrive" -Name DisableFileSyncNGSC -Value 1 -Force 51 | Get-ScheduledTask -TaskPath "\Microsoft\Windows\Customer Experience Improvement Program\" | Disable-ScheduledTask 52 | New-Item "%ProgramData%\Microsoft\Diagnosis\ETLLogs\AutoLogger\AutoLogger-Diagtrack-Listener.etl" -ItemType File -Force 53 | New-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows\OneDrive" -Name DisableFileSyncNGSC -Value 1 -Force 54 | New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\AdvertisingInfo" -Name Enabled -Value 0 -Force 55 | New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\AppHost\EnableWebContentEvaluation" -Name Enabled -Value 0 -Force 56 | New-ItemProperty -Path "HKCU:\Control Panel\International\User Profile" -Name HttpAcceptLanguageOptOut -Value 1 -Force 57 | New-ItemProperty -Path "HKCU:\Software\Microsoft\Siuf\Rules" -Name PeriodInNanoSeconds -Value 0 -Force 58 | New-ItemProperty -Path "HKCU:\Software\Microsoft\Siuf\Rules" -Name NumberOfSIUFInPeriod -Value 0 -Force 59 | New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\WcmSvc\wifinetworkmanager\config" -Name AutoConnectAllowedOEM -Value 0 -Force 60 | New-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\MRT" -Name DontReportInfectionInformation -Value 1 -Force 61 | New-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\DataCollection" -Name AllowTelemetry -Value 0 -Force 62 | 63 | # Disable Cortana 64 | 65 | $path = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Windows Search" 66 | IF(!(Test-Path -Path $path)) { 67 | New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows" -Name "Windows Search" 68 | } 69 | Set-ItemProperty -Path $path -Name "AllowCortana" -Value 1 70 | New-NetFirewallRule -DisplayName "Block Cortana Web Access" -Direction Outbound -Program "%windir%\systemapps\Microsoft.Windows.Cortana_cw5n1h2txyewy\SearchUI.exe" -Action Block 71 | 72 | # Auto Login 73 | 74 | $loginPath = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' 75 | #TODO: next line said alread exists 76 | New-ItemProperty -Path "$loginPath" -Name AutoAdminLogon -Value 1 -force 77 | New-ItemProperty -Path "$loginPath" -Name DefaultUserName -Value "$user" -force 78 | New-ItemProperty -Path "$loginPath" -Name DefaultPassword -Value "$password" -force 79 | 80 | # DNS 81 | 82 | #TODO: $gateway = (Get-NetIPConfiguration).ipv4defaultgateway.nexthop 83 | #TODO: add-content 'C:\Windows\System32\drivers\etc\hosts' "$gateway mirrors.gigenet.com" 84 | 85 | # Desktop Icons 86 | 87 | copy "C:\Users\$user\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows PowerShell\Windows PowerShell.lnk" ~/Desktop/. 88 | 89 | # Stay Awake 90 | 91 | $personalPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\Personalization" 92 | New-Item -Path "$personalPath" -errorAction ignore 93 | New-ItemProperty -Path "$personalPath" -Name NoLockScreen -Value 1 -force 94 | 95 | powercfg /change monitor-timeout-ac 0 96 | powercfg /change disk-timeout-ac 0 97 | powercfg /change standby-timeout-ac 0 98 | powercfg /change hibernate-timeout-ac 0 99 | 100 | # SSH 101 | 102 | Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0 103 | Start-Service sshd 104 | Set-Service -Name sshd -StartupType 'Automatic' 105 | #TODO: Get-NetFirewallRule -Name *ssh* 106 | New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force 107 | New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShellCommandOption -Value "/c" -PropertyType String -Force 108 | New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 -errorAction ignore 109 | 110 | # Chocolatey installs 111 | 112 | install-packageprovider -name NuGet -force 113 | $web = (New-Object System.Net.WebClient) 114 | iex $web.DownloadString('https://chocolatey.org/install.ps1') 115 | 116 | choco install -y 7zip defraggler nsis 117 | 118 | # Convert to EFI 119 | 120 | mbr2gpt /validate /allowfullos 121 | mbr2gpt /convert /allowfullos 122 | 123 | Write-Host 'Done.' 124 | 125 | Stop-Computer -force 126 | -------------------------------------------------------------------------------- /test/tunic.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | cd "%~dp0\.." 3 | 4 | rem For testing purposes 5 | 6 | powershell -executionpolicy bypass -nologo -noninteractive -file tunic.ps1 %* 7 | -------------------------------------------------------------------------------- /tunic.nsi: -------------------------------------------------------------------------------- 1 | Name "Tunic Linux Installer" 2 | OutFile "tunic.exe" 3 | ShowInstDetails hide 4 | SilentInstall silent 5 | Unicode true 6 | Icon "files\tunic-logo.ico" 7 | 8 | !include x64.nsh 9 | 10 | Section "Tunic Linux Installer" 11 | SetOutPath "$TEMP\Tunic" 12 | file tunic.ps1 13 | file /r files 14 | ${If} ${RunningX64} 15 | ExecWait '$WINDIR\sysnative\windowspowershell\v1.0\powershell.exe -executionpolicy bypass -nologo -inputformat none -noninteractive -WindowStyle Hidden -file tunic.ps1' 16 | ${Else} 17 | ExecWait 'powershell.exe -executionpolicy bypass -nologo -inputformat none -noninteractive -WindowStyle Hidden -file tunic.ps1' 18 | ${EndIf} 19 | SectionEnd 20 | 21 | -------------------------------------------------------------------------------- /tunic.ps1: -------------------------------------------------------------------------------- 1 | # Tunic Linux Installer for Windows 2 | # Copyright (c) Michael Slattery under GPLv3 with NO warranty. 3 | # For more info see https://www.gnu.org/licenses/gpl-3.0.html#section15 4 | 5 | # Automated install of an iso_path 6 | 7 | if( $args[0] -eq 'noop') { exit } # for syntax checking 8 | 9 | $global:ProgressPreference = 'SilentlyContinue' 10 | 11 | $global:shim_url = 'https://github.com/pop-os/iso/blob/master/data/efi/shimx64.efi.signed?raw=true' 12 | 13 | $global:letter = $env:HOMEDRIVE[0] 14 | $global:root_dir="${letter}:" 15 | $global:tunic_dir="${env:ALLUSERSPROFILE}\tunic" 16 | 17 | $global:MIN_DISK_GB = 15 18 | 19 | $DUALBOOT = 1 20 | $FULLBOOT = 2 21 | $CUSTOMBOOT = 3 22 | 23 | $web = (New-Object System.Net.WebClient) 24 | 25 | # Do very basic initialization 26 | 27 | function initData() { 28 | if( $PSScriptRoot ) { 29 | set-location -path $PSScriptRoot 30 | } 31 | 32 | if ( -not (Test-Path "$global:tunic_dir") ) { 33 | mkdir "$global:tunic_dir" | out-null 34 | } 35 | 36 | # Load distros from config file 37 | $global:distros = . files/distros.ps1 38 | 39 | # Load distro information from Downloads directory 40 | $mounts = ( dir "${HOME}\Downloads\*.iso" | mount-diskImage ) 41 | try { 42 | if( $mounts ) { 43 | $global:distros += ( $mounts | % { @{ name=($_ | get-volume).fileSystemLabel; url=$_.imagePath; } } ) 44 | } 45 | } 46 | catch { 47 | write-host $_ 48 | } 49 | finally { 50 | $mounts | dismount-diskimage | out-null 51 | } 52 | 53 | # User account 54 | $userInfo = ( Get-WMIObject Win32_UserAccount | where caption -eq (whoami) ) 55 | $global:data = @{ 56 | installType = $DUALBOOT; 57 | fullname = $userInfo.fullName; 58 | username = $userInfo.name.toLower(); 59 | hostname = $userInfo.psComputerName; 60 | iso_url = $global:distros[0].url 61 | } 62 | } 63 | 64 | # Get the name part of an URL 65 | function getUrlFile($url) { 66 | return $url -replace '^.*/', '' -replace '[?#].*$', '' 67 | } 68 | 69 | # Get the path on the disk to the file 70 | function getUrlFilepath($url) { 71 | $file = getUrlFile($url) 72 | 73 | $dir = "${HOME}\Downloads" 74 | if ( -not (Test-Path "$dir") ) { 75 | mkdir "$dir" 76 | } 77 | 78 | return "${dir}\${file}" 79 | } 80 | 81 | # Convert C: file path to grub path. 82 | function getGrubPath($filename) { 83 | $filename -replace '^.*:', '' -replace '\\', '/' 84 | } 85 | 86 | # Disable swap, hibernate, restore, error reports, dumps 87 | function disableSwap() { 88 | Write-Host "Disabling swap..." 89 | 90 | # Turn off hibernation and fast start 91 | powercfg.exe /h off 92 | REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power" /V HiberbootEnabled /T REG_DWORD /D 0 /F 93 | 94 | # Disable swap 95 | $computersys = Get-WmiObject Win32_ComputerSystem -EnableAllPrivileges 96 | $computersys.AutomaticManagedPagefile = $False 97 | $computersys.Put() 98 | 99 | $pagefile = Get-WmiObject win32_pagefilesetting 100 | $pagefile.delete() 101 | 102 | Disable-WindowsErrorReporting 103 | Disable-ComputerRestore -Drive "${global:root_dir}" 104 | 105 | Write-Host "Swap disabled." 106 | } 107 | 108 | function enableSwap() { 109 | Write-Host "Re-enabling Swap" 110 | 111 | Enable-ComputerRestore -Drive C: 112 | Enable-WindowsErrorReporting 113 | 114 | # Enable Swap 115 | wmic pagefileset create name="${global:letter}:\\pagefile.sys" 116 | wmic pagefileset where name="${global:letter}:\\pagefile.sys" set InitialSize=2048,MaximumSize=2048 117 | wmic computersystem set AutomaticManagedPagefile=True 118 | 119 | # Enable Hibernate (but not fast start) 120 | # TODO: see if hibernate is support and/or if it was on before. 121 | powercfg.exe /h on 122 | } 123 | 124 | function clean() { 125 | $regkey = 'registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches' 126 | Get-childItem -path $regkey | new-itemproperty -name 'StateFlags0112' -propertytype DWORD -value 2 -force 127 | start-process cleanmgr /sagerun:112 -wait 128 | } 129 | 130 | function defrag() { 131 | powercfg.exe /h off 132 | REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Power" /V HiberbootEnabled /T REG_DWORD /D 0 /F 133 | Optimize-Volume -DriveLetter $global:letter -Defrag 134 | #TODO: powercfg.exe /h on - if was on before 135 | } 136 | 137 | function ternary($expr, $ontrue, $onfalse) { 138 | if($expr) { return $ontrue } else { return $onfalse } 139 | } 140 | 141 | function die($msg) { 142 | write-host $msg 143 | [System.Windows.Forms.Messagebox]::Show($msg) 144 | $global:form.close() 145 | } 146 | 147 | function say($msg) { 148 | write-host $msg 149 | [System.Windows.Forms.Messagebox]::Show($msg) 150 | } 151 | 152 | function yes($q) { 153 | $buttons = [System.Windows.Forms.MessageBoxButtons]::YesNo 154 | return [System.Windows.Forms.MessageBox]::Show($q,"Tunic", $buttons ) -eq "Yes" 155 | } 156 | 157 | function openUrl($url) { 158 | [System.Diagnostics.Process]::Start($url) 159 | } 160 | 161 | # Returns true if Linux can be installed. 162 | function checks() { 163 | if( !( [Security.Principal.WindowsPrincipal] ` 164 | [Security.Principal.WindowsIdentity]::GetCurrent() ` 165 | ).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) ) { 166 | die( 'Must be an Administrator to run tunic' ) 167 | return 168 | } 169 | 170 | if( ! [System.Environment]::Is64BitOperatingSystem ) { 171 | die( 'Only 64 bit systems supported' ) 172 | return 173 | } 174 | 175 | if( (get-wmiobject -class "Win32_ComputerSystem").totalPhysicalMemory -lt 3.5GB ) { 176 | die('4GB or more RAM required.') 177 | return 178 | } 179 | 180 | if( [intPtr]::size -eq 4 ) { 181 | die( 'Tunic cannot be run from 32 bit Powershell' ) 182 | return 183 | } 184 | 185 | $osversion = [System.Environment]::OSVersion.version 186 | if( $osversion.major -lt 10 ) { 187 | # Windows 7=6.1, 8=6.2, 8.1=6.3 Windows 10=10 188 | die( 'Only Windows 10 supported' ) 189 | return 190 | } 191 | 192 | if( [System.Environment]::Version.major -lt 3 ) { 193 | die( 'Powershell 3 or above required' ) 194 | return 195 | } 196 | 197 | if( (Get-WmiObject Win32_Battery).batteryStatus -eq 1 ) { 198 | say( 'It is too risky to use Tunic while on battery.' ) 199 | } 200 | 201 | #TODO: find lighter way to check for updates 202 | install-packageprovider -name NuGet -force 203 | install-script -name Test-PendingReboot -force 204 | if( (Test-PendingReboot.ps1 -computername localhost).isPendingReboot ) { 205 | if( yes('A Windows Update reboot is pending. You need to reboot and rerun Tunic. Reboot now?') ) { 206 | restart-computer 207 | } 208 | } 209 | 210 | if( (New-Object -ComObject 'Microsoft.Update.Installer').isBusy ) { 211 | say('A Windows Update is in progress. You should quit and try again later.') 212 | } 213 | 214 | $blInfo = (Get-BitLockerVolume -MountPoint "${global:letter}" -erroraction silentlyContinue) 215 | if( $blInfo -and $blInfo.ProtectionStatus -eq 'On' ) { 216 | $recoveryKey = $blInfo.KeyProtector 217 | say( "Bitlocker may have issues with dual boot. Write down your recovery key: $recoveryKey" ) 218 | } 219 | 220 | $partc = ( get-partition -driveLetter $global:letter ) 221 | if( (get-disk -number $partc.diskNumber).partitionStyle -eq 'MBR' ) { 222 | mbr2gpt /validate /allowfullos > $null 2> $null 223 | if( $? ) { 224 | if( yes('UEFI required, but system is MBR. Read web page on how to convert?') ) { 225 | openurl('https://www.isumsoft.com/computer/how-to-convert-mbr-to-gpt-partition-no-data-loss.html') 226 | } 227 | $global:form.close() 228 | } else { 229 | die('UEFI required, but is not supported by this system.') 230 | } 231 | return 232 | } 233 | } 234 | 235 | function downloadIso() { 236 | #TODO: remove. guiDownloadIso w/callback 237 | $iso_path = getUrlFilepath($global:data.iso_url) 238 | $iso_file = getUrlFile($global:data.iso_url) 239 | if ( -not (Test-Path "$iso_path") ) { 240 | $ciso = "Z:\Downloads\$iso_file" 241 | if ( Test-Path "$ciso" ) { 242 | write-host 'Cached.' 243 | copy "$ciso" "$iso_path" 244 | } else { 245 | try { 246 | $web.DownloadFile($global:data.iso_url, "$iso_path") 247 | } catch { 248 | write-host "Error downloading $( $global:data.iso_url ) to $iso_path" 249 | write-host $_ 250 | Remove-Item "$iso_path" 251 | Throw "Download failed" 252 | } 253 | } 254 | } 255 | } 256 | 257 | function guiDownloadIso() { 258 | #TODO: save to temp and move after. 259 | #TODO: verify integrity 260 | $iso_path = getUrlFilepath($global:data.iso_url) 261 | $iso_file = getUrlFile($global:data.iso_url) 262 | if ( -not (Test-Path "$iso_path") ) { 263 | $ciso = "Z:\Downloads\$iso_file" 264 | if ( Test-Path "$ciso" ) { 265 | copy "$ciso" "$iso_path" 266 | } else { 267 | Import-Module BitsTransfer 268 | $url = $global:data.iso_url 269 | 270 | $bits = ( Start-BitsTransfer -DisplayName $url -Source $url -Destination $iso_path -Asynchronous ) 271 | try { 272 | #TODO: use a callback instead of direct updates. 273 | $global:dlStatus.text = 'Connecting...' 274 | While ($Bits.JobState -eq "Connecting") { 275 | sleep 1 276 | [System.Windows.Forms.Application]::DoEvents() 277 | } 278 | $global:dlStatus.text = 'Transferring...' 279 | While ($Bits.JobState -eq "Transferring" -and $Bits.BytesTransferred -lt ( 1GB / 100 ) ) { 280 | sleep 1 281 | [System.Windows.Forms.Application]::DoEvents() 282 | } 283 | While ($Bits.JobState -eq "Transferring") { 284 | if ($Bits.JobState -eq "Error"){ 285 | Resume-BitsTransfer -BitsJob $Bits 286 | } 287 | $state = $bits.jobState 288 | $pct = [int](($Bits.BytesTransferred*100) / $Bits.BytesTotal) 289 | $global:dlStatus.text = "$pct% complete" 290 | sleep 1 291 | [System.Windows.Forms.Application]::DoEvents() 292 | } 293 | #TODO: save to temp and move after. 294 | #TODO: verify integrity 295 | } catch { 296 | write-host "Error downloading $url to $iso_path" 297 | write-host $_ 298 | Remove-Item "$iso_path" 299 | Throw "Download failed" 300 | } 301 | finally { 302 | $Bits | Complete-BitsTransfer 303 | } 304 | } 305 | } 306 | } 307 | 308 | # Returns the Linux timezone converted from Windows. 309 | function getLinuxTimeZone() { 310 | # Download and load list of timezones 311 | 312 | $url = 'https://raw.githubusercontent.com/unicode-org/cldr/master/common/supplemental/windowsZones.xml' 313 | $file = "$env:TEMP\windowsZones.xml" 314 | if( ! (Test-Path $file -ErrorAction SilentlyContinue) ) { 315 | $web.DownloadFile($url, $file) 316 | } 317 | [xml]$xml = Get-Content $file 318 | $nodes = $xml.supplementalData.windowsZones.mapTimezones.childNodes 319 | 320 | # Get Windows timezone and country code. 321 | 322 | $wtz = (get-timezone) 323 | $tzName = $wtz.id 324 | $territory = (New-Object System.Globalization.RegionInfo (Get-Culture).Name).TwoLetterISORegionName 325 | 326 | $zones = ($nodes | where-object { $_.other -eq $tzName } ) 327 | if( $zones.count -eq 1 ) { 328 | $ltz = $zones[0].type 329 | } elseif( $zones.count -gt 1 ) { 330 | 331 | # Scan for exact Linux equivalent 332 | $ltz = ($zones | where-object { $_.territory -eq $territory } ).type 333 | if( ! $ltz ) { 334 | # Direct hit failed. Use the generic territory. This is most common case. 335 | $ltz = ($zones | where-object { $_.territory -eq '001' } ).type 336 | } 337 | 338 | # Sloppy match 339 | if( ! $ltz ) { 340 | $ltz = $zones[0].type 341 | } 342 | } 343 | else { 344 | # Match by GMT and hour difference. 345 | $offset = - $wtz.baseUtcOffset.totalHours 346 | if( $offset -eq [math]::floor($offset) -and ` 347 | -12 -le $offset -and $offset -le 12 -and ` 348 | $offset -ne 0 ) { 349 | 350 | if( $offset -gt 0 ) { 351 | $ltz = "Etc/GMT-${offset}" 352 | } else { 353 | $ltz = "Etc/GMT+${offset}" 354 | } 355 | } 356 | else { 357 | # We give up. This should never happen. 358 | $ltz = "UTC" 359 | } 360 | } 361 | 362 | return $ltz 363 | } 364 | 365 | function expandTemplate($filename) { 366 | $str = ( get-content -path "$filename" ) 367 | $str = $str.split("`n") -join "``n" 368 | return $ExecutionContext.InvokeCommand.ExpandString( $str ) 369 | } 370 | 371 | function installGrub() { 372 | # TODO: allocate drive letter. try..finally 373 | #$efi = (ls function:[d-z]: -n | ?{ !(test-path $_) } | random) 374 | $efi = "S:" 375 | if ( -not (Test-Path "$efi") ) { 376 | mountvol $efi /s 377 | } 378 | 379 | $secureBootEnabled = $false 380 | try { 381 | $secureBootEnabled = (confirm-secureBootUefi) 382 | } catch {} 383 | 384 | $grub_dir="\boot\grub" 385 | $grub_path="${efi}${grub_dir}" 386 | 387 | $iso_path = getUrlFilepath($global:data.iso_url) 388 | $iso_grub_path = getGrubPath($iso_path) 389 | 390 | # Download and install grub files 391 | $grub_version='grub-2.04-for-windows' 392 | $grub_dir="${global:tunic_dir}\${grub_version}" 393 | if ( -not (Test-Path $grub_dir) ) { 394 | $web.downloadFile("https://ftp.gnu.org/gnu/grub/${grub_version}.zip", "${grub_dir}.zip") 395 | expand-archive "${grub_dir}.zip" -destinationPath "${global:tunic_dir}" 396 | rm "${grub_dir}.zip" 397 | } 398 | & "${global:tunic_dir}\${grub_version}\grub-install.exe" --no-nvram --boot-directory=S:\boot --efi-directory=S:\ --target=x86_64-efi > $null 399 | 400 | # Secure Boot shim 401 | if( $secureBootEnabled ) { 402 | $web.DownloadFile($shim_url, "${efi}\EFI\grub\shimx64.efi") 403 | } 404 | 405 | # config 406 | move "$grub_path\grub.cfg" "$grub_path\grub.orig.cfg" -errorAction silentlyContinue 407 | copy "files\grub.cfg" "$grub_path\." 408 | set-content -path "$grub_path\grub.var.cfg" -value "set iso_path='$iso_grub_path'" 409 | 410 | if ( -not (Test-Path "${global:tunic_dir}\bcd-before.bak" ) ) { 411 | bcdedit /export "${global:tunic_dir}\bcd-before.bak" | out-null 412 | } 413 | 414 | # Boot Entry 415 | if( test-path("${global:tunic_dir}\bcd.id") ) { 416 | $osloader = (get-content "${global:tunic_dir}\bcd.id") 417 | bcdedit /delete "$osloader" /cleanup /f | out-null 418 | } 419 | $osloader = (bcdedit /copy '{bootmgr}' /d ubuntu).replace('The entry was successfully copied to ','').replace('.','') 420 | bcdedit /set "$osloader" device "partition=$efi" | out-null 421 | if( $secureBootEnabled ) { 422 | bcdedit /set "$osloader" path "\EFI\grub\shimx64.efi" | out-null 423 | } 424 | else { 425 | bcdedit /set "$osloader" path "\EFI\grub\grubx64.efi" | out-null 426 | } 427 | bcdedit /set "$osloader" description "Tunic Linux Installer" | out-null 428 | ('locale', 'inherit', 'default', 'resumeobject', 'displayorder', 'toolsdisplayorder', 'timeout') | % { 429 | bcdedit /deletevalue "$osloader" $_ | out-null 430 | } 431 | bcdedit /set '{fwbootmgr}' displayorder "$osloader" /addfirst | out-null 432 | set-content -path "${global:tunic_dir}\bcd.id" -value "$osloader" 433 | 434 | # Preseed 435 | set-content -value (expandTemplate "files\preseed.cfg") -path "${global:tunic_dir}\preseed.cfg" 436 | 437 | mountvol $efi /d 438 | 439 | bcdedit /export "${global:tunic_dir}\bcd-grub.bak" | out-null 440 | } 441 | 442 | # Calculates globals gap and maxAvailable 443 | function calcPartition() { 444 | $letter = $global:letter 445 | $global:partc = (get-partition -driveletter $letter) 446 | $disk = (get-disk -number $global:partc.diskNumber) 447 | 448 | # Calculate Gap 449 | $partnext = (get-partition -disknumber $global:partc.disknumber | where-object { $_.partitionNumber -eq ($global:partc.partitionNumber + 1)}) 450 | if( ! $partnext ) { 451 | #TODO: figure out why -1MB needed 452 | $global:gap = $disk.size - ( $global:partc.offset + $global:partc.size ) - 1MB 453 | } else { 454 | $global:gap = $partnext.offset - ( $global:partc.offset + $global:partc.size ) 455 | } 456 | 457 | # Calculate available 458 | $global:maxAvailable = $global:partc.size - (get-partitionsupportedsize -driveletter "$letter").sizeMin + $global:gap 459 | 460 | } 461 | 462 | function repartition() { 463 | $letter = $global:letter 464 | $global:partc = (get-partition -driveletter $letter) 465 | 466 | # size entered in GUI 467 | $linusSizeNum = $global:data.linuxSize * 1GB 468 | 469 | $shrinkBy = $linuxSizeNum - $global:gap 470 | 471 | $newSize = $global:partc.size - ( $shrinkBy ) 472 | 473 | if( $shrinkBy -gt 0 ) { 474 | resize-partition -driveletter $letter -size $newSize 475 | } 476 | } 477 | 478 | function calcGui() { 479 | $global:form.activate() 480 | [System.Windows.Forms.Application]::DoEvents() 481 | 482 | calcPartition 483 | 484 | $letter = $global:letter 485 | $volume = (Get-Volume -driveletter $letter) 486 | 487 | $total = [math]::round( $volume.size / 1GB ) 488 | $free = [math]::round( $volume.sizeremaining / 1GB ) 489 | $used = [math]::round( ( $volume.size - $volume.sizeRemaining ) / 1GB ) 490 | $avail = [math]::floor( $global:maxAvailable / 1GB ) 491 | 492 | $global:sizeGroup.text = "${letter}: Drive" 493 | 494 | $global:totalValue.text = "$total GB" 495 | $global:freeValue.text = "$free GB" 496 | $global:usedValue.text = "$used GB" 497 | $global:availValue.text = "$avail GB" 498 | 499 | if( ! $global:linuxSize.text ) { 500 | $global:linuxSize.text = "$(( [math]::max( $global:MIN_DISK_GB, [math]::min( [math]::floor($total / 2) , $avail ) ) ))" 501 | } 502 | } 503 | 504 | function treeMap() { 505 | $tree_dl='https://windirstat.mirror.wearetriple.com//wds_current_setup.exe' 506 | $tree_setup= "$($global:tunic_dir)\windirstat-setup.exe" 507 | $tree_exe= "C:\Program Files (x86)\WinDirStat\windirstat.exe" 508 | if ( -not (Test-Path "$tree_exe") ) { 509 | $web.DownloadFile($tree_dl, $tree_setup) 510 | start-process $tree_setup /S -wait 511 | } 512 | start-process "$tree_exe" -wait 513 | } 514 | 515 | function initFields() { 516 | checks 517 | initData 518 | 519 | $fullname.text = $global:data.fullname 520 | $username.text = $global:data.username 521 | $hostname.text = $global:data.hostname 522 | 523 | $distroName.items.addRange( ( $global:distros | % { $_.name } ) ) 524 | $distroName.selectedIndex = 0 525 | } 526 | 527 | function checkFields() { 528 | $global:outer.enabled = $false 529 | 530 | if( $password.text.length -eq 0 ) { 531 | [Void][System.Windows.Forms.Messagebox]::Show("Password required.") 532 | $global:outer.enabled = $true 533 | [Void]$global:password.focus() 534 | return $false 535 | } 536 | 537 | if( $global:password.text -ne $global:password2.text ) { 538 | [Void][System.Windows.Forms.Messagebox]::Show("Passwords don't match") 539 | $global:outer.enabled = $true 540 | [Void]$global:password.focus() 541 | return $false 542 | } 543 | 544 | if( ! $global:agreeBox.checked ) { 545 | [Void][System.Windows.Forms.Messagebox]::Show("You must agree to terms to continue.") 546 | $global:outer.enabled = $true 547 | [Void]$global:agreeBox.focus() 548 | return $false 549 | } 550 | 551 | if( $global:dualBootRadio.checked -and $global:dual.visible ) { 552 | $linuxSizeNum = [double]::parse( $global:linuxSize.text ) * 1GB 553 | if( $linuxSizeNum -lt $global:MIN_DISK_GB * 1GB ) { 554 | [Void][System.Windows.Forms.Messagebox]::Show("Linux requires at least ${MIN_DISK_GB}GB") 555 | $global:outer.enabled = $true 556 | [Void]$global:linuxSize.focus() 557 | return $false 558 | } 559 | 560 | if( $linuxSizeNum -gt $global:maxAvailable ) { 561 | [Void][System.Windows.Forms.Messagebox]::Show("Not enough available space.") 562 | $global:outer.enabled = $true 563 | [Void]$global:linuxSize.focus() 564 | return $false 565 | } 566 | } 567 | 568 | $global:outer.enabled = $true 569 | return $true 570 | } 571 | 572 | function installTypeCheck() { 573 | if( $global:dualBootRadio.checked ) { 574 | $global:installButton.text = 'Continue' 575 | } 576 | else { 577 | $installButton.text = 'Install Now' 578 | } 579 | } 580 | 581 | function gui() { 582 | 583 | Add-Type -AssemblyName System.Windows.Forms 584 | [System.Windows.Forms.Application]::EnableVisualStyles() 585 | 586 | $global:Form = New-Object system.Windows.Forms.Form 587 | $Form.text = "Tunic Linux Installer" 588 | $Form.autosize = $true 589 | $pwd = (get-location).path 590 | $form.icon = new-object System.Drawing.Icon("$PSScriptRoot\files\tunic-logo.ico") 591 | 592 | # Outer layout 593 | $global:outer = New-Object system.Windows.Forms.TableLayoutPanel 594 | $outer.autosize = $true 595 | $outer.Dock = [System.Windows.Forms.DockStyle]::Fill 596 | $outer.columnCount = 1 597 | 598 | # Main Input Panel 599 | $global:main = New-Object system.Windows.Forms.TableLayoutPanel 600 | $main.autosize = $true 601 | $main.Dock = [System.Windows.Forms.DockStyle]::Fill 602 | $main.padding = 10 603 | $main.columnCount = 1 604 | 605 | $bootGroup = New-Object system.Windows.Forms.GroupBox 606 | $bootGroup.text = "Installation Type" 607 | $bootGroup.Dock = [System.Windows.Forms.DockStyle]::Fill 608 | 609 | $bootPanel = New-Object system.Windows.Forms.TableLayoutPanel 610 | $bootPanel.autosize = $true 611 | $bootPanel.Dock = [System.Windows.Forms.DockStyle]::Fill 612 | $bootPanel.columnCount = 1 613 | 614 | $global:dualBootRadio = New-Object system.Windows.Forms.RadioButton 615 | $dualBootRadio.text = "Install Linux alongside Windows" 616 | $dualBootRadio.Dock = [System.Windows.Forms.DockStyle]::Fill 617 | $dualBootRadio.checked = $true 618 | $bootPanel.controls.add($dualBootRadio) 619 | 620 | $global:fullBootRadio = New-Object system.Windows.Forms.RadioButton 621 | $fullBootRadio.text = "Erase entire disk and install Linux" 622 | $fullBootRadio.Dock = [System.Windows.Forms.DockStyle]::Fill 623 | $bootPanel.controls.add($fullBootRadio) 624 | 625 | $global:customBootRadio = New-Object system.Windows.Forms.RadioButton 626 | $customBootRadio.text = "Custom/Advanced" 627 | $customBootRadio.Dock = [System.Windows.Forms.DockStyle]::Fill 628 | $bootPanel.controls.add($customBootRadio) 629 | 630 | $bootGroup.controls.add($bootPanel) 631 | 632 | $main.controls.add($bootGroup) 633 | 634 | $distroPanel = New-Object system.Windows.Forms.TableLayoutPanel 635 | $distroPanel.autosize = $true 636 | $distroPanel.Dock = [System.Windows.Forms.DockStyle]::Fill 637 | $distroPanel.padding = 5 638 | $distroPanel.columnCount = 2 639 | $row = 0 640 | 641 | $distroLabel = New-Object system.Windows.Forms.Label 642 | $distroLabel.text = "Distro" 643 | $distroLabel.AutoSize = $true 644 | 645 | $global:distroName = New-Object system.Windows.Forms.ComboBox 646 | $distroName.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList 647 | $distroName.width = 180 648 | $distroName.AutoSize = $true 649 | 650 | $distroPanel.controls.add($distroLabel, 0, $row) 651 | $distroPanel.controls.add($distroName, 1, $row) 652 | $row++ 653 | 654 | $main.controls.add($distroPanel) 655 | 656 | $global:sizeGroup = New-Object system.Windows.Forms.GroupBox 657 | $sizeGroup.text = "C: Drive" 658 | $sizeGroup.autosize = $true 659 | $sizeGroup.Dock = [System.Windows.Forms.DockStyle]::Fill 660 | 661 | $SizePanel = New-Object system.Windows.Forms.TableLayoutPanel 662 | $sizePanel.autosize = $true 663 | $sizePanel.Dock = [System.Windows.Forms.DockStyle]::Fill 664 | $sizePanel.padding = 5 665 | $sizePanel.columnCount = 2 666 | $row = 0 667 | 668 | $totalLabel = New-Object system.Windows.Forms.Label 669 | $totalLabel.text = "Total Size" 670 | $totalLabel.AutoSize = $true 671 | 672 | $global:TotalValue = New-Object system.Windows.Forms.Label 673 | $TotalValue.text = "0 GB" 674 | $TotalValue.AutoSize = $true 675 | 676 | $sizePanel.controls.add($totalLabel, 0, $row) 677 | $sizePanel.controls.add($totalValue, 1, $row) 678 | $row++ 679 | 680 | $UsedLabel = New-Object system.Windows.Forms.Label 681 | $UsedLabel.text = "Used by Windows" 682 | $UsedLabel.AutoSize = $true 683 | 684 | $global:usedValue = New-Object system.Windows.Forms.Label 685 | $usedValue.text = "0 GB" 686 | $usedValue.AutoSize = $true 687 | 688 | $sizePanel.controls.add($UsedLabel, 0, $row) 689 | $sizePanel.controls.add($UsedValue, 1, $row) 690 | $row++ 691 | 692 | $FreeLabel = New-Object system.Windows.Forms.Label 693 | $FreeLabel.text = "Free" 694 | $FreeLabel.AutoSize = $true 695 | 696 | $global:freeValue = New-Object system.Windows.Forms.Label 697 | $freeValue.text = "0 GB" 698 | $freeValue.AutoSize = $true 699 | 700 | $sizePanel.controls.add($freeLabel, 0, $row) 701 | $sizePanel.controls.add($freeValue, 1, $row) 702 | $row++ 703 | 704 | $availLabel = New-Object system.Windows.Forms.Label 705 | $availLabel.text = "Available" 706 | $availLabel.AutoSize = $true 707 | 708 | $global:availValue = New-Object system.Windows.Forms.Label 709 | $availValue.text = "0 GB" 710 | $availValue.AutoSize = $true 711 | 712 | $sizePanel.controls.add($availLabel, 0, $row) 713 | $sizePanel.controls.add($availValue, 1, $row) 714 | $row++ 715 | 716 | $LinuxLabel = New-Object system.Windows.Forms.Label 717 | $LinuxLabel.text = "Linux Size" 718 | $LinuxLabel.AutoSize = $true 719 | 720 | $global:LinuxSize = New-Object system.Windows.Forms.TextBox 721 | $LinuxSize.multiline = $false 722 | $LinuxSize.AutoSize = $true 723 | $LinuxSize.width = 30 724 | 725 | $sizePanel.controls.add($linuxLabel, 0, $row) 726 | $sizePanel.controls.add($linuxSize, 1, $row) 727 | $row++ 728 | 729 | $idGroup = New-Object system.Windows.Forms.GroupBox 730 | $idGroup.text = "Identifcation" 731 | $idGroup.AutoSize = $true 732 | $idGroup.Dock = [System.Windows.Forms.DockStyle]::Fill 733 | 734 | $idPanel = New-Object system.Windows.Forms.TableLayoutPanel 735 | $idPanel.autosize = $true 736 | $idPanel.Dock = [System.Windows.Forms.DockStyle]::Fill 737 | $idPanel.padding = 5 738 | $idPanel.columnCount = 2 739 | $row = 0 740 | 741 | $usernameLabel = New-Object system.Windows.Forms.Label 742 | $usernameLabel.text = "User Name" 743 | $usernameLabel.AutoSize = $true 744 | 745 | $global:username = New-Object system.Windows.Forms.TextBox 746 | $username.multiline = $false 747 | $username.AutoSize = $true 748 | 749 | $idPanel.controls.add($usernameLabel, 0, $row) 750 | $idPanel.controls.add($username, 1, $row) 751 | $row++ 752 | 753 | $passwordLabel = New-Object system.Windows.Forms.Label 754 | $passwordLabel.text = "Password" 755 | $passwordLabel.AutoSize = $true 756 | 757 | $global:password = New-Object system.Windows.Forms.TextBox 758 | $password.passwordChar = '*' 759 | $password.multiline = $false 760 | $password.AutoSize = $true 761 | 762 | $idPanel.controls.add($passwordLabel, 0, $row) 763 | $idPanel.controls.add($password, 1, $row) 764 | $row++ 765 | 766 | $password2Label = New-Object system.Windows.Forms.Label 767 | $password2Label.text = "Password, again" 768 | $password2Label.AutoSize = $true 769 | 770 | $global:password2 = New-Object system.Windows.Forms.TextBox 771 | $password2.passwordChar = '*' 772 | $password2.multiline = $false 773 | $password2.AutoSize = $true 774 | 775 | $idPanel.controls.add($password2Label, 0, $row) 776 | $idPanel.controls.add($password2, 1, $row) 777 | $row++ 778 | 779 | $fullNameLabel = New-Object system.Windows.Forms.Label 780 | $fullNameLabel.text = "Full Name" 781 | $fullNameLabel.AutoSize = $true 782 | 783 | $global:fullName = New-Object system.Windows.Forms.TextBox 784 | $fullName.multiline = $false 785 | $fullName.AutoSize = $true 786 | 787 | $idPanel.controls.add($fullNameLabel, 0, $row) 788 | $idPanel.controls.add($fullName, 1, $row) 789 | $row++ 790 | 791 | $hostnameLabel = New-Object system.Windows.Forms.Label 792 | $hostnameLabel.text = "Computer Name" 793 | $hostnameLabel.AutoSize = $true 794 | 795 | $global:hostname = New-Object system.Windows.Forms.TextBox 796 | $hostname.multiline = $false 797 | $hostname.AutoSize = $true 798 | 799 | $idPanel.controls.add($hostnameLabel, 0, $row) 800 | $idPanel.controls.add($hostname, 1, $row) 801 | $row++ 802 | 803 | $idGroup.controls.add($idPanel) 804 | $main.controls.add($idGroup) 805 | 806 | $global:agreeBox = New-Object system.Windows.Forms.CheckBox 807 | $agreeBox.Dock = [System.Windows.Forms.DockStyle]::Fill 808 | $agreeBox.text = 809 | "I understand this software could cause data loss " + 810 | "and is provided as-is without any warranty. " + 811 | "I shall not hold the authors liable for any damages whatsoever." 812 | $agreeBox.AutoSize = $false 813 | $agreeBox.height = 50 814 | 815 | $main.controls.add($agreeBox) 816 | 817 | $outer.controls.add($main) 818 | 819 | # Dual boot Input Panel 820 | $global:dual = New-Object system.Windows.Forms.TableLayoutPanel 821 | $dual.autosize = $true 822 | $dual.Dock = [System.Windows.Forms.DockStyle]::Fill 823 | $dual.padding = 10 824 | $dual.columnCount = 1 825 | $dual.visible = $false 826 | 827 | $sizeGroup.controls.add($sizePanel) 828 | $dual.controls.add($sizeGroup) 829 | 830 | $cleanNotice = New-Object system.Windows.Forms.Label 831 | $cleanNotice.text = 'These buttons may help free up more available space' 832 | $cleanNotice.Dock = [System.Windows.Forms.DockStyle]::Fill 833 | $cleanNotice.autoSize = $false 834 | $dual.controls.add($cleanNotice) 835 | 836 | $cleanPanel = New-Object system.Windows.Forms.FlowLayoutPanel 837 | $cleanPanel.padding = 5 838 | $cleanPanel.Dock = [System.Windows.Forms.DockStyle]::Fill 839 | $cleanPanel.AutoSize = $false 840 | 841 | $cleanButton = New-Object system.Windows.Forms.Button 842 | $cleanButton.text = "Clean" 843 | $cleanButton.tabStop = $false 844 | $cleanPanel.controls.add($cleanButton) 845 | 846 | $defragButton = New-Object system.Windows.Forms.Button 847 | $defragButton.text = "Defrag" 848 | $defragButton.tabStop = $false 849 | $cleanPanel.controls.add($defragButton) 850 | 851 | $parterButton = New-Object system.Windows.Forms.Button 852 | $parterButton.text = "Partitions" 853 | $parterButton.tabStop = $false 854 | $cleanPanel.controls.add($parterButton) 855 | 856 | $swapButton = New-Object system.Windows.Forms.Button 857 | $swapButton.text = "Disable Swap" 858 | $swapButton.tabStop = $false 859 | $cleanPanel.controls.add($swapButton) 860 | 861 | $treeButton = New-Object system.Windows.Forms.Button 862 | $treeButton.text = "Disk Use" 863 | $treeButton.tabStop = $false 864 | $cleanPanel.controls.add($treeButton) 865 | 866 | $dual.controls.add($cleanPanel) 867 | 868 | $outer.controls.add($dual) 869 | 870 | # Progress Panel 871 | 872 | $global:progress = New-Object system.Windows.Forms.TableLayoutPanel 873 | $progress.autosize = $true 874 | $progress.Dock = [System.Windows.Forms.DockStyle]::Fill 875 | $progress.padding = 10 876 | $progress.columnCount = 1 877 | $progress.visible = $false 878 | #TODO: progress fields 879 | #TODO: use job to run in background. 880 | #TODO: Stop button 881 | 882 | # Requirement Status Panel 883 | 884 | $StatusPanel = New-Object system.Windows.Forms.TableLayoutPanel 885 | $StatusPanel.autosize = $true 886 | $StatusPanel.Dock = [System.Windows.Forms.DockStyle]::Fill 887 | $StatusPanel.padding = 5 888 | $StatusPanel.columnCount = 2 889 | $row = 0 890 | 891 | $defragLabel = New-Object system.Windows.Forms.Label 892 | $defragLabel.text = "Defragment" 893 | $defragLabel.AutoSize = $true 894 | 895 | $global:defragStatus = New-Object system.Windows.Forms.Label 896 | $defragStatus.text = "To Do" 897 | $defragStatus.AutoSize = $true 898 | 899 | $statusPanel.controls.add($defragLabel, 0, $row) 900 | $statusPanel.controls.add($defragStatus, 1, $row) 901 | $row++ 902 | 903 | $partLabel = New-Object system.Windows.Forms.Label 904 | $partLabel.text = "Re-Partition" 905 | $partLabel.AutoSize = $true 906 | 907 | $global:partStatus = New-Object system.Windows.Forms.Label 908 | $partStatus.text = "To Do" 909 | $partStatus.AutoSize = $true 910 | 911 | $statusPanel.controls.add($partLabel, 0, $row) 912 | $statusPanel.controls.add($partStatus, 1, $row) 913 | $row++ 914 | 915 | $dlLabel = New-Object system.Windows.Forms.Label 916 | $dlLabel.text = "Download" 917 | $dlLabel.AutoSize = $true 918 | 919 | $global:dlStatus = New-Object system.Windows.Forms.Label 920 | $dlStatus.text = "To Do" 921 | $dlStatus.AutoSize = $true 922 | 923 | $statusPanel.controls.add($dlLabel, 0, $row) 924 | $statusPanel.controls.add($dlStatus, 1, $row) 925 | $row++ 926 | 927 | $grubLabel = New-Object system.Windows.Forms.Label 928 | $grubLabel.text = "Install Grub" 929 | $grubLabel.AutoSize = $true 930 | 931 | $global:grubStatus = New-Object system.Windows.Forms.Label 932 | $grubStatus.text = "To Do" 933 | $grubStatus.AutoSize = $true 934 | 935 | $statusPanel.controls.add($grubLabel, 0, $row) 936 | $statusPanel.controls.add($grubStatus, 1, $row) 937 | $row++ 938 | 939 | $rebootLabel = New-Object system.Windows.Forms.Label 940 | $rebootLabel.text = "Reboot" 941 | $rebootLabel.AutoSize = $true 942 | 943 | $global:rebootStatus = New-Object system.Windows.Forms.Label 944 | $rebootStatus.text = "To Do" 945 | $rebootStatus.AutoSize = $true 946 | 947 | $statusPanel.controls.add($rebootLabel, 0, $row) 948 | $statusPanel.controls.add($rebootStatus, 1, $row) 949 | $row++ 950 | 951 | $progress.controls.add($statusPanel) 952 | 953 | #TODO: button panel - Abort 954 | $progress.controls.add( (New-Object system.Windows.Forms.Label) ) 955 | 956 | $outer.controls.add($progress) 957 | 958 | # Button Panel - common to all input panels, but not progress 959 | 960 | $buttonPanel = New-Object system.Windows.Forms.FlowLayoutPanel 961 | $buttonPanel.padding = 5 962 | $buttonPanel.AutoSize = $true 963 | 964 | $global:abortButton = New-Object system.Windows.Forms.Button 965 | $abortButton.text = "Quit" 966 | $abortButton.tabStop = $false 967 | $abortButton.dialogResult = [System.Windows.Forms.DialogResult]::Cancel 968 | $buttonPanel.controls.add($abortButton) 969 | 970 | $global:installbutton = New-Object system.Windows.Forms.Button 971 | $installbutton.text = "Continue" 972 | $installButton.enabled = $false 973 | $buttonPanel.controls.add($installButton) 974 | 975 | $outer.controls.add($buttonPanel) 976 | 977 | # The main form 978 | 979 | $form.controls.add($outer) 980 | 981 | # Actions 982 | 983 | $form.add_shown({ 984 | $global:outer.enabled = $false 985 | try { 986 | initFields 987 | } finally { 988 | $global:outer.enabled = $true 989 | } 990 | $global:form.activate() 991 | $dualBootRadio.focus() 992 | }) 993 | 994 | $agreeBox.add_click({ 995 | if( $agreeBox.checked ) { 996 | $installButton.enabled = $true 997 | } 998 | }) 999 | 1000 | $cleanButton.add_click({ 1001 | $global:outer.enabled = $false 1002 | try { 1003 | clean 1004 | calcGui 1005 | } finally { 1006 | $global:outer.enabled = $true 1007 | } 1008 | }) 1009 | 1010 | $defragButton.add_click({ 1011 | $global:outer.enabled = $false 1012 | try { 1013 | start-process dfrgui -wait 1014 | calcGui 1015 | } finally { 1016 | $global:outer.enabled = $true 1017 | } 1018 | }) 1019 | 1020 | $parterButton.add_click({ 1021 | $global:outer.enabled = $false 1022 | try { 1023 | start-process diskmgmt.msc -wait 1024 | calcGui 1025 | } finally { 1026 | $global:outer.enabled = $true 1027 | } 1028 | }) 1029 | 1030 | $swapButton.add_click({ 1031 | $global:outer.enabled = $false 1032 | try { 1033 | #TODO: change button caption disable/enable. 1034 | disableSwap 1035 | if( yes('Swap will be disabled on reboot. Reboot now?') ) { 1036 | restart-computer -force 1037 | } 1038 | } finally { 1039 | $global:outer.enabled = $true 1040 | } 1041 | }) 1042 | 1043 | $treeButton.add_click({ 1044 | $global:outer.enabled = $false 1045 | try { 1046 | treeMap 1047 | calcGui 1048 | } finally { 1049 | $global:outer.enabled = $true 1050 | } 1051 | }) 1052 | 1053 | $global:dualBootRadio.add_click({ 1054 | installTypeCheck 1055 | }) 1056 | 1057 | $global:fullBootRadio.add_click({ 1058 | installTypeCheck 1059 | }) 1060 | 1061 | $global:customBootRadio.add_click({ 1062 | installTypeCheck 1063 | }) 1064 | 1065 | $installButton.add_click({ 1066 | $global:data.username = $username.text 1067 | $global:data.fullname = $fullname.text 1068 | $global:data.hostname = $hostname.text 1069 | $global:data.password = $password.text 1070 | if( $dualBootRadio.checked ) { 1071 | $global:data.installType = $DUALBOOT 1072 | } elseif( $fullBootRadio.checked ) { 1073 | $global:data.installType = $FULLBOOT 1074 | } else { 1075 | $global:data.installType = $CUSTOMBOOT 1076 | } 1077 | $global:data.iso_url = $global:distros[ $distroName.selectedIndex ].url 1078 | 1079 | if( -not (checkFields) ) { 1080 | return 1081 | } 1082 | if( $main.visible -and $dualBootRadio.checked ) { 1083 | $main.visible = $false 1084 | $dual.visible = $true 1085 | $outer.enabled = $false 1086 | try { 1087 | $global:installButton.text = 'Install' 1088 | [System.Windows.Forms.Application]::DoEvents() 1089 | calcGui 1090 | } finally { 1091 | $outer.enabled = $true 1092 | } 1093 | $linuxsize.focus() 1094 | } 1095 | else { 1096 | $global:main.visible = $false 1097 | $global:dual.visible = $false 1098 | $installButton.visible = $false 1099 | $global:progress.visible = $true 1100 | #TODO: Run as PSJob, remove doevents, don't hide abortButton 1101 | $global:abortButton.visible = $false 1102 | 1103 | if( $global:data.installType -eq $DUALBOOT ) { 1104 | $global:data.linuxSize = [double]::parse( $global:linuxSize.text ) 1105 | 1106 | $global:defragStatus.text = 'In Progress' 1107 | [System.Windows.Forms.Application]::DoEvents() 1108 | defrag 1109 | $global:defragStatus.text = 'Done' 1110 | 1111 | $global:partStatus.text = 'In Progress' 1112 | [System.Windows.Forms.Application]::DoEvents() 1113 | repartition 1114 | $global:partStatus.text = 'Done' 1115 | } else { 1116 | $global:defragStatus.text = 'Skipped' 1117 | $global:partStatus.text = 'Skipped' 1118 | } 1119 | 1120 | $global:dlStatus.text = 'In Progress' 1121 | [System.Windows.Forms.Application]::DoEvents() 1122 | guiDownloadIso 1123 | $global:dlStatus.text = 'Done' 1124 | 1125 | $global:grubStatus.text = 'In Progress' 1126 | [System.Windows.Forms.Application]::DoEvents() 1127 | installGrub 1128 | $global:grubStatus.text = 'Done' 1129 | 1130 | $global:rebootStatus.text = 'In Progress' 1131 | [System.Windows.Forms.Application]::DoEvents() 1132 | Restart-Computer -force 1133 | } 1134 | }) 1135 | 1136 | return $form 1137 | } 1138 | 1139 | function hideConsole() { 1140 | 1141 | # .Net methods for hiding/showing the console in the background 1142 | Add-Type -Name Window -Namespace Console -MemberDefinition ' 1143 | [DllImport("Kernel32.dll")] 1144 | public static extern IntPtr GetConsoleWindow(); 1145 | 1146 | [DllImport("user32.dll")] 1147 | public static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow); 1148 | ' 1149 | 1150 | $consoleWin = [Console.Window]::GetConsoleWindow() 1151 | 1152 | # https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow 1153 | [void][Console.Window]::ShowWindow($consoleWin, 6) 1154 | } 1155 | 1156 | function uninstall() { 1157 | if( ! ([Security.Principal.WindowsPrincipal] ` 1158 | [Security.Principal.WindowsIdentity]::GetCurrent() ` 1159 | ).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) ) { 1160 | write-host 'Must be an Administrator' 1161 | exit 1 1162 | } 1163 | if( test-path("${global:tunic_dir}\bcd.id") ) { 1164 | $osloader = (get-content "${global:tunic_dir}\bcd.id") 1165 | bcdedit /delete "$osloader" /cleanup /f 1166 | } 1167 | $efi = "S:" 1168 | if ( -not (Test-Path "$efi") ) { 1169 | mountvol $efi /s 1170 | } 1171 | rm "${efi}\boot" -recurse -force 1172 | mountvol "$efi" /d 1173 | rm "${global:tunic_dir}" -recurse -force 1174 | } 1175 | 1176 | # Installs full disk install. 1177 | # Mainly for testing purposes. 1178 | # User will have 'tunic' password. 1179 | function fullDisk() { 1180 | initData 1181 | $global:data.installType = $FULLBOOT 1182 | $global:data.password = 'tunic' 1183 | # copied from distros.ps1 1184 | $url = 'http://releases.ubuntu.com/18.04.3/ubuntu-18.04.3-desktop-amd64.iso' 1185 | $url = 'http://releases.ubuntu.com/19.10/ubuntu-19.10-desktop-amd64.iso' 1186 | $url = 'http://mirrors.gigenet.com/linuxmint/iso/stable/19.3/linuxmint-19.3-xfce-64bit.iso' 1187 | $url = 'http://mirrors.gigenet.com/linuxmint/iso/stable/19.3/linuxmint-19.3-cinnamon-64bit.iso' 1188 | $global:data.iso_url = $url 1189 | 1190 | if( $global:data.installType -eq $DUALBOOT ) { 1191 | write-host 'Defragmenting...' 1192 | defrag 1193 | write-host 'Repartitioning...' 1194 | calcPartition 1195 | repartition 1196 | } 1197 | 1198 | write-host 'Downloading...' 1199 | downloadIso 1200 | write-host 'Installing Grub...' 1201 | installGrub 1202 | write-host 'Restarting...' 1203 | restart-computer -force 1204 | } 1205 | 1206 | $op = $args[0] 1207 | 1208 | switch($op) { 1209 | {$_ -eq "download-iso" } { 1210 | downloadIso 1211 | } 1212 | {$_ -eq "enable-swap" } { 1213 | enableSwap 1214 | } 1215 | {$_ -eq "disable-swap" } { 1216 | disableSwap 1217 | } 1218 | {$_ -eq "install-grub" } { 1219 | downloadIso 1220 | installGrub 1221 | } 1222 | {$_ -eq "tz" } { 1223 | getLinuxTimezone 1224 | } 1225 | {$_ -eq "full-disk" } { 1226 | fullDisk 1227 | } 1228 | {$_ -eq "defrag" } { 1229 | defrag 1230 | } 1231 | {$_ -eq "preseed" } { 1232 | set-content -value (expandTemplate "files\preseed.cfg") -path "preseed.tmp.cfg" 1233 | get-content -path 'preseed.tmp.cfg' 1234 | rm 'preseed.tmp.cfg' 1235 | } 1236 | {$_ -eq "hidden" } { 1237 | hideConsole 1238 | $global:form = (gui) 1239 | [void]$form.showDialog() 1240 | } 1241 | {$_ -eq "uninstall" } { 1242 | uninstall 1243 | } 1244 | default { 1245 | $global:form = (gui) 1246 | [void]$form.showDialog() 1247 | } 1248 | } 1249 | 1250 | --------------------------------------------------------------------------------