<commit_before>#!/usr/bin/env bash
set -e
HOME_DIR=`pwd`
BASE_DIR="/opt/vaxiom-docker/base/"
CENTOS_SRC_DIR="centos/"
DOCK_USER="vaxiom"
DEFAULT_CONTAINER="centos"
DEFAULT_TAG="latest"
DEFAULT_SSH_KEY="id_rsa"
DEFAULT_ACTION="ALL"

container=$1
tag=$2
ssh_key=$3
action=$4

if [ -z "$container" ];then
	container="$DEFAULT_CONTAINER"
fi

if [ -z "$tag" ];then
	tag="$DEFAULT_TAG"
fi

if [ -z "$ssh_key" ];then
	ssh_key="$DEFAULT_SSH_KEY"
fi

if [ -z "$action" ];then
	action="$DEFAULT_ACTION"
fi

DOCKER_BASE_IMAGE_NAME="$DOCK_USER/$container"
DOCKER_BASE_IMAGE="/opt/vaxiom-docker/base/centos/"
DOCKER_BASE_IMAGE_SRC="/opt/vaxiom-docker/base/centos/src/"

DOCKER_JAVA_IMAGE_NAME="vaxiom/AXIOJAVA8"
DOCKER_JAVA_IMAGE="/opt/vaxiom-docker/java8/centos/"
DOCKER_JAVA_IMAGE_SRC="/opt/vaxiom-docker/java8/centos/src/"

DOCKER_TOMCAT_IMAGE_NAME="vaxiom/AXIOVM01TOMCAT7"
DOCKER_TOMCAT_IMAGE="/opt/vaxiom-docker/tomcat7/centos/"
DOCKER_TOMCAT_IMAGE_SRC="/opt/vaxiom-docker/tomcat7/centos/src/"

usage() {
# ./build-docker-image.sh centos latest id_rsa BASE
	local RC=0

	if [ -z $container ];then
		RC=1
	fi

	if [ -z $tag ];then
		RC=1
	fi

	if [ ! $RC -eq 0 ];then
		echo "INFO:  Usage:  $(basename $0) <container name> <tag> [ssh pub key] <optional image action>"
		echo "INFO:  Usage example 1:  $(basename $0) centos latest $HOME/$USER/.ssh/id_rsa.pub"
		echo "INFO:  Usage example 2:  $(basename $0) centos latest $HOME/$USER/.ssh/id_rsa.pub BASE"
		echo "INFO:  Usage example 3:  $(basename $0) centos latest $HOME/$USER/.ssh/id_rsa.pub JAVA"
		echo "INFO:  Usage example 4:  $(basename $0) centos latest $HOME/$USER/.ssh/id_rsa.pub TOMCAT"
	fi

	return $RC
}

does_file_exists(){
	local f="$1"
	[[ -f "$f" ]] && return 0 || return 1
}

wrapUp() {
    cd $HOME_DIR
}

