<commit_before>#!/bin/bash

CHROME=$(which google-chrome)

fail() {
    echo $1 >&2
    exit $2 
}

KEY_OPT=""
rm -rf src.crx || fail "failed to remove existing .crx" $?

KEY_FILE="${PWD}/src.pem"

if [ -f "${KEY_FILE}" ] ; then
    echo "using existing key ${KEY_FILE}"
    KEY_OPT="--pack-extension-key=${KEY_FILE}"
fi

$CHROME --pack-extension=${PWD}/src "${KEY_OPT}" || fail "failed to pack" $?

ls src.*

OUTFILE="${PWD}/src.crx"
EXT_ID=$(python crxmetadata.py --extension-id "$OUTFILE")
STATUS=$?
if [ $STATUS -ne 0 ]; then
  fail "crx metadata parse failure" $?
fi
echo "extension id: $EXT_ID"
<commit_msg>include version in output file<commit_after>#!/bin/bash

CHROME=$(which google-chrome)
if [ -z "$CHROME" ] ; then
  echo "make.sh: google-chrome is not installed" >&2
  exit 1
fi

fail() {
    echo $1 >&2
    exit $2 
}

INPUT="src"
OUTPUT="chrome-cookie-implant"

KEY_OPT=""
rm -rf "./${INPUT}.crx" || fail "failed to remove existing .crx" $?

KEY_FILE="${PWD}/${INPUT}.pem"

if [ -f "${KEY_FILE}" ] ; then
    KEY_OPT="--pack-extension-key=${KEY_FILE}"
else
    echo "make.sh: no existing key; expected at ${KEY_FILE}" >&2
fi

$CHROME --pack-extension=${PWD}/${INPUT} "${KEY_OPT}" 2>/dev/null || fail "failed to pack" $?

TEMPFILE="${PWD}/${INPUT}.crx"

OUTNAME="${OUTPUT}"
VERSION=$(python -c 'import sys, json; print json.load(sys.stdin)["version"]' < "${INPUT}/manifest.json")
if [ -n "$VERSION" ] ; then
  OUTNAME="${OUTNAME}-${VERSION}"
fi
OUTNAME="${OUTNAME}.crx"
mv "$TEMPFILE" "$OUTNAME"
EXT_ID=$(python crxmetadata.py --extension-id "$OUTNAME")
STATUS=$?
if [ $STATUS -ne 0 ]; then
  fail "crx metadata parse failure" $?
fi
echo "${OUTNAME}: $EXT_ID"

{'fraction_non_alphanumeric': 0.21014925373134327, 'fraction_numerical': 0.007164179104477612, 'mean_word_length': 4.172839506172839, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 8, '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': '3148319', 'n_tokens_mistral': 645, 'n_tokens_neox': 637, 'n_words': 164}