<commit_before># MESSAGING primitives
LOGFILE=".nodeready.log"

say() { echo "# [nodeready] $*" | tee -a $LOGFILE; }
yay() { say "$*"; }
hmm() { say "$*"; }
die() { say "$*"; diagnostics >>$LOGFILE; say "diagnostic information in .nodeready.log"; exit -1; }

diagdo () {
	echo '$' $*
	$* 2>&1
	echo "= $?"
}

diagnostics () {
	echo "########## BEGIN DIAGNOSTICS ################"
	diagdo "date"
	diagdo "uname -a"
	diagdo "which curl wget lynx"
	diagdo "which brew apt-get yum"
	diagdo "which node"
	diagdo "which gcc"
	echo "$ echo \$BASH_VERSION"
	echo $BASH_VERSION
	echo "########## BEGIN env ########################"
	env
	echo "########## BEGIN ~/nvm ######################"
	ls -al $HOME/.nvm
	echo "########## BEGIN nvm.sh #####################"
	cat $HOME/.nvm/nvm.sh
	echo "########## END DIAGNOSTICS ##################"
}

echo
echo
diagnostics >>$LOGFILE
say "strap yourself in, this could get bumpy..."
say "hint: if you want more detail, tail -f .nodeready.log"

# BOOTSTRAPINATOR
has() { which $1 >/dev/null 2>&1; }
use() { has $1 || return; export $2="$3" && yay "using '$1' $4"; }
use_curl() { use $1 CURL "$*" "to download files"; }
use_inst() { use $1 INST "$*" "to install new packages"; }
inst() {
	say "installing $*"
	$INST $* >>$LOGFILE 2>&1
}

# Let's see what we have...
use_inst apt-get -y install || \
use_inst brew install || \
use_inst yum -y install || \
hmm "no package manager found, attempting to continue without one"

if has gcc; then
	say "using 'gcc' to compile"
else
	hmm "we need gcc in order to proceed"
	test `uname` = "Darwin" && die "install XCode first: http://developer.apple.com/technologies/xcode.html"
	hmm "attempting to install gcc with $INST"
	inst gcc || die "failed to install gcc :-("
	yay "successfully installed gcc"
fi

# Well, we need a way to download files for sure
if has curl; then
	use_curl curl -s -C - -o
elif has wget; then
	use_curl wget -q -c -O
else<commit_msg>Try to install build tools, if missing.<commit_after># MESSAGING primitives
LOGFILE=".nodeready.log"

say() { echo "# [nodeready] $*" | tee -a $LOGFILE; }
yay() { say "$*"; }
hmm() { say "$*"; }
die() { say "$*"; diagnostics >>$LOGFILE; say "diagnostic information in .nodeready.log"; exit -1; }

diagdo () {
	echo '$' $*
	$* 2>&1
	echo "= $?"
}

run () {
	echo '$' $* >> $LOGFILE
	$* >> $LOGFILE 2>&1
}

diagnostics () {
	echo "########## BEGIN DIAGNOSTICS ################"
	diagdo "date"
	diagdo "uname -a"
	diagdo "which curl wget lynx"
	diagdo "which brew apt-get yum"
	diagdo "which node"
	diagdo "which gcc"
	echo "$ echo \$BASH_VERSION"
	echo $BASH_VERSION
	echo "########## BEGIN env ########################"
	env
	echo "########## BEGIN ~/nvm ######################"
	ls -al $HOME/.nvm
	echo "########## BEGIN nvm.sh #####################"
	cat $HOME/.nvm/nvm.sh
	echo "########## END DIAGNOSTICS ##################"
}

echo
echo
diagnostics >>$LOGFILE
say "strap yourself in, this could get bumpy..."
say "hint: if you want more detail, tail -f .nodeready.log"

# BOOTSTRAPINATOR
has() { which $1 >/dev/null 2>&1; }
use() { has $1 || return; export $2="$3" && yay "using '$1' $4"; }
use_curl() { use $1 CURL "$*" "to download files"; }

install_buildtools() {
	test `uname` = "Darwin" && die "install XCode first: http://developer.apple.com/technologies/xcode.html"
	if has apt-get; then
		say "We have to install build tools to compile node, which requires sudo:"
		run sudo apt-get -y install build-essential libssl-dev || die "could not install build tools"
	elif has yum; then
		say "We have to install build tools to compile node, which requires sudo:"
		run "(sudo yum groupinstall 'Development Tools' && sudo yum -y install openssl-devel)" || die "could not install build tools"
	else
		hmm "Couldn't find apt-get or yum to install build tools."
		hmm "You'll need g++, make, libssl-dev or their equivalents for your plaftform before we can continue"
		die "cannot continue without build tools"
	fi
}

if has gcc make; then
	say "using 'gcc' to compile"
else
	install_buildtools
fi

# Well, we need a way to download files for sure
if has curl; then
	use_curl curl -s -C - -o
elif has wget; then
	use_curl wget -q -c -O
else
{'fraction_non_alphanumeric': 0.2110179640718563, 'fraction_numerical': 0.006946107784431138, 'mean_word_length': 3.989247311827957, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '170061', 'n_tokens_mistral': 1555, 'n_tokens_neox': 1478, 'n_words': 518}