|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -e -o xtrace |
| 4 | + |
| 5 | + |
| 6 | +append_package_details_to_final_license_file(){ |
| 7 | + # Function to Append Package Details to the THIRD-PARTY-LICENSES file |
| 8 | + #Arguments -> 1- Package Name, 2- Package Version, 3- License Type , 4- URL for package, 5,6,7- URL for License |
| 9 | + # Adding a header to final License file with Package Name, Package Version, License Type , URL for package |
| 10 | + echo -e "\n\n\n$1 \n$2 \n$3 \n$4" >> $final_license_file |
| 11 | + # Appending License |
| 12 | + curl $5 >> $final_license_file |
| 13 | + # Adding Dual Licenses if they exist |
| 14 | + if [ $# -gt 5 ] |
| 15 | + then |
| 16 | + curl $6 >> $final_license_file |
| 17 | + curl $7 >> $final_license_file |
| 18 | + fi |
| 19 | + |
| 20 | +} |
| 21 | + |
| 22 | +function create_attribution_doc() { |
| 23 | + ATTR_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" |
| 24 | + |
| 25 | + # Install the python version if it doesnt exist |
| 26 | + if test ! -d ${PYENV_ROOT}/versions/${PYTHON_VERSION}; |
| 27 | + then |
| 28 | + env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install ${PYTHON_VERSION} |
| 29 | + fi |
| 30 | + |
| 31 | + pyenv virtualenv ${PYTHON_VERSION} attribution-doc-env |
| 32 | + # switch to a specific virtual env |
| 33 | + source ${PYENV_ROOT}/versions/attribution-doc-env/bin/activate |
| 34 | + |
| 35 | + # Update Pip |
| 36 | + pip3 install --upgrade pip |
| 37 | + |
| 38 | + # Installing PyInstaller |
| 39 | + pip3 install pyinstaller |
| 40 | + # Install pip-licenses |
| 41 | + pip3 install pip-licenses |
| 42 | + |
| 43 | + # install via source |
| 44 | + pip3 install -e "$(dirname $ATTR_SCRIPT_DIR )" |
| 45 | + |
| 46 | + final_license_file=$(dirname $ATTR_SCRIPT_DIR )/THIRD-PARTY-LICENSES.txt |
| 47 | + |
| 48 | + # Create a pip License document |
| 49 | + pip-licenses -i aws-parallelcluster-node pip-licenses --format=plain-vertical --with-license-file --with-urls --no-license-path --with-authors --output-file=$final_license_file |
| 50 | + |
| 51 | + #Getting python version |
| 52 | + cpy_version=$(python -V | grep -Eo '([0-9]+)(\.?[0-9]+)' | head -1) |
| 53 | + |
| 54 | + # Python |
| 55 | + append_package_details_to_final_license_file "Python" $cpy_version "PSF License Version 2; Zero-Clause BSD license" "https://raw.githubusercontent.com/python/cpython/$cpy_version/LICENSE" "https://raw.githubusercontent.com/python/cpython/$cpy_version/LICENSE" |
| 56 | + |
| 57 | + |
| 58 | + deactivate |
| 59 | + pyenv virtualenv-delete -f attribution-doc-env |
| 60 | + |
| 61 | +} |
| 62 | + |
| 63 | + |
| 64 | +_error_exit() { |
| 65 | + echo "$1" |
| 66 | + exit 1 |
| 67 | +} |
| 68 | + |
| 69 | +_help() { |
| 70 | + local -- _cmd |
| 71 | + _cmd=$(basename "$0") |
| 72 | + |
| 73 | + cat <<EOF |
| 74 | + This script will create the THIRD_PARTY_LICENSE.txt file assuming you have already installed Pyenv |
| 75 | + Usage: ${_cmd} [OPTION]... |
| 76 | +
|
| 77 | +
|
| 78 | + --python-version <version> Python version with which you want to create the attribution document. |
| 79 | + -h, --help Print this help message |
| 80 | + |
| 81 | + Examples: |
| 82 | + ${_cmd} |
| 83 | + $_cmd --python-version 3.9.10 |
| 84 | +EOF |
| 85 | +} |
| 86 | + |
| 87 | +function parse_options () { |
| 88 | + |
| 89 | + while [ $# -gt 0 ] ; do |
| 90 | + case "$1" in |
| 91 | + --python-version) PYTHON_VERSION="$2"; shift;; |
| 92 | + -h|--help|help) _help; exit 0;; |
| 93 | + *) _help; _error_exit "[error] Unrecognized option '$1'";; |
| 94 | + esac |
| 95 | + shift |
| 96 | + done |
| 97 | + |
| 98 | +} |
| 99 | + |
| 100 | +function main() { |
| 101 | + parse_options "$@" |
| 102 | + create_attribution_doc |
| 103 | +} |
| 104 | + |
| 105 | +main "$@" |
0 commit comments