Apache777 commited on
Commit
fd7b5f7
·
verified ·
1 Parent(s): 4c3b445

Delete scripts

Browse files
Files changed (2) hide show
  1. scripts/release-common.sh +0 -263
  2. scripts/update-loop.sh +0 -15
scripts/release-common.sh DELETED
@@ -1,263 +0,0 @@
1
- #!/bin/sh
2
-
3
- : "${REPO_RELEASES_URL:=https://github.com/caidaoli/CLIProxyAPI/releases}"
4
- : "${RUNTIME_DIR:=/tmp/runtime}"
5
- : "${RELEASES_DIR:=$RUNTIME_DIR/releases}"
6
- : "${CURRENT_LINK:=$RUNTIME_DIR/current}"
7
- : "${CURRENT_TAG_FILE:=$RUNTIME_DIR/current.tag}"
8
- : "${DOWNLOADS_DIR:=$RUNTIME_DIR/downloads}"
9
- : "${SUPERVISOR_CONF:=/etc/supervisord.conf}"
10
- : "${SUPERVISOR_PROGRAM_NAME:=app}"
11
- : "${SUPERVISOR_UPDATER_PROGRAM_NAME:=${SUPERVISOR_PROGRAM_NAME}-updater}"
12
- : "${CURRENT_BINARY_NAME:=app}"
13
- : "${APP_BINARY_NAMES:=}"
14
-
15
- log() {
16
- timestamp=$(date '+%Y-%m-%d %H:%M:%S %z')
17
- printf '[%s] %s\n' "$timestamp" "$*" >&2
18
- }
19
-
20
- tag_to_dir_name() {
21
- printf '%s\n' "$1" | tr '/:' '__'
22
- }
23
-
24
- release_dir_for_tag() {
25
- printf '%s/%s\n' "$RELEASES_DIR" "$(tag_to_dir_name "$1")"
26
- }
27
-
28
- ensure_runtime_dirs() {
29
- mkdir -p "$RUNTIME_DIR" "$RELEASES_DIR" "$DOWNLOADS_DIR"
30
- }
31
-
32
- current_tag() {
33
- if [ -f "$CURRENT_TAG_FILE" ]; then
34
- tr -d '\n' < "$CURRENT_TAG_FILE"
35
- fi
36
- }
37
-
38
- current_binary_path() {
39
- printf '%s/%s\n' "$CURRENT_LINK" "$CURRENT_BINARY_NAME"
40
- }
41
-
42
- repo_base_url() {
43
- # Strip a trailing "/releases" (and any trailing slash) to get the repo root.
44
- printf '%s\n' "$REPO_RELEASES_URL" | sed -E 's#/+$##; s#/releases$##'
45
- }
46
-
47
- resolve_latest_tag() {
48
- # /releases/latest 302-redirects to /releases/tag/<tag>; read the final URL.
49
- effective_url=$(
50
- curl -fsSL -o /dev/null -w '%{url_effective}' "$REPO_RELEASES_URL/latest"
51
- ) || return 1
52
-
53
- tag_name=$(
54
- printf '%s\n' "$effective_url" \
55
- | sed -n 's#.*/releases/tag/##p' \
56
- | head -n 1
57
- )
58
-
59
- [ -n "$tag_name" ] || return 1
60
- printf '%s\n' "$tag_name"
61
- }
62
-
63
- fetch_latest_release_info() {
64
- tag_name=$(resolve_latest_tag) || return 1
65
-
66
- base_url=$(repo_base_url)
67
-
68
- # The expanded_assets fragment lists every asset as an <a href="..."> link.
69
- assets_html=$(curl -fsSL "$base_url/releases/expanded_assets/$tag_name") || return 1
70
-
71
- asset_path=$(
72
- printf '%s\n' "$assets_html" \
73
- | grep -Eo 'href="[^"]*/releases/download/[^"]+"' \
74
- | cut -d '"' -f 2 \
75
- | grep -E '/[^/]*linux[-_]amd64(\.tar\.gz)?$' \
76
- | head -n 1 \
77
- || true
78
- )
79
-
80
- [ -n "$asset_path" ] || return 1
81
-
82
- case "$asset_path" in
83
- http://*|https://*) asset_url=$asset_path ;;
84
- /*) asset_url="https://github.com$asset_path" ;;
85
- *) asset_url="$base_url/$asset_path" ;;
86
- esac
87
-
88
- printf '%s|%s\n' "$tag_name" "$asset_url"
89
- }
90
-
91
- load_latest_release() {
92
- release_info=$(fetch_latest_release_info) || return 1
93
- LATEST_TAG=${release_info%%|*}
94
- LATEST_ASSET_URL=${release_info#*|}
95
- }
96
-
97
- find_release_binary() {
98
- release_dir=$1
99
-
100
- for name in $APP_BINARY_NAMES; do
101
- if [ -f "$release_dir/$name" ]; then
102
- printf '%s\n' "$release_dir/$name"
103
- return 0
104
- fi
105
- done
106
-
107
- for name in $APP_BINARY_NAMES; do
108
- binary_path=$(find "$release_dir" -maxdepth 3 -type f -name "$name" | head -n 1)
109
- if [ -n "$binary_path" ]; then
110
- printf '%s\n' "$binary_path"
111
- return 0
112
- fi
113
- done
114
-
115
- file_list=$(find "$release_dir" -maxdepth 3 -type f ! -name '._*' ! -path '*/__MACOSX/*' | sort)
116
- first_file=$(printf '%s\n' "$file_list" | sed -n '1p')
117
- second_file=$(printf '%s\n' "$file_list" | sed -n '2p')
118
- if [ -n "$first_file" ] && [ -z "$second_file" ]; then
119
- printf '%s\n' "$first_file"
120
- return 0
121
- fi
122
-
123
- return 1
124
- }
125
-
126
- activate_release() {
127
- tag_name=$1
128
- release_dir=$2
129
-
130
- rm -f "$CURRENT_LINK"
131
- ln -s "$release_dir" "$CURRENT_LINK"
132
- printf '%s\n' "$tag_name" > "$CURRENT_TAG_FILE"
133
- }
134
-
135
- extract_release_binary() {
136
- source_dir=$1
137
- target_path=$2
138
- binary_path=$(find_release_binary "$source_dir" || true)
139
-
140
- if [ -z "$binary_path" ]; then
141
- return 1
142
- fi
143
-
144
- if [ "$binary_path" != "$target_path" ]; then
145
- cp "$binary_path" "$target_path"
146
- fi
147
- chmod +x "$target_path"
148
- }
149
-
150
- cleanup_workspace() {
151
- workspace=$1
152
- if [ -n "$workspace" ] && [ -d "$workspace" ]; then
153
- rm -rf "$workspace"
154
- fi
155
- }
156
-
157
- install_release() {
158
- tag_name=$1
159
- asset_url=$2
160
-
161
- ensure_runtime_dirs
162
- release_dir=$(release_dir_for_tag "$tag_name")
163
- release_binary="$release_dir/$CURRENT_BINARY_NAME"
164
-
165
- if [ -x "$release_binary" ]; then
166
- activate_release "$tag_name" "$release_dir"
167
- return 0
168
- fi
169
-
170
- workspace=$(mktemp -d "$RUNTIME_DIR/install.XXXXXX") || return 1
171
- download_name=$(basename "$asset_url")
172
- if [ -z "$download_name" ] || [ "$download_name" = "/" ] || [ "$download_name" = "." ]; then
173
- download_name="release.asset"
174
- fi
175
- download_path="$DOWNLOADS_DIR/$download_name"
176
- stage_dir="$workspace/stage"
177
-
178
- rm -f "$download_path" || {
179
- cleanup_workspace "$workspace"
180
- return 1
181
- }
182
- mkdir -p "$stage_dir" || {
183
- cleanup_workspace "$workspace"
184
- return 1
185
- }
186
- curl -fsSL "$asset_url" -o "$download_path" || {
187
- cleanup_workspace "$workspace"
188
- return 1
189
- }
190
-
191
- case "$download_path" in
192
- *.tar.gz)
193
- tar -xzf "$download_path" -C "$stage_dir" || {
194
- cleanup_workspace "$workspace"
195
- return 1
196
- }
197
- extract_release_binary "$stage_dir" "$stage_dir/$CURRENT_BINARY_NAME" || {
198
- cleanup_workspace "$workspace"
199
- return 1
200
- }
201
- ;;
202
- *)
203
- cp "$download_path" "$stage_dir/$CURRENT_BINARY_NAME" || {
204
- cleanup_workspace "$workspace"
205
- return 1
206
- }
207
- chmod +x "$stage_dir/$CURRENT_BINARY_NAME" || {
208
- cleanup_workspace "$workspace"
209
- return 1
210
- }
211
- ;;
212
- esac
213
-
214
- rm -rf "$release_dir" || {
215
- cleanup_workspace "$workspace"
216
- return 1
217
- }
218
- mv "$stage_dir" "$release_dir" || {
219
- cleanup_workspace "$workspace"
220
- return 1
221
- }
222
- cleanup_workspace "$workspace"
223
-
224
- activate_release "$tag_name" "$release_dir"
225
- }
226
-
227
- ensure_initial_release() {
228
- if load_latest_release; then
229
- if install_release "$LATEST_TAG" "$LATEST_ASSET_URL"; then
230
- return 0
231
- fi
232
- log "警告: 安装最新版本失败,尝试使用已有版本继续启动"
233
- fi
234
-
235
- [ -x "$(current_binary_path)" ]
236
- }
237
-
238
- restart_managed_service() {
239
- supervisorctl -c "$SUPERVISOR_CONF" restart "$SUPERVISOR_PROGRAM_NAME"
240
- }
241
-
242
- update_if_needed() {
243
- load_latest_release || {
244
- log "检查最新版本失败"
245
- return 1
246
- }
247
-
248
- installed_tag=$(current_tag)
249
- if [ "$LATEST_TAG" = "$installed_tag" ]; then
250
- log "当前已是最新版本: $LATEST_TAG"
251
- return 0
252
- fi
253
-
254
- log "发现新版本: ${installed_tag:-<none>} -> $LATEST_TAG"
255
- install_release "$LATEST_TAG" "$LATEST_ASSET_URL" || {
256
- log "安装新版本失败: $LATEST_TAG"
257
- return 1
258
- }
259
-
260
- if [ -n "$installed_tag" ]; then
261
- restart_managed_service
262
- fi
263
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
scripts/update-loop.sh DELETED
@@ -1,15 +0,0 @@
1
- #!/bin/sh
2
- set -eu
3
-
4
- : "${UPDATE_INTERVAL_SECONDS:=3600}"
5
- : "${RELEASE_COMMON_SH:=/usr/local/bin/release-common.sh}"
6
-
7
- . "$RELEASE_COMMON_SH"
8
-
9
- while true; do
10
- sleep "$UPDATE_INTERVAL_SECONDS"
11
- log "开始定时版本检查"
12
- if ! update_if_needed; then
13
- log "警告: 自动更新检查失败,继续运行当前版本"
14
- fi
15
- done