github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/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 commands = []string{
    16  	"/bbin/date",
    17  	"/bbin/dhclient -ipv6=false",
    18  	"/bbin/ip a",
    19  	"/bbin/elvish",
    20  	"/bbin/shutdown halt",
    21  }
    22  
    23  func main() {
    24  	for _, line := range commands {
    25  		log.Printf("Executing Command: %v", line)
    26  		cmdSplit := strings.Split(line, " ")
    27  		if len(cmdSplit) == 0 {
    28  			continue
    29  		}
    30  
    31  		cmd := exec.Command(cmdSplit[0], cmdSplit[1:]...)
    32  		cmd.Stdin = os.Stdin
    33  		cmd.Stderr = os.Stderr
    34  		cmd.Stdout = os.Stdout
    35  		if err := cmd.Run(); err != nil {
    36  			log.Print(err)
    37  		}
    38  
    39  	}
    40  	log.Print("Uinit Done!")
    41  }