Last active
August 6, 2021 16:57
-
-
Save anupash147/5567db2f807a1ee7839efd50acd1b930 to your computer and use it in GitHub Desktop.
Used to setup up the python requisit pypi permission in a machine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
usage(){ | |
echo "Usage:" | |
echo "----------------------------------------------------------------------------------------" | |
echo " -s Setup up" | |
echo " -u/--user Provide your bayer user-email" | |
echo " -p/--passkey Provide the API KEY generated" | |
echo " -r/--repo Provide the default repository within your organization url" | |
echo " -o/--organization Provide the organization url example : https://artifactory.github.com" | |
echo "----------------------------------------------------------------------------------------" | |
exit 0 | |
} | |
make_pypirc() { | |
user=$1 | |
apikey=$2 | |
repo=$3 | |
org=$4 | |
if [[ -f ~/.pypirc ]]; then mv ~/.pypirc ~/.pypirc.bak ;fi | |
cat <<EOF >~/.pypirc | |
[distutils] | |
index-servers = artifactory | |
[artifactory] | |
repository = ${org}/artifactory/api/pypi/${repo} | |
username = ${user} | |
password = ${apikey} | |
EOF | |
echo "----------------------------------------------------------------------------------------" | |
echo "Pypirc setup completed. Below are the files" | |
ls -ltrh ~/.pypirc* | |
} | |
set_pip_global() { | |
user=$1 | |
apikey=$2 | |
repo=$3 | |
org=$4 | |
[ -d ~/.pip ] || mkdir ~/.pip | |
if [[ -f ~/.pip/pip.conf ]]; then mv ~/.pip/pip.conf ~/.pip/pip.conf.bak ;fi | |
org=$(echo ${org} |cut -d/ -f 3) | |
cat <<EOF >~/.pip/pip.conf | |
[global] | |
extra-index-url = https://${user}:${apikey}@${org}/artifactory/api/pypi/${repo}/simple | |
EOF | |
echo "----------------------------------------------------------------------------------------" | |
echo "pip Global config set. Below are the files" | |
ls -ltrh ~/.pip/* | |
} | |
make_selection() { | |
POSITIONAL=() | |
if [[ $# -le 0 ]]; then | |
usage | |
fi | |
while [[ $# -gt 0 ]] | |
do | |
key="$1" | |
case $key in | |
-h|--help) | |
usage | |
shift # past argument | |
shift # past value | |
;; | |
-u|--user) | |
USER=$2 | |
shift # past argument | |
shift # past value | |
;; | |
-p|--passkey) | |
PASSKEY=$2 | |
shift # past argument | |
shift # past value | |
;; | |
-r|--repo) | |
REPO=$2 | |
shift # past argument | |
shift # past value | |
;; | |
-o|--organization) | |
ORG=$2 | |
shift # past argument | |
shift # past value | |
;; | |
*) # unknown option | |
POSITIONAL+=("$1") # save it in an array for later | |
echo "wrong option !!!" | |
usage | |
shift # past argument | |
;; | |
esac | |
done | |
set -- "${POSITIONAL[@]}" # restore positional parameters | |
} | |
################################################################################ | |
# | |
# Main | |
# | |
################################################################################ | |
make_selection "$@" | |
if [[ -z "${USER}" || -z "${PASSKEY}" || -z "${REPO}" || -z "${ORG}" ]] | |
then | |
echo "${USER}" "${PASSKEY}" "${REPO}" $ORG | |
printf " | |
===================== | |
ERROR | |
===================== | |
" | |
usage | |
fi | |
make_pypirc ${USER} ${PASSKEY} ${REPO} ${ORG} | |
set_pip_global ${USER} ${PASSKEY} ${REPO} ${ORG} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment