Merge "Change PTL informatin in INFO"
[bottlenecks.git] / utils / infra_setup / vm_dev_setup / setup_env.sh
index 795a0a6..db280e7 100755 (executable)
@@ -1,4 +1,12 @@
 #!/bin/bash
+##############################################################################
+# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
 
 set -x
 
@@ -6,7 +14,7 @@ wait_vm_ok() {
     ip=$1
 
     retry=0
-    until timeout 10s ssh $ssh_args ec2-user@$ip "exit" >/dev/null 2>&1
+    until timeout 10s ssh $ssh_args ubuntu@$ip "exit" >/dev/null 2>&1
     do
         echo "retry connect rubbos vm ip $ip $retry"
         sleep 1
@@ -20,7 +28,7 @@ wait_vm_ok() {
 
 bottlenecks_prepare_env()
 {
-    echo "Bottlenecks prepare env in VMs"
+    echo "Bottlenecks prepare env"
 
     # configue rubbos control ssh key
     generate_ssh_key
@@ -36,12 +44,12 @@ bottlenecks_prepare_env()
     for i in $rubbos_benchmark $rubbos_client1 $rubbos_client2 \
              $rubbos_client3 $rubbos_client4 $rubbos_httpd $rubbos_mysql1 $rubbos_tomcat1
     do
-          scp $ssh_args -r $SCRIPT_DIR ec2-user@$i:/tmp
-          ssh $ssh_args ec2-user@$i "sudo bash $SCRIPT_DIR/vm_prepare_setup.sh" &
+          scp $ssh_args -r $SCRIPT_DIR ubuntu@$i:/tmp
+          ssh $ssh_args ubuntu@$i "sudo bash $SCRIPT_DIR/vm_prepare_setup.sh" &
     done
 
-    # ugly use ssh execute script to fix ec2-user previlege issue
-    ssh $ssh_args ec2-user@$rubbos_control "sudo bash $SCRIPT_DIR/vm_prepare_setup.sh"
+    # ugly use ssh execute script to fix ubuntu previlege issue
+    ssh $ssh_args ubuntu@$rubbos_control "sudo bash $SCRIPT_DIR/vm_prepare_setup.sh"
 
     # test root access
     for i in $rubbos_control $rubbos_benchmark $rubbos_client1 $rubbos_client2 \
@@ -51,29 +59,30 @@ bottlenecks_prepare_env()
     done
 }
 
+git_checkout()
+{
+    if sudo git cat-file -e $1^{commit} 2>/dev/null; then
+        # branch, tag or sha1 object
+        sudo git checkout $1
+    else
+        # refspec / changeset
+        sudo git fetch --tags --progress $2 $1
+        sudo git checkout FETCH_HEAD
+    fi
+}
+
 bottlenecks_download_repo()
 {
     echo "Bottlenecks: download bottlenecks repo"
 
     sudo git config --global http.sslVerify false
-    if [ -d $BOTTLENECKS_REPO_DIR/.git ]; then
-        cd $BOTTLENECKS_REPO_DIR
-        sudo git pull origin master
-        if [ x"$GERRIT_REFSPEC_DEBUG" != x ]; then
-            sudo git fetch $BOTTLENECKS_REPO $GERRIT_REFSPEC_DEBUG && sudo git checkout FETCH_HEAD
-        fi
-        cd -
-    else
-        sudo rm -rf $BOTTLENECKS_REPO_DIR
+    if [ ! -d $BOTTLENECKS_REPO_DIR ]; then
         sudo git clone $BOTTLENECKS_REPO $BOTTLENECKS_REPO_DIR
-        if [ x"$GERRIT_REFSPEC_DEBUG" != x ]; then
-            cd $BOTTLENECKS_REPO_DIR
-            echo "fetch $GERRIT_REFSPEC_DEBUG"
-            sudo git fetch $BOTTLENECKS_REPO $GERRIT_REFSPEC_DEBUG && sudo git checkout FETCH_HEAD
-            cd -
-        fi
-
     fi
+    cd $BOTTLENECKS_REPO_DIR
+    sudo git checkout master && sudo git pull
+    git_checkout $BOTTLENECKS_BRANCH $BOTTLENECKS_REPO
+    cd -
 }
 
 bottlenecks_config_hosts_ip()
@@ -115,8 +124,8 @@ main()
     SCRIPT_DIR=`cd ${BASH_SOURCE[0]%/*};pwd`
 
     ssh_args="-o StrictHostKeyChecking=no -o BatchMode=yes"
-    source $SCRIPT_DIR/package.conf
     source $SCRIPT_DIR/hosts.conf
+    source $SCRIPT_DIR/package.conf
     source $SCRIPT_DIR/common.sh
 
     bottlenecks_prepare_env