-
Notifications
You must be signed in to change notification settings - Fork 366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Init simple installer #1082
base: master
Are you sure you want to change the base?
Init simple installer #1082
Changes from 5 commits
55c9020
e72d4b2
6364d2b
96ed260
58f5412
f8e0f01
c8b561e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
dist | ||
result | ||
dist-* | ||
cabal-dev | ||
*.o | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
version="2.2.0" | ||
|
||
# Do nothing if echidna is already installed | ||
if echidna-test --version > /dev/null 2>&1 | ||
then | ||
echo "WARNING: $(echidna-test --version) is installed but is out-of-date, we recommend removing it" | ||
fi | ||
|
||
# Do nothing if echidna is already installed | ||
if echidna --version > /dev/null 2>&1 | ||
then | ||
echo "$(echidna --version) is already installed" && exit | ||
# TODO: check that the version is up to date, otherwise offer to upgrade | ||
fi | ||
|
||
# In the unlikely scenario that python3 isn't available, let the user install it manually | ||
if ! python3 --version > /dev/null 2>&1 | ||
then echo "python3 is not available, please install it manually before attempting to install echidna" && exit 1 | ||
fi | ||
|
||
# install pip3 if not already installed | ||
if ! pip3 --version > /dev/null 2>&1 | ||
then | ||
echo "pip3 is not available, installing it now.." | ||
curl https://bootstrap.pypa.io/get-pip.py | python3 | ||
fi | ||
|
||
# install slither if not already installed | ||
if ! slither --version > /dev/null 2>&1 | ||
then | ||
echo "slither is not available, installing it now.." | ||
pip3 install slither-analyzer --user | ||
fi | ||
|
||
echo "Installing Echidna v$version.." | ||
|
||
BASE_DIR=${XDG_CONFIG_HOME:-$HOME} | ||
ECHIDNA_DIR=${ECHIDNA_DIR-"$BASE_DIR/.echidna"} | ||
ECHIDNA_BIN_DIR="$ECHIDNA_DIR/bin" | ||
ECHIDNA_ARCHIVE_DIR="$ECHIDNA_DIR/v$version" | ||
ECHIDNA_ARCHIVE_PATH="$ECHIDNA_ARCHIVE_DIR/echidna.tar.gz" | ||
ECHIDNA_DIGEST_PATH="$ECHIDNA_ARCHIVE_DIR/echidna.sha256" | ||
TRUE_BIN_PATH="$ECHIDNA_ARCHIVE_DIR/echidna/echidna" | ||
BIN_PATH="$ECHIDNA_BIN_DIR/echidna" | ||
|
||
if [[ "$(uname)" == "Darwin" ]] | ||
then arch="MacOS" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should differentiate ARM vs x86 builds, maybe by inspecting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a separate release for ARM vs x86 macs? Under release assets I only see MacOS vs Ubuntu vs Windows There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bohendo yeah, there's MacOS-aarch64 files, with a different structure inside the tarball, e.g see https://github.com/crytic/echidna/releases/tag/v2.1.0 These are manually built (with the nix bundle target in the readme), compressed and uploaded; it seems the latest release is missing them. We used to have a more comprehensive build process that generated a ready to upload archive and fixed TERMINFO on the resulting binaries (the current process has this bug again), maybe we can bring that back to aid releases going forward? |
||
elif [[ "$(uname)" == "Linux" ]] | ||
then arch="Ubuntu" | ||
else echo "Unsupported system: $(uname)" && exit 1 | ||
fi | ||
|
||
TARBALL_URL="https://github.com/crytic/echidna/releases/download/v$version/echidna-$version-$arch.tar.gz" | ||
DIGEST_URL="https://github.com/crytic/echidna/releases/download/v$version/echidna-$version-$arch.tar.gz.sha256" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Our digests are not signed, so someone tampering with the releases may also modify the digest. Is this meant only as an integrity check? Otherwise hardcoding the hashes next to the version in the script may provide a bit more of certainty (unless someone tampers with the script as well) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just integrity, hardcoding the hashes seems like a better path forward 👍 |
||
|
||
# Create the .echidna bin directory and echidna binary if it doesn't exist. | ||
mkdir -p "$ECHIDNA_ARCHIVE_DIR" | ||
pushd "$ECHIDNA_ARCHIVE_DIR" > /dev/null || exit 1 | ||
|
||
# Fetch the digest if not already present | ||
if [[ ! -f "$ECHIDNA_DIGEST_PATH" ]] | ||
then | ||
echo "Downloading the sha256 digest of the echidna archive" | ||
curl -# -L "$DIGEST_URL" -o "$ECHIDNA_DIGEST_PATH" | ||
fi | ||
digest="$(cut -d " " -f 1 < "$ECHIDNA_DIGEST_PATH")" | ||
|
||
# Download the tarball if it's not present or if the digest is wrong | ||
if [[ -f "$ECHIDNA_ARCHIVE_PATH" ]] | ||
then | ||
if [[ "$digest" != "$(sha256sum "$ECHIDNA_ARCHIVE_PATH" | cut -d " " -f 1)" ]] | ||
then | ||
echo "Wrong digest, deleting and re-downloading.." | ||
rm -f "$ECHIDNA_ARCHIVE_PATH" | ||
echo "Downloading the echidna archive" | ||
curl -# -L "$TARBALL_URL" -o "$ECHIDNA_ARCHIVE_PATH" | ||
fi | ||
if [[ "$digest" != "$(sha256sum "$ECHIDNA_ARCHIVE_PATH" | cut -d " " -f 1)" ]] | ||
then echo "Wrong digest again, something's seriously wrong, aborting.." && exit 1 | ||
else echo "Echidna v$version archive already exists and has the expected sha256 digest, moving on.." | ||
fi | ||
else | ||
echo "Downloading the echidna archive" | ||
curl -# -L "$TARBALL_URL" -o "$ECHIDNA_ARCHIVE_PATH" | ||
if [[ "$digest" != "$(sha256sum "$ECHIDNA_ARCHIVE_PATH" | cut -d " " -f 1)" ]] | ||
then echo "Wrong digest, something's seriously wrong, aborting.." && exit 1 | ||
fi | ||
fi | ||
|
||
if [[ ! -d "echidna" ]] | ||
then tar xzf "$ECHIDNA_ARCHIVE_PATH" | ||
fi | ||
|
||
if [[ ! -f "$TRUE_BIN_PATH" || ! -x "$TRUE_BIN_PATH" ]] | ||
then echo "Failed to extract an executable echidna binary" && exit 1 | ||
fi | ||
|
||
popd > /dev/null || exit 1 | ||
pushd "$ECHIDNA_DIR" > /dev/null || exit 1 | ||
mkdir -p "$ECHIDNA_BIN_DIR" | ||
# If a link alreaady exists here, remove it | ||
if [[ -f "$BIN_PATH" ]] | ||
then rm -f "$BIN_PATH" | ||
fi | ||
# Add a symlink to the current version of echidna | ||
ln -s "$TRUE_BIN_PATH" "$BIN_PATH" | ||
popd > /dev/null || exit 1 | ||
|
||
# Store the correct profile file (i.e. .profile for bash or .zshenv for ZSH). | ||
case $SHELL in | ||
*/zsh) | ||
PROFILE=${ZDOTDIR-"$HOME"}/.zshenv | ||
PREF_SHELL=zsh | ||
;; | ||
*/bash) | ||
PROFILE=$HOME/.bashrc | ||
PREF_SHELL=bash | ||
;; | ||
*/fish) | ||
PROFILE=$HOME/.config/fish/config.fish | ||
PREF_SHELL=fish | ||
;; | ||
*/ash) | ||
PROFILE=$HOME/.profile | ||
PREF_SHELL=ash | ||
;; | ||
*) | ||
echo "echidna: could not detect shell, manually add ${ECHIDNA_BIN_DIR} to your PATH." | ||
exit 1 | ||
esac | ||
|
||
# Only add echidna if it isn't already in PATH. | ||
if [[ ":$PATH:" != *":${ECHIDNA_BIN_DIR}:"* ]]; then | ||
# Add the echidna directory to the path and ensure the old PATH variables remain. | ||
(echo >> "$PROFILE" && echo "export PATH=\"\$PATH:$ECHIDNA_BIN_DIR\"" >> "$PROFILE") || (echo "Failed to add echidna to your PATH, is $PROFILE read only?" && exit 1) | ||
fi | ||
|
||
echo && echo "Detected your preferred shell is ${PREF_SHELL} and added echidna to PATH. Run 'source ${PROFILE}' or start a new terminal session to use echidna." | ||
echo "Then, simply run 'echidna --help' to learn how to use this fuzz tester." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be cool to have slither updated if it's out of date. PATH may also need to be adjusted to account for slither installed with
--user
.Maybe we should use a (fresh?) venv instead and just link
slither{,-*}
andcrytic-compile
to the directory we then add to the PATH for echidna?