forked from crytic/solc-select
-
Notifications
You must be signed in to change notification settings - Fork 0
/
solc
executable file
·72 lines (62 loc) · 2.31 KB
/
solc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
function run_linux() {
export SSELECT_INSTALL_DIR="$HOME/.solc-select"
if [ ! -e "$SSELECT_INSTALL_DIR" ]; then
echo 'It appears you do not have solc-select installed, run `solc --install` to install it.'
exit 1
fi
if [[ "$1" == "--upgrade" ]] || [[ "$1" == "--install" ]]; then
if [[ "$1" == "--upgrade" ]]; then
echo "Upgrading solc-select..."
else
echo "Installing solc-select..."
fi
TMP_CLONE_DIR=/tmp/solc-select
rm -rf $TMP_CLONE_DIR
git clone "https://github.com/crytic/solc-select.git" $TMP_CLONE_DIR
$TMP_CLONE_DIR/scripts/install.sh
rm -rf $TMP_CLONE_DIR
else
$SSELECT_INSTALL_DIR/usr/bin/solc-runner $@
fi
}
function run_docker() {
if [[ "$1" == "--upgrade" ]] || [[ "$1" == "--install" ]]; then
if [[ "$1" == "--upgrade" ]]; then
echo "Upgrading solc-select..."
docker pull trailofbits/solc-select:latest
else
echo "Installing solc-select..."
fi
if [[ ! -z "$2" ]]; then
mkdir -p $2/bin
fi
export PREFIX="$2"
docker run --read-only -i --rm --entrypoint='/bin/sh' trailofbits/solc-select:latest -c 'cat /usr/bin/install.sh' | bash
else
docker run --read-only -i --rm --cap-add=SYS_ADMIN -e SOLC_VERSION="$SOLC_VERSION" -e HOST_PWD="$PWD" --mount type=bind,source=/,target=/workdir trailofbits/solc-select:latest $@
fi
}
OS=$(uname)
# use command
if [ "$1" == "use" ]; then
if [[ -z "$2" ]]; then
echo "Need to provide a version to use. To list all available versions use 'solc --versions'"
# The next line will check that the provided version exists in the list of available versions
elif printf '%s\n' $(solc --versions) | grep -q -E "^$2$"; then
echo "export SOLC_VERSION=$2" >$HOME/.solcv
echo "Now using version $2"
else
echo "Version $2 not supported. List all available versions with 'solc --versions'"
fi
else
# Check that a solcv file exists in the home directory, and that the Version was not manually set by a user
if [ -f $HOME/.solcv ] && [[ -z $SOLC_VERSION ]]; then
source $HOME/.solcv
fi
if [ $OS = "Linux" ]; then
run_linux $@
else
run_docker $@
fi
fi