forked from gakonst/ethers-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(forgeup): first draft * feat(forgeup): support cloning * feat(forgeup): wip * feat(forgeup): install script * feat(forgeup): move binaries into cargo bin * fix(forgeup): stale vars * fix(forgeup): args & env vars * fix(forgeup): remove -i * docs(forgeup): cleanup comments * docs(forgeup): more comments * docs(forgeup): cleanup comments * docs(forgeup): cleanup comments * fix(forgeup): fix sysctl throw Co-authored-by: Bjerg <[email protected]> * refactor(forgeup): cleanup & comments * docs(forgeup): install instructions * docs(forgeup): readme * docs(forgeup): cleanup language * docs(forgeup): update wording Co-authored-by: Bjerg <[email protected]>
- Loading branch information
1 parent
2451c4a
commit 0e0e908
Showing
3 changed files
with
175 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# `forgeup` | ||
|
||
Update or revert to a specific Foundry branch with ease. | ||
|
||
## Installing | ||
|
||
```sh | ||
curl https://raw.githubusercontent.com/gakonst/foundry/master/forgeup/install | bash | ||
``` | ||
|
||
## Usage | ||
|
||
To install the **nightly** version: | ||
|
||
```sh | ||
forgeup | ||
``` | ||
|
||
To install a specific **version** (in this case the `nightly` version): | ||
|
||
```sh | ||
forgeup --version nightly | ||
``` | ||
|
||
To install a specific **branch** (in this case the `release/0.1.0` branch's latest commit): | ||
|
||
```sh | ||
forgeup --branch release/0.1.0 | ||
``` | ||
|
||
To install a **fork's main branch** (in this case `transmissions11/foundry`'s main branch): | ||
|
||
```sh | ||
forgeup --repo transmissions11/foundry | ||
``` | ||
|
||
To install a **specific branch in a fork** (in this case the `patch-10` branch's latest commit in `transmissions11/foundry`): | ||
|
||
```sh | ||
forgeup --repo transmissions11/foundry --branch patch-10 | ||
``` | ||
|
||
--- | ||
|
||
**Tip**: All flags have a single character shorthand equivalent! You can use `-v` instead of `--version`, etc. | ||
|
||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
echo Installing forgeup... | ||
|
||
FORGEUP_DIR=${FORGEUP_DIR-"$HOME/.forgeup"} | ||
|
||
FORGEUP='#!/usr/bin/env bash | ||
set -e | ||
FORGEUP_DIR=${FORGEUP_DIR-"$HOME/.forgeup"} | ||
while [[ $1 ]]; do | ||
case $1 in | ||
--) shift; break;; | ||
-r|--repo) shift; FORGEUP_REPO=$1;; | ||
-b|--branch) shift; FORGEUP_BRANCH=$1;; | ||
-v|--version) shift; FORGEUP_VERSION=$1;; | ||
*) printf "forgeup: internal error: %q\\n" "$1"; exit 1 | ||
esac; shift | ||
done | ||
FORGEUP_REPO=${FORGEUP_REPO-gakonst/foundry} | ||
if [[ "$FORGEUP_REPO" == "gakonst/foundry" && -z "$FORGEUP_BRANCH" ]]; then | ||
FORGEUP_VERSION=${FORGEUP_VERSION-nightly} | ||
PLATFORM="$(uname -s)" | ||
case $PLATFORM in | ||
Linux) | ||
PLATFORM="linux" | ||
;; | ||
Darwin) | ||
PLATFORM="darwin" | ||
;; | ||
*) | ||
echo "forgeup: unsupported platform: $PLATFORM" | ||
exit 1 | ||
;; | ||
esac | ||
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" ]; then | ||
ARCHITECTURE="arm64" # Arm. | ||
else | ||
ARCHITECTURE="amd64" # Amd. | ||
fi | ||
# Download the release tarball from the repository, unpack it and move the forge and cast binaries into the cargo bin directory. | ||
# Will replace the existing binaries if they were installed via cargo, can be undone at any time by running cargo install again, if desired. | ||
curl -L https://github.com/${FORGEUP_REPO}/releases/download/${FORGEUP_VERSION}/foundry_${FORGEUP_VERSION}_${PLATFORM}_${ARCHITECTURE}.tar.gz | tar xvz | ||
mv forge $HOME/.cargo/bin/forge | ||
mv cast $HOME/.cargo/bin/cast | ||
else | ||
FORGEUP_BRANCH=${FORGEUP_BRANCH-master} | ||
if ! command -v cargo &> /dev/null ; then | ||
# Error if cargo is not already installed. | ||
echo "forgeup: cargo is not installed. Please install it first." | ||
exit 1 | ||
fi | ||
REPO_PATH="${FORGEUP_DIR}/${FORGEUP_REPO}" | ||
if [ -d $REPO_PATH ]; then | ||
# If the repo path exists move to it, git pull, and checkout the branch and cargo install local. | ||
cd $REPO_PATH | ||
git pull | ||
git checkout ${FORGEUP_BRANCH} | ||
git pull | ||
cargo install --path ./cli --bins --locked --force | ||
else | ||
# Repo path did not exist, grab the author from the repo, make a directory in .forgeup, cd to it, clone and install. | ||
IFS="/" read -ra AUTHOR <<< "$FORGEUP_REPO" | ||
mkdir -p "$FORGEUP_DIR/$AUTHOR" | ||
cd "$FORGEUP_DIR/$AUTHOR" | ||
git clone https://github.com/${FORGEUP_REPO} | ||
cd $REPO_PATH | ||
git checkout ${FORGEUP_BRANCH} | ||
cargo install --path ./cli --bins --locked --force | ||
fi | ||
fi' | ||
|
||
BINARY="$FORGEUP_DIR/forgeup" | ||
|
||
# Create the forgeup directory and binary file if it doesn't exist. | ||
mkdir -p $FORGEUP_DIR | ||
echo "$FORGEUP" > $BINARY | ||
chmod +x $BINARY | ||
|
||
# Store the correct profile file (i.e. .profile for bash or .zshrc for ZSH). | ||
case $SHELL in | ||
*/zsh) | ||
PROFILE=$HOME/.zshrc | ||
PREF_SHELL=zsh | ||
;; | ||
*/bash) | ||
PROFILE=$HOME/.profile | ||
PREF_SHELL=bash | ||
;; | ||
*) | ||
echo "forgeup: could not detect shell, manually add ${FORGEUP_DIR} to your PATH." | ||
exit 1 | ||
esac | ||
|
||
# Only add forgeup if it isn't already in PATH. | ||
if [[ ":$PATH:" != *":${FORGEUP_DIR}:"* ]]; then | ||
# Add the forgeup directory to the path and ensure the old PATH variables remain. | ||
echo >> $PROFILE && echo "export PATH=\"\$PATH:$FORGEUP_DIR\"" >> $PROFILE | ||
fi | ||
|
||
echo && echo "Detected your preferred shell is ${PREF_SHELL} and added forgeup to PATH. Run run source after this script runs, or start a new terminal session to use forgeup." |