Skip to content

Commit

Permalink
Improeve on it b4
Browse files Browse the repository at this point in the history
  • Loading branch information
diemogebhardt committed Nov 30, 2024
1 parent 2c7bfc1 commit 98a55c5
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions bin/verify-binary-architecture.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,21 @@ BINARY_PATH="$2"
# Parse target architecture
parse_target_architecture() {
local target_triple="$1"
local parse="x86_64|aarch64"
local error="unknown target architecture"
echo "$target_triple" | grep -Eo "$parse" || echo "$error"
get() { echo "$target_triple"; }
parse() { grep -Eo 'x86_64|aarch64'; }
fail() { echo "unknown target architecture"; }
get | parse || fail
}
TARGET_ARCHITECTURE=$(parse_target_architecture "$TARGET_TRIPLE")

# Parse and normalize binary architecture
parse_and_normalize_binary_architecture() {
local binary_path="$1"
local parse="x86_64|x86-64|arm64|aarch64|Aarch64"
local normalize='s/x86-64/x86_64/;s/(arm64|Aarch64)/aarch64/'
local error="unknown binary architecture"
file -b "$binary_path" | (grep -Eo "$parse" | head -n1) | sed -E "$normalize" || echo "$error"
# file -b "$binary_path" \
# | grep -Eo "$parse" | head -n1 \
# | sed -E "$normalize" \
# || echo "$error"
get() { file -b "$binary_path"; }
parse() { grep -Eo 'x86_64|x86-64|arm64|aarch64|Aarch64' | head -n1; }
normalize() { sed -E 's/x86-64/x86_64/;s/(arm64|Aarch64)/aarch64/'; }
fail() { echo "unknown binary architecture"; }
get | parse | normalize || fail
}
BINARY_ARCHITECTURE=$(parse_and_normalize_binary_architecture "$BINARY_PATH")

Expand Down

0 comments on commit 98a55c5

Please sign in to comment.