14 func TryRunAndSave(output
string, name
string, arg
[]string) error
{
15 cmd
:= exec
.Command(name
, arg
...)
17 f
, err
:= os
.Create(output
)
33 func RunAndSave(output
string, name
string, arg
...string) {
34 err
:= TryRunAndSave(output
, name
, arg
)
38 idx
:= strings
.LastIndex(name
, "/")
41 relname
= name
[idx
+1:]
43 relname
= "./" + relname
44 err
= TryRunAndSave(output
, relname
, arg
)
50 const MAXPROMPTRETRY
= 3
52 func PromptUser(prompt
string, opts
[]string) (match
string, err error
) {
53 for i
:= 1; i
< MAXPROMPTRETRY
; i
++ {
54 fmt
.Printf("%s. (%s) Default:%s\n", prompt
,
55 strings
.Join(opts
, "/"), opts
[0])
59 // Check for default entry
65 for _
, opt
:= range opts
{
72 err
= errors
.New("max retries exceeded")
73 fmt
.Fprintln(os
.Stderr
, "ERROR: max retries exceeded")
77 func MakeLogs(outDir
string) {
78 os
.MkdirAll(outDir
, 0700)
79 RunAndSave(outDir
+"/lspci.log", "lspci", "-nnvvvxxxx")
80 RunAndSave(outDir
+"/dmidecode.log", "dmidecode")
81 RunAndSave(outDir
+"/acpidump.log", "acpidump")
84 opt
, err
:= PromptUser("WARNING: The following tool MAY cause your system to hang when it attempts "+
85 "to probe for graphics registers. Having the graphics registers will help create a better port. "+
86 "Should autoport probe these registers?",
87 []string{"y", "yes", "n", "no"})
89 // Continue even if there is an error
96 RunAndSave(outDir
+"/inteltool.log", "../inteltool/inteltool", inteltoolArgs
)
97 RunAndSave(outDir
+"/ectool.log", "../ectool/ectool", "-pd")
98 RunAndSave(outDir
+"/superiotool.log", "../superiotool/superiotool", "-ade")
100 SysDir
:= "/sys/class/sound/card0/"
101 files
, _
:= ioutil
.ReadDir(SysDir
)
102 for _
, f
:= range files
{
103 if (strings
.HasPrefix(f
.Name(), "hw") || strings
.HasPrefix(f
.Name(), "hdaudio")) && f
.IsDir() {
104 in
, err
:= os
.Open(SysDir
+ f
.Name() + "/init_pin_configs")
109 out
, err
:= os
.Create(outDir
+ "/pin_" + strings
.Replace(f
.Name(), "hdaudio", "hw", -1))
118 ProcDir
:= "/proc/asound/card0/"
119 files
, _
= ioutil
.ReadDir(ProcDir
)
120 for _
, f
:= range files
{
121 if strings
.HasPrefix(f
.Name(), "codec#") && !f
.IsDir() {
122 in
, err
:= os
.Open(ProcDir
+ f
.Name())
127 out
, err
:= os
.Create(outDir
+ "/" + f
.Name())
136 for _
, fname
:= range []string{"cpuinfo", "ioports"} {
137 in
, err
:= os
.Open("/proc/" + fname
)
142 out
, err
:= os
.Create(outDir
+ "/" + fname
+ ".log")
150 out
, err
:= os
.Create(outDir
+ "/input_bustypes.log")
156 ClassInputDir
:= "/sys/class/input/"
157 files
, _
= ioutil
.ReadDir(ClassInputDir
)
158 for _
, f
:= range files
{
159 if strings
.HasPrefix(f
.Name(), "input") && !f
.Mode().IsRegular() { /* Allow both dirs and symlinks. */
160 in
, err
:= os
.Open(ClassInputDir
+ f
.Name() + "/id/bustype")