-
Notifications
You must be signed in to change notification settings - Fork 0
/
base_upg.go
167 lines (160 loc) · 4.1 KB
/
base_upg.go
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
// main
package main
import (
"fmt"
"strings"
"time"
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
)
func run_upg(Mw *walk.MainWindow) {
defer my_recover()
in := &Install{}
Dialog{
AssignTo: &in.Mw,
Title: "安装包安装",
MinSize: Size{900, 600},
Layout: VBox{MarginsZero: true},
Name: Getuuid(),
Children: []Widget{
Composite{
Layout: HBox{},
Children: []Widget{
Label{
Text: "ip",
},
LineEdit{
AssignTo: &in.Ip,
Text: "7.7.11.160,7.7.16.24,7.7.16.25,7.7.16.26,7.7.16.28,7.7.16.29,7.7.16.11,7.7.16.12,7.7.16.13,7.7.16.14,7.7.16.15,7.7.16.16,7.7.16.17,7.7.16.90,7.7.16.92,3.3.3.2,3.3.3.3,3.3.3.4,3.3.3.5,3.3.3.8,3.3.3.9",
},
Label{
Text: "端口",
},
LineEdit{
Text: "22",
AssignTo: &in.Port,
MaxSize: Size{100, 100},
},
Label{
Text: "密码",
},
LineEdit{
AssignTo: &in.passwd,
Text: "inet-eyed",
MaxSize: Size{100, 100},
},
},
},
Composite{
Layout: HBox{},
Children: []Widget{
Label{
Text: "安装包",
},
LineEdit{
AssignTo: &in.Path,
},
PushButton{
Text: "浏览",
OnClicked: in.select_file,
},
PushButton{
Text: "安装",
OnClicked: in.install_run,
},
},
},
TextEdit{
AssignTo: &in.Res,
ReadOnly: true,
VScroll: true,
MaxLength: 999999999,
},
},
}.Run(Mw)
}
type Install struct {
Mw *walk.Dialog
Ip *walk.LineEdit
passwd *walk.LineEdit
Port *walk.LineEdit
Path *walk.LineEdit
Res *walk.TextEdit
}
func (my *Install) install_run() {
go my.install()
}
func (my *Install) install() {
buf := []string{}
f, err := walk.NewFont("宋体", 12, walk.FontBold)
if err == nil {
my.Res.SetFont(f)
}
if Isexist(my.Path.Text()) {
ips := strings.Split(my.Ip.Text(), ",")
for _, ip := range ips {
my.Res.SetText("准备安装\n")
my.Res.AppendText(fmt.Sprintf("安装包(%s)存在\n", my.Path.Text()))
my.Res.AppendText(fmt.Sprintf("连接服务器(ip:%s)(port:%s)(用户:root)\n", ip, my.Port.Text()))
client, err := Connect_ssh(ip, my.Port.Text(), "root", my.passwd.Text())
if err != nil {
my.Res.AppendText(err.Error() + "\n")
continue
}
defer client.Close()
my.Res.AppendText(fmt.Sprintf("服务器连接成功\n"))
my.Res.AppendText(fmt.Sprintf("准备发送安装包\n"))
_, err = Sendfile_sftp(client, my.Path.Text(), fmt.Sprintf("/opt/base.tar.gz"))
if err != nil {
my.Res.AppendText(err.Error() + "\n")
continue
} else {
my.Res.AppendText(fmt.Sprintf("安装包发送成功\n"))
}
cmd := []string{}
cmd = append(cmd, "cd /opt/")
cmd = append(cmd, "rm -rf /opt/updateservice")
cmd = append(cmd, "tar -zxvf base.tar.gz")
cmd = append(cmd, "cd /opt/updateservice/bin")
cmd = append(cmd, "chmod +x /opt/updateservice/bin/*")
cmd = append(cmd, "./setup.sh")
d, err := Runcmd_ssh_mul(client, cmd)
if err != nil {
my.Res.AppendText(fmt.Sprintf("安装失败(%s)\n", err.Error()))
continue
}
fmt.Println(string(d))
v := strings.Split(string(d), "\n")
for _, v1 := range v {
my.Res.AppendText(v1 + "\n")
}
my.Res.AppendText(fmt.Sprintf("安装成功\n"))
time.Sleep(1000 * 1000 * 1000)
buf = append(buf, fmt.Sprintf("(ip:%s)(port:%s)(用户:root)(安装包:%s)\n", ip, my.Port.Text(), my.Path.Text()))
}
} else {
my.Res.AppendText(fmt.Sprintf("文件不存在,请重新选择\n"))
}
if len(buf) > 1 {
my.Res.SetText("<------------------>\n")
for _, line := range buf {
my.Res.AppendText(line)
}
my.Res.AppendText("全部安装完成")
}
}
func (my *Install) select_file() {
dlg := new(walk.FileDialog)
dlg.FilePath = ""
dlg.Title = "选择安装包"
dlg.Filter = "安装包(*.*)"
ok, err := dlg.ShowOpen(nil)
if err != nil {
fmt.Println(err.Error())
return
}
if !ok {
return
}
my.Path.SetText(dlg.FilePath)
}