Skip to content

Commit 2e122c5

Browse files
authored
Merge pull request #51 from KiraCore/feature/root_and_password_deploy_imrpv
added root check and auto sudo password fill if user entered passwod before
2 parents 14d1ecf + 56cbf2d commit 2e122c5

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

gui/dialog_connect.go

+3
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ func (g *Gui) ShowConnect() {
223223
g.Host = &Host{
224224
IP: ip,
225225
}
226+
if !privKeyState {
227+
g.Host.UserPassword = &passwordEntry.Text
228+
}
226229
go g.sshAliveTracker()
227230
g.ConnectionStatusBinding.Set(true)
228231
wizard.Hide()

gui/dialog_deploy.go

+29-3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,29 @@ func showDeployDialog(g *Gui, doneListener binding.DataListener, shidaiInfra bin
4444
showSudoEnteringDialog(g, sudoPasswordBinding, sudoCheck)
4545
})
4646

47+
log.Printf("rootState = %v", g.sshClient.User() == "root")
48+
49+
if g.sshClient.User() == "root" {
50+
sudoCheck.Set(true)
51+
if !sudoPasswordEntryButton.Hidden {
52+
sudoPasswordEntryButton.Hide()
53+
}
54+
}
55+
if g.Host.UserPassword == nil && g.sshClient.User() != "root" {
56+
sudoCheck.Set(false)
57+
if sudoPasswordEntryButton.Hidden {
58+
sudoPasswordEntryButton.Show()
59+
}
60+
log.Println("Sudo password is nil, assuming we connected with key")
61+
} else if g.Host.UserPassword != nil && g.sshClient.User() != "root" {
62+
sudoCheck.Set(true)
63+
if !sudoPasswordEntryButton.Hidden {
64+
sudoPasswordEntryButton.Hide()
65+
}
66+
log.Println("Sudo password is not nil, applying password from connect dialog")
67+
sudoPasswordBinding.Set(*g.Host.UserPassword)
68+
}
69+
4770
doneMnemonicDataListener := binding.NewDataListener(func() {
4871
mnemonicCheck.Set(true)
4972
})
@@ -143,14 +166,18 @@ func showDeployDialog(g *Gui, doneListener binding.DataListener, shidaiInfra bin
143166

144167
bootstrapFileUrl := types.BOOTSTRAP_SCRIPT
145168
// filePathToSaveOnRemote := filepath.Join("/home/", g.sshClient.User(), "bootstrap.sh")
169+
// var cmdForDeploy string:= fmt.Sprintf(`echo '%v' | sudo -S sh -c "%v --sekai=%v --interx=%v 2>&1"`, sP, filePathToSaveOnRemote, sekaiVersion, interxVersion)
146170
var filePathToSaveOnRemote string
147171
bootstrapFileName := "bootstrap.sh"
172+
173+
var cmdForDeploy string
148174
if g.sshClient.User() == "root" {
149175
filePathToSaveOnRemote = fmt.Sprintf("/%v/%v", g.sshClient.User(), bootstrapFileName)
176+
cmdForDeploy = fmt.Sprintf(`%v --sekai=%v --interx=%v 2>&1`, filePathToSaveOnRemote, sekaiVersion, interxVersion)
150177
} else {
151178
filePathToSaveOnRemote = fmt.Sprintf("/home/%v/%v", g.sshClient.User(), bootstrapFileName)
179+
cmdForDeploy = fmt.Sprintf(`echo '%v' | sudo -S sh -c "%v --sekai=%v --interx=%v 2>&1"`, sP, filePathToSaveOnRemote, sekaiVersion, interxVersion)
152180
}
153-
154181
log.Println("Bootstrap file save path:", filePathToSaveOnRemote)
155182
f, err := httph.MakeHttpRequest(bootstrapFileUrl, "GET")
156183
if err != nil {
@@ -174,9 +201,8 @@ func showDeployDialog(g *Gui, doneListener binding.DataListener, shidaiInfra bin
174201
return
175202
}
176203

177-
cmdForDeploy := fmt.Sprintf(`echo '%v' | sudo -S sh -c "%v --sekai=%v --interx=%v 2>&1"`, sP, filePathToSaveOnRemote, sekaiVersion, interxVersion)
204+
log.Printf("CMD for deploy: <%v>", cmdForDeploy)
178205
showCmdExecDialogAndRunCmdV4(g, "Deploying", cmdForDeploy, true, deployErrorBinding, errorMessageBinding)
179-
180206
errB, _ = deployErrorBinding.Get()
181207
if errB {
182208
errMsg, _ := errorMessageBinding.Get()

gui/gui.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ type TxExecBinding struct {
3737
TxDoneListener binding.DataListener
3838
}
3939
type Host struct {
40-
IP string
40+
IP string
41+
UserPassword *string
4142
}
4243

4344
func (g *Gui) MakeGui() fyne.CanvasObject {

gui/screen_status.go

+2
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ func makeStatusScreen(_ fyne.Window, g *Gui) fyne.CanvasObject {
130130
log.Println("enable state: ", deployButtonCheck)
131131
if deployButtonCheck {
132132
deployButton.Enable()
133+
} else {
134+
deployButton.Disable()
133135
}
134136

135137
defer g.WaitDialog.HideWaitDialog()

0 commit comments

Comments
 (0)