1
0
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:
Josh Curl
2016-10-17 14:47:44 -07:00
parent 9755a37fe6
commit a7d405991c
22 changed files with 321 additions and 226 deletions

View File

@@ -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()
}