<commit_before>package hook

import (
	"errors"
	"os/exec"
	"strings"

	"github.com/ChrisMcKenzie/dropship/service"
)

type ScriptHook struct{}

func (h ScriptHook) Execute(config map[string]interface{}, service service.Config) error {
	if c, ok := config["command"].(string); ok {
		_, err := executeCommand(c)
		return err
	}
	return errors.New("Script: exiting no command was given")
}

func executeCommand(c string) (string, error) {
	cmd := strings.Fields(c)
	out, err := exec.Command(cmd[0], cmd[1:]...).Output()
	return string(out), err
}<commit_msg>fixed issue where script was running from dropship bin path not service install path.<commit_after>package hook

import (
	"errors"
	"os"
	"os/exec"
	"strings"

	"github.com/ChrisMcKenzie/dropship/service"
)

type ScriptHook struct{}

func (h ScriptHook) Execute(config map[string]interface{}, service service.Config) error {
	if c, ok := config["command"].(string); ok {

		// TODO(ChrisMcKenzie): Make this more secure by jailing it.
		var cwd string
		if len(service.Artifact) >= 1 {
			cwd = service.Artifact[0].Destination
		}

		_, err := executeCommand(c, cwd)
		return err
	}
	return errors.New("Script: exiting no command was given")
}

func executeCommand(c, cwd string) (string, error) {
	sCmd := strings.Fields(c)
	cmd := exec.Command(sCmd[0], sCmd[1:]...)
	if _, err := os.Stat(cwd); !os.IsNotExist(err) {
		cmd.Dir = cwd
	}
	out, err := cmd.Output()
	return string(out), err
}
{'fraction_non_alphanumeric': 0.15065653075328264, 'fraction_numerical': 0.00414651002073255, 'mean_word_length': 4.4232209737827715, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7079349', 'n_tokens_mistral': 529, 'n_tokens_neox': 502, 'n_words': 136}