<commit_before>#!/bin/sh

backend_register_longopt "docker-base-image:"
backend_register_longopt "docker-build-stage:"

docker_check_state_dir () {
    if [ ! -d .travis-run/$VM_NAME ]; then
	echo "travis-run: Can't find state dir: ">&2
	echo "\t$PWD/.travis-run/$VM_NAME">&2
	echo >&2
	echo "Have you run \`travis-run create' yet?">&2
	exit 1
    fi
}

docker_create () {
    set -e

    local OPTS VM_NAME LANGUAGE OPT_DISTRIBUTION OPT_FROM OPT_STAGE

    OPTS=$($GETOPT -o "" --long docker-base-image:,docker-build-stage: -n "$(basename $0)" -- "$@")
    eval set -- "$OPTS"

    while true; do
	case "$1" in
            --docker-base-image)  OPT_FROM=$2;     shift; shift ;;
            --docker-build-stage) OPT_STAGE=$2;    shift; shift ;;

            --) shift; break ;;
            *) echo "Error parsing argument: $1">&2; exit 1 ;;
	esac
    done

    VM_NAME=$1; shift
    OPT_LANGUAGE=$1; shift
    OPT_FROM=${OPT_FROM:-ubuntu:precise}

    if [ ! $OPT_LANGUAGE ]; then
	echo "Usage: docker_create VM_NAME LANGUAGE [DOCKER_OPTIONS..]">&2
	exit 1
    fi

    echo STAGE $OPT_STAGE

    echo "Creating base image"
    (
	[ "$OPT_STAGE" -a "$OPT_STAGE" != "base" ] && exit

	mkdir -p ~/.travis-run/${VM_NAME}_base
	cp $SHARE_DIR/vm/base-install.sh     ~/.travis-run/${VM_NAME}_base
	cp $SHARE_DIR/vm/base-configure.sh   ~/.travis-run/${VM_NAME}_base
	cp $SHARE_DIR/vm/language-install.sh ~/.travis-run/${VM_NAME}_base
	cp $SHARE_DIR/keys/travis-run.pub    ~/.travis-run/${VM_NAME}_base

	sed 's/$OPT_FROM/'"$OPT_FROM"'/' \
	    < $SHARE_DIR/docker/Dockerfile.base \
	    > ~/.travis-run/${VM_NAME}_base/Dockerfile

	docker build --rm=false -t ${VM_NAME}_base ~/.travis-run/${VM_NAME}_base
    )

    echo "Creating build-script image"
    (
	[ "$OPT_STAGE" -a "$OPT_STAGE" != "script" ] && exit

	mkdir -p ~/.travis-run/${VM_NAME}_script
	cp -a $SHARE_DIR/script ~/.travis-run/${VM_NAME}_script

	sed 's/$FROM/'"${VM_NAME}_base"'/' \
	    < $SHARE_DIR/docker/Dockerfile.script \
	    > ~/.travis-run/${VM_NAME}_script/Dockerfile

	docker build -t ${VM_NAME}_script ~/.travis-run/${VM_NAME}_script
    )

    echo "Creating language image"
    (
	[ "$OPT_STAGE" -a "$OPT_STAGE" != "language" ] && exit

	mkdir -p ~/.travis-run/${VM_NAME}_$OPT_LANGUAGE

	sed 's/$FROM/'"${VM_NAME}_base"'/' \
	    < $SHARE_DIR/docker/Dockerfile.language \
	    > ~/.travis-run/${VM_NAME}_$OPT_LANGUAGE/Dockerfile
	sed -i 's/$OPT_LANGUAGE/'"$OPT_LANGUAGE"'/' \
	    ~/.travis-run/${VM_NAME}_$OPT_LANGUAGE/Dockerfile

	docker build -t ${VM_NAME}_$OPT_LANGUAGE \
	    ~/.travis-run/${VM_NAME}_$OPT_LANGUAGE
    )

    echo "Creating per-project image"
    (
	[ "$OPT_STAGE" -a "$OPT_STAGE" != "project" ] && exit

	mkdir -p .travis-run/$VM_NAME

	if [ ! -e .travis-run/$VM_NAME/Dockerfile ]; then
	    sed 's/$FROM/'"${VM_NAME}_$OPT_LANGUAGE"'/' \
		< $SHARE_DIR/docker/Dockerfile.project \
		> .travis-run/$VM_NAME/Dockerfile
	fi

	DOCKER_ID=$(docker build .travis-run/$VM_NAME 2>/dev/null \<commit_msg>fix BSD sed weirdness<commit_after>#!/bin/sh

backend_register_longopt "docker-base-image:"
backend_register_longopt "docker-build-stage:"

docker_check_state_dir () {
    if [ ! -d .travis-run/$VM_NAME ]; then
	echo "travis-run: Can't find state dir: ">&2
	echo "\t$PWD/.travis-run/$VM_NAME">&2
	echo >&2
	echo "Have you run \`travis-run create' yet?">&2
	exit 1
    fi
}

docker_create () {
    set -e

    local OPTS VM_NAME LANGUAGE OPT_DISTRIBUTION OPT_FROM OPT_STAGE

    OPTS=$($GETOPT -o "" --long docker-base-image:,docker-build-stage: -n "$(basename $0)" -- "$@")
    eval set -- "$OPTS"

    while true; do
	case "$1" in
            --docker-base-image)  OPT_FROM=$2;     shift; shift ;;
            --docker-build-stage) OPT_STAGE=$2;    shift; shift ;;

            --) shift; break ;;
            *) echo "Error parsing argument: $1">&2; exit 1 ;;
	esac
    done

    VM_NAME=$1; shift
    OPT_LANGUAGE=$1; shift
    OPT_FROM=${OPT_FROM:-ubuntu:precise}

    if [ ! $OPT_LANGUAGE ]; then
	echo "Usage: docker_create VM_NAME LANGUAGE [DOCKER_OPTIONS..]">&2
	exit 1
    fi

    echo "Creating base image"
    (
	[ "$OPT_STAGE" -a "$OPT_STAGE" != "base" ] && exit

	mkdir -p ~/.travis-run/${VM_NAME}_base
	cp $SHARE_DIR/vm/base-install.sh     ~/.travis-run/${VM_NAME}_base
	cp $SHARE_DIR/vm/base-configure.sh   ~/.travis-run/${VM_NAME}_base
	cp $SHARE_DIR/vm/language-install.sh ~/.travis-run/${VM_NAME}_base
	cp $SHARE_DIR/keys/travis-run.pub    ~/.travis-run/${VM_NAME}_base

	sed 's/$OPT_FROM/'"$OPT_FROM"'/' \
	    < $SHARE_DIR/docker/Dockerfile.base \
	    > ~/.travis-run/${VM_NAME}_base/Dockerfile

	docker build --rm=false -t ${VM_NAME}_base ~/.travis-run/${VM_NAME}_base
    )

    echo "Creating build-script image"
    (
	[ "$OPT_STAGE" -a "$OPT_STAGE" != "script" ] && exit

	mkdir -p ~/.travis-run/${VM_NAME}_script
	cp -a $SHARE_DIR/script ~/.travis-run/${VM_NAME}_script

	sed 's/$FROM/'"${VM_NAME}_base"'/' \
	    < $SHARE_DIR/docker/Dockerfile.script \
	    > ~/.travis-run/${VM_NAME}_script/Dockerfile

	docker build -t ${VM_NAME}_script ~/.travis-run/${VM_NAME}_script
    )

    echo "Creating language image"
    (
	[ "$OPT_STAGE" -a "$OPT_STAGE" != "language" ] && exit

	mkdir -p ~/.travis-run/${VM_NAME}_$OPT_LANGUAGE

	sed 's/$FROM/'"${VM_NAME}_base"'/' \
	    < $SHARE_DIR/docker/Dockerfile.language \
	    > ~/.travis-run/${VM_NAME}_$OPT_LANGUAGE/Dockerfile
	sed -i "sed" 's/$OPT_LANGUAGE/'"$OPT_LANGUAGE"'/' \
	    ~/.travis-run/${VM_NAME}_$OPT_LANGUAGE/Dockerfile

	docker build -t ${VM_NAME}_$OPT_LANGUAGE \
	    ~/.travis-run/${VM_NAME}_$OPT_LANGUAGE
    )

    echo "Creating per-project image"
    (
	[ "$OPT_STAGE" -a "$OPT_STAGE" != "project" ] && exit

	mkdir -p .travis-run/$VM_NAME

	if [ ! -e .travis-run/$VM_NAME/Dockerfile ]; then
	    sed 's/$FROM/'"${VM_NAME}_$OPT_LANGUAGE"'/' \
		< $SHARE_DIR/docker/Dockerfile.project \
		> .travis-run/$VM_NAME/Dockerfile
	fi

	DOCKER_ID=$(docker build .travis-run/$VM_NAME 2>/dev/null \
{'fraction_non_alphanumeric': 0.18277768470430558, 'fraction_numerical': 0.005696096498575976, 'mean_word_length': 3.047457627118644, 'pattern_counts': {'":': 0, '<': 11, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3260396', 'n_tokens_mistral': 2507, 'n_tokens_neox': 2428, 'n_words': 411}