Skip to content

Commit

Permalink
fix: address script issue
Browse files Browse the repository at this point in the history
  • Loading branch information
dutterbutter committed Jan 31, 2025
1 parent 5ba773b commit 409dc42
Showing 1 changed file with 75 additions and 19 deletions.
94 changes: 75 additions & 19 deletions foundryup-zksync/foundryup-zksync
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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;;
Expand Down Expand Up @@ -86,19 +89,34 @@ main() {

# Install by downloading binaries
if [[ "$FOUNDRYUP_REPO" == "matter-labs/foundry-zksync" && -z "$FOUNDRYUP_BRANCH" && -z "$FOUNDRYUP_COMMIT" ]]; then
FOUNDRYUP_VERSION=${FOUNDRYUP_VERSION:-nightly}
FOUNDRYUP_TAG=$FOUNDRYUP_VERSION

# Normalize versions (handle channels, versions without v prefix
if [[ "$FOUNDRYUP_VERSION" =~ ^nightly ]]; then
FOUNDRYUP_VERSION="nightly"
elif [[ "$FOUNDRYUP_VERSION" == [[:digit:]]* ]]; then
# Add v prefix
FOUNDRYUP_VERSION="v${FOUNDRYUP_VERSION}"
FOUNDRYUP_TAG="${FOUNDRYUP_VERSION}"
# If --version not specified, fetch the latest release tag from GitHub
if [ -z "$FOUNDRYUP_VERSION" ]; then
# No --version passed -> Use the "latest" semantic-release tag
LATEST_TAG=$(curl -s https://api.github.com/repos/${FOUNDRYUP_REPO}/releases/latest | \
sed -n 's/.*"tag_name": "\([^"]*\)".*/\1/p')
if [ -z "$LATEST_TAG" ]; then
err "could not fetch the latest release tag for $FOUNDRYUP_REPO!"
fi
FOUNDRYUP_TAG="$LATEST_TAG"

say "installing foundry (version ${FOUNDRYUP_VERSION}, tag ${FOUNDRYUP_TAG})"
else
# --version was specified; check if it's nightly or a numeric version, etc.
if [[ "$FOUNDRYUP_VERSION" == "nightly" ]]; then
say "Installing the nightly build"
FOUNDRYUP_TAG="nightly"
elif [[ "$FOUNDRYUP_VERSION" =~ ^foundry-zksync-v ]]; then
# user passed full "foundry-zksync-v0.0.4"
FOUNDRYUP_TAG="$FOUNDRYUP_VERSION"
elif [[ "$FOUNDRYUP_VERSION" =~ ^v ]]; then
# user passed "v0.0.4"
FOUNDRYUP_TAG="foundry-zksync-$FOUNDRYUP_VERSION"
else
# user passed "0.0.4"
FOUNDRYUP_TAG="foundry-zksync-v$FOUNDRYUP_VERSION"
fi

say "installing foundry-zksync ($FOUNDRYUP_TAG)"
fi

uname_s=$(uname -s)
PLATFORM=$(tolower "${FOUNDRYUP_PLATFORM:-$uname_s}")
Expand Down Expand Up @@ -133,21 +151,21 @@ main() {
fi

# Compute the URL of the release tarball in the Foundry repository.
ARCHIVE_TAG=$(echo "$FOUNDRYUP_VERSION" | tr '-' '_')
ARCHIVE_TAG=$(echo "$FOUNDRYUP_TAG" | tr '-' '_')
RELEASE_URL="https://github.com/${FOUNDRYUP_REPO}/releases/download/${FOUNDRYUP_TAG}/"
BIN_ARCHIVE_URL="${RELEASE_URL}${ARCHIVE_TAG}_${PLATFORM}_${ARCHITECTURE}.$EXT"
MAN_TAG=$(echo "$FOUNDRYUP_VERSION" | sed 's/^foundry-zksync-//')
MAN_TAG=$(echo "$FOUNDRYUP_TAG" | sed 's/^foundry-zksync-//')
MAN_TARBALL_URL="${RELEASE_URL}foundry_man_${MAN_TAG}.tar.gz"

# Download and extract the binaries archive
say "downloading latest forge, and cast"
if [ "$PLATFORM" = "win32" ]; then
tmp="$(mktemp -d 2>/dev/null || echo ".")/foundry-zksync.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"
ensure download "$BIN_ARCHIVE_URL" | ensure tar -xzC "$FOUNDRY_BIN_DIR"
fi

# Optionally download the manuals
Expand All @@ -161,6 +179,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)"
Expand Down Expand Up @@ -298,14 +317,16 @@ The installer for Foundry-zksync.
Update or revert to a specific Foundry-zksync version with ease.
By default, the latest nightly version is installed from built binaries.
By default, the latest stable version is installed from built binaries.
USAGE:
foundryup-zksync <OPTIONS>
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
Expand All @@ -317,6 +338,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-zksync: %s\n" "$1"
}
Expand Down

0 comments on commit 409dc42

Please sign in to comment.