Skip to content

Commit b403567

Browse files
committed
Updated to remove gnome-terminal 'dependency' and added a viewer
1 parent 86adbf5 commit b403567

File tree

7 files changed

+207
-38
lines changed

7 files changed

+207
-38
lines changed

Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ darwin:
6161
@cp tray/dist/cloudseeder-monitor-macos-amd64 "fyne-cross/dist/darwin-amd64/${NAME}.app/Contents/MacOS/cloudseeder-monitor"
6262
@lipo -create -output "fyne-cross/dist/darwin-universal/${NAME}.app/Contents/MacOS/cloudseeder-monitor" "tray/dist/cloudseeder-monitor-macos-arm64" "tray/dist/cloudseeder-monitor-macos-amd64"
6363

64+
@cd viewer && make darwin && cd ..
65+
@cp viewer/dist/cloudseeder-viewer-macos-arm64 "fyne-cross/dist/darwin-arm64/${NAME}.app/Contents/Resources/viewer"
66+
@cp viewer/dist/cloudseeder-viewer-macos-amd64 "fyne-cross/dist/darwin-amd64/${NAME}.app/Contents/Resources/viewer"
67+
@lipo -create -output "fyne-cross/dist/darwin-universal/${NAME}.app/Contents/Resources/viewer" "viewer/dist/cloudseeder-viewer-macos-arm64" "viewer/dist/cloudseeder-viewer-macos-amd64"
68+
6469
@mkdir -p dist/
6570
@mv "fyne-cross/dist/darwin-arm64/${NAME}.app" "dist/${NAME}-mac-arm64.app"
6671
@mv "fyne-cross/dist/darwin-amd64/${NAME}.app" "dist/${NAME}-mac-amd64.app"
@@ -98,6 +103,9 @@ linux-x86:
98103
@cd tray && make linux-x86 && cd ..
99104
@cp tray/dist/cloudseeder-monitor-linux-amd64 "fyne-cross/dist/linux-amd64/bin/cloudseeder-monitor"
100105

106+
@cd viewer && make linux-x86 && cd ..
107+
@cp viewer/dist/cloudseeder-viewer-linux-amd64 "fyne-cross/dist/linux-amd64/Resources/viewer"
108+
101109
@rm fyne-cross/dist/linux-amd64/Makefile
102110

103111
@rm fyne-cross/dist/linux-amd64/${CURRENT_FOLDER}.tar.xz
@@ -145,6 +153,9 @@ linux-arm:
145153
@cd tray && make linux-arm && cd ..
146154
@cp tray/dist/cloudseeder-monitor-linux-arm64 "fyne-cross/dist/linux-arm64/bin/cloudseeder-monitor"
147155

156+
@cd viewer && make linux-arm && cd ..
157+
@cp viewer/dist/cloudseeder-viewer-linux-arm64 "fyne-cross/dist/linux-arm64/Resources/viewer"
158+
148159
@rm fyne-cross/dist/linux-arm64/Makefile
149160

150161
@rm fyne-cross/dist/linux-arm64/${CURRENT_FOLDER}.tar.xz
@@ -191,6 +202,9 @@ windows-x86:
191202
@cd tray && make windows-x86 && cd ..
192203
@cp tray/dist/cloudseeder-monitor-windows-amd64.exe "fyne-cross/dist/windows-amd64/bin/cloudseeder-monitor.exe"
193204

205+
@cd viewer && make windows-x86 && cd ..
206+
@cp viewer/dist/cloudseeder-viewer-windows-amd64.exe "fyne-cross/dist/windows-amd64/Resources/viewer.exe"
207+
194208
@rm fyne-cross/dist/windows-amd64/${CURRENT_FOLDER}.exe.zip
195209

196210
@(cd fyne-cross/dist/ && mv windows-amd64 "${NAME}-windows-amd64" && zip -r "${NAME}-windows-amd64.zip" "./${NAME}-windows-amd64" > /dev/null 2>&1)
@@ -229,6 +243,9 @@ windows-arm:
229243
@cd tray && make windows-arm && cd ..
230244
@cp tray/dist/cloudseeder-monitor-windows-arm64.exe "fyne-cross/dist/windows-arm64/bin/cloudseeder-monitor.exe"
231245

246+
@cd viewer && make windows-arm && cd ..
247+
@cp viewer/dist/cloudseeder-viewer-windows-arm64.exe "fyne-cross/dist/windows-arm64/Resources/viewer.exe"
248+
232249
@rm fyne-cross/dist/windows-arm64/${CURRENT_FOLDER}.exe.zip
233250

