Skip to content

Commit fbff9fc

Browse files
committed
refactor(shell): rewrite OpenClash installer workflow
1 parent b28f571 commit fbff9fc

6 files changed

Lines changed: 1058 additions & 1355 deletions

File tree

.github/scripts/test_installers.sh

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,26 @@ run_suite() (
1818
temporary=$(mktemp -d)
1919
trap 'rm -rf "$temporary"' EXIT HUP INT TERM
2020

21-
EXT=apk
22-
metadata_file="$temporary/flat.json"
23-
printf '%s\n' \
24-
'[' \
25-
' {' \
26-
' "name": "/dev/luci-app-openclash-1.2.3.apk",' \
27-
' "hash": "YWJj",' \
28-
' "size": 123' \
29-
' }' \
30-
']' >"$metadata_file"
31-
[ "$(parse_package_metadata "$metadata_file")" = \
32-
'luci-app-openclash-1.2.3.apk|YWJj|123' ] ||
33-
fail "$installer metadata parsing"
34-
3521
version_file="$temporary/version"
3622
printf '%s\n' 'v0.47.999' >"$version_file"
3723
[ "$(parse_package_version "$version_file")" = '0.47.999' ] ||
3824
fail "$installer version parsing"
3925

4026
attempts=''
41-
attempt_count=0
4227
curl_download() {
43-
attempt_count=$((attempt_count + 1))
4428
attempts="${attempts}${2}\n"
45-
[ "$attempt_count" -eq 3 ]
29+
case "$2" in
30+
https://raw.example/*) return 0 ;;
31+
*) return 1 ;;
32+
esac
4633
}
4734
verify_package_file() {
4835
return 0
4936
}
5037
RAW_PACKAGE_PREFIX='https://raw.example/repository'
5138
JSDELIVR_PACKAGE_PREFIX='https://cdn.example/repository@'
5239
GH_PROXY_PREFIX='https://proxy.example/'
53-
download_openclash_package deadbeef package.apk '' '' "$temporary/package.apk" ||
40+
download_openclash_package deadbeef package.apk "$temporary/package.apk" ||
5441
fail "$installer download fallback"
5542
expected_attempts='https://cdn.example/repository@deadbeef/dev/package.apk
5643
https://proxy.example/https://raw.example/repository/deadbeef/dev/package.apk

py/sync_installer_common.py

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python3
2-
"""Keep shared installer helpers synchronized while publishing standalone scripts."""
2+
"""Synchronize shared helpers while keeping both public installers standalone."""
33

44
from __future__ import annotations
55

@@ -13,9 +13,7 @@
1313
LIGHT_INSTALLER = ROOT / "shell" / "install_openclash_dev.sh"
1414
FULL_INSTALLER = ROOT / "shell" / "install_openclash_dev_update.sh"
1515

16-
# The full installer is canonical for helpers whose behavior is intentionally
17-
# identical. The lightweight file embeds synchronized copies so its public
18-
# curl | sh entrypoint remains self-contained.
16+
# The full installer is canonical for every helper used by both entrypoints.
1917
SHARED_FUNCTIONS = {
2018
"print_line",
2119
"print_step",
@@ -24,32 +22,42 @@
2422
"log_error",
2523
"log_ok",
2624
"die",
25+
"logo",
2726
"restore_feed",
27+
"cleanup",
28+
"init_runtime",
29+
"detect_distribution",
2830
"detect_environment",
31+
"select_feed_file",
32+
"rewrite_feed_to_mirror",
33+
"prepare_temporary_feed",
2934
"package_update",
3035
"package_install_dependencies",
31-
"set_feed_file",
32-
"enable_temporary_nju_mirror",
33-
"fetch_package_metadata",
34-
"parse_package_metadata",
36+
"install_dependencies",
37+
"check_required_commands",
38+
"curl_download",
39+
"fetch_package_refs_route",
40+
"fetch_package_branch_sha",
41+
"download_commit_file",
3542
"parse_package_version",
36-
"resolve_package_metadata",
37-
"verify_file_size",
38-
"verify_sha256_base64",
43+
"package_file_name",
44+
"apk_supports_allow_downgrade",
3945
"verify_package_file",
40-
"prepare_latest_package",
41-
"install_openclash_package",
42-
"extract_version_from_filename",
46+
"download_openclash_package",
4347
"normalize_version",
48+
"get_installed_version",
49+
"install_openclash_package",
50+
"preserve_failed_package",
51+
"install_latest_openclash_package",
4452
"has_cpu_flag",
4553
"has_all_cpu_flags",
4654
"detect_mips_float",
4755
"detect_loongarch_abi",
56+
"detect_core_arch",
4857
"get_effective_core_type",
49-
"get_core_path",
50-
"verify_core_version",
51-
"update_core",
52-
"start_openclash",
58+
"configure_base_uci",
59+
"run_core_update",
60+
"enable_and_restart_openclash",
5361
}
5462

5563

@@ -85,10 +93,10 @@ def synchronized_light_content(light: str, full: str) -> str:
8593
raise ValueError(f"missing shared installer functions: {sorted(missing)}")
8694

8795
replacements = sorted(
88-
[
96+
(
8997
(light_functions[name], full_functions[name].content)
9098
for name in SHARED_FUNCTIONS
91-
],
99+
),
92100
key=lambda item: item[0].start,
93101
reverse=True,
94102
)

0 commit comments

Comments
 (0)