-
Notifications
You must be signed in to change notification settings - Fork 0
/
op_install.sh
197 lines (166 loc) · 5.13 KB
/
op_install.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
#!/usr/bin/env bash
# Author: rming <rmingwang AT gmail.com>
#
# Notes: openpilot install script
#
# Project home page:
# http://doc.sdut.me/cn/openpilot_install.html
clear
printf "
##############################################################
# openpilot 一键安装脚本 #
# 更多信息 http://doc.sdut.me/cn/openpilot_install.html #
##############################################################
"
# 配置每个 fork 文件存储位置
PATH_FORK=/data/forks
PATH_SUNNYPILOT=${PATH_FORK}/sunnypilot
PATH_DRAGONPILOT=${PATH_FORK}/dragonpilot
PATH_FROGPILOT=${PATH_FORK}/forgpilot
# 配置每个 fork 的 git 地址
GIT_SUNNYPILOT=https://github.com/sunnypilot/sunnypilot.git
GIT_DRAGONPILOT=https://github.com/dragonpilot-community/dragonpilot.git
GIT_FROGPILOT=https://github.com/FrogAi/FrogPilot.git
# 构建结果文件
FILE_UI_BUILD=selfdrive/ui/ui.o
# OP的入口文件
FILE_OP_LAUNCH=launch_openpilot.sh
#################################################
# echo color
echo=echo
for cmd in echo /bin/echo; do
$cmd >/dev/null 2>&1 || continue
if ! $cmd -e "" | grep -qE '^-e'; then
echo=$cmd
break
fi
done
CSI=$($echo -e "\033[")
CEND="${CSI}0m"
CDGREEN="${CSI}32m"
CRED="${CSI}1;31m"
CGREEN="${CSI}1;32m"
CYELLOW="${CSI}1;33m"
CBLUE="${CSI}1;34m"
CMAGENTA="${CSI}1;35m"
CCYAN="${CSI}1;36m"
CSUCCESS="$CDGREEN"
CFAILURE="$CRED"
CQUESTION="$CMAGENTA"
CWARNING="$CYELLOW"
CMSG="$CCYAN"
# fork_select
while :; do echo
echo -e 'Fork 选择:'
fork_count=$[${#FORKS[@]} - 1]
for i in "${!FORKS[@]}"; do
[[ ${i} -eq "0" ]] && continue
echo -e "\t${CBLUE}${i}. ${FORKS[$i]}${CEND}"
done
read -e -p "请输入序号 ${CRED}[1-${fork_count}]${CEND}:" fork_select
fork_select=${fork_select:-1}
if [[ "${fork_select}" -gt "${fork_count}" ]] || [[ "${fork_select}" -lt "1" ]]; then
echo -e "\n${CWARNING}请输入正确的序号![1-5]${CEND}"
else
echo -e "===========================\n"
FORK_L=${FORKS[$fork_select]}
FORK=`echo ${FORK_L} | tr 'a-z' 'A-Z' | tr -d '-'`
break
fi
done
# branch_select
OP_BRANCHES=(`eval echo "$""{BRANCH_"${FORK}"[@]}"`)
while :; do echo
echo -e '分支选择:'
branch_count=$[${#OP_BRANCHES[@]} - 1]
for i in "${!OP_BRANCHES[@]}"; do
[[ ${i} -eq "0" ]] && continue
echo -e "\t${CBLUE}${i}. ${OP_BRANCHES[$i]}${CEND}"
done
read -e -p "请输入序号 ${CRED}[1-${branch_count}]${CEND}:" branch_select
branch_select=${branch_select:-1}
if [[ "${branch_select}" -gt "${branch_count}" ]] || [[ "${branch_select}" -lt "1" ]]; then
echo -e "\n${CWARNING}请输入正确的序号![1-${branch_count}]${CEND}"
else
echo -e "===========================\n"
OP_BRANCH=${OP_BRANCHES[$branch_select]}
break
fi
done
VAR_OP_PATH=`eval echo "$""PATH_${FORK}"`
VAR_OP_GIT=`eval echo "$""GIT_${FORK}"`
OP_PATH=${VAR_OP_PATH}
OP_GIT=${VAR_OP_GIT}
echo -e "\n${CSUCCESS}已选Fork: ${FORK_L} \n已选分支:${OP_BRANCH}${CEND}"
echo -e "===========================\n"
echo -e "\n${CBLUE}正在更新代码......${CEND}"
# 创建 forks 目录
if [ ! -d "${PATH_FORK}" ]; then
mkdir -p "${PATH_FORK}"
if [[ "$?" -ne "0" ]]; then
echo -e "\n${CFAILURE}${PATH_FORK} 目录创建失败,请检查目录权限${CEND}"
exit 1
fi
fi
if [ ! -d "${OP_PATH}" ]; then
# 目录不存在,第一次安装
git clone -b ${OP_BRANCH} ${OP_GIT} ${OP_PATH}
if [[ "$?" -ne "0" ]]; then
echo -e "\n${CFAILURE}git clone 失败,请检查后重试${CEND}"
exit 1
fi
else
git -C ${OP_PATH} pull
if [[ "$?" -ne "0" ]]; then
echo -e "\n${CFAILURE}git pull 失败,请检查后重试${CEND}"
exit 1
fi
git -C ${OP_PATH} checkout ${OP_BRANCH}
if [[ "$?" -ne "0" ]]; then
echo -e "\n${CFAILURE}git checkout 失败,请检查后重试${CEND}"
exit 1
fi
fi
echo -e "===========================\n"
# 是否首次编译
if [[ ! -f "${OP_PATH}/${FILE_UI_BUILD}" ]];then
echo -e "${CWARNING}首次编译大约需要 25 分钟\n${CEND}"
fi
# 是否需要切换到当前选择的分支
read -e -p "${CWARNING}是否切换分支并编译${CEND} ${CRED}[Y/n]${CEND}:" is_change_fork
is_change_fork=${is_change_fork:-y}
is_change_fork=`echo ${is_change_fork} | tr 'yn' 'YN'`
if [[ "${is_change_fork}" == "N" ]];then
echo -e "${CSUCCESS}\n操作完成!\n${CEND}"
exit 0
fi
# 创建软链
ENV_OP_PATH=/data/openpilot
if [ ! -L "${ENV_OP_PATH}" ]; then
ms=`date +%s_%N`
mv "${ENV_OP_PATH}" "${PATH_FORK}/backup_${ms}"
fi
rm -f ${ENV_OP_PATH}
ln -sf ${OP_PATH} ${ENV_OP_PATH}
# 等待编译提示
echo -e "${CBLUE}\n请耐心等待......\n${CEND}"
# 编译
cd ${ENV_OP_PATH} && make
if [[ "$?" -ne "0" ]]; then
echo -e "\n${CFAILURE}openpilot 编译失败,请检查后重试${CEND}"
exit 1
fi
echo -e "===========================\n"
# 是否需要重启
read -e -p "${CWARNING}是否重启 EON${CEND} ${CRED}[Y/n]${CEND}:" is_reboot
is_reboot=${is_reboot:-y}
is_reboot=`echo ${is_reboot} | tr 'yn' 'YN'`
if [[ "${is_reboot}" == "N" ]];then
echo -e "${CSUCCESS}\n操作完成!\n${CEND}"
exit 0
fi
echo -e "${CSUCCESS}\n系统重启中......\n${CEND}"
if [[ -f "/comma.sh" ]];then
reboot
fi
exit 0