differentiate between OSes

This commit is contained in:
AJ ONeal 2019-06-24 21:34:18 -06:00
parent 7077731356
commit 1e9f95295d
6 changed files with 92 additions and 56 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
installer
watchdog.service
/cmd/install/static
/watchdog

View File

@ -3,6 +3,11 @@
# sudo mkdir -p /opt/{{ .Exec }}/ /var/log/{{ .Exec }}
# sudo chown -R {{ .Exec }}:{{ .Exec }} /opt/{{ .Exec }}/ /var/log/{{ .Exec }}
# Post-install
# sudo systemctl daemon-reload
# sudo systemctl restart {{ .Exec }}.service
# sudo journalctl -xefu {{ .Exec }}
[Unit]
Description={{ .Name }} - {{ .Desc }}
Documentation={{ .URL }}
@ -24,7 +29,7 @@ Group={{ .Group }}
{{ end -}}
WorkingDirectory=/opt/{{ .Exec }}
ExecStart=/opt/{{ .Exec }} {{ .Args }}
ExecStart=/opt/{{ .Exec }}/{{ .Exec }} {{ .Args }}
ExecReload=/bin/kill -USR1 $MAINPID
{{if .Production -}}

View File

@ -4,17 +4,6 @@
// hence there are a few unnecessary things for the sake of the trying it out
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"text/template"
"git.rootprojects.org/root/watchdog.go/cmd/install/static"
)
type Config struct {
Name string `json:"name"`
Desc string `json:"desc"`
@ -30,48 +19,5 @@ type Config struct {
func main() {
b, err := static.ReadFile("dist/etc/systemd/system/watchdog.service.tmpl")
if err != nil {
log.Fatal(err)
return
}
s := string(b)
j, err := static.ReadFile("dist/etc/systemd/system/watchdog.service.json")
if err != nil {
log.Fatal(err)
return
}
//conf := map[string]string{}
conf := &Config{}
err = json.Unmarshal(j, &conf)
if nil != err {
log.Fatal(err)
return
}
if "" == conf.Group {
conf.Group = conf.User
}
serviceFile := conf.Exec + ".service"
rw := &bytes.Buffer{}
// not sure what the template name does, but whatever
tmpl, err := template.New("service").Parse(s)
if err != nil {
log.Fatal(err)
return
}
err = tmpl.Execute(rw, conf)
if nil != err {
log.Fatal(err)
return
}
if err := ioutil.WriteFile(serviceFile, rw.Bytes(), 0644); err != nil {
log.Fatalf("ioutil.WriteFile error: %v", err)
}
fmt.Printf("Wrote %q\n", serviceFile)
install()
}

View File

@ -0,0 +1,7 @@
package main
import "log"
func install() {
log.Fatal("not yet implemented")
}

View File

@ -0,0 +1,60 @@
// +build !windows !darwin
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"text/template"
"git.rootprojects.org/root/watchdog.go/cmd/install/static"
)
func install() {
b, err := static.ReadFile("dist/etc/systemd/system/watchdog.service.tmpl")
if err != nil {
log.Fatal(err)
return
}
s := string(b)
j, err := static.ReadFile("dist/etc/systemd/system/watchdog.service.json")
if err != nil {
log.Fatal(err)
return
}
//conf := map[string]string{}
conf := &Config{}
err = json.Unmarshal(j, &conf)
if nil != err {
log.Fatal(err)
return
}
if "" == conf.Group {
conf.Group = conf.User
}
serviceFile := conf.Exec + ".service"
rw := &bytes.Buffer{}
// not sure what the template name does, but whatever
tmpl, err := template.New("service").Parse(s)
if err != nil {
log.Fatal(err)
return
}
err = tmpl.Execute(rw, conf)
if nil != err {
log.Fatal(err)
return
}
if err := ioutil.WriteFile(serviceFile, rw.Bytes(), 0644); err != nil {
log.Fatalf("ioutil.WriteFile error: %v", err)
}
fmt.Printf("Wrote %q\n", serviceFile)
}

View File

@ -0,0 +1,17 @@
package main
import (
"log"
//"golang.org/x/sys/windows"
)
// See
// https://github.com/golang/go/issues/28804
// https://stackoverflow.com/questions/31558066/how-to-ask-for-administer-privileges-on-windows-with-go/31561120
// https://stackoverflow.com/questions/27366298/check-if-application-is-running-as-administrator-in-golang
// https://www.reddit.com/r/golang/comments/53dthc/way_to_detect_if_the_programs_running_with/
// https://play.golang.org/p/bBtRZrk4_p
func install() {
//token := windows.Token(0)
log.Fatal("not yet implemented")
}