forked from ApolloAuto/apollo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathota.sh
executable file
·97 lines (87 loc) · 2.86 KB
/
ota.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
#!/usr/bin/env bash
###############################################################################
# Copyright 2017 The Apollo Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###############################################################################
APOLLO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
CACHE_DIR="${APOLLO_ROOT}/.cache"
function update() {
UPDATE_TAG=$(python ${APOLLO_ROOT}/modules/tools/ota/query_client.py)
if [ "$?" != "0" ]; then
echo $UPDATE_TAG
exit 1
fi
tip="Type 'y' or 'Y' to start upgrade, or type any other key to exit"
echo $tip
read -n 1 user_agreed
if [ "$user_agreed" != "y" ] && [ "$user_agreed" != "Y" ]; then
exit 1
fi
cp ${APOLLO_ROOT}/scripts/ota.sh "${CACHE_DIR}"
ssh $DOCKER_USER@localhost bash ${CACHE_DIR}/ota.sh download $UPDATE_TAG
python ${APOLLO_ROOT}/modules/tools/ota/verify_client.py
if [ "$?" != "0" ]; then
exit 1
fi
[ -e "${CACHE_DIR}/apollo_release" ] && rm -rf "${CACHE_DIR}/apollo_release"
tar xzf ${CACHE_DIR}/apollo_release.tar.gz -C ${CACHE_DIR}
NEW_TAG="${UPDATE_TAG}-local"
ssh $DOCKER_USER@localhost bash ${CACHE_DIR}/ota.sh setup $NEW_TAG
python ${APOLLO_ROOT}/modules/tools/ota/update_client.py ${UPDATE_TAG}
}
function clean() {
rm -rf ${CACHE_DIR}/apollo_update
rm -rf ${CACHE_DIR}/apollo_release.tar.gz
rm -rf ${CACHE_DIR}/sec_apollo_release.tar.gz
rm -rf ${CACHE_DIR}/ota.sh
docker stop test_container 1> /dev/null
docker rm test_container 1> /dev/null
}
function setup() {
docker exec test_container cp -Lr /root/mnt/apollo_release/apollo /
docker commit test_container $1
echo "Please restart release docker with new release image: $1"
clean
}
function download() {
UPDATE_TAG=$1
docker pull $UPDATE_TAG
if [ "$?" != "0" ]; then
echo "Downloading fails!"
exit 1
else
echo "New release image has been downloaded!"
fi
docker ps -a --format "{{.Names}}" | grep 'test_container' 1> /dev/null
if [ $? == 0 ]; then
docker stop test_container 1> /dev/null
docker rm -f test_container 1> /dev/null
fi
docker run -d -it --name test_container -v ${CACHE_DIR}:/root/mnt $UPDATE_TAG
docker exec test_container cp /root/sec_apollo_release.tar.gz /root/mnt
}
case $1 in
update)
update
;;
download)
download $2
;;
setup)
setup $2
;;
*)
echo "Usage: ota.sh update"
;;
esac