Skip to content

Commit

Permalink
Add post install methods and fix screen reload when done
Browse files Browse the repository at this point in the history
  • Loading branch information
Xpl0itU committed Mar 26, 2024
1 parent 116e386 commit ea72d85
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 32 deletions.
10 changes: 5 additions & 5 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ services:
return dockerComposeFile
}

func batchCreateDockerContainers(menuItems []MenuItem, frame *tview.Frame) []error {
func batchCreateDockerContainers(menuItems []MenuItem, form *tview.Form) []error {
var errors []error
for _, item := range menuItems {
if !item.Config.IsConfigured() {
continue
}
_, err := item.Config.ConfigureDocker(KIND_DIRECTLY_CONFIGURE_DOCKER, frame)
_, err := item.Config.ConfigureDocker(KIND_DIRECTLY_CONFIGURE_DOCKER, form)
if err != nil {
errors = append(errors, err)
}
Expand Down Expand Up @@ -94,13 +94,13 @@ func pullImageBlocking(imageName string, logView *tview.TextView) error {
return nil
}

func createContainer(name string, containerConfig *container.Config, hostConfig *container.HostConfig, frame *tview.Frame) error {
func createContainer(name string, containerConfig *container.Config, hostConfig *container.HostConfig, form *tview.Form) error {
client, err := getDockerClient()
if err != nil {
return err
}

logView := frame.GetPrimitive().(*tview.TextView)
logView := form.GetFormItemByLabel("").(*tview.TextView)

if err := pullImageBlocking(containerConfig.Image, logView); err != nil {
return err
Expand All @@ -111,7 +111,7 @@ func createContainer(name string, containerConfig *container.Config, hostConfig
return err
}
for _, warning := range out.Warnings {
logView.Write([]byte(warning))
logView.Write([]byte(warning + "\n"))
logView.ScrollToEnd()
}
return client.ContainerStart(context.Background(), out.ID, container.StartOptions{})
Expand Down
10 changes: 8 additions & 2 deletions earnapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (i *EarnAppConfig) ConfigureForm(form *tview.Form, frame *tview.Frame, app
})
}

func (i *EarnAppConfig) ConfigureDocker(kind DockerConfigKind, frame *tview.Frame) (string, error) {
func (i *EarnAppConfig) ConfigureDocker(kind DockerConfigKind, form *tview.Form) (string, error) {
switch kind {
case KIND_DOCKER_COMPOSE:
return `earnapp:
Expand Down Expand Up @@ -96,7 +96,7 @@ func (i *EarnAppConfig) ConfigureDocker(kind DockerConfigKind, frame *tview.Fram
},
},
}
return "", createContainer("earnapp", containerConfig, hostConfig, frame)
return "", createContainer("earnapp", containerConfig, hostConfig, form)
default:
return "", errors.New("unknown kind")
}
Expand All @@ -105,3 +105,9 @@ func (i *EarnAppConfig) ConfigureDocker(kind DockerConfigKind, frame *tview.Fram
func (i *EarnAppConfig) IsConfigured() bool {
return i.Configured
}

func (i *EarnAppConfig) PostConfigure(form *tview.Form, app *tview.Application) {
form.AddButton("Open EarnApp Claim URL", func() {
webbrowser.Open("https://earnapp.com/r/" + i.UUID)
})
}
7 changes: 5 additions & 2 deletions grass.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (i *GrassConfig) ConfigureForm(form *tview.Form, frame *tview.Frame, app *t
})
}

func (i *GrassConfig) ConfigureDocker(kind DockerConfigKind, frame *tview.Frame) (string, error) {
func (i *GrassConfig) ConfigureDocker(kind DockerConfigKind, form *tview.Form) (string, error) {
switch kind {
case KIND_DOCKER_COMPOSE:
return `grass:
Expand All @@ -74,7 +74,7 @@ func (i *GrassConfig) ConfigureDocker(kind DockerConfigKind, frame *tview.Frame)
Name: "unless-stopped",
},
}
return "", createContainer("grass", containerConfig, hostConfig, frame)
return "", createContainer("grass", containerConfig, hostConfig, form)
default:
return "", errors.New("unknown kind")
}
Expand All @@ -83,3 +83,6 @@ func (i *GrassConfig) ConfigureDocker(kind DockerConfigKind, frame *tview.Frame)
func (i *GrassConfig) IsConfigured() bool {
return i.Configured
}

func (i *GrassConfig) PostConfigure(form *tview.Form, app *tview.Application) {
}
7 changes: 5 additions & 2 deletions honeygain.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (i *HoneygainConfig) ConfigureForm(form *tview.Form, frame *tview.Frame, ap
})
}

func (i *HoneygainConfig) ConfigureDocker(kind DockerConfigKind, frame *tview.Frame) (string, error) {
func (i *HoneygainConfig) ConfigureDocker(kind DockerConfigKind, form *tview.Form) (string, error) {
switch kind {
case KIND_DOCKER_COMPOSE:
return `honeygain:
Expand Down Expand Up @@ -87,7 +87,7 @@ func (i *HoneygainConfig) ConfigureDocker(kind DockerConfigKind, frame *tview.Fr
i.DeviceName,
},
}
return "", createContainer("honeygain", containerConfig, hostConfig, frame)
return "", createContainer("honeygain", containerConfig, hostConfig, form)
default:
return "", errors.New("unknown kind")
}
Expand All @@ -96,3 +96,6 @@ func (i *HoneygainConfig) ConfigureDocker(kind DockerConfigKind, frame *tview.Fr
func (i *HoneygainConfig) IsConfigured() bool {
return i.Configured
}

func (i *HoneygainConfig) PostConfigure(form *tview.Form, app *tview.Application) {
}
28 changes: 19 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,27 @@ func main() {
})

list.AddItem("[*] Create Docker Containers", "Create docker containers from the selected items (Recommended)", 0, func() {
dockerFrame := tview.NewFrame(tview.NewTextView().
SetDynamicColors(true).
SetChangedFunc(func() {
app.Draw()
})).
AddText("Creating Docker Containers", true, tview.AlignCenter, tview.Styles.PrimaryTextColor).
AddText("This may take a while", true, tview.AlignCenter, tview.Styles.ContrastSecondaryTextColor)
form.
Clear(true).
SetTitle("Creating Docker Containers").
SetBorder(true).
SetTitleAlign(tview.AlignCenter)
form.
AddTextView("", "", 0, 0, true, true)
logView := form.GetFormItemByLabel("").(*tview.TextView)
logView.SetChangedFunc(func() {
app.Draw()
})

go func() {
errors := batchCreateDockerContainers(menuItems, dockerFrame)
errors := batchCreateDockerContainers(menuItems, form)
if len(errors) == 0 {
form.AddTextView("Success", "All containers created successfully", 0, 0, true, false)
for _, item := range menuItems {
if item.Config.IsConfigured() {
item.Config.PostConfigure(form, app)
}
}
} else {
form.AddTextView("Errors", "Some containers failed to create", 0, 0, true, false)
for _, err := range errors {
Expand All @@ -76,8 +85,9 @@ func main() {
form.AddButton("Return", func() {
returnToMenu(mainFrame, app)
})
app.Draw()
}()
app.SetRoot(dockerFrame, true)
app.SetRoot(form, true)
})
app.SetRoot(mainFrame, true).Run()
}
3 changes: 2 additions & 1 deletion menuItem.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import "github.com/rivo/tview"

type MenuItemConfig interface {
ConfigureForm(form *tview.Form, frame *tview.Frame, app *tview.Application)
ConfigureDocker(kind DockerConfigKind, frame *tview.Frame) (string, error)
ConfigureDocker(kind DockerConfigKind, form *tview.Form) (string, error)
IsConfigured() bool
PostConfigure(form *tview.Form, app *tview.Application)
}

type MenuItem struct {
Expand Down
7 changes: 5 additions & 2 deletions mystnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (i *MystConfig) ConfigureForm(form *tview.Form, frame *tview.Frame, app *tv
})
}

func (i *MystConfig) ConfigureDocker(kind DockerConfigKind, frame *tview.Frame) (string, error) {
func (i *MystConfig) ConfigureDocker(kind DockerConfigKind, form *tview.Form) (string, error) {
switch kind {
case KIND_DOCKER_COMPOSE:
return `myst:
Expand Down Expand Up @@ -73,11 +73,14 @@ func (i *MystConfig) ConfigureDocker(kind DockerConfigKind, frame *tview.Frame)
},
},
}
return "", createContainer("myst", containerConfig, hostConfig, frame)
return "", createContainer("myst", containerConfig, hostConfig, form)
}
return "", errors.New("unknown kind")
}

