Skip to content

Commit

Permalink
Add RunInstallScripts
Browse files Browse the repository at this point in the history
  • Loading branch information
evanpurkhiser committed Jul 15, 2019
1 parent cff3a43 commit 5c6952b
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions installer/scripts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package installer

import (
"fmt"
"os"
"os/exec"
)

// RunInstallScripts executes the installation scripts of a PreparedInstall for
// files that have changed (unless ForceReinstall is enabled, in which case
// *all* scripts will be run).
func RunInstallScripts(install PreparedInstall, config InstallConfig) {
for _, script := range install.InstallScripts {
if !script.ShouldInstall() && !config.ForceReinstall {
continue
}

if !script.Executable {
continue
}

command := exec.Command(script.Path)

// Execute the script in the installed path cotnext
if config.OverrideInstallPath != "" {
command.Dir = config.OverrideInstallPath
} else {
command.Dir = config.SourceConfig.InstallPath
}

// Setup the environment
command.Env = append(
os.Environ(),
fmt.Sprintf("DOTS_SOURCE=%s", config.SourceConfig.SourcePath),
fmt.Sprintf("DOTS_FORCE_REINSTALL=%t", config.ForceReinstall),
)

command.Stdout = os.Stdout
command.Stderr = os.Stderr

command.Run()
}

}

0 comments on commit 5c6952b

Please sign in to comment.