-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_simulation.sh
154 lines (120 loc) · 4 KB
/
setup_simulation.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
#!/usr/bin/env bash
# Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause-Clear
# set -Eeo pipefail
TOP=$(dirname "$(readlink -f "$0")")
echo "Setup simulation project start"
function try_create_dir()
{
RESULT=0
if ! [ -e "$1" ]; then
mkdir -p "$1"
RESULT=$?
echo "[Create] $1 dir (new)"
else
echo "[Prompt] $1 dir (exists)"
fi
return $RESULT
}
function try_clone ()
{
RESULT=0
BNAME=${BNAME:="mhead"}
if [ -e "$3" ] && [ -e "$3/.git" ]; then
echo "[Prompt] $3 is ready (exists)"
return $?
fi
echo -e "\n[Dwload] ($1) start..."
git clone --branch $2 $1 $3
cd $3
git checkout -b $BNAME $2 > /dev/null 2>&1
echo "[Switch] branch to track the latest commit-id"
cd - > /dev/null 2>&1
echo -e "[Dwload] $1 done (new)"
}
function try_download_script()
{
remote_raw_file_base="https://git.codelinaro.org/clo/le/platform/TelAF/-/raw/telaf.lnx.1.1/simulation/"
if [ -n "$3" ]; then
remote_raw_file_base="$3"
fi
wget_opts="-P $2 -N" # -q
check_file="simulation_env/$(basename $1)"
if [ -e "$check_file" ]; then
if [ -n "$SIMULA_OVERWRITE_SETUP" ]; then
rm -f $check_file
echo "[Script] Downloading from $remote_raw_file_base/$1, after removed"
wget "$remote_raw_file_base/$1" $wget_opts
if [ $? -ne 0 ]; then
echo "Err.. wget failed"
exit 1
fi
echo "[Script] $check_file done (re-new)"
echo
else
echo "[Script] $check_file (exists)"
return
fi
else
echo "[Script] Downloading from $remote_raw_file_base/$1"
wget "$remote_raw_file_base/$1" $wget_opts
if [ $? -ne 0 ]; then
echo "Err.. wget failed"
exit 1
fi
echo "[Script] $check_file done (new)"
echo
fi
}
try_create_dir "simulation_env"
try_create_dir "simulation_env/telaf"
try_create_dir "simulation_env/legato/legato-af"
try_create_dir "simulation_env/legato/3rdParty"
try_create_dir "simulation_env/legato/3rdParty/Kconfiglib"
try_create_dir "simulation_env/legato/3rdParty/jansson"
try_create_dir "simulation_env/sdk"
remote_server=
branch_mapping_conf="simulation_env/branch_mapping.conf"
echo "external" > simulation_env/FROM
if [ -e "./branch_mapping.x.conf" ]; then
branch_mapping_conf="./branch_mapping.x.conf"
echo "internal" > simulation_env/FROM
if [ -e "./remote.server" ]; then
if ! [ -s "./remote.server" ]; then
echo "Err.. Empty [remote.server] configuration"
exit 3
fi
read -r remote_server < "./remote.server"
echo "[Rmtsvr] ${remote_server}"
if [ -z "${remote_server}" ]; then
echo "Err.. Bad [remote.server] configuration"
exit 2
fi
else
echo "Err.. From: internal, but not provide the [remote.server] for address."
exit 1
fi
fi
try_download_script setup/Makefile simulation_env/ $remote_server
try_download_script setup/helpme_setup.py simulation_env/ $remote_server
try_download_script setup/patch_me.json simulation_env/ $remote_server
try_download_script setup/branch_mapping.conf simulation_env/ $remote_server
echo "[Helper] prepare some scripts (override: export SIMULA_OVERWRITE_SETUP=y)"
OLD_IFS=$IFS
IFS="= "
while read -r line; do
# Drop the empty line and comment
if [ -z "$line" ] || [[ "$line" == \#* ]]; then
continue
fi
read -r _to_dir _git _branch <<< "$line"
# parse the configuraiton file and clone gits accordingly
try_clone $_git $_branch $_to_dir
done < "$branch_mapping_conf"
IFS=$OLD_IFS
echo
echo "Now simulation projects are ready, maybe you need to do as follows:"
echo " 1. Please have a look at 'simulation_env/patch_me.json' and give some changes on demand"
echo " 2. Just run 'cd simulation_env && make update' to update simulation repos"
echo
exit 0