#!/bin/bash # # Author: Georg Voell - georg.voell@oracle.com # Version: @(#)check-tools 1.0.0 23.08.2020 (c)2020 Oracle # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ # #@ This script installs Python3 and Java 8 (using yum - supported platforms: OL and Red Hat) #@ #@Usage: check-tools [options] [action] #@ Options: -h, --help : Displays helptext. #@ -v, --version : Displays the version of the script. #@ Action: #@ install: Install the tools if they are not already installed. # # Exit codes: # 01: Unknown or wrong parameter. # 02: Unsupported platform. # 03: Unknown action. # 04: Action failed. # # Update history: # # V 1.0.0 23.08.2020 New version # script=${0} # Name of this script progstr=`basename "$script"` # Basename of the script progdir=`dirname "$script"` # Dirname of the script libfile=`filecheck -x lib.bash` # Find location of library source "$libfile" # Include default bash library PATH="$WORKPATH" # Set PATH to something useful ### Functions # Install required tool via RPM function InstallTool() { tool=${1} package=${2} installed=`filecheck -x "$tool"` if [ "$installed" = "" ]; then echo "Installing $tool" if [ "$USER" = "root" ]; then yum –y install "$package" stat=$? else sudo yum –y install "$package" stat=$? fi if [ $stat -eq 0 ]; then echo "Tool '$tool' installed." else errormsg 4 "Installing '$tool' failed." "Exit code: '$stat'" return 4 fi else echo "Tool '$tool' already installed: '$installed'." fi return 0 } ### Parameter check # Check parameters: Loop until all parameters are used up while [ $# -gt 0 ]; do pname=${1} case "$pname" in -v | --version) shift showversion=1 ;; -h | --help) shift showhelp=1 ;; *) paramck=`echo "$1" | grep '^-'` # Types don't begin with '-' if [ "$param" = "" -a "$paramck" = "" ]; then param=`echo "$1" | tr "[:upper:]" "[:lower:]"` else errstr="Unknown second parameter: '$1'." fi shift esac done # Plausibility check if [ "$param" = "" ]; then errstr="No action specified." fi # Display help or error message DisplayHelp ### Main # We only run on Linux if [ "$OS" != "Linux" ]; then exitcode=2 errormsg $exitcode "Sorry, script '$progstr' supports Linux only." else case "$param" in install) # Check if we have yum available yum=`filecheck -x yum` if [ "$yum" = "" ]; then # No yum - maybe other Linux than OL or Red Hat? exitcode=2 errormsg $exitcode "Sorry, no 'yum' in PATH." else # We need to be root or can do "sudo" ok=0 if [ "$USER" != "root" ]; then check-sudo stat=$? if [ $stat -eq 0 ]; then ok=1 fi else ok=1 fi if [ $ok -gt 0 ]; then InstallTool python3 "python3 python3-libs python3-setuptools python3-pip" exitcode=$? if [ $exitcode -eq 0 ]; then InstallTool java "java-1.8.0-openjdk" exitcode=$? fi fi fi ;; *) exitcode=3 errormsg $exitcode "Unknown action '$param'." esac fi # Cleanup and exit Cleanup exit $exitcode