ASR_BASE

Change-Id: Icf3719cc0afe3eeb3edc7fa80a2eb5199ca9dda1
diff --git a/ugit.sh b/ugit.sh
new file mode 100755
index 0000000..ecdb73c
--- /dev/null
+++ b/ugit.sh
@@ -0,0 +1,157 @@
+#!/bin/bash -e
+
+#This is a small script that helps pulling and cloning in multiple repositories.
+
+##########################  MUST READ NOTE  ######################################
+
+##### Note 1 #####
+#add the following settings into the SSH key config file ~/.ssh/config
+#note: remove the # when adding into the config file, and replace the 
+#<the_ssh_key_filename> with the public key file name of the key authorized by Marvell
+
+#Host    52.74.198.37 
+#        HostName 52.74.198.37 
+#        Port 443 
+#        PreferredAuthentications publickey 
+#        IdentityFile ~/.ssh/<the_ssh_key_filename>
+#        User git
+
+##### Note 2 #####
+#Usage examples:
+##Clone all repos:
+##./ugit.sh clone
+
+##Update all repos:
+##./ugit.sh pull
+
+##### Note3 ######
+#After ugit.sh finished code clone, there is guide on how to prepare and start the build here
+# openwrt/docs/marvell/howto/start_and_build.txt
+
+###########################  NOTE END   ##########################################
+
+# For display color
+RESET="\033[0m"
+RED="\033[0;31m"
+BROWN="\033[0;33m"
+
+# The top repo dir path
+if [ -z ${OWRT_ROOT+x} ]; then
+	if [ -z ${TOP_DIR} ]; then
+		TOP_DIR=`pwd`
+	fi
+else
+	TOP_DIR=${OWRT_ROOT};
+fi
+
+#The list of repos other than the top repo (openwrt) which contains the script
+#Note: REPOPATHS is path + repo name, the path is relative to TOP_DIR
+#     The sequence should be exactly same as in mgit.sh.
+
+#repos in openwrt top folder
+REPOPATHS="dl"
+#Feeds repos
+REPOPATHS+=" external/management  external/routing  external/subpack"
+#Marvell repos
+REPOPATHS+=" marvell/linux marvell/lte-telephony marvell/obm marvell/services marvell/swd marvell/uboot marvell/fota marvell/webui"
+
+
+###############################################################################
+# Actual code, don't touch:
+
+usage()
+{
+   echo "Usage : $0 <pull|clone|status>"
+   cd - &>/dev/null
+   exit 1
+}
+
+clone_repos()
+{
+   BASE_URL="git@52.74.198.37"
+   echo "Using base URL: '${BASE_URL}'"
+
+   TOPREPO="openwrt"
+   if [ ! -d ".git" ]; then
+      if [ -d "$TOPREPO" ]; then
+         cd ${TOPREPO}
+         git pull
+      else
+         mkdir -p "${TOPREPO}"
+         git clone "${BASE_URL}:${TOPREPO}.git" "${TOPREPO}"
+         cd ${TOPREPO}
+      fi
+   else
+      #TOPNAME=$(basename $(git remote show -n origin | grep Fetch | cut -d: -f3-))
+      TOPNAME=$(basename $(git rev-parse --show-toplevel))
+      if [[ "${TOPNAME}" = "${TOPREPO}" ]]; then
+         git pull
+      else
+         if [ -d "$TOPREPO" ]; then
+            cd ${TOPREPO}
+            git pull
+         else
+            mkdir -p "${TOPREPO}"
+            git clone "${BASE_URL}:${TOPREPO}.git" "${TOPREPO}"
+            cd ${TOPREPO}
+         fi
+      fi
+   fi
+
+   for REPOPATH in $REPOPATHS ; do
+      REPO=$(basename "${REPOPATH}")
+      if [ ! -d "$REPOPATH" ]; then
+		mkdir -p "${REPOPATH}"
+		git clone "${BASE_URL}:${REPO}_ow.git" "${REPOPATH}"
+      else
+         echo "Updating existing repo: ${REPOPATH}"
+         pushd ${REPOPATH} &>/dev/null
+         git pull
+         popd &>/dev/null
+      fi
+   done
+}
+
+run_command_in_dirs()
+{
+   CMD=$1
+
+#the top repo
+   echo -e "Processing command in $RED"openwrt"$RESET"
+   eval $CMD
+   echo -e "\r\n"
+
+   for REPOPATH in $REPOPATHS ; do
+      REPO=$(basename "${REPOPATH}")
+      if [ -d "$REPOPATH" ]; then
+         echo -e "Processing command in $RED${REPOPATH}$RESET"
+         pushd ${REPOPATH} &>/dev/null
+         eval $CMD
+         popd &>/dev/null
+         echo  -e "\r\n"
+      else
+         echo -e "Skipping non-existent dir: $RED${REPOPATH}$RESET\r\n"
+      fi
+   done
+}
+
+cd ${TOP_DIR}
+if [ $# -lt 1 ]; then
+   usage
+fi
+
+case "$1" in
+   clone)
+      clone_repos
+      ;;
+   pull)
+      run_command_in_dirs "git pull"
+      ;;
+   status)
+      run_command_in_dirs "git status"
+      ;;
+   *)
+      usage
+      ;;
+esac
+cd - &>/dev/null