#!/bin/sh # Copyright (c) 2018-2022 Codenotary, Inc. All Rights Reserved. # This software is released under Apache License 2.0. # The full license information can be found under: # https://www.apache.org/licenses/LICENSE-2.0 set -e version_string=$(curl -sL https://api.github.com/repos/codenotary/cas/releases/latest | awk '/tag_name/ {gsub(/"/,""); gsub(/,/,""); print $2}') base_url=https://github.com/codenotary/cas/releases/latest/download echo "Latest available release for cas is: $version_string" linux_file="$base_url/cas-$version_string-linux-amd64-static" windows_file="$base_url/cas-version_string-windows-amd64.exe" mac_file="$base_url/cas-$version_string-darwin-amd64" os_name=$(uname -s) case "${os_name}" in Linux*) target=$linux_file;; Darwin*) target=$mac_file;; FreeBSD*) target=$linux_file;; CYGWIN*) target="$windows_file" && out=".exe";; MINGW*) target="$windows_file" && out=".exe";; *) echo "Unsupported runner OS, aborting CAS Download" && exit 1;; esac http_code=$(curl -s -L "$target" -o cas -w "%{http_code}\n") echo "Downloading cas..." if [[ "$http_code" -ne 200 ]]; then echo -en "Server responded with $http_code, please visit our releases page to manually download at https://github.com/codenotary/cas/releases\n" rm -f cas exit 2 fi chmod +x ./cas user_bin="$HOME/.local/bin" case $PATH in *:"$user_bin":* | "$user_bin":* | *:"$user_bin") default_bin=$user_bin ;; *) default_bin='/usr/local/bin' ;; esac printf "Install location [default: %s]: " "$default_bin" read -r bindir < /dev/tty bindir=${bindir:-$default_bin} while ! test -d "$bindir"; do echo "Directory $bindir does not exist" printf "Install location [default: %s]: " "$default_bin" read -r bindir < /dev/tty bindir=${bindir:-$default_bin} done if test -w "$bindir"; then mv cas "$bindir/" else echo "Using SUDO to install $bindir/cas" sudo mv cas "$bindir/" fi echo "$("$bindir"/cas --version | head -1) has been installed to:" echo " • $bindir/cas" echo "" echo -en "🎉Done \n\nYou can now use the community attestation service (https://cas.codenotary.com) by running: $ cas\n\n" echo -en "To get started set your API key you received by email and login: $ export CAS_API_KEY=; cas login\n\n" echo -en "You can find the online documentation here: https://github.com/codenotary/cas\n\n"