Skip to content

Instantly share code, notes, and snippets.

@SkyN9ne
Forked from mattt/install.sh
Created June 20, 2024 10:03
Show Gist options
  • Save SkyN9ne/aa4787c852adee5c06909f0b3574faa7 to your computer and use it in GitHub Desktop.
Save SkyN9ne/aa4787c852adee5c06909f0b3574faa7 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
PREFIX=${PREFIX:-/usr/local}
set -eo pipefail
if ! which gh >/dev/null; then
echo "gh is not installed. Please install gh and try again."
echo "See https://github.com/cli/cli"
exit 1
fi
# Determine the machine operating system
os=""
case "$(uname -s)" in
Darwin)
os="darwin"
;;
Linux)
os="linux"
;;
CYGWIN*)
os="windows"
;;
MINGW*)
os="windows"
;;
*)
echo "error: unknown os '$(uname -s)'"
exit 1
;;
esac
# Determine the machine architecture
arch="amd64"
case "$os" in
darwin)
if [ -f /sys/devices/platform/soc/soc:firmware/soc:firmware/vendor ]; then
vendor=$(cat /sys/devices/platform/soc/soc:firmware/soc:firmware/vendor)
if [ "$vendor" = "Apple" ]; then
arch="arm64"
fi
fi
;;
linux)
if [ -f /proc/cpuinfo ]; then
if grep -q "aarch64" /proc/cpuinfo; then
arch="arm64"
fi
else
case "$(uname -m)" in
x86_64)
arch="amd64"
;;
i686)
arch="386"
;;
*)
echo "error: unknown architecture '$(uname -m)'"
exit 1
;;
esac
fi
;;
windows)
case "$(uname -m)" in
x86_64)
arch="amd64"
;;
i686)
arch="386"
;;
*)
echo "error: unknown architecture '$(uname -m)'"
exit 1
;;
esac
;;
esac
# Install the latest release of the binary
(
# Create a temporary working directory
tmpdir=$(mktemp -d -t dependabot-install-XXXXXX)
cd "${tmpdir}" || exit 1
trap 'rm -rf ${tmpdir}' EXIT
# Download the release artifact
gh release download -R dependabot/cli -p "*${os}-${arch}.tar.gz" || exit 1
# Extract the release from the archive
for file in *.tar.gz; do
tar xzvf "${file}" >/dev/null 2>&1
rm "${file}"
done
# Check that the dependabot executable exists
if [ ! -f dependabot ]; then
echo "dependabot executable not found in release"
exit 1
fi
# Install the dependabot executable
if install ./dependabot "${PREFIX}/bin"; then
echo "dependabot installed successfully to ${PREFIX}/bin"
exit 0
else
echo "Couldn't install dependabot to ${PREFIX}/bin."
echo "You may need to run this script as root."
exit 1
fi
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment