diff --git a/docker.go b/docker.go index 1284177..cd1273d 100644 --- a/docker.go +++ b/docker.go @@ -2,6 +2,7 @@ package main import ( "context" + "strings" "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/image" @@ -41,7 +42,9 @@ services: if err != nil { continue } - dockerComposeFile += dockerCompose + for _, line := range strings.Split(dockerCompose, "\n") { + dockerComposeFile += "\t" + line + "\n" + } } return dockerComposeFile } diff --git a/earnapp.go b/earnapp.go index 6fa9894..3e75f83 100644 --- a/earnapp.go +++ b/earnapp.go @@ -86,13 +86,13 @@ func (i *EarnAppConfig) ConfigureDocker(kind DockerConfigKind, form *tview.Form) switch kind { case KIND_DOCKER_COMPOSE: return `earnapp: - image: ` + EARNAPP_IMAGE_NAME + ` - environment: - - EARNAPP_UUID=` + i.UUID + ` - - EARNAPP_TERM="yes" - volumes: - - earnapp-data:/etc/earnapp - restart: unless-stopped + image: ` + EARNAPP_IMAGE_NAME + ` + environment: + - EARNAPP_UUID=` + i.UUID + ` + - EARNAPP_TERM="yes" + volumes: + - earnapp-data:/etc/earnapp + restart: unless-stopped `, nil case KIND_DIRECTLY_CONFIGURE_DOCKER: containerConfig := &container.Config{ diff --git a/grass.go b/grass.go index 0be9e56..e65484a 100644 --- a/grass.go +++ b/grass.go @@ -65,11 +65,11 @@ func (i *GrassConfig) ConfigureDocker(kind DockerConfigKind, form *tview.Form) ( switch kind { case KIND_DOCKER_COMPOSE: return `grass: - image: ` + GRASS_IMAGE_NAME + ` - environment: - - GRASS_USER=` + i.Email + ` - - GRASS_PASS=` + i.Password + ` - restart: unless-stopped + image: ` + GRASS_IMAGE_NAME + ` + environment: + - GRASS_USER=` + i.Email + ` + - GRASS_PASS=` + i.Password + ` + restart: unless-stopped `, nil case KIND_DIRECTLY_CONFIGURE_DOCKER: containerConfig := &container.Config{ diff --git a/honeygain.go b/honeygain.go index 3099ef3..f946904 100644 --- a/honeygain.go +++ b/honeygain.go @@ -71,11 +71,11 @@ func (i *HoneygainConfig) ConfigureDocker(kind DockerConfigKind, form *tview.For switch kind { case KIND_DOCKER_COMPOSE: return `honeygain: - image: ` + HONEYGAIN_IMAGE_NAME + ` - restart: unless-stopped - environment: - - HONEYGAIN_DUMMY='' - command: -tou-accept -email ` + i.Email + ` -pass ` + i.Password + ` -device ` + i.DeviceName + "\n", nil + image: ` + HONEYGAIN_IMAGE_NAME + ` + restart: unless-stopped + environment: + - HONEYGAIN_DUMMY='' + command: -tou-accept -email ` + i.Email + ` -pass ` + i.Password + ` -device ` + i.DeviceName + "\n", nil case KIND_DIRECTLY_CONFIGURE_DOCKER: hostConfig := &container.HostConfig{ RestartPolicy: container.RestartPolicy{ diff --git a/main.go b/main.go index f9529bc..46d8a49 100644 --- a/main.go +++ b/main.go @@ -48,6 +48,13 @@ func main() { form.AddTextView("Success", "Copied to clipboard", 0, 1, true, false) } }) + form.AddButton("Save to File", func() { + if err := saveToFile("compose.yml", dockerComposeFile); err != nil { + form.AddTextView("Error", "Failed to save to file", 0, 1, true, false) + } else { + form.AddTextView("Success", "Saved to file", 0, 1, true, false) + } + }) form.AddButton("Return", func() { returnToMenu(mainFrame, app) }) diff --git a/mystnode.go b/mystnode.go index 30a7f37..220cea9 100644 --- a/mystnode.go +++ b/mystnode.go @@ -48,18 +48,18 @@ func (i *MystConfig) ConfigureDocker(kind DockerConfigKind, form *tview.Form) (s switch kind { case KIND_DOCKER_COMPOSE: return `myst: - image: ` + MYST_IMAGE_NAME + ` - environment: - - MYSTNODE_DUMMY='' - command: service --agreed-terms-and-conditions - network_mode: host - cap_add: - - NET_ADMIN - ports: - - "4449:4449" - volumes: - - myst-data:/var/lib/mysterium-node - restart: unless-stopped + image: ` + MYST_IMAGE_NAME + ` + environment: + - MYSTNODE_DUMMY='' + command: service --agreed-terms-and-conditions + network_mode: host + cap_add: + - NET_ADMIN + ports: + - "4449:4449" + volumes: + - myst-data:/var/lib/mysterium-node + restart: unless-stopped `, nil case KIND_DIRECTLY_CONFIGURE_DOCKER: containerConfig := &container.Config{ diff --git a/packetstream.go b/packetstream.go index 703d286..9fad94a 100644 --- a/packetstream.go +++ b/packetstream.go @@ -59,10 +59,10 @@ func (i *PacketStreamConfig) ConfigureDocker(kind DockerConfigKind, form *tview. switch kind { case KIND_DOCKER_COMPOSE: return `packetstream: - image: ` + PACKETSTREAM_IMAGE_NAME + ` - environment: - - CID=` + i.CID + ` - restart: unless-stopped + image: ` + PACKETSTREAM_IMAGE_NAME + ` + environment: + - CID=` + i.CID + ` + restart: unless-stopped `, nil case KIND_DIRECTLY_CONFIGURE_DOCKER: containerConfig := &container.Config{ diff --git a/pawnsapp.go b/pawnsapp.go index c9bdbd3..cdcd83a 100644 --- a/pawnsapp.go +++ b/pawnsapp.go @@ -71,11 +71,11 @@ func (i *PawnsAppConfig) ConfigureDocker(kind DockerConfigKind, form *tview.Form switch kind { case KIND_DOCKER_COMPOSE: return `pawnsapp: - image: ` + PAWNSAPP_IMAGE_NAME + ` - environment: - - IPROYALPAWNS_DUMMY='' - command: -accept-tos -email=` + i.Email + ` -password=` + i.Password + ` -device-name=` + i.DeviceName + ` -device-id=id_` + i.DeviceName + ` - restart: unless-stopped + image: ` + PAWNSAPP_IMAGE_NAME + ` + environment: + - IPROYALPAWNS_DUMMY='' + command: -accept-tos -email=` + i.Email + ` -password=` + i.Password + ` -device-name=` + i.DeviceName + ` -device-id=id_` + i.DeviceName + ` + restart: unless-stopped `, nil case KIND_DIRECTLY_CONFIGURE_DOCKER: containerConfig := &container.Config{ diff --git a/peer2profit.go b/peer2profit.go index eb434ff..ab54097 100644 --- a/peer2profit.go +++ b/peer2profit.go @@ -60,19 +60,19 @@ func (i *Peer2ProfitConfig) ConfigureDocker(kind DockerConfigKind, form *tview.F switch kind { case KIND_DOCKER_COMPOSE: compose := `peer2profit: - image: ` + PEER2PROFIT_IMAGE_NAME + ` - environment: - - email=` + i.Email + ` - - use_proxy=false - restart: unless-stopped - platform: linux/amd64 + image: ` + PEER2PROFIT_IMAGE_NAME + ` + environment: + - email=` + i.Email + ` + - use_proxy=false + restart: unless-stopped + platform: linux/amd64 ` if runtime.GOARCH == "arm64" { return compose + `binfmt: - image: tonistiigi/binfmt:latest - privileged: true - command: --install all - restart: unless-stopped + image: tonistiigi/binfmt:latest + privileged: true + command: --install all + restart: unless-stopped `, nil } return compose, nil diff --git a/utils.go b/utils.go index 9fb82c4..0fbf452 100644 --- a/utils.go +++ b/utils.go @@ -4,6 +4,7 @@ import ( "crypto/md5" "fmt" "math/rand" + "os" "time" ) @@ -25,3 +26,18 @@ func randomString(length int) string { func generateEarnAppUUID() string { return fmt.Sprintf("sdk-node-%x", md5.Sum([]byte(randomString(32)))) } + +func saveToFile(filename, data string) error { + file, err := os.Create(filename) + if err != nil { + return err + } + defer file.Close() + + _, err = file.WriteString(data) + if err != nil { + return err + } + + return nil +} diff --git a/watchtower.go b/watchtower.go index 875e178..ba6f8a1 100644 --- a/watchtower.go +++ b/watchtower.go @@ -33,10 +33,10 @@ func (i *WatchtowerConfig) ConfigureDocker(kind DockerConfigKind, form *tview.Fo switch kind { case KIND_DOCKER_COMPOSE: return `watchtower: - image: ` + WATCHTOWER_IMAGE_NAME + ` - volumes: - - /var/run/docker.sock:/var/run/docker.sock - restart: always + image: ` + WATCHTOWER_IMAGE_NAME + ` + volumes: + - /var/run/docker.sock:/var/run/docker.sock + restart: always `, nil case KIND_DIRECTLY_CONFIGURE_DOCKER: containerConfig := &container.Config{