-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-version.sh
More file actions
executable file
·168 lines (142 loc) · 5.57 KB
/
Copy pathupdate-version.sh
File metadata and controls
executable file
·168 lines (142 loc) · 5.57 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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/env bash
set -euo pipefail
REPO="anomalyco/opencode"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
get_hash() {
local url="$1"
local temp_file
temp_file=$(mktemp)
trap 'rm -f "$temp_file"' RETURN
if ! curl -sfL --fail "$url" -o "$temp_file"; then
echo ""
return 1
fi
local raw_hash
raw_hash=$(sha256sum "$temp_file" | cut -d' ' -f1)
nix hash convert --hash-algo sha256 --to sri "$raw_hash"
}
# 1. Get version
if [ -n "${1:-}" ]; then
version="$1"
echo "Version provided from argument: $version"
else
echo "Fetching latest version from GitHub..."
version=$(curl -fsSL --connect-timeout 10 --max-time 30 --retry 3 --retry-delay 3 --retry-all-errors "https://api.github.com/repos/$REPO/releases/latest" | \
grep -oP '"tag_name":\s*"v\K[^"]+' || true)
if [[ -z "$version" ]]; then
echo "Error: Failed to fetch latest version from GitHub."
exit 1
fi
echo "Latest version: $version"
fi
# Strip leading 'v' if present
version="${version#v}"
echo "------------------------------------------------"
echo "Target Version: $version"
echo "------------------------------------------------"
# 2. Define URLs
url_cli_linux_x64="https://github.com/$REPO/releases/download/v${version}/opencode-linux-x64.tar.gz"
url_cli_linux_arm64="https://github.com/$REPO/releases/download/v${version}/opencode-linux-arm64.tar.gz"
url_cli_darwin_x64="https://github.com/$REPO/releases/download/v${version}/opencode-darwin-x64.zip"
url_cli_darwin_arm64="https://github.com/$REPO/releases/download/v${version}/opencode-darwin-arm64.zip"
url_desktop_amd64="https://github.com/$REPO/releases/download/v${version}/opencode-desktop-linux-amd64.deb"
url_desktop_arm64="https://github.com/$REPO/releases/download/v${version}/opencode-desktop-linux-arm64.deb"
placeholder="sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
# 3. Download and compute hashes
echo ""
echo "=== CLI Hashes ==="
echo "Computing hash for opencode CLI linux-x64..."
hash_cli_linux_x64=$(get_hash "$url_cli_linux_x64")
if [[ -z "$hash_cli_linux_x64" ]]; then
echo "Error: Failed to download opencode CLI linux-x64."
exit 1
fi
echo " Hash: $hash_cli_linux_x64"
echo "Computing hash for opencode CLI linux-arm64..."
hash_cli_linux_arm64=$(get_hash "$url_cli_linux_arm64")
if [[ -z "$hash_cli_linux_arm64" ]]; then
echo "Warning: Failed to download opencode CLI linux-arm64. Setting hash to placeholder."
hash_cli_linux_arm64="$placeholder"
else
echo " Hash: $hash_cli_linux_arm64"
fi
echo "Computing hash for opencode CLI darwin-x64..."
hash_cli_darwin_x64=$(get_hash "$url_cli_darwin_x64")
if [[ -z "$hash_cli_darwin_x64" ]]; then
echo "Warning: Failed to download opencode CLI darwin-x64. Setting hash to placeholder."
hash_cli_darwin_x64="$placeholder"
else
echo " Hash: $hash_cli_darwin_x64"
fi
echo "Computing hash for opencode CLI darwin-arm64..."
hash_cli_darwin_arm64=$(get_hash "$url_cli_darwin_arm64")
if [[ -z "$hash_cli_darwin_arm64" ]]; then
echo "Warning: Failed to download opencode CLI darwin-arm64. Setting hash to placeholder."
hash_cli_darwin_arm64="$placeholder"
else
echo " Hash: $hash_cli_darwin_arm64"
fi
echo ""
echo "=== Desktop Hashes ==="
echo "Computing hash for opencode-desktop linux-amd64..."
hash_desktop_amd64=$(get_hash "$url_desktop_amd64")
if [[ -z "$hash_desktop_amd64" ]]; then
echo "Error: Failed to download opencode-desktop amd64."
exit 1
fi
echo " Hash: $hash_desktop_amd64"
echo "Computing hash for opencode-desktop linux-arm64..."
hash_desktop_arm64=$(get_hash "$url_desktop_arm64")
if [[ -z "$hash_desktop_arm64" ]]; then
echo "Warning: Failed to download opencode-desktop arm64. Setting hash to placeholder."
hash_desktop_arm64="$placeholder"
else
echo " Hash: $hash_desktop_arm64"
fi
# 4. Update version.json
echo ""
echo "Updating version.json..."
cat > "$SCRIPT_DIR/version.json" << EOF
{
"version": "$version"
}
EOF
# 5. Update opencode.nix (CLI — Linux + Darwin)
echo "Updating opencode.nix..."
opencode_file="$SCRIPT_DIR/opencode.nix"
if [[ ! -f "$opencode_file" ]]; then
echo "Error: $opencode_file not found."
exit 1
fi
hash_pattern='sha256-[A-Za-z0-9+/]*='
temp_file=$(mktemp)
sed -E \
-e "s|\"$hash_pattern\"; # cli-linux-x64|\"$hash_cli_linux_x64\"; # cli-linux-x64|" \
-e "s|\"$hash_pattern\"; # cli-linux-arm64|\"$hash_cli_linux_arm64\"; # cli-linux-arm64|" \
-e "s|\"$hash_pattern\"; # cli-darwin-x64|\"$hash_cli_darwin_x64\"; # cli-darwin-x64|" \
-e "s|\"$hash_pattern\"; # cli-darwin-arm64|\"$hash_cli_darwin_arm64\"; # cli-darwin-arm64|" \
"$opencode_file" > "$temp_file"
mv "$temp_file" "$opencode_file"
# 6. Update opencode-desktop.nix (Desktop — Linux only)
echo "Updating opencode-desktop.nix..."
desktop_file="$SCRIPT_DIR/opencode-desktop.nix"
if [[ ! -f "$desktop_file" ]]; then
echo "Error: $desktop_file not found."
exit 1
fi
temp_file=$(mktemp)
sed -E \
-e "s|\"$hash_pattern\"; # desktop-amd64|\"$hash_desktop_amd64\"; # desktop-amd64|" \
-e "s|\"$hash_pattern\"; # desktop-arm64|\"$hash_desktop_arm64\"; # desktop-arm64|" \
"$desktop_file" > "$temp_file"
mv "$temp_file" "$desktop_file"
echo "------------------------------------------------"
echo "Success! Updated to version $version"
echo "------------------------------------------------"
echo " CLI linux-x64: $hash_cli_linux_x64"
echo " CLI linux-arm64: $hash_cli_linux_arm64"
echo " CLI darwin-x64: $hash_cli_darwin_x64"
echo " CLI darwin-arm64: $hash_cli_darwin_arm64"
echo " Desktop linux-amd64: $hash_desktop_amd64"
echo " Desktop linux-arm64: $hash_desktop_arm64"
echo "------------------------------------------------"