first attempt to install protoc on linux
This commit is contained in:
parent
815d061d5d
commit
06564368bc
Notes:
Jeff Carr
2025-02-14 19:22:22 -06:00
// `autogen:go.mod` module go.wit.com/lib/fhelp go 1.22 toolchain go1.23.6 require ( github.com/google/uuid v1.6.0 go.wit.com/lib/gui/shell v0.22.26 go.wit.com/log v0.22.16 golang.org/x/text v0.22.0 ) require github.com/go-cmd/cmd v1.4.3 // indirect // `autogen:go.sum` github.com/go-cmd/cmd v1.4.3 h1:6y3G+3UqPerXvPcXvj+5QNPHT02BUw7p6PsqRxLNA7Y= github.com/go-cmd/cmd v1.4.3/go.mod h1:u3hxg/ry+D5kwh8WvUkHLAMe2zQCaXd00t35WfQaOFk= github.com/go-test/deep v1.1.0 h1:WOcxcdHcvdgThNXjw0t76K42FXTU7HpNQWHpA2HHNlg= github.com/go-test/deep v1.1.0/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= go.wit.com/lib/gui/shell v0.22.26 h1:F+7aadEujsTgyBEs5ptKGL6N72reDkGd/7b0Ju4HeTU= go.wit.com/lib/gui/shell v0.22.26/go.mod h1:Km5o+DLU5up5jvTEum9wiTdsZZG/EUNERVzn2wJ6DBE= go.wit.com/log v0.22.16 h1:E0Vd0Z2ILtfjhs7J/CQ4g13DK1jtQiYl6l5KOBGsZoA= go.wit.com/log v0.22.16/go.mod h1:/c5Uj30sWRQ4B5ei2ElB6Q8Si/cK6v+KbxnH208KD84= golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= // `autogen:`
36
human.go
36
human.go
|
@ -4,19 +4,44 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CheckProtoc() bool {
|
func CheckProtoc() bool {
|
||||||
if checkCmdSimple("protoc") {
|
if !checkCmdSimple("protoc") {
|
||||||
userInstructions()
|
userInstructions()
|
||||||
log.Sleep(2)
|
switch runtime.GOOS {
|
||||||
|
case "linux":
|
||||||
|
linuxInstall("protoc")
|
||||||
|
case "macos":
|
||||||
|
log.Info("todo: print instructions here for installing protoc on macos. brew install?")
|
||||||
|
case "windows":
|
||||||
|
log.Info("todo: print instructions here for installing protoc on windows")
|
||||||
|
default:
|
||||||
|
log.Info("todo: print instructions here for installing protoc on", runtime.GOOS)
|
||||||
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if checkCmdSimple("protoc-gen-go") {
|
if !checkCmdSimple("protoc") {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if !checkCmdSimple("protoc-gen-go") {
|
||||||
userInstructions()
|
userInstructions()
|
||||||
log.Sleep(2)
|
switch runtime.GOOS {
|
||||||
|
case "linux":
|
||||||
|
linuxInstall("protoc-gen-go")
|
||||||
|
case "macos":
|
||||||
|
log.Info("todo: print instructions here for installing protoc on macos. brew install?")
|
||||||
|
case "windows":
|
||||||
|
log.Info("todo: print instructions here for installing protoc on windows")
|
||||||
|
default:
|
||||||
|
log.Info("todo: print instructions here for installing protoc on", runtime.GOOS)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !checkCmdSimple("protoc-gen-go") {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@ -43,6 +68,8 @@ func checkCmd(cmd string) (string, error) {
|
||||||
return path, err
|
return path, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
func oldcheckCmd(cmd string) {
|
func oldcheckCmd(cmd string) {
|
||||||
// path, err := exec.LookPath(cmd)
|
// path, err := exec.LookPath(cmd)
|
||||||
_, err := exec.LookPath(cmd)
|
_, err := exec.LookPath(cmd)
|
||||||
|
@ -54,6 +81,7 @@ func oldcheckCmd(cmd string) {
|
||||||
// fmt.Printf("%s is available at %s\n", cmd, path)
|
// fmt.Printf("%s is available at %s\n", cmd, path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// todo: figure out how to determine, in a package, what the program name is
|
// todo: figure out how to determine, in a package, what the program name is
|
||||||
func okExit(s string) {
|
func okExit(s string) {
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
package fhelp
|
||||||
|
|
||||||
|
// auto run protoc with the correct args
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"go.wit.com/lib/gui/shell"
|
||||||
|
"go.wit.com/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func linuxInstall(pkg string) {
|
||||||
|
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":
|
||||||
|
shell.Sudo(cmd)
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue