<commit_before>#!/usr/bin/env bash
# DeepDive Installer
set -euo pipefail

: ${RELEASE:=v0.8.0}    # the DeepDive release version to install
: ${PREFIX:=~/local}    # the path to install deepdive

: ${INSTALLER_BRANCH:=${BRANCH:-v0.8.x}}    # the branch from which the installer scripts should be downloaded
INSTALLER_HOME_URL=https://github.com/HazyResearch/deepdive/raw/"${INSTALLER_BRANCH}"/util/install
INSTALLER_HOME_DIR=$(dirname "$0")/install

# run the correct installer directly from GitHub if BRANCH is specified
[[ -z "${BRANCH:-}" || -n "${INSTALLER_REMOTE_EXEC:-}" ]] ||
    INSTALLER_REMOTE_EXEC=true \
    exec bash <(set -x; curl -fsSL "${INSTALLER_HOME_URL}.sh") "$@"

running_from_git=true; [[ -e "$INSTALLER_HOME_DIR"/../../.git ]] || running_from_git=false
has() { type "$@"; } &>/dev/null
error() {
    if [ -t 1 ]; then
        # on tty output, color errors in red
        echo -ne '\033[31m'
        echo "$@"
        echo -ne '\033[0m'
    else
        echo "$@"
    fi
    false
} >&2
INSTALLER_TEMP_DIR=
init_INSTALLER_TEMP_DIR() {
    # makes sure INSTALLER_TEMP_DIR points to a temporary directory
    if ! [[ -d "$INSTALLER_TEMP_DIR" ]]; then
        INSTALLER_TEMP_DIR=$(mktemp -d "${TMPDIR:-/tmp}"/deepdive-installer.XXXXXXX)
        trap "rm -rf $INSTALLER_TEMP_DIR" EXIT
    fi
}

# common installers ###########################################################
# installs DeepDive's build dependencies
install__deepdive_build_deps() {
    local deps=
    deps=(
        git
        make
        bzip2
        unzip
        jdk
    )
    error "Please make sure the following packages are available on your system: $(
        printf '\n  %s' "${deps[@]}")" ||
            [[ ! -t 1 ]] || read -p "# Continue? " || true
}
# installs DeepDive's runtime dependencies
install__deepdive_runtime_deps() {
    local deps=
    deps=(
        bash
        coreutils
        xargs
        bc
        gnuplot
        jre
        python
    )
    error "Please make sure the following packages are available on your system:$(
        printf '\n  %s' "${deps[@]}")" ||
            [[ ! -t 1 ]] || read -p "# Continue? " || true
}
# fetches DeepDive source tree
install__deepdive_git_repo() {
    $running_from_git ||
        git clone --recursive --branch "$INSTALLER_BRANCH" https://github.com/HazyResearch/deepdive.git
}
# installs DeepDive from source by going through the full build
install_deepdive_from_source() {<commit_msg>Makes install__deepdive_git_repo idempotent<commit_after>#!/usr/bin/env bash
# DeepDive Installer
set -euo pipefail

: ${RELEASE:=v0.8.0}    # the DeepDive release version to install
: ${PREFIX:=~/local}    # the path to install deepdive

: ${INSTALLER_BRANCH:=${BRANCH:-v0.8.x}}    # the branch from which the installer scripts should be downloaded
INSTALLER_HOME_URL=https://github.com/HazyResearch/deepdive/raw/"${INSTALLER_BRANCH}"/util/install
INSTALLER_HOME_DIR=$(dirname "$0")/install

# run the correct installer directly from GitHub if BRANCH is specified
[[ -z "${BRANCH:-}" || -n "${INSTALLER_REMOTE_EXEC:-}" ]] ||
    INSTALLER_REMOTE_EXEC=true \
    exec bash <(set -x; curl -fsSL "${INSTALLER_HOME_URL}.sh") "$@"

running_from_git=true; [[ -e "$INSTALLER_HOME_DIR"/../../.git ]] || running_from_git=false
has() { type "$@"; } &>/dev/null
error() {
    if [ -t 1 ]; then
        # on tty output, color errors in red
        echo -ne '\033[31m'
        echo "$@"
        echo -ne '\033[0m'
    else
        echo "$@"
    fi
    false
} >&2
INSTALLER_TEMP_DIR=
init_INSTALLER_TEMP_DIR() {
    # makes sure INSTALLER_TEMP_DIR points to a temporary directory
    if ! [[ -d "$INSTALLER_TEMP_DIR" ]]; then
        INSTALLER_TEMP_DIR=$(mktemp -d "${TMPDIR:-/tmp}"/deepdive-installer.XXXXXXX)
        trap "rm -rf $INSTALLER_TEMP_DIR" EXIT
    fi
}

# common installers ###########################################################
# installs DeepDive's build dependencies
install__deepdive_build_deps() {
    local deps=
    deps=(
        git
        make
        bzip2
        unzip
        jdk
    )
    error "Please make sure the following packages are available on your system: $(
        printf '\n  %s' "${deps[@]}")" ||
            [[ ! -t 1 ]] || read -p "# Continue? " || true
}
# installs DeepDive's runtime dependencies
install__deepdive_runtime_deps() {
    local deps=
    deps=(
        bash
        coreutils
        xargs
        bc
        gnuplot
        jre
        python
    )
    error "Please make sure the following packages are available on your system:$(
        printf '\n  %s' "${deps[@]}")" ||
            [[ ! -t 1 ]] || read -p "# Continue? " || true
}
# fetches DeepDive source tree
install__deepdive_git_repo() {
    $running_from_git ||
        # or already has a git clone and can checkout the branch
        { [[ -e deepdive/.git ]] && (cd deepdive && git checkout "$INSTALLER_BRANCH"); } ||
        # or were able to grab a clone with git
        git clone --recursive --branch "$INSTALLER_BRANCH" https://github.com/HazyResearch/deepdive.git
}
# installs DeepDive from source by going through the full build
install_deepdive_from_source() {
{'fraction_non_alphanumeric': 0.15443037974683543, 'fraction_numerical': 0.007789678675754625, 'mean_word_length': 2.879154078549849, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4391425', 'n_tokens_mistral': 1768, 'n_tokens_neox': 1670, 'n_words': 445}