Skip to content

Commit

Permalink
feat(foundryup): add foundryup self-update (foundry-rs#9609)
Browse files Browse the repository at this point in the history
* feat(foundryup):: add self-update

Signed-off-by: 9547 <[email protected]>

* renmae to --update

Signed-off-by: 9547 <[email protected]>

* download to tmp file first

Signed-off-by: 9547 <[email protected]>

---------

Signed-off-by: 9547 <[email protected]>
  • Loading branch information
9547 authored Jan 13, 2025
1 parent e7a0693 commit 92fefaf
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions foundryup/foundryup
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ 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"
FOUNDRY_BIN_URL="https://raw.githubusercontent.com/foundry-rs/foundry/master/foundryup/foundryup"
FOUNDRY_BIN_PATH="$FOUNDRY_BIN_DIR/foundryup"

FOUNDRYUP_JOBS=""

Expand All @@ -30,6 +32,7 @@ main() {
-P|--pr) shift; FOUNDRYUP_PR=$1;;
-C|--commit) shift; FOUNDRYUP_COMMIT=$1;;
-j|--jobs) shift; FOUNDRYUP_JOBS=$1;;
-U|--update) shift; update;;
--arch) shift; FOUNDRYUP_ARCH=$1;;
--platform) shift; FOUNDRYUP_PLATFORM=$1;;
-h|--help)
Expand Down Expand Up @@ -260,6 +263,7 @@ OPTIONS:
-r, --repo Build and install from a remote GitHub repo (uses default branch if no other options are set)
-p, --path Build and install a local repository
-j, --jobs Number of CPUs to use for building Foundry (default: all CPUs)
-U, --update Update foundryup to the latest version
--arch Install a specific architecture (supports amd64 and arm64)
--platform Install a specific platform (supports win32, linux, and darwin)
EOF
Expand Down Expand Up @@ -300,6 +304,21 @@ use() {
fi
}

update() {
say "updating foundryup..."

# Download to a temporary file first
tmp_file="$(mktemp)"
ensure download "$FOUNDRY_BIN_URL" "$tmp_file"

# Replace the current foundryup with the downloaded file
ensure mv "$tmp_file" "$FOUNDRY_BIN_PATH"
ensure chmod +x "$FOUNDRY_BIN_PATH"

say "successfully updated foundryup"
exit 0
}

say() {
printf "foundryup: %s\n" "$1"
}
Expand Down

0 comments on commit 92fefaf

Please sign in to comment.