Print auditwheel version in pip script

Print auditwheel version in pip script

PiperOrigin-RevId: 236381732

#!/usr/bin/env bash
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
# Build the Python PIP installation package for TensorFlow and install
# the package.
#
# Usage:
#   pip_new.sh
#
# Required step(s):
#   Run configure.py prior to running this script.
#
# Required environment variable(s):
#   CONTAINER_TYPE:      (CPU | GPU)
#   OS_TYPE:             (UBUNTU | MACOS)
#   TF_PYTHON_VERSION:   (python2 | python2.7 | python3.5 | python3.7)
#
# Optional environment variables. If provided, overwrites any default values.
#   TF_BUILD_FLAGS:      Bazel build flags.
#                          e.g. TF_BUILD_FLAGS="--config=opt"
#   TF_TEST_FLAGS:       Bazel test flags.
#                          e.g. TF_TEST_FLAGS="--verbose_failures=true \
#                               --build_tests_only --test_output=errors"
#   TF_TEST_FILTER_TAGS: Filtering tags for bazel tests. More specifically,
#                        input tags for `--test_filter_tags` flag.
#                          e.g. TF_TEST_FILTER_TAGS="no_pip,-nomac,no_oss"
#   TF_TEST_TARGETS:     Bazel test targets.
#                          e.g. TF_TEST_TARGETS="//tensorflow/contrib/... \
#                               //tensorflow/... \
#                               //tensorflow/python/..."
#   TF_PIP_TESTS:        PIP tests to run. If NOT specified, skips all tests.
#                          e.g. TF_PIP_TESTS="test_pip_virtualenv_clean \
#                               test_pip_virtualenv_clean \
#                               test_pip_virtualenv_oss_serial"
#   IS_NIGHTLY:          Nightly run flag.
#                          e.g. IS_NIGHTLY=1  # nightly runs
#                          e.g. IS_NIGHTLY=0  # non-nightly runs
#   TF_PROJECT_NAME:     Name of the project. This string will be pass onto
#                        the wheel file name. For nightly builds, it will be
#                        overwritten to 'tf_nightly'. For gpu builds, '_gpu'
#                        will be appended.
#                          e.g. TF_PROJECT_NAME="tensorflow"
#                          e.g. TF_PROJECT_NAME="tf_nightly_gpu"
#   TF_PIP_TEST_ROOT:    Root directory for building and testing pip pkgs.
#                          e.g. TF_PIP_TEST_ROOT="pip_test"
#
# To-be-deprecated variable(s).
#   GIT_TAG_OVERRIDE:    Values for `--git_tag_override`. This flag gets passed
#                        in as `--action_env` for bazel build and tests.
#   TF_BUILD_INSTALL_EXTRA_PIP_PACKAGES
#                        Additonal pip packages to be installed.
#                        Caveat: pip version needs to be checked prior.

# set bash options
set -e
set -x

###########################################################################
# General helper function(s)
###########################################################################

# Strip leading and trailing whitespaces
str_strip () {
  echo -e "$1" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'
}

# Convert string to all lower case
lowercase() {
  if [[ -z "${1}" ]]; then
    die "Nothing to convert to lowercase. No argument given."
  fi
  echo "${1}" | tr '[:upper:]' '[:lower:]'
}

check_global_vars() {
  # Check container type
  if ! [[ ${CONTAINER_TYPE} == "cpu" ]] && \
     ! [[ ${CONTAINER_TYPE} == "rocm" ]] && \
     ! [[ ${CONTAINER_TYPE} == "gpu" ]]; then
    die "Error: Provided CONTAINER_TYPE \"${CONTAINER_TYPE}\" "\
        "is not supported."
  fi
  # Check OS type
  if ! [[ ${OS_TYPE} == "ubuntu" ]] && \
     ! [[ ${OS_TYPE} == "macos" ]]; then
    die"Error: Provided OS_TYPE \"${OS_TYPE}\" is not supported."
  fi
}

add_test_filter_tag() {
  EMPTY=""
  while true; do
    FILTER="${1:$EMPTY}"
    if ! [[ $BAZEL_TEST_FILTER_TAGS == *"${FILTER}"* ]]; then
      BAZEL_TEST_FILTER_TAGS="${FILTER},${BAZEL_TEST_FILTER_TAGS}"
    fi
    shift
    if [[ -z "${1}" ]]; then
      break
    fi
  done
}

remove_test_filter_tag() {
  EMPTY=""
  while true; do
    FILTER="${1:$EMPTY}"
    BAZEL_TEST_FILTER_TAGS="$(echo ${BAZEL_TEST_FILTER_TAGS} | sed -e 's/^'${FILTER}',//g' -e 's/,'${FILTER}'//g')"
    shift
    if [[ -z "${1}" ]]; then
      break
    fi
  done
}

# Clean up bazel build & test flags with proper configuration.
update_bazel_flags() {
  # Add git tag override flag if necessary.
  GIT_TAG_STR=" --action_env=GIT_TAG_OVERRIDE"
  if [[ -z "${GIT_TAG_OVERRIDE}" ]] && \
    ! [[ ${BAZEL_BUILD_FLAGS} = *${GIT_TAG_STR}* ]]; then
    BAZEL_BUILD_FLAGS+="${GIT_TAG_STR}"
  fi
  # Clean up whitespaces
  BAZEL_BUILD_FLAGS=$(str_strip "${BAZEL_BUILD_FLAGS}")
  BAZEL_TEST_FLAGS=$(str_strip "${BAZEL_TEST_FLAGS}")
  # Cleaned bazel flags
  echo "Bazel build flags (cleaned):\n" "${BAZEL_BUILD_FLAGS}"
  echo "Bazel test flags (cleaned):\n" "${BAZEL_TEST_FLAGS}"
}

update_test_filter_tags() {
  # Add test filter tags
  # This script is for validating built PIP packages. Add pip tags.
  add_test_filter_tag -no_pip -nopip
  # MacOS filter tags
  if [[ ${OS_TYPE} == "macos" ]]; then
    remove_test_filter_tag nomac no_mac
    add_test_filter_tag -nomac -no_mac
  fi
  echo "Final test filter tags: ${BAZEL_TEST_FILTER_TAGS}"
}

