-
-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathcommon.sh
More file actions
executable file
·70 lines (66 loc) · 2.47 KB
/
Copy pathcommon.sh
File metadata and controls
executable file
·70 lines (66 loc) · 2.47 KB
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
#!/bin/bash
# Author: Kang Lin <kl222@126.com>
# 安全的 readlink 函数,兼容各种系统
safe_readlink() {
local path="$1"
if [ -L "$path" ]; then
if command -v readlink >/dev/null 2>&1; then
if readlink -f "$path" >/dev/null 2>&1; then
readlink -f "$path"
else
readlink "$path"
fi
else
ls -l "$path" | awk '{print $NF}'
fi
elif [ -e "$path" ]; then
if command -v realpath >/dev/null 2>&1; then
realpath "$path"
else
echo "$(cd "$(dirname "$path")" && pwd)/$(basename "$path")"
fi
else
echo "$path"
fi
}
REPO_ROOT=$(safe_readlink $(dirname $(dirname $(safe_readlink $0))))
echo "REPO_ROOT: $REPO_ROOT"
if [ -z "$RabbitCommon_ROOT" ]; then
if [ -f "$REPO_ROOT/../RabbitCommon/Script/RabbitCommon.sh" ]; then
export RabbitCommon_ROOT=$REPO_ROOT/../RabbitCommon
fi
fi
if [ -z "$RabbitCommon_ROOT" ]; then
echo "RabbitCommon_ROOT is not found. Please use one of the following ways to set it:"
echo "1. Set RabbitCommon_ROOT to source code root of RabbitCommon."
echo "1.1 Please download the source code of RabbitCommon from https://github.com/KangLin/RabbitCommon"
echo " ag:"
echo " git clone https://github.com/KangLin/RabbitCommon.git $REPO_ROOT/.."
echo "1.2 Then set environment variable RabbitCommon_ROOT to download root directory."
echo " ag:"
echo " export RabbitCommon_ROOT=$REPO_ROOT/../RabbitCommon "
echo ""
read -t 3 -p "Download RabbitCommon from https://github.com/KangLin/RabbitCommon? (Y/n): " INPUT || true
if [ "${INPUT:-Y}" != "Y" ] && [ "${INPUT:-Y}" != "y" ]; then
echo "Deployment cancelled"
exit 1
fi
echo "Starting download..." # 添加这行
if ! command -v git &> /dev/null; then
echo "Error: git is not installed"
exit 1
fi
echo "git clone https://github.com/KangLin/RabbitCommon.git $REPO_ROOT/../RabbitCommon"
git clone https://github.com/KangLin/RabbitCommon.git $REPO_ROOT/../RabbitCommon
if [ $? -ne 0 ]; then
echo "Failed to clone RabbitCommon"
exit 1
fi
export RabbitCommon_ROOT=$REPO_ROOT/../RabbitCommon
fi
if [ ! -f "$RabbitCommon_ROOT/Script/RabbitCommon.sh" ]; then
echo "Failed to set 'RabbitCommon_ROOT' to the RabbitCommon root, please set it correctly"
exit 1
fi
source $RabbitCommon_ROOT/Script/RabbitCommon.sh
init_global