-
Notifications
You must be signed in to change notification settings - Fork 553
/
pvetools.sh
executable file
·3973 lines (3909 loc) · 132 KB
/
pvetools.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
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!/bin/bash
#############--Proxmox VE Tools--##########################
# Author : 龙天ivan
# Mail: [email protected]
# Version: v2.4.0
# Github: https://github.com/ivanhao/pvetools
########################################################
#js whiptail --title "Success" --msgbox "c" 10 60
if [ `export|grep 'LC_ALL'|wc -l` = 0 ];then
if [ `grep "LC_ALL" /etc/profile|wc -l` = 0 ];then
echo "export LC_ALL='en_US.UTF-8'" >> /etc/profile
fi
fi
if [ `grep "alias ll" /etc/profile|wc -l` = 0 ];then
echo "alias ll='ls -alh'" >> /etc/profile
echo "alias sn='snapraid'" >> /etc/profile
fi
source /etc/profile
#-----------------functions--start------------------#
example(){
#msgbox
whiptail --title "Success" --msgbox "
" 10 60
#yesno
if (whiptail --title "Yes/No Box" --yesno "
" 10 60);then
echo ""
fi
#password
PASSWORD=$(whiptail --title "Password Box" --passwordbox "
Enter your password and choose Ok to continue.
" 10 60 3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 0 ]; then
echo "Your password is:" $m
fi
#input form
NAME=$(whiptail --title "
Free-form Input Box
" --inputbox "
What is your pet's name?
" 10 60
Peter
3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 0 ]; then
echo ""
else
echo ""
fi
#processing
apt -y install mailutils
}
smbp(){
m=$(whiptail --title "Password Box" --passwordbox "
Enter samba user 'admin' password:
请输入samba用户admin的密码:
" 10 60 3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 0 ]; then
while [ true ]
do
if [[ ! `echo $m|grep "^[0-9a-zA-Z.-@]*$"` ]] || [[ $m = '^M' ]];then
whiptail --title "Warnning" --msgbox "
Wrong format!!! input again:
密码格式不对!!!请重新输入:
" 10 60
smbp
else
break
fi
done
fi
}
#修改debian的镜像源地址:
chSource(){
clear
if [ $1 ];then
#x=a
whiptail --title "Warnning" --msgbox "Not supported!
不支持该模式。" 10 60
chSource
fi
verno=`cat /etc/debian_version |awk -F"." '{print $1}'`
sver=`cat /etc/os-release|grep VERSION_CODENAME|awk -F '=' '{print $2}'`
currentDebianVersion=${verno}
# debian 11 change security source rule
if [ $currentDebianVersion -gt 10 ];then
securitySource="
deb https://mirrors.ustc.edu.cn/debian-security/ stable-security main contrib non-free
deb-src https://mirrors.ustc.edu.cn/debian-security/ stable-security main contrib non-free
"
else
securitySource="
deb https://mirrors.ustc.edu.cn/debian-security/ $sver/updates main contrib non-free
deb-src https://mirrors.ustc.edu.cn/debian-security/ $sver/updates main contrib non-free
"
fi
#"a" "Automation mode." \
#"a" "无脑模式" \
if [ $L = "en" ];then
OPTION=$(whiptail --title " PveTools Version : 2.4.0 " --menu "Config apt source:" 25 60 15 \
"b" "Change to cn source." \
"c" "Disable enterprise." \
"d" "Undo Change." \
"q" "Main menu." \
3>&1 1>&2 2>&3)
else
OPTION=$(whiptail --title " PveTools Version : 2.4.0 " --menu "配置apt镜像源:" 25 60 15 \
"b" "更换为国内源" \
"c" "关闭企业更新源" \
"d" "还原配置" \
"q" "返回主菜单" \
3>&1 1>&2 2>&3)
fi
exitstatus=$?
if [ $exitstatus = 0 ]; then
case "$OPTION" in
a | A )
if (whiptail --title "Yes/No Box" --yesno "修改为ustc.edu.cn源,禁用企业订阅更新源,添加非订阅更新源(ustc.edu.cn),修改ceph镜像更新源" 10 60) then
if [ `grep "ustc.edu.cn" /etc/apt/sources.list|wc -l` = 0 ];then
#sver=`cat /etc/apt/sources.list|awk 'NR==1{print $3}'`
cp /etc/apt/sources.list /etc/apt/sources.list.bak.pvetools
cp /etc/apt/sources.list.d/pve-no-sub.list /etc/apt/sources.list.d/pve-no-sub.list.bak.pvetools
cp /etc/apt/sources.list.d/pve-enterprise.list /etc/apt/sources.list.d/pve-enterprise.list.bak.pvetools
cp /etc/apt/sources.list.d/ceph.list /etc/apt/sources.list.d/ceph.list.bak.pvetools
cat > /etc/apt/sources.list <<EOF
deb https://mirrors.ustc.edu.cn/debian/ $sver main contrib non-free
deb-src https://mirrors.ustc.edu.cn/debian/ $sver main contrib non-free
deb https://mirrors.ustc.edu.cn/debian/ $sver-updates main contrib non-free
deb-src https://mirrors.ustc.edu.cn/debian/ $sver-updates main contrib non-free
deb https://mirrors.ustc.edu.cn/debian/ $sver-backports main contrib non-free
deb-src https://mirrors.ustc.edu.cn/debian/ $sver-backports main contrib non-free
$securitySource
EOF
#修改pve 5.x更新源地址为非订阅更新源,不使用企业订阅更新源。
echo "deb http://mirrors.ustc.edu.cn/proxmox/debian/pve/ $sver pve-no-subscription" > /etc/apt/sources.list.d/pve-no-sub.list
#关闭pve 5.x企业订阅更新源
sed -i 's|deb|#deb|' /etc/apt/sources.list.d/pve-enterprise.list
#修改 ceph镜像更新源
echo "deb http://mirrors.ustc.edu.cn/proxmox/debian/ceph-luminous $sver main" > /etc/apt/sources.list.d/ceph.list
#针对debian 12的处理
if [ $bver -gt 11 ];then
su -c 'echo "APT::Get::Update::SourceListWarnings::NonFreeFirmware \"false\";" > /etc/apt/apt.conf.d/no-bookworm-firmware.conf'
fi
whiptail --title "Success" --msgbox " apt source has been changed successfully!
软件源已更换成功!" 10 60
apt-get update
apt-get -y install net-tools
whiptail --title "Success" --msgbox " apt source has been changed successfully!
软件源已更换成功!" 10 60
else
whiptail --title "Success" --msgbox " Already changed apt source to ustc.edu.cn!
已经更换apt源为 ustc.edu.cn" 10 60
fi
if [ ! $1 ];then
chSource
fi
fi
;;
b | B )
if [ $L = "en" ];then
OPTION=$(whiptail --title " PveTools Version : 2.4.0 " --menu "Config apt source:" 25 60 15 \
"a" "aliyun.com" \
"b" "ustc.edu.cn" \
"q" "Main menu." \
3>&1 1>&2 2>&3)
else
OPTION=$(whiptail --title " PveTools Version : 2.4.0 " --menu "配置apt镜像源:" 25 60 15 \
"a" "aliyun.com" \
"b" "ustc.edu.cn" \
"q" "返回主菜单" \
3>&1 1>&2 2>&3)
fi
exitstatus=$?
if [ $exitstatus = 0 ]; then
case "$OPTION" in
a )
ss="aliyun.com"
;;
b)
ss="ustc.edu.cn"
;;
q )
chSource
esac
if (whiptail --title "Yes/No Box" --yesno "修改更新源为$ss?" 10 60) then
if [ `grep $ss /etc/apt/sources.list|wc -l` = 0 ];then
cp /etc/apt/sources.list /etc/apt/sources.list.bak.pvetools
#cp /etc/apt/sources.list.d/ceph.list /etc/apt/sources.list.d/ceph.list.bak.pvetools
#sver=`cat /etc/apt/sources.list|awk 'NR==1{print $3}'`
cat > /etc/apt/sources.list << EOF
deb https://mirrors.$ss/debian/ $sver main contrib non-free
deb-src https://mirrors.$ss/debian/ $sver main contrib non-free
deb https://mirrors.$ss/debian/ $sver-updates main contrib non-free
deb-src https://mirrors.$ss/debian/ $sver-updates main contrib non-free
deb https://mirrors.$ss/debian/ $sver-backports main contrib non-free
deb-src https://mirrors.$ss/debian/ $sver-backports main contrib non-free
$securitySource
EOF
#修改 ceph镜像更新源
#echo "deb http://mirrors.$ss/proxmox/debian/ceph-luminous $sver main" > /etc/apt/sources.list.d/ceph.list
#修改pve 更新源地址为非订阅更新源,不使用企业订阅更新源。
echo "deb http://mirrors.ustc.edu.cn/proxmox/debian/pve/ $sver pve-no-subscription" > /etc/apt/sources.list.d/pve-no-sub.list
whiptail --title "Success" --msgbox " apt source has been changed successfully!
软件源已更换成功!" 10 60
apt-get update
apt-get -y install net-tools
whiptail --title "Success" --msgbox " apt source has been changed successfully!
软件源已更换成功!" 10 60
else
whiptail --title "Success" --msgbox " Already changed apt source to $ss!
已经更换apt源为 $ss" 10 60
fi
else
chSource
fi
chSource
else
chSource
fi
;;
c | C )
if (whiptail --title "Yes/No Box" --yesno "禁用企业订阅更新源?" 10 60) then
#sver=`cat /etc/apt/sources.list|awk 'NR==1{print $3}'`
if [ -f /etc/apt/sources.list.d/pve-no-sub.list ];then
#修改pve 5.x更新源地址为非订阅更新源,不使用企业订阅更新源
echo "deb http://mirrors.ustc.edu.cn/proxmox/debian/pve/ $sver pve-no-subscription" > /etc/apt/sources.list.d/pve-no-sub.list
else
whiptail --title "Success" --msgbox " apt source has been changed successfully!
软件源已更换成功!" 10 60
fi
if [ `grep "^deb" /etc/apt/sources.list.d/pve-enterprise.list|wc -l` != 0 ];then
#关闭pve 5.x企业订阅更新源
sed -i 's|deb|#deb|' /etc/apt/sources.list.d/pve-enterprise.list
whiptail --title "Success" --msgbox " apt source has been changed successfully!
软件源已更换成功!" 10 60
else
whiptail --title "Success" --msgbox " apt source has been changed successfully!
软件源已更换成功!" 10 60
fi
chSource
fi
;;
d | D )
cp /etc/apt/sources.list.bak.pvetools /etc/apt/sources.list
cp /etc/apt/sources.list.d/pve-no-sub.list.bak.pvetools /etc/apt/sources.list.d/pve-no-sub.list
cp /etc/apt/sources.list.d/pve-enterprise.list.bak.pvetools /etc/apt/sources.list.d/pve-enterprise.list
#cp /etc/apt/sources.list.d/ceph.list.bak.pvetools /etc/apt/sources.list.d/ceph.list
whiptail --title "Success" --msgbox "apt source has been changed successfully!
软件源已更换成功!" 10 60
chSource
;;
q )
echo "q"
#main
;;
esac
fi
}
chMail(){
#set mailutils to send mail
addMail(){
if (whiptail --title "Yes/No Box" --yesno "
Will you want to config mailutils & postfix to send notification?(Y/N):
是否配置mailutils和postfix来发送邮件通知?
" 10 60);then
qqmail=$(whiptail --title "Config mail" --inputbox "
Input email adress:
输入邮箱地址:
" 10 60 3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 0 ]; then
while [ true ]
do
if [ `echo $qqmail|grep '^[a-zA-Z0-9\_\-\.]*\@[A-Za-z0-9\_\-\.]*\.[a-zA-Z\_\-\.]*$'` ];then
break
else
whiptail --title "Warnning" --msgbox "
Wrong email format!!! input [email protected] for example.retry:
错误的邮箱格式!!!请输入类似[email protected]并重试:
" 10 60
addMail
fi
done
if [[ ! -f /etc/mailname || `dpkg -l|grep mailutils|wc -l` = 0 ]];then
apt -y install mailutils
fi
{
echo 10
sleep 1
$(echo "pve.local" > /etc/mailname)
echo 40
sleep 1
$(sed -i -e "/root:/d" /etc/aliases)
echo 70
sleep 1
$(echo "root: $qqmail">>/etc/aliases)
echo 100
sleep 1
} | whiptail --gauge "Please wait while installing" 10 60 0
sleep 1
dpkg-reconfigure postfix
service postfix reload
echo "This is a mail test." |mail -s "mail test" root
whiptail --title "Success" --msgbox "
Config complete and send test email to you.
已经配置好并发送了测试邮件。
" 10 60
main
else
main
fi
else
main
fi
}
if [ -f /etc/mailname ];then
if (whiptail --title "Yes/No Box" --yesno "
It seems you have already configed it before.Reconfig?
您好像已经配置过这个了。重新配置?
" --defaultno 10 60);then
addMail
else
main
fi
fi
addMail
}
chZfs(){
#set max zfs ram
setMen(){
x=$(whiptail --title "Config ZFS" --inputbox "
set max zfs ram 4(G) or 8(G) etc, just enter number or n?
设置最大zfs内存(zfs_arc_max),比如4(G)或8(G)等, 只需要输入纯数字即可,比如4G输入4?
" 20 60 3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 0 ]; then
while [ true ]
do
if [[ "$x" =~ ^[1-9]+$ ]]; then
update-initramfs -u
{
$(echo "options zfs zfs_arc_max=$[$x*1024*1024*1024]">/etc/modprobe.d/zfs.conf)
echo 10
echo 70
sleep 1
#set rpool to list snapshots
$(if [ `zpool get listsnapshots|grep rpool|awk '{print $3}'` = "off" ];then
zpool set listsnapshots=on rpool
fi)
echo 100
}|whiptail --gauge "installing" 10 60 0
whiptail --title "Success" --msgbox "
Config complete!you should reboot later.
配置完成,一会儿最好重启一下系统。
" 10 60
break
else
whiptail --title "Warnning" --msgbox "
Invalidate value.Please comfirm!
输入的值无效,请重新输入!
" 10 60
setMen
fi
done
#zfs-zed
if (whiptail --title "Yes/No Box" --yesno "
Install zfs-zed to get email notification of zfs scrub?(Y/n):
安装zfs-zed来发送zfs scrub的结果提醒邮件?(Y/n):
" 10 60);then
if [ `dpkg -l|grep zfs-zed|wc -l` = 0 ];then
apt-get -y install zfs-zed
fi
whiptail --title "Success" --msgbox "
Install complete!
安装zfs-zed成功!
" 10 60
else
chZfs
fi
else
main
fi
}
if [ ! -f /etc/modprobe.d/zfs.conf ] || [ `grep "zfs_arc_max" /etc/modprobe.d/zfs.conf|wc -l` = 0 ];then
setMen
else
if(whiptail --title "Yes/No box" --yesno "
It seems you have already configed it before.Reconfig?
您好像已经配置过这个了。是否重新配置?
" --defaultno 10 60 );then
setMen
else
main
fi
fi
}
chSamba(){
#config samba
addSmbRecycle(){
if(whiptail --title "Yes/No" --yesno "enable recycle?
开启回收站?" 10 60 )then
if [ ! -f '/etc/samba/smb.conf' ];then
whiptail --title "Warnning" --msgbox "You should install samba first!
请先安装samba!" 10 60
else
if [ `sed -n "/\[$2\]/,/$2 end/p" /etc/samba/smb.conf|egrep '^recycle'|wc -l` != 0 ];then
whiptail --title "Warnning" --msgbox "Already configed! 已经配置过了。" 10 60
smbRecycle
else
cat << EOF > ./recycle
# $2--recycle-start--
vfs object = recycle
recycle:repository = $1/.deleted
recycle:keeptree = Yes
recycle:versions = Yes
recycle:maxsixe = 0
recycle:exclude = *.tmp
# $2--recycle-end--
EOF
#n=`sed '/\['$2'\]/' /etc/samba/smb.conf -n|sed -n '$p'`
cp /etc/samba/smb.conf /etc/samba/smb.conf.bak.pvetools
sed -i '/\['$2'\]/r ./recycle' /etc/samba/smb.conf
rm ./recycle
# cat << EOF >> /etc/samba/smb.conf
#[$2-recycle]
#comment = All
#browseable = yes
#path = $1/.deleted
#guest ok = no
#read only = no
#create mask = 0750
#directory mask = 0750
#; $2-recycle end
#EOF
systemctl restart smbd
whiptail --title "Success" --msgbox "Done.
配置完成" 10 60
fi
fi
else
continue
fi
}
delSmbRecycle(){
if [ ! -f '/etc/samba/smb.conf' ];then
whiptail --title "Warnning" --msgbox "You should install samba first!
请先安装samba!" 10 60
else
if [ `sed -n "/\[$1\]/,/$1 end/p" /etc/samba/smb.conf|egrep '^recycle'|wc -l` = 0 ];then
whiptail --title "Warnning" --msgbox "Already configed! 已经配置过了。" 10 60
smbRecycle
else
cp /etc/samba/smb.conf /etc/samba/smb.conf.bak.pvetools
sed -i '/.*'$1'.*recycle.*start/,/.*'$1'.*end/d' /etc/samba/smb.conf
sed "/\[${1}\-recycle\]/,/${n}\-recycle end/d" /etc/samba/smb.conf -i
systemctl restart smbd
whiptail --title "Success" --msgbox "Done.
配置完成" 10 60
fi
fi
}
clear
#$(grep -E "^\[[0-9a-zA-Z.-]*\]$|^path" /etc/samba/smb.conf|awk 'NR>3{print $0}'|sed 's/path/ path/'|grep -v '-recycle')
if [ $L = "en" ];then
OPTION=$(whiptail --title " PveTools Version : 2.4.0 " --menu "Config samba:" 25 60 15 \
"a" "Install samba and config user." \
"b" "Add folder to share." \
"c" "Delete folder to share." \
"d" "Config recycle" \
"q" "Main menu." \
3>&1 1>&2 2>&3)
else
OPTION=$(whiptail --title " PveTools Version : 2.4.0 " --menu "配置samba:" 25 60 15 \
"a" "安装配置samba并配置好samba用户" \
"b" "添加共享文件夹" \
"c" "取消共享文件夹" \
"d" "配置回收站" \
"q" "返回主菜单" \
3>&1 1>&2 2>&3)
fi
if [ $1 ];then
OPTION=a
fi
exitstatus=$?
if [ $exitstatus = 0 ]; then
case "$OPTION" in
a | A )
if [ `grep samba /etc/group|wc -l` = 0 ];then
if (whiptail --title "Yes/No Box" --yesno "set samba and admin user for samba?
安装samba并配置admin为samba用户?
" 10 60);then
apt -y install samba
groupadd samba
useradd -g samba -M -s /sbin/nologin admin
smbp
echo -e "$m\n$m"|smbpasswd -a admin
service smbd restart
echo -e "已成功配置好samba,请记好samba用户admin的密码!"
whiptail --title "Success" --msgbox "
已成功配置好samba,请记好samba用户admin的密码!
" 10 60
fi
else
whiptail --title "Success" --msgbox "Already configed samba.
已配置过samba,没什么可做的!
" 10 60
fi
if [ ! $1 ];then
chSamba
fi
;;
b | B )
# echo -e "Exist share folders:"
# echo -e "已有的共享目录:"
# echo "`grep "^\[[0-9a-zA-Z.-]*\]$" /etc/samba/smb.conf|awk 'NR>3{print $0}'`"
# echo -e "Input share folder path:"
# echo -e "输入共享文件夹的路径:"
addFolder(){
h=`grep "^\[[0-9a-zA-Z.-]*\]$" /etc/samba/smb.conf|awk 'NR>3{print $0}'|wc -l`
if [ $h -lt 3 ];then
let h=$h*15
else
let h=$h*5
fi
x=$(whiptail --title "Add Samba Share folder" --inputbox "
Exist share folders:
已有的共享目录:
----------------------------------------
$(grep -Ev "-recycle|.deleted$" /etc/samba/smb.conf|grep -E "^\[[0-9a-zA-Z.-]*\]$|^path"|sed 's/path/ path/'|awk 'NR>3{print $0}')
----------------------------------------
Input share folder path(like /root):
输入共享文件夹的路径(只需要输入/root类似的路径):
" $h 60 "" 3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 0 ]; then
while [ ! -d $x ]
do
whiptail --title "Success" --msgbox "Path not exist!
路径不存在!
" 10 60
addFolder
done
while [ `grep "path \= ${x}$" /etc/samba/smb.conf|wc -l` != 0 ]
do
whiptail --title "Success" --msgbox "Path exist!
路径已存在!
" 10 60
addFolder
done
n=`echo $x|grep -o "[a-zA-Z0-9.-]*$"`
while [ `grep "^\[${n}\]$" /etc/samba/smb.conf|wc -l` != 0 ]
do
n=$(whiptail --title "Samba Share folder" --inputbox "
Input share name:
输入共享名称:
" 10 60 "" 3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 0 ]; then
while [ `grep "^\[${n}\]$" /etc/samba/smb.conf|wc -l` != 0 ]
do
whiptail --title "Success" --msgbox "Name exist!
名称已存在!
" 10 60
addFolder
done
fi
done
oldgrp=`ls -l $x|awk 'NR==2{print $4}'`
if [ `grep "${x}$" /etc/samba/smb.conf|wc -l` = 0 ];then
cat << EOF >> /etc/samba/smb.conf
[$n]
comment = All
browseable = yes
path = $x
guest ok = no
read only = no
create mask = 0750
directory mask = 0750
; oldgrp $oldgrp
; $n end
EOF
whiptail --title "Success" --msgbox "
Configed!
配置成功!
" 10 60
#--2.4.0 add group
chgrp -R samba $x
chmod -R g+w $x
addSmbRecycle $x $n
service smbd restart
else
whiptail --title "Success" --msgbox "Already configed!
已经配置过了!
" 10 60
fi
addFolder
else
chSamba
fi
}
addFolder
;;
c )
delFolder(){
h=`grep "^\[[0-9a-zA-Z.-]*\]$" /etc/samba/smb.conf|awk 'NR>3{print $0}'|wc -l`
if [ $h -lt 3 ];then
let h=$h*15
else
let h=$h*5
fi
n=$(whiptail --title "Remove Samba Share folder" --inputbox "
Exist share folders:
已有的共享目录:
----------------------------------------
$(grep -Ev "-recycle|.deleted$" /etc/samba/smb.conf|grep -E "^\[[0-9a-zA-Z.-]*\]$|^path"|sed 's/path/ path/'|awk 'NR>3{print $0}')
----------------------------------------
Input share folder name(type words in []):
输入共享文件夹的名称(只需要输入[]中的名字):
" $h 60 "" 3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 0 ]; then
while [ `grep "^\[${n}\]$" /etc/samba/smb.conf|wc -l` = 0 ]
do
whiptail --title "Success" --msgbox "
Name not exist!:
名称不存在!:
" 10 60
delFolder
done
if [ `grep "^\[${n}\]$" /etc/samba/smb.conf|wc -l` != 0 ];then
oldgrp=`sed -n "/\[${n}\]/,/${n} end/p" /etc/samba/smb.conf |grep oldgrp|awk '{print $3}'`
x=`grep -E "^path = [0-9a-zA-Z/-.]*${n}" /etc/samba/smb.conf|awk '{print $3}'`
if [ $oldgrp ];then
chgrp -R $oldgrp $x
fi
sed "/\[${n}\]/,/${n} end/d" /etc/samba/smb.conf -i
sed "/\[${n}-recycle\]/,/${n}-recycle end/d" /etc/samba/smb.conf -i
whiptail --title "Success" --msgbox "
Configed!
配置成功!
" 10 60
service smbd restart
fi
delFolder
else
chSamba
fi
}
delFolder
;;
d )
smbRecycle(){
if [ $L = "en" ];then
x=$(whiptail --title " PveTools Version : 2.4.0 " --menu "Config samba recycle:" 12 60 4 \
"a" "Enable samba recycle." \
"b" "Disable samba recycle." \
"c" "Clear recycle." \
3>&1 1>&2 2>&3)
else
x=$(whiptail --title " PveTools Version : 2.4.0 " --menu "配置samba回收站!" 12 60 4 \
"a" "开启samba回收站。" \
"b" "关闭samba回收站。" \
"c" "清空samba回收站。" \
3>&1 1>&2 2>&3)
fi
exitstatus=$?
if [ $exitstatus = 0 ]; then
case "$x" in
a )
enSmbRecycle(){
h=`grep "^\[[0-9a-zA-Z.-]*\]$" /etc/samba/smb.conf|awk 'NR>3{print $0}'|wc -l`
if [ $h -lt 3 ];then
let h=$h*15
else
let h=$h*5
fi
n=$(whiptail --title "Remove Samba recycle" --inputbox "
Exist share folders:
已有的共享目录:
----------------------------------------
$(grep -Ev "-recycle|.deleted$" /etc/samba/smb.conf|grep -E "^\[[0-9a-zA-Z.-]*\]$|^path"|sed 's/path/ path/'|awk 'NR>3{print $0}')
----------------------------------------
Input share folder name(type words in []):
输入共享文件夹的名称(只需要输入[]中的名字):
" $h 60 "" 3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 0 ]; then
while [ `grep "^\[${n}\]$" /etc/samba/smb.conf|wc -l` = 0 ]
do
whiptail --title "Success" --msgbox "
Name not exist!:
名称不存在!:
" 10 60
enSmbRecycle
done
if [ `grep "^\[${n}\]$" /etc/samba/smb.conf|wc -l` != 0 ];then
if [ `sed -n "/\[${n}\]/,/${n} end/p" /etc/samba/smb.conf|egrep '^recycle'|wc -l` != 0 ];then
whiptail --title "Warnning" --msgbox "Already configed! 已经配置过了。" 10 60
smbRecycle
else
x=`sed -n "/\[${n}\]/,/${n} end/p" /etc/samba/smb.conf|grep path|awk '{print $3}'`
addSmbRecycle $x $n
service smbd restart
fi
fi
disSmbRecycle
else
smbRecycle
fi
}
enSmbRecycle
;;
b )
disSmbRecycle(){
h=`grep "^\[[0-9a-zA-Z.-]*\]$" /etc/samba/smb.conf|awk 'NR>3{print $0}'|wc -l`
if [ $h -lt 3 ];then
let h=$h*15
else
let h=$h*5
fi
n=$(whiptail --title "Remove Samba recycle" --inputbox "
Exist share folders:
已有的共享目录:
----------------------------------------
$(grep -Ev "-recycle|.deleted$" /etc/samba/smb.conf|grep -E "^\[[0-9a-zA-Z.-]*\]$|^path"|sed 's/path/ path/'|awk 'NR>3{print $0}')
----------------------------------------
Input share folder name(type words in []):
输入共享文件夹的名称(只需要输入[]中的名字):
" $h 60 "" 3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 0 ]; then
while [ `grep "^\[${n}\]$" /etc/samba/smb.conf|wc -l` = 0 ]
do
whiptail --title "Success" --msgbox "
Name not exist!:
名称不存在!:
" 10 60
disSmbRecycle
done
x=`sed -n "/\[${n}\]/,/${n} end/p" /etc/samba/smb.conf|grep path|awk '{print $3}'`
if [ `ls $x/.deleted/|wc -l` != 0 ];then
if(whiptail --title "Warnning" --yesno "recycle not empty, you should clear it first.continue?
回收站中存在文件,建议先清空,是否确认要继续?" 10 60);then
if [ `grep "^\[${n}\]$" /etc/samba/smb.conf|wc -l` != 0 ];then
delSmbRecycle $n
service smbd restart
fi
disSmbRecycle
else
disSmbRecycle
fi
fi
else
smbRecycle
fi
}
disSmbRecycle
;;
c )
checkClearSmb(){
c=$(whiptail --title "Clear Samba recycle" --inputbox "
you can disable recycle to clear it.
clear recycle may cause data lose,pvetools will not response for that,do you agree?
type 'YesIdo' to continue:
你可以先取消回收站再手工清空。
工具清空samba回收站不可逆,pvetools不会对此操作负责,是否同意?
如果确认要清空,请输入'YesIdo'继续:" 20 60 "" 3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 0 ]; then
while [ $c != 'YesIdo' ]
do
whiptail --title "Success" --msgbox "
Woring words,try again:
输入错误,请重试:
" 10 60
checkClearSmb
done
else
continue
fi
}
clearSmbRecycle(){
h=`grep "^\[[0-9a-zA-Z.-]*\]$" /etc/samba/smb.conf|awk 'NR>3{print $0}'|wc -l`
if [ $h -lt 3 ];then
let h=$h*15
else
let h=$h*5
fi
n=$(whiptail --title "Clear Samba recycle" --inputbox "
Exist share folders:
已有的共享目录:
----------------------------------------
$(grep -Ev "-recycle|.deleted$" /etc/samba/smb.conf|grep -E "^\[[0-9a-zA-Z.-]*\]$|^path"|sed 's/path/ path/'|awk 'NR>3{print $0}')
----------------------------------------
Input share folder name(type words in []):
输入共享文件夹的名称(只需要输入[]中的名字):
" $h 60 "" 3>&1 1>&2 2>&3)
exitstatus=$?
if [ $exitstatus = 0 ]; then
while [ `grep "^\[${n}\]$" /etc/samba/smb.conf|wc -l` = 0 ]
do
whiptail --title "Success" --msgbox "
Name not exist!:
名称不存在!:
" 10 60
clearSmbRecycle
done
x=`sed -n "/\[${n}\]/,/${n} end/p" /etc/samba/smb.conf|grep path|awk '{print $3}'`
if [ `ls -a $x/.deleted/|wc -l` -gt 2 ];then
if(whiptail --title "Warnning" --yesno "recycle not empty,continue?
回收站中存在文件,是否确认要继续?" 10 60);then
checkClearSmb
rm -rf $x/.deleted/*
rm -rf $x/.deleted/.*
whiptail --title "Success" --msgbox "ok." 10 60
else
clearSmbRecycle
fi
else
whiptail --title "Success" --msgbox "Already empty.回收站是空的,不需要清空。" 10 60
fi
else
smbRecycle
fi
}
clearSmbRecycle
;;
esac
else
chSamba
fi
}
smbRecycle
;;
q )
main
;;
esac
else
chSamba
fi
}
chVim(){
#config vim
if [ $L = "en" ];then
x=$(whiptail --title " PveTools Version : 2.4.0 " --menu "Config VIM:" 12 60 4 \
"a" "Install vim & simply config display." \
"b" "Install vim & config 'vim-for-server'." \
"c" "Uninstall." \
3>&1 1>&2 2>&3)
else
x=$(whiptail --title " PveTools Version : 2.4.0 " --menu "安装配置VIM!" 12 60 4 \
"a" "安装VIM并简单配置,如配色行号等。" \
"b" "安装VIM并配置'vim-for-server'。" \
"c" "还原配置。" \
3>&1 1>&2 2>&3)
fi
exitstatus=$?
if [ $exitstatus = 0 ]; then
case "$x" in
a )
if(whiptail --title "Yes/No Box" --yesno "
Install vim & simply config display.Continue?
安装VIM并简单配置,如配色行号等,基本是vim原味儿。是否继续?
" 10 60) then
if [ ! -f /root/.vimrc ] || [ `cat /root/.vimrc|wc -l` = 0 ] || [ `dpkg -l |grep vim|wc -l` = 0 ];then
apt -y install vim
else
cp ~/.vimrc ~/.vimrc.bak.pvetools
fi
{
echo 10
echo 50
$(
cat << EOF > ~/.vimrc
set number
set showcmd
set incsearch
set expandtab
set showcmd
set history=400
set autoread
set ffs=unix,mac,dos
set hlsearch
set shiftwidth=2
set wrap
set ai
set si
set cindent
set tabstop=2
set nocompatible
set showmatch
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8
set fileformats=unix
set ttyfast
syntax on
set imcmdline
set previewwindow
set showfulltag
set cursorline
set ruler
color ron
autocmd InsertEnter * se cul
set ruler
set showcmd
set laststatus=2
set tabstop=2
set softtabstop=4
inoremap fff <esc>h
autocmd BufWritePost \$MYVIMRC source \$MYVIMRCi
EOF
)
echo 100
}|whiptail --gauge "installing" 10 60
whiptail --title "Success" --msgbox "
Install & config complete!
安装配置完成!
" 10 60
else
chVim
fi
;;
b | B )
if(whiptail --title "Yes/No Box" --yesno "
安装VIM并配置 \'vim-for-server\'(https://github.com/wklken/vim-for-server).
yes or no?
" 12 60) then
echo "Use curl or git? If one not work,change to another."
echo "选择git或curl,如果一个方式不行可以换一个。"
echo "1 ) git"
echo "2 ) curl"
echo "Please choose:"
read x
case $x in
2 )
apt -y install curl vim
cp ~/.vimrc ~/.vimrc.bak.pvetools
curl https://raw.githubusercontent.com/wklken/vim-for-server/master/vimrc > ~/.vimrc
whiptail --title "Success" --msgbox "
Install & config complete!
安装配置完成!
" 10 60
;;
1 | "" )
apt -y install git vim
rm -rf vim-for-server
git clone https://github.com/wklken/vim-for-server.git
mv ~/.vimrc ~/.vimrc.bak.pvetools
mv vim-for-server/vimrc ~/.vimrc
rm -rf vim-for-server
whiptail --title "Success" --msgbox "
Install & config complete!
安装配置完成!
" 10 60
;;
* )
chVim
esac
else
chVim
fi
;;
c )
if(whiptail --title "Yes/No Box" --yesno "
Remove Config?
确认要还原配置?
" --defaultno 10 60) then
cp ~/.vimrc.bak.pvetools ~/.vimrc
whiptail --title "Success" --msgbox "
Done
已经完成配置
" 10 60
else
chVim
fi
esac
else
main
fi
}