Skip to content

Commit c18b0da

Browse files
authored
Merge pull request #46 from google/docker
Check if hashr is running in a Docker container
2 parents d86b053 + e63fed4 commit c18b0da

1 file changed

Lines changed: 16 additions & 15 deletions

File tree

processors/local/local.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"fmt"
2121
"os/exec"
2222
"path/filepath"
23-
"regexp"
2423

2524
"github.com/golang/glog"
2625
)
@@ -30,21 +29,10 @@ var execute = func(name string, args ...string) *exec.Cmd {
3029
return exec.Command(name, args...)
3130
}
3231

33-
type volume struct {
34-
id int
35-
start int
36-
length int
37-
}
38-
3932
// Processor is an instance of local processor.
4033
type Processor struct {
4134
}
4235

43-
var (
44-
reRow = regexp.MustCompile(`(?m)^\d{3}:.*`)
45-
reSpace = regexp.MustCompile(`\s+`)
46-
)
47-
4836
// New returns new local processor instance.
4937
func New() *Processor {
5038
return &Processor{}
@@ -71,11 +59,24 @@ func (p *Processor) ImageExport(sourcePath string) (string, error) {
7159
exportDir := filepath.Join(baseDir, "export")
7260
logFile := filepath.Join(baseDir, "image_export.log")
7361

74-
args := []string{"run", "--rm", "-v", "/tmp/:/tmp", "log2timeline/plaso", "image_export", "--logfile", logFile, "--partitions", "all", "--volumes", "all", "-w", exportDir, sourcePath}
75-
_, err := shellCommand("docker", args...)
62+
dockerArgs := []string{"run", "--rm", "-v", "/tmp/:/tmp", "log2timeline/plaso", "image_export", "--logfile", logFile, "--partitions", "all", "--volumes", "all", "-w", exportDir, sourcePath}
63+
localArgs := []string{"--logfile", logFile, "--partitions", "all", "--volumes", "all", "-w", exportDir, sourcePath}
64+
var err error
65+
66+
if inDockerContainer() {
67+
_, err = shellCommand("image_export.py", localArgs...)
68+
} else {
69+
_, err = shellCommand("docker", dockerArgs...)
70+
}
71+
7672
if err != nil {
77-
return "", fmt.Errorf("error while running Plaso: %v", err)
73+
return "", fmt.Errorf("error while running image_export: %v", err)
7874
}
7975

8076
return exportDir, nil
8177
}
78+
79+
func inDockerContainer() bool {
80+
_, err := shellCommand("ls", "/.dockerenv")
81+
return err == nil
82+
}

0 commit comments

Comments
 (0)