forked from HorizonRDK/rdk-gen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
source_sync.sh
executable file
·325 lines (298 loc) · 7.93 KB
/
source_sync.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
#!/bin/bash
###
# COPYRIGHT NOTICE
# Copyright 2023 Horizon Robotics, Inc.
# All rights reserved.
# @Date: 2022-12-18 16:06:50
# @LastEditTime: 2023-04-25 12:14:22
###
set -e
#
# This script synchronizes the kernel, bootloader and debian package
# sources in the horizon public git repository.
# The script also provides opportunities to the sync to a specific tag
# so that the binaries shipped with a release can be replicated.
#
# Usage:
# By default it will download all the listed sources
# ./source_sync.sh
# Use the -t <TAG> option to provide the TAG to be used to sync all the sources.
# Use the -k <TAG> option to download only the kernel and device tree repos and optionally sync to TAG
# For detailed usage information run with -h option.
#
# verify that git is installed
if ! which git > /dev/null ; then
echo "ERROR: git is not installed. If your linux distro is 10.04 or later,"
echo "git can be installed by 'sudo apt-get install git-core'."
exit 1
fi
# source dir
RDK_DIR=$(cd `dirname $0` && pwd)
RDK_DIR="${RDK_DIR}/source"
# script name
SCRIPT_NAME=`basename $0`
# info about sources.
# NOTE: *Add only kernel repos here. Add new repos separately below. Keep related repos together*
SOURCE_INFO="
k:kernel:HorizonRDK/kernel.git:
o:bootloader:HorizonRDK/bootloader.git:
o:hobot-miniboot:HorizonRDK/hobot-miniboot.git:
o:hobot-boot:HorizonRDK/hobot-boot.git:
o:hobot-bpu-drivers:HorizonRDK/hobot-bpu-drivers.git:
o:hobot-camera:HorizonRDK/hobot-camera.git:
o:hobot-configs:HorizonRDK/hobot-configs.git:
o:hobot-dnn:HorizonRDK/hobot-dnn.git:
o:hobot-dtb:HorizonRDK/hobot-dtb.git:
o:hobot-display:HorizonRDK/hobot-display.git:
o:hobot-io:HorizonRDK/hobot-io.git:
o:hobot-io-samples:HorizonRDK/hobot-io-samples.git:
o:hobot-kernel-headers:HorizonRDK/hobot-kernel-headers.git:
o:hobot-multimedia:HorizonRDK/hobot-multimedia.git:
o:hobot-multimedia-dev:HorizonRDK/hobot-multimedia-dev.git:
o:hobot-spdev:HorizonRDK/hobot-spdev.git:
o:hobot-sp-samples:HorizonRDK/hobot-sp-samples.git:
o:hobot-utils:HorizonRDK/hobot-utils.git:
o:hobot-wifi:HorizonRDK/hobot-wifi.git:
o:hobot-multimedia-samples:HorizonRDK/hobot-multimedia-samples.git:
o:hobot-audio-config:HorizonRDK/hobot-audio-config.git:
"
# exit on error on sync
EOE=0
# after processing SOURCE_INFO
NSOURCES=0
declare -a SOURCE_INFO_PROCESSED
# download all?
DALL=1
function Usages {
local ScriptName=$1
local LINE
local OP
local DESC
local PROCESSED=()
local i
echo "Use: $1 [options]"
echo "Available general options are,"
echo " -h : help"
echo " -e : exit on sync error"
echo " -d [DIR] : root of source is DIR"
echo " -t [TAG] : Git tag that will be used to sync all the sources"
echo ""
echo "By default, all sources are downloaded."
echo "Only specified sources are downloaded, if one or more of the following options are mentioned."
echo ""
echo "$SOURCE_INFO" | while read LINE; do
if [ ! -z "$LINE" ]; then
OP=$(echo "$LINE" | cut -f 1 -d ':')
DESC=$(echo "$LINE" | cut -f 2 -d ':')
if [[ ! " ${PROCESSED[@]} " =~ " ${OP} " ]]; then
echo " -${OP} [TAG]: Download $DESC source and optionally sync to TAG"
PROCESSED+=("${OP}")
else
echo " and download $DESC source and sync to the same TAG"
fi
fi
done
echo ""
}
function ProcessSwitch {
local SWITCH="$1"
local TAG="$2"
local i
local found=0
for ((i=0; i < NSOURCES; i++)); do
local OP=$(echo "${SOURCE_INFO_PROCESSED[i]}" | cut -f 1 -d ':')
if [ "-${OP}" == "$SWITCH" ]; then
SOURCE_INFO_PROCESSED[i]="${SOURCE_INFO_PROCESSED[i]}${TAG}:y"
DALL=0
found=1
fi
done
if [ "$found" == 1 ]; then
return 0
fi
echo "Terminating... wrong switch: ${SWITCH}" >&2
Usages "$SCRIPT_NAME"
exit 1
}
function UpdateTags {
local SWITCH="$1"
local TAG="$2"
local i
for ((i=0; i < NSOURCES; i++)); do
local OP=$(echo "${SOURCE_INFO_PROCESSED[i]}" | cut -f 1 -d ':')
if [ "${OP}" == "$SWITCH" ]; then
SOURCE_INFO_PROCESSED[i]=$(echo "${SOURCE_INFO_PROCESSED[i]}" \
| awk -F: -v OFS=: -v var="${TAG}" '{$4=var; print}')
fi
done
}
function DownloadAndSync {
local WHAT_SOURCE="$1"
local RDK_SOURCE_DIR="$2"
local REPO_URL="$3"
local TAG="$4"
local OPT="$5"
local RET=0
if [ -d "${RDK_SOURCE_DIR}" ]; then
echo "Directory for $WHAT, ${RDK_SOURCE_DIR}, already exists!"
pushd "${RDK_SOURCE_DIR}" > /dev/null
git status 2>&1 >/dev/null
if [ $? -ne 0 ]; then
echo "But the directory is not a git repository -- clean it up first"
echo ""
echo ""
popd > /dev/null
return 1
fi
git fetch --all 2>&1 >/dev/null
local_head=$(git rev-parse HEAD)
remote_head=$(git rev-parse @{u})
if [[ $local_head != $remote_head ]]; then
echo "There are remote updates for $WHAT, pulling latest code..."
git pull --ff-only
fi
popd > /dev/null
else
echo "Downloading default $WHAT source..."
git clone "$REPO_URL" -n ${RDK_SOURCE_DIR} 2>&1 >/dev/null
if [ $? -ne 0 ]; then
echo "$2 source sync failed!"
echo ""
echo ""
return 1
fi
echo "The default $WHAT source is downloaded in: ${RDK_SOURCE_DIR}"
fi
if [ -z "$TAG" ]; then
echo "Please enter a tag to sync $2 source to"
echo -n "(enter nothing to skip): "
read TAG
TAG=$(echo $TAG)
UpdateTags $OPT $TAG
fi
if [ ! -z "$TAG" ]; then
if [ "xmain" == x"$TAG" ] || [ "xdevelop" == x"$TAG" ]; then
# checkout main or develop
pushd ${RDK_SOURCE_DIR} > /dev/null
echo "Syncing up with branch origin/$TAG..."
git checkout ${TAG}
echo "$2 source sync'ed to branch origin/$TAG successfully!"
popd > /dev/null
else
pushd ${RDK_SOURCE_DIR} > /dev/null
git tag -l 2>/dev/null | grep -q -P "^$TAG\$"
if [ $? -eq 0 ]; then
echo "Syncing up with tag $TAG..."
git checkout -b mybranch_$(date +%Y-%m-%d-%s) $TAG
echo "$2 source sync'ed to tag $TAG successfully!"
else
echo "Couldn't find tag $TAG"
echo "$2 source sync to tag $TAG failed!"
RET=1
fi
popd > /dev/null
fi
fi
echo ""
echo ""
return "$RET"
}
# prepare processing ....
GETOPT=":ehd:t:"
OIFS="$IFS"
IFS=$(echo -en "\n\b")
SOURCE_INFO_PROCESSED=($(echo "$SOURCE_INFO"))
IFS="$OIFS"
NSOURCES=${#SOURCE_INFO_PROCESSED[*]}
for ((i=0; i < NSOURCES; i++)); do
OP=$(echo "${SOURCE_INFO_PROCESSED[i]}" | cut -f 1 -d ':')
GETOPT="${GETOPT}${OP}:"
done
# parse the command line first
while getopts "$GETOPT" opt; do
case $opt in
d)
case $OPTARG in
-[A-Za-z]*)
Usages "$SCRIPT_NAME"
exit 1
;;
*)
RDK_DIR="$OPTARG"
;;
esac
;;
e)
EOE=1
;;
h)
Usages "$SCRIPT_NAME"
exit 1
;;
t)
TAG="$OPTARG"
PROCESSED=()
for ((i=0; i < NSOURCES; i++)); do
OP=$(echo "${SOURCE_INFO_PROCESSED[i]}" | cut -f 1 -d ':')
if [[ ! " ${PROCESSED[@]} " =~ " ${OP} " ]]; then
UpdateTags $OP $TAG
PROCESSED+=("${OP}")
fi
done
;;
[A-Za-z])
case $OPTARG in
-[A-Za-z]*)
eval arg=\$$((OPTIND-1))
case $arg in
-[A-Za-Z]-*)
Usages "$SCRIPT_NAME"
exit 1
;;
*)
ProcessSwitch "-$opt" ""
OPTIND=$((OPTIND-1))
;;
esac
;;
*)
ProcessSwitch "-$opt" "$OPTARG"
;;
esac
;;
:)
case $OPTARG in
#required arguments
d)
Usages "$SCRIPT_NAME"
exit 1
;;
#optional arguments
[A-Za-z])
ProcessSwitch "-$OPTARG" ""
;;
esac
;;
\?)
echo "Terminating... wrong switch: $@" >&2
Usages "$SCRIPT_NAME"
exit 1
;;
esac
done
shift $((OPTIND-1))
for ((i=0; i < NSOURCES; i++)); do
OPT=$(echo "${SOURCE_INFO_PROCESSED[i]}" | cut -f 1 -d ':')
WHAT=$(echo "${SOURCE_INFO_PROCESSED[i]}" | cut -f 2 -d ':')
REPO=$(echo "${SOURCE_INFO_PROCESSED[i]}" | cut -f 3 -d ':')
TAG=$(echo "${SOURCE_INFO_PROCESSED[i]}" | cut -f 4 -d ':')
DNLOAD=$(echo "${SOURCE_INFO_PROCESSED[i]}" | cut -f 5 -d ':')
if [ $DALL -eq 1 -o "x${DNLOAD}" == "xy" ]; then
DownloadAndSync "$WHAT" "${RDK_DIR}/${WHAT}" "[email protected]:${REPO}" "${TAG}" "${OPT}"
tRET=$?
if [ $tRET -ne 0 -a $EOE -eq 1 ]; then
exit $tRET
fi
fi
done
exit 0