1#!/bin/bash 2 3# Copyright 2022 Google LLC 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16################################################################################ 17 18# This scripts installs Tink for Python and its dependencies using Pip. 19# Tink's root folder must be specified. 20# 21# NOTE: If not running on Kokoro, this script will do nothing. 22 23set -eo pipefail 24 25usage() { 26 cat <<EOF 27Usage: $0 <path to tink python root> <tink python deps dir> 28 -h: Help. Print this usage information. 29EOF 30 exit 1 31} 32 33TINK_PY_ROOT_DIR= 34TINK_PY_DEPS_BASE_DIR= 35 36####################################### 37# Process command line arguments. 38####################################### 39process_args() { 40 # Parse options. 41 while getopts "h" opt; do 42 case "${opt}" in 43 *) usage ;; 44 esac 45 done 46 shift $((OPTIND - 1)) 47 TINK_PY_ROOT_DIR="$1" 48 if [[ -z "${TINK_PY_ROOT_DIR}" ]]; then 49 echo "ERROR: The root folder of Tink Python must be specified" >&2 50 usage 51 fi 52 TINK_PY_DEPS_BASE_DIR="$2" 53 if [[ -z "${TINK_PY_DEPS_BASE_DIR}" ]]; then 54 echo "ERROR: The folder containing Tink Python's dependencies must be \ 55specified" >&2 56 usage 57 fi 58 readonly TINK_PY_ROOT_DIR 59 readonly TINK_PY_DEPS_BASE_DIR 60} 61 62 63main() { 64 process_args "$@" 65 if [[ -z "${KOKORO_ROOT:-}" ]] ; then 66 echo "Not running on Kokoro, skip installing tink-py" 67 return 68 fi 69 ( 70 cd "${TINK_PY_ROOT_DIR}" 71 local -r platform="$(uname | tr '[:upper:]' '[:lower:]')" 72 local -a pip_flags 73 if [[ "${platform}" == 'darwin' ]]; then 74 # On MacOS we need to use the --user flag as otherwise pip will complain 75 # about permissions. 76 pip_flags=( --user ) 77 fi 78 readonly pip_flags 79 80 # Set base path to the Tink Python's dependencies. 81 export TINK_PYTHON_SETUPTOOLS_OVERRIDE_BASE_PATH="${TINK_PY_DEPS_BASE_DIR}" 82 pip3 install "${pip_flags[@]}" --upgrade pip setuptools 83 # Install Tink Python requirements. 84 pip3 install "${pip_flags[@]}" --require-hashes -r requirements.txt 85 # Install Tink Python 86 pip3 install "${pip_flags[@]}" . 87 ) 88} 89 90main "$@" 91