diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index b5f0afa774..c71c0ee103 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -37,6 +37,6 @@ // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. // "remoteUser": "vscode", "remoteEnv": { - "PATH": "${containerEnv:PATH}:/workspace/dojo/target/release:/home/vscode/.dojo/bin" + "PATH": "${containerEnv:PATH}:/workspace/dojo/target/release" } } \ No newline at end of file diff --git a/bin/sozo/README.md b/bin/sozo/README.md index bb864ed5b3..614c6c2442 100644 --- a/bin/sozo/README.md +++ b/bin/sozo/README.md @@ -1,4 +1,4 @@ -# `dojoup` +# `sozo` ```sh curl -L https://install.dojoengine.org | bash diff --git a/dojoup/Dockerfile b/dojoup/Dockerfile deleted file mode 100644 index 8b3139cc94..0000000000 --- a/dojoup/Dockerfile +++ /dev/null @@ -1,25 +0,0 @@ -# Dockerfile for minimum system dependencies and Dojoup installation local test. - -FROM ubuntu:24.04 - -# System dependencies for dojoup installation. -RUN apt-get update && \ - apt-get install -y curl unzip git jq ca-certificates && \ - apt-get clean - -# Create a non-root user. -RUN useradd -ms /bin/bash dojo -USER dojo -WORKDIR /home/dojo - -COPY --chown=dojo:dojo install install -COPY --chown=dojo:dojo dojoup dojoup - -RUN ./install ./dojoup && \ - . "${XDG_CONFIG_HOME:-$HOME}"/.dojo/env && \ - dojoup install - -# Copy and run the post-install check -COPY --chown=dojo:dojo post_install_check post_install_check - -CMD ["./post_install_check"] diff --git a/dojoup/README.md b/dojoup/README.md index e50ff4f7b6..9a6763f7c3 100644 --- a/dojoup/README.md +++ b/dojoup/README.md @@ -1,22 +1,16 @@ -# `dojoup` +# Dojo Toolchain Installer + +Install the Dojo toolchain using [asdf](https://asdf-vm.com): ```sh curl -L https://install.dojoengine.org | bash ``` -For more details, you can then issue the following command: +This installs the following tools via asdf plugins: -```sh -dojoup --help -``` +- [sozo](https://github.com/dojoengine/asdf-sozo) +- [katana](https://github.com/dojoengine/asdf-katana) +- [torii](https://github.com/dojoengine/asdf-torii) +- [saya](https://github.com/dojoengine/asdf-saya) [Documentation](https://book.dojoengine.org/getting-started#getting-started) - -## Working with Dojoup - -To test dojoup, there are two options: - -1. Use the `dojoup/Dockerfile` to build a Docker image and run the post-install check. -2. Use the workflow `dojoup.yml` to run the post-install check on a runner. - -Currently, dojoup are bash programs being downloaded and executed. Probably in a near future, only the install script will be downloaded and the dojoup logic will be inside a rust binary. diff --git a/dojoup/dojoup b/dojoup/dojoup deleted file mode 100755 index 28fbc00f9d..0000000000 --- a/dojoup/dojoup +++ /dev/null @@ -1,902 +0,0 @@ -#!/usr/bin/env bash - -# Check if the platform is Windows -if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then - echo "Note: Dojoup does not support Powershell or Cmd on Windows." - echo "Please use Git BASH (https://gitforwindows.org/) or WSL (https://learn.microsoft.com/en-us/windows/wsl/install)." -fi - -set -e - -HOME_DIR=${XDG_CONFIG_HOME:-$HOME} -BASE_DIR=${DOJO_DIR-"$HOME_DIR/.dojo"} - -DEFAULT_TOOLCHAIN_DIR="$BASE_DIR/bin" -INSTALLATION_DIR="$BASE_DIR/installed" -TOOLCHAIN_DIR="$INSTALLATION_DIR/toolchain" -COMPONENTS_DIR="$INSTALLATION_DIR/components" - -# Repository information -DOJO_REPO="dojoengine/dojo" -KATANA_REPO="dojoengine/katana" -TORII_REPO="dojoengine/torii" - -# Toolchain versions compatibility registry -VERSIONS_JSON_URL="https://raw.githubusercontent.com/dojoengine/dojo/refs/heads/main/versions.json" - -# All components -COMPONENT_BINARY=("sozo" "torii" "katana") - -# The last dojo version that is still using the 'legacy' format ie all binaries are included in the monorepo -MIN_NEW_DOJO_VERSION=1.5.0 - -get_repo_for_component() { - local component=$1 - - # Mapping of components and their repositories - COMPONENT_REPO_MAPPING=( - "sozo:$DOJO_REPO" - "torii:$TORII_REPO" - "katana:$KATANA_REPO" - ) - - for component_repo in "${COMPONENT_REPO_MAPPING[@]}"; do - local component_part="${component_repo%%:*}" - local repo_part="${component_repo#*:}" - if [ "$component_part" = "$component" ]; then - echo "$repo_part" - return 0 - fi - done - - return 1 -} - -set_default_version() { - local version=$1 - requested_toolchain_path=$TOOLCHAIN_DIR/$version - - # Return error if the directory path to the requested toolchain doesn't exist - if [[ ! -d "$requested_toolchain_path" ]]; then - err "The requested toolchain \`$version\` is not installed." - fi - - # Do nothing if DEFAULT_TOOLCHAIN_DIR is already pointing to the requested toolchain - if [[ -L "$DEFAULT_TOOLCHAIN_DIR" ]] && [[ "$(readlink -f "$DEFAULT_TOOLCHAIN_DIR")" == "$requested_toolchain_path" ]]; then - return - fi - - if [ -d "$DEFAULT_TOOLCHAIN_DIR" ]; then - rm -rf "$DEFAULT_TOOLCHAIN_DIR" - fi - - ln -sf "$requested_toolchain_path" "$DEFAULT_TOOLCHAIN_DIR" -} - -# Function to get the active Dojo version -get_default_version() { - if [ -d "$DEFAULT_TOOLCHAIN_DIR" ] && [ -L "$DEFAULT_TOOLCHAIN_DIR" ]; then - # Read the link and get the last segment of the path (the toolchain name ie version) - # eg .dojo/installed/toolchain/1.4.0 - active_path=$(readlink -f "$DEFAULT_TOOLCHAIN_DIR") - toolchain=$(basename "$active_path") - echo "$toolchain" - return 0 - else - return 1 - fi -} - -get_active_component_path(){ - local component=$1 - if [ -d "$DEFAULT_TOOLCHAIN_DIR" ]; then - echo "$(readlink -f "$DEFAULT_TOOLCHAIN_DIR/$component")" - return 0 - else - return 1 - fi -} - -usage() { - cat 1>&2 <<'EOF' -The Dojo toolchain installer - -USAGE: - dojoup [COMMAND] - -COMMANDS: - component Manage individual Dojo components - default Switch to a specific installed version - install Install Dojo - list List all installed versions - show Display the default Dojo version -EOF -} - -show_version() { - # Get current global version - local active_version=$(get_default_version) - - if [ -n "$active_version" ]; then - printf "version: $active_version\n" - printf "components:\n" - - # Show details for each binary - for component in "${COMPONENT_BINARY[@]}"; do - component_path=$(get_active_component_path "$component") - bin_version=$(get_component_version "$component_path") - say " $component: $bin_version" - done - else - say "No active Dojo version set. Use 'dojoup install' to install Dojo or 'dojoup default ' to set an active version." - fi -} - -get_component_version() { - local bin_path=$1 - - if [ -n "$bin_path" ]; then - # Extract version by taking everything after the first space without validating the format - local bin_version=$("$bin_path" --version 2>/dev/null | head -1 | cut -d' ' -f2 || echo "unknown") - echo "$bin_version" - else - return 1 - fi -} - -# List all installed versions from the toolchain directory -list_toolchains() { - default_version=$(get_default_version) - if [ -d "$TOOLCHAIN_DIR" ]; then - for toolchain in $(ls -1 "$TOOLCHAIN_DIR" 2>/dev/null); do - if [ "$toolchain" = "$default_version" ]; then - say "$toolchain (default)" - else - say "$toolchain" - fi - done - fi -} - -use_version() { - local version=$1 - - # Check if version was provided - if [ -z "$version" ]; then - show_version - return 0 - fi - - # Set default version and update symlinks - set_default_version "$version" - - say "now using dojo toolchain: $version" -} - -detect_platform_arch() { - # Determine platform - local platform="$(uname -s)" - local ext="tar.gz" - case $platform in - Linux) - platform="linux" - ;; - Darwin) - platform="darwin" - ;; - MINGW*) - ext="zip" - platform="win32" - ;; - *) - err "unsupported platform: $platform" - ;; - esac - - # Determine architecture - local architecture="$(uname -m)" - if [ "${architecture}" = "x86_64" ]; then - # Redirect stderr to /dev/null to avoid printing errors if non Rosetta. - if [ "$(sysctl -n sysctl.proc_translated 2>/dev/null)" = "1" ]; then - architecture="arm64" # Rosetta. - else - architecture="amd64" # Intel. - fi - elif [ "${architecture}" = "arm64" ] ||[ "${architecture}" = "aarch64" ] ; then - architecture="arm64" # Arm. - else - architecture="amd64" # Amd. - fi - - # Return values as a space-separated string - echo "$platform $ext $architecture" -} - -install_dojo() { - need_cmd jq - need_cmd curl - - # Process options for installation - # If the first argument is provided and doesn't start with a dash, treat it as the version - if [[ $1 && ! $1 =~ ^- ]]; then - DOJOUP_VERSION=$1 - shift - fi - - # Process any remaining options - while [[ $1 ]]; do - case $1 in - --) shift; break;; - -h|--help) - usage_install - exit 0 - ;; - *) - warn "unknown install option: $1" - usage_install - exit 1 - ;; - esac - shift - done - - # Default to the main dojo repo - DOJOUP_REPO=${DOJOUP_REPO-$DOJO_REPO} - # Store user specified version separately - DOJOUP_USER_VERSION=${DOJOUP_VERSION} - - # Install by downloading binaries - DOJOUP_VERSION=${DOJOUP_VERSION-stable} - DOJOUP_TAG=$DOJOUP_VERSION - - # Normalize versions (handle channels, versions without v prefix) - if [[ "$DOJOUP_VERSION" == "stable" ]]; then - # Fetch the list of releases from the GitHub API and filter out `prerelease`` releases and `alpha`` releases - DOJOUP_TAG=$(curl -s "https://api.github.com/repos/${DOJO_REPO}/releases" \ - | grep -oE '"tag_name": "[^"]*"|"prerelease": (true|false)' \ - | grep -B1 '"prerelease": false' \ - | grep '"tag_name":' \ - | grep -oE '"v[0-9]*\.[0-9]*\.[0-9]*(-rc\.[0-9]*)?"' \ - | tr -d '"' \ - | head -n 1) - DOJOUP_VERSION=$DOJOUP_TAG - elif [[ "$DOJOUP_VERSION" == [[:digit:]]* ]]; then - # Add v prefix - DOJOUP_VERSION="v${DOJOUP_VERSION}" - DOJOUP_TAG="${DOJOUP_VERSION}" - fi - - say "installing dojo (version ${DOJOUP_VERSION}, tag ${DOJOUP_TAG})" - - # Get platform and architecture information - read -r PLATFORM EXT ARCHITECTURE <<< "$(detect_platform_arch)" - - VERSIONS_REGISTRY=$(mktemp) - - # Try to download the latest versions.json - say "syncing dojo toolchain..." - if ! download "$VERSIONS_JSON_URL" "$VERSIONS_REGISTRY" 2>/dev/null; then - # If no local copy exists either, error out - rm -f "$VERSIONS_REGISTRY" - err "failed to sync toolchain versions." - fi - - # Parse the versions.json file to get compatible versions - # Remove the 'v' prefix from DOJOUP_VERSION for json lookup - DOJO_VERSION_NO_V=$(echo "$DOJOUP_VERSION" | sed 's/^v//') - - # Track which archives we've already downloaded to avoid redundancy - DOWNLOADED_ARCHIVES="" - INSTALLED_BINARIES=() - - # get the latest component version that is compatible with the given dojo version - get_compatible_version() { - local binary=$1 - compatible_version=$(jq -r --arg v "$DOJO_VERSION_NO_V" --arg b "$binary" '.[$v][$b][0]' "$VERSIONS_REGISTRY") - if [ "$compatible_version" = "null" ]; then - err "No compatible version found for ${binary}" - else - echo "$compatible_version" - fi - } - - # for backward compatibitliy with the legacy monorepo format - do_legacy_install() { - # Dojo repo binaries use dojo version - bin_version=$DOJO_VERSION_NO_V - bin_tag=$DOJOUP_TAG - - RELEASE_URL="https://github.com/${DOJO_REPO}/releases/download/${bin_tag}/" - local bin_path - - ARCHIVE_NAME="dojo_${bin_tag}_${PLATFORM}_${ARCHITECTURE}.$EXT" - BIN_ARCHIVE_URL="${RELEASE_URL}${ARCHIVE_NAME}" - EXTRACT_DIR=$(mktemp -d) - - # Check if the version exists in the repository - if ! curl --output /dev/null --silent --head --fail "$BIN_ARCHIVE_URL"; then - err "Version ${bin_tag} for ${component} does not exist." - fi - - # Download and extract the binaries archive - if [ "$PLATFORM" = "win32" ]; then - tmp="$(mktemp -d 2>/dev/null || echo ".")/dojo.zip" - ensure download "$BIN_ARCHIVE_URL" "$tmp" - ensure unzip "$tmp" -d "$EXTRACT_DIR" - rm -f "$tmp" - else - ensure download "$BIN_ARCHIVE_URL" | ensure tar -xzC "$EXTRACT_DIR" - fi - - for component in "${COMPONENT_BINARY[@]}"; do - say "installing $component" - - # the path to the extracted the component binary - extracted_bin_dir="$EXTRACT_DIR/$component" - component_bin_path="$COMPONENTS_DIR/$component/$bin_version" - - # Create directory for this binary version - ensure mkdir -p "$component_bin_path" - - # Move only this binary to its version directory - if [ -f "$extracted_bin_dir" ]; then - ensure cp "$extracted_bin_dir" "$component_bin_path/" - else - err "Version ${bin_tag} for ${component} is not found in the downloaded archive file." - fi - - # Only check for Scarb version if we're installing sozo - if [ "$component" = "sozo" ]; then - check_scarb $component_bin_path - fi - - bin_path="$component_bin_path/$component" - INSTALLED_BINARIES+=("$bin_path:$component") - done - } - - do_install() { - for component in "${COMPONENT_BINARY[@]}"; do - say "installing $component" - - # Determine the version of each component that is compatible with the given Dojo version - repo=$(get_repo_for_component "$component") - if [ "$repo" = "$DOJO_REPO" ]; then - # Dojo repo binaries use dojo version - bin_version=$DOJO_VERSION_NO_V - bin_tag=$DOJOUP_TAG - else - bin_version=$(get_compatible_version "$component") - bin_tag="v$bin_version" - fi - - # Create directory for this binary version - component_bin_path="$COMPONENTS_DIR/$component/$bin_version" - ensure mkdir -p "$component_bin_path" - - # Compute the URL of the release tarball - RELEASE_URL="https://github.com/${repo}/releases/download/${bin_tag}/" - local bin_path - - # Download the component binary - if [ "$repo" = "$DOJO_REPO" ]; then - # For dojo repo, all binaries are in a single archive - ARCHIVE_NAME="dojo_${bin_tag}_${PLATFORM}_${ARCHITECTURE}.$EXT" - BIN_ARCHIVE_URL="${RELEASE_URL}${ARCHIVE_NAME}" - - # Check if we've already downloaded this archive - if [[ "$DOWNLOADED_ARCHIVES" != *"$ARCHIVE_NAME"* ]]; then - EXTRACT_DIR=$(mktemp -d) - - # Check if the version exists in the repository - if ! curl --output /dev/null --silent --head --fail "$BIN_ARCHIVE_URL"; then - err "Version ${bin_tag} for ${component} does not exist." - fi - - # Download and extract the binaries archive - if [ "$PLATFORM" = "win32" ]; then - tmp="$(mktemp -d 2>/dev/null || echo ".")/dojo.zip" - ensure download "$BIN_ARCHIVE_URL" "$tmp" - ensure unzip "$tmp" -d "$EXTRACT_DIR" - rm -f "$tmp" - else - ensure download "$BIN_ARCHIVE_URL" | ensure tar -xzC "$EXTRACT_DIR" - fi - - # Remember that we've downloaded this archive - DOWNLOADED_ARCHIVES="$DOWNLOADED_ARCHIVES $ARCHIVE_NAME" - fi - - # Move only this binary to its version directory - if [ -f "$EXTRACT_DIR/$component" ]; then - ensure cp "$EXTRACT_DIR/$component" "$component_bin_path/" - else - err "Version ${bin_tag} for ${component} is not found in the downloaded archive file." - fi - - bin_path="$component_bin_path/$component" - else - # For other repos like katana, each binary has its own archive - BIN_ARCHIVE_URL="${RELEASE_URL}${component}_${bin_tag}_${PLATFORM}_${ARCHITECTURE}.$EXT" - - # Check if the version exists in the repository - if ! curl --output /dev/null --silent --head --fail "$BIN_ARCHIVE_URL"; then - err "Version ${bin_tag} for ${component} does not exist." - fi - - # Download and extract the binaries archive - if [ "$PLATFORM" = "win32" ]; then - tmp="$(mktemp -d 2>/dev/null || echo ".")/dojo.zip" - ensure download "$BIN_ARCHIVE_URL" "$tmp" - ensure unzip "$tmp" -d "$component_bin_path" - rm -f "$tmp" - else - ensure download "$BIN_ARCHIVE_URL" | ensure tar -xzC "$component_bin_path" - fi - - bin_path="$component_bin_path/$component" - fi - - INSTALLED_BINARIES+=("$bin_path:$component") - - # Only check for Scarb version if we're installing sozo - if [ "$component" = "sozo" ]; then - check_scarb $bin_path - fi - done - } - - if [ "$(version_is_bigger_than "$DOJO_VERSION_NO_V" "$MIN_NEW_DOJO_VERSION" )" -ne -1 ]; then - do_install - else - do_legacy_install - fi - - # Create version-specific directory in DOJO_DIR for symlinks - TOOLCHAIN_VER_DIR="$TOOLCHAIN_DIR/$DOJO_VERSION_NO_V" - ensure mkdir -p "$TOOLCHAIN_VER_DIR" - - # Create symlinks for all installed binaries in the version-specific directory - for binary_entry in "${INSTALLED_BINARIES[@]}"; do - bin_path="${binary_entry%%:*}" - bin_name="${binary_entry##*:}" - - # Create symlink to the binary - if [ -f "$bin_path" ]; then - ln -sf "$bin_path" "$TOOLCHAIN_VER_DIR/$bin_name" - fi - done - - # Set the global version to the one we just installed - set_default_version "$DOJO_VERSION_NO_V" - - say "done!" - welcome_msg - - cleanup() { - # Clean up temporary files - if [ -n "$EXTRACT_DIR" ] && [ -d "$EXTRACT_DIR" ]; then - rm -rf "$EXTRACT_DIR" - fi - - if [ -f "$VERSIONS_REGISTRY" ]; then - rm -f "$VERSIONS_REGISTRY" - fi - } - - cleanup -} - -usage_install() { - cat 1>&2 <<'EOF' -Install the Dojo toolchain. - -USAGE: - dojoup install [VERSION] - -ARGS: - VERSION The version to install (if not specified, defaults to the latest stable version) - -OPTIONS: - -h, --help Print help information -EOF -} - -say() { - printf "%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 -} - -# 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 -} - -# Downloads $1 into $2 or stdout -download() { - if [ "$2" ]; then - # output into $2 - if check_cmd curl; then - curl -#o "$2" -L "$1" - else - wget --show-progress -qO "$2" "$1" - fi - else - # output to stdout - if check_cmd curl; then - curl -#L "$1" - else - wget --show-progress -qO- "$1" - fi - fi -} - -# Function to check mutual exclusivity of options -check_exclusive_options() { - local options=("$@") - local count=0 - local set_option="" - - for option in "${options[@]}"; do - if [ -n "${!option}" ]; then - ((count++)) - set_option="$option" - fi - done - - if [ "$count" -gt 1 ]; then - err "only one of ${options[*]} can be specified" - elif [ "$count" -eq 1 ]; then - echo "$set_option" - fi -} - -# Welcome message printed after having installed Dojo. -welcome_msg() { - dojo='\033[1;34m' - title='\033[0;32m' - emphasis='\033[0;34m' - command='\033[0;31m' - clear='\033[0m' - - printf " -═════════════════════════════════════════════════════════════════════════ - - - ██████╗ ██╗ ██╗ █████╗ ██╗ ██╗ ██████╗ - ██╔═══██╗██║ ██║██╔══██╗╚██╗ ██╔╝██╔═══██╗ - ██║ ██║███████║███████║ ╚████╔╝ ██║ ██║ - ██║ ██║██╔══██║██╔══██║ ╚██╔╝ ██║ ██║ - ╚██████╔╝██║ ██║██║ ██║ ██║ ╚██████╔╝ - ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═════╝ - - - - Repo : https://github.com/dojoengine/dojo - Book : https://book.dojoengine.org/ - Chat : https://discord.gg/dojoengine - https://t.me/dojoengine - -Congratulations on successfully installing ${dojo}Dojo${clear} ${DOJOUP_VERSION}! 🥷 - -For more info on getting started, check out the Dojo Starter guide: https://book.dojoengine.org/tutorials/dojo-starter - -═════════════════════════════════════════════════════════════════════════ - -" -} - -check_scarb() { - local sozo_path=$1 - # Extracting the scarb version from the output of 'sozo --version' - if [ -n "$sozo_path" ] && [ -f "$sozo_path" ]; then - scarb_version=$(echo "$($sozo_path --version)" | grep -o 'scarb: [0-9.]*' | cut -d ' ' -f 2) - # Check if scarb is already installed - if [ -n "$scarb_version" ] && [ "$(scarb --version 2>/dev/null)" != "scarb $scarb_version" ]; then - # Check if scarb is managed by asdf - if command -v asdf &> /dev/null; then - if asdf list | grep -q "scarb"; then - # Check if default version is set - if ! asdf current scarb &> /dev/null; then - # Try newer asdf command first, fall back to older command if it fails. - if ! asdf set scarb $scarb_version &> /dev/null; then - asdf global scarb $scarb_version - fi - fi - else - # Install scarb using asdf - asdf plugin add scarb - asdf install scarb $scarb_version - fi - else - # Install scarb using the install script - curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh -s -- -v $scarb_version - fi - fi - fi -} - -# Function to compare version strings (like "1.2.3" vs "1.3.0") -# Takes two version strings as input and compares them semantically -# Returns: -1 if version1 < version2, 0 if equal, 1 if version1 > version2 -# This is useful for determining if a newer version is available or for sorting versions -version_is_bigger_than() { - if [[ $# -ne 2 ]]; then - echo "Usage: compare_versions version1 version2" - echo "Returns: -1 if version1 < version2, 0 if equal, 1 if version1 > version2" - return 2 - fi - - local v1=($1) - local v2=($2) - - # Split versions by dots - IFS='.' read -ra v1_parts <<< "$1" - IFS='.' read -ra v2_parts <<< "$2" - - # Compare each component - for i in "${!v1_parts[@]}"; do - # If we've reached the end of v2 but v1 has more parts, v1 is greater - if [[ -z "${v2_parts[i]}" ]]; then - echo 1 - return 0 - fi - - # Compare the numeric values - if (( v1_parts[i] > v2_parts[i] )); then - echo 1 - return 0 - elif (( v1_parts[i] < v2_parts[i] )); then - echo -1 - return 0 - fi - done - - # If we get here and v2 has more parts, v2 is greater - if [[ "${#v1_parts[@]}" -lt "${#v2_parts[@]}" ]]; then - echo -1 - return 0 - fi - - # Versions are equal - echo 0 - return 0 -} - -install_component() { - need_cmd jq - need_cmd curl - - # Check if component name and version are provided - if [ $# -lt 2 ]; then - usage_component - exit 1 - fi - - local component=$1 - local version=$2 - shift 2 - - # Process any remaining options - while [[ $1 ]]; do - case $1 in - --) shift; break;; - -h|--help) - usage_component - exit 0 - ;; - *) - warn "unknown component option: $1" - usage_component - exit 1 - ;; - esac - shift - done - - # Validate component name - if [[ ! " ${COMPONENT_BINARY[@]} " =~ " ${component} " ]]; then - err "Invalid component name: $component. Valid components are: ${COMPONENT_BINARY[*]}" - fi - - # Normalize version (handle versions without v prefix) - if [[ "$version" == [[:digit:]]* ]]; then - version="v${version}" - fi - - say "installing $component (version ${version})" - - # Get platform and architecture information - read -r PLATFORM EXT ARCHITECTURE <<< "$(detect_platform_arch)" - - # Get the repository for the component - repo=$(get_repo_for_component "$component") - if [ -z "$repo" ]; then - err "Could not determine repository for component: $component" - fi - - # Create directory for this binary version - component_bin_path="$COMPONENTS_DIR/$component/$version" - ensure mkdir -p "$component_bin_path" - - # Compute the URL of the release tarball - RELEASE_URL="https://github.com/${repo}/releases/download/${version}/" - local bin_path - - # Download the component binary - if [ "$repo" = "$DOJO_REPO" ]; then - # For dojo repo, all binaries are in a single archive - ARCHIVE_NAME="dojo_${version}_${PLATFORM}_${ARCHITECTURE}.$EXT" - BIN_ARCHIVE_URL="${RELEASE_URL}${ARCHIVE_NAME}" - EXTRACT_DIR=$(mktemp -d) - - # Check if the version exists in the repository - if ! curl --output /dev/null --silent --head --fail "$BIN_ARCHIVE_URL"; then - err "Version ${version} for ${component} does not exist." - fi - - # Download and extract the binaries archive - if [ "$PLATFORM" = "win32" ]; then - tmp="$(mktemp -d 2>/dev/null || echo ".")/dojo.zip" - ensure download "$BIN_ARCHIVE_URL" "$tmp" - ensure unzip "$tmp" -d "$EXTRACT_DIR" - rm -f "$tmp" - else - ensure download "$BIN_ARCHIVE_URL" | ensure tar -xzC "$EXTRACT_DIR" - fi - - # Move only this binary to its version directory - if [ -f "$EXTRACT_DIR/$component" ]; then - ensure cp "$EXTRACT_DIR/$component" "$component_bin_path/" - else - err "Version ${version} for ${component} is not found in the downloaded archive file." - fi - - bin_path="$component_bin_path/$component" - else - # For other repos like katana, each binary has its own archive - BIN_ARCHIVE_URL="${RELEASE_URL}${component}_${version}_${PLATFORM}_${ARCHITECTURE}.$EXT" - - # Check if the version exists in the repository - if ! curl --output /dev/null --silent --head --fail "$BIN_ARCHIVE_URL"; then - err "Version ${version} for ${component} does not exist." - fi - - # Download and extract the binaries archive - if [ "$PLATFORM" = "win32" ]; then - tmp="$(mktemp -d 2>/dev/null || echo ".")/dojo.zip" - ensure download "$BIN_ARCHIVE_URL" "$tmp" - ensure unzip "$tmp" -d "$component_bin_path" - rm -f "$tmp" - else - ensure download "$BIN_ARCHIVE_URL" | ensure tar -xzC "$component_bin_path" - fi - - bin_path="$component_bin_path/$component" - fi - - # Only check for Scarb version if we're installing sozo - if [ "$component" = "sozo" ]; then - check_scarb $bin_path - fi - - # Create symlink in the default toolchain directory - if [ -f "$bin_path" ]; then - ln -sf "$bin_path" "$DEFAULT_TOOLCHAIN_DIR/$component" - fi - - say "done!" - - cleanup() { - # Clean up temporary files - if [ -n "$EXTRACT_DIR" ] && [ -d "$EXTRACT_DIR" ]; then - rm -rf "$EXTRACT_DIR" - fi - } - - cleanup -} - -usage_component() { - cat 1>&2 <<'EOF' -Manage individual Dojo components. - -USAGE: - dojoup component - -COMMANDS: - add Add a specific component version - help Print this message or the help of the given subcommand(s) - -USAGE: - dojoup component add - -ARGS: - COMPONENT The component to install (sozo, torii, katana) - VERSION The version to install - -OPTIONS: - -h, --help Print help information -EOF -} - -main() { - # Process commands - if [ $# -eq 0 ]; then - # If no command provided, default to the backward compatible behavior - # which is installing the latest version of Dojo. - install_dojo "$@" - fi - - if [ ! -d "$BASE_DIR" ]; then - ensure mkdir -p "$BASE_DIR" - fi - - # First argument is the command - COMMAND=$1 - shift - - case $COMMAND in - show) - show_version - exit 0 - ;; - install) - install_dojo "$@" - ;; - default) - use_version "$@" - ;; - list) - list_toolchains - ;; - component) - if [ $# -eq 0 ]; then - usage_component - exit 0 - fi - SUBCOMMAND=$1 - shift - case $SUBCOMMAND in - add) - install_component "$@" - ;; - help|-h|--help) - usage_component - exit 0 - ;; - *) - warn "unknown component command: $SUBCOMMAND" - usage_component - exit 1 - ;; - esac - ;; - help|-h|--help) - usage - exit 0 - ;; - esac -} - -main "$@" || exit 1 diff --git a/dojoup/dojoup-install b/dojoup/dojoup-install deleted file mode 100755 index ad9ec053f6..0000000000 --- a/dojoup/dojoup-install +++ /dev/null @@ -1,157 +0,0 @@ -#!/usr/bin/env bash -set -e - -echo Installing dojoup... - -check_cmd() { - command -v "$1" &>/dev/null -} - -need_cmd() { - if ! check_cmd "$1"; then - err "need '$1' (command not found)" - fi -} - -need_cmd curl - -BASE_DIR=${XDG_CONFIG_HOME:-$HOME} -DOJO_DIR=${DOJO_DIR-"$BASE_DIR/.dojo"} -DOJO_BIN_DIR="$DOJO_DIR/bin" -DOJO_DOJOUP_DIR="$DOJO_DIR/dojoup" -DOJO_MAN_DIR="$DOJO_DIR/share/man/man1" - -# Use first argument as BIN_URL if provided, otherwise default to GitHub main. -BIN_URL=${1:-"https://raw.githubusercontent.com/dojoengine/dojo/main/dojoup/dojoup"} -BIN_PATH="$DOJO_DOJOUP_DIR/dojoup" - -# Create the .dojo bin directory and dojoup binary if it doesn't exist. -mkdir -p $DOJO_BIN_DIR -mkdir -p $DOJO_DOJOUP_DIR - -# Handle both remote and local dojoup binary sources. -# To test dojoup, having a local dojoup binary is useful. -if [[ "$BIN_URL" == http* ]]; then - echo "Downloading dojoup from $BIN_URL..." - curl -# -L "$BIN_URL" -o "$BIN_PATH" -else - echo "Copying local dojoup from $BIN_URL..." - cp "$BIN_URL" "$BIN_PATH" -fi - -chmod +x "$BIN_PATH" - -# Create the man directory for future man files if it doesn't exist. -mkdir -p $DOJO_MAN_DIR - -# Create env file with PATH configuration -ENV_FILE="$DOJO_DIR/env" -cat > $ENV_FILE << EOF -#!/bin/sh -# dojoup shell setup -# affix colons on either side of \$PATH to simplify matching -case ":\${PATH}:" in - *:"$DOJO_BIN_DIR":*) - ;; - *) - # Appending path for dojo binary directory - export PATH="\$PATH:$DOJO_BIN_DIR" - ;; -esac - -case ":\${PATH}:" in - *:"$DOJO_DOJOUP_DIR":*) - ;; - *) - # Appending path for dojoup directory - export PATH="\$PATH:$DOJO_DOJOUP_DIR" - ;; -esac -EOF - -SOURCE_COMMAND=". \"$ENV_FILE\"" - -case $(basename "$SHELL") in -zsh) - commands=("$SOURCE_COMMAND") - - zsh_config=$HOME/.zshrc - - if [[ -w $zsh_config ]]; then - { - echo -e '\n# dojo' - for command in "${commands[@]}"; do - echo "$command" - done - } >>"$zsh_config" - - echo "Added \"$ENV_FILE\" to \$PATH in \"$zsh_config\"" - else - echo "Manually add the directory to $zsh_config (or similar):" - for command in "${commands[@]}"; do - echo " $command" - done - fi - ;; -bash) - commands=("$SOURCE_COMMAND") - - bash_configs=( - "$HOME/.bashrc" - "$HOME/.bash_profile" - ) - - if [[ ${XDG_CONFIG_HOME:-} ]]; then - bash_configs+=( - "$XDG_CONFIG_HOME/.bash_profile" - "$XDG_CONFIG_HOME/.bashrc" - "$XDG_CONFIG_HOME/bash_profile" - "$XDG_CONFIG_HOME/bashrc" - ) - fi - - set_manually=true - for bash_config in "${bash_configs[@]}"; do - # if file is writable - if [[ -w $bash_config ]]; then - { - echo -e '\n# dojo' - for command in "${commands[@]}"; do - echo "$command" - done - } >>"$bash_config" - - echo "Added \"$ENV_FILE\" to \$PATH in \"$bash_config\"" - - set_manually=false - break - fi - done - - if [[ $set_manually = true ]]; then - echo "Manually add the directory to $bash_config (or similar):" - for command in "${commands[@]}"; do - echo " $command" - done - fi - ;; -*) - echo 'Manually add the directory to ~/.bashrc (or similar):' - echo " $SOURCE_COMMAND" - ;; -esac - -echo -echo -e "\033[1mDojoup is installed now.\033[0m" -echo -echo "To get started you may need to restart your current shell." -echo "This would reload your \$PATH environment variable to include" -echo "Dojo's bin directory ($DOJO_BIN_DIR)." -echo -echo "To configure your current shell, you need to source" -echo "the corresponding env file under $DOJO_DIR." -echo -echo "This is usually done by running the following (note the leading DOT):" -echo "$SOURCE_COMMAND # For sh/bash/zsh/ash/dash/pdksh" -echo -echo "Then, simply run 'dojoup install' to install a Dojo toolchain." diff --git a/dojoup/install.ps1 b/dojoup/install.ps1 deleted file mode 100644 index e7e9d6b28b..0000000000 --- a/dojoup/install.ps1 +++ /dev/null @@ -1,92 +0,0 @@ -# Function to download and extract a zip file -function Download-And-Extract { - param ( - [string]$Url, - [string]$Destination - ) - - $tempFile = [System.IO.Path]::GetTempPath() + [System.Guid]::NewGuid().ToString() + ".zip" - Write-Host "Downloading from $Url..." - Invoke-WebRequest -Uri $Url -OutFile $tempFile - - Write-Host "Extracting to $Destination..." - Expand-Archive -Path $tempFile -DestinationPath $Destination -Force - Remove-Item $tempFile -} - -# Function to add a directory to PATH -function Add-ToPath { - param ( - [string]$Path - ) - - $currentPath = [Environment]::GetEnvironmentVariable("Path", "User") - if ($currentPath -notlike "*$Path*") { - [Environment]::SetEnvironmentVariable("Path", "$currentPath;$Path", "User") - Write-Host "Added $Path to PATH" - } -} - -# Check if version parameter is provided -if ($args.Count -eq 0) { - $dojoVersion = "1.5.0" -} else { - $dojoVersion = $args[0] -} - -# Create installation directory -$installDir = Join-Path $env:USERPROFILE ".dojo" -if (-not (Test-Path $installDir)) { - New-Item -ItemType Directory -Path $installDir | Out-Null -} - -# Download versions.json -$versionsUrl = "https://raw.githubusercontent.com/dojoengine/dojo/main/versions.json" -$versionsPath = Join-Path $installDir "versions.json" -Write-Host "Downloading versions.json..." -Invoke-WebRequest -Uri $versionsUrl -OutFile $versionsPath - -# Parse versions.json -$versions = Get-Content $versionsPath | ConvertFrom-Json - -# Check if the requested version exists -if (-not $versions.$dojoVersion) { - Write-Host "Error: Version $dojoVersion not found in versions.json" - Write-Host "Available versions:" - $versions.PSObject.Properties.Name | ForEach-Object { Write-Host "- $_" } - exit 1 -} - -$versionInfo = $versions.$dojoVersion - -# Get the first version from the arrays for each tool -$toriiVersion = $versionInfo.torii[0] -$katanaVersion = $versionInfo.katana[0] - -# Download and install Dojo -$dojoUrl = "https://github.com/dojoengine/dojo/releases/download/v$dojoVersion/dojo_v$dojoVersion`_win32_amd64.zip" -$dojoDir = Join-Path $installDir "dojo" -Download-And-Extract -Url $dojoUrl -Destination $dojoDir - -# Download and install Torii -$toriiUrl = "https://github.com/dojoengine/torii/releases/download/v$toriiVersion/torii_v$toriiVersion`_win32_amd64.zip" -$toriiDir = Join-Path $installDir "torii" -Download-And-Extract -Url $toriiUrl -Destination $toriiDir - -# Download and install Torii -$toriiUrl = "https://github.com/dojoengine/torii/releases/download/v$toriiVersion/torii_v$toriiVersion`_win32_amd64.zip" -$toriiDir = Join-Path $installDir "torii" -Download-And-Extract -Url $toriiUrl -Destination $toriiDir - -# Download and install Katana -$katanaUrl = "https://github.com/dojoengine/katana/releases/download/v$katanaVersion/katana_v$katanaVersion`_win32_amd64.zip" -$katanaDir = Join-Path $installDir "katana" -Download-And-Extract -Url $katanaUrl -Destination $katanaDir - -# Add binaries to PATH -Add-ToPath -Path $dojoDir -Add-ToPath -Path $toriiDir -Add-ToPath -Path $katanaDir - -Write-Host "Installation complete! Dojo, Torii and Katana have been installed to $installDir" -Write-Host "Please restart your terminal to use the new PATH settings." diff --git a/dojoup/post_install_check b/dojoup/post_install_check deleted file mode 100755 index b29a633908..0000000000 --- a/dojoup/post_install_check +++ /dev/null @@ -1,239 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -BASE_DIR=${XDG_CONFIG_HOME:-$HOME} -DOJO_DIR=${DOJO_DIR-"$BASE_DIR/.dojo"} - -log() { - echo "$1" -} - -success() { - echo "[✓] $1" -} - -error() { - echo "[✗] $1" - exit 1 -} - -# Cleanups background processes. -cleanup() { - local pids=("$@") - log "Cleaning up background processes..." - for pid in "${pids[@]}"; do - if kill -0 "$pid" 2>/dev/null; then - kill "$pid" 2>/dev/null || true - fi - done - wait "${pids[@]}" 2>/dev/null || true -} - -# Tests the dojoup install command. -test_install() { - log "Testing dojoup install..." - - # Check if .env file exists - if [ ! -f "${DOJO_DIR}/env" ]; then - error "Installation failed: .env file not found in ${DOJO_DIR}" - fi - - # Source the .env file of dojo - . "${DOJO_DIR}"/env - - # Technically, it's already installed since 1.5.0 is currently the last release. - # However, to ensure the install can be checked with fixed versions, we re-install 1.5.0 explicitly. - dojoup install 1.5.0 - - if [ ! -d "$DOJO_DIR" ]; then - error "Installation failed: .dojo directory not created" - fi - - if [ ! -d "$DOJO_DIR/bin" ]; then - error "Installation failed: bin directory not created" - fi - - for binary in sozo torii katana dojo-language-server; do - if [ ! -f "$DOJO_DIR/bin/$binary" ]; then - error "Installation failed: $binary not found" - fi - done - - success "Installation test passed" -} - -# Tests the dojoup default version switching command. -test_default_version() { - log "Testing dojoup default version switching..." - - current_version=$(dojoup show | grep "version:" | cut -d' ' -f2) - - dojoup install "1.4.0" - - dojoup default "1.4.0" - - new_version=$(dojoup show | grep "version:" | cut -d' ' -f2) - if [ "$new_version" != "1.4.0" ]; then - error "Default version switch failed: expected 1.4.0, got $new_version" - fi - - dojoup default "$current_version" - - success "Default version switching test passed" -} - -# Tests the dojoup component management command. -test_component_management() { - log "Testing dojoup component management..." - - current_version=$(dojoup show | grep "version:" | cut -d' ' -f2) - - dojoup component add katana 1.5.1 - - # Only test the bin symlink, since we may have internal folder structure changes - # in the future for dojoup. - # Also, the current version of component overrides the Katana install into the - # default toolchain version folder. - if [ ! -f "$DOJO_DIR/bin/katana" ]; then - error "Component installation failed: katana not found" - fi - - component_version=$("$DOJO_DIR/bin/katana" --version | head -1 | cut -d' ' -f2) - if [ "$component_version" != "1.5.1" ]; then - error "Component version mismatch: expected 1.5.1, got $component_version" - fi - - success "Component management test passed" -} - -# Tests the dojoup list versions command. -test_list_versions() { - log "Testing dojoup list versions..." - - versions=$(dojoup list) - - # Verify both versions are present that we installed during this post-install check. - if ! echo "$versions" | grep -q "1.4.0"; then - error "List versions failed: version 1.4.0 not found" - fi - - if ! echo "$versions" | grep -q "1.5.0"; then - error "List versions failed: version 1.5.0 not found" - fi - - if ! echo "$versions" | grep -q "1.5.0 (default)"; then - error "List versions failed: default version marker not found" - fi - - success "List versions test passed" -} - -# Tests the dojoup show version command. -test_show_version() { - log "Testing dojoup show version..." - - # Get current version info - version_info=$(dojoup show) - - # Verify version format and exact version - if ! echo "$version_info" | grep -q "version: 1.5.0"; then - error "Show version failed: expected version 1.5.0 not found" - fi - - # Verify components section exists - if ! echo "$version_info" | grep -q "components:"; then - error "Show version failed: components section not found" - fi - - # Check each component version - if ! echo "$version_info" | grep -q "sozo: 1.5"; then - error "Show version failed: sozo version not found or less than 1.5" - fi - - if ! echo "$version_info" | grep -q "torii: 1.5"; then - error "Show version failed: torii version not found or less than 1.5" - fi - - if ! echo "$version_info" | grep -q "katana: 1.5"; then - error "Show version failed: katana version not found or less than 1.5" - fi - - if ! echo "$version_info" | grep -q "dojo-language-server: 1.5"; then - error "Show version failed: dojo-language-server version not found or less than 1.5" - fi - - success "Show version test passed" -} - -# A end to end test that starts Katana and Torii and migrates a world using Sozo. -test_katana_torii() { - log "Testing Katana and Torii functionality..." - - KATANA_LOG="/tmp/katana.log" - TORII_LOG="/tmp/torii.log" - TEST_DIR="/tmp/dojo-test" - - # 1. Start katana in the background - katana --dev > "${KATANA_LOG}" 2>&1 & - KATANA_PID=$! - - # Wait a bit for katana to be up - sleep 2 - - # Check if katana is running and has no errors - if ! pgrep -f katana > /dev/null || grep -i "error" "${KATANA_LOG}"; then - error "Katana failed to start or encountered errors" - fi - - log "Katana started with PID $KATANA_PID" - - # 2. Initialize, build and migrate with sozo - rm -rf "${TEST_DIR}" - sozo init "${TEST_DIR}" - cd "${TEST_DIR}" - sozo build - sozo migrate - - # 3. Start torii with a dummy world address in background. - WORLD_ADDRESS=$(jq -r '.world.address' "${TEST_DIR}/manifest_dev.json") - - torii --world "${WORLD_ADDRESS}" > "${TORII_LOG}" 2>&1 & - TORII_PID=$! - - # Wait for torii to be up and indexing data. - sleep 2 - - # Check if torii is running and has no errors - if ! pgrep -f torii > /dev/null || grep -i "error" "${TORII_LOG}"; then - error "Torii failed to start or encountered errors" - cleanup "$KATANA_PID" - fi - - log "Torii started with PID $TORII_PID" - - WORLD_CHECK=$(curl -s -X POST http://localhost:8080/sql -d "SELECT contract_address FROM contracts WHERE contract_address = '${WORLD_ADDRESS}';") - WORLD_CHECK=$(echo "${WORLD_CHECK}" | jq -r '.[0].contract_address') - - if [ -z "${WORLD_CHECK}" ] || [ "${WORLD_CHECK}" != "${WORLD_ADDRESS}" ]; then - error "World address mismatch. Expected: ${WORLD_ADDRESS}, Got: ${WORLD_CHECK}" - cleanup "$KATANA_PID" "$TORII_PID" - fi - - cleanup "$KATANA_PID" "$TORII_PID" - success "Katana and Torii test passed" -} - -main() { - log "Starting dojoup test suite..." - - test_install - test_default_version - test_component_management - test_list_versions - test_show_version - test_katana_torii - - success "All tests passed!" -} - -main