├── LICENSE
├── README.md
├── install-raid0.sh
├── install.sh
├── template-181112.sh
└── template-190512.sh
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Linux-Reinstall
2 |
3 | This repo includes modified scripts from , with credit to Vicer.
4 |
5 | ## template-YYMMDD.sh
6 |
7 | The original scripts. See for detailed usage.
8 |
9 | ## install.sh
10 |
11 | The modified script, mainly differing in:
12 |
13 | 1. use `en_US.UTF-8` instead of `en_US` for debian/ubuntu.
14 | 2. use `ifupdown` instead of `netplan` for newer ubuntu releases.
15 | 3. use UEFI/GPT instead, for single partition of 2TB or larger.
16 | 4. use boot-root-noswap partition style instead of built-in atomic.
17 |
18 | ## install-raid0.sh
19 |
20 | Same flavor as `install.sh`, but offer to install software RAID-0.
21 |
22 | Currently:
23 |
24 | 1. The machine must have `/dev/sda` and `/dev/sdb` of **identical** size.
25 | 2. RAID1 is used for `/boot` and RAID0 is used for `/`.
26 | 3. SWAP is disabled. You can enable it by `swapon`.
27 |
28 | **Installing Debian 8 on ikoula machines will fail.**
29 |
--------------------------------------------------------------------------------
/install-raid0.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | ## It can reinstall Debian, Ubuntu, CentOS system with network.
4 | ## Suitable for using by GRUB.
5 | ## Default root password: Vicer
6 | ## Blog: https://moeclub.org
7 | ## Written By Vicer
8 | ## Modified By Airium
9 |
10 | export tmpVER=''
11 | export tmpDIST=''
12 | export tmpURL=''
13 | export tmpWORD=''
14 | export tmpMirror=''
15 | export tmpSSL=''
16 | export tmpINS=''
17 | export tmpFW=''
18 | export ipAddr=''
19 | export ipMask=''
20 | export ipGate=''
21 | export linuxdists=''
22 | export ddMode='0'
23 | export setNet='0'
24 | export setRDP='0'
25 | export isMirror='0'
26 | export FindDists='0'
27 | export loaderMode='0'
28 | export SpikCheckDIST='0'
29 | export UNKNOWHW='0'
30 | export UNVER='6.4'
31 |
32 | while [[ $# -ge 1 ]]; do
33 | case $1 in
34 | -v|--ver)
35 | shift
36 | tmpVER="$1"
37 | shift
38 | ;;
39 | -d|--debian)
40 | shift
41 | linuxdists='debian'
42 | tmpDIST="$1"
43 | shift
44 | ;;
45 | -u|--ubuntu)
46 | shift
47 | linuxdists='ubuntu'
48 | tmpDIST="$1"
49 | shift
50 | ;;
51 | -c|--centos)
52 | shift
53 | linuxdists='centos'
54 | tmpDIST="$1"
55 | shift
56 | ;;
57 | -dd|--image)
58 | shift
59 | ddMode='1'
60 | tmpURL="$1"
61 | shift
62 | ;;
63 | -p|--password)
64 | shift
65 | tmpWORD="$1"
66 | shift
67 | ;;
68 | -i|--interface)
69 | shift
70 | interface="$1"
71 | shift
72 | ;;
73 | --ip-addr)
74 | shift
75 | ipAddr="$1"
76 | shift
77 | ;;
78 | --ip-mask)
79 | shift
80 | ipMask="$1"
81 | shift
82 | ;;
83 | --ip-gate)
84 | shift
85 | ipGate="$1"
86 | shift
87 | ;;
88 | --loader)
89 | shift
90 | loaderMode='1'
91 | ;;
92 | --prefer)
93 | shift
94 | tmpPrefer="$1"
95 | shift
96 | ;;
97 | -a|--auto)
98 | shift
99 | tmpINS='auto'
100 | ;;
101 | -m|--manual)
102 | shift
103 | tmpINS='manual'
104 | ;;
105 | -apt|-yum|--mirror)
106 | shift
107 | isMirror='1'
108 | tmpMirror="$1"
109 | shift
110 | ;;
111 | -rdp)
112 | shift
113 | setRDP='1'
114 | WinRemote="$1"
115 | shift
116 | ;;
117 | -ssl)
118 | shift
119 | tmpSSL="$1"
120 | shift
121 | ;;
122 | --firmware)
123 | shift
124 | tmpFW='1'
125 | ;;
126 | *)
127 | if [[ "$1" != 'error' ]]; then echo -ne "\nInvaild option: '$1'\n\n"; fi
128 | echo -ne " Usage:\n\tbash DebianNET.sh\t-d/--debian [\033[33m\033[04mdists-name\033[0m]\n\t\t\t\t-u/--ubuntu [\033[04mdists-name\033[0m]\n\t\t\t\t-c/--centos [\033[33m\033[04mdists-verison\033[0m]\n\t\t\t\t-v/--ver [32/\033[33m\033[04mi386\033[0m|64/amd64]\n\t\t\t\t--ip-addr/--ip-gate/--ip-mask\n\t\t\t\t-apt/-yum/--mirror\n\t\t\t\t-dd/--image\n\t\t\t\t-a/--auto\n\t\t\t\t-m/--manual\n"
129 | exit 1;
130 | ;;
131 | esac
132 | done
133 |
134 | [[ "$EUID" -ne '0' ]] && echo "Error:This script must be run as root!" && exit 1;
135 |
136 | function CheckDependence(){
137 | FullDependence='0';
138 | for BIN_DEP in `echo "$1" |sed 's/,/\n/g'`
139 | do
140 | if [[ -n "$BIN_DEP" ]]; then
141 | Founded='0';
142 | for BIN_PATH in `echo "$PATH" |sed 's/:/\n/g'`
143 | do
144 | ls $BIN_PATH/$BIN_DEP >/dev/null 2>&1;
145 | if [ $? == '0' ]; then
146 | Founded='1';
147 | break;
148 | fi
149 | done
150 | if [ "$Founded" == '1' ]; then
151 | echo -en "[\033[32mok\033[0m]\t";
152 | else
153 | FullDependence='1';
154 | echo -en "[\033[31mNot Install\033[0m]";
155 | fi
156 | echo -en "\t$BIN_DEP\n";
157 | fi
158 | done
159 | if [ "$FullDependence" == '1' ]; then
160 | echo -ne "\n\033[31mError! \033[0mPlease use '\033[33mapt-get\033[0m' or '\033[33myum\033[0m' install it.\n\n\n"
161 | exit 1;
162 | fi
163 | }
164 |
165 | if [[ -z "$linuxdists" ]]; then
166 | linuxdists='debian';
167 | fi
168 |
169 | clear && echo -e "\n\033[36m# Check Dependence\033[0m\n"
170 |
171 | if [[ "$ddMode" == '1' ]]; then
172 | CheckDependence iconv;
173 | linuxdists='debian';
174 | tmpDIST='jessie';
175 | tmpVER='amd64';
176 | tmpINS='auto';
177 | fi
178 |
179 | if [[ "$linuxdists" == 'debian' ]] || [[ "$linuxdists" == 'ubuntu' ]]; then
180 | CheckDependence wget,awk,grep,sed,cut,cat,cpio,gzip,find,dirname,basename;
181 | elif [[ "$linuxdists" == 'centos' ]]; then
182 | CheckDependence wget,awk,grep,sed,cut,cat,cpio,gzip,find,dirname,basename,file,xz;
183 | fi
184 |
185 | if [[ -n "$tmpWORD" ]]; then
186 | CheckDependence openssl;
187 | fi
188 |
189 | if [[ "$loaderMode" == "0" ]]; then
190 | [[ -f '/boot/grub/grub.cfg' ]] && GRUBOLD='0' && GRUBDIR='/boot/grub' && GRUBFILE='grub.cfg';
191 | [[ -z "$GRUBDIR" ]] && [[ -f '/boot/grub2/grub.cfg' ]] && GRUBOLD='0' && GRUBDIR='/boot/grub2' && GRUBFILE='grub.cfg';
192 | [[ -z "$GRUBDIR" ]] && [[ -f '/boot/grub/grub.conf' ]] && GRUBOLD='1' && GRUBDIR='/boot/grub' && GRUBFILE='grub.conf';
193 | [ -z "$GRUBDIR" -o -z "$GRUBFILE" ] && echo -ne "Error! \nNot Found grub path.\n" && exit 1;
194 | else
195 | tmpINS='auto'
196 | fi
197 |
198 | if [[ "$isMirror" == '1' ]]; then
199 | if [[ -n "$tmpMirror" ]]; then
200 | TMPMirrorHost="$(echo -n "$tmpMirror" |grep -Eo '.*\.(\w+)')";
201 | echo "$TMPMirrorHost" |grep -q '://';
202 | if [[ $? == '0' ]]; then
203 | MirrorHost="$(echo "$TMPMirrorHost" |awk -F'://' '{print $2}')";
204 | else
205 | echo -en "\n\033[31mInvaild Mirror! \033[0m\n";
206 | [[ "$linuxdists" == 'debian' ]] && echo -en "\033[33mexample:\033[0m http://deb.debian.org/debian\n\n";
207 | [[ "$linuxdists" == 'ubuntu' ]] && echo -en "\033[33mexample:\033[0m http://archive.ubuntu.com/ubuntu\n\n";
208 | [[ "$linuxdists" == 'centos' ]] && echo -en "\033[33mexample:\033[0m http://mirror.centos.org/centos\n\n";
209 | exit 1
210 | fi
211 | if [[ -n "$MirrorHost" ]]; then
212 | MirrorFolder="$(echo -n "$tmpMirror" |awk -F''${MirrorHost}'' '{print $2}' |sed 's/\/$//g')";
213 | if [[ -z "$MirrorFolder" ]]; then
214 | [[ "$linuxdists" == 'debian' ]] && MirrorFolder='/debian';
215 | [[ "$linuxdists" == 'ubuntu' ]] && MirrorFolder='/ubuntu';
216 | [[ "$linuxdists" == 'centos' ]] && MirrorFolder='/centos';
217 | fi
218 | DISTMirror="${MirrorHost}${MirrorFolder}";
219 | fi
220 | fi
221 | fi
222 |
223 | if [[ -z "$DISTMirror" ]]; then
224 | [[ "$linuxdists" == 'debian' ]] && MirrorHost='deb.debian.org' && MirrorFolder='/debian' && DISTMirror="${MirrorHost}${MirrorFolder}";
225 | [[ "$linuxdists" == 'ubuntu' ]] && MirrorHost='archive.ubuntu.com' && MirrorFolder='/ubuntu' && DISTMirror="${MirrorHost}${MirrorFolder}";
226 | [[ "$linuxdists" == 'centos' ]] && DISTMirror='vault.centos.org';
227 | fi
228 |
229 | if [[ -n "$tmpVER" ]]; then
230 | tmpVER="$(echo "$tmpVER" |sed -r 's/(.*)/\L\1/')";
231 | if [[ "$tmpVER" == '32' ]] || [[ "$tmpVER" == 'i386' ]] || [[ "$tmpVER" == 'x86' ]]; then
232 | VER='i386';
233 | fi
234 | if [[ "$tmpVER" == '64' ]] || [[ "$tmpVER" == 'amd64' ]] || [[ "$tmpVER" == 'x86_64' ]] || [[ "$tmpVER" == 'x64' ]]; then
235 | if [[ "$linuxdists" == 'debian' ]] || [[ "$linuxdists" == 'ubuntu' ]]; then
236 | VER='amd64';
237 | elif [[ "$linuxdists" == 'centos' ]]; then
238 | VER='x86_64';
239 | fi
240 | fi
241 | fi
242 |
243 | if [[ -z "$VER" ]]; then
244 | VER='i386';
245 | fi
246 |
247 | if [[ -n "$tmpPrefer" ]]; then
248 | PreferOption="$(echo "$tmpPrefer" |sed 's/[[:space:]]*//g')"
249 | fi
250 |
251 | if [[ -z "$PreferOption" ]]; then
252 | PreferOption='current';
253 | fi
254 |
255 | if [[ -z "$tmpDIST" ]]; then
256 | [[ "$linuxdists" == 'debian' ]] && DIST='jessie';
257 | [[ "$linuxdists" == 'ubuntu' ]] && DIST='xenial';
258 | [[ "$linuxdists" == 'centos' ]] && DIST='6.8';
259 | fi
260 |
261 | if [[ -z "$DIST" ]]; then
262 | if [[ "$linuxdists" == 'debian' ]]; then
263 | SpikCheckDIST='0'
264 | DIST="$(echo "$tmpDIST" |sed -r 's/(.*)/\L\1/')";
265 | echo "$DIST" |grep -q '[0-9]';
266 | [[ $? -eq '0' ]] && {
267 | isDigital="$(echo "$DIST" |grep -o '[\.0-9]\{1,\}' |sed -n '1h;1!H;$g;s/\n//g;$p' |cut -d'.' -f1)";
268 | [[ -n $isDigital ]] && {
269 | [[ "$isDigital" == '7' ]] && DIST='wheezy';
270 | [[ "$isDigital" == '8' ]] && DIST='jessie';
271 | [[ "$isDigital" == '9' ]] && DIST='stretch';
272 | [[ "$isDigital" == '10' ]] && DIST='buster';
273 | }
274 | }
275 | fi
276 | if [[ "$linuxdists" == 'ubuntu' ]]; then
277 | SpikCheckDIST='0'
278 | DIST="$(echo "$tmpDIST" |sed -r 's/(.*)/\L\1/')";
279 | echo "$DIST" |grep -q '[0-9]';
280 | [[ $? -eq '0' ]] && {
281 | isDigital="$(echo "$DIST" |grep -o '[\.0-9]\{1,\}' |sed -n '1h;1!H;$g;s/\n//g;$p')";
282 | [[ -n $isDigital ]] && {
283 | [[ "$isDigital" == '12.04' ]] && DIST='precise';
284 | [[ "$isDigital" == '14.04' ]] && DIST='trusty';
285 | [[ "$isDigital" == '16.04' ]] && DIST='xenial';
286 | [[ "$isDigital" == '18.04' ]] && DIST='bionic';
287 | }
288 | }
289 | fi
290 | if [[ "$linuxdists" == 'centos' ]]; then
291 | SpikCheckDIST='1'
292 | DISTCheck="$(echo "$tmpDIST" |grep -o '[\.0-9]\{1,\}')";
293 | ListDIST="$(wget --no-check-certificate -qO- "http://$DISTMirror/dir_sizes" |cut -f2 |grep '^[0-9]')"
294 | DIST="$(echo "$ListDIST" |grep "^$DISTCheck" |head -n1)"
295 | [[ -z "$DIST" ]] && {
296 | echo -ne '\nThe dists version not found in this mirror, Please check it! \n\n'
297 | bash $0 error;
298 | exit 1;
299 | }
300 | wget --no-check-certificate -qO- "http://$DISTMirror/$DIST/os/$VER/.treeinfo" |grep -q 'general';
301 | [[ $? != '0' ]] && {
302 | wget --no-check-certificate -qO- "http://$DISTMirror/centos/$DIST/os/$VER/.treeinfo" |grep -q 'general';
303 | [[ $? == '0' ]] && {
304 | DISTMirror="${DISTMirror}/${linuxdists}"
305 | } || {
306 | echo -ne "\nThe version not found in this mirror, Please change mirror try again! \n\n";
307 | exit 1;
308 | }
309 | }
310 |
311 | fi
312 | fi
313 |
314 | if [[ "$SpikCheckDIST" == '0' ]]; then
315 | DistsList="$(wget --no-check-certificate -qO- "http://$DISTMirror/dists/" |grep -o 'href=.*/"' |cut -d'"' -f2 |sed '/-\|old\|Debian\|experimental\|stable\|test\|sid\|devel/d' |grep '^[^/]' |sed -n '1h;1!H;$g;s/\n//g;s/\//\;/g;$p')";
316 | for CheckDEB in `echo "$DistsList" |sed 's/;/\n/g'`
317 | do
318 | [[ "$CheckDEB" == "$DIST" ]] && FindDists='1';
319 | [[ "$FindDists" == '1' ]] && break;
320 | done
321 | [[ "$FindDists" == '0' ]] && {
322 | echo -ne '\nThe dists version not found, Please check it! \n\n'
323 | bash $0 error;
324 | exit 1;
325 | }
326 | fi
327 |
328 | [[ "$ddMode" == '1' ]] && {
329 | export SSL_SUPPORT='https://moeclub.org/get-wget_udeb_amd64';
330 | if [[ -n "$tmpURL" ]]; then
331 | DDURL="$tmpURL"
332 | echo "$DDURL" |grep -q '^http://\|^ftp://\|^https://';
333 | [[ $? -ne '0' ]] && echo 'Please input vaild URL,Only support http://, ftp:// and https:// !' && exit 1;
334 | [[ -n "$tmpSSL" ]] && SSL_SUPPORT="$tmpSSL";
335 | else
336 | echo 'Please input vaild image URL! ';
337 | exit 1;
338 | fi
339 | }
340 |
341 | [[ -n "$tmpINS" ]] && {
342 | [[ "$tmpINS" == 'auto' ]] && inVNC='n';
343 | [[ "$tmpINS" == 'manual' ]] && inVNC='y';
344 | }
345 |
346 | [ -n "$ipAddr" ] && [ -n "$ipMask" ] && [ -n "$ipGate" ] && setNet='1';
347 | [[ -n "$tmpWORD" ]] && myPASSWORD="$(openssl passwd -1 "$tmpWORD")";
348 | [[ -z "$myPASSWORD" ]] && myPASSWORD='$1$0shYGfBd$8v189JOozDO1jPqPO645e1';
349 | [[ -n "$tmpFW" ]] && INCFW="$tmpFW";
350 | [[ -z "$INCFW" ]] && INCFW='0';
351 |
352 | if [[ -n "$interface" ]]; then
353 | IFETH="$interface"
354 | else
355 | if [[ "$linuxdists" == 'centos' ]]; then
356 | IFETH="link"
357 | else
358 | IFETH="auto"
359 | fi
360 | fi
361 |
362 | clear && echo -e "\n\033[36m# Install\033[0m\n"
363 |
364 | ASKVNC(){
365 | inVNC='y';
366 | [[ "$ddMode" == '0' ]] && {
367 | echo -ne "\033[34mCan you login VNC?\033[0m\e[33m[\e[32my\e[33m/n]\e[0m "
368 | read tmpinVNC
369 | [[ -n "$inVNCtmp" ]] && inVNC="$tmpinVNC"
370 | }
371 | [ "$inVNC" == 'y' -o "$inVNC" == 'Y' ] && inVNC='y';
372 | [ "$inVNC" == 'n' -o "$inVNC" == 'N' ] && inVNC='n';
373 | }
374 |
375 | [ "$inVNC" == 'y' -o "$inVNC" == 'n' ] || ASKVNC;
376 | [[ "$linuxdists" == 'debian' ]] && LinuxName='Debian';
377 | [[ "$linuxdists" == 'ubuntu' ]] && LinuxName='Ubuntu';
378 | [[ "$linuxdists" == 'centos' ]] && LinuxName='CentOS';
379 | [[ "$ddMode" == '0' ]] && {
380 | [[ "$inVNC" == 'y' ]] && echo -e "\033[34mManual Mode\033[0m install \033[33m$LinuxName\033[0m [\033[33m$DIST\033[0m] [\033[33m$VER\033[0m] in VNC. "
381 | [[ "$inVNC" == 'n' ]] && echo -e "\033[34mAuto Mode\033[0m install \033[33m$LinuxName\033[0m [\033[33m$DIST\033[0m] [\033[33m$VER\033[0m]. "
382 | }
383 | [[ "$ddMode" == '1' ]] && {
384 | echo -ne "\033[34mAuto Mode\033[0m install \033[33mWindows\033[0m\n[\033[33m$DDURL\033[0m]\n"
385 | }
386 |
387 | if [[ "$linuxdists" == 'centos' ]]; then
388 | if [[ "$DIST" != "$UNVER" ]]; then
389 | awk 'BEGIN{print '${UNVER}'-'${DIST}'}' |grep -q '^-'
390 | if [ $? != '0' ]; then
391 | UNKNOWHW='1';
392 | echo -en "\033[33mThe version lower then \033[31m$UNVER\033[33m may not support in auto mode! \033[0m\n";
393 | if [[ "$inVNC" == 'n' ]]; then
394 | echo -en "\033[35mYou can connect VNC with \033[32mPublic IP\033[35m and port \033[32m1\033[35m/\033[32m5901\033[35m in vnc viewer.\033[0m\n"
395 | read -n 1 -p "Press Enter to continue..." INP
396 | [[ "$INP" != '' ]] && echo -ne '\b \n\n';
397 | fi
398 | fi
399 | awk 'BEGIN{print '${UNVER}'-'${DIST}'+0.59}' |grep -q '^-'
400 | if [ $? == '0' ]; then
401 | echo -en "\n\033[31mThe version higher then \033[33m6.9 \033[31mis not support in current! \033[0m\n\n"
402 | exit 1;
403 | fi
404 | fi
405 | fi
406 |
407 | echo -e "\n[\033[33m$LinuxName\033[0m] [\033[33m$DIST\033[0m] [\033[33m$VER\033[0m] Downloading..."
408 |
409 | [[ -z "$DISTMirror" ]] && echo -ne "\033[31mError! \033[0mInvaild mirror! \n" && exit 1
410 |
411 | if [[ "$linuxdists" == 'debian' ]] || [[ "$linuxdists" == 'ubuntu' ]]; then
412 | wget --no-check-certificate -qO '/boot/initrd.img' "http://$DISTMirror/dists/$DIST/main/installer-$VER/$PreferOption/images/netboot/$linuxdists-installer/$VER/initrd.gz"
413 | [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'initrd.img' for \033[33m$linuxdists\033[0m failed! \n" && exit 1
414 | wget --no-check-certificate -qO '/boot/vmlinuz' "http://$DISTMirror/dists/$DIST/main/installer-$VER/$PreferOption/images/netboot/$linuxdists-installer/$VER/linux"
415 | [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'vmlinuz' for \033[33m$linuxdists\033[0m failed! \n" && exit 1
416 | elif [[ "$linuxdists" == 'centos' ]]; then
417 | wget --no-check-certificate -qO '/boot/initrd.img' "http://$DISTMirror/$DIST/os/$VER/isolinux/initrd.img"
418 | [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'initrd.img' for \033[33m$linuxdists\033[0m failed! \n" && exit 1
419 | wget --no-check-certificate -qO '/boot/vmlinuz' "http://$DISTMirror/$DIST/os/$VER/isolinux/vmlinuz"
420 | [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'vmlinuz' for \033[33m$linuxdists\033[0m failed! \n" && exit 1
421 | fi
422 | if [[ "$linuxdists" == 'debian' ]]; then
423 | if [[ "$INCFW" == '1' ]]; then
424 | wget --no-check-certificate -qO '/boot/firmware.cpio.gz' "http://cdimage.debian.org/cdimage/unofficial/non-free/firmware/$DIST/current/firmware.cpio.gz"
425 | [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'firmware' for \033[33m$linuxdists\033[0m failed! \n" && exit 1
426 | fi
427 | if [[ "$ddMode" == '1' ]]; then
428 | vKernel_udeb=$(wget --no-check-certificate -qO- "http://$DISTMirror/dists/$DIST/main/installer-$VER/$PreferOption/images/udeb.list" |grep '^acpi-modules' |head -n1 |grep -o '[0-9]\{1,2\}.[0-9]\{1,2\}.[0-9]\{1,2\}-[0-9]\{1,2\}' |head -n1)
429 | [[ -z "vKernel_udeb" ]] && vKernel_udeb="3.16.0-4"
430 | fi
431 | fi
432 |
433 | [[ "$setNet" == '1' ]] && {
434 | IPv4="$ipAddr";
435 | MASK="$ipMask";
436 | GATE="$ipGate";
437 | } || {
438 | DEFAULTNET="$(ip route show |grep -o 'default via [0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.*' |head -n1 |sed 's/proto.*\|onlink.*//g' |awk '{print $NF}')";
439 | [[ -n "$DEFAULTNET" ]] && IPSUB="$(ip addr |grep ''${DEFAULTNET}'' |grep 'global' |grep 'brd' |head -n1 |grep -o '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}/[0-9]\{1,2\}')";
440 | IPv4="$(echo -n "$IPSUB" |cut -d'/' -f1)";
441 | NETSUB="$(echo -n "$IPSUB" |grep -o '/[0-9]\{1,2\}')";
442 | GATE="$(ip route show |grep -o 'default via [0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}' |head -n1 |grep -o '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}')";
443 | [[ -n "$NETSUB" ]] && MASK="$(echo -n '128.0.0.0/1,192.0.0.0/2,224.0.0.0/3,240.0.0.0/4,248.0.0.0/5,252.0.0.0/6,254.0.0.0/7,255.0.0.0/8,255.128.0.0/9,255.192.0.0/10,255.224.0.0/11,255.240.0.0/12,255.248.0.0/13,255.252.0.0/14,255.254.0.0/15,255.255.0.0/16,255.255.128.0/17,255.255.192.0/18,255.255.224.0/19,255.255.240.0/20,255.255.248.0/21,255.255.252.0/22,255.255.254.0/23,255.255.255.0/24,255.255.255.128/25,255.255.255.192/26,255.255.255.224/27,255.255.255.240/28,255.255.255.248/29,255.255.255.252/30,255.255.255.254/31,255.255.255.255/32' |grep -o '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}'${NETSUB}'' |cut -d'/' -f1)";
444 | }
445 |
446 | [[ -n "$GATE" ]] && [[ -n "$MASK" ]] && [[ -n "$IPv4" ]] || {
447 | echo "Not found `ip command`, It will use `route command`."
448 | ipNum() {
449 | local IFS='.';
450 | read ip1 ip2 ip3 ip4 <<<"$1";
451 | echo $((ip1*(1<<24)+ip2*(1<<16)+ip3*(1<<8)+ip4));
452 | }
453 |
454 | SelectMax(){
455 | ii=0;
456 | for IPITEM in `route -n |awk -v OUT=$1 '{print $OUT}' |grep '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}'`
457 | do
458 | NumTMP="$(ipNum $IPITEM)";
459 | eval "arrayNum[$ii]='$NumTMP,$IPITEM'";
460 | ii=$[$ii+1];
461 | done
462 | echo ${arrayNum[@]} |sed 's/\s/\n/g' |sort -n -k 1 -t ',' |tail -n1 |cut -d',' -f2;
463 | }
464 |
465 | [[ -z $IPv4 ]] && IPv4="$(ifconfig |grep 'Bcast' |head -n1 |grep -o '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}' |head -n1)";
466 | [[ -z $GATE ]] && GATE="$(SelectMax 2)";
467 | [[ -z $MASK ]] && MASK="$(SelectMax 3)";
468 |
469 | [[ -n "$GATE" ]] && [[ -n "$MASK" ]] && [[ -n "$IPv4" ]] || {
470 | echo "Error! Not configure network. ";
471 | exit 1;
472 | }
473 | }
474 |
475 | [[ "$setNet" != '1' ]] && [[ -f '/etc/network/interfaces' ]] && {
476 | [[ -z "$(sed -n '/iface.*inet static/p' /etc/network/interfaces)" ]] && AutoNet='1' || AutoNet='0';
477 | [[ -d /etc/network/interfaces.d ]] && {
478 | ICFGN="$(find /etc/network/interfaces.d -name '*.cfg' |wc -l)" || ICFGN='0';
479 | [[ "$ICFGN" -ne '0' ]] && {
480 | for NetCFG in `ls -1 /etc/network/interfaces.d/*.cfg`
481 | do
482 | [[ -z "$(cat $NetCFG | sed -n '/iface.*inet static/p')" ]] && AutoNet='1' || AutoNet='0';
483 | [[ "$AutoNet" -eq '0' ]] && break;
484 | done
485 | }
486 | }
487 | }
488 |
489 | [[ "$setNet" != '1' ]] && [[ -d '/etc/sysconfig/network-scripts' ]] && {
490 | ICFGN="$(find /etc/sysconfig/network-scripts -name 'ifcfg-*' |grep -v 'lo'|wc -l)" || ICFGN='0';
491 | [[ "$ICFGN" -ne '0' ]] && {
492 | for NetCFG in `ls -1 /etc/sysconfig/network-scripts/ifcfg-* |grep -v 'lo$' |grep -v ':[0-9]\{1,\}'`
493 | do
494 | [[ -n "$(cat $NetCFG | sed -n '/BOOTPROTO.*[dD][hH][cC][pP]/p')" ]] && AutoNet='1' || {
495 | AutoNet='0' && . $NetCFG;
496 | [[ -n $NETMASK ]] && MASK="$NETMASK";
497 | [[ -n $GATEWAY ]] && GATE="$GATEWAY";
498 | }
499 | [[ "$AutoNet" -eq '0' ]] && break;
500 | done
501 | }
502 | }
503 |
504 | if [[ "$loaderMode" == "0" ]]; then
505 | [[ ! -f $GRUBDIR/$GRUBFILE ]] && echo "Error! Not Found $GRUBFILE. " && exit 1;
506 |
507 | [[ ! -f $GRUBDIR/$GRUBFILE.old ]] && [[ -f $GRUBDIR/$GRUBFILE.bak ]] && mv -f $GRUBDIR/$GRUBFILE.bak $GRUBDIR/$GRUBFILE.old;
508 | mv -f $GRUBDIR/$GRUBFILE $GRUBDIR/$GRUBFILE.bak;
509 | [[ -f $GRUBDIR/$GRUBFILE.old ]] && cat $GRUBDIR/$GRUBFILE.old >$GRUBDIR/$GRUBFILE || cat $GRUBDIR/$GRUBFILE.bak >$GRUBDIR/$GRUBFILE;
510 | else
511 | GRUBOLD='2'
512 | fi
513 |
514 | [[ "$GRUBOLD" == '0' ]] && {
515 | READGRUB='/tmp/grub.read'
516 | cat $GRUBDIR/$GRUBFILE |sed -n '1h;1!H;$g;s/\n/%%%%%%%/g;$p' |grep -om 1 'menuentry\ [^{]*{[^}]*}%%%%%%%' |sed 's/%%%%%%%/\n/g' >$READGRUB
517 | LoadNum="$(cat $READGRUB |grep -c 'menuentry ')"
518 | if [[ "$LoadNum" -eq '1' ]]; then
519 | cat $READGRUB |sed '/^$/d' >/tmp/grub.new;
520 | elif [[ "$LoadNum" -gt '1' ]]; then
521 | CFG0="$(awk '/menuentry /{print NR}' $READGRUB|head -n 1)";
522 | CFG2="$(awk '/menuentry /{print NR}' $READGRUB|head -n 2 |tail -n 1)";
523 | CFG1="";
524 | for tmpCFG in `awk '/}/{print NR}' $READGRUB`
525 | do
526 | [ "$tmpCFG" -gt "$CFG0" -a "$tmpCFG" -lt "$CFG2" ] && CFG1="$tmpCFG";
527 | done
528 | [[ -z "$CFG1" ]] && {
529 | echo "Error! read $GRUBFILE. ";
530 | exit 1;
531 | }
532 |
533 | sed -n "$CFG0,$CFG1"p $READGRUB >/tmp/grub.new;
534 | [[ -f /tmp/grub.new ]] && [[ "$(grep -c '{' /tmp/grub.new)" -eq "$(grep -c '}' /tmp/grub.new)" ]] || {
535 | echo -ne "\033[31mError! \033[0mNot configure $GRUBFILE. \n";
536 | exit 1;
537 | }
538 | fi
539 | [ ! -f /tmp/grub.new ] && echo "Error! $GRUBFILE. " && exit 1;
540 | sed -i "/menuentry.*/c\menuentry\ \'Install OS \[$DIST\ $VER\]\'\ --class debian\ --class\ gnu-linux\ --class\ gnu\ --class\ os\ \{" /tmp/grub.new
541 | sed -i "/echo.*Loading/d" /tmp/grub.new;
542 | INSERTGRUB="$(awk '/menuentry /{print NR}' $GRUBDIR/$GRUBFILE|head -n 1)"
543 | }
544 |
545 | [[ "$GRUBOLD" == '1' ]] && {
546 | CFG0="$(awk '/title[\ ]|title[\t]/{print NR}' $GRUBDIR/$GRUBFILE|head -n 1)";
547 | CFG1="$(awk '/title[\ ]|title[\t]/{print NR}' $GRUBDIR/$GRUBFILE|head -n 2 |tail -n 1)";
548 | [[ -n $CFG0 ]] && [ -z $CFG1 -o $CFG1 == $CFG0 ] && sed -n "$CFG0,$"p $GRUBDIR/$GRUBFILE >/tmp/grub.new;
549 | [[ -n $CFG0 ]] && [ -z $CFG1 -o $CFG1 != $CFG0 ] && sed -n "$CFG0,$[$CFG1-1]"p $GRUBDIR/$GRUBFILE >/tmp/grub.new;
550 | [[ ! -f /tmp/grub.new ]] && echo "Error! configure append $GRUBFILE. " && exit 1;
551 | sed -i "/title.*/c\title\ \'Install OS \[$DIST\ $VER\]\'" /tmp/grub.new;
552 | sed -i '/^#/d' /tmp/grub.new;
553 | INSERTGRUB="$(awk '/title[\ ]|title[\t]/{print NR}' $GRUBDIR/$GRUBFILE|head -n 1)"
554 | }
555 |
556 | if [[ "$loaderMode" == "0" ]]; then
557 | [[ -n "$(grep 'linux.*/\|kernel.*/' /tmp/grub.new |awk '{print $2}' |tail -n 1 |grep '^/boot/')" ]] && Type='InBoot' || Type='NoBoot';
558 |
559 | LinuxKernel="$(grep 'linux.*/\|kernel.*/' /tmp/grub.new |awk '{print $1}' |head -n 1)";
560 | [[ -z "$LinuxKernel" ]] && echo "Error! read grub config! " && exit 1;
561 | LinuxIMG="$(grep 'initrd.*/' /tmp/grub.new |awk '{print $1}' |tail -n 1)";
562 | [ -z "$LinuxIMG" ] && sed -i "/$LinuxKernel.*\//a\\\tinitrd\ \/" /tmp/grub.new && LinuxIMG='initrd';
563 |
564 | if [[ "$linuxdists" == 'debian' ]] || [[ "$linuxdists" == 'ubuntu' ]]; then
565 | BOOT_OPTION="auto=true hostname=$linuxdists domain= -- quiet"
566 | elif [[ "$linuxdists" == 'centos' ]]; then
567 | BOOT_OPTION="ks=file://ks.cfg ksdevice=$IFETH"
568 | fi
569 |
570 | [[ "$Type" == 'InBoot' ]] && {
571 | sed -i "/$LinuxKernel.*\//c\\\t$LinuxKernel\\t\/boot\/vmlinuz $BOOT_OPTION" /tmp/grub.new;
572 | sed -i "/$LinuxIMG.*\//c\\\t$LinuxIMG\\t\/boot\/initrd.img" /tmp/grub.new;
573 | }
574 |
575 | [[ "$Type" == 'NoBoot' ]] && {
576 | sed -i "/$LinuxKernel.*\//c\\\t$LinuxKernel\\t\/vmlinuz $BOOT_OPTION" /tmp/grub.new;
577 | sed -i "/$LinuxIMG.*\//c\\\t$LinuxIMG\\t\/initrd.img" /tmp/grub.new;
578 | }
579 |
580 | sed -i '$a\\n' /tmp/grub.new;
581 | fi
582 |
583 | [[ "$inVNC" == 'n' ]] && {
584 | GRUBPATCH='0';
585 |
586 | if [[ "$loaderMode" == "0" ]]; then
587 | [ -f '/etc/network/interfaces' -o -d '/etc/sysconfig/network-scripts' ] || {
588 | echo "Error, Not found interfaces config.";
589 | exit 1;
590 | }
591 |
592 | sed -i ''${INSERTGRUB}'i\\n' $GRUBDIR/$GRUBFILE;
593 | sed -i ''${INSERTGRUB}'r /tmp/grub.new' $GRUBDIR/$GRUBFILE;
594 | [[ -f $GRUBDIR/grubenv ]] && sed -i 's/saved_entry/#saved_entry/g' $GRUBDIR/grubenv;
595 | fi
596 |
597 | [[ -d /tmp/boot ]] && rm -rf /tmp/boot;
598 | mkdir -p /tmp/boot;
599 | cd /tmp/boot;
600 | if [[ "$linuxdists" == 'debian' ]] || [[ "$linuxdists" == 'ubuntu' ]]; then
601 | COMPTYPE="gzip";
602 | elif [[ "$linuxdists" == 'centos' ]]; then
603 | COMPTYPE="$(file /boot/initrd.img |grep -o ':.*compressed data' |cut -d' ' -f2 |sed -r 's/(.*)/\L\1/' |head -n1)"
604 | [[ -z "$COMPTYPE" ]] && echo "Detect compressed type fail." && exit 1;
605 | fi
606 | CompDected='0'
607 | for ListCOMP in `echo -en 'gzip\nlzma\nxz'`
608 | do
609 | if [[ "$COMPTYPE" == "$ListCOMP" ]]; then
610 | CompDected='1'
611 | if [[ "$COMPTYPE" == 'gzip' ]]; then
612 | NewIMG="initrd.img.gz"
613 | else
614 | NewIMG="initrd.img.$COMPTYPE"
615 | fi
616 | mv -f "/boot/initrd.img" "/tmp/$NewIMG"
617 | break;
618 | fi
619 | done
620 | [[ "$CompDected" != '1' ]] && echo "Detect compressed type not support." && exit 1;
621 | [[ "$COMPTYPE" == 'lzma' ]] && UNCOMP='xz --format=lzma --decompress';
622 | [[ "$COMPTYPE" == 'xz' ]] && UNCOMP='xz --decompress';
623 | [[ "$COMPTYPE" == 'gzip' ]] && UNCOMP='gzip -d';
624 |
625 | $UNCOMP < /tmp/$NewIMG | cpio --extract --verbose --make-directories --no-absolute-filenames >>/dev/null 2>&1
626 |
627 | if [[ "$linuxdists" == 'debian' ]] || [[ "$linuxdists" == 'ubuntu' ]]; then
628 | cat >/tmp/boot/preseed.cfg<>/dev/null 2>&1
733 | }
734 |
735 | [[ "$ddMode" == '1' ]] && {
736 | WinNoDHCP(){
737 | echo -ne "for\0040\0057f\0040\0042tokens\00753\0052\0042\0040\0045\0045i\0040in\0040\0050\0047netsh\0040interface\0040show\0040interface\0040\0136\0174more\0040\00533\0040\0136\0174findstr\0040\0057I\0040\0057R\0040\0042本地\0056\0052\0040以太\0056\0052\0040Local\0056\0052\0040Ethernet\0042\0047\0051\0040do\0040\0050set\0040EthName\0075\0045\0045j\0051\r\nnetsh\0040\0055c\0040interface\0040ip\0040set\0040address\0040name\0075\0042\0045EthName\0045\0042\0040source\0075static\0040address\0075$IPv4\0040mask\0075$MASK\0040gateway\0075$GATE\r\nnetsh\0040\0055c\0040interface\0040ip\0040add\0040dnsservers\0040name\0075\0042\0045EthName\0045\0042\0040address\00758\00568\00568\00568\0040index\00751\0040validate\0075no\r\n\r\n" >>'/tmp/boot/net.tmp';
738 | }
739 | WinRDP(){
740 | echo -ne "netsh\0040firewall\0040set\0040portopening\0040protocol\0075ALL\0040port\0075$WinRemote\0040name\0075RDP\0040mode\0075ENABLE\0040scope\0075ALL\0040profile\0075ALL\r\nnetsh\0040firewall\0040set\0040portopening\0040protocol\0075ALL\0040port\0075$WinRemote\0040name\0075RDP\0040mode\0075ENABLE\0040scope\0075ALL\0040profile\0075CURRENT\r\nreg\0040add\0040\0042HKLM\0134SYSTEM\0134CurrentControlSet\0134Control\0134Network\0134NewNetworkWindowOff\0042\0040\0057f\r\nreg\0040add\0040\0042HKLM\0134SYSTEM\0134CurrentControlSet\0134Control\0134Terminal\0040Server\0042\0040\0057v\0040fDenyTSConnections\0040\0057t\0040reg\0137dword\0040\0057d\00400\0040\0057f\r\nreg\0040add\0040\0042HKLM\0134SYSTEM\0134CurrentControlSet\0134Control\0134Terminal\0040Server\0134Wds\0134rdpwd\0134Tds\0134tcp\0042\0040\0057v\0040PortNumber\0040\0057t\0040reg\0137dword\0040\0057d\0040$WinRemote\0040\0057f\r\nreg\0040add\0040\0042HKLM\0134SYSTEM\0134CurrentControlSet\0134Control\0134Terminal\0040Server\0134WinStations\0134RDP\0055Tcp\0042\0040\0057v\0040PortNumber\0040\0057t\0040reg\0137dword\0040\0057d\0040$WinRemote\0040\0057f\r\nreg\0040add\0040\0042HKLM\0134SYSTEM\0134CurrentControlSet\0134Control\0134Terminal\0040Server\0134WinStations\0134RDP\0055Tcp\0042\0040\0057v\0040UserAuthentication\0040\0057t\0040reg\0137dword\0040\0057d\00400\0040\0057f\r\nFOR\0040\0057F\0040\0042tokens\00752\0040delims\0075\0072\0042\0040\0045\0045i\0040in\0040\0050\0047SC\0040QUERYEX\0040TermService\0040\0136\0174FINDSTR\0040\0057I\0040\0042PID\0042\0047\0051\0040do\0040TASKKILL\0040\0057F\0040\0057PID\0040\0045\0045i\r\nFOR\0040\0057F\0040\0042tokens\00752\0040delims\0075\0072\0042\0040\0045\0045i\0040in\0040\0050\0047SC\0040QUERYEX\0040UmRdpService\0040\0136\0174FINDSTR\0040\0057I\0040\0042PID\0042\0047\0051\0040do\0040TASKKILL\0040\0057F\0040\0057PID\0040\0045\0045i\r\nSC\0040START\0040TermService\r\n\r\n" >>'/tmp/boot/net.tmp';
741 | }
742 | echo -ne "\0100ECHO\0040OFF\r\n\r\ncd\0056\0076\0045WINDIR\0045\0134GetAdmin\r\nif\0040exist\0040\0045WINDIR\0045\0134GetAdmin\0040\0050del\0040\0057f\0040\0057q\0040\0042\0045WINDIR\0045\0134GetAdmin\0042\0051\0040else\0040\0050\r\necho\0040CreateObject\0136\0050\0042Shell\0056Application\0042\0136\0051\0056ShellExecute\0040\0042\0045\0176s0\0042\0054\0040\0042\0045\0052\0042\0054\0040\0042\0042\0054\0040\0042runas\0042\0054\00401\0040\0076\0076\0040\0042\0045temp\0045\0134Admin\0056vbs\0042\r\n\0042\0045temp\0045\0134Admin\0056vbs\0042\r\ndel\0040\0057f\0040\0057q\0040\0042\0045temp\0045\0134Admin\0056vbs\0042\r\nexit\0040\0057b\00402\0051\r\n\r\n" >'/tmp/boot/net.tmp';
743 | [[ "$setNet" == '1' ]] && WinNoDHCP;
744 | [[ "$setNet" == '0' ]] && [[ "$AutoNet" == '0' ]] && WinNoDHCP;
745 | [[ "$setRDP" == '1' ]] && [[ -n "$WinRemote" ]] && WinRDP
746 | echo -ne "ECHO\0040SELECT\0040VOLUME\0075\0045\0045SystemDrive\0045\0045\0040\0076\0040\0042\0045SystemDrive\0045\0134diskpart\0056extend\0042\r\nECHO\0040EXTEND\0040\0076\0076\0040\0042\0045SystemDrive\0045\0134diskpart\0056extend\0042\r\nSTART\0040/WAIT\0040DISKPART\0040\0057S\0040\0042\0045SystemDrive\0045\0134diskpart\0056extend\0042\r\nDEL\0040\0057f\0040\0057q\0040\0042\0045SystemDrive\0045\0134diskpart\0056extend\0042\r\n\r\n" >>'/tmp/boot/net.tmp';
747 | echo -ne "cd\0040\0057d\0040\0042\0045ProgramData\0045\0057Microsoft\0057Windows\0057Start\0040Menu\0057Programs\0057Startup\0042\r\ndel\0040\0057f\0040\0057q\0040net\0056bat\r\n\r\n\r\n" >>'/tmp/boot/net.tmp';
748 | iconv -f 'UTF-8' -t 'GBK' '/tmp/boot/net.tmp' -o '/tmp/boot/net.bat'
749 | rm -rf '/tmp/boot/net.tmp'
750 | echo "$DDURL" |grep -q '^https://'
751 | [[ $? -eq '0' ]] && {
752 | echo -ne '\nAdd ssl support...\n'
753 | [[ -n $SSL_SUPPORT ]] && {
754 | wget --no-check-certificate -qO- "$SSL_SUPPORT" |tar -x
755 | [[ ! -f /tmp/boot/usr/bin/wget ]] && echo 'Error! SSL_SUPPORT.' && exit 1;
756 | sed -i 's/wget\ -qO-/\/usr\/bin\/wget\ --no-check-certificate\ --retry-connrefused\ --tries=7\ --continue\ -qO-/g' /tmp/boot/preseed.cfg
757 | [[ $? -eq '0' ]] && echo -ne 'Success! \n\n'
758 | } || {
759 | echo -ne 'Not ssl support package! \n\n';
760 | exit 1;
761 | }
762 | }
763 | }
764 |
765 | [[ "$ddMode" == '0' ]] && {
766 | sed -i '/anna-install/d' /tmp/boot/preseed.cfg
767 | sed -i 's/wget.*\/sbin\/reboot\;\ //g' /tmp/boot/preseed.cfg
768 | }
769 |
770 | elif [[ "$linuxdists" == 'centos' ]]; then
771 | cat >/tmp/boot/ks.cfg< /boot/initrd.img;
821 | rm -rf /tmp/boot;
822 | }
823 |
824 | [[ "$inVNC" == 'y' ]] && {
825 | sed -i '$i\\n' $GRUBDIR/$GRUBFILE
826 | sed -i '$r /tmp/grub.new' $GRUBDIR/$GRUBFILE
827 | echo -e "\n\033[33m\033[04mIt will reboot! \nPlease look at VNC! \nSelect\033[0m\033[32m Install OS [$DIST $VER] \033[33m\033[4mto install system.\033[04m\n\n\033[31m\033[04mThere is some information for you.\nDO NOT CLOSE THE WINDOW! \033[0m\n"
828 | echo -e "\033[35mIPv4\t\tNETMASK\t\tGATEWAY\033[0m"
829 | echo -e "\033[36m\033[04m$IPv4\033[0m\t\033[36m\033[04m$MASK\033[0m\t\033[36m\033[04m$GATE\033[0m\n\n"
830 |
831 | read -n 1 -p "Press Enter to reboot..." INP
832 | [[ "$INP" != '' ]] && echo -ne '\b \n\n';
833 | }
834 |
835 | chown root:root $GRUBDIR/$GRUBFILE
836 | chmod 444 $GRUBDIR/$GRUBFILE
837 |
838 | if [[ "$loaderMode" == "0" ]]; then
839 | sleep 3 && reboot >/dev/null 2>&1
840 | else
841 | rm -rf "$HOME/loader"
842 | mkdir -p "$HOME/loader"
843 | cp -rf "/boot/initrd.img" "$HOME/loader/initrd.img"
844 | cp -rf "/boot/vmlinuz" "$HOME/loader/vmlinuz"
845 | [[ -f "/boot/initrd.img" ]] && rm -rf "/boot/initrd.img"
846 | [[ -f "/boot/vmlinuz" ]] && rm -rf "/boot/vmlinuz"
847 | echo && ls -AR1 "$HOME/loader"
848 | fi
--------------------------------------------------------------------------------
/install.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | ## License: GPL
4 | ## It can reinstall Debian, Ubuntu, CentOS system with network.
5 | ## Default root password: MoeClub.org
6 | ## Blog: https://moeclub.org
7 | ## Written By MoeClub.org
8 |
9 |
10 | export tmpVER=''
11 | export tmpDIST=''
12 | export tmpURL=''
13 | export tmpWORD=''
14 | export tmpMirror=''
15 | export tmpSSL=''
16 | export tmpINS=''
17 | export ipAddr=''
18 | export ipMask=''
19 | export ipGate=''
20 | export Relese=''
21 | export ddMode='0'
22 | export setNet='0'
23 | export setRDP='0'
24 | export setIPv6='0'
25 | export isMirror='0'
26 | export FindDists='0'
27 | export loaderMode='0'
28 | export SpikCheckDIST='0'
29 | export setInterfaceName='0'
30 | export UNKNOWHW='0'
31 | export UNVER='6.4'
32 |
33 | while [[ $# -ge 1 ]]; do
34 | case $1 in
35 | -v|--ver)
36 | shift
37 | tmpVER="$1"
38 | shift
39 | ;;
40 | -d|--debian)
41 | shift
42 | Relese='Debian'
43 | tmpDIST="$1"
44 | shift
45 | ;;
46 | -u|--ubuntu)
47 | shift
48 | Relese='Ubuntu'
49 | tmpDIST="$1"
50 | shift
51 | ;;
52 | -c|--centos)
53 | shift
54 | Relese='CentOS'
55 | tmpDIST="$1"
56 | shift
57 | ;;
58 | -dd|--image)
59 | shift
60 | ddMode='1'
61 | tmpURL="$1"
62 | shift
63 | ;;
64 | -p|--password)
65 | shift
66 | tmpWORD="$1"
67 | shift
68 | ;;
69 | -i|--interface)
70 | shift
71 | interface="$1"
72 | shift
73 | ;;
74 | --ip-addr)
75 | shift
76 | ipAddr="$1"
77 | shift
78 | ;;
79 | --ip-mask)
80 | shift
81 | ipMask="$1"
82 | shift
83 | ;;
84 | --ip-gate)
85 | shift
86 | ipGate="$1"
87 | shift
88 | ;;
89 | --dev-net)
90 | shift
91 | setInterfaceName='1'
92 | ;;
93 | --loader)
94 | shift
95 | loaderMode='1'
96 | ;;
97 | --prefer)
98 | shift
99 | tmpPrefer="$1"
100 | shift
101 | ;;
102 | -a|--auto)
103 | shift
104 | tmpINS='auto'
105 | ;;
106 | -m|--manual)
107 | shift
108 | tmpINS='manual'
109 | ;;
110 | -apt|-yum|--mirror)
111 | shift
112 | isMirror='1'
113 | tmpMirror="$1"
114 | shift
115 | ;;
116 | -rdp)
117 | shift
118 | setRDP='1'
119 | WinRemote="$1"
120 | shift
121 | ;;
122 | -ssl)
123 | shift
124 | tmpSSL="$1"
125 | shift
126 | ;;
127 | --ipv6)
128 | shift
129 | setIPv6='1'
130 | ;;
131 | *)
132 | if [[ "$1" != 'error' ]]; then echo -ne "\nInvaild option: '$1'\n\n"; fi
133 | echo -ne " Usage:\n\tbash $(basename $0)\t-d/--debian [\033[33m\033[04mdists-name\033[0m]\n\t\t\t\t-u/--ubuntu [\033[04mdists-name\033[0m]\n\t\t\t\t-c/--centos [\033[33m\033[04mdists-verison\033[0m]\n\t\t\t\t-v/--ver [32/\033[33m\033[04mi386\033[0m|64/amd64]\n\t\t\t\t--ip-addr/--ip-gate/--ip-mask\n\t\t\t\t-apt/-yum/--mirror\n\t\t\t\t-dd/--image\n\t\t\t\t-a/--auto\n\t\t\t\t-m/--manual\n"
134 | exit 1;
135 | ;;
136 | esac
137 | done
138 |
139 | [[ "$EUID" -ne '0' ]] && echo "Error:This script must be run as root!" && exit 1;
140 |
141 | function CheckDependence(){
142 | FullDependence='0';
143 | for BIN_DEP in `echo "$1" |sed 's/,/\n/g'`
144 | do
145 | if [[ -n "$BIN_DEP" ]]; then
146 | Founded='0';
147 | for BIN_PATH in `echo "$PATH" |sed 's/:/\n/g'`
148 | do
149 | ls $BIN_PATH/$BIN_DEP >/dev/null 2>&1;
150 | if [ $? == '0' ]; then
151 | Founded='1';
152 | break;
153 | fi
154 | done
155 | if [ "$Founded" == '1' ]; then
156 | echo -en "[\033[32mok\033[0m]\t";
157 | else
158 | FullDependence='1';
159 | echo -en "[\033[31mNot Install\033[0m]";
160 | fi
161 | echo -en "\t$BIN_DEP\n";
162 | fi
163 | done
164 | if [ "$FullDependence" == '1' ]; then
165 | echo -ne "\n\033[31mError! \033[0mPlease use '\033[33mapt-get\033[0m' or '\033[33myum\033[0m' install it.\n\n\n"
166 | exit 1;
167 | fi
168 | }
169 |
170 | function SelectMirror(){
171 | [ $# -ge 3 ] || exit 1
172 | Relese="$1"
173 | DIST=$(echo "$2" |sed 's/\ //g' |sed -r 's/(.*)/\L\1/')
174 | VER=$(echo "$3" |sed 's/\ //g' |sed -r 's/(.*)/\L\1/')
175 | New=$(echo "$4" |sed 's/\ //g')
176 | [ -n "$Relese" ] || exit 1
177 | [ -n "$DIST" ] || exit 1
178 | [ -n "$VER" ] || exit 1
179 | relese=$(echo $Relese |sed -r 's/(.*)/\L\1/')
180 | if [ "$Relese" == "Debian" ] || [ "$Relese" == "Ubuntu" ]; then
181 | inUpdate=''; [ "$Relese" == "Ubuntu" ] && inUpdate='-updates'
182 | MirrorTEMP="SUB_MIRROR/dists/${DIST}${inUpdate}/main/installer-${VER}/current/images/netboot/${relese}-installer/${VER}/initrd.gz"
183 | elif [ "$Relese" == "CentOS" ]; then
184 | MirrorTEMP="SUB_MIRROR/${DIST}/os/${VER}/isolinux/initrd.img"
185 | fi
186 | [ -n "$MirrorTEMP" ] || exit 1
187 | MirrorStatus=0
188 | declare -A MirrorBackup
189 | MirrorBackup=(["Debian0"]="" ["Debian1"]="http://deb.debian.org/debian" ["Debian2"]="http://archive.debian.org/debian" ["Ubuntu0"]="" ["Ubuntu1"]="http://archive.ubuntu.com/ubuntu" ["CentOS0"]="" ["CentOS1"]="http://mirror.centos.org/centos" ["CentOS2"]="http://vault.centos.org")
190 | echo "$New" |grep -q '^http://\|^https://\|^ftp://' && MirrorBackup[${Relese}0]="$New"
191 | for mirror in $(echo "${!MirrorBackup[@]}" |sed 's/\ /\n/g' |sort -n |grep "^$Relese")
192 | do
193 | CurMirror="${MirrorBackup[$mirror]}"
194 | [ -n "$CurMirror" ] || continue
195 | MirrorURL=`echo "$MirrorTEMP" |sed "s#SUB_MIRROR#${CurMirror}#g"`
196 | wget --no-check-certificate --spider --timeout=3 -o /dev/null "$MirrorURL"
197 | [ $? -eq 0 ] && MirrorStatus=1 && break
198 | done
199 | [ $MirrorStatus -eq 1 ] && echo "$CurMirror" || exit 1
200 | }
201 |
202 | [ -n "$Relese" ] || Relese='Debian'
203 | linux_relese=$(echo "$Relese" |sed 's/\ //g' |sed -r 's/(.*)/\L\1/')
204 | clear && echo -e "\n\033[36m# Check Dependence\033[0m\n"
205 |
206 | if [[ "$ddMode" == '1' ]]; then
207 | CheckDependence iconv;
208 | linux_relese='debian';
209 | tmpDIST='jessie';
210 | tmpVER='amd64';
211 | tmpINS='auto';
212 | fi
213 |
214 | if [[ "$Relese" == 'Debian' ]] || [[ "$Relese" == 'Ubuntu' ]]; then
215 | CheckDependence wget,awk,grep,sed,cut,cat,cpio,gzip,find,dirname,basename;
216 | elif [[ "$Relese" == 'CentOS' ]]; then
217 | CheckDependence wget,awk,grep,sed,cut,cat,cpio,gzip,find,dirname,basename,file,xz;
218 | fi
219 | [ -n "$tmpWORD" ] && CheckDependence openssl
220 |
221 | if [[ "$loaderMode" == "0" ]]; then
222 | [[ -f '/boot/grub/grub.cfg' ]] && GRUBVER='0' && GRUBDIR='/boot/grub' && GRUBFILE='grub.cfg';
223 | [[ -z "$GRUBDIR" ]] && [[ -f '/boot/grub2/grub.cfg' ]] && GRUBVER='0' && GRUBDIR='/boot/grub2' && GRUBFILE='grub.cfg';
224 | [[ -z "$GRUBDIR" ]] && [[ -f '/boot/grub/grub.conf' ]] && GRUBVER='1' && GRUBDIR='/boot/grub' && GRUBFILE='grub.conf';
225 | [ -z "$GRUBDIR" -o -z "$GRUBFILE" ] && echo -ne "Error! \nNot Found grub.\n" && exit 1;
226 | else
227 | tmpINS='auto'
228 | fi
229 |
230 | if [[ -n "$tmpVER" ]]; then
231 | tmpVER="$(echo "$tmpVER" |sed -r 's/(.*)/\L\1/')";
232 | if [[ "$tmpVER" == '32' ]] || [[ "$tmpVER" == 'i386' ]] || [[ "$tmpVER" == 'x86' ]]; then
233 | VER='i386';
234 | fi
235 | if [[ "$tmpVER" == '64' ]] || [[ "$tmpVER" == 'amd64' ]] || [[ "$tmpVER" == 'x86_64' ]] || [[ "$tmpVER" == 'x64' ]]; then
236 | if [[ "$Relese" == 'Debian' ]] || [[ "$Relese" == 'Ubuntu' ]]; then
237 | VER='amd64';
238 | elif [[ "$Relese" == 'CentOS' ]]; then
239 | VER='x86_64';
240 | fi
241 | fi
242 | fi
243 | [ -z "$VER" ] && VER='amd64'
244 |
245 | if [[ -z "$tmpDIST" ]]; then
246 | [ "$Relese" == 'Debian' ] && tmpDIST='jessie' && DIST='jessie';
247 | [ "$Relese" == 'Ubuntu' ] && tmpDIST='bionic' && DIST='bionic';
248 | [ "$Relese" == 'CentOS' ] && tmpDIST='6.10' && DIST='6.10';
249 | fi
250 |
251 | if [[ -z "$DIST" ]]; then
252 | if [[ "$Relese" == 'Debian' ]]; then
253 | SpikCheckDIST='0'
254 | DIST="$(echo "$tmpDIST" |sed -r 's/(.*)/\L\1/')";
255 | echo "$DIST" |grep -q '[0-9]';
256 | [[ $? -eq '0' ]] && {
257 | isDigital="$(echo "$DIST" |grep -o '[\.0-9]\{1,\}' |sed -n '1h;1!H;$g;s/\n//g;$p' |cut -d'.' -f1)";
258 | [[ -n $isDigital ]] && {
259 | [[ "$isDigital" == '7' ]] && DIST='wheezy';
260 | [[ "$isDigital" == '8' ]] && DIST='jessie';
261 | [[ "$isDigital" == '9' ]] && DIST='stretch';
262 | [[ "$isDigital" == '10' ]] && DIST='buster';
263 | }
264 | }
265 | LinuxMirror=$(SelectMirror "$Relese" "$DIST" "$VER" "$tmpMirror")
266 | fi
267 | if [[ "$Relese" == 'Ubuntu' ]]; then
268 | SpikCheckDIST='0'
269 | DIST="$(echo "$tmpDIST" |sed -r 's/(.*)/\L\1/')";
270 | echo "$DIST" |grep -q '[0-9]';
271 | [[ $? -eq '0' ]] && {
272 | isDigital="$(echo "$DIST" |grep -o '[\.0-9]\{1,\}' |sed -n '1h;1!H;$g;s/\n//g;$p')";
273 | [[ -n $isDigital ]] && {
274 | [[ "$isDigital" == '12.04' ]] && DIST='precise';
275 | [[ "$isDigital" == '14.04' ]] && DIST='trusty';
276 | [[ "$isDigital" == '16.04' ]] && DIST='xenial';
277 | [[ "$isDigital" == '18.04' ]] && DIST='bionic';
278 | }
279 | }
280 | LinuxMirror=$(SelectMirror "$Relese" "$DIST" "$VER" "$tmpMirror")
281 | fi
282 | if [[ "$Relese" == 'CentOS' ]]; then
283 | SpikCheckDIST='1'
284 | DISTCheck="$(echo "$tmpDIST" |grep -o '[\.0-9]\{1,\}')";
285 | LinuxMirror=$(SelectMirror "$Relese" "$DISTCheck" "$VER" "$tmpMirror")
286 | ListDIST="$(wget --no-check-certificate -qO- "$LinuxMirror/dir_sizes" |cut -f2 |grep '^[0-9]')"
287 | DIST="$(echo "$ListDIST" |grep "^$DISTCheck" |head -n1)"
288 | [[ -z "$DIST" ]] && {
289 | echo -ne '\nThe dists version not found in this mirror, Please check it! \n\n'
290 | bash $0 error;
291 | exit 1;
292 | }
293 | wget --no-check-certificate -qO- "$LinuxMirror/$DIST/os/$VER/.treeinfo" |grep -q 'general';
294 | [[ $? != '0' ]] && {
295 | echo -ne "\nThe version not found in this mirror, Please change mirror try again! \n\n";
296 | exit 1;
297 | }
298 | fi
299 | fi
300 |
301 | if [[ -z "$LinuxMirror" ]]; then
302 | echo -ne "\033[31mError! \033[0mInvaild mirror! \n"
303 | [ "$Relese" == 'Debian' ] && echo -en "\033[33mexample:\033[0m http://deb.debian.org/debian\n\n";
304 | [ "$Relese" == 'Ubuntu' ] && echo -en "\033[33mexample:\033[0m http://archive.ubuntu.com/ubuntu\n\n";
305 | [ "$Relese" == 'CentOS' ] && echo -en "\033[33mexample:\033[0m http://mirror.centos.org/centos\n\n";
306 | bash $0 error;
307 | exit 1;
308 | fi
309 |
310 | if [[ "$SpikCheckDIST" == '0' ]]; then
311 | DistsList="$(wget --no-check-certificate -qO- "$LinuxMirror/dists/" |grep -o 'href=.*/"' |cut -d'"' -f2 |sed '/-\|old\|Debian\|experimental\|stable\|test\|sid\|devel/d' |grep '^[^/]' |sed -n '1h;1!H;$g;s/\n//g;s/\//\;/g;$p')";
312 | for CheckDEB in `echo "$DistsList" |sed 's/;/\n/g'`
313 | do
314 | [[ "$CheckDEB" == "$DIST" ]] && FindDists='1' && break;
315 | done
316 | [[ "$FindDists" == '0' ]] && {
317 | echo -ne '\nThe dists version not found, Please check it! \n\n'
318 | bash $0 error;
319 | exit 1;
320 | }
321 | fi
322 |
323 | [[ "$ddMode" == '1' ]] && {
324 | export SSL_SUPPORT='https://moeclub.org/get/wget_udeb_amd64';
325 | if [[ -n "$tmpURL" ]]; then
326 | DDURL="$tmpURL"
327 | echo "$DDURL" |grep -q '^http://\|^ftp://\|^https://';
328 | [[ $? -ne '0' ]] && echo 'Please input vaild URL,Only support http://, ftp:// and https:// !' && exit 1;
329 | [[ -n "$tmpSSL" ]] && SSL_SUPPORT="$tmpSSL";
330 | else
331 | echo 'Please input vaild image URL! ';
332 | exit 1;
333 | fi
334 | }
335 |
336 | [[ -n "$tmpINS" ]] && {
337 | [[ "$tmpINS" == 'auto' ]] && inVNC='n';
338 | [[ "$tmpINS" == 'manual' ]] && inVNC='y';
339 | }
340 |
341 | [ -n "$ipAddr" ] && [ -n "$ipMask" ] && [ -n "$ipGate" ] && setNet='1';
342 | [[ -n "$tmpWORD" ]] && myPASSWORD="$(openssl passwd -1 "$tmpWORD")";
343 | [[ -z "$myPASSWORD" ]] && myPASSWORD='$1$4BJZaD0A$y1QykUnJ6mXprENfwpseH0';
344 |
345 | if [[ -n "$interface" ]]; then
346 | IFETH="$interface"
347 | else
348 | if [[ "$linux_relese" == 'centos' ]]; then
349 | IFETH="link"
350 | else
351 | IFETH="auto"
352 | fi
353 | fi
354 |
355 | clear && echo -e "\n\033[36m# Install\033[0m\n"
356 |
357 | ASKVNC(){
358 | inVNC='y';
359 | [[ "$ddMode" == '0' ]] && {
360 | echo -ne "\033[34mDo you want to install os manually?\033[0m\e[33m[\e[32my\e[33m/n]\e[0m "
361 | read tmpinVNC
362 | [[ -n "$inVNCtmp" ]] && inVNC="$tmpinVNC"
363 | }
364 | [ "$inVNC" == 'y' -o "$inVNC" == 'Y' ] && inVNC='y';
365 | [ "$inVNC" == 'n' -o "$inVNC" == 'N' ] && inVNC='n';
366 | }
367 |
368 | [ "$inVNC" == 'y' -o "$inVNC" == 'n' ] || ASKVNC;
369 | [[ "$ddMode" == '0' ]] && {
370 | [[ "$inVNC" == 'y' ]] && echo -e "\033[34mManual Mode\033[0m insatll [\033[33m$Relese\033[0m] [\033[33m$DIST\033[0m] [\033[33m$VER\033[0m] in VNC. "
371 | [[ "$inVNC" == 'n' ]] && echo -e "\033[34mAuto Mode\033[0m insatll [\033[33m$Relese\033[0m] [\033[33m$DIST\033[0m] [\033[33m$VER\033[0m]. "
372 | }
373 | [[ "$ddMode" == '1' ]] && {
374 | echo -ne "\033[34mAuto Mode\033[0m insatll \033[33mWindows\033[0m\n[\033[33m$DDURL\033[0m]\n"
375 | }
376 |
377 | if [[ "$linux_relese" == 'centos' ]]; then
378 | if [[ "$DIST" != "$UNVER" ]]; then
379 | awk 'BEGIN{print '${UNVER}'-'${DIST}'}' |grep -q '^-'
380 | if [ $? != '0' ]; then
381 | UNKNOWHW='1';
382 | echo -en "\033[33mThe version lower then \033[31m$UNVER\033[33m may not support in auto mode! \033[0m\n";
383 | if [[ "$inVNC" == 'n' ]]; then
384 | echo -en "\033[35mYou can connect VNC with \033[32mPublic IP\033[35m and port \033[32m1\033[35m/\033[32m5901\033[35m in vnc viewer.\033[0m\n"
385 | read -n 1 -p "Press Enter to continue..." INP
386 | [[ "$INP" != '' ]] && echo -ne '\b \n\n';
387 | fi
388 | fi
389 | awk 'BEGIN{print '${UNVER}'-'${DIST}'+0.59}' |grep -q '^-'
390 | if [ $? == '0' ]; then
391 | echo -en "\n\033[31mThe version higher then \033[33m6.10 \033[31mis not support in current! \033[0m\n\n"
392 | exit 1;
393 | fi
394 | fi
395 | fi
396 |
397 | echo -e "\n[\033[33m$Relese\033[0m] [\033[33m$DIST\033[0m] [\033[33m$VER\033[0m] Downloading..."
398 |
399 | if [[ "$linux_relese" == 'debian' ]] || [[ "$linux_relese" == 'ubuntu' ]]; then
400 | inUpdate=''; [ "$linux_relese" == 'ubuntu' ] && inUpdate='-updates'
401 | wget --no-check-certificate -qO '/boot/initrd.img' "${LinuxMirror}/dists/${DIST}${inUpdate}/main/installer-${VER}/current/images/netboot/${linux_relese}-installer/${VER}/initrd.gz"
402 | [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'initrd.img' for \033[33m$linux_relese\033[0m failed! \n" && exit 1
403 | wget --no-check-certificate -qO '/boot/vmlinuz' "${LinuxMirror}/dists/${DIST}${inUpdate}/main/installer-${VER}/current/images/netboot/${linux_relese}-installer/${VER}/linux"
404 | [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'vmlinuz' for \033[33m$linux_relese\033[0m failed! \n" && exit 1
405 | MirrorHost="$(echo "$LinuxMirror" |awk -F'://|/' '{print $2}')";
406 | MirrorFolder="$(echo "$LinuxMirror" |awk -F''${MirrorHost}'' '{print $2}')";
407 | elif [[ "$linux_relese" == 'centos' ]]; then
408 | wget --no-check-certificate -qO '/boot/initrd.img' "${LinuxMirror}/${DIST}/os/${VER}/isolinux/initrd.img"
409 | [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'initrd.img' for \033[33m$linux_relese\033[0m failed! \n" && exit 1
410 | wget --no-check-certificate -qO '/boot/vmlinuz' "${LinuxMirror}/${DIST}/os/${VER}/isolinux/vmlinuz"
411 | [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'vmlinuz' for \033[33m$linux_relese\033[0m failed! \n" && exit 1
412 | else
413 | bash $0 error;
414 | exit 1;
415 | fi
416 | if [[ "$linux_relese" == 'debian' ]]; then
417 | wget --no-check-certificate -qO '/boot/firmware.cpio.gz' "http://cdimage.debian.org/cdimage/unofficial/non-free/firmware/${DIST}/current/firmware.cpio.gz"
418 | [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'firmware' for \033[33m$linux_relese\033[0m failed! \n" && exit 1
419 | if [[ "$ddMode" == '1' ]]; then
420 | vKernel_udeb=$(wget --no-check-certificate -qO- "http://$DISTMirror/dists/$DIST/main/installer-$VER/current/images/udeb.list" |grep '^acpi-modules' |head -n1 |grep -o '[0-9]\{1,2\}.[0-9]\{1,2\}.[0-9]\{1,2\}-[0-9]\{1,2\}' |head -n1)
421 | [[ -z "vKernel_udeb" ]] && vKernel_udeb="3.16.0-6"
422 | fi
423 | fi
424 |
425 | [[ "$setNet" == '1' ]] && {
426 | IPv4="$ipAddr";
427 | MASK="$ipMask";
428 | GATE="$ipGate";
429 | } || {
430 | DEFAULTNET="$(ip route show |grep -o 'default via [0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.*' |head -n1 |sed 's/proto.*\|onlink.*//g' |awk '{print $NF}')";
431 | [[ -n "$DEFAULTNET" ]] && IPSUB="$(ip addr |grep ''${DEFAULTNET}'' |grep 'global' |grep 'brd' |head -n1 |grep -o '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}/[0-9]\{1,2\}')";
432 | IPv4="$(echo -n "$IPSUB" |cut -d'/' -f1)";
433 | NETSUB="$(echo -n "$IPSUB" |grep -o '/[0-9]\{1,2\}')";
434 | GATE="$(ip route show |grep -o 'default via [0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}' |head -n1 |grep -o '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}')";
435 | [[ -n "$NETSUB" ]] && MASK="$(echo -n '128.0.0.0/1,192.0.0.0/2,224.0.0.0/3,240.0.0.0/4,248.0.0.0/5,252.0.0.0/6,254.0.0.0/7,255.0.0.0/8,255.128.0.0/9,255.192.0.0/10,255.224.0.0/11,255.240.0.0/12,255.248.0.0/13,255.252.0.0/14,255.254.0.0/15,255.255.0.0/16,255.255.128.0/17,255.255.192.0/18,255.255.224.0/19,255.255.240.0/20,255.255.248.0/21,255.255.252.0/22,255.255.254.0/23,255.255.255.0/24,255.255.255.128/25,255.255.255.192/26,255.255.255.224/27,255.255.255.240/28,255.255.255.248/29,255.255.255.252/30,255.255.255.254/31,255.255.255.255/32' |grep -o '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}'${NETSUB}'' |cut -d'/' -f1)";
436 | }
437 |
438 | [[ -n "$GATE" ]] && [[ -n "$MASK" ]] && [[ -n "$IPv4" ]] || {
439 | echo "Not found \`ip command\`, It will use \`route command\`."
440 | ipNum() {
441 | local IFS='.';
442 | read ip1 ip2 ip3 ip4 <<<"$1";
443 | echo $((ip1*(1<<24)+ip2*(1<<16)+ip3*(1<<8)+ip4));
444 | }
445 |
446 | SelectMax(){
447 | ii=0;
448 | for IPITEM in `route -n |awk -v OUT=$1 '{print $OUT}' |grep '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}'`
449 | do
450 | NumTMP="$(ipNum $IPITEM)";
451 | eval "arrayNum[$ii]='$NumTMP,$IPITEM'";
452 | ii=$[$ii+1];
453 | done
454 | echo ${arrayNum[@]} |sed 's/\s/\n/g' |sort -n -k 1 -t ',' |tail -n1 |cut -d',' -f2;
455 | }
456 |
457 | [[ -z $IPv4 ]] && IPv4="$(ifconfig |grep 'Bcast' |head -n1 |grep -o '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}' |head -n1)";
458 | [[ -z $GATE ]] && GATE="$(SelectMax 2)";
459 | [[ -z $MASK ]] && MASK="$(SelectMax 3)";
460 |
461 | [[ -n "$GATE" ]] && [[ -n "$MASK" ]] && [[ -n "$IPv4" ]] || {
462 | echo "Error! Not configure network. ";
463 | exit 1;
464 | }
465 | }
466 |
467 | [[ "$setNet" != '1' ]] && [[ -f '/etc/network/interfaces' ]] && {
468 | [[ -z "$(sed -n '/iface.*inet static/p' /etc/network/interfaces)" ]] && AutoNet='1' || AutoNet='0';
469 | [[ -d /etc/network/interfaces.d ]] && {
470 | ICFGN="$(find /etc/network/interfaces.d -name '*.cfg' |wc -l)" || ICFGN='0';
471 | [[ "$ICFGN" -ne '0' ]] && {
472 | for NetCFG in `ls -1 /etc/network/interfaces.d/*.cfg`
473 | do
474 | [[ -z "$(cat $NetCFG | sed -n '/iface.*inet static/p')" ]] && AutoNet='1' || AutoNet='0';
475 | [[ "$AutoNet" -eq '0' ]] && break;
476 | done
477 | }
478 | }
479 | }
480 |
481 | [[ "$setNet" != '1' ]] && [[ -d '/etc/sysconfig/network-scripts' ]] && {
482 | ICFGN="$(find /etc/sysconfig/network-scripts -name 'ifcfg-*' |grep -v 'lo'|wc -l)" || ICFGN='0';
483 | [[ "$ICFGN" -ne '0' ]] && {
484 | for NetCFG in `ls -1 /etc/sysconfig/network-scripts/ifcfg-* |grep -v 'lo$' |grep -v ':[0-9]\{1,\}'`
485 | do
486 | [[ -n "$(cat $NetCFG | sed -n '/BOOTPROTO.*[dD][hH][cC][pP]/p')" ]] && AutoNet='1' || {
487 | AutoNet='0' && . $NetCFG;
488 | [[ -n $NETMASK ]] && MASK="$NETMASK";
489 | [[ -n $GATEWAY ]] && GATE="$GATEWAY";
490 | }
491 | [[ "$AutoNet" -eq '0' ]] && break;
492 | done
493 | }
494 | }
495 |
496 | if [[ "$loaderMode" == "0" ]]; then
497 | [[ ! -f $GRUBDIR/$GRUBFILE ]] && echo "Error! Not Found $GRUBFILE. " && exit 1;
498 |
499 | [[ ! -f $GRUBDIR/$GRUBFILE.old ]] && [[ -f $GRUBDIR/$GRUBFILE.bak ]] && mv -f $GRUBDIR/$GRUBFILE.bak $GRUBDIR/$GRUBFILE.old;
500 | mv -f $GRUBDIR/$GRUBFILE $GRUBDIR/$GRUBFILE.bak;
501 | [[ -f $GRUBDIR/$GRUBFILE.old ]] && cat $GRUBDIR/$GRUBFILE.old >$GRUBDIR/$GRUBFILE || cat $GRUBDIR/$GRUBFILE.bak >$GRUBDIR/$GRUBFILE;
502 | else
503 | GRUBVER='2'
504 | fi
505 |
506 | [[ "$GRUBVER" == '0' ]] && {
507 | READGRUB='/tmp/grub.read'
508 | cat $GRUBDIR/$GRUBFILE |sed -n '1h;1!H;$g;s/\n/%%%%%%%/g;$p' |grep -om 1 'menuentry\ [^{]*{[^}]*}%%%%%%%' |sed 's/%%%%%%%/\n/g' >$READGRUB
509 | LoadNum="$(cat $READGRUB |grep -c 'menuentry ')"
510 | if [[ "$LoadNum" -eq '1' ]]; then
511 | cat $READGRUB |sed '/^$/d' >/tmp/grub.new;
512 | elif [[ "$LoadNum" -gt '1' ]]; then
513 | CFG0="$(awk '/menuentry /{print NR}' $READGRUB|head -n 1)";
514 | CFG2="$(awk '/menuentry /{print NR}' $READGRUB|head -n 2 |tail -n 1)";
515 | CFG1="";
516 | for tmpCFG in `awk '/}/{print NR}' $READGRUB`
517 | do
518 | [ "$tmpCFG" -gt "$CFG0" -a "$tmpCFG" -lt "$CFG2" ] && CFG1="$tmpCFG";
519 | done
520 | [[ -z "$CFG1" ]] && {
521 | echo "Error! read $GRUBFILE. ";
522 | exit 1;
523 | }
524 |
525 | sed -n "$CFG0,$CFG1"p $READGRUB >/tmp/grub.new;
526 | [[ -f /tmp/grub.new ]] && [[ "$(grep -c '{' /tmp/grub.new)" -eq "$(grep -c '}' /tmp/grub.new)" ]] || {
527 | echo -ne "\033[31mError! \033[0mNot configure $GRUBFILE. \n";
528 | exit 1;
529 | }
530 | fi
531 | [ ! -f /tmp/grub.new ] && echo "Error! $GRUBFILE. " && exit 1;
532 | sed -i "/menuentry.*/c\menuentry\ \'Install OS \[$DIST\ $VER\]\'\ --class debian\ --class\ gnu-linux\ --class\ gnu\ --class\ os\ \{" /tmp/grub.new
533 | sed -i "/echo.*Loading/d" /tmp/grub.new;
534 | INSERTGRUB="$(awk '/menuentry /{print NR}' $GRUBDIR/$GRUBFILE|head -n 1)"
535 | }
536 |
537 | [[ "$GRUBVER" == '1' ]] && {
538 | CFG0="$(awk '/title[\ ]|title[\t]/{print NR}' $GRUBDIR/$GRUBFILE|head -n 1)";
539 | CFG1="$(awk '/title[\ ]|title[\t]/{print NR}' $GRUBDIR/$GRUBFILE|head -n 2 |tail -n 1)";
540 | [[ -n $CFG0 ]] && [ -z $CFG1 -o $CFG1 == $CFG0 ] && sed -n "$CFG0,$"p $GRUBDIR/$GRUBFILE >/tmp/grub.new;
541 | [[ -n $CFG0 ]] && [ -z $CFG1 -o $CFG1 != $CFG0 ] && sed -n "$CFG0,$[$CFG1-1]"p $GRUBDIR/$GRUBFILE >/tmp/grub.new;
542 | [[ ! -f /tmp/grub.new ]] && echo "Error! configure append $GRUBFILE. " && exit 1;
543 | sed -i "/title.*/c\title\ \'Install OS \[$DIST\ $VER\]\'" /tmp/grub.new;
544 | sed -i '/^#/d' /tmp/grub.new;
545 | INSERTGRUB="$(awk '/title[\ ]|title[\t]/{print NR}' $GRUBDIR/$GRUBFILE|head -n 1)"
546 | }
547 |
548 | if [[ "$loaderMode" == "0" ]]; then
549 | [[ -n "$(grep 'linux.*/\|kernel.*/' /tmp/grub.new |awk '{print $2}' |tail -n 1 |grep '^/boot/')" ]] && Type='InBoot' || Type='NoBoot';
550 |
551 | LinuxKernel="$(grep 'linux.*/\|kernel.*/' /tmp/grub.new |awk '{print $1}' |head -n 1)";
552 | [[ -z "$LinuxKernel" ]] && echo "Error! read grub config! " && exit 1;
553 | LinuxIMG="$(grep 'initrd.*/' /tmp/grub.new |awk '{print $1}' |tail -n 1)";
554 | [ -z "$LinuxIMG" ] && sed -i "/$LinuxKernel.*\//a\\\tinitrd\ \/" /tmp/grub.new && LinuxIMG='initrd';
555 |
556 | if [[ "$setInterfaceName" == "1" ]]; then
557 | Add_OPTION="net.ifnames=0 biosdevname=0";
558 | else
559 | Add_OPTION="";
560 | fi
561 |
562 | if [[ "$setIPv6" == "1" ]]; then
563 | Add_OPTION="$Add_OPTION ipv6.disable=1";
564 | fi
565 |
566 | if [[ "$linux_relese" == 'debian' ]] || [[ "$linux_relese" == 'ubuntu' ]]; then
567 | BOOT_OPTION="auto=true $Add_OPTION hostname=$linux_relese domain= -- quiet"
568 | elif [[ "$linux_relese" == 'centos' ]]; then
569 | BOOT_OPTION="ks=file://ks.cfg $Add_OPTION ksdevice=$IFETH"
570 | fi
571 |
572 | [[ "$Type" == 'InBoot' ]] && {
573 | sed -i "/$LinuxKernel.*\//c\\\t$LinuxKernel\\t\/boot\/vmlinuz $BOOT_OPTION" /tmp/grub.new;
574 | sed -i "/$LinuxIMG.*\//c\\\t$LinuxIMG\\t\/boot\/initrd.img" /tmp/grub.new;
575 | }
576 |
577 | [[ "$Type" == 'NoBoot' ]] && {
578 | sed -i "/$LinuxKernel.*\//c\\\t$LinuxKernel\\t\/vmlinuz $BOOT_OPTION" /tmp/grub.new;
579 | sed -i "/$LinuxIMG.*\//c\\\t$LinuxIMG\\t\/initrd.img" /tmp/grub.new;
580 | }
581 |
582 | sed -i '$a\\n' /tmp/grub.new;
583 | fi
584 |
585 | [[ "$inVNC" == 'n' ]] && {
586 | GRUBPATCH='0';
587 |
588 | if [[ "$loaderMode" == "0" ]]; then
589 | [ -f '/etc/network/interfaces' -o -d '/etc/sysconfig/network-scripts' ] || {
590 | echo "Error, Not found interfaces config.";
591 | exit 1;
592 | }
593 |
594 | sed -i ''${INSERTGRUB}'i\\n' $GRUBDIR/$GRUBFILE;
595 | sed -i ''${INSERTGRUB}'r /tmp/grub.new' $GRUBDIR/$GRUBFILE;
596 | [[ -f $GRUBDIR/grubenv ]] && sed -i 's/saved_entry/#saved_entry/g' $GRUBDIR/grubenv;
597 | fi
598 |
599 | [[ -d /tmp/boot ]] && rm -rf /tmp/boot;
600 | mkdir -p /tmp/boot;
601 | cd /tmp/boot;
602 | if [[ "$linux_relese" == 'debian' ]] || [[ "$linux_relese" == 'ubuntu' ]]; then
603 | COMPTYPE="gzip";
604 | elif [[ "$linux_relese" == 'centos' ]]; then
605 | COMPTYPE="$(file /boot/initrd.img |grep -o ':.*compressed data' |cut -d' ' -f2 |sed -r 's/(.*)/\L\1/' |head -n1)"
606 | [[ -z "$COMPTYPE" ]] && echo "Detect compressed type fail." && exit 1;
607 | fi
608 | CompDected='0'
609 | for ListCOMP in `echo -en 'gzip\nlzma\nxz'`
610 | do
611 | if [[ "$COMPTYPE" == "$ListCOMP" ]]; then
612 | CompDected='1'
613 | if [[ "$COMPTYPE" == 'gzip' ]]; then
614 | NewIMG="initrd.img.gz"
615 | else
616 | NewIMG="initrd.img.$COMPTYPE"
617 | fi
618 | mv -f "/boot/initrd.img" "/tmp/$NewIMG"
619 | break;
620 | fi
621 | done
622 | [[ "$CompDected" != '1' ]] && echo "Detect compressed type not support." && exit 1;
623 | [[ "$COMPTYPE" == 'lzma' ]] && UNCOMP='xz --format=lzma --decompress';
624 | [[ "$COMPTYPE" == 'xz' ]] && UNCOMP='xz --decompress';
625 | [[ "$COMPTYPE" == 'gzip' ]] && UNCOMP='gzip -d';
626 |
627 | $UNCOMP < /tmp/$NewIMG | cpio --extract --verbose --make-directories --no-absolute-filenames >>/dev/null 2>&1
628 |
629 | echo $MirrorHost
630 |
631 | if [[ "$linux_relese" == 'debian' ]] || [[ "$linux_relese" == 'ubuntu' ]]; then
632 | cat >/tmp/boot/preseed.cfg<>/dev/null 2>&1
761 | }
762 |
763 | [[ "$ddMode" == '1' ]] && {
764 | WinNoDHCP(){
765 | echo -ne "for\0040\0057f\0040\0042tokens\00753\0052\0042\0040\0045\0045i\0040in\0040\0050\0047netsh\0040interface\0040show\0040interface\0040\0136\0174more\0040\00533\0040\0136\0174findstr\0040\0057I\0040\0057R\0040\0042本地\0056\0052\0040以太\0056\0052\0040Local\0056\0052\0040Ethernet\0042\0047\0051\0040do\0040\0050set\0040EthName\0075\0045\0045j\0051\r\nnetsh\0040\0055c\0040interface\0040ip\0040set\0040address\0040name\0075\0042\0045EthName\0045\0042\0040source\0075static\0040address\0075$IPv4\0040mask\0075$MASK\0040gateway\0075$GATE\r\nnetsh\0040\0055c\0040interface\0040ip\0040add\0040dnsservers\0040name\0075\0042\0045EthName\0045\0042\0040address\00758\00568\00568\00568\0040index\00751\0040validate\0075no\r\n\r\n" >>'/tmp/boot/net.tmp';
766 | }
767 | WinRDP(){
768 | echo -ne "netsh\0040firewall\0040set\0040portopening\0040protocol\0075ALL\0040port\0075$WinRemote\0040name\0075RDP\0040mode\0075ENABLE\0040scope\0075ALL\0040profile\0075ALL\r\nnetsh\0040firewall\0040set\0040portopening\0040protocol\0075ALL\0040port\0075$WinRemote\0040name\0075RDP\0040mode\0075ENABLE\0040scope\0075ALL\0040profile\0075CURRENT\r\nreg\0040add\0040\0042HKLM\0134SYSTEM\0134CurrentControlSet\0134Control\0134Network\0134NewNetworkWindowOff\0042\0040\0057f\r\nreg\0040add\0040\0042HKLM\0134SYSTEM\0134CurrentControlSet\0134Control\0134Terminal\0040Server\0042\0040\0057v\0040fDenyTSConnections\0040\0057t\0040reg\0137dword\0040\0057d\00400\0040\0057f\r\nreg\0040add\0040\0042HKLM\0134SYSTEM\0134CurrentControlSet\0134Control\0134Terminal\0040Server\0134Wds\0134rdpwd\0134Tds\0134tcp\0042\0040\0057v\0040PortNumber\0040\0057t\0040reg\0137dword\0040\0057d\0040$WinRemote\0040\0057f\r\nreg\0040add\0040\0042HKLM\0134SYSTEM\0134CurrentControlSet\0134Control\0134Terminal\0040Server\0134WinStations\0134RDP\0055Tcp\0042\0040\0057v\0040PortNumber\0040\0057t\0040reg\0137dword\0040\0057d\0040$WinRemote\0040\0057f\r\nreg\0040add\0040\0042HKLM\0134SYSTEM\0134CurrentControlSet\0134Control\0134Terminal\0040Server\0134WinStations\0134RDP\0055Tcp\0042\0040\0057v\0040UserAuthentication\0040\0057t\0040reg\0137dword\0040\0057d\00400\0040\0057f\r\nFOR\0040\0057F\0040\0042tokens\00752\0040delims\0075\0072\0042\0040\0045\0045i\0040in\0040\0050\0047SC\0040QUERYEX\0040TermService\0040\0136\0174FINDSTR\0040\0057I\0040\0042PID\0042\0047\0051\0040do\0040TASKKILL\0040\0057F\0040\0057PID\0040\0045\0045i\r\nFOR\0040\0057F\0040\0042tokens\00752\0040delims\0075\0072\0042\0040\0045\0045i\0040in\0040\0050\0047SC\0040QUERYEX\0040UmRdpService\0040\0136\0174FINDSTR\0040\0057I\0040\0042PID\0042\0047\0051\0040do\0040TASKKILL\0040\0057F\0040\0057PID\0040\0045\0045i\r\nSC\0040START\0040TermService\r\n\r\n" >>'/tmp/boot/net.tmp';
769 | }
770 | echo -ne "\0100ECHO\0040OFF\r\n\r\ncd\0056\0076\0045WINDIR\0045\0134GetAdmin\r\nif\0040exist\0040\0045WINDIR\0045\0134GetAdmin\0040\0050del\0040\0057f\0040\0057q\0040\0042\0045WINDIR\0045\0134GetAdmin\0042\0051\0040else\0040\0050\r\necho\0040CreateObject\0136\0050\0042Shell\0056Application\0042\0136\0051\0056ShellExecute\0040\0042\0045\0176s0\0042\0054\0040\0042\0045\0052\0042\0054\0040\0042\0042\0054\0040\0042runas\0042\0054\00401\0040\0076\0076\0040\0042\0045temp\0045\0134Admin\0056vbs\0042\r\n\0042\0045temp\0045\0134Admin\0056vbs\0042\r\ndel\0040\0057f\0040\0057q\0040\0042\0045temp\0045\0134Admin\0056vbs\0042\r\nexit\0040\0057b\00402\0051\r\n\r\n" >'/tmp/boot/net.tmp';
771 | [[ "$setNet" == '1' ]] && WinNoDHCP;
772 | [[ "$setNet" == '0' ]] && [[ "$AutoNet" == '0' ]] && WinNoDHCP;
773 | [[ "$setRDP" == '1' ]] && [[ -n "$WinRemote" ]] && WinRDP
774 | echo -ne "ECHO\0040SELECT\0040VOLUME\0075\0045\0045SystemDrive\0045\0045\0040\0076\0040\0042\0045SystemDrive\0045\0134diskpart\0056extend\0042\r\nECHO\0040EXTEND\0040\0076\0076\0040\0042\0045SystemDrive\0045\0134diskpart\0056extend\0042\r\nSTART\0040/WAIT\0040DISKPART\0040\0057S\0040\0042\0045SystemDrive\0045\0134diskpart\0056extend\0042\r\nDEL\0040\0057f\0040\0057q\0040\0042\0045SystemDrive\0045\0134diskpart\0056extend\0042\r\n\r\n" >>'/tmp/boot/net.tmp';
775 | echo -ne "cd\0040\0057d\0040\0042\0045ProgramData\0045\0057Microsoft\0057Windows\0057Start\0040Menu\0057Programs\0057Startup\0042\r\ndel\0040\0057f\0040\0057q\0040net\0056bat\r\n\r\n\r\n" >>'/tmp/boot/net.tmp';
776 | iconv -f 'UTF-8' -t 'GBK' '/tmp/boot/net.tmp' -o '/tmp/boot/net.bat'
777 | rm -rf '/tmp/boot/net.tmp'
778 | echo "$DDURL" |grep -q '^https://'
779 | [[ $? -eq '0' ]] && {
780 | echo -ne '\nAdd ssl support...\n'
781 | [[ -n $SSL_SUPPORT ]] && {
782 | wget --no-check-certificate -qO- "$SSL_SUPPORT" |tar -x
783 | [[ ! -f /tmp/boot/usr/bin/wget ]] && echo 'Error! SSL_SUPPORT.' && exit 1;
784 | sed -i 's/wget\ -qO-/\/usr\/bin\/wget\ --no-check-certificate\ --retry-connrefused\ --tries=7\ --continue\ -qO-/g' /tmp/boot/preseed.cfg
785 | [[ $? -eq '0' ]] && echo -ne 'Success! \n\n'
786 | } || {
787 | echo -ne 'Not ssl support package! \n\n';
788 | exit 1;
789 | }
790 | }
791 | }
792 |
793 | [[ "$ddMode" == '0' ]] && {
794 | sed -i '/anna-install/d' /tmp/boot/preseed.cfg
795 | sed -i 's/wget.*\/sbin\/reboot\;\ //g' /tmp/boot/preseed.cfg
796 | }
797 |
798 | elif [[ "$linux_relese" == 'centos' ]]; then
799 | cat >/tmp/boot/ks.cfg< /boot/initrd.img;
845 | rm -rf /tmp/boot;
846 | }
847 |
848 | [[ "$inVNC" == 'y' ]] && {
849 | sed -i '$i\\n' $GRUBDIR/$GRUBFILE
850 | sed -i '$r /tmp/grub.new' $GRUBDIR/$GRUBFILE
851 | echo -e "\n\033[33m\033[04mIt will reboot! \nPlease connect VNC! \nSelect\033[0m\033[32m Install OS [$DIST $VER] \033[33m\033[4mto install system.\033[04m\n\n\033[31m\033[04mThere is some information for you.\nDO NOT CLOSE THE WINDOW! \033[0m\n"
852 | echo -e "\033[35mIPv4\t\tNETMASK\t\tGATEWAY\033[0m"
853 | echo -e "\033[36m\033[04m$IPv4\033[0m\t\033[36m\033[04m$MASK\033[0m\t\033[36m\033[04m$GATE\033[0m\n\n"
854 |
855 | read -n 1 -p "Press Enter to reboot..." INP
856 | [[ "$INP" != '' ]] && echo -ne '\b \n\n';
857 | }
858 |
859 | chown root:root $GRUBDIR/$GRUBFILE
860 | chmod 444 $GRUBDIR/$GRUBFILE
861 |
862 | if [[ "$loaderMode" == "0" ]]; then
863 | sleep 3 && reboot >/dev/null 2>&1
864 | else
865 | rm -rf "$HOME/loader"
866 | mkdir -p "$HOME/loader"
867 | cp -rf "/boot/initrd.img" "$HOME/loader/initrd.img"
868 | cp -rf "/boot/vmlinuz" "$HOME/loader/vmlinuz"
869 | [[ -f "/boot/initrd.img" ]] && rm -rf "/boot/initrd.img"
870 | [[ -f "/boot/vmlinuz" ]] && rm -rf "/boot/vmlinuz"
871 | echo && ls -AR1 "$HOME/loader"
872 | fi
873 |
--------------------------------------------------------------------------------
/template-181112.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | ## It can reinstall Debian, Ubuntu, CentOS system with network.
4 | ## Suitable for using by GRUB.
5 | ## Default root password: Vicer
6 | ## Blog: https://moeclub.org
7 | ## Written By Vicer
8 |
9 | export tmpVER=''
10 | export tmpDIST=''
11 | export tmpURL=''
12 | export tmpWORD=''
13 | export tmpMirror=''
14 | export tmpSSL=''
15 | export tmpINS=''
16 | export tmpFW=''
17 | export ipAddr=''
18 | export ipMask=''
19 | export ipGate=''
20 | export linuxdists=''
21 | export ddMode='0'
22 | export setNet='0'
23 | export setRDP='0'
24 | export isMirror='0'
25 | export FindDists='0'
26 | export loaderMode='0'
27 | export SpikCheckDIST='0'
28 | export UNKNOWHW='0'
29 | export UNVER='6.4'
30 |
31 | while [[ $# -ge 1 ]]; do
32 | case $1 in
33 | -v|--ver)
34 | shift
35 | tmpVER="$1"
36 | shift
37 | ;;
38 | -d|--debian)
39 | shift
40 | linuxdists='debian'
41 | tmpDIST="$1"
42 | shift
43 | ;;
44 | -u|--ubuntu)
45 | shift
46 | linuxdists='ubuntu'
47 | tmpDIST="$1"
48 | shift
49 | ;;
50 | -c|--centos)
51 | shift
52 | linuxdists='centos'
53 | tmpDIST="$1"
54 | shift
55 | ;;
56 | -dd|--image)
57 | shift
58 | ddMode='1'
59 | tmpURL="$1"
60 | shift
61 | ;;
62 | -p|--password)
63 | shift
64 | tmpWORD="$1"
65 | shift
66 | ;;
67 | -i|--interface)
68 | shift
69 | interface="$1"
70 | shift
71 | ;;
72 | --ip-addr)
73 | shift
74 | ipAddr="$1"
75 | shift
76 | ;;
77 | --ip-mask)
78 | shift
79 | ipMask="$1"
80 | shift
81 | ;;
82 | --ip-gate)
83 | shift
84 | ipGate="$1"
85 | shift
86 | ;;
87 | --loader)
88 | shift
89 | loaderMode='1'
90 | ;;
91 | --prefer)
92 | shift
93 | tmpPrefer="$1"
94 | shift
95 | ;;
96 | -a|--auto)
97 | shift
98 | tmpINS='auto'
99 | ;;
100 | -m|--manual)
101 | shift
102 | tmpINS='manual'
103 | ;;
104 | -apt|-yum|--mirror)
105 | shift
106 | isMirror='1'
107 | tmpMirror="$1"
108 | shift
109 | ;;
110 | -rdp)
111 | shift
112 | setRDP='1'
113 | WinRemote="$1"
114 | shift
115 | ;;
116 | -ssl)
117 | shift
118 | tmpSSL="$1"
119 | shift
120 | ;;
121 | --firmware)
122 | shift
123 | tmpFW='1'
124 | ;;
125 | *)
126 | if [[ "$1" != 'error' ]]; then echo -ne "\nInvaild option: '$1'\n\n"; fi
127 | echo -ne " Usage:\n\tbash DebianNET.sh\t-d/--debian [\033[33m\033[04mdists-name\033[0m]\n\t\t\t\t-u/--ubuntu [\033[04mdists-name\033[0m]\n\t\t\t\t-c/--centos [\033[33m\033[04mdists-verison\033[0m]\n\t\t\t\t-v/--ver [32/\033[33m\033[04mi386\033[0m|64/amd64]\n\t\t\t\t--ip-addr/--ip-gate/--ip-mask\n\t\t\t\t-apt/-yum/--mirror\n\t\t\t\t-dd/--image\n\t\t\t\t-a/--auto\n\t\t\t\t-m/--manual\n"
128 | exit 1;
129 | ;;
130 | esac
131 | done
132 |
133 | [[ "$EUID" -ne '0' ]] && echo "Error:This script must be run as root!" && exit 1;
134 |
135 | function CheckDependence(){
136 | FullDependence='0';
137 | for BIN_DEP in `echo "$1" |sed 's/,/\n/g'`
138 | do
139 | if [[ -n "$BIN_DEP" ]]; then
140 | Founded='0';
141 | for BIN_PATH in `echo "$PATH" |sed 's/:/\n/g'`
142 | do
143 | ls $BIN_PATH/$BIN_DEP >/dev/null 2>&1;
144 | if [ $? == '0' ]; then
145 | Founded='1';
146 | break;
147 | fi
148 | done
149 | if [ "$Founded" == '1' ]; then
150 | echo -en "[\033[32mok\033[0m]\t";
151 | else
152 | FullDependence='1';
153 | echo -en "[\033[31mNot Install\033[0m]";
154 | fi
155 | echo -en "\t$BIN_DEP\n";
156 | fi
157 | done
158 | if [ "$FullDependence" == '1' ]; then
159 | echo -ne "\n\033[31mError! \033[0mPlease use '\033[33mapt-get\033[0m' or '\033[33myum\033[0m' install it.\n\n\n"
160 | exit 1;
161 | fi
162 | }
163 |
164 | if [[ -z "$linuxdists" ]]; then
165 | linuxdists='debian';
166 | fi
167 |
168 | clear && echo -e "\n\033[36m# Check Dependence\033[0m\n"
169 |
170 | if [[ "$ddMode" == '1' ]]; then
171 | CheckDependence iconv;
172 | linuxdists='debian';
173 | tmpDIST='jessie';
174 | tmpVER='amd64';
175 | tmpINS='auto';
176 | fi
177 |
178 | if [[ "$linuxdists" == 'debian' ]] || [[ "$linuxdists" == 'ubuntu' ]]; then
179 | CheckDependence wget,awk,grep,sed,cut,cat,cpio,gzip,find,dirname,basename;
180 | elif [[ "$linuxdists" == 'centos' ]]; then
181 | CheckDependence wget,awk,grep,sed,cut,cat,cpio,gzip,find,dirname,basename,file,xz;
182 | fi
183 |
184 | if [[ -n "$tmpWORD" ]]; then
185 | CheckDependence openssl;
186 | fi
187 |
188 | if [[ "$loaderMode" == "0" ]]; then
189 | [[ -f '/boot/grub/grub.cfg' ]] && GRUBOLD='0' && GRUBDIR='/boot/grub' && GRUBFILE='grub.cfg';
190 | [[ -z "$GRUBDIR" ]] && [[ -f '/boot/grub2/grub.cfg' ]] && GRUBOLD='0' && GRUBDIR='/boot/grub2' && GRUBFILE='grub.cfg';
191 | [[ -z "$GRUBDIR" ]] && [[ -f '/boot/grub/grub.conf' ]] && GRUBOLD='1' && GRUBDIR='/boot/grub' && GRUBFILE='grub.conf';
192 | [ -z "$GRUBDIR" -o -z "$GRUBFILE" ] && echo -ne "Error! \nNot Found grub path.\n" && exit 1;
193 | else
194 | tmpINS='auto'
195 | fi
196 |
197 | if [[ "$isMirror" == '1' ]]; then
198 | if [[ -n "$tmpMirror" ]]; then
199 | TMPMirrorHost="$(echo -n "$tmpMirror" |grep -Eo '.*\.(\w+)')";
200 | echo "$TMPMirrorHost" |grep -q '://';
201 | if [[ $? == '0' ]]; then
202 | MirrorHost="$(echo "$TMPMirrorHost" |awk -F'://' '{print $2}')";
203 | else
204 | echo -en "\n\033[31mInvaild Mirror! \033[0m\n";
205 | [[ "$linuxdists" == 'debian' ]] && echo -en "\033[33mexample:\033[0m http://deb.debian.org/debian\n\n";
206 | [[ "$linuxdists" == 'ubuntu' ]] && echo -en "\033[33mexample:\033[0m http://archive.ubuntu.com/ubuntu\n\n";
207 | [[ "$linuxdists" == 'centos' ]] && echo -en "\033[33mexample:\033[0m http://mirror.centos.org/centos\n\n";
208 | exit 1
209 | fi
210 | if [[ -n "$MirrorHost" ]]; then
211 | MirrorFolder="$(echo -n "$tmpMirror" |awk -F''${MirrorHost}'' '{print $2}' |sed 's/\/$//g')";
212 | if [[ -z "$MirrorFolder" ]]; then
213 | [[ "$linuxdists" == 'debian' ]] && MirrorFolder='/debian';
214 | [[ "$linuxdists" == 'ubuntu' ]] && MirrorFolder='/ubuntu';
215 | [[ "$linuxdists" == 'centos' ]] && MirrorFolder='/centos';
216 | fi
217 | DISTMirror="${MirrorHost}${MirrorFolder}";
218 | fi
219 | fi
220 | fi
221 |
222 | if [[ -z "$DISTMirror" ]]; then
223 | [[ "$linuxdists" == 'debian' ]] && MirrorHost='deb.debian.org' && MirrorFolder='/debian' && DISTMirror="${MirrorHost}${MirrorFolder}";
224 | [[ "$linuxdists" == 'ubuntu' ]] && MirrorHost='archive.ubuntu.com' && MirrorFolder='/ubuntu' && DISTMirror="${MirrorHost}${MirrorFolder}";
225 | [[ "$linuxdists" == 'centos' ]] && DISTMirror='vault.centos.org';
226 | fi
227 |
228 | if [[ -n "$tmpVER" ]]; then
229 | tmpVER="$(echo "$tmpVER" |sed -r 's/(.*)/\L\1/')";
230 | if [[ "$tmpVER" == '32' ]] || [[ "$tmpVER" == 'i386' ]] || [[ "$tmpVER" == 'x86' ]]; then
231 | VER='i386';
232 | fi
233 | if [[ "$tmpVER" == '64' ]] || [[ "$tmpVER" == 'amd64' ]] || [[ "$tmpVER" == 'x86_64' ]] || [[ "$tmpVER" == 'x64' ]]; then
234 | if [[ "$linuxdists" == 'debian' ]] || [[ "$linuxdists" == 'ubuntu' ]]; then
235 | VER='amd64';
236 | elif [[ "$linuxdists" == 'centos' ]]; then
237 | VER='x86_64';
238 | fi
239 | fi
240 | fi
241 |
242 | if [[ -z "$VER" ]]; then
243 | VER='i386';
244 | fi
245 |
246 | if [[ -n "$tmpPrefer" ]]; then
247 | PreferOption="$(echo "$tmpPrefer" |sed 's/[[:space:]]*//g')"
248 | fi
249 |
250 | if [[ -z "$PreferOption" ]]; then
251 | PreferOption='current';
252 | fi
253 |
254 | if [[ -z "$tmpDIST" ]]; then
255 | [[ "$linuxdists" == 'debian' ]] && DIST='jessie';
256 | [[ "$linuxdists" == 'ubuntu' ]] && DIST='xenial';
257 | [[ "$linuxdists" == 'centos' ]] && DIST='6.8';
258 | fi
259 |
260 | if [[ -z "$DIST" ]]; then
261 | if [[ "$linuxdists" == 'debian' ]]; then
262 | SpikCheckDIST='0'
263 | DIST="$(echo "$tmpDIST" |sed -r 's/(.*)/\L\1/')";
264 | echo "$DIST" |grep -q '[0-9]';
265 | [[ $? -eq '0' ]] && {
266 | isDigital="$(echo "$DIST" |grep -o '[\.0-9]\{1,\}' |sed -n '1h;1!H;$g;s/\n//g;$p' |cut -d'.' -f1)";
267 | [[ -n $isDigital ]] && {
268 | [[ "$isDigital" == '7' ]] && DIST='wheezy';
269 | [[ "$isDigital" == '8' ]] && DIST='jessie';
270 | [[ "$isDigital" == '9' ]] && DIST='stretch';
271 | [[ "$isDigital" == '10' ]] && DIST='buster';
272 | }
273 | }
274 | fi
275 | if [[ "$linuxdists" == 'ubuntu' ]]; then
276 | SpikCheckDIST='0'
277 | DIST="$(echo "$tmpDIST" |sed -r 's/(.*)/\L\1/')";
278 | echo "$DIST" |grep -q '[0-9]';
279 | [[ $? -eq '0' ]] && {
280 | isDigital="$(echo "$DIST" |grep -o '[\.0-9]\{1,\}' |sed -n '1h;1!H;$g;s/\n//g;$p')";
281 | [[ -n $isDigital ]] && {
282 | [[ "$isDigital" == '12.04' ]] && DIST='precise';
283 | [[ "$isDigital" == '14.04' ]] && DIST='trusty';
284 | [[ "$isDigital" == '16.04' ]] && DIST='xenial';
285 | [[ "$isDigital" == '18.04' ]] && DIST='bionic';
286 | }
287 | }
288 | fi
289 | if [[ "$linuxdists" == 'centos' ]]; then
290 | SpikCheckDIST='1'
291 | DISTCheck="$(echo "$tmpDIST" |grep -o '[\.0-9]\{1,\}')";
292 | ListDIST="$(wget --no-check-certificate -qO- "http://$DISTMirror/dir_sizes" |cut -f2 |grep '^[0-9]')"
293 | DIST="$(echo "$ListDIST" |grep "^$DISTCheck" |head -n1)"
294 | [[ -z "$DIST" ]] && {
295 | echo -ne '\nThe dists version not found in this mirror, Please check it! \n\n'
296 | bash $0 error;
297 | exit 1;
298 | }
299 | wget --no-check-certificate -qO- "http://$DISTMirror/$DIST/os/$VER/.treeinfo" |grep -q 'general';
300 | [[ $? != '0' ]] && {
301 | wget --no-check-certificate -qO- "http://$DISTMirror/centos/$DIST/os/$VER/.treeinfo" |grep -q 'general';
302 | [[ $? == '0' ]] && {
303 | DISTMirror="${DISTMirror}/${linuxdists}"
304 | } || {
305 | echo -ne "\nThe version not found in this mirror, Please change mirror try again! \n\n";
306 | exit 1;
307 | }
308 | }
309 |
310 | fi
311 | fi
312 |
313 | if [[ "$SpikCheckDIST" == '0' ]]; then
314 | DistsList="$(wget --no-check-certificate -qO- "http://$DISTMirror/dists/" |grep -o 'href=.*/"' |cut -d'"' -f2 |sed '/-\|old\|Debian\|experimental\|stable\|test\|sid\|devel/d' |grep '^[^/]' |sed -n '1h;1!H;$g;s/\n//g;s/\//\;/g;$p')";
315 | for CheckDEB in `echo "$DistsList" |sed 's/;/\n/g'`
316 | do
317 | [[ "$CheckDEB" == "$DIST" ]] && FindDists='1';
318 | [[ "$FindDists" == '1' ]] && break;
319 | done
320 | [[ "$FindDists" == '0' ]] && {
321 | echo -ne '\nThe dists version not found, Please check it! \n\n'
322 | bash $0 error;
323 | exit 1;
324 | }
325 | fi
326 |
327 | [[ "$ddMode" == '1' ]] && {
328 | export SSL_SUPPORT='https://moeclub.org/get-wget_udeb_amd64';
329 | if [[ -n "$tmpURL" ]]; then
330 | DDURL="$tmpURL"
331 | echo "$DDURL" |grep -q '^http://\|^ftp://\|^https://';
332 | [[ $? -ne '0' ]] && echo 'Please input vaild URL,Only support http://, ftp:// and https:// !' && exit 1;
333 | [[ -n "$tmpSSL" ]] && SSL_SUPPORT="$tmpSSL";
334 | else
335 | echo 'Please input vaild image URL! ';
336 | exit 1;
337 | fi
338 | }
339 |
340 | [[ -n "$tmpINS" ]] && {
341 | [[ "$tmpINS" == 'auto' ]] && inVNC='n';
342 | [[ "$tmpINS" == 'manual' ]] && inVNC='y';
343 | }
344 |
345 | [ -n "$ipAddr" ] && [ -n "$ipMask" ] && [ -n "$ipGate" ] && setNet='1';
346 | [[ -n "$tmpWORD" ]] && myPASSWORD="$(openssl passwd -1 "$tmpWORD")";
347 | [[ -z "$myPASSWORD" ]] && myPASSWORD='$1$0shYGfBd$8v189JOozDO1jPqPO645e1';
348 | [[ -n "$tmpFW" ]] && INCFW="$tmpFW";
349 | [[ -z "$INCFW" ]] && INCFW='0';
350 |
351 | if [[ -n "$interface" ]]; then
352 | IFETH="$interface"
353 | else
354 | if [[ "$linuxdists" == 'centos' ]]; then
355 | IFETH="link"
356 | else
357 | IFETH="auto"
358 | fi
359 | fi
360 |
361 | clear && echo -e "\n\033[36m# Install\033[0m\n"
362 |
363 | ASKVNC(){
364 | inVNC='y';
365 | [[ "$ddMode" == '0' ]] && {
366 | echo -ne "\033[34mCan you login VNC?\033[0m\e[33m[\e[32my\e[33m/n]\e[0m "
367 | read tmpinVNC
368 | [[ -n "$inVNCtmp" ]] && inVNC="$tmpinVNC"
369 | }
370 | [ "$inVNC" == 'y' -o "$inVNC" == 'Y' ] && inVNC='y';
371 | [ "$inVNC" == 'n' -o "$inVNC" == 'N' ] && inVNC='n';
372 | }
373 |
374 | [ "$inVNC" == 'y' -o "$inVNC" == 'n' ] || ASKVNC;
375 | [[ "$linuxdists" == 'debian' ]] && LinuxName='Debian';
376 | [[ "$linuxdists" == 'ubuntu' ]] && LinuxName='Ubuntu';
377 | [[ "$linuxdists" == 'centos' ]] && LinuxName='CentOS';
378 | [[ "$ddMode" == '0' ]] && {
379 | [[ "$inVNC" == 'y' ]] && echo -e "\033[34mManual Mode\033[0m install \033[33m$LinuxName\033[0m [\033[33m$DIST\033[0m] [\033[33m$VER\033[0m] in VNC. "
380 | [[ "$inVNC" == 'n' ]] && echo -e "\033[34mAuto Mode\033[0m install \033[33m$LinuxName\033[0m [\033[33m$DIST\033[0m] [\033[33m$VER\033[0m]. "
381 | }
382 | [[ "$ddMode" == '1' ]] && {
383 | echo -ne "\033[34mAuto Mode\033[0m install \033[33mWindows\033[0m\n[\033[33m$DDURL\033[0m]\n"
384 | }
385 |
386 | if [[ "$linuxdists" == 'centos' ]]; then
387 | if [[ "$DIST" != "$UNVER" ]]; then
388 | awk 'BEGIN{print '${UNVER}'-'${DIST}'}' |grep -q '^-'
389 | if [ $? != '0' ]; then
390 | UNKNOWHW='1';
391 | echo -en "\033[33mThe version lower then \033[31m$UNVER\033[33m may not support in auto mode! \033[0m\n";
392 | if [[ "$inVNC" == 'n' ]]; then
393 | echo -en "\033[35mYou can connect VNC with \033[32mPublic IP\033[35m and port \033[32m1\033[35m/\033[32m5901\033[35m in vnc viewer.\033[0m\n"
394 | read -n 1 -p "Press Enter to continue..." INP
395 | [[ "$INP" != '' ]] && echo -ne '\b \n\n';
396 | fi
397 | fi
398 | awk 'BEGIN{print '${UNVER}'-'${DIST}'+0.59}' |grep -q '^-'
399 | if [ $? == '0' ]; then
400 | echo -en "\n\033[31mThe version higher then \033[33m6.9 \033[31mis not support in current! \033[0m\n\n"
401 | exit 1;
402 | fi
403 | fi
404 | fi
405 |
406 | echo -e "\n[\033[33m$LinuxName\033[0m] [\033[33m$DIST\033[0m] [\033[33m$VER\033[0m] Downloading..."
407 |
408 | [[ -z "$DISTMirror" ]] && echo -ne "\033[31mError! \033[0mInvaild mirror! \n" && exit 1
409 |
410 | if [[ "$linuxdists" == 'debian' ]] || [[ "$linuxdists" == 'ubuntu' ]]; then
411 | wget --no-check-certificate -qO '/boot/initrd.img' "http://$DISTMirror/dists/$DIST/main/installer-$VER/$PreferOption/images/netboot/$linuxdists-installer/$VER/initrd.gz"
412 | [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'initrd.img' for \033[33m$linuxdists\033[0m failed! \n" && exit 1
413 | wget --no-check-certificate -qO '/boot/vmlinuz' "http://$DISTMirror/dists/$DIST/main/installer-$VER/$PreferOption/images/netboot/$linuxdists-installer/$VER/linux"
414 | [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'vmlinuz' for \033[33m$linuxdists\033[0m failed! \n" && exit 1
415 | elif [[ "$linuxdists" == 'centos' ]]; then
416 | wget --no-check-certificate -qO '/boot/initrd.img' "http://$DISTMirror/$DIST/os/$VER/isolinux/initrd.img"
417 | [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'initrd.img' for \033[33m$linuxdists\033[0m failed! \n" && exit 1
418 | wget --no-check-certificate -qO '/boot/vmlinuz' "http://$DISTMirror/$DIST/os/$VER/isolinux/vmlinuz"
419 | [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'vmlinuz' for \033[33m$linuxdists\033[0m failed! \n" && exit 1
420 | fi
421 | if [[ "$linuxdists" == 'debian' ]]; then
422 | if [[ "$INCFW" == '1' ]]; then
423 | wget --no-check-certificate -qO '/boot/firmware.cpio.gz' "http://cdimage.debian.org/cdimage/unofficial/non-free/firmware/$DIST/current/firmware.cpio.gz"
424 | [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'firmware' for \033[33m$linuxdists\033[0m failed! \n" && exit 1
425 | fi
426 | if [[ "$ddMode" == '1' ]]; then
427 | vKernel_udeb=$(wget --no-check-certificate -qO- "http://$DISTMirror/dists/$DIST/main/installer-$VER/$PreferOption/images/udeb.list" |grep '^acpi-modules' |head -n1 |grep -o '[0-9]\{1,2\}.[0-9]\{1,2\}.[0-9]\{1,2\}-[0-9]\{1,2\}' |head -n1)
428 | [[ -z "vKernel_udeb" ]] && vKernel_udeb="3.16.0-4"
429 | fi
430 | fi
431 |
432 | [[ "$setNet" == '1' ]] && {
433 | IPv4="$ipAddr";
434 | MASK="$ipMask";
435 | GATE="$ipGate";
436 | } || {
437 | DEFAULTNET="$(ip route show |grep -o 'default via [0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.*' |head -n1 |sed 's/proto.*\|onlink.*//g' |awk '{print $NF}')";
438 | [[ -n "$DEFAULTNET" ]] && IPSUB="$(ip addr |grep ''${DEFAULTNET}'' |grep 'global' |grep 'brd' |head -n1 |grep -o '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}/[0-9]\{1,2\}')";
439 | IPv4="$(echo -n "$IPSUB" |cut -d'/' -f1)";
440 | NETSUB="$(echo -n "$IPSUB" |grep -o '/[0-9]\{1,2\}')";
441 | GATE="$(ip route show |grep -o 'default via [0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}' |head -n1 |grep -o '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}')";
442 | [[ -n "$NETSUB" ]] && MASK="$(echo -n '128.0.0.0/1,192.0.0.0/2,224.0.0.0/3,240.0.0.0/4,248.0.0.0/5,252.0.0.0/6,254.0.0.0/7,255.0.0.0/8,255.128.0.0/9,255.192.0.0/10,255.224.0.0/11,255.240.0.0/12,255.248.0.0/13,255.252.0.0/14,255.254.0.0/15,255.255.0.0/16,255.255.128.0/17,255.255.192.0/18,255.255.224.0/19,255.255.240.0/20,255.255.248.0/21,255.255.252.0/22,255.255.254.0/23,255.255.255.0/24,255.255.255.128/25,255.255.255.192/26,255.255.255.224/27,255.255.255.240/28,255.255.255.248/29,255.255.255.252/30,255.255.255.254/31,255.255.255.255/32' |grep -o '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}'${NETSUB}'' |cut -d'/' -f1)";
443 | }
444 |
445 | [[ -n "$GATE" ]] && [[ -n "$MASK" ]] && [[ -n "$IPv4" ]] || {
446 | echo "Not found `ip command`, It will use `route command`."
447 | ipNum() {
448 | local IFS='.';
449 | read ip1 ip2 ip3 ip4 <<<"$1";
450 | echo $((ip1*(1<<24)+ip2*(1<<16)+ip3*(1<<8)+ip4));
451 | }
452 |
453 | SelectMax(){
454 | ii=0;
455 | for IPITEM in `route -n |awk -v OUT=$1 '{print $OUT}' |grep '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}'`
456 | do
457 | NumTMP="$(ipNum $IPITEM)";
458 | eval "arrayNum[$ii]='$NumTMP,$IPITEM'";
459 | ii=$[$ii+1];
460 | done
461 | echo ${arrayNum[@]} |sed 's/\s/\n/g' |sort -n -k 1 -t ',' |tail -n1 |cut -d',' -f2;
462 | }
463 |
464 | [[ -z $IPv4 ]] && IPv4="$(ifconfig |grep 'Bcast' |head -n1 |grep -o '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}' |head -n1)";
465 | [[ -z $GATE ]] && GATE="$(SelectMax 2)";
466 | [[ -z $MASK ]] && MASK="$(SelectMax 3)";
467 |
468 | [[ -n "$GATE" ]] && [[ -n "$MASK" ]] && [[ -n "$IPv4" ]] || {
469 | echo "Error! Not configure network. ";
470 | exit 1;
471 | }
472 | }
473 |
474 | [[ "$setNet" != '1' ]] && [[ -f '/etc/network/interfaces' ]] && {
475 | [[ -z "$(sed -n '/iface.*inet static/p' /etc/network/interfaces)" ]] && AutoNet='1' || AutoNet='0';
476 | [[ -d /etc/network/interfaces.d ]] && {
477 | ICFGN="$(find /etc/network/interfaces.d -name '*.cfg' |wc -l)" || ICFGN='0';
478 | [[ "$ICFGN" -ne '0' ]] && {
479 | for NetCFG in `ls -1 /etc/network/interfaces.d/*.cfg`
480 | do
481 | [[ -z "$(cat $NetCFG | sed -n '/iface.*inet static/p')" ]] && AutoNet='1' || AutoNet='0';
482 | [[ "$AutoNet" -eq '0' ]] && break;
483 | done
484 | }
485 | }
486 | }
487 |
488 | [[ "$setNet" != '1' ]] && [[ -d '/etc/sysconfig/network-scripts' ]] && {
489 | ICFGN="$(find /etc/sysconfig/network-scripts -name 'ifcfg-*' |grep -v 'lo'|wc -l)" || ICFGN='0';
490 | [[ "$ICFGN" -ne '0' ]] && {
491 | for NetCFG in `ls -1 /etc/sysconfig/network-scripts/ifcfg-* |grep -v 'lo$' |grep -v ':[0-9]\{1,\}'`
492 | do
493 | [[ -n "$(cat $NetCFG | sed -n '/BOOTPROTO.*[dD][hH][cC][pP]/p')" ]] && AutoNet='1' || {
494 | AutoNet='0' && . $NetCFG;
495 | [[ -n $NETMASK ]] && MASK="$NETMASK";
496 | [[ -n $GATEWAY ]] && GATE="$GATEWAY";
497 | }
498 | [[ "$AutoNet" -eq '0' ]] && break;
499 | done
500 | }
501 | }
502 |
503 | if [[ "$loaderMode" == "0" ]]; then
504 | [[ ! -f $GRUBDIR/$GRUBFILE ]] && echo "Error! Not Found $GRUBFILE. " && exit 1;
505 |
506 | [[ ! -f $GRUBDIR/$GRUBFILE.old ]] && [[ -f $GRUBDIR/$GRUBFILE.bak ]] && mv -f $GRUBDIR/$GRUBFILE.bak $GRUBDIR/$GRUBFILE.old;
507 | mv -f $GRUBDIR/$GRUBFILE $GRUBDIR/$GRUBFILE.bak;
508 | [[ -f $GRUBDIR/$GRUBFILE.old ]] && cat $GRUBDIR/$GRUBFILE.old >$GRUBDIR/$GRUBFILE || cat $GRUBDIR/$GRUBFILE.bak >$GRUBDIR/$GRUBFILE;
509 | else
510 | GRUBOLD='2'
511 | fi
512 |
513 | [[ "$GRUBOLD" == '0' ]] && {
514 | READGRUB='/tmp/grub.read'
515 | cat $GRUBDIR/$GRUBFILE |sed -n '1h;1!H;$g;s/\n/%%%%%%%/g;$p' |grep -om 1 'menuentry\ [^{]*{[^}]*}%%%%%%%' |sed 's/%%%%%%%/\n/g' >$READGRUB
516 | LoadNum="$(cat $READGRUB |grep -c 'menuentry ')"
517 | if [[ "$LoadNum" -eq '1' ]]; then
518 | cat $READGRUB |sed '/^$/d' >/tmp/grub.new;
519 | elif [[ "$LoadNum" -gt '1' ]]; then
520 | CFG0="$(awk '/menuentry /{print NR}' $READGRUB|head -n 1)";
521 | CFG2="$(awk '/menuentry /{print NR}' $READGRUB|head -n 2 |tail -n 1)";
522 | CFG1="";
523 | for tmpCFG in `awk '/}/{print NR}' $READGRUB`
524 | do
525 | [ "$tmpCFG" -gt "$CFG0" -a "$tmpCFG" -lt "$CFG2" ] && CFG1="$tmpCFG";
526 | done
527 | [[ -z "$CFG1" ]] && {
528 | echo "Error! read $GRUBFILE. ";
529 | exit 1;
530 | }
531 |
532 | sed -n "$CFG0,$CFG1"p $READGRUB >/tmp/grub.new;
533 | [[ -f /tmp/grub.new ]] && [[ "$(grep -c '{' /tmp/grub.new)" -eq "$(grep -c '}' /tmp/grub.new)" ]] || {
534 | echo -ne "\033[31mError! \033[0mNot configure $GRUBFILE. \n";
535 | exit 1;
536 | }
537 | fi
538 | [ ! -f /tmp/grub.new ] && echo "Error! $GRUBFILE. " && exit 1;
539 | sed -i "/menuentry.*/c\menuentry\ \'Install OS \[$DIST\ $VER\]\'\ --class debian\ --class\ gnu-linux\ --class\ gnu\ --class\ os\ \{" /tmp/grub.new
540 | sed -i "/echo.*Loading/d" /tmp/grub.new;
541 | INSERTGRUB="$(awk '/menuentry /{print NR}' $GRUBDIR/$GRUBFILE|head -n 1)"
542 | }
543 |
544 | [[ "$GRUBOLD" == '1' ]] && {
545 | CFG0="$(awk '/title[\ ]|title[\t]/{print NR}' $GRUBDIR/$GRUBFILE|head -n 1)";
546 | CFG1="$(awk '/title[\ ]|title[\t]/{print NR}' $GRUBDIR/$GRUBFILE|head -n 2 |tail -n 1)";
547 | [[ -n $CFG0 ]] && [ -z $CFG1 -o $CFG1 == $CFG0 ] && sed -n "$CFG0,$"p $GRUBDIR/$GRUBFILE >/tmp/grub.new;
548 | [[ -n $CFG0 ]] && [ -z $CFG1 -o $CFG1 != $CFG0 ] && sed -n "$CFG0,$[$CFG1-1]"p $GRUBDIR/$GRUBFILE >/tmp/grub.new;
549 | [[ ! -f /tmp/grub.new ]] && echo "Error! configure append $GRUBFILE. " && exit 1;
550 | sed -i "/title.*/c\title\ \'Install OS \[$DIST\ $VER\]\'" /tmp/grub.new;
551 | sed -i '/^#/d' /tmp/grub.new;
552 | INSERTGRUB="$(awk '/title[\ ]|title[\t]/{print NR}' $GRUBDIR/$GRUBFILE|head -n 1)"
553 | }
554 |
555 | if [[ "$loaderMode" == "0" ]]; then
556 | [[ -n "$(grep 'linux.*/\|kernel.*/' /tmp/grub.new |awk '{print $2}' |tail -n 1 |grep '^/boot/')" ]] && Type='InBoot' || Type='NoBoot';
557 |
558 | LinuxKernel="$(grep 'linux.*/\|kernel.*/' /tmp/grub.new |awk '{print $1}' |head -n 1)";
559 | [[ -z "$LinuxKernel" ]] && echo "Error! read grub config! " && exit 1;
560 | LinuxIMG="$(grep 'initrd.*/' /tmp/grub.new |awk '{print $1}' |tail -n 1)";
561 | [ -z "$LinuxIMG" ] && sed -i "/$LinuxKernel.*\//a\\\tinitrd\ \/" /tmp/grub.new && LinuxIMG='initrd';
562 |
563 | if [[ "$linuxdists" == 'debian' ]] || [[ "$linuxdists" == 'ubuntu' ]]; then
564 | BOOT_OPTION="auto=true hostname=$linuxdists domain= -- quiet"
565 | elif [[ "$linuxdists" == 'centos' ]]; then
566 | BOOT_OPTION="ks=file://ks.cfg ksdevice=$IFETH"
567 | fi
568 |
569 | [[ "$Type" == 'InBoot' ]] && {
570 | sed -i "/$LinuxKernel.*\//c\\\t$LinuxKernel\\t\/boot\/vmlinuz $BOOT_OPTION" /tmp/grub.new;
571 | sed -i "/$LinuxIMG.*\//c\\\t$LinuxIMG\\t\/boot\/initrd.img" /tmp/grub.new;
572 | }
573 |
574 | [[ "$Type" == 'NoBoot' ]] && {
575 | sed -i "/$LinuxKernel.*\//c\\\t$LinuxKernel\\t\/vmlinuz $BOOT_OPTION" /tmp/grub.new;
576 | sed -i "/$LinuxIMG.*\//c\\\t$LinuxIMG\\t\/initrd.img" /tmp/grub.new;
577 | }
578 |
579 | sed -i '$a\\n' /tmp/grub.new;
580 | fi
581 |
582 | [[ "$inVNC" == 'n' ]] && {
583 | GRUBPATCH='0';
584 |
585 | if [[ "$loaderMode" == "0" ]]; then
586 | [ -f '/etc/network/interfaces' -o -d '/etc/sysconfig/network-scripts' ] || {
587 | echo "Error, Not found interfaces config.";
588 | exit 1;
589 | }
590 |
591 | sed -i ''${INSERTGRUB}'i\\n' $GRUBDIR/$GRUBFILE;
592 | sed -i ''${INSERTGRUB}'r /tmp/grub.new' $GRUBDIR/$GRUBFILE;
593 | [[ -f $GRUBDIR/grubenv ]] && sed -i 's/saved_entry/#saved_entry/g' $GRUBDIR/grubenv;
594 | fi
595 |
596 | [[ -d /tmp/boot ]] && rm -rf /tmp/boot;
597 | mkdir -p /tmp/boot;
598 | cd /tmp/boot;
599 | if [[ "$linuxdists" == 'debian' ]] || [[ "$linuxdists" == 'ubuntu' ]]; then
600 | COMPTYPE="gzip";
601 | elif [[ "$linuxdists" == 'centos' ]]; then
602 | COMPTYPE="$(file /boot/initrd.img |grep -o ':.*compressed data' |cut -d' ' -f2 |sed -r 's/(.*)/\L\1/' |head -n1)"
603 | [[ -z "$COMPTYPE" ]] && echo "Detect compressed type fail." && exit 1;
604 | fi
605 | CompDected='0'
606 | for ListCOMP in `echo -en 'gzip\nlzma\nxz'`
607 | do
608 | if [[ "$COMPTYPE" == "$ListCOMP" ]]; then
609 | CompDected='1'
610 | if [[ "$COMPTYPE" == 'gzip' ]]; then
611 | NewIMG="initrd.img.gz"
612 | else
613 | NewIMG="initrd.img.$COMPTYPE"
614 | fi
615 | mv -f "/boot/initrd.img" "/tmp/$NewIMG"
616 | break;
617 | fi
618 | done
619 | [[ "$CompDected" != '1' ]] && echo "Detect compressed type not support." && exit 1;
620 | [[ "$COMPTYPE" == 'lzma' ]] && UNCOMP='xz --format=lzma --decompress';
621 | [[ "$COMPTYPE" == 'xz' ]] && UNCOMP='xz --decompress';
622 | [[ "$COMPTYPE" == 'gzip' ]] && UNCOMP='gzip -d';
623 |
624 | $UNCOMP < /tmp/$NewIMG | cpio --extract --verbose --make-directories --no-absolute-filenames >>/dev/null 2>&1
625 |
626 | if [[ "$linuxdists" == 'debian' ]] || [[ "$linuxdists" == 'ubuntu' ]]; then
627 | cat >/tmp/boot/preseed.cfg<>/dev/null 2>&1
735 | }
736 |
737 | [[ "$ddMode" == '1' ]] && {
738 | WinNoDHCP(){
739 | echo -ne "for\0040\0057f\0040\0042tokens\00753\0052\0042\0040\0045\0045i\0040in\0040\0050\0047netsh\0040interface\0040show\0040interface\0040\0136\0174more\0040\00533\0040\0136\0174findstr\0040\0057I\0040\0057R\0040\0042本地\0056\0052\0040以太\0056\0052\0040Local\0056\0052\0040Ethernet\0042\0047\0051\0040do\0040\0050set\0040EthName\0075\0045\0045j\0051\r\nnetsh\0040\0055c\0040interface\0040ip\0040set\0040address\0040name\0075\0042\0045EthName\0045\0042\0040source\0075static\0040address\0075$IPv4\0040mask\0075$MASK\0040gateway\0075$GATE\r\nnetsh\0040\0055c\0040interface\0040ip\0040add\0040dnsservers\0040name\0075\0042\0045EthName\0045\0042\0040address\00758\00568\00568\00568\0040index\00751\0040validate\0075no\r\n\r\n" >>'/tmp/boot/net.tmp';
740 | }
741 | WinRDP(){
742 | echo -ne "netsh\0040firewall\0040set\0040portopening\0040protocol\0075ALL\0040port\0075$WinRemote\0040name\0075RDP\0040mode\0075ENABLE\0040scope\0075ALL\0040profile\0075ALL\r\nnetsh\0040firewall\0040set\0040portopening\0040protocol\0075ALL\0040port\0075$WinRemote\0040name\0075RDP\0040mode\0075ENABLE\0040scope\0075ALL\0040profile\0075CURRENT\r\nreg\0040add\0040\0042HKLM\0134SYSTEM\0134CurrentControlSet\0134Control\0134Network\0134NewNetworkWindowOff\0042\0040\0057f\r\nreg\0040add\0040\0042HKLM\0134SYSTEM\0134CurrentControlSet\0134Control\0134Terminal\0040Server\0042\0040\0057v\0040fDenyTSConnections\0040\0057t\0040reg\0137dword\0040\0057d\00400\0040\0057f\r\nreg\0040add\0040\0042HKLM\0134SYSTEM\0134CurrentControlSet\0134Control\0134Terminal\0040Server\0134Wds\0134rdpwd\0134Tds\0134tcp\0042\0040\0057v\0040PortNumber\0040\0057t\0040reg\0137dword\0040\0057d\0040$WinRemote\0040\0057f\r\nreg\0040add\0040\0042HKLM\0134SYSTEM\0134CurrentControlSet\0134Control\0134Terminal\0040Server\0134WinStations\0134RDP\0055Tcp\0042\0040\0057v\0040PortNumber\0040\0057t\0040reg\0137dword\0040\0057d\0040$WinRemote\0040\0057f\r\nreg\0040add\0040\0042HKLM\0134SYSTEM\0134CurrentControlSet\0134Control\0134Terminal\0040Server\0134WinStations\0134RDP\0055Tcp\0042\0040\0057v\0040UserAuthentication\0040\0057t\0040reg\0137dword\0040\0057d\00400\0040\0057f\r\nFOR\0040\0057F\0040\0042tokens\00752\0040delims\0075\0072\0042\0040\0045\0045i\0040in\0040\0050\0047SC\0040QUERYEX\0040TermService\0040\0136\0174FINDSTR\0040\0057I\0040\0042PID\0042\0047\0051\0040do\0040TASKKILL\0040\0057F\0040\0057PID\0040\0045\0045i\r\nFOR\0040\0057F\0040\0042tokens\00752\0040delims\0075\0072\0042\0040\0045\0045i\0040in\0040\0050\0047SC\0040QUERYEX\0040UmRdpService\0040\0136\0174FINDSTR\0040\0057I\0040\0042PID\0042\0047\0051\0040do\0040TASKKILL\0040\0057F\0040\0057PID\0040\0045\0045i\r\nSC\0040START\0040TermService\r\n\r\n" >>'/tmp/boot/net.tmp';
743 | }
744 | echo -ne "\0100ECHO\0040OFF\r\n\r\ncd\0056\0076\0045WINDIR\0045\0134GetAdmin\r\nif\0040exist\0040\0045WINDIR\0045\0134GetAdmin\0040\0050del\0040\0057f\0040\0057q\0040\0042\0045WINDIR\0045\0134GetAdmin\0042\0051\0040else\0040\0050\r\necho\0040CreateObject\0136\0050\0042Shell\0056Application\0042\0136\0051\0056ShellExecute\0040\0042\0045\0176s0\0042\0054\0040\0042\0045\0052\0042\0054\0040\0042\0042\0054\0040\0042runas\0042\0054\00401\0040\0076\0076\0040\0042\0045temp\0045\0134Admin\0056vbs\0042\r\n\0042\0045temp\0045\0134Admin\0056vbs\0042\r\ndel\0040\0057f\0040\0057q\0040\0042\0045temp\0045\0134Admin\0056vbs\0042\r\nexit\0040\0057b\00402\0051\r\n\r\n" >'/tmp/boot/net.tmp';
745 | [[ "$setNet" == '1' ]] && WinNoDHCP;
746 | [[ "$setNet" == '0' ]] && [[ "$AutoNet" == '0' ]] && WinNoDHCP;
747 | [[ "$setRDP" == '1' ]] && [[ -n "$WinRemote" ]] && WinRDP
748 | echo -ne "ECHO\0040SELECT\0040VOLUME\0075\0045\0045SystemDrive\0045\0045\0040\0076\0040\0042\0045SystemDrive\0045\0134diskpart\0056extend\0042\r\nECHO\0040EXTEND\0040\0076\0076\0040\0042\0045SystemDrive\0045\0134diskpart\0056extend\0042\r\nSTART\0040/WAIT\0040DISKPART\0040\0057S\0040\0042\0045SystemDrive\0045\0134diskpart\0056extend\0042\r\nDEL\0040\0057f\0040\0057q\0040\0042\0045SystemDrive\0045\0134diskpart\0056extend\0042\r\n\r\n" >>'/tmp/boot/net.tmp';
749 | echo -ne "cd\0040\0057d\0040\0042\0045ProgramData\0045\0057Microsoft\0057Windows\0057Start\0040Menu\0057Programs\0057Startup\0042\r\ndel\0040\0057f\0040\0057q\0040net\0056bat\r\n\r\n\r\n" >>'/tmp/boot/net.tmp';
750 | iconv -f 'UTF-8' -t 'GBK' '/tmp/boot/net.tmp' -o '/tmp/boot/net.bat'
751 | rm -rf '/tmp/boot/net.tmp'
752 | echo "$DDURL" |grep -q '^https://'
753 | [[ $? -eq '0' ]] && {
754 | echo -ne '\nAdd ssl support...\n'
755 | [[ -n $SSL_SUPPORT ]] && {
756 | wget --no-check-certificate -qO- "$SSL_SUPPORT" |tar -x
757 | [[ ! -f /tmp/boot/usr/bin/wget ]] && echo 'Error! SSL_SUPPORT.' && exit 1;
758 | sed -i 's/wget\ -qO-/\/usr\/bin\/wget\ --no-check-certificate\ --retry-connrefused\ --tries=7\ --continue\ -qO-/g' /tmp/boot/preseed.cfg
759 | [[ $? -eq '0' ]] && echo -ne 'Success! \n\n'
760 | } || {
761 | echo -ne 'Not ssl support package! \n\n';
762 | exit 1;
763 | }
764 | }
765 | }
766 |
767 | [[ "$ddMode" == '0' ]] && {
768 | sed -i '/anna-install/d' /tmp/boot/preseed.cfg
769 | sed -i 's/wget.*\/sbin\/reboot\;\ //g' /tmp/boot/preseed.cfg
770 | }
771 |
772 | elif [[ "$linuxdists" == 'centos' ]]; then
773 | cat >/tmp/boot/ks.cfg< /boot/initrd.img;
823 | rm -rf /tmp/boot;
824 | }
825 |
826 | [[ "$inVNC" == 'y' ]] && {
827 | sed -i '$i\\n' $GRUBDIR/$GRUBFILE
828 | sed -i '$r /tmp/grub.new' $GRUBDIR/$GRUBFILE
829 | echo -e "\n\033[33m\033[04mIt will reboot! \nPlease look at VNC! \nSelect\033[0m\033[32m Install OS [$DIST $VER] \033[33m\033[4mto install system.\033[04m\n\n\033[31m\033[04mThere is some information for you.\nDO NOT CLOSE THE WINDOW! \033[0m\n"
830 | echo -e "\033[35mIPv4\t\tNETMASK\t\tGATEWAY\033[0m"
831 | echo -e "\033[36m\033[04m$IPv4\033[0m\t\033[36m\033[04m$MASK\033[0m\t\033[36m\033[04m$GATE\033[0m\n\n"
832 |
833 | read -n 1 -p "Press Enter to reboot..." INP
834 | [[ "$INP" != '' ]] && echo -ne '\b \n\n';
835 | }
836 |
837 | chown root:root $GRUBDIR/$GRUBFILE
838 | chmod 444 $GRUBDIR/$GRUBFILE
839 |
840 | if [[ "$loaderMode" == "0" ]]; then
841 | sleep 3 && reboot >/dev/null 2>&1
842 | else
843 | rm -rf "$HOME/loader"
844 | mkdir -p "$HOME/loader"
845 | cp -rf "/boot/initrd.img" "$HOME/loader/initrd.img"
846 | cp -rf "/boot/vmlinuz" "$HOME/loader/vmlinuz"
847 | [[ -f "/boot/initrd.img" ]] && rm -rf "/boot/initrd.img"
848 | [[ -f "/boot/vmlinuz" ]] && rm -rf "/boot/vmlinuz"
849 | echo && ls -AR1 "$HOME/loader"
850 | fi
851 |
--------------------------------------------------------------------------------
/template-190512.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | ## License: GPL
4 | ## It can reinstall Debian, Ubuntu, CentOS system with network.
5 | ## Default root password: MoeClub.org
6 | ## Blog: https://moeclub.org
7 | ## Written By MoeClub.org
8 |
9 |
10 | export tmpVER=''
11 | export tmpDIST=''
12 | export tmpURL=''
13 | export tmpWORD=''
14 | export tmpMirror=''
15 | export tmpSSL=''
16 | export tmpINS=''
17 | export ipAddr=''
18 | export ipMask=''
19 | export ipGate=''
20 | export Relese=''
21 | export ddMode='0'
22 | export setNet='0'
23 | export setRDP='0'
24 | export setIPv6='0'
25 | export isMirror='0'
26 | export FindDists='0'
27 | export loaderMode='0'
28 | export SpikCheckDIST='0'
29 | export setInterfaceName='0'
30 | export UNKNOWHW='0'
31 | export UNVER='6.4'
32 |
33 | while [[ $# -ge 1 ]]; do
34 | case $1 in
35 | -v|--ver)
36 | shift
37 | tmpVER="$1"
38 | shift
39 | ;;
40 | -d|--debian)
41 | shift
42 | Relese='Debian'
43 | tmpDIST="$1"
44 | shift
45 | ;;
46 | -u|--ubuntu)
47 | shift
48 | Relese='Ubuntu'
49 | tmpDIST="$1"
50 | shift
51 | ;;
52 | -c|--centos)
53 | shift
54 | Relese='CentOS'
55 | tmpDIST="$1"
56 | shift
57 | ;;
58 | -dd|--image)
59 | shift
60 | ddMode='1'
61 | tmpURL="$1"
62 | shift
63 | ;;
64 | -p|--password)
65 | shift
66 | tmpWORD="$1"
67 | shift
68 | ;;
69 | -i|--interface)
70 | shift
71 | interface="$1"
72 | shift
73 | ;;
74 | --ip-addr)
75 | shift
76 | ipAddr="$1"
77 | shift
78 | ;;
79 | --ip-mask)
80 | shift
81 | ipMask="$1"
82 | shift
83 | ;;
84 | --ip-gate)
85 | shift
86 | ipGate="$1"
87 | shift
88 | ;;
89 | --dev-net)
90 | shift
91 | setInterfaceName='1'
92 | ;;
93 | --loader)
94 | shift
95 | loaderMode='1'
96 | ;;
97 | --prefer)
98 | shift
99 | tmpPrefer="$1"
100 | shift
101 | ;;
102 | -a|--auto)
103 | shift
104 | tmpINS='auto'
105 | ;;
106 | -m|--manual)
107 | shift
108 | tmpINS='manual'
109 | ;;
110 | -apt|-yum|--mirror)
111 | shift
112 | isMirror='1'
113 | tmpMirror="$1"
114 | shift
115 | ;;
116 | -rdp)
117 | shift
118 | setRDP='1'
119 | WinRemote="$1"
120 | shift
121 | ;;
122 | -ssl)
123 | shift
124 | tmpSSL="$1"
125 | shift
126 | ;;
127 | --ipv6)
128 | shift
129 | setIPv6='1'
130 | ;;
131 | *)
132 | if [[ "$1" != 'error' ]]; then echo -ne "\nInvaild option: '$1'\n\n"; fi
133 | echo -ne " Usage:\n\tbash $(basename $0)\t-d/--debian [\033[33m\033[04mdists-name\033[0m]\n\t\t\t\t-u/--ubuntu [\033[04mdists-name\033[0m]\n\t\t\t\t-c/--centos [\033[33m\033[04mdists-verison\033[0m]\n\t\t\t\t-v/--ver [32/\033[33m\033[04mi386\033[0m|64/amd64]\n\t\t\t\t--ip-addr/--ip-gate/--ip-mask\n\t\t\t\t-apt/-yum/--mirror\n\t\t\t\t-dd/--image\n\t\t\t\t-a/--auto\n\t\t\t\t-m/--manual\n"
134 | exit 1;
135 | ;;
136 | esac
137 | done
138 |
139 | [[ "$EUID" -ne '0' ]] && echo "Error:This script must be run as root!" && exit 1;
140 |
141 | function CheckDependence(){
142 | FullDependence='0';
143 | for BIN_DEP in `echo "$1" |sed 's/,/\n/g'`
144 | do
145 | if [[ -n "$BIN_DEP" ]]; then
146 | Founded='0';
147 | for BIN_PATH in `echo "$PATH" |sed 's/:/\n/g'`
148 | do
149 | ls $BIN_PATH/$BIN_DEP >/dev/null 2>&1;
150 | if [ $? == '0' ]; then
151 | Founded='1';
152 | break;
153 | fi
154 | done
155 | if [ "$Founded" == '1' ]; then
156 | echo -en "[\033[32mok\033[0m]\t";
157 | else
158 | FullDependence='1';
159 | echo -en "[\033[31mNot Install\033[0m]";
160 | fi
161 | echo -en "\t$BIN_DEP\n";
162 | fi
163 | done
164 | if [ "$FullDependence" == '1' ]; then
165 | echo -ne "\n\033[31mError! \033[0mPlease use '\033[33mapt-get\033[0m' or '\033[33myum\033[0m' install it.\n\n\n"
166 | exit 1;
167 | fi
168 | }
169 |
170 | function SelectMirror(){
171 | [ $# -ge 3 ] || exit 1
172 | Relese="$1"
173 | DIST=$(echo "$2" |sed 's/\ //g' |sed -r 's/(.*)/\L\1/')
174 | VER=$(echo "$3" |sed 's/\ //g' |sed -r 's/(.*)/\L\1/')
175 | New=$(echo "$4" |sed 's/\ //g')
176 | [ -n "$Relese" ] || exit 1
177 | [ -n "$DIST" ] || exit 1
178 | [ -n "$VER" ] || exit 1
179 | relese=$(echo $Relese |sed -r 's/(.*)/\L\1/')
180 | if [ "$Relese" == "Debian" ] || [ "$Relese" == "Ubuntu" ]; then
181 | inUpdate=''; [ "$Relese" == "Ubuntu" ] && inUpdate='-updates'
182 | MirrorTEMP="SUB_MIRROR/dists/${DIST}${inUpdate}/main/installer-${VER}/current/images/netboot/${relese}-installer/${VER}/initrd.gz"
183 | elif [ "$Relese" == "CentOS" ]; then
184 | MirrorTEMP="SUB_MIRROR/${DIST}/os/${VER}/isolinux/initrd.img"
185 | fi
186 | [ -n "$MirrorTEMP" ] || exit 1
187 | MirrorStatus=0
188 | declare -A MirrorBackup
189 | MirrorBackup=(["Debian0"]="" ["Debian1"]="http://deb.debian.org/debian" ["Debian2"]="http://archive.debian.org/debian" ["Ubuntu0"]="" ["Ubuntu1"]="http://archive.ubuntu.com/ubuntu" ["CentOS0"]="" ["CentOS1"]="http://mirror.centos.org/centos" ["CentOS2"]="http://vault.centos.org")
190 | echo "$New" |grep -q '^http://\|^https://\|^ftp://' && MirrorBackup[${Relese}0]="$New"
191 | for mirror in $(echo "${!MirrorBackup[@]}" |sed 's/\ /\n/g' |sort -n |grep "^$Relese")
192 | do
193 | CurMirror="${MirrorBackup[$mirror]}"
194 | [ -n "$CurMirror" ] || continue
195 | MirrorURL=`echo "$MirrorTEMP" |sed "s#SUB_MIRROR#${CurMirror}#g"`
196 | wget --no-check-certificate --spider --timeout=3 -o /dev/null "$MirrorURL"
197 | [ $? -eq 0 ] && MirrorStatus=1 && break
198 | done
199 | [ $MirrorStatus -eq 1 ] && echo "$CurMirror" || exit 1
200 | }
201 |
202 | [ -n "$Relese" ] || Relese='Debian'
203 | linux_relese=$(echo "$Relese" |sed 's/\ //g' |sed -r 's/(.*)/\L\1/')
204 | clear && echo -e "\n\033[36m# Check Dependence\033[0m\n"
205 |
206 | if [[ "$ddMode" == '1' ]]; then
207 | CheckDependence iconv;
208 | linux_relese='debian';
209 | tmpDIST='jessie';
210 | tmpVER='amd64';
211 | tmpINS='auto';
212 | fi
213 |
214 | if [[ "$Relese" == 'Debian' ]] || [[ "$Relese" == 'Ubuntu' ]]; then
215 | CheckDependence wget,awk,grep,sed,cut,cat,cpio,gzip,find,dirname,basename;
216 | elif [[ "$Relese" == 'CentOS' ]]; then
217 | CheckDependence wget,awk,grep,sed,cut,cat,cpio,gzip,find,dirname,basename,file,xz;
218 | fi
219 | [ -n "$tmpWORD" ] && CheckDependence openssl
220 |
221 | if [[ "$loaderMode" == "0" ]]; then
222 | [[ -f '/boot/grub/grub.cfg' ]] && GRUBVER='0' && GRUBDIR='/boot/grub' && GRUBFILE='grub.cfg';
223 | [[ -z "$GRUBDIR" ]] && [[ -f '/boot/grub2/grub.cfg' ]] && GRUBVER='0' && GRUBDIR='/boot/grub2' && GRUBFILE='grub.cfg';
224 | [[ -z "$GRUBDIR" ]] && [[ -f '/boot/grub/grub.conf' ]] && GRUBVER='1' && GRUBDIR='/boot/grub' && GRUBFILE='grub.conf';
225 | [ -z "$GRUBDIR" -o -z "$GRUBFILE" ] && echo -ne "Error! \nNot Found grub.\n" && exit 1;
226 | else
227 | tmpINS='auto'
228 | fi
229 |
230 | if [[ -n "$tmpVER" ]]; then
231 | tmpVER="$(echo "$tmpVER" |sed -r 's/(.*)/\L\1/')";
232 | if [[ "$tmpVER" == '32' ]] || [[ "$tmpVER" == 'i386' ]] || [[ "$tmpVER" == 'x86' ]]; then
233 | VER='i386';
234 | fi
235 | if [[ "$tmpVER" == '64' ]] || [[ "$tmpVER" == 'amd64' ]] || [[ "$tmpVER" == 'x86_64' ]] || [[ "$tmpVER" == 'x64' ]]; then
236 | if [[ "$Relese" == 'Debian' ]] || [[ "$Relese" == 'Ubuntu' ]]; then
237 | VER='amd64';
238 | elif [[ "$Relese" == 'CentOS' ]]; then
239 | VER='x86_64';
240 | fi
241 | fi
242 | fi
243 | [ -z "$VER" ] && VER='amd64'
244 |
245 | if [[ -z "$tmpDIST" ]]; then
246 | [ "$Relese" == 'Debian' ] && tmpDIST='jessie' && DIST='jessie';
247 | [ "$Relese" == 'Ubuntu' ] && tmpDIST='bionic' && DIST='bionic';
248 | [ "$Relese" == 'CentOS' ] && tmpDIST='6.10' && DIST='6.10';
249 | fi
250 |
251 | if [[ -z "$DIST" ]]; then
252 | if [[ "$Relese" == 'Debian' ]]; then
253 | SpikCheckDIST='0'
254 | DIST="$(echo "$tmpDIST" |sed -r 's/(.*)/\L\1/')";
255 | echo "$DIST" |grep -q '[0-9]';
256 | [[ $? -eq '0' ]] && {
257 | isDigital="$(echo "$DIST" |grep -o '[\.0-9]\{1,\}' |sed -n '1h;1!H;$g;s/\n//g;$p' |cut -d'.' -f1)";
258 | [[ -n $isDigital ]] && {
259 | [[ "$isDigital" == '7' ]] && DIST='wheezy';
260 | [[ "$isDigital" == '8' ]] && DIST='jessie';
261 | [[ "$isDigital" == '9' ]] && DIST='stretch';
262 | [[ "$isDigital" == '10' ]] && DIST='buster';
263 | }
264 | }
265 | LinuxMirror=$(SelectMirror "$Relese" "$DIST" "$VER" "$tmpMirror")
266 | fi
267 | if [[ "$Relese" == 'Ubuntu' ]]; then
268 | SpikCheckDIST='0'
269 | DIST="$(echo "$tmpDIST" |sed -r 's/(.*)/\L\1/')";
270 | echo "$DIST" |grep -q '[0-9]';
271 | [[ $? -eq '0' ]] && {
272 | isDigital="$(echo "$DIST" |grep -o '[\.0-9]\{1,\}' |sed -n '1h;1!H;$g;s/\n//g;$p')";
273 | [[ -n $isDigital ]] && {
274 | [[ "$isDigital" == '12.04' ]] && DIST='precise';
275 | [[ "$isDigital" == '14.04' ]] && DIST='trusty';
276 | [[ "$isDigital" == '16.04' ]] && DIST='xenial';
277 | [[ "$isDigital" == '18.04' ]] && DIST='bionic';
278 | }
279 | }
280 | LinuxMirror=$(SelectMirror "$Relese" "$DIST" "$VER" "$tmpMirror")
281 | fi
282 | if [[ "$Relese" == 'CentOS' ]]; then
283 | SpikCheckDIST='1'
284 | DISTCheck="$(echo "$tmpDIST" |grep -o '[\.0-9]\{1,\}')";
285 | LinuxMirror=$(SelectMirror "$Relese" "$DISTCheck" "$VER" "$tmpMirror")
286 | ListDIST="$(wget --no-check-certificate -qO- "$LinuxMirror/dir_sizes" |cut -f2 |grep '^[0-9]')"
287 | DIST="$(echo "$ListDIST" |grep "^$DISTCheck" |head -n1)"
288 | [[ -z "$DIST" ]] && {
289 | echo -ne '\nThe dists version not found in this mirror, Please check it! \n\n'
290 | bash $0 error;
291 | exit 1;
292 | }
293 | wget --no-check-certificate -qO- "$LinuxMirror/$DIST/os/$VER/.treeinfo" |grep -q 'general';
294 | [[ $? != '0' ]] && {
295 | echo -ne "\nThe version not found in this mirror, Please change mirror try again! \n\n";
296 | exit 1;
297 | }
298 | fi
299 | fi
300 |
301 | if [[ -z "$LinuxMirror" ]]; then
302 | echo -ne "\033[31mError! \033[0mInvaild mirror! \n"
303 | [ "$Relese" == 'Debian' ] && echo -en "\033[33mexample:\033[0m http://deb.debian.org/debian\n\n";
304 | [ "$Relese" == 'Ubuntu' ] && echo -en "\033[33mexample:\033[0m http://archive.ubuntu.com/ubuntu\n\n";
305 | [ "$Relese" == 'CentOS' ] && echo -en "\033[33mexample:\033[0m http://mirror.centos.org/centos\n\n";
306 | bash $0 error;
307 | exit 1;
308 | fi
309 |
310 | if [[ "$SpikCheckDIST" == '0' ]]; then
311 | DistsList="$(wget --no-check-certificate -qO- "$LinuxMirror/dists/" |grep -o 'href=.*/"' |cut -d'"' -f2 |sed '/-\|old\|Debian\|experimental\|stable\|test\|sid\|devel/d' |grep '^[^/]' |sed -n '1h;1!H;$g;s/\n//g;s/\//\;/g;$p')";
312 | for CheckDEB in `echo "$DistsList" |sed 's/;/\n/g'`
313 | do
314 | [[ "$CheckDEB" == "$DIST" ]] && FindDists='1' && break;
315 | done
316 | [[ "$FindDists" == '0' ]] && {
317 | echo -ne '\nThe dists version not found, Please check it! \n\n'
318 | bash $0 error;
319 | exit 1;
320 | }
321 | fi
322 |
323 | [[ "$ddMode" == '1' ]] && {
324 | export SSL_SUPPORT='https://moeclub.org/get/wget_udeb_amd64';
325 | if [[ -n "$tmpURL" ]]; then
326 | DDURL="$tmpURL"
327 | echo "$DDURL" |grep -q '^http://\|^ftp://\|^https://';
328 | [[ $? -ne '0' ]] && echo 'Please input vaild URL,Only support http://, ftp:// and https:// !' && exit 1;
329 | [[ -n "$tmpSSL" ]] && SSL_SUPPORT="$tmpSSL";
330 | else
331 | echo 'Please input vaild image URL! ';
332 | exit 1;
333 | fi
334 | }
335 |
336 | [[ -n "$tmpINS" ]] && {
337 | [[ "$tmpINS" == 'auto' ]] && inVNC='n';
338 | [[ "$tmpINS" == 'manual' ]] && inVNC='y';
339 | }
340 |
341 | [ -n "$ipAddr" ] && [ -n "$ipMask" ] && [ -n "$ipGate" ] && setNet='1';
342 | [[ -n "$tmpWORD" ]] && myPASSWORD="$(openssl passwd -1 "$tmpWORD")";
343 | [[ -z "$myPASSWORD" ]] && myPASSWORD='$1$4BJZaD0A$y1QykUnJ6mXprENfwpseH0';
344 |
345 | if [[ -n "$interface" ]]; then
346 | IFETH="$interface"
347 | else
348 | if [[ "$linux_relese" == 'centos' ]]; then
349 | IFETH="link"
350 | else
351 | IFETH="auto"
352 | fi
353 | fi
354 |
355 | clear && echo -e "\n\033[36m# Install\033[0m\n"
356 |
357 | ASKVNC(){
358 | inVNC='y';
359 | [[ "$ddMode" == '0' ]] && {
360 | echo -ne "\033[34mDo you want to install os manually?\033[0m\e[33m[\e[32my\e[33m/n]\e[0m "
361 | read tmpinVNC
362 | [[ -n "$inVNCtmp" ]] && inVNC="$tmpinVNC"
363 | }
364 | [ "$inVNC" == 'y' -o "$inVNC" == 'Y' ] && inVNC='y';
365 | [ "$inVNC" == 'n' -o "$inVNC" == 'N' ] && inVNC='n';
366 | }
367 |
368 | [ "$inVNC" == 'y' -o "$inVNC" == 'n' ] || ASKVNC;
369 | [[ "$ddMode" == '0' ]] && {
370 | [[ "$inVNC" == 'y' ]] && echo -e "\033[34mManual Mode\033[0m insatll [\033[33m$Relese\033[0m] [\033[33m$DIST\033[0m] [\033[33m$VER\033[0m] in VNC. "
371 | [[ "$inVNC" == 'n' ]] && echo -e "\033[34mAuto Mode\033[0m insatll [\033[33m$Relese\033[0m] [\033[33m$DIST\033[0m] [\033[33m$VER\033[0m]. "
372 | }
373 | [[ "$ddMode" == '1' ]] && {
374 | echo -ne "\033[34mAuto Mode\033[0m insatll \033[33mWindows\033[0m\n[\033[33m$DDURL\033[0m]\n"
375 | }
376 |
377 | if [[ "$linux_relese" == 'centos' ]]; then
378 | if [[ "$DIST" != "$UNVER" ]]; then
379 | awk 'BEGIN{print '${UNVER}'-'${DIST}'}' |grep -q '^-'
380 | if [ $? != '0' ]; then
381 | UNKNOWHW='1';
382 | echo -en "\033[33mThe version lower then \033[31m$UNVER\033[33m may not support in auto mode! \033[0m\n";
383 | if [[ "$inVNC" == 'n' ]]; then
384 | echo -en "\033[35mYou can connect VNC with \033[32mPublic IP\033[35m and port \033[32m1\033[35m/\033[32m5901\033[35m in vnc viewer.\033[0m\n"
385 | read -n 1 -p "Press Enter to continue..." INP
386 | [[ "$INP" != '' ]] && echo -ne '\b \n\n';
387 | fi
388 | fi
389 | awk 'BEGIN{print '${UNVER}'-'${DIST}'+0.59}' |grep -q '^-'
390 | if [ $? == '0' ]; then
391 | echo -en "\n\033[31mThe version higher then \033[33m6.10 \033[31mis not support in current! \033[0m\n\n"
392 | exit 1;
393 | fi
394 | fi
395 | fi
396 |
397 | echo -e "\n[\033[33m$Relese\033[0m] [\033[33m$DIST\033[0m] [\033[33m$VER\033[0m] Downloading..."
398 |
399 | if [[ "$linux_relese" == 'debian' ]] || [[ "$linux_relese" == 'ubuntu' ]]; then
400 | inUpdate=''; [ "$linux_relese" == 'ubuntu' ] && inUpdate='-updates'
401 | wget --no-check-certificate -qO '/boot/initrd.img' "${LinuxMirror}/dists/${DIST}${inUpdate}/main/installer-${VER}/current/images/netboot/${linux_relese}-installer/${VER}/initrd.gz"
402 | [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'initrd.img' for \033[33m$linux_relese\033[0m failed! \n" && exit 1
403 | wget --no-check-certificate -qO '/boot/vmlinuz' "${LinuxMirror}/dists/${DIST}${inUpdate}/main/installer-${VER}/current/images/netboot/${linux_relese}-installer/${VER}/linux"
404 | [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'vmlinuz' for \033[33m$linux_relese\033[0m failed! \n" && exit 1
405 | MirrorHost="$(echo "$LinuxMirror" |awk -F'://|/' '{print $2}')";
406 | MirrorFolder="$(echo "$LinuxMirror" |awk -F''${MirrorHost}'' '{print $2}')";
407 | elif [[ "$linux_relese" == 'centos' ]]; then
408 | wget --no-check-certificate -qO '/boot/initrd.img' "${LinuxMirror}/${DIST}/os/${VER}/isolinux/initrd.img"
409 | [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'initrd.img' for \033[33m$linux_relese\033[0m failed! \n" && exit 1
410 | wget --no-check-certificate -qO '/boot/vmlinuz' "${LinuxMirror}/${DIST}/os/${VER}/isolinux/vmlinuz"
411 | [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'vmlinuz' for \033[33m$linux_relese\033[0m failed! \n" && exit 1
412 | else
413 | bash $0 error;
414 | exit 1;
415 | fi
416 | if [[ "$linux_relese" == 'debian' ]]; then
417 | wget --no-check-certificate -qO '/boot/firmware.cpio.gz' "http://cdimage.debian.org/cdimage/unofficial/non-free/firmware/${DIST}/current/firmware.cpio.gz"
418 | [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'firmware' for \033[33m$linux_relese\033[0m failed! \n" && exit 1
419 | if [[ "$ddMode" == '1' ]]; then
420 | vKernel_udeb=$(wget --no-check-certificate -qO- "http://$DISTMirror/dists/$DIST/main/installer-$VER/current/images/udeb.list" |grep '^acpi-modules' |head -n1 |grep -o '[0-9]\{1,2\}.[0-9]\{1,2\}.[0-9]\{1,2\}-[0-9]\{1,2\}' |head -n1)
421 | [[ -z "vKernel_udeb" ]] && vKernel_udeb="3.16.0-6"
422 | fi
423 | fi
424 |
425 | [[ "$setNet" == '1' ]] && {
426 | IPv4="$ipAddr";
427 | MASK="$ipMask";
428 | GATE="$ipGate";
429 | } || {
430 | DEFAULTNET="$(ip route show |grep -o 'default via [0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.*' |head -n1 |sed 's/proto.*\|onlink.*//g' |awk '{print $NF}')";
431 | [[ -n "$DEFAULTNET" ]] && IPSUB="$(ip addr |grep ''${DEFAULTNET}'' |grep 'global' |grep 'brd' |head -n1 |grep -o '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}/[0-9]\{1,2\}')";
432 | IPv4="$(echo -n "$IPSUB" |cut -d'/' -f1)";
433 | NETSUB="$(echo -n "$IPSUB" |grep -o '/[0-9]\{1,2\}')";
434 | GATE="$(ip route show |grep -o 'default via [0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}' |head -n1 |grep -o '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}')";
435 | [[ -n "$NETSUB" ]] && MASK="$(echo -n '128.0.0.0/1,192.0.0.0/2,224.0.0.0/3,240.0.0.0/4,248.0.0.0/5,252.0.0.0/6,254.0.0.0/7,255.0.0.0/8,255.128.0.0/9,255.192.0.0/10,255.224.0.0/11,255.240.0.0/12,255.248.0.0/13,255.252.0.0/14,255.254.0.0/15,255.255.0.0/16,255.255.128.0/17,255.255.192.0/18,255.255.224.0/19,255.255.240.0/20,255.255.248.0/21,255.255.252.0/22,255.255.254.0/23,255.255.255.0/24,255.255.255.128/25,255.255.255.192/26,255.255.255.224/27,255.255.255.240/28,255.255.255.248/29,255.255.255.252/30,255.255.255.254/31,255.255.255.255/32' |grep -o '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}'${NETSUB}'' |cut -d'/' -f1)";
436 | }
437 |
438 | [[ -n "$GATE" ]] && [[ -n "$MASK" ]] && [[ -n "$IPv4" ]] || {
439 | echo "Not found \`ip command\`, It will use \`route command\`."
440 | ipNum() {
441 | local IFS='.';
442 | read ip1 ip2 ip3 ip4 <<<"$1";
443 | echo $((ip1*(1<<24)+ip2*(1<<16)+ip3*(1<<8)+ip4));
444 | }
445 |
446 | SelectMax(){
447 | ii=0;
448 | for IPITEM in `route -n |awk -v OUT=$1 '{print $OUT}' |grep '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}'`
449 | do
450 | NumTMP="$(ipNum $IPITEM)";
451 | eval "arrayNum[$ii]='$NumTMP,$IPITEM'";
452 | ii=$[$ii+1];
453 | done
454 | echo ${arrayNum[@]} |sed 's/\s/\n/g' |sort -n -k 1 -t ',' |tail -n1 |cut -d',' -f2;
455 | }
456 |
457 | [[ -z $IPv4 ]] && IPv4="$(ifconfig |grep 'Bcast' |head -n1 |grep -o '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}' |head -n1)";
458 | [[ -z $GATE ]] && GATE="$(SelectMax 2)";
459 | [[ -z $MASK ]] && MASK="$(SelectMax 3)";
460 |
461 | [[ -n "$GATE" ]] && [[ -n "$MASK" ]] && [[ -n "$IPv4" ]] || {
462 | echo "Error! Not configure network. ";
463 | exit 1;
464 | }
465 | }
466 |
467 | [[ "$setNet" != '1' ]] && [[ -f '/etc/network/interfaces' ]] && {
468 | [[ -z "$(sed -n '/iface.*inet static/p' /etc/network/interfaces)" ]] && AutoNet='1' || AutoNet='0';
469 | [[ -d /etc/network/interfaces.d ]] && {
470 | ICFGN="$(find /etc/network/interfaces.d -name '*.cfg' |wc -l)" || ICFGN='0';
471 | [[ "$ICFGN" -ne '0' ]] && {
472 | for NetCFG in `ls -1 /etc/network/interfaces.d/*.cfg`
473 | do
474 | [[ -z "$(cat $NetCFG | sed -n '/iface.*inet static/p')" ]] && AutoNet='1' || AutoNet='0';
475 | [[ "$AutoNet" -eq '0' ]] && break;
476 | done
477 | }
478 | }
479 | }
480 |
481 | [[ "$setNet" != '1' ]] && [[ -d '/etc/sysconfig/network-scripts' ]] && {
482 | ICFGN="$(find /etc/sysconfig/network-scripts -name 'ifcfg-*' |grep -v 'lo'|wc -l)" || ICFGN='0';
483 | [[ "$ICFGN" -ne '0' ]] && {
484 | for NetCFG in `ls -1 /etc/sysconfig/network-scripts/ifcfg-* |grep -v 'lo$' |grep -v ':[0-9]\{1,\}'`
485 | do
486 | [[ -n "$(cat $NetCFG | sed -n '/BOOTPROTO.*[dD][hH][cC][pP]/p')" ]] && AutoNet='1' || {
487 | AutoNet='0' && . $NetCFG;
488 | [[ -n $NETMASK ]] && MASK="$NETMASK";
489 | [[ -n $GATEWAY ]] && GATE="$GATEWAY";
490 | }
491 | [[ "$AutoNet" -eq '0' ]] && break;
492 | done
493 | }
494 | }
495 |
496 | if [[ "$loaderMode" == "0" ]]; then
497 | [[ ! -f $GRUBDIR/$GRUBFILE ]] && echo "Error! Not Found $GRUBFILE. " && exit 1;
498 |
499 | [[ ! -f $GRUBDIR/$GRUBFILE.old ]] && [[ -f $GRUBDIR/$GRUBFILE.bak ]] && mv -f $GRUBDIR/$GRUBFILE.bak $GRUBDIR/$GRUBFILE.old;
500 | mv -f $GRUBDIR/$GRUBFILE $GRUBDIR/$GRUBFILE.bak;
501 | [[ -f $GRUBDIR/$GRUBFILE.old ]] && cat $GRUBDIR/$GRUBFILE.old >$GRUBDIR/$GRUBFILE || cat $GRUBDIR/$GRUBFILE.bak >$GRUBDIR/$GRUBFILE;
502 | else
503 | GRUBVER='2'
504 | fi
505 |
506 | [[ "$GRUBVER" == '0' ]] && {
507 | READGRUB='/tmp/grub.read'
508 | cat $GRUBDIR/$GRUBFILE |sed -n '1h;1!H;$g;s/\n/%%%%%%%/g;$p' |grep -om 1 'menuentry\ [^{]*{[^}]*}%%%%%%%' |sed 's/%%%%%%%/\n/g' >$READGRUB
509 | LoadNum="$(cat $READGRUB |grep -c 'menuentry ')"
510 | if [[ "$LoadNum" -eq '1' ]]; then
511 | cat $READGRUB |sed '/^$/d' >/tmp/grub.new;
512 | elif [[ "$LoadNum" -gt '1' ]]; then
513 | CFG0="$(awk '/menuentry /{print NR}' $READGRUB|head -n 1)";
514 | CFG2="$(awk '/menuentry /{print NR}' $READGRUB|head -n 2 |tail -n 1)";
515 | CFG1="";
516 | for tmpCFG in `awk '/}/{print NR}' $READGRUB`
517 | do
518 | [ "$tmpCFG" -gt "$CFG0" -a "$tmpCFG" -lt "$CFG2" ] && CFG1="$tmpCFG";
519 | done
520 | [[ -z "$CFG1" ]] && {
521 | echo "Error! read $GRUBFILE. ";
522 | exit 1;
523 | }
524 |
525 | sed -n "$CFG0,$CFG1"p $READGRUB >/tmp/grub.new;
526 | [[ -f /tmp/grub.new ]] && [[ "$(grep -c '{' /tmp/grub.new)" -eq "$(grep -c '}' /tmp/grub.new)" ]] || {
527 | echo -ne "\033[31mError! \033[0mNot configure $GRUBFILE. \n";
528 | exit 1;
529 | }
530 | fi
531 | [ ! -f /tmp/grub.new ] && echo "Error! $GRUBFILE. " && exit 1;
532 | sed -i "/menuentry.*/c\menuentry\ \'Install OS \[$DIST\ $VER\]\'\ --class debian\ --class\ gnu-linux\ --class\ gnu\ --class\ os\ \{" /tmp/grub.new
533 | sed -i "/echo.*Loading/d" /tmp/grub.new;
534 | INSERTGRUB="$(awk '/menuentry /{print NR}' $GRUBDIR/$GRUBFILE|head -n 1)"
535 | }
536 |
537 | [[ "$GRUBVER" == '1' ]] && {
538 | CFG0="$(awk '/title[\ ]|title[\t]/{print NR}' $GRUBDIR/$GRUBFILE|head -n 1)";
539 | CFG1="$(awk '/title[\ ]|title[\t]/{print NR}' $GRUBDIR/$GRUBFILE|head -n 2 |tail -n 1)";
540 | [[ -n $CFG0 ]] && [ -z $CFG1 -o $CFG1 == $CFG0 ] && sed -n "$CFG0,$"p $GRUBDIR/$GRUBFILE >/tmp/grub.new;
541 | [[ -n $CFG0 ]] && [ -z $CFG1 -o $CFG1 != $CFG0 ] && sed -n "$CFG0,$[$CFG1-1]"p $GRUBDIR/$GRUBFILE >/tmp/grub.new;
542 | [[ ! -f /tmp/grub.new ]] && echo "Error! configure append $GRUBFILE. " && exit 1;
543 | sed -i "/title.*/c\title\ \'Install OS \[$DIST\ $VER\]\'" /tmp/grub.new;
544 | sed -i '/^#/d' /tmp/grub.new;
545 | INSERTGRUB="$(awk '/title[\ ]|title[\t]/{print NR}' $GRUBDIR/$GRUBFILE|head -n 1)"
546 | }
547 |
548 | if [[ "$loaderMode" == "0" ]]; then
549 | [[ -n "$(grep 'linux.*/\|kernel.*/' /tmp/grub.new |awk '{print $2}' |tail -n 1 |grep '^/boot/')" ]] && Type='InBoot' || Type='NoBoot';
550 |
551 | LinuxKernel="$(grep 'linux.*/\|kernel.*/' /tmp/grub.new |awk '{print $1}' |head -n 1)";
552 | [[ -z "$LinuxKernel" ]] && echo "Error! read grub config! " && exit 1;
553 | LinuxIMG="$(grep 'initrd.*/' /tmp/grub.new |awk '{print $1}' |tail -n 1)";
554 | [ -z "$LinuxIMG" ] && sed -i "/$LinuxKernel.*\//a\\\tinitrd\ \/" /tmp/grub.new && LinuxIMG='initrd';
555 |
556 | if [[ "$setInterfaceName" == "1" ]]; then
557 | Add_OPTION="net.ifnames=0 biosdevname=0";
558 | else
559 | Add_OPTION="";
560 | fi
561 |
562 | if [[ "$setIPv6" == "1" ]]; then
563 | Add_OPTION="$Add_OPTION ipv6.disable=1";
564 | fi
565 |
566 | if [[ "$linux_relese" == 'debian' ]] || [[ "$linux_relese" == 'ubuntu' ]]; then
567 | BOOT_OPTION="auto=true $Add_OPTION hostname=$linux_relese domain= -- quiet"
568 | elif [[ "$linux_relese" == 'centos' ]]; then
569 | BOOT_OPTION="ks=file://ks.cfg $Add_OPTION ksdevice=$IFETH"
570 | fi
571 |
572 | [[ "$Type" == 'InBoot' ]] && {
573 | sed -i "/$LinuxKernel.*\//c\\\t$LinuxKernel\\t\/boot\/vmlinuz $BOOT_OPTION" /tmp/grub.new;
574 | sed -i "/$LinuxIMG.*\//c\\\t$LinuxIMG\\t\/boot\/initrd.img" /tmp/grub.new;
575 | }
576 |
577 | [[ "$Type" == 'NoBoot' ]] && {
578 | sed -i "/$LinuxKernel.*\//c\\\t$LinuxKernel\\t\/vmlinuz $BOOT_OPTION" /tmp/grub.new;
579 | sed -i "/$LinuxIMG.*\//c\\\t$LinuxIMG\\t\/initrd.img" /tmp/grub.new;
580 | }
581 |
582 | sed -i '$a\\n' /tmp/grub.new;
583 | fi
584 |
585 | [[ "$inVNC" == 'n' ]] && {
586 | GRUBPATCH='0';
587 |
588 | if [[ "$loaderMode" == "0" ]]; then
589 | [ -f '/etc/network/interfaces' -o -d '/etc/sysconfig/network-scripts' ] || {
590 | echo "Error, Not found interfaces config.";
591 | exit 1;
592 | }
593 |
594 | sed -i ''${INSERTGRUB}'i\\n' $GRUBDIR/$GRUBFILE;
595 | sed -i ''${INSERTGRUB}'r /tmp/grub.new' $GRUBDIR/$GRUBFILE;
596 | [[ -f $GRUBDIR/grubenv ]] && sed -i 's/saved_entry/#saved_entry/g' $GRUBDIR/grubenv;
597 | fi
598 |
599 | [[ -d /tmp/boot ]] && rm -rf /tmp/boot;
600 | mkdir -p /tmp/boot;
601 | cd /tmp/boot;
602 | if [[ "$linux_relese" == 'debian' ]] || [[ "$linux_relese" == 'ubuntu' ]]; then
603 | COMPTYPE="gzip";
604 | elif [[ "$linux_relese" == 'centos' ]]; then
605 | COMPTYPE="$(file /boot/initrd.img |grep -o ':.*compressed data' |cut -d' ' -f2 |sed -r 's/(.*)/\L\1/' |head -n1)"
606 | [[ -z "$COMPTYPE" ]] && echo "Detect compressed type fail." && exit 1;
607 | fi
608 | CompDected='0'
609 | for ListCOMP in `echo -en 'gzip\nlzma\nxz'`
610 | do
611 | if [[ "$COMPTYPE" == "$ListCOMP" ]]; then
612 | CompDected='1'
613 | if [[ "$COMPTYPE" == 'gzip' ]]; then
614 | NewIMG="initrd.img.gz"
615 | else
616 | NewIMG="initrd.img.$COMPTYPE"
617 | fi
618 | mv -f "/boot/initrd.img" "/tmp/$NewIMG"
619 | break;
620 | fi
621 | done
622 | [[ "$CompDected" != '1' ]] && echo "Detect compressed type not support." && exit 1;
623 | [[ "$COMPTYPE" == 'lzma' ]] && UNCOMP='xz --format=lzma --decompress';
624 | [[ "$COMPTYPE" == 'xz' ]] && UNCOMP='xz --decompress';
625 | [[ "$COMPTYPE" == 'gzip' ]] && UNCOMP='gzip -d';
626 |
627 | $UNCOMP < /tmp/$NewIMG | cpio --extract --verbose --make-directories --no-absolute-filenames >>/dev/null 2>&1
628 |
629 | if [[ "$linux_relese" == 'debian' ]] || [[ "$linux_relese" == 'ubuntu' ]]; then
630 | cat >/tmp/boot/preseed.cfg<>/dev/null 2>&1
739 | }
740 |
741 | [[ "$ddMode" == '1' ]] && {
742 | WinNoDHCP(){
743 | echo -ne "for\0040\0057f\0040\0042tokens\00753\0052\0042\0040\0045\0045i\0040in\0040\0050\0047netsh\0040interface\0040show\0040interface\0040\0136\0174more\0040\00533\0040\0136\0174findstr\0040\0057I\0040\0057R\0040\0042本地\0056\0052\0040以太\0056\0052\0040Local\0056\0052\0040Ethernet\0042\0047\0051\0040do\0040\0050set\0040EthName\0075\0045\0045j\0051\r\nnetsh\0040\0055c\0040interface\0040ip\0040set\0040address\0040name\0075\0042\0045EthName\0045\0042\0040source\0075static\0040address\0075$IPv4\0040mask\0075$MASK\0040gateway\0075$GATE\r\nnetsh\0040\0055c\0040interface\0040ip\0040add\0040dnsservers\0040name\0075\0042\0045EthName\0045\0042\0040address\00758\00568\00568\00568\0040index\00751\0040validate\0075no\r\n\r\n" >>'/tmp/boot/net.tmp';
744 | }
745 | WinRDP(){
746 | echo -ne "netsh\0040firewall\0040set\0040portopening\0040protocol\0075ALL\0040port\0075$WinRemote\0040name\0075RDP\0040mode\0075ENABLE\0040scope\0075ALL\0040profile\0075ALL\r\nnetsh\0040firewall\0040set\0040portopening\0040protocol\0075ALL\0040port\0075$WinRemote\0040name\0075RDP\0040mode\0075ENABLE\0040scope\0075ALL\0040profile\0075CURRENT\r\nreg\0040add\0040\0042HKLM\0134SYSTEM\0134CurrentControlSet\0134Control\0134Network\0134NewNetworkWindowOff\0042\0040\0057f\r\nreg\0040add\0040\0042HKLM\0134SYSTEM\0134CurrentControlSet\0134Control\0134Terminal\0040Server\0042\0040\0057v\0040fDenyTSConnections\0040\0057t\0040reg\0137dword\0040\0057d\00400\0040\0057f\r\nreg\0040add\0040\0042HKLM\0134SYSTEM\0134CurrentControlSet\0134Control\0134Terminal\0040Server\0134Wds\0134rdpwd\0134Tds\0134tcp\0042\0040\0057v\0040PortNumber\0040\0057t\0040reg\0137dword\0040\0057d\0040$WinRemote\0040\0057f\r\nreg\0040add\0040\0042HKLM\0134SYSTEM\0134CurrentControlSet\0134Control\0134Terminal\0040Server\0134WinStations\0134RDP\0055Tcp\0042\0040\0057v\0040PortNumber\0040\0057t\0040reg\0137dword\0040\0057d\0040$WinRemote\0040\0057f\r\nreg\0040add\0040\0042HKLM\0134SYSTEM\0134CurrentControlSet\0134Control\0134Terminal\0040Server\0134WinStations\0134RDP\0055Tcp\0042\0040\0057v\0040UserAuthentication\0040\0057t\0040reg\0137dword\0040\0057d\00400\0040\0057f\r\nFOR\0040\0057F\0040\0042tokens\00752\0040delims\0075\0072\0042\0040\0045\0045i\0040in\0040\0050\0047SC\0040QUERYEX\0040TermService\0040\0136\0174FINDSTR\0040\0057I\0040\0042PID\0042\0047\0051\0040do\0040TASKKILL\0040\0057F\0040\0057PID\0040\0045\0045i\r\nFOR\0040\0057F\0040\0042tokens\00752\0040delims\0075\0072\0042\0040\0045\0045i\0040in\0040\0050\0047SC\0040QUERYEX\0040UmRdpService\0040\0136\0174FINDSTR\0040\0057I\0040\0042PID\0042\0047\0051\0040do\0040TASKKILL\0040\0057F\0040\0057PID\0040\0045\0045i\r\nSC\0040START\0040TermService\r\n\r\n" >>'/tmp/boot/net.tmp';
747 | }
748 | echo -ne "\0100ECHO\0040OFF\r\n\r\ncd\0056\0076\0045WINDIR\0045\0134GetAdmin\r\nif\0040exist\0040\0045WINDIR\0045\0134GetAdmin\0040\0050del\0040\0057f\0040\0057q\0040\0042\0045WINDIR\0045\0134GetAdmin\0042\0051\0040else\0040\0050\r\necho\0040CreateObject\0136\0050\0042Shell\0056Application\0042\0136\0051\0056ShellExecute\0040\0042\0045\0176s0\0042\0054\0040\0042\0045\0052\0042\0054\0040\0042\0042\0054\0040\0042runas\0042\0054\00401\0040\0076\0076\0040\0042\0045temp\0045\0134Admin\0056vbs\0042\r\n\0042\0045temp\0045\0134Admin\0056vbs\0042\r\ndel\0040\0057f\0040\0057q\0040\0042\0045temp\0045\0134Admin\0056vbs\0042\r\nexit\0040\0057b\00402\0051\r\n\r\n" >'/tmp/boot/net.tmp';
749 | [[ "$setNet" == '1' ]] && WinNoDHCP;
750 | [[ "$setNet" == '0' ]] && [[ "$AutoNet" == '0' ]] && WinNoDHCP;
751 | [[ "$setRDP" == '1' ]] && [[ -n "$WinRemote" ]] && WinRDP
752 | echo -ne "ECHO\0040SELECT\0040VOLUME\0075\0045\0045SystemDrive\0045\0045\0040\0076\0040\0042\0045SystemDrive\0045\0134diskpart\0056extend\0042\r\nECHO\0040EXTEND\0040\0076\0076\0040\0042\0045SystemDrive\0045\0134diskpart\0056extend\0042\r\nSTART\0040/WAIT\0040DISKPART\0040\0057S\0040\0042\0045SystemDrive\0045\0134diskpart\0056extend\0042\r\nDEL\0040\0057f\0040\0057q\0040\0042\0045SystemDrive\0045\0134diskpart\0056extend\0042\r\n\r\n" >>'/tmp/boot/net.tmp';
753 | echo -ne "cd\0040\0057d\0040\0042\0045ProgramData\0045\0057Microsoft\0057Windows\0057Start\0040Menu\0057Programs\0057Startup\0042\r\ndel\0040\0057f\0040\0057q\0040net\0056bat\r\n\r\n\r\n" >>'/tmp/boot/net.tmp';
754 | iconv -f 'UTF-8' -t 'GBK' '/tmp/boot/net.tmp' -o '/tmp/boot/net.bat'
755 | rm -rf '/tmp/boot/net.tmp'
756 | echo "$DDURL" |grep -q '^https://'
757 | [[ $? -eq '0' ]] && {
758 | echo -ne '\nAdd ssl support...\n'
759 | [[ -n $SSL_SUPPORT ]] && {
760 | wget --no-check-certificate -qO- "$SSL_SUPPORT" |tar -x
761 | [[ ! -f /tmp/boot/usr/bin/wget ]] && echo 'Error! SSL_SUPPORT.' && exit 1;
762 | sed -i 's/wget\ -qO-/\/usr\/bin\/wget\ --no-check-certificate\ --retry-connrefused\ --tries=7\ --continue\ -qO-/g' /tmp/boot/preseed.cfg
763 | [[ $? -eq '0' ]] && echo -ne 'Success! \n\n'
764 | } || {
765 | echo -ne 'Not ssl support package! \n\n';
766 | exit 1;
767 | }
768 | }
769 | }
770 |
771 | [[ "$ddMode" == '0' ]] && {
772 | sed -i '/anna-install/d' /tmp/boot/preseed.cfg
773 | sed -i 's/wget.*\/sbin\/reboot\;\ //g' /tmp/boot/preseed.cfg
774 | }
775 |
776 | elif [[ "$linux_relese" == 'centos' ]]; then
777 | cat >/tmp/boot/ks.cfg< /boot/initrd.img;
823 | rm -rf /tmp/boot;
824 | }
825 |
826 | [[ "$inVNC" == 'y' ]] && {
827 | sed -i '$i\\n' $GRUBDIR/$GRUBFILE
828 | sed -i '$r /tmp/grub.new' $GRUBDIR/$GRUBFILE
829 | echo -e "\n\033[33m\033[04mIt will reboot! \nPlease connect VNC! \nSelect\033[0m\033[32m Install OS [$DIST $VER] \033[33m\033[4mto install system.\033[04m\n\n\033[31m\033[04mThere is some information for you.\nDO NOT CLOSE THE WINDOW! \033[0m\n"
830 | echo -e "\033[35mIPv4\t\tNETMASK\t\tGATEWAY\033[0m"
831 | echo -e "\033[36m\033[04m$IPv4\033[0m\t\033[36m\033[04m$MASK\033[0m\t\033[36m\033[04m$GATE\033[0m\n\n"
832 |
833 | read -n 1 -p "Press Enter to reboot..." INP
834 | [[ "$INP" != '' ]] && echo -ne '\b \n\n';
835 | }
836 |
837 | chown root:root $GRUBDIR/$GRUBFILE
838 | chmod 444 $GRUBDIR/$GRUBFILE
839 |
840 | if [[ "$loaderMode" == "0" ]]; then
841 | sleep 3 && reboot >/dev/null 2>&1
842 | else
843 | rm -rf "$HOME/loader"
844 | mkdir -p "$HOME/loader"
845 | cp -rf "/boot/initrd.img" "$HOME/loader/initrd.img"
846 | cp -rf "/boot/vmlinuz" "$HOME/loader/vmlinuz"
847 | [[ -f "/boot/initrd.img" ]] && rm -rf "/boot/initrd.img"
848 | [[ -f "/boot/vmlinuz" ]] && rm -rf "/boot/vmlinuz"
849 | echo && ls -AR1 "$HOME/loader"
850 | fi
851 |
--------------------------------------------------------------------------------