Skip to content

Commit

Permalink
Simplify json parsing in installer, remove awk dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptibell committed Aug 10, 2024
1 parent f999281 commit ac9f7fd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
Binary file added .zip
Binary file not shown.
40 changes: 24 additions & 16 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ dependencies=(
unzip
uname
tr
awk
)

for dep in "${dependencies[@]}"; do
Expand Down Expand Up @@ -85,21 +84,30 @@ fi

# Try to extract the asset url from the response by searching for a
# matching asset name, and then picking the "url" that came before it
read RELEASE_ASSET_ID RELEASE_ASSET_NAME <<EOF
$(echo "$RELEASE_JSON_DATA" | awk -v repo="$REPOSITORY" -v pattern="$FILE_PATTERN" '
/"url":/ && $0 ~ "https://api.github.com/repos/" repo "/releases/assets/" {
gsub(/.*\/releases\/assets\/|"|,/, "", $0)
asset_number=$0
}
/"name":/ && asset_number && $0 ~ pattern {
# Remove quotes and trailing comma for clean output
gsub(/"|,/, "", $2)
print asset_number, $2
exit
}
')
EOF
if [ -z "$RELEASE_ASSET_ID" ]; then
RELEASE_ASSET_ID=""
RELEASE_ASSET_NAME=""
while IFS= read -r current_line; do
if [[ "$current_line" == *'"url":'* && "$current_line" == *"https://api.github.com/repos/$REPOSITORY/releases/assets/"* ]]; then
RELEASE_ASSET_ID="${current_line##*/releases/assets/}"
RELEASE_ASSET_ID="${RELEASE_ASSET_ID%%\"*}"
elif [[ "$current_line" == *'"name":'* ]]; then
current_name="${current_line#*: \"}"
current_name="${current_name%%\"*}"
if [[ "$current_name" =~ $FILE_PATTERN ]]; then
if [ -n "$RELEASE_ASSET_ID" ]; then
RELEASE_ASSET_ID="$RELEASE_ASSET_ID"
RELEASE_ASSET_NAME="$current_name"
break
else
RELEASE_ASSET_ID=""
fi
else
RELEASE_ASSET_ID=""
fi
fi
done <<< "$RELEASE_JSON_DATA"

if [ -z "$RELEASE_ASSET_ID" ] || [ -z "$RELEASE_ASSET_NAME" ]; then
echo "ERROR: Failed to find asset that matches the pattern \"$FILE_PATTERN\" in the latest release." >&2
exit 1
fi
Expand Down

0 comments on commit ac9f7fd

Please sign in to comment.