github.com/oweisse/u-root@v0.0.0-20181109060735-d005ad25fef1/examples/uinit/uinit.go (about)

     1  // Copyright 2012-2017 the u-root Authors. All rights reserved
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // This is a basic init script.
     6  package main
     7  
     8  import (
     9  	"log"
    10  	"os"
    11  	"os/exec"
    12  	"strings"
    13  )
    14  
    15  var (
    16  	commands = []string{
    17  		"/bbin/date",
    18  		"/bbin/dhclient -ipv6=false",
    19  		"/bbin/ip a",
    20  		"/bbin/elvish",
    21  		"/bbin/shutdown halt",
    22  	}
    23  )
    24  
    25  func main() {
    26  	for _, line := range commands {
    27  		log.Printf("Executing Command: %v", line)
    28  		cmdSplit := strings.Split(line, " ")
    29  		if len(cmdSplit) == 0 {
    30  			continue
    31  		}
    32  
    33  		cmd := exec.Command(cmdSplit[0], cmdSplit[1:]...)
    34  		cmd.Stdin = os.Stdin
    35  		cmd.Stderr = os.Stderr
    36  		cmd.Stdout = os.Stdout
    37  		if err := cmd.Run(); err != nil {
    38  			log.Print(err)
    39  		}
    40  
    41  	}
    42  	log.Print("Uinit Done!")
    43  }