blob: ecdb73c546c382fcb511ee667cf2db0b610e4b61 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001#!/bin/bash -e
2
3#This is a small script that helps pulling and cloning in multiple repositories.
4
5########################## MUST READ NOTE ######################################
6
7##### Note 1 #####
8#add the following settings into the SSH key config file ~/.ssh/config
9#note: remove the # when adding into the config file, and replace the
10#<the_ssh_key_filename> with the public key file name of the key authorized by Marvell
11
12#Host 52.74.198.37
13# HostName 52.74.198.37
14# Port 443
15# PreferredAuthentications publickey
16# IdentityFile ~/.ssh/<the_ssh_key_filename>
17# User git
18
19##### Note 2 #####
20#Usage examples:
21##Clone all repos:
22##./ugit.sh clone
23
24##Update all repos:
25##./ugit.sh pull
26
27##### Note3 ######
28#After ugit.sh finished code clone, there is guide on how to prepare and start the build here
29# openwrt/docs/marvell/howto/start_and_build.txt
30
31########################### NOTE END ##########################################
32
33# For display color
34RESET="\033[0m"
35RED="\033[0;31m"
36BROWN="\033[0;33m"
37
38# The top repo dir path
39if [ -z ${OWRT_ROOT+x} ]; then
40 if [ -z ${TOP_DIR} ]; then
41 TOP_DIR=`pwd`
42 fi
43else
44 TOP_DIR=${OWRT_ROOT};
45fi
46
47#The list of repos other than the top repo (openwrt) which contains the script
48#Note: REPOPATHS is path + repo name, the path is relative to TOP_DIR
49# The sequence should be exactly same as in mgit.sh.
50
51#repos in openwrt top folder
52REPOPATHS="dl"
53#Feeds repos
54REPOPATHS+=" external/management external/routing external/subpack"
55#Marvell repos
56REPOPATHS+=" marvell/linux marvell/lte-telephony marvell/obm marvell/services marvell/swd marvell/uboot marvell/fota marvell/webui"
57
58
59###############################################################################
60# Actual code, don't touch:
61
62usage()
63{
64 echo "Usage : $0 <pull|clone|status>"
65 cd - &>/dev/null
66 exit 1
67}
68
69clone_repos()
70{
71 BASE_URL="git@52.74.198.37"
72 echo "Using base URL: '${BASE_URL}'"
73
74 TOPREPO="openwrt"
75 if [ ! -d ".git" ]; then
76 if [ -d "$TOPREPO" ]; then
77 cd ${TOPREPO}
78 git pull
79 else
80 mkdir -p "${TOPREPO}"
81 git clone "${BASE_URL}:${TOPREPO}.git" "${TOPREPO}"
82 cd ${TOPREPO}
83 fi
84 else
85 #TOPNAME=$(basename $(git remote show -n origin | grep Fetch | cut -d: -f3-))
86 TOPNAME=$(basename $(git rev-parse --show-toplevel))
87 if [[ "${TOPNAME}" = "${TOPREPO}" ]]; then
88 git pull
89 else
90 if [ -d "$TOPREPO" ]; then
91 cd ${TOPREPO}
92 git pull
93 else
94 mkdir -p "${TOPREPO}"
95 git clone "${BASE_URL}:${TOPREPO}.git" "${TOPREPO}"
96 cd ${TOPREPO}
97 fi
98 fi
99 fi
100
101 for REPOPATH in $REPOPATHS ; do
102 REPO=$(basename "${REPOPATH}")
103 if [ ! -d "$REPOPATH" ]; then
104 mkdir -p "${REPOPATH}"
105 git clone "${BASE_URL}:${REPO}_ow.git" "${REPOPATH}"
106 else
107 echo "Updating existing repo: ${REPOPATH}"
108 pushd ${REPOPATH} &>/dev/null
109 git pull
110 popd &>/dev/null
111 fi
112 done
113}
114
115run_command_in_dirs()
116{
117 CMD=$1
118
119#the top repo
120 echo -e "Processing command in $RED"openwrt"$RESET"
121 eval $CMD
122 echo -e "\r\n"
123
124 for REPOPATH in $REPOPATHS ; do
125 REPO=$(basename "${REPOPATH}")
126 if [ -d "$REPOPATH" ]; then
127 echo -e "Processing command in $RED${REPOPATH}$RESET"
128 pushd ${REPOPATH} &>/dev/null
129 eval $CMD
130 popd &>/dev/null
131 echo -e "\r\n"
132 else
133 echo -e "Skipping non-existent dir: $RED${REPOPATH}$RESET\r\n"
134 fi
135 done
136}
137
138cd ${TOP_DIR}
139if [ $# -lt 1 ]; then
140 usage
141fi
142
143case "$1" in
144 clone)
145 clone_repos
146 ;;
147 pull)
148 run_command_in_dirs "git pull"
149 ;;
150 status)
151 run_command_in_dirs "git status"
152 ;;
153 *)
154 usage
155 ;;
156esac
157cd - &>/dev/null