aboutsummaryrefslogtreecommitdiffsponsor
diff options
context:
space:
mode:
-rw-r--r--internal/exec.go21
-rw-r--r--internal/service/service.go13
2 files changed, 34 insertions, 0 deletions
diff --git a/internal/exec.go b/internal/exec.go
new file mode 100644
index 0000000..6ed3e5c
--- /dev/null
+++ b/internal/exec.go
@@ -0,0 +1,21 @@
+package internal
+
+import (
+ "fmt"
+ "os/exec"
+)
+
+type CommandNotFound string
+
+func (e CommandNotFound) Error() string {
+ return fmt.Sprintf("command '%s' is missing and must be present for operation", string(e))
+}
+
+func RequireCommand(cmd string) error {
+ _, err := exec.LookPath(cmd)
+ if err != nil {
+ return CommandNotFound(cmd)
+ }
+
+ return nil
+}
diff --git a/internal/service/service.go b/internal/service/service.go
index 38cabf8..9fbacfb 100644
--- a/internal/service/service.go
+++ b/internal/service/service.go
@@ -10,9 +10,16 @@ import (
"sync"
"time"
+ "git.server.ky/slackcoder/mirror/internal"
"git.server.ky/slackcoder/mirror/internal/github"
)
+// These commands are required by the service to operate.
+var requiredCommands = []string{
+ "git",
+ "rsync",
+}
+
type Service struct {
cfg *Config
@@ -26,6 +33,12 @@ type Service struct {
func NewService(cfg *Config) (*Service, error) {
cfg.Apply(DefaultConfig)
+ for _, cmd := range requiredCommands {
+ if err := internal.RequireCommand(cmd); err != nil {
+ return nil, err
+ }
+ }
+
srv := &Service{
cfg: cfg,
mirrors: nil,