summaryrefslogtreecommitdiff
path: root/install_linux.go
blob: f86946afde9cf6dfaf69fdeb33042cdee8ecb7b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package fhelp

// auto run protoc with the correct args

import (
	"bufio"
	"fmt"
	"os"
	"strings"

	"go.wit.com/log"
)

func osInstall(pkg string) error {
	cmd := []string{"apt", "install", "-y", pkg}
	if pkg == "protoc" {
		cmd = []string{"apt", "install", "-y", "protobuf-compiler"}
	}
	log.Info("Would you like to run", "sudo", cmd, "now?")
	fmt.Fprintf(os.Stdout, "(y)es or (n)o ? ")

	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		line := scanner.Text()
		line = strings.TrimSpace(line)
		line = strings.ToLower(line)
		switch line {
		case "y":
			log.Info("todo: fix this")
			Sudo(cmd)
			return log.Errorf("user didn't install package %s", pkg)
		default:
		}
	}
	return log.Errorf("user didn't install package %s", pkg)
}