From d13ed4ccddc2ccb94a877fbba7ad87fb0f8f6bc0 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Wed, 8 Jan 2020 04:33:12 +0300 Subject: Travis: verify executable file bitness --- .ci/.gitattributes | 1 + .ci/verify_arch.sh | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 .ci/.gitattributes create mode 100755 .ci/verify_arch.sh (limited to '.ci') diff --git a/.ci/.gitattributes b/.ci/.gitattributes new file mode 100644 index 0000000..dfdb8b7 --- /dev/null +++ b/.ci/.gitattributes @@ -0,0 +1 @@ +*.sh text eol=lf diff --git a/.ci/verify_arch.sh b/.ci/verify_arch.sh new file mode 100755 index 0000000..aafc5e8 --- /dev/null +++ b/.ci/verify_arch.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash + +set -o errexit -o nounset -o pipefail + +script_name="$( basename -- "${BASH_SOURCE[0]}" )" +readonly script_name + +elf_file_class() { + local path + for path; do + od --address-radix=n --skip-bytes=4 --read-bytes=1 --format=x1 -- "$path" + done +} + +arch_to_file_class() { + local arch + for arch; do + case "$arch" in + x86) + echo '01' + ;; + x64) + echo '02' + ;; + *) + echo "$script_name: unsupported architecture: $arch" >&2 + return 1 + ;; + esac + done +} + +main() { + if [ "$#" -ne 2 ]; then + echo "usage: $script_name BIN_PATH ARCH" >&2 + return 1 + fi + + local path="$1" + local arch="$2" + + local expected + expected=" $( arch_to_file_class "$arch" )" + local actual + actual="$( elf_file_class "$path" )" + + if [ "$expected" = "$actual" ]; then + echo "$script_name: file '$path' matches architecture '$arch'" + else + echo "$script_name: file '$path' DOES NOT match architecture '$arch'" + echo "$script_name: expected ELF file class '$expected', actual file class is '$actual'" >&2 + return 1 + fi +} + +main "$@" -- cgit v1.2.3