genSSHKeys() {
	local RC=0
	local key="$1"
	local pubExt="pub"
	local USER_SSH_HOME="$HOME/.ssh"
	local key="$USER_SSH_HOME/$key"
	local pub="${key}.${pubExt}"
		
	#local key="id_rsa"
	#local pubExt="id_rsa_pub.pub"

	if [ ! -d "$USER_SSH_HOME" ];then
		mkdir -p "$USER_SSH_HOME"
		if [ ! $? -eq 0 ];then
			RC=1
			echo "ERROR: Unable to create directory: $USER_SSH_HOME"
		fi
	fi
	
	if [[ $RC -eq 0 && ! -f "$key" ]]; then
		echo "INFO:  No public ssh key found. Generating a new ssh key"
		echo "INFO:  Running cmd:  ssh-keygen -q -t rsa -N '' -f $key"
		ssh-keygen -q -t rsa -N "" -f "$key"
		if [ ! $? -eq 0 ];then
			RC=1
		fi
	fi
	
	if [[ $RC -eq 0 && -f "$key" ]];then
		RC=1
		mv -f "$key" "$DOCKER_BASE_IMAGE_SRC"
		if [[ $? -eq 0 && -f "$pub" ]];then
			cat "$pub" >> "USER_SSH_HOME/authorized_keys"
			mv -f "$pub" "$DOCKER_BASE_IMAGE_SRC"
			if [ $? -eq 0 ];then
				RC=0
				chmod 700 "$USER_SSH_HOME"
				chmod 600 "$USER_SSH_HOME/authorized_keys"
				chown $USER:$USER "$USER_SSH_HOME/authorized_keys"
				chown -R $USER:$USER $USER_SSH_HOME
			fi			
		fi<commit_msg>no message<commit_after>#!/usr/bin/env bash
set -e
HOME_DIR=`pwd`
BASE_DIR="/opt/vaxiom-docker/base/"
CENTOS_SRC_DIR="centos/"
DOCK_USER="vaxiom"
DEFAULT_CONTAINER="centos"
DEFAULT_TAG="latest"
DEFAULT_SSH_KEY="id_rsa"
DEFAULT_ACTION="ALL"

container=$1
tag=$2
ssh_key=$3
action=$4

if [ -z "$container" ];then
	container="$DEFAULT_CONTAINER"
fi

if [ -z "$tag" ];then
	tag="$DEFAULT_TAG"
fi

if [ -z "$ssh_key" ];then
	ssh_key="$DEFAULT_SSH_KEY"
fi

if [ -z "$action" ];then
	action="$DEFAULT_ACTION"
fi

DOCKER_BASE_IMAGE_NAME="$DOCK_USER/$container"
DOCKER_BASE_IMAGE="/opt/vaxiom-docker/base/centos/"
DOCKER_BASE_IMAGE_SRC="/opt/vaxiom-docker/base/centos/src/"

DOCKER_JAVA_IMAGE_NAME="vaxiom/AXIOJAVA8"
DOCKER_JAVA_IMAGE="/opt/vaxiom-docker/java8/centos/"
DOCKER_JAVA_IMAGE_SRC="/opt/vaxiom-docker/java8/centos/src/"

DOCKER_TOMCAT_IMAGE_NAME="vaxiom/AXIOVM01TOMCAT7"
DOCKER_TOMCAT_IMAGE="/opt/vaxiom-docker/tomcat7/centos/"
DOCKER_TOMCAT_IMAGE_SRC="/opt/vaxiom-docker/tomcat7/centos/src/"

usage() {
# ./build-docker-image.sh centos latest id_rsa BASE
	local RC=0

	if [ -z $container ];then
		RC=1
	fi

	if [ -z $tag ];then
		RC=1
	fi

	if [ ! $RC -eq 0 ];then
		echo "INFO:  Usage:  $(basename $0) <container name> <tag> [ssh pub key] <optional image action>"
		echo "INFO:  Usage example 1:  $(basename $0) centos latest $HOME/$USER/.ssh/id_rsa.pub"
		echo "INFO:  Usage example 2:  $(basename $0) centos latest $HOME/$USER/.ssh/id_rsa.pub BASE"
		echo "INFO:  Usage example 3:  $(basename $0) centos latest $HOME/$USER/.ssh/id_rsa.pub JAVA"
		echo "INFO:  Usage example 4:  $(basename $0) centos latest $HOME/$USER/.ssh/id_rsa.pub TOMCAT"
	fi

	return $RC
}

does_file_exists(){
	local f="$1"
	[[ -f "$f" ]] && return 0 || return 1
}

wrapUp() {
    cd $HOME_DIR
}

genSSHKeys() {
	local RC=0
	local key="$1"
	local pubExt="pub"
	local USER_SSH_HOME="$HOME/.ssh"
	local key="$USER_SSH_HOME/$key"
	local pub="${key}.${pubExt}"
		
	#local key="id_rsa"
	#local pubExt="id_rsa_pub.pub"

	if [ ! -d "$USER_SSH_HOME" ];then
		mkdir -p "$USER_SSH_HOME"
		if [ ! $? -eq 0 ];then
			RC=1
			echo "ERROR: Unable to create directory: $USER_SSH_HOME"
		fi
	fi
	
	if [[ $RC -eq 0 && ! -f "$key" ]]; then
		echo "INFO:  No public ssh key found. Generating a new ssh key"
		echo "INFO:  Running cmd:  ssh-keygen -q -t rsa -N '' -f $key"
		ssh-keygen -q -t rsa -N "" -f "$key"
		if [ ! $? -eq 0 ];then
			RC=1
		fi
	fi
	
	if [[ $RC -eq 0 && -f "$key" ]];then
		RC=1
		cp -f "$key" "$DOCKER_BASE_IMAGE_SRC"
		if [[ $? -eq 0 && -f "$pub" ]];then
			cat "$pub" >> "USER_SSH_HOME/authorized_keys"
			cp -f "$pub" "$DOCKER_BASE_IMAGE_SRC"
			if [ $? -eq 0 ];then
				RC=0
				chmod 700 "$USER_SSH_HOME"
				chmod 600 "$key"
			fi			
		fi
{'fraction_non_alphanumeric': 0.17126972740315638, 'fraction_numerical': 0.01649928263988522, 'mean_word_length': 3.8664921465968587, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '1329521', 'n_tokens_mistral': 2638, 'n_tokens_neox': 2403, 'n_words': 539}