Adding checks for installation prerequisites
[kuberef.git] / functions.sh
index d246ace..f991dc8 100755 (executable)
@@ -20,6 +20,58 @@ clean_up() {
     sleep 5
 }
 
+
+check_prerequisites() {
+    echo "Info  : Check prerequisites"
+
+    #-------------------------------------------------------------------------------
+    # We shouldn't be running as root
+    #-------------------------------------------------------------------------------
+    if [[ "$(whoami)" == "root" ]]; then
+        echo "ERROR : This script must not be run as root!"
+        echo "        Please switch to a regular user before running the script."
+        exit 1
+    fi
+
+    #-------------------------------------------------------------------------------
+    # Check for passwordless sudo
+    #-------------------------------------------------------------------------------
+    if ! sudo -n "true"; then
+        echo "ERROR : passwordless sudo is needed for '$(id -nu)' user."
+        exit 1
+    fi
+
+    #-------------------------------------------------------------------------------
+    # Check if SSH key exists
+    #-------------------------------------------------------------------------------
+    if [[ ! -f "$HOME/.ssh/id_rsa" ]]; then
+        echo "ERROR : You must have SSH keypair in order to run this script!"
+        exit 1
+    fi
+
+    #-------------------------------------------------------------------------------
+    # We are using sudo so we need to make sure that env_reset is not present
+    #-------------------------------------------------------------------------------
+    sudo sed -i "s/^Defaults.*env_reset/#&/" /etc/sudoers
+
+    #-------------------------------------------------------------------------------
+    # Check if Ansible is installed
+    #-------------------------------------------------------------------------------
+    if ! command -v ansible &> /dev/null; then
+        echo "ERROR : Ansible not found. Please install."
+        exit 1
+    fi
+
+    #-------------------------------------------------------------------------------
+    # Check is libvirt is installed
+    #-------------------------------------------------------------------------------
+    if ! command -v virsh &> /dev/null; then
+        echo "ERROR : Libvirt not found. Please install."
+        exit 1
+    fi
+}
+
+
 # Create jumphost VM
 create_jump() {
 # Create VM image
@@ -152,6 +204,9 @@ fi
 if [ ! -d "${PROJECT_ROOT}/container-experience-kits" ]; then
     git clone --recurse-submodules --depth 1 https://github.com/intel/container-experience-kits.git -b v1.4.1 ${PROJECT_ROOT}/container-experience-kits/
     cp -r ${PROJECT_ROOT}/container-experience-kits/examples/group_vars examples/host_vars ${PROJECT_ROOT}/container-experience-kits/
+#TODO Remove this once the reported issue is fixed in the next BMRA Release
+    sed -i '/\openshift/a \    extra_args: --ignore-installed PyYAML' \
+         ${PROJECT_ROOT}/container-experience-kits/roles/net-attach-defs-create/tasks/main.yml
 fi
 cp ${PROJECT_ROOT}/${INSTALLER}/inventory.ini \
     ${PROJECT_ROOT}/container-experience-kits/