Skip to content

Instantly share code, notes, and snippets.

@groob
Last active May 1, 2017 22:23
Show Gist options
  • Save groob/a0d7cd64d3163cf5d991566dde6f600f to your computer and use it in GitHub Desktop.
Save groob/a0d7cd64d3163cf5d991566dde6f600f to your computer and use it in GitHub Desktop.
run munki in a loop until removed.
// runs `managedsoftwareupdate --id=dep_bootstrap` in a loop.
// This utility is installed along with munkitools via InstallApplication during DEP enrollment.
// The utility is stopped/removed by a package called dep_complete which is the last item to run in the
// `dep_bootstrap` munki manifest.
package main
import (
"fmt"
"log"
"os"
"os/exec"
"time"
)
func main() {
ticker := time.NewTicker(2 * time.Second).C
done := make(chan bool)
for {
if err := runMunkiID("dep_bootstrap", done); err != nil {
log.Println(err)
os.Exit(1)
}
<-done
<-ticker
}
}
func runMunkiID(id string, done chan<- bool) error {
idArg := fmt.Sprintf("--id=%s", id)
checkArgs := []string{"--munkipkgsonly", "--checkonly", idArg}
installArgs := []string{"--munkipkgsonly", "--installonly", idArg}
cmdName := "/usr/local/munki/managedsoftwareupdate"
runWithArgs := func(args ...string) error {
cmd := exec.Command(cmdName, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}
if err := runWithArgs(checkArgs...); err != nil {
return err
}
if err := runWithArgs(installArgs...); err != nil {
return err
}
go func() { done <- true }()
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment