Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add simple bb installer script #6376

Merged
merged 6 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions barretenberg/cpp/installation/bbup
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!/usr/bin/env bash
set -e

BB_HOME=${BB_HOME-"$HOME/.bb"}

main() {
need_cmd curl

while [[ $1 ]]; do
case $1 in
--) shift; break;;

-v|--version) shift; BBUP_VERSION=$1;;
-h|--help)
usage
exit 0
;;
*)
err "internal error: unknown option "$1"\n";;
esac; shift
done

if [ -z "$BBUP_VERSION" ]; then
err "--version option is required"
fi

BBUP_REPO=AztecProtocol/aztec-packages

PLATFORM="$(uname -s)"
case $PLATFORM in
Linux)
PLATFORM="linux-gnu"
;;
Darwin)
PLATFORM="apple-darwin"
;;
*)
err "unsupported platform: $PLATFORM"
;;
esac

# Fetch system's architecture.
ARCHITECTURE="$(uname -m)"

# Align ARM naming for release fetching.
if [ "${ARCHITECTURE}" = "arm64" ]; then
ARCHITECTURE="aarch64" # Align release naming.
fi

# Reject unsupported architectures.
if [ "${ARCHITECTURE}" != "x86_64" ] && [ "${ARCHITECTURE}" != "aarch64" ]; then
err "unsupported architecure: $ARCHITECTURE-$PLATFORM"
fi

BBUP_TAG=$BBUP_VERSION
# Normalize versions (handle channels, versions without v prefix)
if [[ "$BBUP_VERSION" == [[:digit:]]* ]]; then
# Add v prefix
BBUP_VERSION="v${BBUP_VERSION}"
BBUP_TAG="aztec-packages-${BBUP_VERSION}"
fi

say "installing bb (version ${BBUP_VERSION} with tag ${BBUP_TAG})"

RELEASE_URL="https://github.com/${BBUP_REPO}/releases/download/${BBUP_TAG}"
BIN_TARBALL_URL="${RELEASE_URL}/barretenberg-${ARCHITECTURE}-${PLATFORM}.tar.gz"

# Download the binary's tarball and unpack it into the .bb directory.
say "downloading bb to '$BB_HOME'"
ensure curl -# -L $BIN_TARBALL_URL | tar -xzC $BB_HOME

say "done"
}

usage() {
cat 1>&2 <<EOF
The installer for bb.
Update or revert to a specific bb version with ease.
USAGE:
bb <OPTIONS>
OPTIONS:
-h, --help Print help information
-v, --version Install a specific version (required)
EOF
}

say() {
printf 'bbup: %s\n' "$1"
}

warn() {
say "warning: ${1}" >&2
}

err() {
say "$1" >&2
exit 1
}

need_cmd() {
if ! check_cmd "$1"; then
err "need '$1' (command not found)"
fi
}

check_cmd() {
command -v "$1" >/dev/null 2>&1
}

# Run a command that should never fail. If the command fails execution
# will immediately terminate with an error showing the failing
# command.
ensure() {
if ! "$@"; then err "command failed: $*"; fi
}

main "$@" || exit 1
48 changes: 48 additions & 0 deletions barretenberg/cpp/installation/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash
set -e

echo Installing bbup...

BB_HOME=${BB_HOME-"$HOME/.bb"}

BBUP_BIN_URL=${BBUP_BIN_URL-"https://raw.githubusercontent.com/AztecProtocol/aztec-packages/master/barretenberg/cpp/installation/bbup"}
BBUP_BIN_PATH="$BB_HOME/bbup"

# Create the .bb directory and bbup binary if it doesn't exist.
mkdir -p $BB_HOME
curl -# -L $BBUP_BIN_URL -o $BBUP_BIN_PATH
chmod +x $BBUP_BIN_PATH

# Store the correct profile file (i.e. .profile for bash or .zshrc for ZSH).
case $SHELL in
*/zsh)
PROFILE=$HOME/.zshrc
PREF_SHELL=zsh
;;
*/bash)
PROFILE=$HOME/.bashrc
PREF_SHELL=bash
;;
*/fish)
PROFILE=$HOME/.config/fish/config.fish
PREF_SHELL=fish
;;
*/ash)
PROFILE=$HOME/.profile
PREF_SHELL=ash
;;
*)
echo "bbup: could not detect shell, manually add ${BB_HOME} to your PATH."
exit 1
;;
esac

# Only add bbup if it isn't already in PATH.
if [[ ":$PATH:" != *":${BB_HOME}:"* ]]; then
# Add the .bb directory to the path and ensure the old PATH variables remain.
echo >>$PROFILE && echo "export BB_HOME=\"$BB_HOME\"" >>$PROFILE
echo >>$PROFILE && echo "export PATH=\"\$PATH:\$BB_HOME\"" >>$PROFILE
fi

echo && echo "Detected your preferred shell is ${PREF_SHELL} and added bbup to PATH. Run 'source ${PROFILE}' or start a new terminal session to use bbup."
echo "Then, simply run 'bbup' to install bb."
Loading