# Check currently running python and pip version
check_python_pip_version() {
  # Check if only the major version of python is provided by the user.
  MAJOR_VER_ONLY=0
  if [[ ${#PYTHON_VER} -lt 9 ]]; then
    # User only provided major version (e.g. 'python2' instead of 'python2.7')
    MAJOR_VER_ONLY=1
  fi

  # Retrieve only the version number of the user requested python.
  PYTHON_VER_REQUESTED=${PYTHON_VER:6:3}
  echo "PYTHON_VER_REQUESTED: ${PYTHON_VER_REQUESTED}"

  # Retrieve only the version numbers of the python & pip in use currently.
  PYTHON_VER_IN_USE=$(python --version 2>&1)
  PYTHON_VER_IN_USE=${PYTHON_VER_IN_USE:7:3}
  PIP_VER_IN_USE=$(pip --version)
  PIP_VER_IN_USE=${PIP_VER_IN_USE:${#PIP_VER_IN_USE}-4:3}

  # If only major versions are applied, drop minor versions.
  if [[ $MAJOR_VER_ONLY == 1 ]]; then
    PYTHON_VER_IN_USE=${PYTHON_VER_IN_USE:0:1}
    PIP_VER_IN_USE=${PIP_VER_IN_USE:0:1}
  fi

  # Check if all versions match.
  echo -e "User requested python version: '${PYTHON_VER_REQUESTED}'\n" \
    "Detected python version in use: '${PYTHON_VER_IN_USE}'\n"\
    "Detected pip version in use: '${PIP_VER_IN_USE}'"
  if ! [[ $PYTHON_VER_REQUESTED == $PYTHON_VER_IN_USE ]]; then
    die "Error: Mismatch in python versions detected."
  else:
    echo "Python and PIP versions in use match the requested."
  fi
}

###########################################################################
# Setup: directories, local/global variables
###########################################################################

# Script directory and source necessary files.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${SCRIPT_DIR}/builds_common.sh"

# Required global variables
# Checks on values for these vars are done in "Build TF PIP Package" section.
CONTAINER_TYPE=$(lowercase "${CONTAINER_TYPE}")
OS_TYPE=$(lowercase "${OS_TYPE}")
PYTHON_VER=$(lowercase "${TF_PYTHON_VERSION}")

# Python bin path
if [[ -z "$PYTHON_BIN_PATH" ]]; then
  die "Error: PYTHON_BIN_PATH was not provided. Did you run configure?"
fi
# Get python version for configuring pip later in installation.
PYTHON_VER_CFG=$(${PYTHON_BIN_PATH} -V 2>&1 | awk '{print $NF}' | cut -d. -f-2)
if [[ $OS_TYPE == "macos" ]]; then
  echo "PYTHON_VER_CFG (-V): $(${PYTHON_BIN_PATH} -V 2>&1)"
  echo "PYTHON_VER_CFG (--version): $(${PYTHON_BIN_PATH} --version 2>&1)"
  PYTHON_VER_CFG=$(${PYTHON_BIN_PATH} --version 2>&1 | awk '{print $NF}' | cut -d. -f-2)
fi
echo "PYTHON_BIN_PATH: ${PYTHON_BIN_PATH} (version: ${PYTHON_VER_CFG})"

# Default values for optional global variables in case they are not user
# defined.
DEFAULT_BAZEL_BUILD_FLAGS='--config=opt'
DEFAULT_BAZEL_TEST_FLAGS='--test_output=errors --verbose_failures=true'
DEFAULT_BAZEL_TEST_FILTERS='-no_oss,-oss_serial'
DEFAULT_BAZEL_TEST_TARGETS='//tensorflow/python/... -//tensorflow/core/... -//tensorflow/compiler/... '
DEFAULT_PIP_TESTS="" # Do not run any tests by default
DEFAULT_IS_NIGHTLY=0 # Not nightly by default
DEFAULT_PROJECT_NAME="tensorflow"
DEFAULT_PIP_TEST_ROOT="pip_test"

# Take in optional global variables
BAZEL_BUILD_FLAGS=${TF_BUILD_FLAGS:-$DEFAULT_BAZEL_BUILD_FLAGS}
BAZEL_TEST_FLAGS=${TF_TEST_FLAGS:-$DEFAULT_BAZEL_TEST_FLAGS}
BAZEL_TEST_TARGETS=${TF_TEST_TARGETS:-$DEFAULT_BAZEL_TEST_TARGETS}
BAZEL_TEST_FILTER_TAGS=${TF_TEST_FILTER_TAGS:-$DEFAULT_BAZEL_TEST_FILTERS}
PIP_TESTS=${TF_PIP_TESTS:-$DEFAULT_PIP_TESTS}
IS_NIGHTLY=${IS_NIGHTLY:-$DEFAULT_IS_NIGHTLY}
PROJECT_NAME=${TF_PROJECT_NAME:-$DEFAULT_PROJECT_NAME}
PIP_TEST_ROOT=${TF_PIP_TEST_ROOT:-$DEFAULT_PIP_TEST_ROOT}

# Local variables
PIP_WHL_DIR="${KOKORO_ARTIFACTS_DIR}/tensorflow/${PIP_TEST_ROOT}/whl"
mkdir -p "${PIP_WHL_DIR}"
PIP_WHL_DIR=$(realpath "${PIP_WHL_DIR}") # Get absolute path
WHL_PATH=""
# Determine the major.minor versions of python being used (e.g., 2.7).
# Useful for determining the directory of the local pip installation.
PY_MAJOR_MINOR_VER=$(${PYTHON_BIN_PATH} -V 2>&1 | awk '{print $NF}' | cut -d. -f-2)
if [[ -z "${PY_MAJOR_MINOR_VER}" ]]; then
  die "ERROR: Unable to determine the major.minor version of Python."
fi
echo "Python binary path to be used in PIP install: ${PYTHON_BIN_PATH} "\
"(Major.Minor version: ${PY_MAJOR_MINOR_VER})"
PYTHON_BIN_PATH_INIT=${PYTHON_BIN_PATH}
PIP_BIN_PATH="$(which pip${PYTHON_VER_CFG})"
PIP_BIN_PATH_INIT=${PIP_BIN_PATH}

# PIP packages
INSTALL_EXTRA_PIP_PACKAGES=${TF_BUILD_INSTALL_EXTRA_PIP_PACKAGES}

###########################################################################
# Build TF PIP Package
###########################################################################

# First remove any already existing binaries for a clean start and test.
if [[ -d ${PIP_TEST_ROOT} ]]; then
  echo "Test root directory ${PIP_TEST_ROOT} already exists. Deleting it."
  sudo rm -rf ${PIP_TEST_ROOT}
fi

# Check that global variables are properly set.
check_global_vars

# Check if in a virtualenv and exit if yes.
IN_VENV=$(python -c 'import sys; print("1" if hasattr(sys, "real_prefix") else "0")')
if [[ "$IN_VENV" == "1" ]]; then
  echo "It appears that we are already in a virtualenv. Deactivating..."
  deactivate || source deactivate || die "FAILED: Unable to deactivate from existing virtualenv."
fi

# Configure python. Obtain the path to python binary.
source tools/python_bin_path.sh
# Assume PYTHON_BIN_PATH is exported by the script above.
if [[ -z "$PYTHON_BIN_PATH" ]]; then
  die "PYTHON_BIN_PATH was not provided. Did you run configure?"
fi

# Bazel build the file.
PIP_BUILD_TARGET="//tensorflow/tools/pip_package:build_pip_package"
# Clean bazel cache.
bazel clean
# Clean up and update bazel flags
update_bazel_flags
# Build. This outputs the file `build_pip_package`.
bazel build ${BAZEL_BUILD_FLAGS} ${PIP_BUILD_TARGET} || \
  die "Error: Bazel build failed for target: '${PIP_BUILD_TARGET}'"

###########################################################################
# Test function(s)
###########################################################################

test_pip_virtualenv_clean() {
  # Create a clean directory.
  CLEAN_VENV_DIR="${PIP_TEST_ROOT}/venv_clean"

  # activate virtual environment and install tensorflow with PIP.
  create_activate_virtualenv --clean "${CLEAN_VENV_DIR}"
  # Install TF with pip
  install_tensorflow_pip "${WHL_PATH}"

  # cd to a temporary directory to avoid picking up Python files in the source
  # tree.
  TMP_DIR=$(mktemp -d)
  pushd "${TMP_DIR}"

  # Run a quick check on tensorflow installation.
  RET_VAL=$(python -c "import tensorflow as tf; t1=tf.constant([1,2,3,4]); t2=tf.constant([5,6,7,8]); print(tf.add(t1,t2).shape)")

  # Deactivate virtualenv.
  deactivate || source deactivate || die "FAILED: Unable to deactivate from existing virtualenv."

  # Return to original directory. Remove temp dirs.
  popd
  sudo rm -rf "${TMP_DIR}" "${CLEAN_VENV_DIR}"

  # Check result to see if tensorflow is properly installed.
  if [[ ${RET_VAL} == *'(4,)'* ]]; then
    echo "PIP test on clean virtualenv PASSED."
    return 0
  else
    echo "PIP test on clean virtualenv FAILED."
    return 1
  fi
}

test_pip_virtualenv_non_clean() {
  # Create virtualenv directory for install test
  VENV_DIR="${PIP_TEST_ROOT}/venv"

  # Activate virtualenv
  create_activate_virtualenv "${VENV_DIR}"
  # Install TF with pip
  install_tensorflow_pip "${WHL_PATH}"

  # cd to a temporary directory to avoid picking up Python files in the source
  # tree.
  TMP_DIR=$(mktemp -d)
  pushd "${TMP_DIR}"

  # Run a quick check on tensorflow installation.
  RET_VAL=$(python -c "import tensorflow as tf; t1=tf.constant([1,2,3,4]); t2=tf.constant([5,6,7,8]); print(tf.add(t1,t2).shape)")

  # Return to original directory. Remove temp dirs.
  popd
  sudo rm -rf "${TMP_DIR}"

  # Check result to see if tensorflow is properly installed.
  if ! [[ ${RET_VAL} == *'(4,)'* ]]; then
    echo "PIP test on virtualenv (non-clean) FAILED"
    return 1
  fi

  # Install extra pip packages, if specified.
  for PACKAGE in ${INSTALL_EXTRA_PIP_PACKAGES}; do
    echo "Installing extra pip package required by test-on-install: ${PACKAGE}"

    ${PIP_BIN_PATH} install ${PACKAGE}
    if [[ $? != 0 ]]; then
      echo "${PIP_BIN_PATH} install ${PACKAGE} FAILED."
      deactivate || source deactivate || die "FAILED: Unable to deactivate from existing virtualenv."
      return 1
    fi
  done

  # Run bazel test.
  run_test_with_bazel
  RESULT=$?

  # Deactivate from virtualenv.
  deactivate || source deactivate || die "FAILED: Unable to deactivate from existing virtualenv."
  sudo rm -rf "${VENV_DIR}"

  if [[ $RESULT -ne 0 ]]; then
    echo "PIP test on virtualenv (non-clean) FAILED."
    return 1
  else
    echo "PIP test on virtualenv (non-clean) PASSED."
    return 0
  fi
}

test_pip_virtualenv_oss_serial() {
  # Create virtualenv directory
  VENV_DIR="${PIP_TEST_ROOT}/venv"

  create_activate_virtualenv "${VENV_DIR}"
  run_test_with_bazel --oss_serial
  RESULT=$?

  # deactivate virtualenv
  deactivate || source deactivate || die "FAILED: Unable to deactivate from existing virtualenv."

  if [[ ${RESULT} -ne 0 ]]; then
    echo "PIP test on virtualenv (oss-serial) FAILED."
    return 1
  else
    echo "PIP test on virtualenv (oss-serial) PASSED."
    return 0
  fi
}

###########################################################################
# Test helper function(s)
###########################################################################

create_activate_virtualenv() {
  VIRTUALENV_FLAGS="--system-site-packages"
  if [[ "${1}" == "--clean" ]]; then
    shift
  fi

  VIRTUALENV_DIR="${1}"
  if [[ -d "${VIRTUALENV_DIR}" ]]; then
    if sudo rm -rf "${VIRTUALENV_DIR}"
    then
      echo "Removed existing virtualenv directory: ${VIRTUALENV_DIR}"
    else
      die "Failed to remove existing virtualenv directory: ${VIRTUALENV_DIR}"
    fi
  fi

  if mkdir -p "${VIRTUALENV_DIR}"
  then
    echo "Created virtualenv directory: ${VIRTUALENV_DIR}"
  else
    die "FAILED to create virtualenv directory: ${VIRTUALENV_DIR}"
  fi

  # Use the virtualenv from the default python version (i.e., python-virtualenv)
  # to create the virtualenv directory for testing. Use the -p flag to specify
  # the python version inside the to-be-created virtualenv directory.
  ${PYTHON_BIN_PATH_INIT} -m virtualenv -p ${PYTHON_BIN_PATH_INIT} ${VIRTUALENV_FLAGS} ${VIRTUALENV_DIR} || \
    die "FAILED: Unable to create virtualenv"

  source "${VIRTUALENV_DIR}/bin/activate" || \
    die "FAILED: Unable to activate virtualenv in ${VIRTUALENV_DIR}"

  # Update .tf_configure.bazelrc with venv python path for bazel test.
  PYTHON_BIN_PATH="$(which python)"
  yes "" | ./configure
}

install_tensorflow_pip() {
  if [[ -z "${1}" ]]; then
    die "Please provide a proper wheel file path."
  fi

  # Set path to pip.
  PIP_BIN_PATH="$(which pip${PYTHON_VER_CFG})"

  # Print python and pip bin paths
  echo "PYTHON_BIN_PATH to be used to install the .whl: ${PYTHON_BIN_PATH}"
  echo "PIP_BIN_PATH to be used to install the .whl: ${PIP_BIN_PATH}"

  # Upgrade pip so it supports tags such as cp27mu, manylinux1 etc.
  echo "Upgrade pip in virtualenv"

  # NOTE: pip install --upgrade pip leads to a documented TLS issue for
  # some versions in python
  curl https://bootstrap.pypa.io/get-pip.py | ${PYTHON_BIN_PATH} || \
    die "Error: pip install (get-pip.py) FAILED"

  # Check that requested python version matches configured one.
  check_python_pip_version

  # Force upgrade of setuptools. This must happen before the pip install of the
  # WHL_PATH, which pulls in absl-py, which uses install_requires notation
  # introduced in setuptools >=20.5. The default version of setuptools is 5.5.1,
  # which is too old for absl-py.
  ${PIP_BIN_PATH} install --upgrade setuptools==39.1.0 || \
    die "Error: setuptools install, upgrade FAILED"

  # Force tensorflow reinstallation. Otherwise it may not get installed from
  # last build if it had the same version number as previous build.
  PIP_FLAGS="--upgrade --force-reinstall"
  ${PIP_BIN_PATH} install -v ${PIP_FLAGS} ${WHL_PATH} || \
    die "pip install (forcing to reinstall tensorflow) FAILED"
  echo "Successfully installed pip package ${WHL_PATH}"

  # Force downgrade of setuptools. This must happen after the pip install of the
  # WHL_PATH, which ends up upgrading to the latest version of setuptools.
  # Versions of setuptools >= 39.1.0 will cause tests to fail like this:
  #   ImportError: cannot import name py31compat
  ${PIP_BIN_PATH} install --upgrade setuptools==39.1.0 || \
    die "Error: setuptools install, upgrade FAILED"
}

run_test_with_bazel() {
  IS_OSS_SERIAL=0
  if [[ "${1}" == "--oss_serial" ]]; then
    IS_OSS_SERIAL=1
  fi
  TF_GPU_COUNT=${TF_GPU_COUNT:-4}

  # PIP tests should have a "different" path. Different than the one we place
  # virtualenv, because we are deleting and recreating it here.
  PIP_TEST_PREFIX=bazel_pip
  TEST_ROOT=$(pwd)/${PIP_TEST_PREFIX}
  sudo rm -rf $TEST_ROOT
  mkdir -p $TEST_ROOT
  ln -s $(pwd)/tensorflow $TEST_ROOT/tensorflow

  if [[ "${IS_OSS_SERIAL}" == "1" ]]; then
    remove_test_filter_tag -no_oss
    add_test_filter_tag oss_serial
  else
    add_test_filter_tag -oss_serial
  fi

  # Clean the bazel cache
  bazel clean
  # Clean up flags before running bazel commands
  update_bazel_flags
  # Clean up and update test filter tags
  update_test_filter_tags

  # Figure out how many concurrent tests we can run and do run the tests.
  BAZEL_PARALLEL_TEST_FLAGS=""
  if [[ $CONTAINER_TYPE == "gpu" ]]; then
    # Number of test threads is the number of GPU cards available.
    if [[ $OS_TYPE == "macos" ]]; then
      BAZEL_PARALLEL_TEST_FLAGS="--local_test_jobs=1"
    else
      BAZEL_PARALLEL_TEST_FLAGS="--local_test_jobs=${TF_GPU_COUNT} \
        --run_under=//tensorflow/tools/ci_build/gpu_build:parallel_gpu_execute"
    fi
  else
    # Number of test threads is the number of physical CPUs.
    if [[ $OS_TYPE == "macos" ]]; then
      BAZEL_PARALLEL_TEST_FLAGS="--local_test_jobs=$(sysctl -n hw.ncpu)"
    else
      BAZEL_PARALLEL_TEST_FLAGS="--local_test_jobs=$(grep -c ^processor /proc/cpuinfo)"
    fi
  fi

  if [[ ${IS_OSS_SERIAL} == 1 ]]; then
    BAZEL_PARALLEL_TEST_FLAGS="--local_test_jobs=1"
  fi

  # TODO(hyey): Update test target after validation.
  # Run the test.
  bazel test --build_tests_only ${BAZEL_TEST_FLAGS} ${BAZEL_PARALLEL_TEST_FLAGS} --test_tag_filters=${BAZEL_TEST_FILTER_TAGS} -k -- //$PIP_TEST_PREFIX/tensorflow/python/...

  unlink ${TEST_ROOT}/tensorflow
}

run_all_tests() {
  if [[ -z "${PIP_TESTS}" ]]; then
    echo "No test was specified to run. Skipping all tests."
    return 0
  fi
  FAIL_COUNTER=0
  PASS_COUNTER=0
  for TEST in ${PIP_TESTS[@]}; do

    # Run tests.
    case "${TEST}" in
    "test_pip_virtualenv_clean")
      test_pip_virtualenv_clean
      ;;
    "test_pip_virtualenv_non_clean")
      test_pip_virtualenv_non_clean
      ;;
    "test_pip_virtualenv_oss_serial")
      test_pip_virtualenv_oss_serial
      ;;
    *)
      die "No matching test ${TEST} was found. Stopping test."
      ;;
    esac

    # Check and update the results.
    RETVAL=$?

    # Update results counter
    if [ ${RETVAL} -eq 0 ]; then
      echo "Test (${TEST}) PASSED. (PASS COUNTER: ${PASS_COUNTER})"
      PASS_COUNTER=$(($PASS_COUNTER+1))
    else
      echo "Test (${TEST}) FAILED. (FAIL COUNTER: ${FAIL_COUNTER})"
      FAIL_COUNTER=$(($FAIL_COUNTER+1))
    fi
  done
  printf "${PASS_COUNTER} PASSED | ${FAIL_COUNTER} FAILED"
  if [[ "${FAIL_COUNTER}" == "0" ]]; then
    printf "PIP tests ${COLOR_GREEN}PASSED${COLOR_NC}\n"
    return 0
  else:
    printf "PIP tests ${COLOR_RED}FAILED${COLOR_NC}\n"
    return 1
  fi
}

###########################################################################
# Build TF PIP Wheel file
###########################################################################

# Update the build flags for building whl.
# Flags: GPU, OS, tf_nightly, project name
GPU_FLAG=""
NIGHTLY_FLAG=""

# TF Nightly flag
if [[ "$IS_NIGHTLY" == 1 ]]; then
  # If 'nightly' is not specified in the project name already, then add.
  if ! [[ $PROJECT_NAME == *"nightly"* ]]; then
    echo "WARNING: IS_NIGHTLY=${IS_NIGHTLY} but requested project name \
    (PROJECT_NAME=${PROJECT_NAME}) does not include 'nightly' string. \
    Renaming it to 'tf_nightly'."
    PROJECT_NAME="tf_nightly"
  fi
  NIGHTLY_FLAG="--nightly_flag"
fi

# CPU / GPU flag
if [[ ${CONTAINER_TYPE} == "gpu" ]]; then
  GPU_FLAG="--gpu"
  if ! [[ $PROJECT_NAME == *"gpu"* ]]; then
    echo "WARNING: GPU is specified but requested project name (PROJECT_NAME=${PROJECT_NAME}) \
    does not include 'gpu'. Appending '_gpu' to the project name."
    PROJECT_NAME="${PROJECT_NAME}_gpu"
  fi
fi

./bazel-bin/tensorflow/tools/pip_package/build_pip_package ${PIP_WHL_DIR} ${GPU_FLAG} ${NIGHTLY_FLAG} "--project_name" ${PROJECT_NAME} || die "build_pip_package FAILED"

PY_MAJOR_MINOR_VER=$(echo $PY_MAJOR_MINOR_VER | tr -d '.')
if [[ $PY_MAJOR_MINOR_VER == "2" ]]; then
  PY_MAJOR_MINOR_VER="27"
fi

# Set wheel path and verify that there is only one .whl file in the path.
WHL_PATH=$(ls "${PIP_WHL_DIR}"/"${PROJECT_NAME}"-*"${PY_MAJOR_MINOR_VER}"*"${PY_MAJOR_MINOR_VER}"*.whl)
if [[ $(echo "${WHL_PATH}" | wc -w) -ne 1 ]]; then
  echo "ERROR: Failed to find exactly one built TensorFlow .whl file in "\
  "directory: ${PIP_WHL_DIR}"
fi

WHL_DIR=$(dirname "${WHL_PATH}")
WHL_BASE_NAME=$(basename "${WHL_PATH}")
AUDITED_WHL_NAME="${WHL_DIR}"/$(echo "${WHL_BASE_NAME//linux/manylinux1}")

# Print the size of the wheel file.
echo "Size of the PIP wheel file built: $(ls -l ${WHL_PATH} | awk '{print $5}')"

# Run tests (if any is specified).
run_all_tests

for WHL_PATH in $(ls ${PIP_WHL_DIR}/${PROJECT_NAME}*.whl); do
  if [[ "${TF_NEED_CUDA}" -eq "1" ]]; then
    # Copy and rename for gpu manylinux as we do not want auditwheel to package in libcudart.so
    WHL_PATH=${AUDITED_WHL_NAME}
    cp "${WHL_DIR}"/"${WHL_BASE_NAME}" "${WHL_PATH}"
    echo "Copied manylinux1 wheel file at ${WHL_PATH}"
  else
    if [[ ${OS_TYPE} == "ubuntu" ]]; then
      # Repair the wheels for cpu manylinux1
      echo "auditwheel repairing ${WHL_PATH}"
      auditwheel --version
      pip show auditwheel
      auditwheel repair -w "${WHL_DIR}" "${WHL_PATH}"

      if [[ -f ${AUDITED_WHL_NAME} ]]; then
        WHL_PATH=${AUDITED_WHL_NAME}
        echo "Repaired manylinux1 wheel file at: ${WHL_PATH}"
      else
        die "WARNING: Cannot find repaired wheel."
      fi
    fi
  fi
done

echo "EOF: Successfully ran pip_new.sh"

#!/usr/bin/env bash
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
# Build the Python PIP installation package for TensorFlow and install
# the package.
#
# Usage:
#   pip_new.sh
#
# Required step(s):
#   Run configure.py prior to running this script.
#
# Required environment variable(s):
#   CONTAINER_TYPE:      (CPU | GPU)
#   OS_TYPE:             (UBUNTU | MACOS)
#   TF_PYTHON_VERSION:   (python2 | python2.7 | python3.5 | python3.7)
#
# Optional environment variables. If provided, overwrites any default values.
#   TF_BUILD_FLAGS:      Bazel build flags.
#                          e.g. TF_BUILD_FLAGS="--config=opt"
#   TF_TEST_FLAGS:       Bazel test flags.
#                          e.g. TF_TEST_FLAGS="--verbose_failures=true \
#                               --build_tests_only --test_output=errors"
#   TF_TEST_FILTER_TAGS: Filtering tags for bazel tests. More specifically,
#                        input tags for `--test_filter_tags` flag.
#                          e.g. TF_TEST_FILTER_TAGS="no_pip,-nomac,no_oss"
#   TF_TEST_TARGETS:     Bazel test targets.
#                          e.g. TF_TEST_TARGETS="//tensorflow/contrib/... \
#                               //tensorflow/... \
#                               //tensorflow/python/..."
#   TF_PIP_TESTS:        PIP tests to run. If NOT specified, skips all tests.
#                          e.g. TF_PIP_TESTS="test_pip_virtualenv_clean \
#                               test_pip_virtualenv_clean \
#                               test_pip_virtualenv_oss_serial"
#   IS_NIGHTLY:          Nightly run flag.
#                          e.g. IS_NIGHTLY=1  # nightly runs
#                          e.g. IS_NIGHTLY=0  # non-nightly runs
#   TF_PROJECT_NAME:     Name of the project. This string will be pass onto
#                        the wheel file name. For nightly builds, it will be
#                        overwritten to 'tf_nightly'. For gpu builds, '_gpu'
#                        will be appended.
#                          e.g. TF_PROJECT_NAME="tensorflow"
#                          e.g. TF_PROJECT_NAME="tf_nightly_gpu"
#   TF_PIP_TEST_ROOT:    Root directory for building and testing pip pkgs.
#                          e.g. TF_PIP_TEST_ROOT="pip_test"
#
# To-be-deprecated variable(s).
#   GIT_TAG_OVERRIDE:    Values for `--git_tag_override`. This flag gets passed
#                        in as `--action_env` for bazel build and tests.
#   TF_BUILD_INSTALL_EXTRA_PIP_PACKAGES
#                        Additonal pip packages to be installed.
#                        Caveat: pip version needs to be checked prior.

# set bash options
set -e
set -x

###########################################################################
# General helper function(s)
###########################################################################

# Strip leading and trailing whitespaces
str_strip () {
  echo -e "$1" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'
}

# Convert string to all lower case
lowercase() {
  if [[ -z "${1}" ]]; then
    die "Nothing to convert to lowercase. No argument given."
  fi
  echo "${1}" | tr '[:upper:]' '[:lower:]'
}

check_global_vars() {
  # Check container type
  if ! [[ ${CONTAINER_TYPE} == "cpu" ]] && \
     ! [[ ${CONTAINER_TYPE} == "rocm" ]] && \
     ! [[ ${CONTAINER_TYPE} == "gpu" ]]; then
    die "Error: Provided CONTAINER_TYPE \"${CONTAINER_TYPE}\" "\
        "is not supported."
  fi
  # Check OS type
  if ! [[ ${OS_TYPE} == "ubuntu" ]] && \
     ! [[ ${OS_TYPE} == "macos" ]]; then
    die"Error: Provided OS_TYPE \"${OS_TYPE}\" is not supported."
  fi
}

add_test_filter_tag() {
  EMPTY=""
  while true; do
    FILTER="${1:$EMPTY}"
    if ! [[ $BAZEL_TEST_FILTER_TAGS == *"${FILTER}"* ]]; then
      BAZEL_TEST_FILTER_TAGS="${FILTER},${BAZEL_TEST_FILTER_TAGS}"
    fi
    shift
    if [[ -z "${1}" ]]; then
      break
    fi
  done
}

remove_test_filter_tag() {
  EMPTY=""
  while true; do
    FILTER="${1:$EMPTY}"
    BAZEL_TEST_FILTER_TAGS="$(echo ${BAZEL_TEST_FILTER_TAGS} | sed -e 's/^'${FILTER}',//g' -e 's/,'${FILTER}'//g')"
    shift
    if [[ -z "${1}" ]]; then
      break
    fi
  done
}

# Clean up bazel build & test flags with proper configuration.
update_bazel_flags() {
  # Add git tag override flag if necessary.
  GIT_TAG_STR=" --action_env=GIT_TAG_OVERRIDE"
  if [[ -z "${GIT_TAG_OVERRIDE}" ]] && \
    ! [[ ${BAZEL_BUILD_FLAGS} = *${GIT_TAG_STR}* ]]; then
    BAZEL_BUILD_FLAGS+="${GIT_TAG_STR}"
  fi
  # Clean up whitespaces
  BAZEL_BUILD_FLAGS=$(str_strip "${BAZEL_BUILD_FLAGS}")
  BAZEL_TEST_FLAGS=$(str_strip "${BAZEL_TEST_FLAGS}")
  # Cleaned bazel flags
  echo "Bazel build flags (cleaned):\n" "${BAZEL_BUILD_FLAGS}"
  echo "Bazel test flags (cleaned):\n" "${BAZEL_TEST_FLAGS}"
}

update_test_filter_tags() {
  # Add test filter tags
  # This script is for validating built PIP packages. Add pip tags.
  add_test_filter_tag -no_pip -nopip
  # MacOS filter tags
  if [[ ${OS_TYPE} == "macos" ]]; then
    remove_test_filter_tag nomac no_mac
    add_test_filter_tag -nomac -no_mac
  fi
  echo "Final test filter tags: ${BAZEL_TEST_FILTER_TAGS}"
}

# Check currently running python and pip version
check_python_pip_version() {
  # Check if only the major version of python is provided by the user.
  MAJOR_VER_ONLY=0
  if [[ ${#PYTHON_VER} -lt 9 ]]; then
    # User only provided major version (e.g. 'python2' instead of 'python2.7')
    MAJOR_VER_ONLY=1
  fi

  # Retrieve only the version number of the user requested python.
  PYTHON_VER_REQUESTED=${PYTHON_VER:6:3}
  echo "PYTHON_VER_REQUESTED: ${PYTHON_VER_REQUESTED}"

  # Retrieve only the version numbers of the python & pip in use currently.
  PYTHON_VER_IN_USE=$(python --version 2>&1)
  PYTHON_VER_IN_USE=${PYTHON_VER_IN_USE:7:3}
  PIP_VER_IN_USE=$(pip --version)
  PIP_VER_IN_USE=${PIP_VER_IN_USE:${#PIP_VER_IN_USE}-4:3}

  # If only major versions are applied, drop minor versions.
  if [[ $MAJOR_VER_ONLY == 1 ]]; then
    PYTHON_VER_IN_USE=${PYTHON_VER_IN_USE:0:1}
    PIP_VER_IN_USE=${PIP_VER_IN_USE:0:1}
  fi

  # Check if all versions match.
  echo -e "User requested python version: '${PYTHON_VER_REQUESTED}'\n" \
    "Detected python version in use: '${PYTHON_VER_IN_USE}'\n"\
    "Detected pip version in use: '${PIP_VER_IN_USE}'"
  if ! [[ $PYTHON_VER_REQUESTED == $PYTHON_VER_IN_USE ]]; then
    die "Error: Mismatch in python versions detected."
  else:
    echo "Python and PIP versions in use match the requested."
  fi
}

###########################################################################
# Setup: directories, local/global variables
###########################################################################

# Script directory and source necessary files.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${SCRIPT_DIR}/builds_common.sh"

# Required global variables
# Checks on values for these vars are done in "Build TF PIP Package" section.
CONTAINER_TYPE=$(lowercase "${CONTAINER_TYPE}")
OS_TYPE=$(lowercase "${OS_TYPE}")
PYTHON_VER=$(lowercase "${TF_PYTHON_VERSION}")

# Python bin path
if [[ -z "$PYTHON_BIN_PATH" ]]; then
  die "Error: PYTHON_BIN_PATH was not provided. Did you run configure?"
fi
# Get python version for configuring pip later in installation.
PYTHON_VER_CFG=$(${PYTHON_BIN_PATH} -V 2>&1 | awk '{print $NF}' | cut -d. -f-2)
if [[ $OS_TYPE == "macos" ]]; then
  echo "PYTHON_VER_CFG (-V): $(${PYTHON_BIN_PATH} -V 2>&1)"
  echo "PYTHON_VER_CFG (--version): $(${PYTHON_BIN_PATH} --version 2>&1)"
  PYTHON_VER_CFG=$(${PYTHON_BIN_PATH} --version 2>&1 | awk '{print $NF}' | cut -d. -f-2)
fi
echo "PYTHON_BIN_PATH: ${PYTHON_BIN_PATH} (version: ${PYTHON_VER_CFG})"

# Default values for optional global variables in case they are not user
# defined.
DEFAULT_BAZEL_BUILD_FLAGS='--config=opt'
DEFAULT_BAZEL_TEST_FLAGS='--test_output=errors --verbose_failures=true'
DEFAULT_BAZEL_TEST_FILTERS='-no_oss,-oss_serial'
DEFAULT_BAZEL_TEST_TARGETS='//tensorflow/python/... -//tensorflow/core/... -//tensorflow/compiler/... '
DEFAULT_PIP_TESTS="" # Do not run any tests by default
DEFAULT_IS_NIGHTLY=0 # Not nightly by default
DEFAULT_PROJECT_NAME="tensorflow"
DEFAULT_PIP_TEST_ROOT="pip_test"

# Take in optional global variables
BAZEL_BUILD_FLAGS=${TF_BUILD_FLAGS:-$DEFAULT_BAZEL_BUILD_FLAGS}
BAZEL_TEST_FLAGS=${TF_TEST_FLAGS:-$DEFAULT_BAZEL_TEST_FLAGS}
BAZEL_TEST_TARGETS=${TF_TEST_TARGETS:-$DEFAULT_BAZEL_TEST_TARGETS}
BAZEL_TEST_FILTER_TAGS=${TF_TEST_FILTER_TAGS:-$DEFAULT_BAZEL_TEST_FILTERS}
PIP_TESTS=${TF_PIP_TESTS:-$DEFAULT_PIP_TESTS}
IS_NIGHTLY=${IS_NIGHTLY:-$DEFAULT_IS_NIGHTLY}
PROJECT_NAME=${TF_PROJECT_NAME:-$DEFAULT_PROJECT_NAME}
PIP_TEST_ROOT=${TF_PIP_TEST_ROOT:-$DEFAULT_PIP_TEST_ROOT}

# Local variables
PIP_WHL_DIR="${KOKORO_ARTIFACTS_DIR}/tensorflow/${PIP_TEST_ROOT}/whl"
mkdir -p "${PIP_WHL_DIR}"
PIP_WHL_DIR=$(realpath "${PIP_WHL_DIR}") # Get absolute path
WHL_PATH=""
# Determine the major.minor versions of python being used (e.g., 2.7).
# Useful for determining the directory of the local pip installation.
PY_MAJOR_MINOR_VER=$(${PYTHON_BIN_PATH} -V 2>&1 | awk '{print $NF}' | cut -d. -f-2)
if [[ -z "${PY_MAJOR_MINOR_VER}" ]]; then
  die "ERROR: Unable to determine the major.minor version of Python."
fi
echo "Python binary path to be used in PIP install: ${PYTHON_BIN_PATH} "\
"(Major.Minor version: ${PY_MAJOR_MINOR_VER})"
PYTHON_BIN_PATH_INIT=${PYTHON_BIN_PATH}
PIP_BIN_PATH="$(which pip${PYTHON_VER_CFG})"
PIP_BIN_PATH_INIT=${PIP_BIN_PATH}

# PIP packages
INSTALL_EXTRA_PIP_PACKAGES=${TF_BUILD_INSTALL_EXTRA_PIP_PACKAGES}

###########################################################################
# Build TF PIP Package
###########################################################################

# First remove any already existing binaries for a clean start and test.
if [[ -d ${PIP_TEST_ROOT} ]]; then
  echo "Test root directory ${PIP_TEST_ROOT} already exists. Deleting it."
  sudo rm -rf ${PIP_TEST_ROOT}
fi

# Check that global variables are properly set.
check_global_vars

# Check if in a virtualenv and exit if yes.
IN_VENV=$(python -c 'import sys; print("1" if hasattr(sys, "real_prefix") else "0")')
if [[ "$IN_VENV" == "1" ]]; then
  echo "It appears that we are already in a virtualenv. Deactivating..."
  deactivate || source deactivate || die "FAILED: Unable to deactivate from existing virtualenv."
fi

# Configure python. Obtain the path to python binary.
source tools/python_bin_path.sh
# Assume PYTHON_BIN_PATH is exported by the script above.
if [[ -z "$PYTHON_BIN_PATH" ]]; then
  die "PYTHON_BIN_PATH was not provided. Did you run configure?"
fi

# Bazel build the file.
PIP_BUILD_TARGET="//tensorflow/tools/pip_package:build_pip_package"
# Clean bazel cache.
bazel clean
# Clean up and update bazel flags
update_bazel_flags
# Build. This outputs the file `build_pip_package`.
bazel build ${BAZEL_BUILD_FLAGS} ${PIP_BUILD_TARGET} || \
  die "Error: Bazel build failed for target: '${PIP_BUILD_TARGET}'"

###########################################################################
# Test function(s)
###########################################################################

test_pip_virtualenv_clean() {
  # Create a clean directory.
  CLEAN_VENV_DIR="${PIP_TEST_ROOT}/venv_clean"

  # activate virtual environment and install tensorflow with PIP.
  create_activate_virtualenv --clean "${CLEAN_VENV_DIR}"
  # Install TF with pip
  install_tensorflow_pip "${WHL_PATH}"

  # cd to a temporary directory to avoid picking up Python files in the source
  # tree.
  TMP_DIR=$(mktemp -d)
  pushd "${TMP_DIR}"

  # Run a quick check on tensorflow installation.
  RET_VAL=$(python -c "import tensorflow as tf; t1=tf.constant([1,2,3,4]); t2=tf.constant([5,6,7,8]); print(tf.add(t1,t2).shape)")

  # Deactivate virtualenv.
  deactivate || source deactivate || die "FAILED: Unable to deactivate from existing virtualenv."

  # Return to original directory. Remove temp dirs.
  popd
  sudo rm -rf "${TMP_DIR}" "${CLEAN_VENV_DIR}"

  # Check result to see if tensorflow is properly installed.
  if [[ ${RET_VAL} == *'(4,)'* ]]; then
    echo "PIP test on clean virtualenv PASSED."
    return 0
  else
    echo "PIP test on clean virtualenv FAILED."
    return 1
  fi
}

test_pip_virtualenv_non_clean() {
  # Create virtualenv directory for install test
  VENV_DIR="${PIP_TEST_ROOT}/venv"

  # Activate virtualenv
  create_activate_virtualenv "${VENV_DIR}"
  # Install TF with pip
  install_tensorflow_pip "${WHL_PATH}"

  # cd to a temporary directory to avoid picking up Python files in the source
  # tree.
  TMP_DIR=$(mktemp -d)
  pushd "${TMP_DIR}"

  # Run a quick check on tensorflow installation.
  RET_VAL=$(python -c "import tensorflow as tf; t1=tf.constant([1,2,3,4]); t2=tf.constant([5,6,7,8]); print(tf.add(t1,t2).shape)")

  # Return to original directory. Remove temp dirs.
  popd
  sudo rm -rf "${TMP_DIR}"

  # Check result to see if tensorflow is properly installed.
  if ! [[ ${RET_VAL} == *'(4,)'* ]]; then
    echo "PIP test on virtualenv (non-clean) FAILED"
    return 1
  fi

  # Install extra pip packages, if specified.
  for PACKAGE in ${INSTALL_EXTRA_PIP_PACKAGES}; do
    echo "Installing extra pip package required by test-on-install: ${PACKAGE}"

    ${PIP_BIN_PATH} install ${PACKAGE}
    if [[ $? != 0 ]]; then
      echo "${PIP_BIN_PATH} install ${PACKAGE} FAILED."
      deactivate || source deactivate || die "FAILED: Unable to deactivate from existing virtualenv."
      return 1
    fi
  done

  # Run bazel test.
  run_test_with_bazel
  RESULT=$?

  # Deactivate from virtualenv.
  deactivate || source deactivate || die "FAILED: Unable to deactivate from existing virtualenv."
  sudo rm -rf "${VENV_DIR}"

  if [[ $RESULT -ne 0 ]]; then
    echo "PIP test on virtualenv (non-clean) FAILED."
    return 1
  else
    echo "PIP test on virtualenv (non-clean) PASSED."
    return 0
  fi
}

test_pip_virtualenv_oss_serial() {
  # Create virtualenv directory
  VENV_DIR="${PIP_TEST_ROOT}/venv"

  create_activate_virtualenv "${VENV_DIR}"
  run_test_with_bazel --oss_serial
  RESULT=$?

  # deactivate virtualenv
  deactivate || source deactivate || die "FAILED: Unable to deactivate from existing virtualenv."

  if [[ ${RESULT} -ne 0 ]]; then
    echo "PIP test on virtualenv (oss-serial) FAILED."
    return 1
  else
    echo "PIP test on virtualenv (oss-serial) PASSED."
    return 0
  fi
}

###########################################################################
# Test helper function(s)
###########################################################################

create_activate_virtualenv() {
  VIRTUALENV_FLAGS="--system-site-packages"
  if [[ "${1}" == "--clean" ]]; then
    shift
  fi

  VIRTUALENV_DIR="${1}"
  if [[ -d "${VIRTUALENV_DIR}" ]]; then
    if sudo rm -rf "${VIRTUALENV_DIR}"
    then
      echo "Removed existing virtualenv directory: ${VIRTUALENV_DIR}"
    else
      die "Failed to remove existing virtualenv directory: ${VIRTUALENV_DIR}"
    fi
  fi

  if mkdir -p "${VIRTUALENV_DIR}"
  then
    echo "Created virtualenv directory: ${VIRTUALENV_DIR}"
  else
    die "FAILED to create virtualenv directory: ${VIRTUALENV_DIR}"
  fi

  # Use the virtualenv from the default python version (i.e., python-virtualenv)
  # to create the virtualenv directory for testing. Use the -p flag to specify
  # the python version inside the to-be-created virtualenv directory.
  ${PYTHON_BIN_PATH_INIT} -m virtualenv -p ${PYTHON_BIN_PATH_INIT} ${VIRTUALENV_FLAGS} ${VIRTUALENV_DIR} || \
    die "FAILED: Unable to create virtualenv"

  source "${VIRTUALENV_DIR}/bin/activate" || \
    die "FAILED: Unable to activate virtualenv in ${VIRTUALENV_DIR}"

  # Update .tf_configure.bazelrc with venv python path for bazel test.
  PYTHON_BIN_PATH="$(which python)"
  yes "" | ./configure
}

install_tensorflow_pip() {
  if [[ -z "${1}" ]]; then
    die "Please provide a proper wheel file path."
  fi

  # Set path to pip.
  PIP_BIN_PATH="$(which pip${PYTHON_VER_CFG})"

  # Print python and pip bin paths
  echo "PYTHON_BIN_PATH to be used to install the .whl: ${PYTHON_BIN_PATH}"
  echo "PIP_BIN_PATH to be used to install the .whl: ${PIP_BIN_PATH}"

  # Upgrade pip so it supports tags such as cp27mu, manylinux1 etc.
  echo "Upgrade pip in virtualenv"

  # NOTE: pip install --upgrade pip leads to a documented TLS issue for
  # some versions in python
  curl https://bootstrap.pypa.io/get-pip.py | ${PYTHON_BIN_PATH} || \
    die "Error: pip install (get-pip.py) FAILED"

  # Check that requested python version matches configured one.
  check_python_pip_version

  # Force upgrade of setuptools. This must happen before the pip install of the
  # WHL_PATH, which pulls in absl-py, which uses install_requires notation
  # introduced in setuptools >=20.5. The default version of setuptools is 5.5.1,
  # which is too old for absl-py.
  ${PIP_BIN_PATH} install --upgrade setuptools==39.1.0 || \
    die "Error: setuptools install, upgrade FAILED"

  # Force tensorflow reinstallation. Otherwise it may not get installed from
  # last build if it had the same version number as previous build.
  PIP_FLAGS="--upgrade --force-reinstall"
  ${PIP_BIN_PATH} install -v ${PIP_FLAGS} ${WHL_PATH} || \
    die "pip install (forcing to reinstall tensorflow) FAILED"
  echo "Successfully installed pip package ${WHL_PATH}"

  # Force downgrade of setuptools. This must happen after the pip install of the
  # WHL_PATH, which ends up upgrading to the latest version of setuptools.
  # Versions of setuptools >= 39.1.0 will cause tests to fail like this:
  #   ImportError: cannot import name py31compat
  ${PIP_BIN_PATH} install --upgrade setuptools==39.1.0 || \
    die "Error: setuptools install, upgrade FAILED"
}

run_test_with_bazel() {
  IS_OSS_SERIAL=0
  if [[ "${1}" == "--oss_serial" ]]; then
    IS_OSS_SERIAL=1
  fi
  TF_GPU_COUNT=${TF_GPU_COUNT:-4}

  # PIP tests should have a "different" path. Different than the one we place
  # virtualenv, because we are deleting and recreating it here.
  PIP_TEST_PREFIX=bazel_pip
  TEST_ROOT=$(pwd)/${PIP_TEST_PREFIX}
  sudo rm -rf $TEST_ROOT
  mkdir -p $TEST_ROOT
  ln -s $(pwd)/tensorflow $TEST_ROOT/tensorflow

  if [[ "${IS_OSS_SERIAL}" == "1" ]]; then
    remove_test_filter_tag -no_oss
    add_test_filter_tag oss_serial
  else
    add_test_filter_tag -oss_serial
  fi

  # Clean the bazel cache
  bazel clean
  # Clean up flags before running bazel commands
  update_bazel_flags
  # Clean up and update test filter tags
  update_test_filter_tags

  # Figure out how many concurrent tests we can run and do run the tests.
  BAZEL_PARALLEL_TEST_FLAGS=""
  if [[ $CONTAINER_TYPE == "gpu" ]]; then
    # Number of test threads is the number of GPU cards available.
    if [[ $OS_TYPE == "macos" ]]; then
      BAZEL_PARALLEL_TEST_FLAGS="--local_test_jobs=1"
    else
      BAZEL_PARALLEL_TEST_FLAGS="--local_test_jobs=${TF_GPU_COUNT} \
        --run_under=//tensorflow/tools/ci_build/gpu_build:parallel_gpu_execute"
    fi
  else
    # Number of test threads is the number of physical CPUs.
    if [[ $OS_TYPE == "macos" ]]; then
      BAZEL_PARALLEL_TEST_FLAGS="--local_test_jobs=$(sysctl -n hw.ncpu)"
    else
      BAZEL_PARALLEL_TEST_FLAGS="--local_test_jobs=$(grep -c ^processor /proc/cpuinfo)"
    fi
  fi

  if [[ ${IS_OSS_SERIAL} == 1 ]]; then
    BAZEL_PARALLEL_TEST_FLAGS="--local_test_jobs=1"
  fi

  # TODO(hyey): Update test target after validation.
  # Run the test.
  bazel test --build_tests_only ${BAZEL_TEST_FLAGS} ${BAZEL_PARALLEL_TEST_FLAGS} --test_tag_filters=${BAZEL_TEST_FILTER_TAGS} -k -- //$PIP_TEST_PREFIX/tensorflow/python/...

  unlink ${TEST_ROOT}/tensorflow
}

run_all_tests() {
  if [[ -z "${PIP_TESTS}" ]]; then
    echo "No test was specified to run. Skipping all tests."
    return 0
  fi
  FAIL_COUNTER=0
  PASS_COUNTER=0
  for TEST in ${PIP_TESTS[@]}; do

    # Run tests.
    case "${TEST}" in
    "test_pip_virtualenv_clean")
      test_pip_virtualenv_clean
      ;;
    "test_pip_virtualenv_non_clean")
      test_pip_virtualenv_non_clean
      ;;
    "test_pip_virtualenv_oss_serial")
      test_pip_virtualenv_oss_serial
      ;;
    *)
      die "No matching test ${TEST} was found. Stopping test."
      ;;
    esac

    # Check and update the results.
    RETVAL=$?

    # Update results counter
    if [ ${RETVAL} -eq 0 ]; then
      echo "Test (${TEST}) PASSED. (PASS COUNTER: ${PASS_COUNTER})"
      PASS_COUNTER=$(($PASS_COUNTER+1))
    else
      echo "Test (${TEST}) FAILED. (FAIL COUNTER: ${FAIL_COUNTER})"
      FAIL_COUNTER=$(($FAIL_COUNTER+1))
    fi
  done
  printf "${PASS_COUNTER} PASSED | ${FAIL_COUNTER} FAILED"
  if [[ "${FAIL_COUNTER}" == "0" ]]; then
    printf "PIP tests ${COLOR_GREEN}PASSED${COLOR_NC}\n"
    return 0
  else:
    printf "PIP tests ${COLOR_RED}FAILED${COLOR_NC}\n"
    return 1
  fi
}

###########################################################################
# Build TF PIP Wheel file
###########################################################################

# Update the build flags for building whl.
# Flags: GPU, OS, tf_nightly, project name
GPU_FLAG=""
NIGHTLY_FLAG=""

# TF Nightly flag
if [[ "$IS_NIGHTLY" == 1 ]]; then
  # If 'nightly' is not specified in the project name already, then add.
  if ! [[ $PROJECT_NAME == *"nightly"* ]]; then
    echo "WARNING: IS_NIGHTLY=${IS_NIGHTLY} but requested project name \
    (PROJECT_NAME=${PROJECT_NAME}) does not include 'nightly' string. \
    Renaming it to 'tf_nightly'."
    PROJECT_NAME="tf_nightly"
  fi
  NIGHTLY_FLAG="--nightly_flag"
fi

# CPU / GPU flag
if [[ ${CONTAINER_TYPE} == "gpu" ]]; then
  GPU_FLAG="--gpu"
  if ! [[ $PROJECT_NAME == *"gpu"* ]]; then
    echo "WARNING: GPU is specified but requested project name (PROJECT_NAME=${PROJECT_NAME}) \
    does not include 'gpu'. Appending '_gpu' to the project name."
    PROJECT_NAME="${PROJECT_NAME}_gpu"
  fi
fi

./bazel-bin/tensorflow/tools/pip_package/build_pip_package ${PIP_WHL_DIR} ${GPU_FLAG} ${NIGHTLY_FLAG} "--project_name" ${PROJECT_NAME} || die "build_pip_package FAILED"

PY_MAJOR_MINOR_VER=$(echo $PY_MAJOR_MINOR_VER | tr -d '.')
if [[ $PY_MAJOR_MINOR_VER == "2" ]]; then
  PY_MAJOR_MINOR_VER="27"
fi

# Set wheel path and verify that there is only one .whl file in the path.
WHL_PATH=$(ls "${PIP_WHL_DIR}"/"${PROJECT_NAME}"-*"${PY_MAJOR_MINOR_VER}"*"${PY_MAJOR_MINOR_VER}"*.whl)
if [[ $(echo "${WHL_PATH}" | wc -w) -ne 1 ]]; then
  echo "ERROR: Failed to find exactly one built TensorFlow .whl file in "\
  "directory: ${PIP_WHL_DIR}"
fi

WHL_DIR=$(dirname "${WHL_PATH}")
WHL_BASE_NAME=$(basename "${WHL_PATH}")
AUDITED_WHL_NAME="${WHL_DIR}"/$(echo "${WHL_BASE_NAME//linux/manylinux1}")

# Print the size of the wheel file.
echo "Size of the PIP wheel file built: $(ls -l ${WHL_PATH} | awk '{print $5}')"

# Run tests (if any is specified).
run_all_tests

for WHL_PATH in $(ls ${PIP_WHL_DIR}/${PROJECT_NAME}*.whl); do
  if [[ "${TF_NEED_CUDA}" -eq "1" ]]; then
    # Copy and rename for gpu manylinux as we do not want auditwheel to package in libcudart.so
    WHL_PATH=${AUDITED_WHL_NAME}
    cp "${WHL_DIR}"/"${WHL_BASE_NAME}" "${WHL_PATH}"
    echo "Copied manylinux1 wheel file at ${WHL_PATH}"
  else
    if [[ ${OS_TYPE} == "ubuntu" ]]; then
      # Repair the wheels for cpu manylinux1
      echo "auditwheel repairing ${WHL_PATH}"
      auditwheel repair -w "${WHL_DIR}" "${WHL_PATH}"

      if [[ -f ${AUDITED_WHL_NAME} ]]; then
        WHL_PATH=${AUDITED_WHL_NAME}
        echo "Repaired manylinux1 wheel file at: ${WHL_PATH}"
      else
        die "WARNING: Cannot find repaired wheel."
      fi
    fi
  fi
done

echo "EOF: Successfully ran pip_new.sh"


Updated encrypt script

Updated encrypt script

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/JHart9/DiscordBot.git/'


Add running script

Add running script

#!/bin/bash -e

if pgrep "php" > /dev/null; then
    echo "The server is probably running."
    echo ""
else
    echo "The server is probably stopped."
    echo ""
fi

ps aux | grep "SCREEN.*pocketmine"  | grep -v grep

error: pathspec 'bin/running.sh' did not match any file(s) known to git


[源] startup.sh - Start Script for the CATALINA Server

#!/bin/sh

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# -----------------------------------------------------------------------------
# Start Script for the CATALINA Server
# -----------------------------------------------------------------------------

# Better OS/400 detection: see Bugzilla 31132
os400=false
case "`uname`" in
OS400*) os400=true;;
esac

# resolve links - $0 may be a softlink
PRG="$0"

while [ -h "$PRG" ] ; do
  ls=`ls -ld "$PRG"`
  link=`expr "$ls" : '.*-> \(.*\)$'`
  if expr "$link" : '/.*' > /dev/null; then
    PRG="$link"
  else
    PRG=`dirname "$PRG"`/"$link"
  fi
done

PRGDIR=`dirname "$PRG"`
EXECUTABLE=catalina.sh

# Check that target executable exists
if $os400; then
  # -x will Only work on the os400 if the files are:
  # 1. owned by the user
  # 2. owned by the PRIMARY group of the user
  # this will not work if the user belongs in secondary groups
  eval
else
  if [ ! -x "$PRGDIR"/"$EXECUTABLE" ]; then
    echo "Cannot find $PRGDIR/$EXECUTABLE"
    echo "The file is absent or does not have execute permission"
    echo "This file is needed to run this program"
    exit 1
  fi
fi

exec "$PRGDIR"/"$EXECUTABLE" start "$@"

error: pathspec 'bin/startup.sh' did not match any file(s) known to git


script to set kubectl alias with correct .kubeconfig

#!/bin/bash
#
# setup kubectl for our Kraken clusters
#
# As long as the --kubeconfig arg points to the correct .kubeconfig file
# things will work.  NOTE: This is also to avoid the inconsistencies
# that can happen by depending on default locations for the .kubeconfig file.
#
# e.g.   what we want:
#alias kubectl='/opt/kubernetes/platforms/darwin/amd64/kubectl --kubeconfig="/Users/mikel_nelson/dev/cloud/kraken/kubernetes/.kubeconfig"'
#
echo "--------------------------------------------"
echo "  Attempting to set a kubectl alias"
echo "  for Kraken."
echo ""
echo " NOTE: You must 'source' this file"
echo "       so the alias will stick."
echo ""
echo " \$source ./setmyenv.sh"
echo "   or"
echo " \$. ./setmyenv.sh"
echo ""
unset CDPATH
echo "Locating Kraken Project kubectl and .kubeconfig..."
SCRIPTPATH="$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )"
cd ${SCRIPTPATH}
KUBECONFIG=`find ${SCRIPTPATH} -type f -name ".kubeconfig" -print | egrep 'kubernetes'`
if [ $? -ne 0 ];then
    echo "Could not find Kraken .kubeconfig in ${SCRIPTPATH}"
    exit 1
else
    echo "found: $KUBECONFIG"
fi
KUBECTL=`find /opt/kubernetes/platforms/darwin/amd64 -type f -name "kubectl" -print | egrep '.*'`
if [ $? -ne 0 ];then
    echo "Could not find kubectl. Make sure you have /opt/kubernetes/platforms/darwin/amd64/kubectl defined."
    exit 2
else
    echo "found: $KUBECTL"
fi
echo "Setting alias for kubectl with the kraken .kubeconfig file"
alias kubectl="${KUBECTL} --kubeconfig=${KUBECONFIG}"
echo `alias kubectl`
echo "--------------------------------------------"
echo "  Switching back to the starting directory:"
#
# switch back to where we started
cd -

error: pathspec 'kubernetes/setmyenv.sh' did not match any file(s) known to git


change to project dir

change to project dir

#!/usr/bin/env bash

#exit if any command fails
#set -e

artifactsFolder="./artifacts"

if [ -d $artifactsFolder ]; then
  rm -R $artifactsFolder
fi

# Restore packages
dotnet restore --configfile ./build/NuGet.config

# Change to project dir
cd KQAnalytics3/src/KQAnalytics3

# Build
dotnet build -c Release

# Publish
dotnet publish -c Release

#!/usr/bin/env bash

#exit if any command fails
#set -e

artifactsFolder="./artifacts"

if [ -d $artifactsFolder ]; then
  rm -R $artifactsFolder
fi

# Restore packages
dotnet restore --configfile ./build/NuGet.config

# Build
dotnet build -c Release KQAnalytics3/src/KQAnalytics3

# Publish
dotnet publish -c Release KQAnalytics3/src/KQAnalytics3


fix path.

fix path.

#!/bin/bash

tag=$(git describe --abbrev=0 --tags)
sed -i '' 's/{RELEASE}/${tag}/g' '${WORKSPACE}/src/main/resources/application-*'
mvn package

docker build -f build/Dockerfile -t hello-world:$tag .

$(aws ecr get-login --region eu-central-1)
docker tag hello-world:$tag 156161676080.dkr.ecr.eu-central-1.amazonaws.com/hello-world:$tag
docker tag hello-world:$tag 156161676080.dkr.ecr.eu-central-1.amazonaws.com/hello-world:latest

docker push 156161676080.dkr.ecr.eu-central-1.amazonaws.com/hello-world:$tag
docker push 156161676080.dkr.ecr.eu-central-1.amazonaws.com/hello-world:latest

docker rmi hello-world:$tag
docker rmi 156161676080.dkr.ecr.eu-central-1.amazonaws.com/hello-world:$tag

#!/bin/bash

tag=$(git describe --abbrev=0 --tags)
sed -i '' 's/{RELEASE}/${tag}/g' ${WORKSPACE}/src/main/resources/application-*
mvn package

docker build -f ${WORKSPACE}build/Dockerfile -t hello-world:$tag .

$(aws ecr get-login --region eu-central-1)
docker tag hello-world:$tag 156161676080.dkr.ecr.eu-central-1.amazonaws.com/hello-world:$tag
docker tag hello-world:$tag 156161676080.dkr.ecr.eu-central-1.amazonaws.com/hello-world:latest

docker push 156161676080.dkr.ecr.eu-central-1.amazonaws.com/hello-world:$tag
docker push 156161676080.dkr.ecr.eu-central-1.amazonaws.com/hello-world:latest

docker rmi hello-world:$tag
docker rmi 156161676080.dkr.ecr.eu-central-1.amazonaws.com/hello-world:$tag


Add script path var

Add script path var

#!/bin/bash
SCRIPT_PATH="${BASH_SOURCE[0]}";
if ([ -h "${SCRIPT_PATH}" ]) then
  while([ -h "${SCRIPT_PATH}" ]) do SCRIPT_PATH=`readlink "${SCRIPT_PATH}"`; done
fi
pushd . > /dev/null
cd `dirname ${SCRIPT_PATH}` > /dev/null
SCRIPT_PATH=`pwd`;
popd  > /dev/null

mono $SCRIPT_PATH/../packages/FAKE.4.3.4/tools/FAKE.exe BuildTests --fsiargs -d:MONO build.fsx

#!/bin/bash
mono packages/FAKE.4.3.4/tools/Fake.exe BuildTests --fsiargs -d:MONO build.fsx


Now we need the grammar itself be projected, not doing project on FSTs externally

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/cybeliak/mispronounceableness.git/'


swap script

swap script

#!/bin/sh

# size of swapfile in megabytes
swapsize=512
fallocate -l ${swapsize}M /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo '/swapfile none swap defaults 0 0' >> /etc/fstab

error: pathspec 'p2psafety_vagrant/files/bash/swapfile.sh' did not match any file(s) known to git


script for fixing bin privs

script for fixing bin privs

#!/bin/sh

# find all bin/ folders inside home dir and make executable all files there
find $HOME/ -type d -name bin | while read bin ; do
    find "$bin" -type f | xargs chmod -v +x
done

error: pathspec 'bin/fix-bin-privs.sh' did not match any file(s) known to git


Bluemix: let apps fetch registry credentials from controller

#!/bin/bash

source .bluemixrc

#################################################################################
# Pull Dockerhub images
#################################################################################

echo "Looking up Bluemix registry images"
BLUEMIX_IMAGES=$(cf ic images | tail -n +2 | sed -r 's/([^ ]+) +([^ ]+).*/\1:\2/')

REQUIRED_IMAGES=(
    ${PRODUCTPAGE_IMAGE}:v1
    ${DETAILS_IMAGE}:v1
    ${RATINGS_IMAGE}:v1
    ${REVIEWS_IMAGE}:v1
    ${REVIEWS_IMAGE}:v2
    ${REVIEWS_IMAGE}:v3
    ${GATEWAY_IMAGE}
)

for image in ${REQUIRED_IMAGES[@]}; do
    echo $BLUEMIX_IMAGES | grep $image > /dev/null
    if [ $? -ne 0 ]; then
        echo "Pulling ${DOCKERHUB_NAMESPACE}/$image from Dockerhub"
        cf ic cpi ${DOCKERHUB_NAMESPACE}/$image ${BLUEMIX_REGISTRY_HOST}/${BLUEMIX_REGISTRY_NAMESPACE}/$image
    fi
done

#################################################################################
# Fetch registry credentials
#################################################################################

if [ "$ENABLE_SERVICEDISCOVERY" = true ]; then
    SDKEY=$(cf service-key sd sdkey | tail -n +3)
    REGISTRY_URL=$(echo "$SDKEY" | jq -r '.url')
    REGISTRY_TOKEN=$(echo "$SDKEY" | jq -r '.auth_token')
else
    # TODO: Use local registry credentials
    echo "Not not implemented"
    exit 1
fi

#################################################################################
# Start the productpage microservice instances
#################################################################################

echo "Starting bookinfo productpage microservice (v1)"

cf ic group create --name bookinfo_productpage \
  --publish 9080 --memory 256 --auto \
  --min 1 --max 2 --desired 1 \
  --env CONTROLLER_URL=$CONTROLLER_URL \
  --env TENANT_ID=$CONTROLLER_TENANT_ID \
  --env TENANT_TOKEN=$CONTROLLER_TENANT_TOKEN \
  --env SERVICE=productpage \
  --env SERVICE_VERSION=v1 \
  --env ENDPOINT_PORT=9080 \
  --env LOG=false \
  ${BLUEMIX_REGISTRY_HOST}/${BLUEMIX_REGISTRY_NAMESPACE}/${PRODUCTPAGE_IMAGE}:v1

#################################################################################
# Start the details microservice instances
#################################################################################

echo "Starting bookinfo details microservice (v1)"

cf ic group create --name bookinfo_details \
  --publish 9080 --memory 256 --auto \
  --min 1 --max 2 --desired 1 \
  --env REGISTRY_URL=$REGISTRY_URL \
  --env REGISTRY_TOKEN=$REGISTRY_TOKEN \
  --env SERVICE=details \
  --env SERVICE_VERSION=v1 \
  --env ENDPOINT_PORT=9080 \
  ${BLUEMIX_REGISTRY_HOST}/${BLUEMIX_REGISTRY_NAMESPACE}/${DETAILS_IMAGE}:v1

#################################################################################
# Start the ratings microservice instances
#################################################################################

echo "Starting bookinfo ratings microservice (v1)"

cf ic group create --name bookinfo_ratings \
  --publish 9080 --memory 256 --auto \
  --min 1 --max 2 --desired 1 \
  --env REGISTRY_URL=$REGISTRY_URL \
  --env REGISTRY_TOKEN=$REGISTRY_TOKEN \
  --env SERVICE=ratings \
  --env SERVICE_VERSION=v1 \
  --env ENDPOINT_PORT=9080 \
  ${BLUEMIX_REGISTRY_HOST}/${BLUEMIX_REGISTRY_NAMESPACE}/${RATINGS_IMAGE}:v1

#################################################################################
# Start the reviews microservice instances
#################################################################################

echo "Starting bookinfo reviews microservice (v1)"

cf ic group create --name bookinfo_reviews1 \
  --publish 9080 --memory 256 --auto \
  --min 1 --max 2 --desired 1 \
  --env CONTROLLER_URL=$CONTROLLER_URL \
  --env TENANT_ID=$CONTROLLER_TENANT_ID \
  --env TENANT_TOKEN=$CONTROLLER_TENANT_TOKEN \
  --env SERVICE=reviews \
  --env SERVICE_VERSION=v1 \
  --env ENDPOINT_PORT=9080 \
  --env LOG=false \
  ${BLUEMIX_REGISTRY_HOST}/${BLUEMIX_REGISTRY_NAMESPACE}/${REVIEWS_IMAGE}:v1

echo "Starting bookinfo reviews microservice (v2)"

cf ic group create --name bookinfo_reviews2 \
  --publish 9080 --memory 256 --auto \
  --min 1 --max 2 --desired 1 \
  --env CONTROLLER_URL=$CONTROLLER_URL \
  --env TENANT_ID=$CONTROLLER_TENANT_ID \
  --env TENANT_TOKEN=$CONTROLLER_TENANT_TOKEN \
  --env SERVICE=reviews \
  --env SERVICE_VERSION=v2 \
  --env ENDPOINT_PORT=9080 \
  --env LOG=false \
  ${BLUEMIX_REGISTRY_HOST}/${BLUEMIX_REGISTRY_NAMESPACE}/${REVIEWS_IMAGE}:v2

echo "Starting bookinfo reviews microservice (v3)"

cf ic group create --name bookinfo_reviews3 \
  --publish 9080 --memory 256 --auto \
  --min 1 --max 2 --desired 1 \
  --env CONTROLLER_URL=$CONTROLLER_URL \
  --env TENANT_ID=$CONTROLLER_TENANT_ID \
  --env TENANT_TOKEN=$CONTROLLER_TENANT_TOKEN \
  --env SERVICE=reviews \
  --env SERVICE_VERSION=v3 \
  --env ENDPOINT_PORT=9080 \
  --env LOG=false \
  ${BLUEMIX_REGISTRY_HOST}/${BLUEMIX_REGISTRY_NAMESPACE}/${REVIEWS_IMAGE}:v3

#################################################################################
# Start the gateway
#################################################################################

echo "Starting bookinfo gateway"

cf ic group create --name bookinfo_gateway \
  --publish 6379 --memory 256 --auto \
  --min 1 --max 2 --desired 1 \
  --env CONTROLLER_URL=$CONTROLLER_URL \
  --env TENANT_TOKEN=12345 \
  --env TENANT_ID=local \
  --env SERVICE=gateway \
  --env SERVICE_VERSION=v1 \
  --env LOG=false \
  --env REGISTER=false \
  ${BLUEMIX_REGISTRY_HOST}/${BLUEMIX_REGISTRY_NAMESPACE}/$GATEWAY_IMAGE

echo "Waiting for gateway to start..."
sleep 15s

echo "Mapping route to gateway: $BOOKINFO_URL"
cf ic route map --hostname $BOOKINFO_HOSTNAME --domain $ROUTES_DOMAIN bookinfo_gateway

#!/bin/bash

source .bluemixrc

#################################################################################
# Pull Dockerhub images
#################################################################################

echo "Looking up Bluemix registry images"
BLUEMIX_IMAGES=$(cf ic images | tail -n +2 | sed -r 's/([^ ]+) +([^ ]+).*/\1:\2/')

REQUIRED_IMAGES=(
    ${PRODUCTPAGE_IMAGE}:v1
    ${DETAILS_IMAGE}:v1
    ${RATINGS_IMAGE}:v1
    ${REVIEWS_IMAGE}:v1
    ${REVIEWS_IMAGE}:v2
    ${REVIEWS_IMAGE}:v3
    ${GATEWAY_IMAGE}
)

for image in ${REQUIRED_IMAGES[@]}; do
    echo $BLUEMIX_IMAGES | grep $image > /dev/null
    if [ $? -ne 0 ]; then
        echo "Pulling ${DOCKERHUB_NAMESPACE}/$image from Dockerhub"
        cf ic cpi ${DOCKERHUB_NAMESPACE}/$image ${BLUEMIX_REGISTRY_HOST}/${BLUEMIX_REGISTRY_NAMESPACE}/$image
    fi
done

#################################################################################
# Fetch registry credentials
#################################################################################

if [ "$ENABLE_SERVICEDISCOVERY" = true ]; then
    SDKEY=$(cf service-key sd sdkey | tail -n +3)
    REGISTRY_URL=$(echo "$SDKEY" | jq -r '.url')
    REGISTRY_TOKEN=$(echo "$SDKEY" | jq -r '.auth_token')
else
    # TODO: Use local registry credentials
    echo "Not not implemented"
    exit 1
fi

#################################################################################
# Start the productpage microservice instances
#################################################################################

echo "Starting bookinfo productpage microservice (v1)"

cf ic group create --name bookinfo_productpage \
  --publish 9080 --memory 256 --auto \
  --min 1 --max 2 --desired 1 \
  --env CONTROLLER_URL=$CONTROLLER_URL \
  --env TENANT_ID=$CONTROLLER_TENANT_ID \
  --env TENANT_TOKEN=$CONTROLLER_TENANT_TOKEN \
  --env REGISTRY_URL=$REGISTRY_URL \
  --env REGISTRY_TOKEN=$REGISTRY_TOKEN \
  --env SERVICE=productpage \
  --env SERVICE_VERSION=v1 \
  --env ENDPOINT_PORT=9080 \
  --env LOG=false \
  ${BLUEMIX_REGISTRY_HOST}/${BLUEMIX_REGISTRY_NAMESPACE}/${PRODUCTPAGE_IMAGE}:v1

#################################################################################
# Start the details microservice instances
#################################################################################

echo "Starting bookinfo details microservice (v1)"

cf ic group create --name bookinfo_details \
  --publish 9080 --memory 256 --auto \
  --min 1 --max 2 --desired 1 \
  --env REGISTRY_URL=$REGISTRY_URL \
  --env REGISTRY_TOKEN=$REGISTRY_TOKEN \
  --env SERVICE=details \
  --env SERVICE_VERSION=v1 \
  --env ENDPOINT_PORT=9080 \
  ${BLUEMIX_REGISTRY_HOST}/${BLUEMIX_REGISTRY_NAMESPACE}/${DETAILS_IMAGE}:v1

#################################################################################
# Start the ratings microservice instances
#################################################################################

echo "Starting bookinfo ratings microservice (v1)"

cf ic group create --name bookinfo_ratings \
  --publish 9080 --memory 256 --auto \
  --min 1 --max 2 --desired 1 \
  --env REGISTRY_URL=$REGISTRY_URL \
  --env REGISTRY_TOKEN=$REGISTRY_TOKEN \
  --env SERVICE=ratings \
  --env SERVICE_VERSION=v1 \
  --env ENDPOINT_PORT=9080 \
  ${BLUEMIX_REGISTRY_HOST}/${BLUEMIX_REGISTRY_NAMESPACE}/${RATINGS_IMAGE}:v1

#################################################################################
# Start the reviews microservice instances
#################################################################################

echo "Starting bookinfo reviews microservice (v1)"

cf ic group create --name bookinfo_reviews1 \
  --publish 9080 --memory 256 --auto \
  --min 1 --max 2 --desired 1 \
  --env CONTROLLER_URL=$CONTROLLER_URL \
  --env TENANT_ID=$CONTROLLER_TENANT_ID \
  --env TENANT_TOKEN=$CONTROLLER_TENANT_TOKEN \
  --env REGISTRY_URL=$REGISTRY_URL \
  --env REGISTRY_TOKEN=$REGISTRY_TOKEN \
  --env SERVICE=reviews \
  --env SERVICE_VERSION=v1 \
  --env ENDPOINT_PORT=9080 \
  --env LOG=false \
  ${BLUEMIX_REGISTRY_HOST}/${BLUEMIX_REGISTRY_NAMESPACE}/${REVIEWS_IMAGE}:v1

echo "Starting bookinfo reviews microservice (v2)"

cf ic group create --name bookinfo_reviews2 \
  --publish 9080 --memory 256 --auto \
  --min 1 --max 2 --desired 1 \
  --env CONTROLLER_URL=$CONTROLLER_URL \
  --env TENANT_ID=$CONTROLLER_TENANT_ID \
  --env TENANT_TOKEN=$CONTROLLER_TENANT_TOKEN \
  --env REGISTRY_URL=$REGISTRY_URL \
  --env REGISTRY_TOKEN=$REGISTRY_TOKEN \
  --env SERVICE=reviews \
  --env SERVICE_VERSION=v2 \
  --env ENDPOINT_PORT=9080 \
  --env LOG=false \
  ${BLUEMIX_REGISTRY_HOST}/${BLUEMIX_REGISTRY_NAMESPACE}/${REVIEWS_IMAGE}:v2

echo "Starting bookinfo reviews microservice (v3)"

cf ic group create --name bookinfo_reviews3 \
  --publish 9080 --memory 256 --auto \
  --min 1 --max 2 --desired 1 \
  --env CONTROLLER_URL=$CONTROLLER_URL \
  --env TENANT_ID=$CONTROLLER_TENANT_ID \
  --env TENANT_TOKEN=$CONTROLLER_TENANT_TOKEN \
  --env REGISTRY_URL=$REGISTRY_URL \
  --env REGISTRY_TOKEN=$REGISTRY_TOKEN \
  --env SERVICE=reviews \
  --env SERVICE_VERSION=v3 \
  --env ENDPOINT_PORT=9080 \
  --env LOG=false \
  ${BLUEMIX_REGISTRY_HOST}/${BLUEMIX_REGISTRY_NAMESPACE}/${REVIEWS_IMAGE}:v3

#################################################################################
# Start the gateway
#################################################################################

echo "Starting bookinfo gateway"

cf ic group create --name bookinfo_gateway \
  --publish 6379 --memory 256 --auto \
  --min 1 --max 2 --desired 1 \
  --env CONTROLLER_URL=$CONTROLLER_URL \
  --env TENANT_TOKEN=12345 \
  --env TENANT_ID=local \
  --env SERVICE=gateway \
  --env SERVICE_VERSION=v1 \
  --env LOG=false \
  --env REGISTER=false \
  ${BLUEMIX_REGISTRY_HOST}/${BLUEMIX_REGISTRY_NAMESPACE}/$GATEWAY_IMAGE

echo "Waiting for gateway to start..."
sleep 15s

echo "Mapping route to gateway: $BOOKINFO_URL"
cf ic route map --hostname $BOOKINFO_HOSTNAME --domain $ROUTES_DOMAIN bookinfo_gateway


Added av alias

Added av alias

# THIS FILE IS UNDER VERSION CONTROL.  MAKE CHANGES IN YOUR REPO!!!!! #
#*********************************************************************#
#!/usr/bin/env bash

# Alias aws-vault
alias av='aws-vault'

error: pathspec '.functions/aws.sh' did not match any file(s) known to git


update travis deploy script

update travis deploy script

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/santaswap/ui.git/'


moves PP script config to nzbToMedia script

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/chrisanthropic/PlexInTheCloud.git/'


feat(dev-extras): add dev-extras module

feat(dev-extras): add dev-extras module

if [ "$1" = macos ]; then
  brew list jq >/dev/null || brew install jq
elif [ "$1" = alpine ]; then
  type jq >/dev/null || apk add jq
fi

error: pathspec 'modules/dev-extras/install.sh' did not match any file(s) known to git


* dist.sh: use /tmp when TMPDIR isn't set.

#!/bin/sh

REPOS="http://serf.googlecode.com/svn/"

if test $# != 2; then
  echo "USAGE: $0 TAG APR-SOURCE-PARENT"
  exit 1
fi

version=$1
srcdir=$2

release="serf-${version}"

work="${TMPDIR-/tmp}/serf-dist.$$"
short='${TMPDIR}'/serf-dist.$$

echo "Preparing ${release} in ${short} ..."

mkdir "${work}"
cd "${work}"

echo "Exporting latest serf ..."
svn export --quiet "${REPOS}/tags/${version}" "${release}" || exit 1
echo "`find ${release} -type f | wc -l` files exported"

cd "${release}"

if ! ./buildconf --with-apr="${srcdir}/apr" --with-apr-util="${srcdir}/apr-util" ; then
  echo "Exiting..."
  exit 1
fi

# Remove anything that should not be in the distribution
echo "Removing from release: dist.sh"
rm dist.sh

major="`sed -n '/SERF_MAJOR_VERSION/s/[^0-9]*//p' serf.h`"
minor="`sed -n '/SERF_MINOR_VERSION/s/[^0-9]*//p' serf.h`"
patch="`sed -n '/SERF_PATCH_VERSION/s/[^0-9]*//p' serf.h`"

actual_version="${major}.${minor}.${patch}"

cd $work

if test "${version}" != "${actual_version}"; then
  echo "ERROR: exported version does not match"
  exit 1
fi

tarball="${work}/${release}.tar"
tar -cf "${tarball}" "${release}"

bzip2 --keep "${tarball}"
echo "${short}/${release}.tar.bz2 ready."

gzip -9 "${tarball}"
echo "${short}/${release}.tar.gz ready."

#!/bin/sh

REPOS="http://serf.googlecode.com/svn/"

if test $# != 2; then
  echo "USAGE: $0 TAG APR-SOURCE-PARENT"
  exit 1
fi

version=$1
srcdir=$2

release="serf-${version}"

work="${TMPDIR}/serf-dist.$$"
short='${TMPDIR}'/serf-dist.$$

echo "Preparing ${release} in ${short} ..."

mkdir "${work}"
cd "${work}"

echo "Exporting latest serf ..."
svn export --quiet "${REPOS}/tags/${version}" "${release}" || exit 1
echo "`find ${release} -type f | wc -l` files exported"

cd "${release}"

if ! ./buildconf --with-apr="${srcdir}/apr" --with-apr-util="${srcdir}/apr-util" ; then
  echo "Exiting..."
  exit 1
fi

# Remove anything that should not be in the distribution
echo "Removing from release: dist.sh"
rm dist.sh

major="`sed -n '/SERF_MAJOR_VERSION/s/[^0-9]*//p' serf.h`"
minor="`sed -n '/SERF_MINOR_VERSION/s/[^0-9]*//p' serf.h`"
patch="`sed -n '/SERF_PATCH_VERSION/s/[^0-9]*//p' serf.h`"

actual_version="${major}.${minor}.${patch}"

cd $work

if test "${version}" != "${actual_version}"; then
  echo "ERROR: exported version does not match"
  exit 1
fi

tarball="${work}/${release}.tar"
tar -cf "${tarball}" "${release}"

bzip2 --keep "${tarball}"
echo "${short}/${release}.tar.bz2 ready."

gzip -9 "${tarball}"
echo "${short}/${release}.tar.gz ready."


Use same logic to prepare rootfs across dotnet if possible

1. Update logic more safely for unmount and cleaning directory
2. Refactor logic to achieve consistency across dotnet
3. Remove unused variable and fix typo

Signed-off-by: Hyung-Kyu Choi <b24f6a1d8ab6a697998e8a2c60eb031a02db5070@samsung.com>

#!/usr/bin/env bash

usage()
{
    echo "Usage: $0 [BuildArch] [LinuxCodeName] [--skipunmount]"
    echo "BuildArch can be: arm(default), armel, arm64, x86"
    echo "LinuxCodeName - optional, Code name for Linux, can be: trusty(default), vivid, wily, xenial. If BuildArch is armel, LinuxCodeName is jessie(default) or tizen."
    echo "--skipunmount - optional, will skip the unmount of rootfs folder."
    exit 1
}

__LinuxCodeName=trusty
__CrossDir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
__InitialDir=$PWD
__BuildArch=arm
__UbuntuArch=armhf
__UbuntuRepo="http://ports.ubuntu.com/"
__LLDB_Package="lldb-3.6-dev"
__SkipUnmount=0

# base development support
__UbuntuPackages="build-essential"

# symlinks fixer
__UbuntuPackages+=" symlinks"

# CoreCLR and CoreFX dependencies
__UbuntuPackages+=" gettext"
__UbuntuPackages+=" libunwind8-dev"
__UbuntuPackages+=" liblttng-ust-dev"
__UbuntuPackages+=" libicu-dev"

# CoreFX dependencies
__UbuntuPackages+=" libcurl4-openssl-dev"
__UbuntuPackages+=" libkrb5-dev"
__UbuntuPackages+=" libssl-dev"
__UbuntuPackages+=" zlib1g-dev"

__UnprocessedBuildArgs=
for i in "$@" ; do
    lowerI="$(echo $i | awk '{print tolower($0)}')"
    case $lowerI in
        -?|-h|--help)
            usage
            exit 1
            ;;
        arm)
            __BuildArch=arm
            __UbuntuArch=armhf
            ;;
        arm64)
            __BuildArch=arm64
            __UbuntuArch=arm64
            ;;
        armel)
            __BuildArch=armel
            __UbuntuArch=armel
            __UbuntuRepo="http://ftp.debian.org/debian/"
            __LinuxCodeName=jessie
            ;;
        x86)
            __BuildArch=x86
            __UbuntuArch=i386
            __UbuntuRepo="http://archive.ubuntu.com/ubuntu/"
            ;;
        vivid)
            if [ "$__LinuxCodeName" != "jessie" ]; then
                __LinuxCodeName=vivid
            fi
            ;;
        wily)
            if [ "$__LinuxCodeName" != "jessie" ]; then
                __LinuxCodeName=wily
            fi
            ;;
        xenial)
            if [ "$__LinuxCodeName" != "jessie" ]; then
                __LinuxCodeName=xenial
            fi
            ;;
        jessie)
            __LinuxCodeName=jessie
            __UbuntuRepo="http://ftp.debian.org/debian/"
            ;;
        tizen)
            if [ "$__BuildArch" != "armel" ]; then
                echo "Tizen is available only for armel."
                usage;
                exit 1;
            fi
            __LinuxCodeName=
            __UbuntuRepo=
            __Tizen=tizen
            ;;
        --skipunmount)
            __SkipUnmount=1
            ;;
        *)
            __UnprocessedBuildArgs="$__UnprocessedBuildArgs $i"
            ;;
    esac
