<commit_before>package urknall

import (
	"bytes"
	"fmt"
	"strings"
)

type Runner struct {
	User      string
	DryRun    bool
	Env       []string
	Commander Commander
}

func (runner *Runner) Hostname() string {
	if s, ok := runner.Commander.(fmt.Stringer); ok {
		return s.String()
	}
	return "MISSING"
}

func (runner *Runner) IsSudoRequired() bool {
	return runner.User != "root"
}

func prepareHost(runner *Runner) error {
	if runner.User == "" {
		return fmt.Errorf("User not set")
	}
	cmd, e := runner.Commander.Command(fmt.Sprintf(`grep "^%s:" /etc/group | grep %s`, ukGROUP, runner.User))
	if e != nil {
		return e
	}
	if e := cmd.Run(); e != nil {
		// If user is missing the group, create group (if necessary), add user and restart ssh connection.
		cmds := []string{
			fmt.Sprintf(`{ grep -e '^%[1]s:' /etc/group > /dev/null || { groupadd %[1]s; }; }`, ukGROUP),
			fmt.Sprintf(`{ [[ -d %[1]s ]] || { mkdir -p -m 2775 %[1]s && chgrp %[2]s %[1]s; }; }`, ukCACHEDIR, ukGROUP),
			fmt.Sprintf("usermod -a -G %s %s", ukGROUP, runner.User),
		}

		cmd, e = runner.Commander.Command(fmt.Sprintf(`sudo bash -c "%s"`, strings.Join(cmds, " && ")))
		if e != nil {
			return e
		}
		out := &bytes.Buffer{}
		err := &bytes.Buffer{}
		cmd.SetStderr(err)
		cmd.SetStdout(out)
		if e := cmd.Run(); e != nil {
			return fmt.Errorf("failed to initiate user %q for provisioning: %s, out=%q err=%q", runner.User, e, out.String(), err.String())
		}
	}
	return nil
}
<commit_msg>also re-prepare if /var/lib/urknall no longer exists<commit_after>package urknall

import (
	"bytes"
	"fmt"
	"strings"
)

type Runner struct {
	User      string
	DryRun    bool
	Env       []string
	Commander Commander
}

func (runner *Runner) Hostname() string {
	if s, ok := runner.Commander.(fmt.Stringer); ok {
		return s.String()
	}
	return "MISSING"
}

func (runner *Runner) IsSudoRequired() bool {
	return runner.User != "root"
}

func prepareHost(runner *Runner) error {
	if runner.User == "" {
		return fmt.Errorf("User not set")
	}
	cmd, e := runner.Commander.Command(fmt.Sprintf(`{ grep "^%s:" /etc/group | grep %s; } && [[ -d /var/lib/urknall ]]`, ukGROUP, runner.User))
	if e != nil {
		return e
	}
	if e := cmd.Run(); e != nil {
		// If user is missing the group, create group (if necessary), add user and restart ssh connection.
		cmds := []string{
			fmt.Sprintf(`{ grep -e '^%[1]s:' /etc/group > /dev/null || { groupadd %[1]s; }; }`, ukGROUP),
			fmt.Sprintf(`{ [[ -d %[1]s ]] || { mkdir -p -m 2775 %[1]s && chgrp %[2]s %[1]s; }; }`, ukCACHEDIR, ukGROUP),
			fmt.Sprintf("usermod -a -G %s %s", ukGROUP, runner.User),
		}

		cmd, e = runner.Commander.Command(fmt.Sprintf(`sudo bash -c "%s"`, strings.Join(cmds, " && ")))
		if e != nil {
			return e
		}
		out := &bytes.Buffer{}
		err := &bytes.Buffer{}
		cmd.SetStderr(err)
		cmd.SetStdout(out)
		if e := cmd.Run(); e != nil {
			return fmt.Errorf("failed to initiate user %q for provisioning: %s, out=%q err=%q", runner.User, e, out.String(), err.String())
		}
	}
	return nil
}

{'fraction_non_alphanumeric': 0.19071310116086235, 'fraction_numerical': 0.006633499170812604, 'mean_word_length': 3.3085714285714287, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5159173', 'n_tokens_mistral': 1221, 'n_tokens_neox': 1151, 'n_words': 319}