-
Notifications
You must be signed in to change notification settings - Fork 0
/
installation.go
128 lines (105 loc) · 3.43 KB
/
installation.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
//go:build install
package main
import (
"fmt"
"go/build"
"os"
"os/exec"
"path/filepath"
"runtime"
)
var dependencies = map[string]string{
"pidof": "Please install `pidof` on your local machine to continue installationg, e.g for Ubuntu: sudo apt-get pidof",
"wails": "You'll need the wails cli to build the desktop application, run `go install github.com/wailsapp/wails/v2/cmd/wails@latest` or visit https://wails.io/docs/gettingstarted/installation",
"templ": "You'll need the templ cli to compile the frontend, run `go install github.com/a-h/templ/cmd/templ@latest` or visit https://templ.guide/quick-start/installation",
"tailwindcss": "You'll need the tailwindcss cli to compile the frontend, visit https://tailwindcss.com/blog/standalone-cli and ensure to rename the binary to `tailwindcss`",
"badger": "You'll need the badger cli for the database, run `go install go install github.com/dgraph-io/badger/v4/badger@latest",
}
func main() {
if runtime.GOOS != "linux" {
fmt.Println("This program is only supported on Linux for now")
os.Exit(1)
}
if !isXorgRunning() {
fmt.Println("Xorg server is not running, ensure you are running this program on a graphical environment using X11.")
os.Exit(1)
}
var dependenciesUnmet bool
for dep, msg := range dependencies {
if !checkBinaryExists(dep) {
fmt.Println(msg)
dependenciesUnmet = true
}
}
if dependenciesUnmet {
os.Exit(1)
}
fmt.Println("You have all neccessary dependencies...")
smDaemonDesktopFile := fmt.Sprintf(daemonAutoStart, getGOPATH())
smDaemonTrayIconDesktopFile := fmt.Sprintf(trayIconAutoStart, getGOPATH())
for fileName, data := range map[string][]byte{"smDaemon.desktop": []byte(smDaemonDesktopFile), "smTrayIcon.desktop": []byte(smDaemonTrayIconDesktopFile)} {
if err := writeDesktopFile(fileName, data); err != nil {
fmt.Printf("Failed to write desktop file for %s: err : %s\n", fileName, err.Error())
os.Exit(1)
}
if err := os.Rename(fileName, autoStartDir(fileName)); err != nil {
fmt.Printf("Failed to move %s to %s: err : %s\n", fileName, autoStartDir(""), err.Error())
os.Exit(1)
}
}
fmt.Printf("created a two .desktop files (smDaemon.desktop, smTrayIcon.desktop) and move them to %s/\n", autoStartDir(""))
os.Exit(0)
}
func checkBinaryExists(binary string) bool {
_, err := exec.LookPath(binary)
return err == nil
}
func isXorgRunning() bool {
cmd := exec.Command("pidof", "Xorg")
err := cmd.Run()
return err == nil
}
var daemonAutoStart = `[Desktop Entry]
Type=Application
Exec=%s/bin/smDaemon restart
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name[en_US]=smDaemon
Name=smDaemon
Comment[en_US]=ME...
Comment=ME...
`
var trayIconAutoStart = `[Desktop Entry]
Type=Application
Exec=%s/bin/smTrayIcon
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name[en_US]=smDesktop
Name=smDesktop
Comment[en_US]=ME...
Comment=ME...
`
func getGOPATH() string {
var gopath string
if gopath = build.Default.GOPATH; gopath == "" {
if gopath = os.Getenv("GOPATH"); gopath == "" {
os.Exit(1)
}
}
return gopath
}
func writeDesktopFile(fileName string, data []byte) error {
return os.WriteFile(fileName, data, 0644)
}
func autoStartDir(fileName string) string {
if runtime.GOOS == "linux" { // xdgConfigHome := os.Getenv("XDG_CONFIG_HOME")
return filepath.Join(os.Getenv("HOME"), ".config", "autostart", fileName)
}
if runtime.GOOS == "windows" {
}
if runtime.GOOS == "darwin" {
}
return ""
}