done

if [[ "$__BuildArch" == "arm" ]]; then
    __UbuntuPackages+=" ${__LLDB_Package:-}"
fi

if [ "$__BuildArch" == "armel" ]; then
    __LLDB_Package="lldb-3.5-dev"
    __UbuntuPackages+=" ${__LLDB_Package:-}"
fi

__RootfsDir="$__CrossDir/rootfs/$__BuildArch"

if [[ -n "$ROOTFS_DIR" ]]; then
    __RootfsDir=$ROOTFS_DIR
fi

if [ -d "$__RootfsDir" ]; then
    if [ $__SkipUnmount == 0 ]; then
        umount $__RootfsDir/*
    fi
    rm -rf $__RootfsDir
fi

if [[ -n $__LinuxCodeName ]]; then
    qemu-debootstrap --arch $__UbuntuArch $__LinuxCodeName $__RootfsDir $__UbuntuRepo
    cp $__CrossDir/$__BuildArch/sources.list.$__LinuxCodeName $__RootfsDir/etc/apt/sources.list
    chroot $__RootfsDir apt-get update
    chroot $__RootfsDir apt-get -f -y install
    chroot $__RootfsDir apt-get -y install $__UbuntuPackages
    chroot $__RootfsDir symlinks -cr /usr

    if [ $__SkipUnmount == 0 ]; then
        umount $__RootfsDir/*
    fi
elif [ "$__Tizen" == "tizen" ]; then
    ROOTFS_DIR=$__RootfsDir $__CrossDir/$__BuildArch/tizen-build-rootfs.sh
else
    echo "Unsupported target platform."
    usage;
    exit 1
fi

#!/usr/bin/env bash

usage()
{
    echo "Usage: $0 [BuildArch] [LinuxCodeName] [--SkipUnmount]"
    echo "BuildArch can be: arm, armel, arm64, x86"
    echo "LinuxCodeName - optional, Code name for Ubuntu, can be: trusty(default), vivid, wily, xenial. If BuildArch is armel, jessie(default) or tizen."
    echo "[--SkipUnmount] - do not unmount rootfs folders."
    exit 1
}

__CrossDir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
__InitialDir=$PWD

# base development support
__UbuntuPackages="build-essential"

# symlinks fixer
__UbuntuPackages+=" symlinks"

# CoreCLR and CoreFX dependencies
__UbuntuPackages+=" gettext"
__UbuntuPackages+=" libcurl4-openssl-dev"
__UbuntuPackages+=" libicu-dev"
__UbuntuPackages+=" libkrb5-dev"
__UbuntuPackages+=" liblttng-ust-dev"
__UbuntuPackages+=" libssl-dev"
__UbuntuPackages+=" libunwind8-dev"
__UbuntuPackages+=" zlib1g-dev"

if [ -z "$LLVM_ARM_HOME" ]; then
    __LLDB_Package="lldb-3.6-dev"
fi

__BuildArch=arm
__UbuntuArch=armhf
__LinuxCodeName=trusty
__UbuntuRepo="http://ports.ubuntu.com/"
__MachineTriple=arm-linux-gnueabihf
__SkipUnmount=0

__UnprocessedBuildArgs=
for i in "$@" ; do
    lowerI="$(echo $i | awk '{print tolower($0)}')"
    case $lowerI in
        -?|-h|--help)
            usage
            exit 1
            ;;
        --skipunmount)
            __SkipUnmount=1
            ;;
        arm)
            __BuildArch=arm
            __UbuntuArch=armhf
            __MachineTriple=arm-linux-gnueabihf
            ;;
        arm64)
            __BuildArch=arm64
            __UbuntuArch=arm64
            __MachineTriple=aarch64-linux-gnu
            ;;
        x86)
            __BuildArch=x86
            __UbuntuArch=i386
            __UbuntuRepo="http://archive.ubuntu.com/ubuntu"
            ;;
        armel)
            __BuildArch=armel
            __UbuntuArch=armel
            __UbuntuRepo="http://ftp.debian.org/debian/"
            __MachineTriple=arm-linux-gnueabi
            __LinuxCodeName=jessie
            ;;
        vivid)
            if [ "$__LinuxCodeName" != "jessie" ]; then
                __LinuxCodeName=vivid
            fi
            ;;
        wily)
            if [ "$__LinuxCodeName" != "jessie" ]; then
                __LinuxCodeName=wily
            fi
            ;;
        xenial)
            if [ "$__LinuxCodeName" != "jessie" ]; then
                __LinuxCodeName=xenial
            fi
            ;;
        jessie)
            __LinuxCodeName=jessie
            __UbuntuRepo="http://ftp.debian.org/debian/"
            ;;
        tizen)
            if [ "$__BuildArch" != "armel" ]; then
                echo "Tizen is available only for armel"
                usage;
                exit 1;
            fi
            __LinuxCodeName=
            __UbuntuRepo=
            __Tizen=tizen
            ;;
        *)
            __UnprocessedBuildArgs="$__UnprocessedBuildArgs $i"
            ;;
    esac
done

if [[ "$__BuildArch" == "arm" ]]; then
    __UbuntuPackages+=" ${__LLDB_Package:-}"
fi

if [ "$__BuildArch" == "armel" ]; then
    __LLDB_Package="lldb-3.5-dev"
    __UbuntuPackages+=" ${__LLDB_Package:-}"
fi

__RootfsDir="$__CrossDir/rootfs/$__BuildArch"

if [[ -n "$ROOTFS_DIR" ]]; then
    __RootfsDir=$ROOTFS_DIR
fi

if [ $__SkipUnmount == 0 ]; then
    umount $__RootfsDir/*
fi

rm -rf $__RootfsDir

if [[ -n $__LinuxCodeName ]]; then
    qemu-debootstrap --arch $__UbuntuArch $__LinuxCodeName $__RootfsDir $__UbuntuRepo
    cp $__CrossDir/$__BuildArch/sources.list.$__LinuxCodeName $__RootfsDir/etc/apt/sources.list
    chroot $__RootfsDir apt-get update
    chroot $__RootfsDir apt-get -f -y install
    chroot $__RootfsDir apt-get -y install $__UbuntuPackages
    chroot $__RootfsDir symlinks -cr /usr

    if [ $__SkipUnmount == 0 ]; then
        umount $__RootfsDir/*
    fi

elif [ "$__Tizen" == "tizen" ]; then
    ROOTFS_DIR=$__RootfsDir $__CrossDir/$__BuildArch/tizen-build-rootfs.sh
else
    echo "Unsupported target platform."
    usage;
    exit 1
fi


Smoke Test - Import Order

Smoke Test - Import Order

PiperOrigin-RevId: 418068216
Change-Id: I95b3fd781fa9e4158a41f397bf3c8278371fdcc3

#!/bin/bash
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
# Pip install TensorFlow and run basic test on the pip package.

set -e
set -x

# Get size check function
source tensorflow/tools/ci_build/release/common.sh

function run_smoke_test() {

  if [[ -z "${WHL_NAME}" ]]; then
    echo "TF WHL path not given, unable to install and test."
    exit 1
  fi

  # Upload the PIP package if whl test passes.
  if [ ${IN_VENV} -eq 0 ]; then
    VENV_TMP_DIR=$(mktemp -d)

    ${PYTHON_BIN_PATH} -m pip install virtualenv

    ${PYTHON_BIN_PATH} -m virtualenv -p ${PYTHON_BIN_PATH} "${VENV_TMP_DIR}" || \
        die "FAILED: Unable to create virtualenv"

    source "${VENV_TMP_DIR}/bin/activate" || \
        die "FAILED: Unable to activate virtualenv "
  fi

  # install tensorflow
  python -m pip install ${WHL_NAME} || \
      die "pip install (forcing to reinstall tensorflow) FAILED"
      echo "Successfully installed pip package ${WHL_NAME}"

  # Test TensorflowFlow imports
  test_tf_imports

  # Test TensorFlow whl file size
  test_tf_whl_size ${WHL_NAME}

  RESULT=$?

  # Upload the PIP package if whl test passes.
  if [ ${IN_VENV} -eq 0 ]; then
    # Deactivate from virtualenv.
    deactivate || source deactivate || die "FAILED: Unable to deactivate from existing virtualenv."
    sudo rm -rf "${KOKORO_GFILE_DIR}/venv"
  fi

  return $RESULT
}

function test_tf_imports() {
  TMP_DIR=$(mktemp -d)
  pushd "${TMP_DIR}"

  # test for basic import and perform tf.add operation.
  RET_VAL=$(python -c "import tensorflow as tf; t1=tf.constant([1,2,3,4]); t2=tf.constant([5,6,7,8]); print(tf.add(t1,t2).shape)")
  if ! [[ ${RET_VAL} == *'(4,)'* ]]; then
    echo "Unexpected return value: ${RET_VALUE}"
    echo "PIP test on virtualenv FAILED, will not upload ${WHL_NAME} package."
     return 1
  fi

  # test basic keras is available
  RET_VAL=$(python -c "import tensorflow as tf; print(tf.keras.__name__)")
  if ! [[ ${RET_VAL} == *'keras.api'* ]]; then
    echo "Unexpected return value: ${RET_VALUE}"
    echo "PIP test on virtualenv FAILED, will not upload ${WHL_NAME} package."
    return 1
  fi

  # similar test for estimator
  RET_VAL=$(python -c "import tensorflow as tf; print(tf.estimator.__name__)")
  if ! [[ ${RET_VAL} == *'tensorflow_estimator.python.estimator.api._v2.estimator'* ]]; then
    echo "Unexpected return value: ${RET_VALUE}"
    echo "PIP test on virtualenv FAILED, will not upload ${WHL_NAME} package."
    return 1
  fi

  RESULT=$?

  # TODO(b/210940071): Debug import order. Ignore returned errors.
  set +e
  python -m pip install google-cloud-bigquery
  $(python -c "from google.cloud.bigquery_v2 import types; import tensorflow")
  $(python -c "import tensorflow; from google.cloud.bigquery_v2 import types")
  set -e

  popd
  return $RESULT
}

###########################################################################
# Main
###########################################################################

IN_VENV=$(python -c 'import sys; print("1" if sys.version_info.major == 3 and sys.prefix != sys.base_prefix else "0")')
WHL_NAME=${1}
run_smoke_test

#!/bin/bash
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
# Pip install TensorFlow and run basic test on the pip package.

set -e
set -x

# Get size check function
source tensorflow/tools/ci_build/release/common.sh

function run_smoke_test() {

  if [[ -z "${WHL_NAME}" ]]; then
    echo "TF WHL path not given, unable to install and test."
    exit 1
  fi

  # Upload the PIP package if whl test passes.
  if [ ${IN_VENV} -eq 0 ]; then
    VENV_TMP_DIR=$(mktemp -d)

    ${PYTHON_BIN_PATH} -m pip install virtualenv

    ${PYTHON_BIN_PATH} -m virtualenv -p ${PYTHON_BIN_PATH} "${VENV_TMP_DIR}" || \
        die "FAILED: Unable to create virtualenv"

    source "${VENV_TMP_DIR}/bin/activate" || \
        die "FAILED: Unable to activate virtualenv "
  fi

  # install tensorflow
  python -m pip install ${WHL_NAME} || \
      die "pip install (forcing to reinstall tensorflow) FAILED"
      echo "Successfully installed pip package ${WHL_NAME}"

  # Test TensorflowFlow imports
  test_tf_imports

  # Test TensorFlow whl file size
  test_tf_whl_size ${WHL_NAME}

  RESULT=$?

  # TODO(b/210940071): Debug import order. Ignore returned errors.
  set +e
  python -m pip install google-cloud-bigquery
  $(python -c "from google.cloud.bigquery_v2 import types; import tensorflow")
  $(python -c "import tensorflow; from google.cloud.bigquery_v2 import types")
  set -e

  # Upload the PIP package if whl test passes.
  if [ ${IN_VENV} -eq 0 ]; then
    # Deactivate from virtualenv.
    deactivate || source deactivate || die "FAILED: Unable to deactivate from existing virtualenv."
    sudo rm -rf "${KOKORO_GFILE_DIR}/venv"
  fi

  return $RESULT
}

function test_tf_imports() {
  TMP_DIR=$(mktemp -d)
  pushd "${TMP_DIR}"

  # test for basic import and perform tf.add operation.
  RET_VAL=$(python -c "import tensorflow as tf; t1=tf.constant([1,2,3,4]); t2=tf.constant([5,6,7,8]); print(tf.add(t1,t2).shape)")
  if ! [[ ${RET_VAL} == *'(4,)'* ]]; then
    echo "Unexpected return value: ${RET_VALUE}"
    echo "PIP test on virtualenv FAILED, will not upload ${WHL_NAME} package."
     return 1
  fi

  # test basic keras is available
  RET_VAL=$(python -c "import tensorflow as tf; print(tf.keras.__name__)")
  if ! [[ ${RET_VAL} == *'keras.api'* ]]; then
    echo "Unexpected return value: ${RET_VALUE}"
    echo "PIP test on virtualenv FAILED, will not upload ${WHL_NAME} package."
    return 1
  fi

  # similar test for estimator
  RET_VAL=$(python -c "import tensorflow as tf; print(tf.estimator.__name__)")
  if ! [[ ${RET_VAL} == *'tensorflow_estimator.python.estimator.api._v2.estimator'* ]]; then
    echo "Unexpected return value: ${RET_VALUE}"
    echo "PIP test on virtualenv FAILED, will not upload ${WHL_NAME} package."
    return 1
  fi

  RESULT=$?

  popd
  return $RESULT
}

###########################################################################
# Main
###########################################################################

IN_VENV=$(python -c 'import sys; print("1" if sys.version_info.major == 3 and sys.prefix != sys.base_prefix else "0")')
WHL_NAME=${1}
run_smoke_test


Update RingOpenGL 4.1 - Build script for MacOS X

clang -c -fpic ring_opengl41.c -I $PWD/../../../include -I /usr/local/include
clang -dynamiclib -o $PWD/../../../lib/libring_opengl41.dylib ring_opengl41.o /usr/local/lib/libglew.dylib -framework OpenGL -framework GLUT -L $PWD/../../../lib  -lring

error: pathspec 'extensions/ringopengl/opengl41/buildclang.sh' did not match any file(s) known to git


Added ans, fixed the rep counter, fixed endless repeat

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/t-16x/Linux-Scripts.git/'


Create dots.sh

Create dots.sh

echo -n "."
sleep 0.5
echo -n "."
sleep 0.5
echo "."
sleep 0.5

error: pathspec 'dots.sh' did not match any file(s) known to git


add candidate into local repository

add candidate into local repository

#!/bin/bash

#
#   Copyright 2012 Jacky Chan
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
#

# add candidate into local repository
# @param $1 candidate name
# @param $2 candidate version
function __jenvtool_add {
	CANDIDATE=`echo "$1" | tr '[:upper:]' '[:lower:]'`
	mkdir -p "${JENV_DIR}/repo/local"
	# update candidates file to add candidate
	candidates_file="${JENV_DIR}/repo/local/candidates"
	if [ -f "${candidates_file}" ]; then
	   CANDIDATES=($(cat "${candidates_file}"))
	   if [[ ${#CANDIDATES[@]} == 0 ]]; then  # empty file
	       echo -n "${CANDIDATE}" > "${candidates_file}"
	   else
	      if ! __jenvtool_array_contains CANDIDATES[@] "${CANDIDATE}"; then
	      	  echo -n " ${CANDIDATE}" >> "${candidates_file}"
	      fi
	   fi
	   unset CANDIDATES
	else
	   echo -n "${CANDIDATE}" > "${candidates_file}"
	fi
	unset candidates_file
	# add version
	if [[ ! -z "$2" ]] ; then
        mkdir -p "${JENV_DIR}/repo/local/version"
        version_file="${JENV_DIR}/repo/local/version/${CANDIDATE}.txt"
        if [ -f "${version_file}" ]; then
           VERSIONS=($(cat "${version_file}"))
           if [[ ${#VERSIONS[@]} == 0 ]]; then  # empty file
              echo -n "$2" > "${version_file}"
           else
              # append version
              if ! __jenvtool_array_contains VERSIONS[@] "$2"; then
                 echo -n " $2" >> "${version_file}"
              fi
           fi
           unset VERSIONS
        else
          echo -n "$2" > "${version_file}"
        fi
        unset version_file
	fi
}

error: pathspec 'src/main/scripts/commands/jenv-add.sh' did not match any file(s) known to git


Create erep.sh

Create erep.sh

#!/bin/sh

EVAL_FILE=/opt/docker/eval.conf

if [ ! -d $ENAME ]; then
  sed -i 's/EmailAuthUsername = \"juliatest38\"/EmailAuthUsername = \"'$ENAME'\"/' $EVAL_FILE
fi

if [ ! -d $EPASS ]; then
  sed -i 's/EmailAuthPassword = \"juliatestjuliatest\"/EmailAuthPassword = \"'$EPASS'\"/' $EVAL_FILE
fi

if [ ! -d $EADDR ]; then
  sed -i 's/EmailFromAddress = \"juliatest38@gmail.com\"/EmailFromAddress = \"'$EADDR'\"/' $EVAL_FILE
fi

error: pathspec 'erep.sh' did not match any file(s) known to git


initial checkin

initial checkin

#!/bin/sh
#
# cmsshell.sh 2001/02/21 Alexander Lucas, Framfab Deutschland AG
#
# Start script for the OpenCms Shell
# Version 1.3

JAVA_HOME=/usr/local/java
EXTCOMPPATH=./lib
JARS="mysql xerces"
PRE_CLASSPATH=""

echo " "
echo "Starting OpenCms shell..."
echo " "

# Check which java version we are running
if [ -f $JAVA_HOME/lib/classes.zip ]; then
  # We are running Java 1, so we have to add the classes.zip to our classpath
  echo "Java 1.1 VM detected."
  JAVA_CLASSPATH=$JAVA_HOME/lib/classes.zip
else
  echo "Java 1.2 VM or higher detected."
  JAVA_CLASSPATH=""
fi

if [ -e opencms.jar ]; then
    echo opencms.jar found. Using it for setting the CLASSPATH.
    CLASSPATH=opencms.jar
else
    CLASSPATH=.
fi

if [ "$PRE_CLASSPATH" != "" ]; then
  CLASSPATH="$PRE_CLASSPATH:$CLASSPATH"
fi

if [ "$JAVA_CLASSPATH" != "" ]; then
  CLASSPATH="$JAVA_CLASSPATH:$CLASSPATH"
fi

CLASSPATH=$PRE_CLASSPATH:$CMSPATH
for jar in $JARS; do
    if [ -e $EXTCOMPPATH/$jar ]; then
        CLASSPATH=$CLASSPATH:$EXTCOMPPATH/$jar
    else
        # external component could not be found. try appending ".jar"
        if [ -e $EXTCOMPPATH/$jar.jar ]; then
            CLASSPATH=$CLASSPATH:$EXTCOMPPATH/$jar.jar
        else
            # The jar file could not be found. Try a zip file
            if [ -e $EXTCOMPPATH/$jar.zip ]; then
                CLASSPATH=$CLASSPATH:$EXTCOMPPATH/$jar.zip
            else
                echo External component $jar could not be found.
            fi
        fi
    fi
done

echo Using Classpath:
echo $CLASSPATH
echo " "

$JAVA_HOME/bin/java -mx256M -classpath $CLASSPATH com.opencms.core.CmsShell config/opencms.properties

error: pathspec 'etc/cmsshell.sh' did not match any file(s) known to git


Add init script

Add init script

#!/bin/sh
pyvenv venv
. venv/bin/activate
pip install -r requirements.txt
./manage.py migrate

error: pathspec 'init.sh' did not match any file(s) known to git


Create init.sh

Create init.sh

cd ~
git clone https://github.com/magicmonty/bash-git-prompt.git .bash-git-prompt


custumScript

custumScript

# Custom Script for Linux
apt-get update
sudo apt-get install apt-transport-https ca-certificates
apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" | sudo tee /etc/apt/sources.list.d/docker.list
apt-get update
apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual
apt-get update
apt-get install docker-engine
service docker start
systemctl enable docker
docker swarm init
docker service create --name=viz --publish=8080:8080/tcp --constraint=node.role==manager --mount=type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock manomarks/visualizer

error: pathspec 'ARMTemplate/ARMTemplate/CustomScripts/masterCustomScriptInit.sh' did not match any file(s) known to git


rename to radiasoft/radtrack and remove old box

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/radiasoft/radtrack-installer.git/'


ops: if typo

ops: if typo

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/khipu/dockerfiles.git/'