-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·104 lines (84 loc) · 3.29 KB
/
setup.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
#!/usr/bin/env bash
function _echoInfo() {
echo -e "\e[1;33m[Info]: ${1}\e[0m"
}
function _echoError() {
echo -e "\e[1;31m[Error]: ${1} \e[0m"
}
function _echoSuccess() {
echo -e "\e[1;32m[Success]: ${1} \e[0m"
}
function onCtrlC() {
_echoError "[Warning]: stopped by user."
exit
}
function modifyUE4Path() {
local file="./scripts/VisionVoyageServer.sh"
local new_path
# 提示用户输入新的路径
echo "请输入您的 \`VisionVoyageServer/文件夹的\` 路径(例如:/home/m0rtzz/Programs/VisionVoyageServer):"
read new_path
new_path=$(realpath "${new_path}")
# 使用 sed 进行替换,注意使用双引号以正确处理包含空格的路径
sed -i "s|^UE4_PROJECT_ROOT=.*|UE4_PROJECT_ROOT=\"${new_path}\"|" "${file}" || {
_echoError "替换失败,请手动修改文件 ${file} 中的路径"
exit 1
}
_echoSuccess "已替换文件 '${file}' 的 \`UE4_PROJECT_ROOT\`为 '${new_path}'"
}
function modifyInterpreterPath() {
local file_paths=("$@") # 将参数作为文件路径数组
# env_path=$(python3 -c 'import os, sys; print(os.path.join(sys.prefix, "bin/python3"))')
env_path=$(python3 -c 'import sys; print(sys.executable)')
local replacement="#!${env_path}" # 替换为的新内容
for file in "${file_paths[@]}"; do
if [ -f "${file}" ]; then # 检查文件是否存在
if [ -s "${file}" ]; then # 检查文件是否非空
# 临时保存第一行以外的内容
old_first_line=$(head -n 1 "${file}")
rest_of_file=$(tail -n +2 "${file}")
# 将新的第一行内容和剩余内容重定向回原文件
echo "${replacement}" >"${file}"
echo "${rest_of_file}" >>"${file}"
_echoSuccess "已替换文件 '${file}' 的SheBang为 '${replacement}'"
else
_echoError "文件 '${file}' 为空,跳过替换操作"
fi
else
_echoError "文件 '${file}' 不存在"
fi
done
}
function confirmAndModify() {
_echoInfo "执行此脚本前请先使用 \`conda activate your-env\` 切换到您的虚拟环境."
echo "脚本将完成:"
echo " 修改Python文件的SheBang中的解释器路径。"
echo "请确认是否继续(按回车键继续,按 \`Ctrl+C\` 取消):"
read -r
# modifyUE4Path
modifyInterpreterPath "${file_paths[@]}"
}
trap 'onCtrlC' INT
file_paths=(
"./main.py"
"./scripts/automatic_control.py"
"./scripts/cubemap2fisheye.py"
"./scripts/dataset_main.py"
"./scripts/fisheye_utils.py"
"./scripts/generate_traffic.py"
"./scripts/get_fisheye_dataset.py"
"./scripts/manual_control_gbuffer.py"
"./scripts/manual_control.py"
"./scripts/PT2fisheye.py"
"./scripts/sem_seg_image.py"
"./scripts/sem_seg_video.py"
"./scripts/agents/navigation/basic_agent.py"
"./scripts/agents/navigation/behavior_agent.py"
"./scripts/agents/navigation/behavior_types.py"
"./scripts/agents/navigation/constant_velocity_agent.py"
"./scripts/agents/navigation/controller.py"
"./scripts/agents/navigation/global_route_planner.py"
"./scripts/agents/navigation/local_planner.py"
"./scripts/agents/tools/misc.py"
)
confirmAndModify