Skip to content

Commit 4bd6b34

Browse files
committed
Use manifest.json to extract sha256 hash
1 parent 04f90ea commit 4bd6b34

File tree

1 file changed

+23
-34
lines changed

1 file changed

+23
-34
lines changed

scripts/install.sh

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ BINARY_NAME="q"
1111
CLI_NAME="Q CLI"
1212
COMMAND_NAME="q"
1313
BASE_URL="https://desktop-release.q.us-east-1.amazonaws.com"
14-
INDEX_URL="${BASE_URL}/index.json"
14+
MANIFEST_URL="${BASE_URL}/latest/manifest.json"
1515

1616
# Installation directories
1717
MACOS_APP_DIR="/Applications"
@@ -126,25 +126,28 @@ download_file() {
126126
fi
127127
}
128128

129-
# Simple JSON parser for when jq is not available
130-
parse_json_value() {
131-
local json="$1"
132-
local key="$2"
133-
134-
# Remove whitespace and extract value
135-
echo "$json" | sed -n "s/.*\"$key\"[[:space:]]*:[[:space:]]*\"\([^\"]*\)\".*/\1/p" | head -1
136-
}
137-
138-
# Get checksum from index.json
129+
# Get checksum from manifest.json
139130
get_checksum() {
140131
local json="$1"
141132
local filename="$2"
142133

143134
if command -v jq >/dev/null 2>&1; then
144-
# Use jq to find the package with matching download filename from the latest version
145-
echo "$json" | jq -r ".versions[-1].packages[] | select(.download | endswith(\"$filename\")) | .sha256 // empty"
135+
# Use jq to find the package with matching download filename
136+
echo "$json" | jq -r ".packages[] | select(.download | endswith(\"$filename\")) | .sha256 // empty"
146137
else
147-
error "jq is required for checksum verification. Please install jq and try again."
138+
# Fallback: parse JSON manually
139+
# Normalize to single line
140+
local package_obj
141+
package_obj=$(echo "$json" | tr -d '\n\r' | grep -o '{[^}]*"download"[^}]*'"$filename"'[^}]*}')
142+
143+
if [[ -n "$package_obj" ]]; then
144+
if [[ $package_obj =~ \"sha256\"[[:space:]]*:[[:space:]]*\"([a-f0-9]{64})\" ]]; then
145+
echo "${BASH_REMATCH[1]}"
146+
return 0
147+
fi
148+
fi
149+
150+
return 1
148151
fi
149152
}
150153

@@ -268,11 +271,11 @@ download_and_verify() {
268271
download_file "$download_url" "$file_path"
269272

270273
log "Verifying download..."
271-
local index_json
272-
index_json=$(download_file "$INDEX_URL")
274+
local manifest_json
275+
manifest_json=$(download_file "$MANIFEST_URL")
273276

274277
local expected_checksum
275-
expected_checksum=$(get_checksum "$index_json" "$filename")
278+
expected_checksum=$(get_checksum "$manifest_json" "$filename")
276279

277280
if [[ -z "$expected_checksum" ]] || [[ ! "$expected_checksum" =~ ^[a-f0-9]{64}$ ]]; then
278281
error "Could not find valid checksum for $filename"
@@ -333,7 +336,9 @@ install_macos() {
333336

334337
hdiutil detach "$mount_path" -quiet
335338

336-
open "$MACOS_APP_DIR/$app_name"
339+
mkdir -p "$HOME/.local/bin"
340+
local macos_bin="$MACOS_APP_DIR/$app_name/Contents/MacOS"
341+
cp -f "$macos_bin/q" "$macos_bin/qchat" "$macos_bin/qterm" "$HOME/.local/bin/"
337342
}
338343

339344
# Install on Linux
@@ -357,24 +362,8 @@ install_linux() {
357362
log "Running installer..."
358363
chmod +x "$install_script"
359364
"$install_script"
360-
361-
success "$CLI_NAME installed successfully"
362365
}
363366

364-
# # Install shell integrations
365-
# install_integrations() {
366-
# log "Installing shell integrations..."
367-
368-
# # Check if q command is available
369-
# if command -v "$COMMAND_NAME" >/dev/null 2>&1; then
370-
# "$COMMAND_NAME" integrations install all || warning "Failed to install shell integrations"
371-
# success "Shell integrations installed"
372-
# else
373-
# warning "Could not find $COMMAND_NAME command. You may need to restart your shell or add it to your PATH."
374-
# echo "After restarting your shell, run: $COMMAND_NAME integrations install"
375-
# fi
376-
# }
377-
378367
# Cleanup function - only removes files/dirs we created
379368
cleanup() {
380369
# Remove downloaded files

0 commit comments

Comments
 (0)