func (i *MystConfig) IsConfigured() bool {
return i.Configured
}

func (i *MystConfig) PostConfigure(form *tview.Form, app *tview.Application) {
}
7 changes: 5 additions & 2 deletions packetstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (i *PacketStreamConfig) ConfigureForm(form *tview.Form, frame *tview.Frame,
})
}

func (i *PacketStreamConfig) ConfigureDocker(kind DockerConfigKind, frame *tview.Frame) (string, error) {
func (i *PacketStreamConfig) ConfigureDocker(kind DockerConfigKind, form *tview.Form) (string, error) {
switch kind {
case KIND_DOCKER_COMPOSE:
return `packetstream:
Expand All @@ -66,7 +66,7 @@ func (i *PacketStreamConfig) ConfigureDocker(kind DockerConfigKind, frame *tview
Name: "unless-stopped",
},
}
return "", createContainer("packetstream", containerConfig, hostConfig, frame)
return "", createContainer("packetstream", containerConfig, hostConfig, form)
default:
return "", errors.New("unknown kind")
}
Expand All @@ -75,3 +75,6 @@ func (i *PacketStreamConfig) ConfigureDocker(kind DockerConfigKind, frame *tview
func (i *PacketStreamConfig) IsConfigured() bool {
return i.Configured
}

func (i *PacketStreamConfig) PostConfigure(form *tview.Form, app *tview.Application) {
}
7 changes: 5 additions & 2 deletions pawnsapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (i *PawnsAppConfig) ConfigureForm(form *tview.Form, frame *tview.Frame, app
})
}

func (i *PawnsAppConfig) ConfigureDocker(kind DockerConfigKind, frame *tview.Frame) (string, error) {
func (i *PawnsAppConfig) ConfigureDocker(kind DockerConfigKind, form *tview.Form) (string, error) {
switch kind {
case KIND_DOCKER_COMPOSE:
return `pawnsapp:
Expand All @@ -80,7 +80,7 @@ func (i *PawnsAppConfig) ConfigureDocker(kind DockerConfigKind, frame *tview.Fra
Name: "unless-stopped",
},
}
return "", createContainer("pawnsapp", containerConfig, hostConfig, frame)
return "", createContainer("pawnsapp", containerConfig, hostConfig, form)
default:
return "", errors.New("unknown kind")
}
Expand All @@ -89,3 +89,6 @@ func (i *PawnsAppConfig) ConfigureDocker(kind DockerConfigKind, frame *tview.Fra
func (i *PawnsAppConfig) IsConfigured() bool {
return i.Configured
}

func (i *PawnsAppConfig) PostConfigure(form *tview.Form, app *tview.Application) {
}
9 changes: 6 additions & 3 deletions peer2profit.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (i *Peer2ProfitConfig) ConfigureForm(form *tview.Form, frame *tview.Frame,
})
}

