Created
August 21, 2019 21:45
-
-
Save rcarrata/c26300263e7691ed4ead2c52846b76e4 to your computer and use it in GitHub Desktop.
OCP4 Automatic Installer Script
This file contains 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
#!/bin/bash | |
# Small Script for install IPI OCP4 automatically | |
set -e | |
set -o pipefail | |
usage() { | |
echo "Usage: $0 [ -a aws_secret_key_id ] [ -s aws_secret_access_key ] [ -o ocp_version ] [ -r aws_region ]" 1>&2 | |
} | |
# Set default ops | |
aws_region="eu-central-1" | |
aws_bin="/usr/bin/aws" | |
while getopts 'a:s:o:r:' options; do | |
case "${options}" in | |
a) | |
aws_secret_key_id="${OPTARG}" | |
;; | |
s) | |
aws_secret_access_key="${OPTARG}" | |
;; | |
o) | |
ocp4_version="${OPTARG}" | |
#echo "The value provided is $OPTARG" | |
;; | |
r) | |
aws_region="${OPTARG}" | |
#echo "The value provided is $OPTARG" | |
;; | |
:) | |
usage | |
exit 1 | |
;; | |
esac | |
done | |
shift "$(($OPTIND -1))" | |
# Error handler if the input have not any vars | |
if [[ "$aws_secret_access_key" = "" ]]; then | |
echo "Error! Insert Secret Access Key" | |
usage | |
exit; | |
elif [[ "$aws_secret_key_id" = "" ]]; then | |
echo "Error! Insert Access Key Id" | |
usage | |
exit; | |
fi | |
echo "### Welcome to autoinstall OCP4" | |
echo "###" | |
echo "### OCP4 Cluster:" | |
echo "### aws_secret_access_key: $aws_secret_access_key" | |
echo "### aws_secret_key_id: $aws_secret_key_id" | |
echo "### aws_region: $aws_region" | |
echo "### Prereqs..." | |
if [ -f "$aws_bin" ]; then | |
echo "### AWS already installed. Skipping!" | |
else | |
echo "### Installing AWS CLI" | |
curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip" | |
unzip awscli-bundle.zip | |
./awscli-bundle/install -i /usr/local/aws -b /bin/aws | |
aws --version | |
rm -rf awscli-bundle | |
rm -rf awscli-bundle.zip | |
fi | |
echo "### Installing Openshift binaries" | |
wget https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest/openshift-install-linux-${ocp4_version}.tar.gz | |
wget https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest/openshift-client-linux-${ocp4_version}.tar.gz | |
tar zxvf openshift-client-linux-${ocp4_version}.tar.gz -C /usr/bin | |
tar zxvf openshift-install-linux-${ocp4_version}.tar.gz -C /usr/bin | |
chmod +x /usr/bin/openshift-install | |
chmod +x /usr/bin/oc | |
ls -l /usr/bin/{oc,openshift-install} | |
oc completion bash >/etc/bash_completion.d/openshift | |
rm -rf openshift-client-linux* | |
rm -rf openshift-install-linux* | |
echo "### Creating the AWS creds" | |
if [ -f "$HOME/.aws" ]; then | |
echo "### AWS creds already exist" | |
echo "### Updating the creds" | |
else | |
mkdir $HOME/.aws | |
echo "### Creating the AWS" | |
fi | |
cat << EOF > $HOME/.aws/credentials | |
[default] | |
aws_access_key_id = ${aws_secret_key_id} | |
aws_secret_access_key = ${aws_secret_access_key} | |
region = $aws_region | |
EOF | |
echo "### Check the AWS creds" | |
aws sts get-caller-identity | |
if [ -f "~/.ssh/ocp4-key" ]; then | |
ssh-keygen -f ~/.ssh/ocp4-key -N '' | |
fi | |
if [ -d "ocp4-install" ]; then | |
echo "### OCP already installed" | |
else | |
mkdir ocp4-install | |
openshift-install create cluster --dir=ocp4-install | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment