#!/bin/sh # # Radicle installation script. # set -e url() { echo "https://files.radicle.xyz/latest/$1/radicle-$1.tar.gz" } info() { printf "\033[36m$*\033[0m\n" } warn() { printf "\033[33m$*\033[0m\n" } success() { printf "\033[32m✓\033[0m Radicle was installed successfully.\n" printf "\n" } error() { printf "\033[31merror\033[0m: $*\n" >&2 } fatal() { error "$@" exit 1 } usage() { echo "Usage" echo echo " $0 []" echo echo " This script will install the Radicle binaries under '$RAD_PATH'". echo " To change the location, set \$RAD_PATH to a different directory." echo echo " Your Radicle home is set to '$RAD_HOME'." echo " To change it, set \$RAD_HOME to a different directory." echo echo "Options" echo echo " --no-modify-path Do not modify the PATH environment variable" echo " --help, -h Show this help message and exit" echo echo "Environment" echo echo " RAD_HOME Radicle home directory" echo " RAD_PATH Radicle binaries directory" echo " RAD_MANPATH Radicle manual pages directory" } target() { TARGET="" case "$(uname)/$(uname -m)" in Darwin/arm64) TARGET="aarch64-apple-darwin" ;; Darwin/x86_64) TARGET="x86_64-apple-darwin" ;; Linux/arm64|Linux/aarch64) TARGET="aarch64-unknown-linux-musl" ;; Linux/x86_64) TARGET="x86_64-unknown-linux-musl" ;; *) fatal "Your operating system is currently unsupported. Sorry!" ;; esac echo $TARGET } tempdir() { if [ -n "$TMPDIR" ]; then echo "$TMPDIR" elif [ -d "/tmp" ]; then echo "/tmp" else fatal "Could not locate temporary directory" fi } in_path() { IFS=":" for dir in $PATH; do if [ "$dir" = "$1" ]; then return 0 # The path is in $PATH fi done return 1 # The path is not in $PATH } get_started() { echo success printf "Get started by creating your Radicle key pair with \033[35m\`rad auth\`\033[0m.\n" } main() { RAD_HOME=${RAD_HOME:-"$HOME/.radicle"} RAD_PATH=${RAD_PATH:-"$RAD_HOME/bin"} RAD_MANPATH=${RAD_MANPATH:-"$RAD_HOME/man"} SHELL=${SHELL:-"/bin/sh"} NO_MODIFY_PATH=false case "$1" in --no-modify-path) NO_MODIFY_PATH=true ;; -h|--help) usage exit 0 ;; "") # No arguments, normal operation ;; *) error "unrecognized argument '$1'" echo ; usage ; exit 1 ;; esac if [ "$#" -gt 1 ]; then error "too many arguments" echo ; usage ; exit 1 fi echo echo "👾 Welcome to Radicle" echo info "Detecting operating system..." TARGET=$(target) if ! command -v tar >/dev/null 2>&1; then fatal "Please install 'tar' and try again" fi if ! command -v curl >/dev/null 2>&1; then fatal "Please install 'curl' and try again" fi info "Installing radicle into $RAD_PATH..." mkdir -p "$RAD_PATH" mkdir -p "$RAD_MANPATH/man1" curl -# -L "$(url "$TARGET")" | tar -xz --strip-components=1 -C "$RAD_PATH" chmod +x \ $RAD_PATH/radicle-node \ $RAD_PATH/radicle-httpd \ $RAD_PATH/rad \ $RAD_PATH/rad-web \ $RAD_PATH/git-remote-rad info "Installing manuals into $RAD_MANPATH..." mv "$RAD_PATH"/*.1 "$RAD_MANPATH"/man1/ if ! command -v git >/dev/null 2>&1; then warn warn "Warning: a Git installation was not detected on your system." warn "Warning: please install Git for Radicle to work correctly." fi # If radicle is not in $PATH, add it here. if $NO_MODIFY_PATH; then info "Not modifying shell path variable, as requested." get_started elif in_path $RAD_PATH; then info "Radicle is configured in shell already, not modifying." get_started else PROFILE="" case $SHELL in */zsh) PROFILE=$HOME/.zshenv ;; */bash) PROFILE=$HOME/.bashrc ;; */fish) PROFILE=$HOME/.config/fish/config.fish ;; */ash) PROFILE=$HOME/.profile ;; */csh) PROFILE=$HOME/.cshrc ;; esac if [ -z "$PROFILE" ]; then warn "Warning: unable to update your PATH variable." warn "Warning: please manually add $RAD_PATH to your PATH." get_started else info "Configuring path variable in ~${PROFILE#$HOME}..." echo >> "$PROFILE" echo "# Added by Radicle." >> "$PROFILE" echo "export PATH=\"\$PATH:$RAD_PATH\"" >> "$PROFILE" echo success printf "Before running Radicle for the first time,\n" printf "run \033[34m\`source ~${PROFILE#$HOME}\`\033[0m or open a new terminal.\n" printf "\n" printf "Then, create your radicle key pair with \033[35m\`rad auth\`\033[0m.\n" fi fi } main "$@"