func (i *Peer2ProfitConfig) ConfigureDocker(kind DockerConfigKind, frame *tview.Frame) (string, error) {
func (i *Peer2ProfitConfig) ConfigureDocker(kind DockerConfigKind, form *tview.Form) (string, error) {
switch kind {
case KIND_DOCKER_COMPOSE:
compose := `peer2profit:
Expand Down Expand Up @@ -80,7 +80,7 @@ func (i *Peer2ProfitConfig) ConfigureDocker(kind DockerConfigKind, frame *tview.
Name: "unless-stopped",
},
}
if err := createContainer("binfmt", containerConfig, hostConfig, frame); err != nil {
if err := createContainer("binfmt", containerConfig, hostConfig, form); err != nil {
return "", err
}
}
Expand All @@ -96,11 +96,14 @@ func (i *Peer2ProfitConfig) ConfigureDocker(kind DockerConfigKind, frame *tview.
Name: "unless-stopped",
},
}
return "", createContainer("peer2profit", containerConfig, hostConfig, frame)
return "", createContainer("peer2profit", containerConfig, hostConfig, form)
}
return "", errors.New("unknown kind")
}

func (i *Peer2ProfitConfig) IsConfigured() bool {
return i.Configured
}

func (i *Peer2ProfitConfig) PostConfigure(form *tview.Form, app *tview.Application) {
}
7 changes: 5 additions & 2 deletions watchtower.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (i *WatchtowerConfig) ConfigureForm(form *tview.Form, frame *tview.Frame, a
})
}

func (i *WatchtowerConfig) ConfigureDocker(kind DockerConfigKind, frame *tview.Frame) (string, error) {
func (i *WatchtowerConfig) ConfigureDocker(kind DockerConfigKind, form *tview.Form) (string, error) {
switch kind {
case KIND_DOCKER_COMPOSE:
return `watchtower:
Expand All @@ -50,7 +50,7 @@ func (i *WatchtowerConfig) ConfigureDocker(kind DockerConfigKind, frame *tview.F
Name: "always",
},
}
return "", createContainer("watchtower", containerConfig, hostConfig, frame)
return "", createContainer("watchtower", containerConfig, hostConfig, form)
default:
return "", errors.New("unknown kind")
}
Expand All @@ -59,3 +59,6 @@ func (i *WatchtowerConfig) ConfigureDocker(kind DockerConfigKind, frame *tview.F
func (i *WatchtowerConfig) IsConfigured() bool {
return i.Configured
}

func (i *WatchtowerConfig) PostConfigure(form *tview.Form, app *tview.Application) {
}

0 comments on commit ea72d85

Please sign in to comment.