-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice.go
40 lines (33 loc) · 822 Bytes
/
service.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
package main
import (
_ "embed"
"github.com/cross-cpm/go-shutil"
"os"
"os/exec"
"path/filepath"
)
//go:embed init-file
var INIT_FILE string
func InstallService() {
targetPath := "/usr/local/bin/rc2http"
initPath := "/etc/init.d/rc2http"
err := os.MkdirAll(filepath.Dir(targetPath), 0755)
FatalError(err)
executable, err := os.Executable()
FatalError(err)
exePath, err := filepath.Abs(executable)
FatalError(err)
if exePath != targetPath {
_, err := shutil.CopyFile(exePath, targetPath, &shutil.CopyOptions{})
FatalError(err)
err = os.Chmod(targetPath, 0755)
FatalError(err)
}
err = os.WriteFile(initPath, []byte(INIT_FILE), 0644)
FatalError(err)
err = os.Chmod(initPath, 0755)
FatalError(err)
cmd := exec.Command("update-rc.d", "rc2http", "defaults")
err = cmd.Run()
FatalError(err)
}