|
#!/bin/bash |
|
{ |
|
set -e |
|
|
|
# Check for the --apple-silicone flag |
|
FORCE_X86_64=false |
|
while [[ "$#" -gt 0 ]]; do |
|
case $1 in |
|
--apple-silicone) FORCE_X86_64=true; shift ;; |
|
*) echo "Unknown parameter passed: $1"; exit 1 ;; |
|
esac |
|
done |
|
|
|
SUDO='' |
|
if [ "$(id -u)" != "0" ]; then |
|
SUDO='sudo' |
|
echo "This script requires superuser access." |
|
echo "You will be prompted for your password by sudo." |
|
# clear any previous sudo permission |
|
sudo -k |
|
fi |
|
|
|
|
|
# run inside sudo |
|
$SUDO bash <<SCRIPT |
|
set -e |
|
|
|
echoerr() { echo "\$@" 1>&2; } |
|
|
|
if [[ ! ":\$PATH:" == *":/usr/local/bin:"* ]]; then |
|
echoerr "Your path is missing /usr/local/bin, you need to add this to use this installer." |
|
exit 1 |
|
fi |
|
|
|
if [ "\$(uname)" == "Darwin" ]; then |
|
OS=darwin |
|
elif [ "\$(expr substr \$(uname -s) 1 5)" == "Linux" ]; then |
|
OS=linux |
|
else |
|
echoerr "This installer is only supported on Linux and MacOS" |
|
exit 1 |
|
fi |
|
|
|
ARCH="\$(uname -m)" |
|
|
|
# Force x86_64 if the --apple-silicone flag is passed |
|
if [ "$FORCE_X86_64" = true ]; then |
|
echo "Forcing architecture to x86_64 due to --apple-silicone flag" |
|
ARCH=x64 |
|
else |
|
if [ "\$ARCH" == "x86_64" ]; then |
|
ARCH=x64 |
|
elif [[ "\$ARCH" == aarch* ]]; then |
|
ARCH=arm |
|
else |
|
echoerr "unsupported arch: \$ARCH" |
|
exit 1 |
|
fi |
|
fi |
|
|
|
mkdir -p /usr/local/lib |
|
cd /usr/local/lib |
|
rm -rf heroku |
|
rm -rf ~/.local/share/heroku/client |
|
if [ \$(command -v xz) ]; then |
|
URL=https://cli-assets.heroku.com/channels/stable/heroku-\$OS-\$ARCH.tar.xz |
|
TAR_ARGS="xJ" |
|
else |
|
URL=https://cli-assets.heroku.com/channels/stable/heroku-\$OS-\$ARCH.tar.gz |
|
TAR_ARGS="xz" |
|
fi |
|
echo "Installing CLI from \$URL" |
|
if [ \$(command -v curl) ]; then |
|
curl "\$URL" | tar "\$TAR_ARGS" |
|
else |
|
wget -O- "\$URL" | tar "\$TAR_ARGS" |
|
fi |
|
# delete old heroku bin if exists |
|
rm -f \$(command -v heroku) || true |
|
rm -f /usr/local/bin/heroku |
|
ln -s /usr/local/lib/heroku/bin/heroku /usr/local/bin/heroku |
|
|
|
# on alpine (and maybe others) the basic node binary does not work |
|
# remove our node binary and fall back to whatever node is on the PATH |
|
/usr/local/lib/heroku/bin/node -v || rm /usr/local/lib/heroku/bin/node |
|
|
|
SCRIPT |
|
# test the CLI |
|
LOCATION=$(command -v heroku) |
|
echo "heroku installed to $LOCATION" |
|
heroku version |
|
} |