Skip to content

Commit

Permalink
fix: install script (#1285)
Browse files Browse the repository at this point in the history
  • Loading branch information
dprats authored Feb 19, 2025
1 parent aca10be commit b0af9e3
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 51 deletions.
120 changes: 98 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,73 +16,147 @@ A high-performance command-line interface for contributing proofs to the Nexus n

The [Nexus Network](https://docs.nexus.xyz/network) is a global distributed prover network that unites the world's computers to power a new and better Internet: the Verifiable Internet.

There have been two testnets:
There have been two testnets so far:
- First testnet: [October 08 – 28, 2024](https://blog.nexus.xyz/nexus-launches-worlds-first-open-prover-network/)
- Second testnet: [December 9 – 13, 2024](https://blog.nexus.xyz/the-new-nexus-testnet-is-live/)

- The first testnet period was in [October 08 to 28 2024](https://blog.nexus.xyz/nexus-launches-worlds-first-open-prover-network/).
- The second testnet period was in [December 9 to 13, 2024](https://blog.nexus.xyz/the-new-nexus-testnet-is-live/).

**Important:** *The Nexus network is currently in devnet. It is important to note that you cannot earn Nexus points. Instead, devnet allows developers to experiment and build with the network. Stay tuned for updates regarding future testnets.*
---

## Quick Start

### Single-User Installation

For the simplest one-command install (especially for local testing or personal use). This is what most users will want to do:

```bash
curl https://cli.nexus.xyz/ | sh
```

Running `install.sh` locally
```sh
**Note:** This script automatically installs Rust if you don’t have it and prompts for Terms of Use in an interactive shell.

Alternatively, if you’ve already downloaded `install.sh`:

```bash
./install.sh
```

If you don't have Rust installed, you will be prompted to install it.
### CI

The `install.sh` script is designed to do few things:

This comment has been minimized.

Copy link
@Dralex30

Dralex30 Feb 19, 2025

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh


1. Install Rust if it's not already installed... and do it non-interactively if possible, so it does not bother the user.
2. Prompt the user to accept the Terms of Use (via bash) and enter their node id (via the Rust program)

```sh
# this is the part in the install.sh script has the brittle `< /dev/tty` part within CI environments
(
cd "$REPO_PATH/clients/cli" || exit
cargo run --release -- --start --beta
) < /dev/tty
```



This combination of bash and Rust is a bit brittle in CI environments. Consider these approaches instead:

1. **Build from source**:
```bash
git clone https://github.com/nexus-xyz/network-api
cd network-api/clients/cli
cargo build --release
./target/release/nexus-network --start --beta
```
2. **Download the script locally** (and optionally set `NONINTERACTIVE=1` if you need it to run without prompts):
```bash
curl -sSf https://cli.nexus.xyz/ -o install.sh
chmod +x install.sh
NONINTERACTIVE=1 ./install.sh
```

Building from source or running a downloaded script gives you more control over dependencies and versions, and avoids any unexpected prompts during automated runs.

---

## Local Testing with a Local HTTP Server

If you want to simulate `curl https://cli.nexus.xyz/ | sh` **locally**:

1. In the project’s root directory, start a local server:
```sh
python3 -m http.server 8080
```
2. In a separate terminal, run:
```sh
curl -sSf http://localhost:8080/public/install.sh | sh -x
```
3. Observe the script output and verify installation logic.

If you don’t have Rust installed, you will be prompted to install it (unless `NONINTERACTIVE=1` is set).

---

## Prerequisites

### Linux

```bash
sudo apt update && sudo apt upgrade
sudo apt install build-essential pkg-config libssl-dev git-all protobuf-compiler
```

### macOS

```bash
brew install git
```

### Windows
[Install WSL](https://learn.microsoft.com/en-us/windows/wsl/install) first, then follow Linux instructions.

1. [Install WSL](https://learn.microsoft.com/en-us/windows/wsl/install).
2. Follow the Linux instructions above within WSL.

---

## Terms of Use

Use of the CLI is subject to the [Terms of Use](https://nexus.xyz/terms-of-use). First-time users will be prompted to accept the terms. For non-interactive acceptance (e.g., CI environments), use:
Use of the CLI is subject to the [Terms of Use](https://nexus.xyz/terms-of-use). First-time users running interactively will be prompted to accept these terms. For **non-interactive acceptance** (e.g., in CI), run:

```bash
NONINTERACTIVE=1 sh
NONINTERACTIVE=1 sh install.sh
```

## Prover Id
or set `NONINTERACTIVE=1` before invoking the script.

---

## Node ID

The CLI will prompt for your web prover id from the Nexus testnet or devnet on startup. It is ok to skip this prompt and a random id will be generated, but you'll be prompted again on startup until your web prover id is entered.
During the CLI’s startup, you’ll be asked for your node ID (used on Testnet or Devnet).
- To skip prompts in a non-interactive environment (`NONINTERACTIVE=1`), manually place your node ID in `~/.nexus/node-id`.

The prover id prompt is disabled when NONINTERACTIVE=1 is set. In a server environment,
you can manually overwrite $HOME/.nexus/prover-id with your full prover id.
---

## Current Limitations

- Only latest CLI version is supported
- No prebuilt binaries yet
- Proof cycle counting coming soon
- Program submission requires API key (contact [email protected])
- Only the latest CLI version is supported.
- No prebuilt binaries yet.
- Proof cycle counting is coming soon.
- Program submission requires an API key (contact [[email protected]](mailto:[email protected])).

---

## Get Help

- [Network FAQ](https://nexus.xyz/network#network-faqs)
- [Discord Community](https://discord.gg/nexus-xyz)
- [Network FAQ](https://nexus.xyz/network#network-faqs)
- [Discord Community](https://discord.gg/nexus-xyz)
- Technical issues? [Open an issue](https://github.com/nexus-xyz/network-api/issues)

---

## Repository Structure

```
```txt
network-api/
├── assets/ # Media for documentation
├── clients/
Expand All @@ -91,6 +165,8 @@ network-api/
└── public/ # Files hosted at cli.nexus.xyz
```

---

## Contributing

See [CONTRIBUTING.md](./CONTRIBUTING.md) for development setup and guidelines.
2 changes: 1 addition & 1 deletion clients/cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion clients/cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nexus-network"
version = "0.5.0"
version = "0.5.1"
edition = "2021"
rust-version = "1.75"
build = "build.rs"
Expand Down
13 changes: 3 additions & 10 deletions clients/cli/src/utils/cli_branding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,14 @@ pub const LOGO_NAME: &str = r#"
pub fn print_banner() {
println!("{}", LOGO_NAME.bright_cyan());
println!(
"{} {}\n",
"{} {} {}\n",
"Welcome to the".bright_white(),
"Nexus Network CLI".bright_cyan().bold()
"Nexus Network CLI".bright_cyan().bold(),
"v0.5.1".bright_white()
);
println!(
"{}",
"The Nexus network is a massively-parallelized proof network for executing and proving the \x1b]8;;https://docs.nexus.org\x1b\\Nexus zkVM\x1b]8;;\x1b\\.\n\n"
.bright_white()
);
}

// pub fn print_success(message: &str) {
// println!("✨ {}", message.green());
// }

// pub fn print_error(message: &str) {
// println!("❌ {}", message.red());
// }
84 changes: 67 additions & 17 deletions public/install.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
#!/bin/sh

# -----------------------------------------------------------------------------
# 1) Ensure Rust is installed.
# - First, check if rustc is available. If not, install Rust non-interactively
# using the official rustup script.
# -----------------------------------------------------------------------------
rustc --version || curl https://sh.rustup.rs -sSf | sh
NEXUS_HOME=$HOME/.nexus

# -----------------------------------------------------------------------------
# 2) Define environment variables and colors for terminal output.
# -----------------------------------------------------------------------------
NEXUS_HOME="$HOME/.nexus"
GREEN='\033[1;32m'
ORANGE='\033[1;33m'
NC='\033[0m' # No Color
NC='\033[0m' # No Color

[ -d $NEXUS_HOME ] || mkdir -p $NEXUS_HOME
# Ensure the $NEXUS_HOME directory exists.
[ -d "$NEXUS_HOME" ] || mkdir -p "$NEXUS_HOME"

# -----------------------------------------------------------------------------
# 3) Display a message if we're interactive (NONINTERACTIVE is not set) and the
# $NODE_ID is not a 28-character ID. This is for Testnet II info.
# -----------------------------------------------------------------------------
if [ -z "$NONINTERACTIVE" ] && [ "${#NODE_ID}" -ne "28" ]; then
echo "\n${ORANGE}The Nexus network is currently in Testnet II. You can now earn Nexus Points.${NC}\n\n"
echo ""
echo "${ORANGE}The Nexus network is currently in Testnet II. You can now earn Nexus Points.${NC}"
echo ""
fi

# -----------------------------------------------------------------------------
# 4) Prompt the user to agree to the Nexus Beta Terms of Use if we're in an
# interactive mode (i.e., NONINTERACTIVE is not set) and no node-id file exists.
# We explicitly read from /dev/tty to ensure user input is requested from the
# terminal rather than the script's standard input.
# -----------------------------------------------------------------------------
while [ -z "$NONINTERACTIVE" ] && [ ! -f "$NEXUS_HOME/node-id" ]; do
read -p "Do you agree to the Nexus Beta Terms of Use (https://nexus.xyz/terms-of-use)? (Y/n) " yn </dev/tty
echo ""
Expand All @@ -32,27 +54,55 @@ while [ -z "$NONINTERACTIVE" ] && [ ! -f "$NEXUS_HOME/node-id" ]; do
esac
done

# -----------------------------------------------------------------------------
# 5) Check for 'git' availability. If not found, prompt the user to install it.
# -----------------------------------------------------------------------------
git --version 2>&1 >/dev/null
GIT_IS_AVAILABLE=$?
if [ $GIT_IS_AVAILABLE != 0 ]; then
echo Unable to find git. Please install it and try again.
exit 1;
if [ "$GIT_IS_AVAILABLE" != 0 ]; then
echo "Unable to find git. Please install it and try again."
exit 1
fi



REPO_PATH=$NEXUS_HOME/network-api
# -----------------------------------------------------------------------------
# 6) Clone or update the network-api repository in $NEXUS_HOME.
# -----------------------------------------------------------------------------
REPO_PATH="$NEXUS_HOME/network-api"
if [ -d "$REPO_PATH" ]; then
echo "$REPO_PATH exists. Updating.";
(cd $REPO_PATH && git stash && git fetch --tags)
echo "$REPO_PATH exists. Updating."
(
cd "$REPO_PATH" || exit
git stash
git fetch --tags
)
else
(cd $NEXUS_HOME && git clone https://github.com/nexus-xyz/network-api)
(
cd "$NEXUS_HOME" || exit
git clone https://github.com/nexus-xyz/network-api
)
fi
(cd $REPO_PATH && git -c advice.detachedHead=false checkout $(git rev-list --tags --max-count=1))

(cd $REPO_PATH/clients/cli && cargo run --release -- --start --beta)
# -----------------------------------------------------------------------------
# 7) Check out the latest tagged commit in the repository.
# -----------------------------------------------------------------------------
(
cd "$REPO_PATH" || exit
git -c advice.detachedHead=false checkout "$(git rev-list --tags --max-count=1)"
)

# For local testing
# -----------------------------------------------------------------------------
# 8) Finally, run the Rust CLI in interactive mode. We explicitly attach
# /dev/tty to cargo's stdin so it can prompt the user, even if the script
# itself was piped in or otherwise redirected.
# -----------------------------------------------------------------------------
(
cd "$REPO_PATH/clients/cli" || exit
cargo run --release -- --start --beta
) < /dev/tty
# -----------------------------------------------------------------------------
# For local testing (e.g., staging mode), comment out the above cargo run line
# and uncomment the line below.
#
# echo "Current location: $(pwd)"
# (cd clients/cli && cargo run --release -- --start --staging)

# -----------------------------------------------------------------------------

1 comment on commit b0af9e3

@pumpdog
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#!/bin/sh

-----------------------------------------------------------------------------

1) Ensure Rust is installed.

- First, check if rustc is available. If not, install Rust non-interactively

using the official rustup script.

-----------------------------------------------------------------------------

if ! command -v rustc >/dev/null 2>&1; then
curl https://sh.rustup.rs/ -sSf | sh -s -- -y
fi

-----------------------------------------------------------------------------

2) Define environment variables and colors for terminal output.

-----------------------------------------------------------------------------

NEXUS_HOME="$HOME/.nexus"
GREEN='\033[1;32m'
ORANGE='\033[1;33m'
NC='\033[0m' # No Color

Ensure the $NEXUS_HOME directory exists.

mkdir -p "$NEXUS_HOME"

-----------------------------------------------------------------------------

3) Display a message if we're interactive (NONINTERACTIVE is not set) and the

$NODE_ID is not a 28-character ID. This is for Testnet II info.

-----------------------------------------------------------------------------

if [ -z "$NONINTERACTIVE" ] && [ "${#NODE_ID}" -ne 28 ]; then
echo ""
echo "${ORANGE}The Nexus network is currently in Testnet II. You can now earn Nexus Points.${NC}"
echo ""
fi

-----------------------------------------------------------------------------

4) Prompt the user to agree to the Nexus Beta Terms of Use if we're in an

interactive mode (i.e., NONINTERACTIVE is not set) and no node-id file exists.

-----------------------------------------------------------------------------

if [ -z "$NONINTERACTIVE" ] && [ ! -f "$NEXUS_HOME/node-id" ]; then
while true; do
read -r -p "Do you agree to the Nexus Beta Terms of Use (https://nexus.xyz/terms-of-use)? (Y/n) " yn
case "$yn" in
[Yy]|"") break ;;
[Nn]
) echo "You must agree to continue."; exit 1 ;;
*) echo "Please answer Y or n." ;;
esac
done
fi

-----------------------------------------------------------------------------

5) Check for 'git' availability. If not found, prompt the user to install it.

-----------------------------------------------------------------------------

if ! command -v git >/dev/null 2>&1; then
echo "Unable to find git. Please install it and try again."
exit 1
fi

-----------------------------------------------------------------------------

6) Clone or update the network-api repository in $NEXUS_HOME.

-----------------------------------------------------------------------------

REPO_PATH="$NEXUS_HOME/network-api"

if [ -d "$REPO_PATH" ]; then
echo "$REPO_PATH exists. Updating."
(
cd "$REPO_PATH" || exit
git stash push --keep-index
git fetch --tags
)
else
echo "Cloning network-api repository..."
(
cd "$NEXUS_HOME" || exit
git clone https://github.com/nexus-xyz/network-api
)
fi

-----------------------------------------------------------------------------

7) Check out the latest tagged commit in the repository.

-----------------------------------------------------------------------------

(
cd "$REPO_PATH" || exit
git -c advice.detachedHead=false checkout "$(git rev-list --tags --max-count=1)"
)

-----------------------------------------------------------------------------

8) Run the Rust CLI in interactive mode.

-----------------------------------------------------------------------------

(
cd "$REPO_PATH/clients/cli" || exit
cargo run --release -- --start --beta
) < /dev/tty

Please sign in to comment.