#!/bin/sh set -e # This script is meant for quick & easy install via: # # curl -s "https://get.idc.eu1.oracleinfinity.io" | bash # # This value will automatically get changed for: # * stable # * test # * dev DEFAULT_CHANNEL_VALUE="stable" if [ -z "$CHANNEL" ]; then export CHANNEL=$DEFAULT_CHANNEL_VALUE fi DEFAULT_VERSION_VALUE="latest" if [ -z "$VERSION" ]; then export VERSION=$DEFAULT_VERSION_VALUE fi DEFAULT_BUCKET_VALUE="idc-agent-$CHANNEL" if [ -z "$BUCKET" ]; then export BUCKET=$DEFAULT_BUCKET_VALUE fi DEFAULT_IDC_DOMAIN="get.idc.eu1.oracleinfinity.io" if [ -z "$IDC_DOMAIN" ]; then export IDC_DOMAIN=$DEFAULT_IDC_DOMAIN fi DEFAULT_DOWNLOAD_URL="https://objectstorage.us-ashburn-1.oraclecloud.com/n/infinity/b/$BUCKET/o" if [ -z "$DOWNLOAD_URL" ]; then export DOWNLOAD_URL=$DEFAULT_DOWNLOAD_URL fi SUPPORT_MAP=" x86_64-centos-7 x86_64-fedora-26 x86_64-fedora-27 x86_64-debian-wheezy x86_64-debian-jessie x86_64-debian-stretch x86_64-debian-buster x86_64-ol-7 x86_64-ubuntu-trusty x86_64-ubuntu-xenial x86_64-ubuntu-artful x86_64-darwin17- x86_64-darwin18- " command_exists() { command -v "$@" > /dev/null 2>&1 } deprecation_notice() { distro=$1 date=$2 echo echo "DEPRECATION WARNING:" echo " The distribution, $distro, will no longer be supported in this script as of $date." echo sleep 10 } get_distribution() { lsb_dist="" # Every system that we officially support has /etc/os-release if [ -r /etc/os-release ]; then lsb_dist="$(. /etc/os-release && echo "$ID")" else lsb_dist=$OSTYPE fi # Returning an empty string here should be alright since the # case statements don't act unless you provide an actual value echo "$lsb_dist" } # Check if this is a forked Linux distro check_forked() { # Check for lsb_release command existence, it usually exists in forked distros if command_exists lsb_release; then # Check if the `-u` option is supported set +e lsb_release -a -u > /dev/null 2>&1 lsb_release_exit_code=$? set -e # Check if the command has exited successfully, it means we're in a forked distro if [ "$lsb_release_exit_code" = "0" ]; then # Print info about current distro cat <<-EOF You're using '$lsb_dist' version '$dist_version'. EOF # Get the upstream release info lsb_dist=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'id' | cut -d ':' -f 2 | tr -d '[:space:]') dist_version=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'codename' | cut -d ':' -f 2 | tr -d '[:space:]') # Print info about upstream distro cat <<-EOF Upstream release is '$lsb_dist' version '$dist_version'. EOF else if [ -r /etc/debian_version ] && [ "$lsb_dist" != "ubuntu" ] && [ "$lsb_dist" != "raspbian" ]; then if [ "$lsb_dist" = "osmc" ]; then # OSMC runs Raspbian lsb_dist=raspbian else # We're Debian and don't even know it! lsb_dist=debian fi dist_version="$(sed 's/\/.*//' /etc/debian_version | sed 's/\..*//')" case "$dist_version" in 9) dist_version="stretch" ;; 8|'Kali Linux 2') dist_version="jessie" ;; 7) dist_version="wheezy" ;; esac fi fi fi } semverParse() { major="${1%%.*}" minor="${1#$major.}" minor="${minor%%.*}" patch="${1#$major.$minor.}" patch="${patch%%[-.]*}" } do_install() { echo "# Executing Oracle Infinity Data Connector install script..." if command_exists docker; then docker_version="$(docker -v | cut -d ' ' -f3 | cut -d ',' -f1)" MAJOR_W=1 MINOR_W=10 semverParse "$docker_version" shouldWarn=0 if [ "$major" -lt "$MAJOR_W" ]; then shouldWarn=1 fi if [ "$major" -le "$MAJOR_W" ] && [ "$minor" -lt "$MINOR_W" ]; then shouldWarn=1 fi if [ $shouldWarn -eq 1 ]; then cat >&2 <<-'EOF' Warning: the "docker" command appears to already exist on this system. Please update Docker, we urge you to migrate your image store before upgrading to v1.10+. You can find instructions for this here: https://github.com/docker/docker/wiki/Engine-v1.10.0-content-addressability-migration EOF cat >&2 <<-'EOF' You may press Ctrl+C now to abort this script. EOF ( set -x; sleep 20 ) fi fi user="$(id -un 2>/dev/null || true)" sh_c='sh -c' if [ "$user" != 'root' ]; then echo "Do you wish to install this agent as root?" select yn in "Yes" "No"; do case $yn in Yes ) if command_exists sudo; then sh_c='sudo -E sh -c' elif command_exists su; then sh_c='su -c' else cat >&2 <<-'EOF' Error: this installer needs the ability to run commands as root. We are unable to find either "sudo" or "su" available to make this happen. EOF exit 1 fi break;; No ) break;; esac done fi # perform some very rudimentary platform detection lsb_dist=$( get_distribution ) lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')" case "$lsb_dist" in ubuntu) if command_exists lsb_release; then dist_version="$(lsb_release --codename | cut -f2)" fi if [ -z "$dist_version" ] && [ -r /etc/lsb-release ]; then dist_version="$(. /etc/lsb-release && echo "$DISTRIB_CODENAME")" fi ;; debian|raspbian) dist_version="$(sed 's/\/.*//' /etc/debian_version | sed 's/\..*//')" case "$dist_version" in 9) dist_version="stretch" ;; 8) dist_version="jessie" ;; 7) dist_version="wheezy" ;; esac ;; rhel|ol|sles|centos) if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then dist_version="$(. /etc/os-release && echo "$VERSION_ID")" semverParse "$dist_version" dist_version="$major" fi ;; *) if command_exists lsb_release; then dist_version="$(lsb_release --release | cut -f2)" fi if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then dist_version="$(. /etc/os-release && echo "$VERSION_ID")" fi ;; esac # Check if this is a forked Linux distro check_forked # Check if we actually support this configuration if ! echo "$SUPPORT_MAP" | grep "$(uname -m)-$lsb_dist-$dist_version" >/dev/null; then cat >&2 <<-'EOF' WARNING: Either your platform is not easily detectable or is not supported by this installer script this is an unsupported configuration. EOF fi if command_exists java; then JAVA_MAJOR="$(java -version 2>&1 | head -n1 | cut -d ' ' -f3 | cut -d '"' -f2 | cut -d '.' -f1)" JAVA_MINOR="$(java -version 2>&1 | head -n1 | cut -d ' ' -f3 | cut -d '"' -f2 | cut -d '.' -f2)" if [ "$JAVA_MAJOR" -le "1" ] && [ "$JAVA_MINOR" -lt "7" ]; then cat >&2 <<-'EOF' Warning: "java" command appears to already exist on this system. Please ensure you have Java SDK 1.7 or greater installed. EOF exit 1 fi else cat >&2 <<-'EOF' Warning: "java" command does not appear to already exist on this system. Please ensure you have Java SDK 1.7 or greater installed. EOF exit 1 fi $sh_c "curl -fsSL \"$DOWNLOAD_URL/infinity-data-connector-$VERSION-install.jar\" -o /tmp/infinity-data-connector-$VERSION-install.jar && java -jar /tmp/infinity-data-connector-$VERSION-install.jar" $sh_c "rm /tmp/infinity-data-connector-$VERSION-install.jar" exit 0 } # wrapped up in a function so that we have some protection against only getting # half the file during "curl | sh" do_install