From 7ddf69872fdacdc3a9ec19888950774be4370bff Mon Sep 17 00:00:00 2001 From: Serhiy Ovsianikov Date: Fri, 30 Jan 2015 17:08:04 +0200 Subject: [PATCH] Call which from virtualbox scripts The "which" command is replaced with the "type" command. The free memory check error on the host has been fixed. Change-Id: I2cb8d143616372b649d51b9543160d40e5f2f510 Closes-Bug: #1415685 --- actions/check-available-memory.sh | 9 ++++-- actions/prepare-environment.sh | 52 ++++++++++++++++++++----------- functions/memory.sh | 40 ++++++------------------ launch.sh | 4 ++- 4 files changed, 51 insertions(+), 54 deletions(-) mode change 100644 => 100755 actions/check-available-memory.sh mode change 100644 => 100755 functions/memory.sh diff --git a/actions/check-available-memory.sh b/actions/check-available-memory.sh old mode 100644 new mode 100755 index 14530c2..ced0eef --- a/actions/check-available-memory.sh +++ b/actions/check-available-memory.sh @@ -18,11 +18,14 @@ # This script check availble memory on host PC for quality provision VMs via VirtualBox # -total_memory=$(get_available_memory $os_type) +source ./config.sh +source ./functions/memory.sh + +total_memory=$(get_available_memory) if [ $total_memory -eq -1 ]; then echo "Launch without checking RAM on host PC" - echo "Auto check memory is unavailable, you need install 'top' and 'free'. Please install procps package." + echo "Auto check memory is unavailable, you need install 'free'. Please install procps package." else # Count selected RAM configuration for machine_number in $(eval echo {1..$cluster_size}); do @@ -41,4 +44,4 @@ else echo "You can allocate no more than ${can_allocate_mb}MB, but trying to run VMs with ${vm_total_mb}MB" exit 1 fi -fi \ No newline at end of file +fi diff --git a/actions/prepare-environment.sh b/actions/prepare-environment.sh index 1c3092a..d7e3574 100755 --- a/actions/prepare-environment.sh +++ b/actions/prepare-environment.sh @@ -29,24 +29,37 @@ source ./functions/network.sh # Check for procps package if [ "$(uname -s | cut -c1-6)" = "CYGWIN" ]; then - echo -n "Checking for 'top' and 'free'" - free -V >/dev/null 2>&1 || { echo >&2 " \"free\" is not available in the path, but it's required. Please install \"procps\" package. Aborting."; exit 1; } - top -v >/dev/null 2>&1 || { echo >&2 " \"top\" is not available in the path, but it's required. Please install \"procps\" package. Aborting."; exit 1; } + echo -n "Checking for 'free'... " + type free >/dev/null 2>&1 + if [ $? -eq 1 ]; then + echo "\"free\" is not available in the path, but it's required. Please install the \"procps\" package. Aborting." + exit 1 + else echo "OK" + fi fi # Check for expect echo -n "Checking for 'expect'... " -expect -v >/dev/null 2>&1 || { echo >&2 " \"expect\" is not available in the path, but it's required. Please install Tcl \"expect\" package. Aborting."; exit 1; } -echo "OK" +type expect >/dev/null 2>&1 +if [ $? -eq 1 ]; then + echo "\"expect\" is not available in the path, but it's required. Please install Tcl \"expect\" package. Aborting." + exit 1 +else + echo "OK" +fi # Check for VirtualBox echo "If you run this script under Cygwin, you may have to add path to VirtualBox directory to your PATH. " echo "Usually it is enough to run \"export PATH=\$PATH:\"/cygdrive/c/Program Files/Oracle/VirtualBox\" " echo -n "Checking for \"VBoxManage\"... " -echo -n " " -VBoxManage -v >/dev/null 2>&1 || { echo >&2 "\"VBoxManage\" is not available in the path, but it's required. Likely, VirtualBox is not installed. Aborting."; exit 1; } -echo "OK" +type VBoxManage >/dev/null 2>&1 +if [ $? -eq 1 ]; then + echo "\"VBoxManage\" is not available in the path, but it's required. Likely, VirtualBox is not installed. Aborting." + exit 1 +else + echo "OK" +fi # Check for VirtualBox Extension Pack echo -n "Checking for VirtualBox Extension Pack... " @@ -66,29 +79,30 @@ echo "OK" echo "Going to use Mirantis OpenStack ISO file $iso_path" # Check if SSH is installed. Cygwin does not install SSH by default. -echo "Checking if SSH client installed... " -sshs=`which ssh | wc -l` -if [ "$sshs" -le 0 ] ; then - echo -n "SSH client is not installed. Please install \"openssh\" package if you run this script under Cygwin. Aborting" +echo -n "Checking if SSH client installed... " +type ssh >/dev/null 2>&1 +if [ $? -eq 1 ]; then + echo "SSH client is not installed. Please install the \"openssh\" package if you run this script under Cygwin. Aborting." exit 1 +else + echo "OK" fi -echo "OK" -echo "Checking if ipconfig or ifconfig installed... " +echo -n "Checking if ipconfig or ifconfig installed... " case "$(uname)" in Linux | Darwin) if [ ! -x /sbin/ifconfig ] ; then - echo -n "No ifconfig available at /sbin/ifconfig path! This path is hard-coded into VBoxNetAdpCtl utility." - echo -n "Please install ifconfig or create symlink to proper interface configuration utility." + echo "No ifconfig available at /sbin/ifconfig path! This path is hard-coded into VBoxNetAdpCtl utility." + echo "Please install ifconfig or create symlink to proper interface configuration utility. Aborting." exit 1 fi ;; CYGWIN*) # Cygwin does not use ifconfig at all and even has no link to it. # It uses built-in Windows ipconfig utility instead. - ipconfigs=`which ipconfig | wc -l` - if [ "$ipconfigs" -le 0 ] ; then - echo -n "No ipconfig available in Cygwin environment. Please check you can run ipconfig from Cygwin command prompt." + type ipconfig >/dev/null 2>&1 + if [ $? -eq 1 ]; then + echo "No ipconfig available in Cygwin environment. Please check you can run ipconfig from Cygwin command prompt. Aborting." exit 1 fi ;; diff --git a/functions/memory.sh b/functions/memory.sh old mode 100644 new mode 100755 index 09b3596..8eddfdc --- a/functions/memory.sh +++ b/functions/memory.sh @@ -17,40 +17,18 @@ # This file contains the functions to get available memory on host PC get_available_memory() { - os_type=$1 - local total_memory="" - # Check available commands and RAM on host PC - if [ "$os_type" = "linux" ]; then - # runing on linux - if [ "$(which free)" != "" ]; then - # using free +local total_memory + case $(uname) in + Linux | CYGWIN*) total_memory=$(LANG=C free | grep Mem | awk '{print $2}') - elif [ "$(which top)" != "" ]; then - # using top - total_memory=$(LANG=C top -n 1 | grep "Mem:" | awk '{ print $4 }') - else - total_memory="-1" - fi - elif [ "$os_type" = "darwin" ]; then - # runing on mac os darwin - if [ "$(which sysctl)" != "" ]; then - # using sysctl + ;; + Darwin) total_memory=$(sysctl -n hw.memsize) total_memory=$(( $total_memory / 1024 )) - else + ;; + *) total_memory="-1" - fi - elif [ "$os_type" = "cygwin" ]; then - # runing on cygwin - if [ "$(which free)" != "" ]; then - # using free - total_memory=$(LANG=C free | grep Mem | awk '{print $2}') - elif [ "$(which top)" != "" ]; then - # using top - total_memory=$(LANG=C top -n 1 | grep "Mem:" | awk '{ print $4 }') - else - total_memory="-1" - fi - fi + ;; + esac echo $total_memory } diff --git a/launch.sh b/launch.sh index 4550f4f..12cc8e0 100755 --- a/launch.sh +++ b/launch.sh @@ -29,13 +29,15 @@ esac # Prepare the host system ./actions/prepare-environment.sh || exit 1 +# Check available memory on the host system +./actions/check-available-memory.sh || exit 1 + # clean previous installation if exists ./actions/clean-previous-installation.sh || exit 1 # create host-only interfaces ./actions/create-interfaces.sh || exit 1 - # Create and launch master node ./actions/master-node-create-and-install.sh || exit 1