Created
February 10, 2023 04:35
-
-
Save iamkirkbater/2a0ca461b9b63164ce4bfa021a3791fd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -o pipefail | |
usage() { | |
cat >&2 <<EOF | |
usage: $0 stringWith@@PLATFORM@@toReplace --ARMARCH --X86ARCH [ OPTIONS ] | |
requires one of each of the x86 arch options below and arm arch options below. | |
ARMARCH Options: | |
--arm64 target arm64 binary for arm arch | |
--aarch64 target aarch64 binary for arm arch | |
X86ARCH Options: | |
--amd64 target amd64 binary for x86 arch | |
--x86_64 target x86_64 binary for x86 arch | |
Additonal Options: | |
-v | --verbose Enables more verbose output | |
EOF | |
} | |
# Remove this if check if there is not a need for parameters to be passed in. | |
if [ $# -lt 3 ]; then | |
usage | |
exit 1 | |
fi | |
REPLACESTR= | |
VERBOSE=false | |
while [ "$1" != "" ]; do | |
case $1 in | |
--aarch64 ) ARMARCH=aarch64 | |
;; | |
--arm64 ) ARMARCH=arm64 | |
;; | |
--amd64 ) X86ARCH=amd64 | |
;; | |
--x86_64 ) X86ARCH=x86_64 | |
;; | |
-v | --verbose ) VERBOSE=true | |
;; | |
--* ) echo "Unexpected parameter $1" >&2 | |
usage | |
exit 1 | |
;; | |
* ) if [[ -z $REPLACESTR ]]; | |
then | |
REPLACESTR=$1 | |
else | |
echo "Too many positional arguments." >&2 | |
usage | |
exit 1 | |
fi | |
;; | |
esac | |
shift | |
done | |
if [[ -z $REPLACESTR ]] | |
then | |
echo "Missing required string." >&2 | |
usage | |
exit 1 | |
fi | |
if [[ $(grep "@@PLATFORM@@" <<< $REPLACESTR | wc -l) -eq 0 ]] | |
then | |
echo "Replacement string needs '@@PLATFORM@@' to replace." >&2 | |
usage | |
exit 1 | |
fi | |
if [[ -z $ARMARCH ]] | |
then | |
echo "Missing ARMARCH parameter." >&2 | |
usage | |
exit 1 | |
fi | |
if [[ -z $X86ARCH ]] | |
then | |
echo "Missing X86ARCH parameter." >&2 | |
usage | |
exit 1 | |
fi | |
arch=$(uname -m) | |
if [[ $arch == "arm64" ]] || [[ $arch == "aarch64" ]]; | |
then | |
sed -e "s/@@PLATFORM@@/$ARMARCH/" <<< $REPLACESTR | |
exit 0 | |
fi | |
if [[ $arch == "amd64" ]] || [[ $arch == "x86_64" ]]; | |
then | |
sed -e "s/@@PLATFORM@@/$X86ARCH/" <<< $REPLACESTR | |
exit 0 | |
fi | |
echo "Unexpected architecture from 'uname -m': $arch" >&2 | |
exit 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment