diff options
-rw-r--r-- | git_hooks_deploy.go | 50 | ||||
-rw-r--r-- | main.go | 5 |
2 files changed, 55 insertions, 0 deletions
diff --git a/git_hooks_deploy.go b/git_hooks_deploy.go new file mode 100644 index 0000000..01be550 --- /dev/null +++ b/git_hooks_deploy.go @@ -0,0 +1,50 @@ +package main + +import ( + "errors" + "io" + "os" + "path/filepath" +) + +func deploy_hooks_to_filesystem() (err error) { + err = func() error { + src_fd, err := resources_fs.Open("git_hooks_client/git_hooks_client") + if err != nil { + return err + } + defer src_fd.Close() + + dst_fd, err := os.OpenFile(filepath.Join(config.Hooks.Execs, "git_hooks_client"), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o755) + if err != nil { + return err + } + defer dst_fd.Close() + + _, err = io.Copy(dst_fd, src_fd) + if err != nil { + return err + } + + return nil + }() + if err != nil { + return err + } + + err = os.Chmod(filepath.Join(config.Hooks.Execs, "git_hooks_client"), 0755) + if err != nil { + return err + } + + for _, hook_name := range []string{ + "pre-receive", + } { + err = os.Symlink(filepath.Join(config.Hooks.Execs, "git_hooks_client"), filepath.Join(config.Hooks.Execs, hook_name)) + if err != nil && !errors.Is(err, os.ErrExist) { + return err + } + } + + return nil +} @@ -21,6 +21,11 @@ func main() { clog.Fatal(1, "Loading configuration: "+err.Error()) } + err = deploy_hooks_to_filesystem() + if err != nil { + clog.Fatal(1, "Deploying hooks to filesystem: "+err.Error()) + } + err = load_templates() if err != nil { clog.Fatal(1, "Loading templates: "+err.Error()) |