234251
@(cd fyne-cross/dist/ && mv windows-arm64 "${NAME}-windows-arm64" && zip -r "${NAME}-windows-arm64.zip" "./${NAME}-windows-arm64" > /dev/null 2>&1)
@@ -245,6 +262,7 @@ clean:
245262
cd backup && make clean && cd ..
246263
cd checker && make clean && cd ..
247264
cd tray && make clean && cd ..
265+
cd viewer && make clean && cd ..
248266

249267
help:
250268
@echo "Available commands:"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Cloud Seeders by IPv6rs will instantly setup a server appliance for you on:
111111

112112
- MacOS (x86 or ARM)
113113
- Windows 10, 11 (x86 only)
114-
- Linux (gnome-terminal required) (x86 or ARM)
114+
- Linux (GUI) (x86 or ARM)
115115

116116
Podman must be installed first.
117117

backup/main.go

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ import (
2828

2929

3030
func main() {
31+
exists := checkBinaryExists("podman")
32+
33+
if !exists {
34+
log.Fatalf("You need to install podman to use this tool.")
35+
}
3136
if len(os.Args) < 3 {
3237
log.Fatalf("Usage: %s [backup|restore] containerName [timestamp]", os.Args[0])
3338
}
@@ -318,18 +323,59 @@ func restoreContainer(containerName, imageFilePath, configFilePath string) error
318323
return recreateContainerFromConfig(containerName, imageFilePath, configFilePath)
319324
}
320325

326+
func checkBinaryExists(binaryName string) bool {
327+
if runtime.GOOS == "windows" && filepath.Ext(binaryName) != ".exe" {
328+
binaryName += ".exe"
329+
}
330+
331+
_, err := exec.LookPath(binaryName)
332+
if err != nil {
333+
commonPaths := []string{
334+
"/usr/local/bin/",
335+
"/usr/bin/",
336+
"/bin/",
337+
"/usr/local/bin/",
338+
"/opt/homebrew/bin/",
339+
"/opt/podman/bin/",
340+
"C:\\Program Files (x86)\\Podman\\",
341+
"C:\\Program Files\\RedHat\\Podman\\",
342+
}
343+
for _, path := range commonPaths {
344+
fullPath := filepath.Join(path, binaryName)
345+
if _, err := os.Stat(fullPath); err == nil {
346+
addPath(path)
347+
fmt.Printf("Found '%s' at '%s'\n", binaryName, fullPath)
348+
return true
349+
}
350+
}
351+
352+
return false
353+
}
354+
return true
355+
}
356+
321357
func getPodmanExecutable() string {
322358
switch runtime.GOOS {
323359
case "windows":
324360
return "podman.exe"
325361
case "linux":
326362
return "podman"
327363
case "darwin":
328-
return "/opt/podman/bin/podman"
364+
return "podman"
329365
default:
330366
fmt.Println("Unsupported")
331367
return ""
332368
}
369+
}
370+
371+
func addPath(dirs ...string) error {
372+
originalPath := os.Getenv("PATH")
373+
additionalPath := strings.Join(dirs, string(os.PathListSeparator))
374+
newPath := originalPath + string(os.PathListSeparator) + additionalPath
375+
if err := os.Setenv("PATH", newPath); err != nil {
376+
return err
377+
}
378+
return nil
333379
}
334-
380+
335381

checker/main.go

Lines changed: 69 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,29 @@ type UIItem struct {
4949

5050

5151
func main() {
52-
appliances, err := getApplianceVersions()
53-
if err != nil {
54-
fmt.Printf("Error reading appliance versions: %v\n", err)
55-
return
56-
}
57-
uiState, err := getUIStateConfig()
58-
if err != nil {
59-
fmt.Printf("Error reading UI update config: %v\n", err)
60-
return
61-
}
62-
edited := checkAndUpdateContainers(appliances, &uiState)
63-
if edited {
64-
if err := saveUIStateConfig(uiState); err != nil {
65-
fmt.Printf("Error writing UI update config: %v\n", err)
66-
}
52+
exists := checkBinaryExists("podman")
53+
54+
if !exists {
55+
fmt.Printf("You need to install podman to use this tool.")
6756
} else {
68-
fmt.Println("No changes.")
57+
appliances, err := getApplianceVersions()
58+
if err != nil {
59+
fmt.Printf("Error reading appliance versions: %v\n", err)
60+
return
61+
}
62+
uiState, err := getUIStateConfig()
63+
if err != nil {
64+
fmt.Printf("Error reading UI update config: %v\n", err)
65+
return
66+
}
67+
edited := checkAndUpdateContainers(appliances, &uiState)
68+
if edited {
69+
if err := saveUIStateConfig(uiState); err != nil {
70+
fmt.Printf("Error writing UI update config: %v\n", err)
71+
}
72+
} else {
73+
fmt.Println("No changes.")
74+
}
6975
}
7076
}
7177

@@ -234,18 +240,13 @@ func insertUpgradeOption(index int, uiState *UIState, item UIItem, appliance str
234240
scriptPath = filepath.Join(homeDir, ".ipv6rs", "upgrade.sh")
235241
}
236242

237-
var upgradeCommand string
238-
if runtime.GOOS == "windows" {
239-
upgradeCommand = fmt.Sprintf("'%s', '%s', '%s', '%d'", scriptPath, item.Title, appliance, newVersion)
240-
} else {
241-
upgradeCommand = fmt.Sprintf("'%s' '%s' '%s' '%d'", scriptPath, item.Title, appliance, newVersion)
242-
}
243+
upgradeCommand := fmt.Sprintf("'%s' '%s' '%s' '%d'", scriptPath, item.Title, appliance, newVersion)
243244
terminalCommand := getShellCommand(upgradeCommand)
244-
245245
upgradeItem := UIItem{
246246
Title: "Upgrade",
247247
Exec: terminalCommand,
248248
Icon: "UploadIcon",
249+
Hide: true,
249250
}
250251

251252
if index >= 0 && index < len(uiState.Items) {
@@ -259,28 +260,69 @@ func insertUpgradeOption(index int, uiState *UIState, item UIItem, appliance str
259260
func getShellCommand(command string) string {
260261
switch runtime.GOOS {
261262
case "windows":
262-
return fmt.Sprintf("Start-Process powershell -ArgumentList '-NoExit', '-File', %s", command)
263+
return fmt.Sprintf(`& '%s/viewer.exe' %s`, getConfigPath(), command)
263264
case "darwin":
264-
return fmt.Sprintf("osascript -e 'tell application \"Terminal\" to do script \"%s\"'", command)
265+
return fmt.Sprintf(`'%s/viewer' "%s"`, getConfigPath(), command)
265266
case "linux":
266-
return fmt.Sprintf("gnome-terminal -- bash -c '%s; exec bash'", command)
267+
return fmt.Sprintf(`'%s/viewer' "%s; exec bash"`, getConfigPath(), command)
267268
default:
268269
fmt.Println("Unsupported platform")
269270
return ""
270271
}
271272
}
272273

274+
func checkBinaryExists(binaryName string) bool {
275+
if runtime.GOOS == "windows" && filepath.Ext(binaryName) != ".exe" {
276+
binaryName += ".exe"
277+
}
278+
279+
_, err := exec.LookPath(binaryName)
280+
if err != nil {
281+
commonPaths := []string{
282+
"/usr/local/bin/",
283+
"/usr/bin/",
284+
"/bin/",
285+
"/usr/local/bin/",
286+
"/opt/homebrew/bin/",
287+
"/opt/podman/bin/",
288+
"C:\\Program Files (x86)\\Podman\\",
289+
"C:\\Program Files\\RedHat\\Podman\\",
290+
}
291+
for _, path := range commonPaths {
292+
fullPath := filepath.Join(path, binaryName)
293+
if _, err := os.Stat(fullPath); err == nil {
294+
addPath(path)
295+
fmt.Printf("Found '%s' at '%s'\n", binaryName, fullPath)
296+
return true
297+
}
298+
}
299+
300+
return false
301+
}
302+
return true
303+
}
304+
273305
func getPodmanExecutable() string {
274306
switch runtime.GOOS {
275307
case "windows":
276308
return "podman.exe"
277309
case "linux":
278310
return "podman"
279311
case "darwin":
280-
return "/opt/podman/bin/podman"
312+
return "podman"
281313
default:
282314
fmt.Println("Unsupported")
283315
return ""
284316
}
285317
}
286318

319+
func addPath(dirs ...string) error {
320+
originalPath := os.Getenv("PATH")
321+
additionalPath := strings.Join(dirs, string(os.PathListSeparator))
322+
newPath := originalPath + string(os.PathListSeparator) + additionalPath
323+
if err := os.Setenv("PATH", newPath); err != nil {
324+
return err
325+
}
326+
return nil
327+
}
328+

src/init.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,24 +174,31 @@ func setupInitialFiles() {
174174
log.Println("No sideload.json found or error reading: ", err)
175175
}
176176

177+
viewer := "viewer"
177178
backup := "backup"
178179
checker := "checker"
179180
upgrade := "upgrade"
180181
if runtime.GOOS == "windows" {
181182
backup += ".exe"
182183
checker += ".exe"
183184
upgrade += ".ps1"
185+
viewer += ".exe"
184186
} else {
185187
upgrade += ".sh"
186188
}
187189

190+
srcViewerFile := filepath.Join(resourcesPath, viewer)
188191
srcBackupFile := filepath.Join(resourcesPath, backup)
189192
srcCheckerFile := filepath.Join(resourcesPath, checker)
190193
srcUpgradeFile := filepath.Join(resourcesPath, upgrade)
194+
destViewerFile := filepath.Join(configPath, viewer)
191195
destBackupFile := filepath.Join(configPath, backup)
192196
destCheckerFile := filepath.Join(configPath, checker)
193197
destUpgradeFile := filepath.Join(configPath, upgrade)
194198

199+
if err := copyFile(srcViewerFile, destViewerFile); err != nil {
200+
log.Fatalf("Failed to copy viewer file: %v", err)
201+
}
195202
if err := copyFile(srcBackupFile, destBackupFile); err != nil {
196203
log.Fatalf("Failed to copy backup file: %v", err)
197204
}
@@ -203,6 +210,10 @@ func setupInitialFiles() {
203210
}
204211

205212
if runtime.GOOS != "windows" {
213+
err = os.Chmod(destViewerFile, 0755)
214+
if err != nil {
215+
log.Fatalf("Failed to chmod the viewer file: %v", err)
216+
}
206217
err = os.Chmod(destBackupFile, 0755)
207218
if err != nil {
208219
log.Fatalf("Failed to chmod the backup file: %v", err)

src/main.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ package main
1414

1515
import (
1616
"github.com/ipv6rslimited/configurator"
17+
"strings"
1718
"encoding/json"
1819
"fyne.io/fyne/v2"
1920
"fyne.io/fyne/v2/app"
@@ -26,7 +27,6 @@ import (
2627
"path/filepath"
2728
"io/ioutil"
2829
"log"
29-
"time"
3030
"os"
3131
"os/exec"
3232
"runtime"
@@ -122,8 +122,6 @@ func main() {
122122
)))
123123
splashWindow.Show()
124124

125-
time.Sleep(1 * time.Second)
126-
127125
setupInitialFiles()
128126
statusLabel.SetText("Loading Appliances...")
129127
applianceInfos, err = loadAppliancesFromJSON(filepath.Join(configPath, "appliances.json"))
@@ -132,7 +130,6 @@ func main() {
132130
log.Fatal(err)
133131
}
134132
updateUI(myApp, myWindow, configPath)
135-
time.Sleep(1 * time.Second)
136133

137134
splashWindow.Close()
138135
myWindow.Show()
@@ -227,6 +224,16 @@ func makeCardInteractive(app fyne.App, window fyne.Window, card *widget.Card, ac
227224
return cardContainer
228225
}
229226

227+
func addPath(dirs ...string) error {
228+
originalPath := os.Getenv("PATH")
229+
additionalPath := strings.Join(dirs, string(os.PathListSeparator))
230+
newPath := originalPath + string(os.PathListSeparator) + additionalPath
231+
if err := os.Setenv("PATH", newPath); err != nil {
232+
return err
233+
}
234+
return nil
235+
}
236+
230237
func createConfirmationWindow(app fyne.App, requirements string, target string) {
231238
win := app.NewWindow("Confirmation")
232239
win.Resize(fyne.NewSize(600, 300))
@@ -294,12 +301,16 @@ func checkBinaryExists(binaryName string) bool {
294301
"/usr/local/bin/",
295302
"/usr/bin/",
296303
"/bin/",
297-
"/opt/",
304+
"/usr/local/bin/",
305+
"/opt/homebrew/bin/",
306+
"/opt/podman/bin/",
298307
"C:\\Program Files (x86)\\Podman\\",
308+
"C:\\Program Files\\RedHat\\Podman\\",
299309
}
300310
for _, path := range commonPaths {
301311
fullPath := filepath.Join(path, binaryName)
302312
if _, err := os.Stat(fullPath); err == nil {
313+
addPath(path)
303314
fmt.Printf("Found '%s' at '%s'\n", binaryName, fullPath)
304315
return true
305316
}

0 commit comments

Comments
 (0)