-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathw.sh
508 lines (382 loc) · 10.8 KB
/
w.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
#!/bin/bash
#====================================================
# System Request: Debian/Ubuntu
# Author: dylanbai8
# Dscription: OpenVZ虚拟化(架构)VPS 一键安装 Windows 系统
# Open Source: https://github.com/dylanbai8/Onekey_OpenVZ_Install_Windows
# Official document: https://oo0.bid
#====================================================
# 为Debian安装远程桌面
install_lxde_vnc(){
# 卸载或去除不必要的系统服务
apt-get purge apache2 -y
# 升级Debian
apt-get update -y
# 安装LXDE+VncServer桌面环境
apt-get install xorg lxde-core -y
apt-get install tightvncserver -y
apt-get install curl -y
# 设置VNC密码
echo "----------------------------------------"
echo " 按提示设置 VNC Password 远程桌面密码"
echo "----------------------------------------"
vncserver :1
vncserver -kill :1
# VNC启动时自动启动LXDE桌面
sed -i '/starlxde/'d /root/.vnc/xstartup
echo "starlxde &" >> /root/.vnc/xstartup
chmod +x /root/.vnc/xstartup
}
install_lxde_vnc_menu(){
local_ip=`curl -4 ip.sb`
clear
echo "----------------------------------------"
echo " 提示:安装 Lxde+VNC 远程桌面 成功"
echo " VNC服务器:${local_ip}:1 未启动"
echo "----------------------------------------"
echo ""
read -e -p "按任意键返回菜单 ..."
clear
menu
}
# 添加firefox浏览器和简体中文字体
add_firefox_ttf(){
apt-get install iceweasel -y
apt-get install ttf-arphic-ukai ttf-arphic-uming ttf-arphic-gbsn00lp ttf-arphic-bkai00mp ttf-arphic-bsmi00lp -y
clear
echo "----------------------------------------"
echo " 提示:安装 Firefox 浏览器 和 简体中文字体 成功"
echo "----------------------------------------"
echo ""
read -e -p "按任意键返回菜单 ..."
clear
menu
}
# 安装qemu+win虚拟机
install_qemu_win(){
# 安装qemu虚拟机
apt-get install qemu -y
# 安装win到虚拟机
wget https://www.dropbox.com/s/gq3e3feukskw72k/winxp.img
mkdir /root/IMG
mv winxp.img /root/IMG/win.img
touch /root/.vnc/ram.txt
cat <<EOF > /root/.vnc/ram.txt
512
EOF
}
install_qemu_win_menu(){
local_ip=`curl -4 ip.sb`
clear
echo "----------------------------------------"
echo " 提示:安装 Qemu+WindowsXP 虚拟机 成功"
echo " WindowsXP 默认启动内存 512M 硬盘 4G"
echo " 远程桌面地址:${local_ip}:3389 未启动"
echo "----------------------------------------"
echo ""
read -e -p "按任意键返回菜单 ..."
clear
menu
}
check_vnc_install_qemu_win(){
if [[ -e /usr/bin/vncserver ]]; then
install_qemu_win
else
install_lxde_vnc
install_qemu_win
fi
}
# 启动 VNC+lxde/qemu_win
start_vnc(){
vncserver -kill :1
lsof -i:"3389" | awk '{print $2}'| grep -v "PID" | xargs kill -9
getram=$(cat /root/.vnc/ram.txt)
vncserver :1
qemu-system-x86_64 -hda /root/IMG/win.img -m ${getram}M -smp 1 -daemonize -vnc :2 -net nic,model=virtio -net user -redir tcp:3389::3389
local_ip=`curl -4 ip.sb`
clear
echo "----------------------------------------"
echo " 提示:启动 Lxde+VNC(+WindowsXP 如果已安装) 成功"
echo " VNC服务器:${local_ip}:1"
echo ""
echo " 如果已安装 WindowsXP 预计5分钟后可以连接桌面"
echo " VNC服务器:${local_ip}:2"
echo " 远程桌面地址:${local_ip}:3389"
echo " 用户名:administrator 密码:abfan.com"
echo "----------------------------------------"
echo ""
read -e -p "按任意键返回菜单 ..."
clear
menu
}
# 关闭 VNC+lxde/qemu_win
stop_vnc(){
vncserver -kill :1
lsof -i:"3389" | awk '{print $2}'| grep -v "PID" | xargs kill -9
clear
echo "----------------------------------------"
echo " 提示:关闭 Lxde+VNC(+WindowsXP 如果已启动) 成功"
echo "----------------------------------------"
echo ""
read -e -p "按任意键返回菜单 ..."
clear
menu
}
# 设置Windows启动内存
set_win_ram(){
if [[ -e /root/IMG/win.img ]]; then
clear
echo "----------------------------------------"
echo " 请输入要设置的RAM值,如:1024"
echo "----------------------------------------"
echo ""
read -e -p "请输入:" ram
[[ -z ${ram} ]] && ram="none"
if [ "${ram}" = "none" ];then
set_win_ram
fi
touch /root/.vnc/ram.txt
cat <<EOF > /root/.vnc/ram.txt
${ram}
EOF
clear
echo "----------------------------------------"
echo " 操作已完成 当前 Windows 虚拟机内存为:${ram}M"
echo " 重启 Windows 虚拟机 生效"
echo "----------------------------------------"
echo ""
read -e -p "按任意键返回菜单 ..."
clear
menu
else
clear
echo "----------------------------------------"
echo " 未检查到 Windows 系统镜像 请先执行安装"
echo "----------------------------------------"
echo ""
read -e -p "按任意键返回菜单 ..."
clear
menu
fi
}
win_iso_install(){
clear
echo "----------------------------------------"
echo " Note: This command must be executed inside the VNC Remote Desktop"
echo " After the installation is complete, log in to the Windows system:"
echo " 1. My computer - right click property - allow remote desktop"
echo " 2. Add account password"
echo "----------------------------------------"
echo ""
read -e -p "Press any key to continue! Exit with 'Ctrl'+'C' !"
mv /root/*.iso /root/win.iso
if [[ -e /root/win.iso ]]; then
apt-get install qemu -y
win_iso_ram_disk
touch /root/.vnc/ram.txt
cat <<EOF > /root/.vnc/ram.txt
${nram}
EOF
rm -rf /root/IMG
mkdir /root/IMG
qemu-img create /root/IMG/win.img ${ndisk}G
qemu-system-x86_64 -cdrom /root/win.iso -m ${nram}M -boot d /root/IMG/win.img -k en-us
clear
echo "----------------------------------------"
echo " After the installation is complete, log in to the Windows system:"
echo " 1. My computer - right click property - allow remote desktop"
echo " 2. Add account password"
echo " Back to shell Start VNC to run New Windows system in the background"
echo "----------------------------------------"
else
clear
echo "----------------------------------------"
echo " No iso image file detected! Cancel installation"
echo " Please manually download the iso system image into the /root/ directory"
echo " Note: The image file extension must be .iso lowercase"
echo "----------------------------------------"
fi
}
win_iso_ram_disk(){
clear
echo "----------------------------------------"
echo " Enter the RAM value to be set, for example: 1024"
echo "----------------------------------------"
echo ""
read -e -p "please enter (Default size 512):" nram
[[ -z ${nram} ]] && nram="512"
echo ""
echo "----------------------------------------"
echo " Enter the hard disk value to be set, for example: 10"
echo "----------------------------------------"
echo ""
read -e -p "please enter (Default size 10):" ndisk
[[ -z ${ndisk} ]] && ndisk="10"
}
winxp_iso_install(){
cd /root
wget https://www.dropbox.com/s/x20vw6bkwink0fm/winxp.iso
win_iso_install
}
# 全部卸载
unstall_all(){
# 卸载lxde和vnc
vncserver -kill :1
apt-get purge xorg -y
apt-get purge lxde -y
apt-get purge tightvncserver -y
apt-get purge curl -y
rm -rf /root/.vnc
rm -rf /root/Desktop
rm -rf /root/.cache
rm -rf /root/.config
rm -rf /root/.dbus
rm -rf /root/.gconf
rm -rf /root/.gvfs
rm -rf /root/.Xauthority
rm -rf /root/.xsession-errors
# 卸载firefox浏览器和简体中文字体
apt-get purge iceweasel -y
apt-get purge ttf-arphic-ukai ttf-arphic-uming ttf-arphic-gbsn00lp ttf-arphic-bkai00mp ttf-arphic-bsmi00lp -y
# 卸载qemu虚拟机
lsof -i:"3389" | awk '{print $2}'| grep -v "PID" | xargs kill -9
apt-get purge qemu -y
# 删除IMG镜像
if [[ -e /root/IMG/win.img ]]; then
echo "----------------------------------------"
echo " 检测到已安装Windows系统镜像 是否删除?"
echo "----------------------------------------"
echo ""
read -e -p "请输入(y/n):" rmIMG
case ${rmIMG} in
[yY][eE][sS]|[yY])
rm -rf /root/IMG
echo " 已删除 /root/IMG/win.img 系统镜像"
;;
*)
echo " 取消删除操作 镜像位置:/root/IMG/win.img"
esac
fi
clear
echo "----------------------------------------"
echo " 卸载 Lxde+VNC、FireFox+ttf、Qemu+Windows 成功"
echo "----------------------------------------"
echo ""
read -e -p "按任意键返回菜单 ..."
clear
menu
}
get_help(){
local_ip=`curl -4 ip.sb`
clear
echo "----------------------------------------"
echo " **** 自定义安装 Windows 系统版本 ****"
echo "----------------------------------------"
echo ""
echo " 1.依次执行菜单中的 1、4 安装并启动 Lxde+VNC 服务"
echo ""
echo " 2.手动下载 Windows系统 iso镜像文件到 /root/ 目录内"
echo ""
echo " 以 深度精简版 WindowsXP 为例(支持原版安装和Ghost系统)"
echo " cd /root"
echo " wget https://www.dropbox.com/s/x20vw6bkwink0fm/winxp.iso"
echo ""
echo " 3.使用 Windows VNC 客户端连接远程桌面"
echo ""
echo " a.VNC服务器地址:${local_ip}:1"
echo " Windows客户端下载地址:"
echo " https://github.com/dylanbai8/Onekey_OpenVZ_Install_Windows/raw/master/VNC-4.0-x86_CN.exe"
echo ""
echo " b.在 VNC 桌面内 打开终端(Terminal)执行以下命令:"
echo ""
echo " bash w.sh windows"
echo ""
echo " 注意:此命令必须在 VNC 远程桌面内执行"
echo " 按提示设置虚拟机内存和硬盘大小 默认512M内存10G硬盘"
echo " 按提示安装完系统后:1.我的电脑-右键属性-允许远程桌面 2.添加开机密码"
echo ""
echo " 调试完成后 返回 shell 执行脚本启动 VNC 即可在后台运行 新的Windows系统"
echo ""
echo ""
echo " c.如果要安装WindowsXP系统 直接在VNC执行 bash w.sh windowsxp 会自动下载镜像并执行安装"
echo "----------------------------------------"
echo ""
read -e -p "按任意键返回菜单 ..."
clear
menu
}
# 安装菜单
menu(){
echo "----------------------------------------"
echo " 1.一键安装 Lxde+VNC 远程桌面"
echo " 2.添加 Firefox 浏览器 和 简体中文字体"
echo ""
echo " 3.一键安装 Qemu+WindowsXP 虚拟机"
echo ""
echo " 4.启动 Lxde+VNC(+WindowsXP 如果已安装)"
echo " 5.关闭 Lxde+VNC(+WindowsXP 如果已启动)"
echo ""
echo " 6.设置 WindowsXP 启动内存(默认512M)"
echo ""
echo " 7.自定义安装 Windows 系统版本"
echo ""
echo " 8.卸载所有"
echo " 9.退出脚本"
echo "----------------------------------------"
echo ""
read -e -p "请输入对应的数字:" num
case $num in
1)
install_lxde_vnc
install_lxde_vnc_menu
;;
2)
add_firefox_ttf
;;
3)
check_vnc_install_qemu_win
install_qemu_win_menu
;;
4)
start_vnc
;;
5)
stop_vnc
;;
6)
set_win_ram
;;
7)
get_help
;;
8)
unstall_all
;;
9)
exit 0
;;
*)
clear
menu
esac
}
# 检测root权限
if [ `id -u` == 0 ]; then
echo "当前用户是 root 用户 开始安装流程"
else
echo "当前用户不是root用户 请切换到 root 用户后重新执行脚本"
exit 1
fi
# 脚本菜单
case "$1" in
windows)
win_iso_install
;;
windowsxp)
winxp_iso_install
;;
*)
clear
menu
esac
# 转载请保留版权:https://github.com/dylanbai8/Onekey_OpenVZ_Install_Windows