-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
150 lines (119 loc) · 3.4 KB
/
entrypoint.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
#!/bin/bash
#set -e
bit=$(getconf LONG_BIT)
echo "bit=$bit"
if [ ! -a ~/bit.txt ]; then
echo "bit=$bit" >~/bit.txt
fi
if [ "$bit" = "64" ]; then
arch="arm64"
else
arch="armhf"
echo "温馨提醒:32位树莓派系统需要更新补丁!"
fi
echo "USE_DEFAULT_GIT = $USE_DEFAULT_GIT"
base_directory="/ysuauth"
if [ "$DOCKER" = "Haomin Kong" ]; then
base_directory="/ysuauth"
else
base_directory=$(pwd)
fi
#mode_file="$base_directory/log/mode.ysuauth"
mode_file="$LOGS_PATH/mode.ysuauth"
# -f 参数判断 $file 是否存在
if [ -f "$mode_file" ]; then
touch "mode_file"
fi
# cat /dev/null > "$mode_file"
echo "( $(date "+%Y-%m-%d %H:%M:%S") ) RUN entrypoint" >>"$mode_file"
[ -f "$BASE_PATH/remote/ready.ysuauth" ] && isUpdate=true || isUpdate=false
#检测网络链接畅通
network() {
#超时时间
local timeout=1
#目标网站
local target=www.baidu.com
echo "curl -I -s --connect-timeout ${timeout} ${target} -w %{http_code}"
#获取响应状态码
local ret_code
ret_code="$(curl -I -s --connect-timeout "${timeout}" "${target}" -w "%{http_code}" | tail -n1)"
# echo "$ret_code" >>"$mode_file"
echo "$target return $ret_code"
#curl -I -s --connect-timeout 1 www.gitee.com -w %{http_code} | tail -n1
if [ "$ret_code" = "200" ]; then
echo "Connect $target Ok!"
#网络畅通
return 0
else
echo "Fail to connect to $target!"
#网络不畅通
return 1
fi
return 1
}
echo "isUpdate = $isUpdate"
# 判断是否已经Update
if [ "$isUpdate" = true ]; then
echo "Check Time:"
more "$BASE_PATH/remote/check_date.ysuauth"
echo "Last end time:"
more "$BASE_PATH/remote/update_date.ysuauth"
mode="git"
else
echo "还未clone仓库"
mode="local"
if [ "$USE_DEFAULT_GIT" = "True" ]; then
echo "设置->默认使用Git版本"
if network; then
echo "联网状态->已经连接到互联网!"
echo "Update脚本->前台阻塞执行Update!"
if python3 "update.py" -i; then
mode="git"
else
mode="local"
fi
[ -f "$BASE_PATH/remote/ready.ysuauth" ] && isUpdate=true || isUpdate=false
if [ "$isUpdate" = true ]; then
echo "Update脚本->更新完毕!"
mode="git"
else
echo "Update脚本->更新失败!"
echo "Update脚本->后台静默等待网络并执行Update!"
python3 "update.py" -w &
mode="local"
fi
else
echo "联网状态->还未连接到互联网!"
echo "Update脚本->后台静默等待网络并执行Update!"
python3 "update.py" -w &
mode="local"
fi
fi
fi
echo "mode = $mode"
if ! ping -c 5 www.gitee.com; then
echo "Can't ping to www.gitee.com"
mode="local"
fi
if [ ! "$USE_DEFAULT_GIT" = "True" ] || [ ! "$mode" = "git" ]; then
mode="local"
fi
if [ "$mode" = "git" ]; then
echo "最终决定!Git模式!"
echo "[git仓库目录结构类型]新版目录结构!"
if [ ! -d ""$base_directory/remote/allfiles/src"" ]; then
script_directory="$base_directory/remote/allfiles/src"
else
echo "[git仓库目录结构类型]旧版目录结构!"
script_directory="$base_directory/remote/allfiles/ysuauth_python/src"
fi
else
echo "最终决定!Local模式!"
script_directory="$base_directory/src"
fi
echo "脚本文件路径$script_directory"
cd "$script_directory" || exit
python3 "auto_auth.py"
cd "$base_directory" || exit
python3 "update.py"
reboot