Skip to content

Commit

Permalink
update CPU arch detection for rpm linux distros
Browse files Browse the repository at this point in the history
  • Loading branch information
robertpeteuil committed Feb 17, 2018
1 parent f38ba94 commit 0a3da9c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ curl -fsSL https://raw.github.com/robertpeteuil/terraform-installer/master/terra

CPU architecture is detected for each OS accordingly:

- Linux / Windows (WSL since this is a Bash script) - detected with dpkg
- Linux / Windows (WSL since this is a Bash script)
- detected with `lscpu` or by inspecting `/proc/cpuinfo`
- macOS - uses Default - only terraform CPU Arch available on macOS is `AMD64`
- Default Value - `AMD64`

Expand Down
19 changes: 11 additions & 8 deletions terraform-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# sudoInstall=true

scriptname=$(basename "$0")
scriptbuildnum="1.1.0"
scriptbuilddate="2018-02-08"
scriptbuildnum="1.1.1"
scriptbuilddate="2018-02-17"

displayVer() {
echo -e "${scriptname} ver ${scriptbuildnum} - ${scriptbuilddate}"
Expand Down Expand Up @@ -50,12 +50,15 @@ if [[ -z "$VERSION" ]]; then
VERSION=$(curl -s https://api.github.com/repos/hashicorp/terraform/releases/latest | awk '/tag_name/ {b = gensub(/("|,|v)/, "", "g", $2); print b}')
fi
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
case "$OS" in
linux)
PROC=$(dpkg --print-architecture);;
*)
PROC="amd64";;
esac
if [[ "$OS" == "linux" ]]; then
PROC=$(lscpu 2> /dev/null | awk '/Architecture/ {if($2 == "x86_64") {print "amd64"; exit} else {print "386"; exit}}')
if [[ -z $PROC ]]; then
PROC=$(cat /proc/cpuinfo | awk '/flags/ {if($0 ~ /lm/) {print "arm64"; exit} else {print "386"; exit}}')
fi
else
PROC="amd64"
fi
[[ $PROC =~ arm ]] && PROC="arm" # tarraform only lists arm in the url

# CREATE FILENAME AND DOWNLOAD LINK BASED ON GATHERED PARAMETERS
FILENAME="terraform_${VERSION}_${OS}_${PROC}.zip"
Expand Down

0 comments on commit 0a3da9c

Please sign in to comment.