mirror of
https://github.com/rancher/os.git
synced 2025-09-01 14:48:55 +00:00
Rewrite a few scripts in Go and remove unneeded services
This commit is contained in:
27
util/util.go
27
util/util.go
@@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
@@ -241,3 +242,29 @@ func ExistsAndExecutable(path string) bool {
|
||||
mode := info.Mode().Perm()
|
||||
return mode&os.ModePerm != 0
|
||||
}
|
||||
|
||||
func RunScript(path string) error {
|
||||
if !ExistsAndExecutable(path) {
|
||||
return nil
|
||||
}
|
||||
|
||||
script, err := os.Open(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
magic := make([]byte, 2)
|
||||
if _, err = script.Read(magic); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cmd := exec.Command("/bin/sh", path)
|
||||
if string(magic) == "#!" {
|
||||
cmd = exec.Command(path)
|
||||
}
|
||||
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
return cmd.Run()
|
||||
}
|
||||
|
Reference in New Issue
Block a user