<commit_before>#!/bin/bash
# ==========================================================
# This script installs docker via wget on a linux server
# Optionally send proxy file as parameter - Depends on get_proxy script
# =========================================================

# Uncomment the following line to debug
# set -o xtrace

# Ensure script is run as root
if [ "$EUID" -ne "0" ]; then
  echo "$(date +"%F %T.%N") ERROR : This script must be run as root." >&2
  exit 1
fi

# Set locale
locale-gen en_US
update-locale
export HOME=/root

proxy=""

# ============================= Get Proxy information if passed as parameter ============================
while [[ ${1} ]]; do
  case "${1}" in
    --proxy|-x)
      if [ -f "${2}" ]; then
            echo "   Getting proxy information."
            http_proxy_=$(awk -F "=" '/http_proxy/ {print $2}' ${2})
            https_proxy_=$(awk -F "=" '/https_proxy/ {print $2}' ${2})
            no_proxy_=$(awk -F "=" '/no_proxy/ {print $2}' ${2})
            proxy="http_proxy=${http_proxy_} https_proxy=${https_proxy_} no_proxy=${no_proxy_}"
            echo "    Proxy set to: $proxy"
      else
           echo "Missing proxy file. See file fintaxis at ~/InstallScripts/utilities/proxyrc.sample"
           exit 1
      fi
      shift
      ;;
    --help|-h)
      echo " "
      echo "Script installs docker."
      echo "Optionally use --proxy to pass proxy details to the installation"
      echo " "
      echo "Usage:"
      echo "     ./install_docker [--proxy | -x] <filePath>"
      echo " "
      echo "     --proxy <filePath>     Pass the full file name where proxy information lives"
      echo "     -x      <filePath>     Pass the full file name where proxy information lives."
      echo "     --help                 Prints current help text. "
      echo "Find Proxy File Sintaxis at https://github.com/dlux/InstallScripts/blob/master/utilities/proxyrc.sample"
      echo " "
      exit 1
      ;;
    *)
      echo "***************************" >&2
      echo "* Error: Invalid argument. $1" >&2
      echo "  See ./install_docker --help" >&2
      echo "***************************" >&2
      exit 1
  esac
  shift
done

# ============================= Docker instalation ============================
# Update/Re-sync packages index
echo "Docker installation begins"

eval $proxy apt-get -y -qq update
eval $proxy apt-get -y -qq install wget

# Set gpg if server is behind a proxy
if [ ! -z "$proxy" ]; then
     echo "Setting gpg"
     eval $proxy wget -qO- https://get.docker.com/gpg | apt-key add -
fi

# Install Docker
eval $proxy wget -qO- https://get.docker.com/ | eval $proxy sh

# Set docker proxy if server is behind a proxy
if [ ! -z "$proxy" ]; then
	if [ -f /etc/default/docker ]; then
		stop docker
		# httpproxy=`expr "$proxy" : '\(.*\) https'`
		echo "export $http_proxy_" >> /etc/default/docker
		start docker
    fi
   # http_proxy_host=`expr "$http_proxy" : '\(.*\):'`
   # http_proxy_port=`expr "$http_proxy" : '.*\:\(.*\)'`
fi

# Verify Installation
echo "Verifying Docker installation."
eval $proxy docker run hello-world
eval $proxy docker run docker/whalesay cowsay Dlux test container running

echo "Adding caller user to docker group"
callerUser=$(who -m | awk '{print $1;}')
usermod -aG docker $callerUser
echo "Docker installation finished."
echo "Re-login with current user credentials."<commit_msg>Update proxy passed as parameter<commit_after>#!/bin/bash
# ==========================================================
# This script installs docker via curl sh in a linux server
# Optionally send proxy server or file with full proxy info.
# =========================================================

# Uncomment the following line to debug
# set -o xtrace

# Ensure script is run as root
if [ "$EUID" -ne "0" ]; then
  echo "$(date +"%F %T.%N") ERROR : This script must be run as root." >&2
  exit 1
fi

# Set locale
locale-gen en_US
update-locale
export HOME=/root

#=================================================
# GLOBAL VARIABLES DEFINITION
#=================================================
_original_proxy=''
_proxy=''
_domain=',.intel.com'

