返回 DeepSeek-Reasonix
decide-desktop-pointer-update.sh
根目录 / scripts / decide-desktop-pointer-update.sh
1 #!/usr/bin/env bash
2 set -euo pipefail
3
4 # Select the validated manifest that should align one Desktop channel's public
5 # pointer(s). The candidate is authoritative when it is newest. Otherwise the
6 # newest existing pointer repairs lagging compatibility aliases. Equal newer
7 # versions with different content are ambiguous and fail closed.
8
9 if [ "$#" -lt 3 ]; then
10 echo "usage: $0 CHANNEL CANDIDATE_MANIFEST CURRENT_MANIFEST|- [CURRENT_MANIFEST|- ...]" >&2
11 exit 2
12 fi
13
14 script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
15 compare="$script_dir/compare-desktop-release-versions.sh"
16 channel="$1"
17 candidate_file="$2"
18 shift 2
19
20 case "$channel" in
21 stable | preview) ;;
22 *)
23 echo "unsupported Desktop pointer channel: $channel" >&2
24 exit 2
25 ;;
26 esac
27 if [ ! -f "$candidate_file" ]; then
28 echo "candidate Desktop manifest is not a readable file: $candidate_file" >&2
29 exit 2
30 fi
31
32 candidate_version="$(jq -er '.version | strings' "$candidate_file")"
33 bash "$compare" "$channel" "$candidate_version" "" >/dev/null
34 selected_file="$candidate_file"
35 selected_version="$candidate_version"
36 selected_is_candidate=1
37
38 for current_file in "$@"; do
39 if [ "$current_file" = "-" ]; then
40 continue
41 fi
42 if [ ! -f "$current_file" ]; then
43 echo "current Desktop manifest is not a readable file: $current_file" >&2
44 exit 2
45 fi
46
47 current_version="$(jq -er '.version | strings' "$current_file")"
48 if [ "$(bash "$compare" "$channel" "$current_version" "$selected_version")" = "update" ]; then
49 selected_file="$current_file"
50 selected_version="$current_version"
51 selected_is_candidate=0
52 elif [ "$current_version" = "$selected_version" ] &&
53 [ "$selected_is_candidate" -eq 0 ] &&
54 ! cmp -s "$current_file" "$selected_file"; then
55 echo "conflicting Desktop $channel pointers have the same newer version $current_version" >&2
56 exit 1
57 fi
58 done
59
60 needs_update=0
61 for current_file in "$@"; do
62 if [ "$current_file" = "-" ] || ! cmp -s "$selected_file" "$current_file"; then
63 needs_update=1
64 fi
65 done
66
67 if [ "$needs_update" -eq 1 ]; then
68 printf 'update\t%s\n' "$selected_file"
69 else
70 echo skip
71 fi
72
72 lines BASH