HirCoir commited on
Commit
efc1570
·
verified ·
1 Parent(s): ebb4af0

Upload InstallNET.sh

Browse files
Files changed (1) hide show
  1. InstallNET.sh +796 -0
InstallNET.sh ADDED
@@ -0,0 +1,796 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ export tmpVER=''
10
+ export tmpDIST=''
11
+ export tmpURL=''
12
+ export tmpWORD=''
13
+ export tmpMirror=''
14
+ export ipAddr=''
15
+ export ipMask=''
16
+ export ipGate=''
17
+ export ipDNS='8.8.8.8'
18
+ export IncDisk='default'
19
+ export interface=''
20
+ export interfaceSelect=''
21
+ export Relese=''
22
+ export sshPORT='22'
23
+ export ddMode='0'
24
+ export setNet='0'
25
+ export setRDP='0'
26
+ export setIPv6='0'
27
+ export isMirror='0'
28
+ export FindDists='0'
29
+ export loaderMode='0'
30
+ export IncFirmware='0'
31
+ export SpikCheckDIST='0'
32
+ export setInterfaceName='0'
33
+ export UNKNOWHW='0'
34
+ export UNVER='6.4'
35
+ export GRUBDIR=''
36
+ export GRUBFILE=''
37
+ export GRUBVER=''
38
+ export VER=''
39
+ export setCMD=''
40
+ export setConsole=''
41
+
42
+ while [[ $# -ge 1 ]]; do
43
+ case $1 in
44
+ -v|--ver)
45
+ shift
46
+ tmpVER="$1"
47
+ shift
48
+ ;;
49
+ -d|--debian)
50
+ shift
51
+ Relese='Debian'
52
+ tmpDIST="$1"
53
+ shift
54
+ ;;
55
+ -u|--ubuntu)
56
+ shift
57
+ Relese='Ubuntu'
58
+ tmpDIST="$1"
59
+ shift
60
+ ;;
61
+ -c|--centos)
62
+ shift
63
+ Relese='CentOS'
64
+ tmpDIST="$1"
65
+ shift
66
+ ;;
67
+ -dd|--image)
68
+ shift
69
+ ddMode='1'
70
+ tmpURL="$1"
71
+ shift
72
+ ;;
73
+ -p|--password)
74
+ shift
75
+ tmpWORD="$1"
76
+ shift
77
+ ;;
78
+ -i|--interface)
79
+ shift
80
+ interfaceSelect="$1"
81
+ shift
82
+ ;;
83
+ --ip-addr)
84
+ shift
85
+ ipAddr="$1"
86
+ shift
87
+ ;;
88
+ --ip-mask)
89
+ shift
90
+ ipMask="$1"
91
+ shift
92
+ ;;
93
+ --ip-gate)
94
+ shift
95
+ ipGate="$1"
96
+ shift
97
+ ;;
98
+ --ip-dns)
99
+ shift
100
+ ipDNS="$1"
101
+ shift
102
+ ;;
103
+ --dev-net)
104
+ shift
105
+ setInterfaceName='1'
106
+ ;;
107
+ --loader)
108
+ shift
109
+ loaderMode='1'
110
+ ;;
111
+ -apt|-yum|--mirror)
112
+ shift
113
+ isMirror='1'
114
+ tmpMirror="$1"
115
+ shift
116
+ ;;
117
+ -rdp)
118
+ shift
119
+ setRDP='1'
120
+ WinRemote="$1"
121
+ shift
122
+ ;;
123
+ -cmd)
124
+ shift
125
+ setCMD="$1"
126
+ shift
127
+ ;;
128
+ -console)
129
+ shift
130
+ setConsole="$1"
131
+ shift
132
+ ;;
133
+ -firmware)
134
+ shift
135
+ IncFirmware="1"
136
+ ;;
137
+ -port)
138
+ shift
139
+ sshPORT="$1"
140
+ shift
141
+ ;;
142
+ --noipv6)
143
+ shift
144
+ setIPv6='1'
145
+ ;;
146
+ -a|--auto|-m|--manual|-ssl)
147
+ shift
148
+ ;;
149
+ *)
150
+ if [[ "$1" != 'error' ]]; then echo -ne "\nInvaild option: '$1'\n\n"; fi
151
+ 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[04mdists-name\033[0m]\n\t\t\t\t-v/--ver [32/i386|64/\033[33m\033[04mamd64\033[0m] [\033[33m\033[04mdists-verison\033[0m]\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-p [linux password]\n\t\t\t\t-port [linux ssh port]\n"
152
+ exit 1;
153
+ ;;
154
+ esac
155
+ done
156
+
157
+ [[ "$EUID" -ne '0' ]] && echo "Error:This script must be run as root!" && exit 1;
158
+
159
+ function dependence(){
160
+ Full='0';
161
+ for BIN_DEP in `echo "$1" |sed 's/,/\n/g'`
162
+ do
163
+ if [[ -n "$BIN_DEP" ]]; then
164
+ Found='0';
165
+ for BIN_PATH in `echo "$PATH" |sed 's/:/\n/g'`
166
+ do
167
+ ls $BIN_PATH/$BIN_DEP >/dev/null 2>&1;
168
+ if [ $? == '0' ]; then
169
+ Found='1';
170
+ break;
171
+ fi
172
+ done
173
+ if [ "$Found" == '1' ]; then
174
+ echo -en "[\033[32mok\033[0m]\t";
175
+ else
176
+ Full='1';
177
+ echo -en "[\033[31mNot Install\033[0m]";
178
+ fi
179
+ echo -en "\t$BIN_DEP\n";
180
+ fi
181
+ done
182
+ if [ "$Full" == '1' ]; then
183
+ echo -ne "\n\033[31mError! \033[0mPlease use '\033[33mapt-get\033[0m' or '\033[33myum\033[0m' install it.\n\n\n"
184
+ exit 1;
185
+ fi
186
+ }
187
+
188
+ function selectMirror(){
189
+ [ $# -ge 3 ] || exit 1
190
+ Relese=$(echo "$1" |sed -r 's/(.*)/\L\1/')
191
+ DIST=$(echo "$2" |sed 's/\ //g' |sed -r 's/(.*)/\L\1/')
192
+ VER=$(echo "$3" |sed 's/\ //g' |sed -r 's/(.*)/\L\1/')
193
+ New=$(echo "$4" |sed 's/\ //g')
194
+ [ -n "$Relese" ] && [ -n "$DIST" ] && [ -n "$VER" ] || exit 1
195
+ if [ "$Relese" == "debian" ] || [ "$Relese" == "ubuntu" ]; then
196
+ [ "$DIST" == "focal" ] && legacy="legacy-" || legacy=""
197
+ TEMP="SUB_MIRROR/dists/${DIST}/main/installer-${VER}/current/${legacy}images/netboot/${Relese}-installer/${VER}/initrd.gz"
198
+ elif [ "$Relese" == "centos" ]; then
199
+ TEMP="SUB_MIRROR/${DIST}/os/${VER}/isolinux/initrd.img"
200
+ fi
201
+ [ -n "$TEMP" ] || exit 1
202
+ mirrorStatus=0
203
+ declare -A MirrorBackup
204
+ MirrorBackup=(["debian0"]="" ["debian1"]="http://deb.debian.org/debian" ["debian2"]="http://archive.debian.org/debian" ["ubuntu0"]="" ["ubuntu1"]="http://archive.ubuntu.com/ubuntu" ["ubuntu2"]="http://ports.ubuntu.com" ["centos0"]="" ["centos1"]="http://mirror.centos.org/centos" ["centos2"]="http://vault.centos.org")
205
+ echo "$New" |grep -q '^http://\|^https://\|^ftp://' && MirrorBackup[${Relese}0]="$New"
206
+ for mirror in $(echo "${!MirrorBackup[@]}" |sed 's/\ /\n/g' |sort -n |grep "^$Relese")
207
+ do
208
+ Current="${MirrorBackup[$mirror]}"
209
+ [ -n "$Current" ] || continue
210
+ MirrorURL=`echo "$TEMP" |sed "s#SUB_MIRROR#${Current}#g"`
211
+ wget --no-check-certificate --spider --timeout=3 -o /dev/null "$MirrorURL"
212
+ [ $? -eq 0 ] && mirrorStatus=1 && break
213
+ done
214
+ [ $mirrorStatus -eq 1 ] && echo "$Current" || exit 1
215
+ }
216
+
217
+ function netmask() {
218
+ n="${1:-32}"
219
+ b=""
220
+ m=""
221
+ for((i=0;i<32;i++)){
222
+ [ $i -lt $n ] && b="${b}1" || b="${b}0"
223
+ }
224
+ for((i=0;i<4;i++)){
225
+ s=`echo "$b"|cut -c$[$[$i*8]+1]-$[$[$i+1]*8]`
226
+ [ "$m" == "" ] && m="$((2#${s}))" || m="${m}.$((2#${s}))"
227
+ }
228
+ echo "$m"
229
+ }
230
+
231
+ function getInterface(){
232
+ interface=""
233
+ Interfaces=`cat /proc/net/dev |grep ':' |cut -d':' -f1 |sed 's/\s//g' |grep -iv '^lo\|^sit\|^stf\|^gif\|^dummy\|^vmnet\|^vir\|^gre\|^ipip\|^ppp\|^bond\|^tun\|^tap\|^ip6gre\|^ip6tnl\|^teql\|^ocserv\|^vpn'`
234
+ defaultRoute=`ip route show default |grep "^default"`
235
+ for item in `echo "$Interfaces"`
236
+ do
237
+ [ -n "$item" ] || continue
238
+ echo "$defaultRoute" |grep -q "$item"
239
+ [ $? -eq 0 ] && interface="$item" && break
240
+ done
241
+ echo "$interface"
242
+ }
243
+
244
+ function getDisk(){
245
+ disks=`lsblk | sed 's/[[:space:]]*$//g' |grep "disk$" |cut -d' ' -f1 |grep -v "fd[0-9]*\|sr[0-9]*" |head -n1`
246
+ [ -n "$disks" ] || echo ""
247
+ echo "$disks" |grep -q "/dev"
248
+ [ $? -eq 0 ] && echo "$disks" || echo "/dev/$disks"
249
+ }
250
+
251
+ function diskType(){
252
+ echo `udevadm info --query all "$1" 2>/dev/null |grep 'ID_PART_TABLE_TYPE' |cut -d'=' -f2`
253
+ }
254
+
255
+ function getGrub(){
256
+ Boot="${1:-/boot}"
257
+ folder=`find "$Boot" -type d -name "grub*" 2>/dev/null |head -n1`
258
+ [ -n "$folder" ] || return
259
+ fileName=`ls -1 "$folder" 2>/dev/null |grep '^grub.conf$\|^grub.cfg$'`
260
+ if [ -z "$fileName" ]; then
261
+ ls -1 "$folder" 2>/dev/null |grep -q '^grubenv$'
262
+ [ $? -eq 0 ] || return
263
+ folder=`find "$Boot" -type f -name "grubenv" 2>/dev/null |xargs dirname |grep -v "^$folder" |head -n1`
264
+ [ -n "$folder" ] || return
265
+ fileName=`ls -1 "$folder" 2>/dev/null |grep '^grub.conf$\|^grub.cfg$'`
266
+ fi
267
+ [ -n "$fileName" ] || return
268
+ [ "$fileName" == "grub.cfg" ] && ver="0" || ver="1"
269
+ echo "${folder}:${fileName}:${ver}"
270
+ }
271
+
272
+ function lowMem(){
273
+ mem=`grep "^MemTotal:" /proc/meminfo 2>/dev/null |grep -o "[0-9]*"`
274
+ [ -n "$mem" ] || return 0
275
+ [ "$mem" -le "524288" ] && return 1 || return 0
276
+ }
277
+
278
+ if [[ "$loaderMode" == "0" ]]; then
279
+ Grub=`getGrub "/boot"`
280
+ [ -z "$Grub" ] && echo -ne "Error! Not Found grub.\n" && exit 1;
281
+ GRUBDIR=`echo "$Grub" |cut -d':' -f1`
282
+ GRUBFILE=`echo "$Grub" |cut -d':' -f2`
283
+ GRUBVER=`echo "$Grub" |cut -d':' -f3`
284
+ fi
285
+
286
+ [ -n "$Relese" ] || Relese='Debian'
287
+ linux_relese=$(echo "$Relese" |sed 's/\ //g' |sed -r 's/(.*)/\L\1/')
288
+ clear && echo -e "\n\033[36m# Check Dependence\033[0m\n"
289
+
290
+ if [[ "$ddMode" == '1' ]]; then
291
+ dependence iconv;
292
+ linux_relese='debian';
293
+ tmpDIST='bullseye';
294
+ tmpVER='amd64';
295
+ fi
296
+
297
+ [ -n "$ipAddr" ] && [ -n "$ipMask" ] && [ -n "$ipGate" ] && setNet='1';
298
+ if [ "$setNet" == "0" ]; then
299
+ dependence ip
300
+ [ -n "$interface" ] || interface=`getInterface`
301
+ iAddr=`ip addr show dev $interface |grep "inet.*" |head -n1 |grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\/[0-9]\{1,2\}'`
302
+ ipAddr=`echo ${iAddr} |cut -d'/' -f1`
303
+ ipMask=`netmask $(echo ${iAddr} |cut -d'/' -f2)`
304
+ ipGate=`ip route show default |grep "^default" |grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' |head -n1`
305
+ fi
306
+ if [ -z "$interface" ]; then
307
+ dependence ip
308
+ [ -n "$interface" ] || interface=`getInterface`
309
+ fi
310
+ IPv4="$ipAddr"; MASK="$ipMask"; GATE="$ipGate";
311
+
312
+ [ -n "$IPv4" ] && [ -n "$MASK" ] && [ -n "$GATE" ] && [ -n "$ipDNS" ] || {
313
+ echo -ne '\nError: Invalid network config\n\n'
314
+ bash $0 error;
315
+ exit 1;
316
+ }
317
+
318
+ if [[ "$Relese" == 'Debian' ]] || [[ "$Relese" == 'Ubuntu' ]]; then
319
+ dependence wget,awk,grep,sed,cut,cat,lsblk,cpio,gzip,find,dirname,basename;
320
+ elif [[ "$Relese" == 'CentOS' ]]; then
321
+ dependence wget,awk,grep,sed,cut,cat,lsblk,cpio,gzip,find,dirname,basename,file,xz;
322
+ fi
323
+ [ -n "$tmpWORD" ] && dependence openssl
324
+ [[ -n "$tmpWORD" ]] && myPASSWORD="$(openssl passwd -1 "$tmpWORD")";
325
+ [[ -z "$myPASSWORD" ]] && myPASSWORD='$1$4BJZaD0A$y1QykUnJ6mXprENfwpseH0';
326
+
327
+ tempDisk=`getDisk`; [ -n "$tempDisk" ] && IncDisk="$tempDisk"
328
+
329
+ case `uname -m` in aarch64|arm64) VER="arm64";; x86|i386|i686) VER="i386";; x86_64|amd64) VER="amd64";; *) VER="";; esac
330
+ tmpVER="$(echo "$tmpVER" |sed -r 's/(.*)/\L\1/')";
331
+ if [[ "$VER" != "arm64" ]] && [[ -n "$tmpVER" ]]; then
332
+ case "$tmpVER" in i386|i686|x86|32) VER="i386";; amd64|x86_64|x64|64) [[ "$Relese" == 'CentOS' ]] && VER='x86_64' || VER='amd64';; *) VER='';; esac
333
+ fi
334
+
335
+ if [[ ! -n "$VER" ]]; then
336
+ echo "Error! Not Architecture."
337
+ bash $0 error;
338
+ exit 1;
339
+ fi
340
+
341
+ if [[ -z "$tmpDIST" ]]; then
342
+ [ "$Relese" == 'Debian' ] && tmpDIST='buster';
343
+ [ "$Relese" == 'Ubuntu' ] && tmpDIST='bionic';
344
+ [ "$Relese" == 'CentOS' ] && tmpDIST='6.10';
345
+ fi
346
+
347
+ if [[ -n "$tmpDIST" ]]; then
348
+ if [[ "$Relese" == 'Debian' ]]; then
349
+ SpikCheckDIST='0'
350
+ DIST="$(echo "$tmpDIST" |sed -r 's/(.*)/\L\1/')";
351
+ echo "$DIST" |grep -q '[0-9]';
352
+ [[ $? -eq '0' ]] && {
353
+ isDigital="$(echo "$DIST" |grep -o '[\.0-9]\{1,\}' |sed -n '1h;1!H;$g;s/\n//g;$p' |cut -d'.' -f1)";
354
+ [[ -n $isDigital ]] && {
355
+ [[ "$isDigital" == '7' ]] && DIST='wheezy';
356
+ [[ "$isDigital" == '8' ]] && DIST='jessie';
357
+ [[ "$isDigital" == '9' ]] && DIST='stretch';
358
+ [[ "$isDigital" == '10' ]] && DIST='buster';
359
+ [[ "$isDigital" == '11' ]] && DIST='bullseye';
360
+ # [[ "$isDigital" == '12' ]] && DIST='bookworm';
361
+ }
362
+ }
363
+ LinuxMirror=$(selectMirror "$Relese" "$DIST" "$VER" "$tmpMirror")
364
+ fi
365
+ if [[ "$Relese" == 'Ubuntu' ]]; then
366
+ SpikCheckDIST='0'
367
+ DIST="$(echo "$tmpDIST" |sed -r 's/(.*)/\L\1/')";
368
+ echo "$DIST" |grep -q '[0-9]';
369
+ [[ $? -eq '0' ]] && {
370
+ isDigital="$(echo "$DIST" |grep -o '[\.0-9]\{1,\}' |sed -n '1h;1!H;$g;s/\n//g;$p')";
371
+ [[ -n $isDigital ]] && {
372
+ [[ "$isDigital" == '12.04' ]] && DIST='precise';
373
+ [[ "$isDigital" == '14.04' ]] && DIST='trusty';
374
+ [[ "$isDigital" == '16.04' ]] && DIST='xenial';
375
+ [[ "$isDigital" == '18.04' ]] && DIST='bionic';
376
+ [[ "$isDigital" == '20.04' ]] && DIST='focal';
377
+ # [[ "$isDigital" == '22.04' ]] && DIST='jammy';
378
+ }
379
+ }
380
+ LinuxMirror=$(selectMirror "$Relese" "$DIST" "$VER" "$tmpMirror")
381
+ fi
382
+ if [[ "$Relese" == 'CentOS' ]]; then
383
+ SpikCheckDIST='1'
384
+ DISTCheck="$(echo "$tmpDIST" |grep -o '[\.0-9]\{1,\}' |head -n1)";
385
+ LinuxMirror=$(selectMirror "$Relese" "$DISTCheck" "$VER" "$tmpMirror")
386
+ ListDIST="$(wget --no-check-certificate -qO- "$LinuxMirror/dir_sizes" |cut -f2 |grep '^[0-9]')"
387
+ DIST="$(echo "$ListDIST" |grep "^$DISTCheck" |head -n1)"
388
+ [[ -z "$DIST" ]] && {
389
+ echo -ne '\nThe dists version not found in this mirror, Please check it! \n\n'
390
+ bash $0 error;
391
+ exit 1;
392
+ }
393
+ wget --no-check-certificate -qO- "$LinuxMirror/$DIST/os/$VER/.treeinfo" |grep -q 'general';
394
+ [[ $? != '0' ]] && {
395
+ echo -ne "\nThe version not found in this mirror, Please change mirror try again! \n\n";
396
+ exit 1;
397
+ }
398
+ fi
399
+ fi
400
+
401
+ if [[ -z "$LinuxMirror" ]]; then
402
+ echo -ne "\033[31mError! \033[0mInvaild mirror! \n"
403
+ [ "$Relese" == 'Debian' ] && echo -en "\033[33mexample:\033[0m http://deb.debian.org/debian\n\n";
404
+ [ "$Relese" == 'Ubuntu' ] && echo -en "\033[33mexample:\033[0m http://archive.ubuntu.com/ubuntu\n\n";
405
+ [ "$Relese" == 'CentOS' ] && echo -en "\033[33mexample:\033[0m http://mirror.centos.org/centos\n\n";
406
+ bash $0 error;
407
+ exit 1;
408
+ fi
409
+
410
+ if [[ "$SpikCheckDIST" == '0' ]]; then
411
+ 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')";
412
+ for CheckDEB in `echo "$DistsList" |sed 's/;/\n/g'`
413
+ do
414
+ [[ "$CheckDEB" == "$DIST" ]] && FindDists='1' && break;
415
+ done
416
+ [[ "$FindDists" == '0' ]] && {
417
+ echo -ne '\nThe dists version not found, Please check it! \n\n'
418
+ bash $0 error;
419
+ exit 1;
420
+ }
421
+ fi
422
+
423
+ if [[ "$ddMode" == '1' ]]; then
424
+ if [[ -n "$tmpURL" ]]; then
425
+ DDURL="$tmpURL"
426
+ echo "$DDURL" |grep -q '^http://\|^ftp://\|^https://';
427
+ [[ $? -ne '0' ]] && echo 'Please input vaild URL,Only support http://, ftp:// and https:// !' && exit 1;
428
+ else
429
+ echo 'Please input vaild image URL! ';
430
+ exit 1;
431
+ fi
432
+ fi
433
+
434
+ clear && echo -e "\n\033[36m# Install\033[0m\n"
435
+
436
+ [[ "$ddMode" == '1' ]] && echo -ne "\033[34mAuto Mode\033[0m insatll \033[33mWindows\033[0m\n[\033[33m$DDURL\033[0m]\n"
437
+
438
+ if [ -z "$interfaceSelect" ]; then
439
+ if [[ "$linux_relese" == 'debian' ]] || [[ "$linux_relese" == 'ubuntu' ]]; then
440
+ interfaceSelect="auto"
441
+ elif [[ "$linux_relese" == 'centos' ]]; then
442
+ interfaceSelect="link"
443
+ fi
444
+ fi
445
+
446
+ if [[ "$linux_relese" == 'centos' ]]; then
447
+ if [[ "$DIST" != "$UNVER" ]]; then
448
+ awk 'BEGIN{print '${UNVER}'-'${DIST}'}' |grep -q '^-'
449
+ if [ $? != '0' ]; then
450
+ UNKNOWHW='1';
451
+ echo -en "\033[33mThe version lower then \033[31m$UNVER\033[33m may not support in auto mode! \033[0m\n";
452
+ fi
453
+ awk 'BEGIN{print '${UNVER}'-'${DIST}'+0.59}' |grep -q '^-'
454
+ if [ $? == '0' ]; then
455
+ echo -en "\n\033[31mThe version higher then \033[33m6.10 \033[31mis not support in current! \033[0m\n\n"
456
+ exit 1;
457
+ fi
458
+ fi
459
+ fi
460
+
461
+ echo -e "\n[\033[33m$Relese\033[0m] [\033[33m$DIST\033[0m] [\033[33m$VER\033[0m] Downloading..."
462
+
463
+ if [[ "$linux_relese" == 'debian' ]] || [[ "$linux_relese" == 'ubuntu' ]]; then
464
+ [ "$DIST" == "focal" ] && legacy="legacy-" || legacy=""
465
+ wget --no-check-certificate -qO '/tmp/initrd.img' "${LinuxMirror}/dists/${DIST}/main/installer-${VER}/current/${legacy}images/netboot/${linux_relese}-installer/${VER}/initrd.gz"
466
+ [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'initrd.img' for \033[33m$linux_relese\033[0m failed! \n" && exit 1
467
+ wget --no-check-certificate -qO '/tmp/vmlinuz' "${LinuxMirror}/dists/${DIST}${inUpdate}/main/installer-${VER}/current/${legacy}images/netboot/${linux_relese}-installer/${VER}/linux"
468
+ [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'vmlinuz' for \033[33m$linux_relese\033[0m failed! \n" && exit 1
469
+ MirrorHost="$(echo "$LinuxMirror" |awk -F'://|/' '{print $2}')";
470
+ MirrorFolder="$(echo "$LinuxMirror" |awk -F''${MirrorHost}'' '{print $2}')";
471
+ [ -n "$MirrorFolder" ] || MirrorFolder="/"
472
+ elif [[ "$linux_relese" == 'centos' ]]; then
473
+ wget --no-check-certificate -qO '/tmp/initrd.img' "${LinuxMirror}/${DIST}/os/${VER}/isolinux/initrd.img"
474
+ [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'initrd.img' for \033[33m$linux_relese\033[0m failed! \n" && exit 1
475
+ wget --no-check-certificate -qO '/tmp/vmlinuz' "${LinuxMirror}/${DIST}/os/${VER}/isolinux/vmlinuz"
476
+ [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'vmlinuz' for \033[33m$linux_relese\033[0m failed! \n" && exit 1
477
+ else
478
+ bash $0 error;
479
+ exit 1;
480
+ fi
481
+ if [[ "$linux_relese" == 'debian' ]]; then
482
+ if [[ "$IncFirmware" == '1' ]]; then
483
+ wget --no-check-certificate -qO '/tmp/firmware.cpio.gz' "http://cdimage.debian.org/cdimage/unofficial/non-free/firmware/${DIST}/current/firmware.cpio.gz"
484
+ [[ $? -ne '0' ]] && echo -ne "\033[31mError! \033[0mDownload 'firmware' for \033[33m$linux_relese\033[0m failed! \n" && exit 1
485
+ fi
486
+ if [[ "$ddMode" == '1' ]]; then
487
+ 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)
488
+ [[ -z "vKernel_udeb" ]] && vKernel_udeb="4.19.0-17"
489
+ fi
490
+ fi
491
+
492
+ if [[ "$loaderMode" == "0" ]]; then
493
+ [[ ! -f "${GRUBDIR}/${GRUBFILE}" ]] && echo "Error! Not Found ${GRUBFILE}. " && exit 1;
494
+
495
+ [[ ! -f "${GRUBDIR}/${GRUBFILE}.old" ]] && [[ -f "${GRUBDIR}/${GRUBFILE}.bak" ]] && mv -f "${GRUBDIR}/${GRUBFILE}.bak" "${GRUBDIR}/${GRUBFILE}.old";
496
+ mv -f "${GRUBDIR}/${GRUBFILE}" "${GRUBDIR}/${GRUBFILE}.bak";
497
+ [[ -f "${GRUBDIR}/${GRUBFILE}.old" ]] && cat "${GRUBDIR}/${GRUBFILE}.old" >"${GRUBDIR}/${GRUBFILE}" || cat "${GRUBDIR}/${GRUBFILE}.bak" >"${GRUBDIR}/${GRUBFILE}";
498
+ else
499
+ GRUBVER='-1'
500
+ fi
501
+
502
+ [[ "$GRUBVER" == '0' ]] && {
503
+ READGRUB='/tmp/grub.read'
504
+ cat $GRUBDIR/$GRUBFILE |sed -n '1h;1!H;$g;s/\n/%%%%%%%/g;$p' |grep -om 1 'menuentry\ [^{]*{[^}]*}%%%%%%%' |sed 's/%%%%%%%/\n/g' >$READGRUB
505
+ LoadNum="$(cat $READGRUB |grep -c 'menuentry ')"
506
+ if [[ "$LoadNum" -eq '1' ]]; then
507
+ cat $READGRUB |sed '/^$/d' >/tmp/grub.new;
508
+ elif [[ "$LoadNum" -gt '1' ]]; then
509
+ CFG0="$(awk '/menuentry /{print NR}' $READGRUB|head -n 1)";
510
+ CFG2="$(awk '/menuentry /{print NR}' $READGRUB|head -n 2 |tail -n 1)";
511
+ CFG1="";
512
+ for tmpCFG in `awk '/}/{print NR}' $READGRUB`
513
+ do
514
+ [ "$tmpCFG" -gt "$CFG0" -a "$tmpCFG" -lt "$CFG2" ] && CFG1="$tmpCFG";
515
+ done
516
+ [[ -z "$CFG1" ]] && {
517
+ echo "Error! read $GRUBFILE. ";
518
+ exit 1;
519
+ }
520
+
521
+ sed -n "$CFG0,$CFG1"p $READGRUB >/tmp/grub.new;
522
+ [[ -f /tmp/grub.new ]] && [[ "$(grep -c '{' /tmp/grub.new)" -eq "$(grep -c '}' /tmp/grub.new)" ]] || {
523
+ echo -ne "\033[31mError! \033[0mNot configure $GRUBFILE. \n";
524
+ exit 1;
525
+ }
526
+ fi
527
+ [ ! -f /tmp/grub.new ] && echo "Error! $GRUBFILE. " && exit 1;
528
+ sed -i "/menuentry.*/c\menuentry\ \'Install OS \[$DIST\ $VER\]\'\ --class debian\ --class\ gnu-linux\ --class\ gnu\ --class\ os\ \{" /tmp/grub.new
529
+ sed -i "/echo.*Loading/d" /tmp/grub.new;
530
+ INSERTGRUB="$(awk '/menuentry /{print NR}' $GRUBDIR/$GRUBFILE|head -n 1)"
531
+ }
532
+
533
+ [[ "$GRUBVER" == '1' ]] && {
534
+ CFG0="$(awk '/title[\ ]|title[\t]/{print NR}' $GRUBDIR/$GRUBFILE|head -n 1)";
535
+ CFG1="$(awk '/title[\ ]|title[\t]/{print NR}' $GRUBDIR/$GRUBFILE|head -n 2 |tail -n 1)";
536
+ [[ -n $CFG0 ]] && [ -z $CFG1 -o $CFG1 == $CFG0 ] && sed -n "$CFG0,$"p $GRUBDIR/$GRUBFILE >/tmp/grub.new;
537
+ [[ -n $CFG0 ]] && [ -z $CFG1 -o $CFG1 != $CFG0 ] && sed -n "$CFG0,$[$CFG1-1]"p $GRUBDIR/$GRUBFILE >/tmp/grub.new;
538
+ [[ ! -f /tmp/grub.new ]] && echo "Error! configure append $GRUBFILE. " && exit 1;
539
+ sed -i "/title.*/c\title\ \'Install OS \[$DIST\ $VER\]\'" /tmp/grub.new;
540
+ sed -i '/^#/d' /tmp/grub.new;
541
+ INSERTGRUB="$(awk '/title[\ ]|title[\t]/{print NR}' $GRUBDIR/$GRUBFILE|head -n 1)"
542
+ }
543
+
544
+ if [[ "$loaderMode" == "0" ]]; then
545
+ [[ -n "$(grep 'linux.*/\|kernel.*/' /tmp/grub.new |awk '{print $2}' |tail -n 1 |grep '^/boot/')" ]] && Type='InBoot' || Type='NoBoot';
546
+
547
+ LinuxKernel="$(grep 'linux.*/\|kernel.*/' /tmp/grub.new |awk '{print $1}' |head -n 1)";
548
+ [[ -z "$LinuxKernel" ]] && echo "Error! read grub config! " && exit 1;
549
+ LinuxIMG="$(grep 'initrd.*/' /tmp/grub.new |awk '{print $1}' |tail -n 1)";
550
+ [ -z "$LinuxIMG" ] && sed -i "/$LinuxKernel.*\//a\\\tinitrd\ \/" /tmp/grub.new && LinuxIMG='initrd';
551
+
552
+ [[ "$setInterfaceName" == "1" ]] && Add_OPTION="net.ifnames=0 biosdevname=0" || Add_OPTION=""
553
+ [[ "$setIPv6" == "1" ]] && Add_OPTION="$Add_OPTION ipv6.disable=1"
554
+
555
+ lowMem || Add_OPTION="$Add_OPTION lowmem=+0"
556
+
557
+ if [[ "$linux_relese" == 'debian' ]] || [[ "$linux_relese" == 'ubuntu' ]]; then
558
+ BOOT_OPTION="auto=true $Add_OPTION hostname=$linux_relese domain=$linux_relese quiet"
559
+ elif [[ "$linux_relese" == 'centos' ]]; then
560
+ BOOT_OPTION="ks=file://ks.cfg $Add_OPTION ksdevice=$interfaceSelect"
561
+ fi
562
+
563
+ [ -n "$setConsole" ] && BOOT_OPTION="$BOOT_OPTION --- console=$setConsole"
564
+
565
+ [[ "$Type" == 'InBoot' ]] && {
566
+ sed -i "/$LinuxKernel.*\//c\\\t$LinuxKernel\\t\/boot\/vmlinuz $BOOT_OPTION" /tmp/grub.new;
567
+ sed -i "/$LinuxIMG.*\//c\\\t$LinuxIMG\\t\/boot\/initrd.img" /tmp/grub.new;
568
+ }
569
+
570
+ [[ "$Type" == 'NoBoot' ]] && {
571
+ sed -i "/$LinuxKernel.*\//c\\\t$LinuxKernel\\t\/vmlinuz $BOOT_OPTION" /tmp/grub.new;
572
+ sed -i "/$LinuxIMG.*\//c\\\t$LinuxIMG\\t\/initrd.img" /tmp/grub.new;
573
+ }
574
+
575
+ sed -i '$a\\n' /tmp/grub.new;
576
+
577
+ sed -i ''${INSERTGRUB}'i\\n' $GRUBDIR/$GRUBFILE;
578
+ sed -i ''${INSERTGRUB}'r /tmp/grub.new' $GRUBDIR/$GRUBFILE;
579
+ [[ -f $GRUBDIR/grubenv ]] && sed -i 's/saved_entry/#saved_entry/g' $GRUBDIR/grubenv;
580
+ fi
581
+
582
+ [[ -d /tmp/boot ]] && rm -rf /tmp/boot;
583
+ mkdir -p /tmp/boot;
584
+ cd /tmp/boot;
585
+
586
+ if [[ "$linux_relese" == 'debian' ]] || [[ "$linux_relese" == 'ubuntu' ]]; then
587
+ COMPTYPE="gzip";
588
+ elif [[ "$linux_relese" == 'centos' ]]; then
589
+ COMPTYPE="$(file ../initrd.img |grep -o ':.*compressed data' |cut -d' ' -f2 |sed -r 's/(.*)/\L\1/' |head -n1)"
590
+ [[ -z "$COMPTYPE" ]] && echo "Detect compressed type fail." && exit 1;
591
+ fi
592
+ CompDected='0'
593
+ for COMP in `echo -en 'gzip\nlzma\nxz'`
594
+ do
595
+ if [[ "$COMPTYPE" == "$COMP" ]]; then
596
+ CompDected='1'
597
+ if [[ "$COMPTYPE" == 'gzip' ]]; then
598
+ NewIMG="initrd.img.gz"
599
+ else
600
+ NewIMG="initrd.img.$COMPTYPE"
601
+ fi
602
+ mv -f "/tmp/initrd.img" "/tmp/$NewIMG"
603
+ break;
604
+ fi
605
+ done
606
+ [[ "$CompDected" != '1' ]] && echo "Detect compressed type not support." && exit 1;
607
+ [[ "$COMPTYPE" == 'lzma' ]] && UNCOMP='xz --format=lzma --decompress';
608
+ [[ "$COMPTYPE" == 'xz' ]] && UNCOMP='xz --decompress';
609
+ [[ "$COMPTYPE" == 'gzip' ]] && UNCOMP='gzip -d';
610
+
611
+ $UNCOMP < /tmp/$NewIMG | cpio --extract --verbose --make-directories --no-absolute-filenames >>/dev/null 2>&1
612
+
613
+ if [[ "$linux_relese" == 'debian' ]] || [[ "$linux_relese" == 'ubuntu' ]]; then
614
+ cat >/tmp/boot/preseed.cfg<<EOF
615
+ d-i debian-installer/locale string en_US
616
+ d-i console-setup/layoutcode string us
617
+
618
+ d-i keyboard-configuration/xkb-keymap string us
619
+
620
+ d-i netcfg/choose_interface select $interfaceSelect
621
+
622
+ d-i netcfg/disable_autoconfig boolean true
623
+ d-i netcfg/dhcp_failed note
624
+ d-i netcfg/dhcp_options select Configure network manually
625
+ d-i netcfg/get_ipaddress string $IPv4
626
+ d-i netcfg/get_netmask string $MASK
627
+ d-i netcfg/get_gateway string $GATE
628
+ d-i netcfg/get_nameservers string $ipDNS
629
+ d-i netcfg/no_default_route boolean true
630
+ d-i netcfg/confirm_static boolean true
631
+
632
+ d-i hw-detect/load_firmware boolean true
633
+
634
+ d-i mirror/country string manual
635
+ d-i mirror/http/hostname string $MirrorHost
636
+ d-i mirror/http/directory string $MirrorFolder
637
+ d-i mirror/http/proxy string
638
+
639
+ d-i passwd/root-login boolean ture
640
+ d-i passwd/make-user boolean false
641
+ d-i passwd/root-password-crypted password $myPASSWORD
642
+ d-i user-setup/allow-password-weak boolean true
643
+ d-i user-setup/encrypt-home boolean false
644
+
645
+ d-i clock-setup/utc boolean true
646
+ d-i time/zone string US/Eastern
647
+ d-i clock-setup/ntp boolean false
648
+
649
+ d-i preseed/early_command string anna-install libfuse2-udeb fuse-udeb ntfs-3g-udeb libcrypto1.1-udeb libpcre2-8-0-udeb libssl1.1-udeb libuuid1-udeb zlib1g-udeb wget-udeb
650
+ d-i partman/early_command string [[ -n "\$(blkid -t TYPE='vfat' -o device)" ]] && umount "\$(blkid -t TYPE='vfat' -o device)"; \
651
+ debconf-set partman-auto/disk "\$(list-devices disk |head -n1)"; \
652
+ wget -qO- '$DDURL' |gunzip -dc |/bin/dd of=\$(list-devices disk |head -n1); \
653
+ mount.ntfs-3g \$(list-devices partition |head -n1) /mnt; \
654
+ cd '/mnt/ProgramData/Microsoft/Windows/Start Menu/Programs'; \
655
+ cd Start* || cd start*; \
656
+ cp -f '/net.bat' './net.bat'; \
657
+ /sbin/reboot; \
658
+ umount /media || true; \
659
+
660
+ d-i partman-partitioning/confirm_write_new_label boolean true
661
+ d-i partman/mount_style select uuid
662
+ d-i partman/choose_partition select finish
663
+ d-i partman-auto/method string regular
664
+ d-i partman-auto/init_automatically_partition select Guided - use entire disk
665
+ d-i partman-auto/choose_recipe select All files in one partition (recommended for new users)
666
+ d-i partman-md/device_remove_md boolean true
667
+ d-i partman-lvm/device_remove_lvm boolean true
668
+ d-i partman-lvm/confirm boolean true
669
+ d-i partman-lvm/confirm_nooverwrite boolean true
670
+ d-i partman/confirm boolean true
671
+ d-i partman/confirm_nooverwrite boolean true
672
+
673
+ d-i debian-installer/allow_unauthenticated boolean true
674
+
675
+ tasksel tasksel/first multiselect minimal
676
+ d-i pkgsel/update-policy select none
677
+ d-i pkgsel/include string openssh-server
678
+ d-i pkgsel/upgrade select none
679
+
680
+ popularity-contest popularity-contest/participate boolean false
681
+
682
+ d-i grub-installer/only_debian boolean true
683
+ d-i grub-installer/bootdev string $IncDisk
684
+ d-i grub-installer/force-efi-extra-removable boolean true
685
+ d-i finish-install/reboot_in_progress note
686
+ d-i debian-installer/exit/reboot boolean true
687
+ d-i preseed/late_command string \
688
+ sed -ri 's/^#?Port.*/Port ${sshPORT}/g' /target/etc/ssh/sshd_config; \
689
+ sed -ri 's/^#?PermitRootLogin.*/PermitRootLogin yes/g' /target/etc/ssh/sshd_config; \
690
+ sed -ri 's/^#?PasswordAuthentication.*/PasswordAuthentication yes/g' /target/etc/ssh/sshd_config; \
691
+ echo '@reboot root cat /etc/run.sh 2>/dev/null |base64 -d >/tmp/run.sh; rm -rf /etc/run.sh; sed -i /^@reboot/d /etc/crontab; bash /tmp/run.sh' >>/target/etc/crontab; \
692
+ echo '' >>/target/etc/crontab; \
693
+ echo '${setCMD}' >/target/etc/run.sh;
694
+ EOF
695
+
696
+ if [[ "$loaderMode" != "0" ]] && [[ "$setNet" == '0' ]]; then
697
+ sed -i '/netcfg\/disable_autoconfig/d' /tmp/boot/preseed.cfg
698
+ sed -i '/netcfg\/dhcp_options/d' /tmp/boot/preseed.cfg
699
+ sed -i '/netcfg\/get_.*/d' /tmp/boot/preseed.cfg
700
+ sed -i '/netcfg\/confirm_static/d' /tmp/boot/preseed.cfg
701
+ fi
702
+
703
+ if [[ "$linux_relese" == 'debian' ]]; then
704
+ sed -i '/user-setup\/allow-password-weak/d' /tmp/boot/preseed.cfg
705
+ sed -i '/user-setup\/encrypt-home/d' /tmp/boot/preseed.cfg
706
+ sed -i '/pkgsel\/update-policy/d' /tmp/boot/preseed.cfg
707
+ sed -i 's/umount\ \/media.*true\;\ //g' /tmp/boot/preseed.cfg
708
+ [[ -f '/tmp/firmware.cpio.gz' ]] && gzip -d < /tmp/firmware.cpio.gz | cpio --extract --verbose --make-directories --no-absolute-filenames >>/dev/null 2>&1
709
+ else
710
+ sed -i '/d-i\ grub-installer\/force-efi-extra-removable/d' /tmp/boot/preseed.cfg
711
+ fi
712
+
713
+ [[ "$ddMode" == '1' ]] && {
714
+ WinNoDHCP(){
715
+ 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';
716
+ }
717
+ WinRDP(){
718
+ 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';
719
+ }
720
+ 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';
721
+ [[ "$setNet" == '1' ]] && WinNoDHCP;
722
+ [[ "$setNet" == '0' ]] && [[ "$AutoNet" == '0' ]] && WinNoDHCP;
723
+ [[ "$setRDP" == '1' ]] && [[ -n "$WinRemote" ]] && WinRDP
724
+ 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';
725
+ 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';
726
+ iconv -f 'UTF-8' -t 'GBK' '/tmp/boot/net.tmp' -o '/tmp/boot/net.bat'
727
+ rm -rf '/tmp/boot/net.tmp'
728
+ }
729
+
730
+ [[ "$ddMode" == '0' ]] && {
731
+ sed -i '/anna-install/d' /tmp/boot/preseed.cfg
732
+ sed -i 's/wget.*\/sbin\/reboot\;\ //g' /tmp/boot/preseed.cfg
733
+ }
734
+
735
+ elif [[ "$linux_relese" == 'centos' ]]; then
736
+ cat >/tmp/boot/ks.cfg<<EOF
737
+ #platform=x86, AMD64, or Intel EM64T
738
+ firewall --enabled --ssh
739
+ install
740
+ url --url="$LinuxMirror/$DIST/os/$VER/"
741
+ rootpw --iscrypted $myPASSWORD
742
+ auth --useshadow --passalgo=sha512
743
+ firstboot --disable
744
+ lang en_US
745
+ keyboard us
746
+ selinux --disabled
747
+ logging --level=info
748
+ reboot
749
+ text
750
+ unsupported_hardware
751
+ vnc
752
+ skipx
753
+ timezone --isUtc Asia/Hong_Kong
754
+ #ONDHCP network --bootproto=dhcp --onboot=on
755
+ network --bootproto=static --ip=$IPv4 --netmask=$MASK --gateway=$GATE --nameserver=$ipDNS --onboot=on
756
+ bootloader --location=mbr --append="rhgb quiet crashkernel=auto"
757
+ zerombr
758
+ clearpart --all --initlabel
759
+ autopart
760
+
761
+ %packages
762
+ @base
763
+ %end
764
+
765
+ %post --interpreter=/bin/bash
766
+ rm -rf /root/anaconda-ks.cfg
767
+ rm -rf /root/install.*log
768
+ %end
769
+
770
+ EOF
771
+
772
+
773
+ [[ "$UNKNOWHW" == '1' ]] && sed -i 's/^unsupported_hardware/#unsupported_hardware/g' /tmp/boot/ks.cfg
774
+ [[ "$(echo "$DIST" |grep -o '^[0-9]\{1\}')" == '5' ]] && sed -i '0,/^%end/s//#%end/' /tmp/boot/ks.cfg
775
+ fi
776
+
777
+ find . | cpio -H newc --create --verbose | gzip -9 > /tmp/initrd.img;
778
+ cp -f /tmp/initrd.img /boot/initrd.img || sudo cp -f /tmp/initrd.img /boot/initrd.img
779
+ cp -f /tmp/vmlinuz /boot/vmlinuz || sudo cp -f /tmp/vmlinuz /boot/vmlinuz
780
+
781
+ chown root:root $GRUBDIR/$GRUBFILE
782
+ chmod 444 $GRUBDIR/$GRUBFILE
783
+
784
+ if [[ "$loaderMode" == "0" ]]; then
785
+ sleep 3 && reboot || sudo reboot >/dev/null 2>&1
786
+ else
787
+ rm -rf "$HOME/loader"
788
+ mkdir -p "$HOME/loader"
789
+ cp -rf "/boot/initrd.img" "$HOME/loader/initrd.img"
790
+ cp -rf "/boot/vmlinuz" "$HOME/loader/vmlinuz"
791
+ [[ -f "/boot/initrd.img" ]] && rm -rf "/boot/initrd.img"
792
+ [[ -f "/boot/vmlinuz" ]] && rm -rf "/boot/vmlinuz"
793
+ echo && ls -AR1 "$HOME/loader"
794
+ fi
795
+
796
+