diff --git a/foundryup/README.md b/foundryup/README.md index 39a53288c001..5504063abfe3 100644 --- a/foundryup/README.md +++ b/foundryup/README.md @@ -2,6 +2,8 @@ Update or revert to a specific Foundry branch with ease. +`foundryup` supports installing and managing multiple versions. + ## Installing ```sh @@ -16,10 +18,22 @@ To install the **nightly** version: foundryup ``` -To install a specific **version** (in this case the `nightly` version): +To **install** a specific **version** (in this case the `nightly` version): + +```sh +foundryup --install nightly +``` + +To **list** all **versions** installed: + +```sh +foundryup --list +``` + +To switch between different versions and **use**: ```sh -foundryup --version nightly +foundryup --use nightly-00efa0d5965269149f374ba142fb1c3c7edd6c94 ``` To install a specific **branch** (in this case the `release/0.1.0` branch's latest commit): @@ -62,6 +76,6 @@ foundryup --path ./git/foundry --- -**Tip**: All flags have a single character shorthand equivalent! You can use `-v` instead of `--version`, etc. +**Tip**: All flags have a single character shorthand equivalent! You can use `-i` instead of `--install`, etc. --- diff --git a/foundryup/foundryup b/foundryup/foundryup index 2dc94bfb49d3..55b0b5a4b053 100755 --- a/foundryup/foundryup +++ b/foundryup/foundryup @@ -3,6 +3,7 @@ set -eo pipefail BASE_DIR=${XDG_CONFIG_HOME:-$HOME} FOUNDRY_DIR=${FOUNDRY_DIR:-"$BASE_DIR/.foundry"} +FOUNDRY_VERSIONS_DIR="$FOUNDRY_DIR/versions" FOUNDRY_BIN_DIR="$FOUNDRY_DIR/bin" FOUNDRY_MAN_DIR="$FOUNDRY_DIR/share/man/man1" @@ -22,7 +23,9 @@ main() { -r|--repo) shift; FOUNDRYUP_REPO=$1;; -b|--branch) shift; FOUNDRYUP_BRANCH=$1;; - -v|--version) shift; FOUNDRYUP_VERSION=$1;; + -i|--install) shift; FOUNDRYUP_VERSION=$1;; + -l|--list) shift; list;; + -u|--use) shift; FOUNDRYUP_VERSION=$1; use;; -p|--path) shift; FOUNDRYUP_LOCAL_REPO=$1;; -P|--pr) shift; FOUNDRYUP_PR=$1;; -C|--commit) shift; FOUNDRYUP_COMMIT=$1;; @@ -137,15 +140,22 @@ main() { BIN_ARCHIVE_URL="${RELEASE_URL}foundry_${FOUNDRYUP_VERSION}_${PLATFORM}_${ARCHITECTURE}.$EXT" MAN_TARBALL_URL="${RELEASE_URL}foundry_man_${FOUNDRYUP_VERSION}.tar.gz" + ensure mkdir -p $FOUNDRY_VERSIONS_DIR # Download and extract the binaries archive - say "downloading latest forge, cast, anvil, and chisel" + say "downloading forge, cast, anvil, and chisel for $FOUNDRYUP_TAG version" if [ "$PLATFORM" = "win32" ]; then tmp="$(mktemp -d 2>/dev/null || echo ".")/foundry.zip" ensure download "$BIN_ARCHIVE_URL" "$tmp" - ensure unzip "$tmp" -d "$FOUNDRY_BIN_DIR" + ensure unzip "$tmp" -d "$FOUNDRY_VERSIONS_DIR/$FOUNDRYUP_TAG" rm -f "$tmp" else - ensure download "$BIN_ARCHIVE_URL" | ensure tar -xzC "$FOUNDRY_BIN_DIR" + tmp="$(mktemp -d 2>/dev/null || echo ".")/foundry.tar.gz" + ensure download "$BIN_ARCHIVE_URL" "$tmp" + # Make sure it's a valid tar archive. + ensure tar tf $tmp 1> /dev/null + ensure mkdir -p $FOUNDRY_VERSIONS_DIR/$FOUNDRYUP_TAG + ensure tar -C "$FOUNDRY_VERSIONS_DIR/$FOUNDRYUP_TAG" -xvf $tmp + rm -f "$tmp" fi # Optionally download the manuals @@ -159,6 +169,7 @@ main() { for bin in "${BINS[@]}"; do bin_path="$FOUNDRY_BIN_DIR/$bin" + cp $FOUNDRY_VERSIONS_DIR/$FOUNDRYUP_TAG/$bin $bin_path # Print installed msg say "installed - $(ensure "$bin_path" --version)" @@ -240,7 +251,9 @@ USAGE: OPTIONS: -h, --help Print help information - -v, --version Install a specific version from built binaries + -i, --install Install a specific version from built binaries + -l, --list List versions installed from built binaries + -u, --use Use a specific installed version from built binaries -b, --branch Build and install a specific branch -P, --pr Build and install a specific Pull Request -C, --commit Build and install a specific commit @@ -252,6 +265,41 @@ OPTIONS: EOF } +list() { + if [ -d "$FOUNDRY_VERSIONS_DIR" ]; then + for VERSION in $FOUNDRY_VERSIONS_DIR/*; do + say "${VERSION##*/}" + for bin in "${BINS[@]}"; do + bin_path="$VERSION/$bin" + say "- $(ensure "$bin_path" --version)" + done + printf "\n" + done + else + for bin in "${BINS[@]}"; do + bin_path="$FOUNDRY_BIN_DIR/$bin" + say "- $(ensure "$bin_path" --version)" + done + fi + exit 0 +} + +use() { + [ -z "$FOUNDRYUP_VERSION" ] && err "no version provided" + FOUNDRY_VERSION_DIR="$FOUNDRY_VERSIONS_DIR/$FOUNDRYUP_VERSION" + if [ -d "$FOUNDRY_VERSION_DIR" ]; then + for bin in "${BINS[@]}"; do + bin_path="$FOUNDRY_BIN_DIR/$bin" + cp $FOUNDRY_VERSION_DIR/$bin $bin_path + # Print usage msg + say "use - $(ensure "$bin_path" --version)" + done + exit 0 + else + err "version $FOUNDRYUP_VERSION not installed" + fi +} + say() { printf "foundryup: %s\n" "$1" } @@ -316,11 +364,11 @@ banner() { .xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx -Repo : https://github.com/foundry-rs/ +Repo : https://github.com/foundry-rs/foundry Book : https://book.getfoundry.sh/ Chat : https://t.me/foundry_rs/ Support : https://t.me/foundry_support/ -Contribute : https://github.com/orgs/foundry-rs/projects/2/ +Contribute : https://github.com/foundry-rs/foundry/blob/master/CONTRIBUTING.md .xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx.xOx