#=================================================
# GLOBAL FUNCTIONS
#=================================================
# Error Function
function PrintError {
    echo "************************" >&2
    echo "* $(date +"%F %T.%N") ERROR: $1" >&2
    echo "************************" >&2
    exit 1
}

function PrintHelp {
    echo " "
    echo "Script installs docker server. Optionally uses given proxy"
    echo " "
    echo "Usage:"
    echo "./install_docker.sh [--proxy | -x <http://proxyserver:port>]"
    echo " "
    echo "     --proxy | -x     Uses the given proxy server to install the tools."
    echo "     --help           Prints current help text. "
    echo " "
    exit 1
}

# ============================= Processes docker installation options ============================
while [[ ${1} ]]; do
  case "${1}" in
    --proxy|-x)
      if [[ -z "${2}" || "${2}" == -* ]]; then
          PrintError "Missing proxy data."
      else
          _original_proxy="${2}"
          if [ -f /etc/apt/apt.conf ]; then
              echo "Acquire::http::Proxy \"${2}\";" >>  /etc/apt/apt.conf
              echo "Acquire::https::Proxy \"${2}\";" >>  /etc/apt/apt.conf
          elif [ -d /etc/apt/apt.conf.d ]; then
              echo "Acquire::http::Proxy \"${2}\";" >>  /etc/apt/apt.conf.d/70proxy.conf
              echo "Acquire::https::Proxy \"${2}\";" >>  /etc/apt/apt.conf.d/70proxy.conf
          fi
          npx="127.0.0.0/8,localhost,10.0.0.0/8,192.168.0.0/16${_domain}"
          _proxy="http_proxy=${2} https_proxy=${2} no_proxy=${npx}"
          _proxy="$_proxy HTTP_PROXY=${2} HTTPS_PROXY=${2} NO_PROXY=${npx}"
      fi
      shift
      ;;
    --help|-h)
      PrintHelp
      ;;
    *)
      PrintError "Invalid Argument."
  esac
  shift
done

# ============================= Docker instalation ============================
# Update/Re-sync packages index
echo "Docker installation begins"

eval $_proxy apt-get -y -qq update
eval $_proxy apt-get -y -qq install wget

# Set gpg if server is behind a proxy
if [ -n "$_proxy" ]; then
     echo "Setting gpg since server is behind a proxy"
     eval $_proxy wget -qO- https://get.docker.com/gpg | apt-key add -
fi

# Install Docker
eval $_proxy wget -qO- https://get.docker.com/ | eval $_proxy sh

# Set docker proxy if server is behind a proxy
if [ -n "$_proxy" ]; then
	if [ -f /etc/default/docker ]; then
		stop docker
		# httpproxy=`expr "$proxy" : '\(.*\) https'`
		echo "export $_original_proxy" >> /etc/default/docker
		start docker
    fi
   # http_proxy_host=`expr "$http_proxy" : '\(.*\):'`
   # http_proxy_port=`expr "$http_proxy" : '.*\:\(.*\)'`
fi

# Verify Installation
echo "Verifying Docker installation."
eval $_proxy docker run hello-world
eval $_proxy docker run docker/whalesay cowsay Dlux test container running

echo "Adding caller user to docker group"
callerUser=$(who -m | awk '{print $1;}')
usermod -aG docker $callerUser
echo "Docker installation finished."
echo "Re-login with current user credentials."

# Cleanup proxy from apt if added - first coincedence
if [[ ! -z "${_original_proxy}" ]]; then
  scaped_str=$(echo $_original_proxy | sed -s 's/[\/&]/\\&/g')
  if [ -f /etc/apt/apt.conf ]; then
      sed -i "0,/$scaped_str/{/$scaped_str/d;}" /etc/apt/apt.conf
  elif [ -d /etc/apt/apt.conf.d ]; then
      sed -i "0,/$scaped_str/{/$scaped_str/d;}" /etc/apt/apt.conf.d/70proxy.conf
  fi
fi

{'fraction_non_alphanumeric': 0.23451386125480833, 'fraction_numerical': 0.009948269001193792, 'mean_word_length': 2.9538542212899843, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 28, 'https://': 5, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 3, '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': '3552782', 'n_tokens_mistral': 2432, 'n_tokens_neox': 2314, 'n_words': 726}