<commit_before>#!/bin/sh

# Tell zsh we expect to be treated like an sh script
# zsh really should take the hint from the shebang line
if which emulate 1>&2; then
	emulate sh
fi

# Make sure HOME is set up
if [ -z "$HOME" ]; then
	HOME="`ls -d ~`"
fi

INTERACTIVE=0
while [ $# -gt 1 ]; do
	case "$1" in
		-i)
			INTERACTIVE=1
			shift
		;;
		-d*)
			TVEDB="`echo "$1" | cut -c3-`"
			if [ -z "$TVEDB" ]; then
				TVEDB=">>"
			fi
			shift
		;;
		-*)
			echo "Unsupported switch $1" 1>&2
			exit 1
		;;
		*)
			if [ "$TVEDB" = ">>" ]; then
				TVEDB="$1"
				shift
			fi
		;;
	esac
done

# Check that a package was specified to install
if [ -z "$1" ]; then
	echo "No package was specified." 1>&2
	exit 1
fi

# Find the network utility
if which wget 1>&2; then
	GET="wget -q -O -"
elif which curl 1>&2; then
	GET="curl -sfL"
else
	echo "You must have wget or curl installed." 1>&2
	exit 1
fi

# Verify the presence of oauthsign
if ! which oauthsign 1>&2; then
	echo "You need the oauthsign utility from oauth-utils installed to use this script." 1>&2
	exit 1
fi

# do_install KIND PACKAGE
do_install () {
	# If interactive, ask for confirmation
	if [ $INTERACTIVE != 0 ]; then
		read -p "Install $1 ${2}? [Yn] " YN
		if [ "$YN" = "N" -o "$YN" = "n" -o "$YN" = "No" -o "$YN" = "no" ]; then
			echo "You opted not to install $1 ${2}. Aborting install..."
			exit 2
		fi
	fi
	# Extract the download URL from the database
	URL="`TVEDB="$TVEDB" search/search -v "$2" | grep Download | cut -d' ' -f2`"
	# Sign the URL with oauth utils (oauthsign)
	URL="`oauthsign -c $CONSUMER_TOKEN -C $CONSUMER_SECRET -t $TOKEN -T $SECRET "$URL"`"
	# Get remote URL and download deb file with GET
	if ! $GET "$URL" > "$temp/$2.deb"; then
		echo "Error downloading ${2}... Aborting..."
		exit 1
	fi
	# TODO: Verify size and MD5 from database (needs modification to search)
	# Install deb file with $INTERNAL
	LOG="$LOGDIR/$2" PREFIX="$TVEROOT/" $INTERNAL "$temp/$2.deb"
	if [ $? != 0 ]; then
		echo "Error unpacking ${2}."
		exit 1
	fi
	# TODO: UPDATE status in DB for this 2 (write set-status C utility)
}

# Get dependencies
DEP="`TVEDB="$TVEDB" depends/depends "$1"`"
if [ $? != 0 ]; then<commit_msg>Do integrity check.<commit_after>#!/bin/sh

# Tell zsh we expect to be treated like an sh script
# zsh really should take the hint from the shebang line
if which emulate 1>&2; then
	emulate sh
fi

# Make sure HOME is set up
if [ -z "$HOME" ]; then
	HOME="`ls -d ~`"
fi

INTERACTIVE=0
while [ $# -gt 1 ]; do
	case "$1" in
		-i)
			INTERACTIVE=1
			shift
		;;
		-d*)
			TVEDB="`echo "$1" | cut -c3-`"
			if [ -z "$TVEDB" ]; then
				TVEDB=">>"
			fi
			shift
		;;
		-*)
			echo "Unsupported switch $1" 1>&2
			exit 1
		;;
		*)
			if [ "$TVEDB" = ">>" ]; then
				TVEDB="$1"
				shift
			fi
		;;
	esac
done

# Check that a package was specified to install
if [ -z "$1" ]; then
	echo "No package was specified." 1>&2
	exit 1
fi

# Find the network utility
if which wget 1>&2; then
	GET="wget -q -O -"
elif which curl 1>&2; then
	GET="curl -sfL"
else
	echo "You must have wget or curl installed." 1>&2
	exit 1
fi

# Verify the presence of oauthsign
if ! which oauthsign 1>&2; then
	echo "You need the oauthsign utility from oauth-utils installed to use this script." 1>&2
	exit 1
fi

# do_install KIND PACKAGE
do_install () {
	# If interactive, ask for confirmation
	if [ $INTERACTIVE != 0 ]; then
		read -p "Install $1 ${2}? [Yn] " YN
		if [ "$YN" = "N" -o "$YN" = "n" -o "$YN" = "No" -o "$YN" = "no" ]; then
			echo "You opted not to install $1 ${2}. Aborting install..."
			exit 2
		fi
	fi
	# Extract the download URL from the database
	DATA="`TVEDB="$TVEDB" search/search -v "$2"`"
	URL="`echo "$DATA" | grep Download | cut -d' ' -f2`"
	# Sign the URL with oauth utils (oauthsign)
	URL="`oauthsign -c $CONSUMER_TOKEN -C $CONSUMER_SECRET -t $TOKEN -T $SECRET "$URL"`"
	# Get remote URL and download deb file with GET
	if ! $GET "$URL" > "$temp/$2.deb"; then
		echo "Error downloading ${2}... Aborting..."
		exit 1
	fi
	# Verify size and MD5 from database
	SIZE="`echo "$DATA" | grep Size | cut -d' ' -f2`"
	REALSIZE="`wc -c "$temp/$2.deb" | awk '{ print $1 }'`"
	if [ "$SIZE" != "$REALSIZE" ]; then
		echo "Integrity check for $1 failed. Size does not match." 1>&2
		exit 1
	fi
	MD5="`echo "$DATA" | grep MD5sum | cut -d' ' -f2`"
	REALMD5="`md5/md5 -q "$temp/$2.deb"`"
	if [ "$MD5" != "$REALMD5" ]; then
		echo "Integrity check for $1 failed. MD5 sum does not match." 1>&2
		exit 1
	fi
	# Install deb file with $INTERNAL
	LOG="$LOGDIR/$2" PREFIX="$TVEROOT/" $INTERNAL "$temp/$2.deb"
	if [ $? != 0 ]; then
		echo "Error unpacking ${2}."
		exit 1
	fi
	# TODO: UPDATE status in DB for this 2 (write set-status C utility)
}

# Get dependencies
DEP="`TVEDB="$TVEDB" depends/depends "$1"`"
if [ $? != 0 ]; then
{'fraction_non_alphanumeric': 0.1616816565572056, 'fraction_numerical': 0.024890190336749635, 'mean_word_length': 3.018487394957983, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3649242', 'n_tokens_mistral': 2041, 'n_tokens_neox': 1859, 'n_words': 684}