#!/bin/sh set -eu SUPPORTED_TARGETS="aarch64-apple-darwin x86_64-apple-darwin aarch64-unknown-linux-gnu x86_64-unknown-linux-gnu" BASE_URL="https://github.com/phylum-dev/cli/releases/latest/download" OPENSSL_PUBKEY=$(cat < /dev/null 2>&1; then echo "ERROR: This script requires \`${cmd}\`. Please install it and re-run this script to continue." >&2 if [ -n "${help_msg}" ]; then printf "\n" >&2 echo "${help_msg}" >&2 fi exit 1 fi } usage() { cat 1>&2 <&2 usage exit 1 ;; esac done if [ -z "${NO_VERIFY:-}" ]; then require_command openssl fi if [ -z "${TARGET:-}" ]; then TARGET="$(get_target_triple)" fi # shellcheck disable=SC2310 if ! is_supported "${TARGET}"; then echo "ERROR: Target not supported: ${TARGET}" >&2 exit 1 fi URL="${BASE_URL}/phylum-${TARGET}.zip" echo "Release archive URL: ${URL}" if [ -z "${SKIP_CONFIRM:-}" ]; then # We need stdout to be a terminal or the user won't see our prompt if ! [ -t 1 ]; then echo "ERROR: Cannot prompt for confirmation and --yes was not provided. Aborting install" >&2 exit 1 fi printf "Continue install? [y/N] " # Read from /dev/tty if stdin isn't a terminal (e.g., because this script is being piped to sh on stdin) if ! [ -t 0 ]; then read -r yn < /dev/tty else read -r yn fi yn="$(echo "${yn}" | tr "[:upper:]" "[:lower:]")" if [ "${yn}" != "y" ] && [ "${yn}" != "yes" ]; then echo "Aborting install" exit 1 fi fi tempdir="$(mktemp -d)" archive="${tempdir}/phylum.zip" # Download the archive download "${archive}" "${URL}" # Validate the archive if [ -z "${NO_VERIFY:-}" ]; then pubkey="${tempdir}/key.pub" echo "${OPENSSL_PUBKEY}" > "${pubkey}" download "${archive}.signature" "${URL}.signature" if ! openssl dgst -sha256 -verify "${pubkey}" -signature "${archive}.signature" "${archive}"; then echo "ERROR: File signature is invalid! Aborting install" >&2 exit 1 fi fi unzip -qq "${archive}" -d "${tempdir}" install_script="${tempdir}/phylum-${TARGET}/install.sh" if ! [ -f "${install_script}" ]; then echo "ERROR: install.sh not found in the downloaded archive" >&2 exit 1 fi # Run the installer sh "${install_script}" # Cleanup the temporary directory rm -r "${tempdir}"