forked from ucsb-seclab/greed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·200 lines (164 loc) · 9.58 KB
/
setup.sh
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/bin/bash
# set -x
if [ ! $VIRTUAL_ENV ]; then
echo "${bold}${red}Can't install outside of a Python virtualenv${normal}"; exit 1
fi
bold=$(tput bold)
normal=$(tput sgr0)
red=$(tput setaf 160)
j=1
while (( $# >= 1 )); do
case $1 in
-j) j=$2; shift; shift;;
--no-gigahorse) NO_GIGAHORSE=TRUE; shift; shift;;
*) break;
esac;
done
# confirm whether the user wants to install gigahorse
if [ -z $NO_GIGAHORSE ]; then
read -rsn1 -p "This script will install gigahorse. If you don't want to install gigahorse, run $0 --no-gigahorse. Press any key to continue (ctrl-c to abort)"
echo
fi
# navigate to this script's directory
GREED_DIR=`dirname "${BASH_SOURCE[0]}"`
GREED_DIR=`readlink -f $GREED_DIR` || { echo "${bold}${red}Can't find greed absolute path ${normal}"; exit 1; }
GIGAHORSE_DIR=$GREED_DIR/gigahorse-toolchain
VIRTUAL_ENV_BIN=$VIRTUAL_ENV/bin
VIRTUAL_ENV_LIB=`echo $VIRTUAL_ENV/lib/python3.*/site-packages`
########################################################################################################################
########################################################################################################################
# DEPENDENCIES
########################################################################################################################
echo "Checking for dependencies.."
MISSING_APT_PACKAGES=()
IS_SOUFFLE_MISSING=FALSE
for package in gcc cmake gperf libgmp-dev; do
dpkg -l | grep -q $package || MISSING_APT_PACKAGES+=($package)
done
if [ -z $NO_GIGAHORSE ]; then
command -v >&- mkisofs || MISSING_APT_PACKAGES+=("mkisofs")
for package in bison build-essential clang cmake doxygen flex g++ git libffi7 libffi-dev libncurses5-dev libsqlite3-dev make mcpp python sqlite zlib1g-dev libboost-all-dev; do
dpkg -l | grep -q $package || MISSING_APT_PACKAGES+=($package)
done
command -v >&- souffle || IS_SOUFFLE_MISSING=TRUE
fi
source /etc/os-release
IS_UBUNTU=$([ $ID = "ubuntu" ] && echo TRUE || echo FALSE)
if [ ${#MISSING_APT_PACKAGES[@]} -gt 0 ]; then
echo "${bold}${red}The following packages are missing: ${MISSING_APT_PACKAGES[*]}. Please install them before proceeding (e.g., sudo apt install ${MISSING_APT_PACKAGES[*]})${normal}"
if [ $IS_UBUNTU = TRUE ]; then
read -rsn1 -p "Or press any key to install them now (ctrl-c to abort)"
sudo apt update && sudo apt install ${MISSING_APT_PACKAGES[*]} || { echo "${bold}${red}Failed to install missing packages${normal}"; exit 1; }
else
exit 1
fi
fi
if [ $IS_SOUFFLE_MISSING = TRUE ]; then
echo "${bold}${red}souffle is not installed. Please install it before proceeding (see https://github.com/souffle-lang/souffle/releases/tag/2.4 and https://souffle-lang.github.io/build, version 2.4 preferred)${normal}"
if [ $IS_UBUNTU = TRUE ]; then
read -rsn1 -p "Or press any key to install it now (ctrl-c to abort)"
wget https://github.com/souffle-lang/souffle/releases/download/2.4/x86_64-ubuntu-2004-souffle-2.4-Linux.deb -O /tmp/x86_64-ubuntu-2004-souffle-2.4-Linux.deb &&
sudo dpkg -i /tmp/x86_64-ubuntu-2004-souffle-2.4-Linux.deb &&
rm /tmp/x86_64-ubuntu-2004-souffle-2.4-Linux.deb || { rm -f /tmp/x86_64-ubuntu-2004-souffle-2.4-Linux.deb; echo "${bold}${red}Failed to install souffle${normal}"; exit 1; }
else
exit 1
fi
else
SOUFFLE_VERSION=$(souffle --version | grep -oP "Version: \K[0-9]+\.[0-9]+")
if [ $SOUFFLE_VERSION != "2.3" ] && [ $SOUFFLE_VERSION != "2.4" ]; then
echo "${bold}${red}souffle version $SOUFFLE_VERSION is not supported. Please install version 2.3 or 2.4 before proceeding${normal}";
exit 1;
fi
fi
########################################################################################################################
########################################################################################################################
# YICES
########################################################################################################################
# clone the yices2 repo
if [ ! -d $GREED_DIR/yices2 ]; then
git clone https://github.com/SRI-CSL/yices2.git $GREED_DIR/yices2
fi
cd $GREED_DIR/yices2
# check if all required packages are installed (cmake, cython, libgmp-dev)
# dpkg -l | grep -q gcc || { echo "${bold}${red}gcc is not installed. Please install it before proceeding (e.g., sudo apt install gcc)${normal}"; exit 1; }
# dpkg -l | grep -q cmake || { echo "${bold}${red}cmake is not installed. Please install it before proceeding (e.g., sudo apt install cmake)${normal}"; exit 1; }
# dpkg -l | grep -q gperf || { echo "${bold}${red}gperf is not installed. Please install it before proceeding (e.g., sudo apt install gperf)${normal}"; exit 1; }
# dpkg -l | grep -q libgmp-dev || { echo "${bold}${red}libgmp-dev is not installed. Please install it before proceeding (e.g., sudo apt install libgmp-dev)${normal}"; exit 1; }
# install
make clean || { echo "${bold}${red}Failed to run make clean ${normal}. Continuing..."; }
autoconf || { echo "${bold}${red}Failed to run autoconf${normal}"; exit 1; }
./configure || { echo "${bold}${red}Failed to run ./configure${normal}"; exit 1; }
make || { echo "${bold}${red}Failed to run make${normal}"; exit 1; }
# finally, link yices2/build/lib/ to the virtualenv's site-packages dir
ln -sf $GREED_DIR/yices2/build/*-release/bin/* $VIRTUAL_ENV_BIN/
ln -sf $GREED_DIR/yices2/build/*-release/lib/* $VIRTUAL_ENV_LIB/
LIBNAME=$(python -c 'from ctypes.util import find_library; print(find_library("yices") or "libyices.so")')
cp $VIRTUAL_ENV/lib/python3.*/site-packages/libyices.so.* $VIRTUAL_ENV_LIB/$LIBNAME
cd $GREED_DIR
# clone the yices2_python_bindings repo
if [ ! -d $GREED_DIR/yices2_python_bindings ]; then
git clone https://github.com/ruaronicola/yices2_python_bindings.git $GREED_DIR/yices2_python_bindings
fi
# We need libyices.so at build time, but pip will happily use an isolated build env unless we specify otherwise
# (and take care of installing build dependencies)
pip install setuptools wheel # build dependencies
pip install -e yices2_python_bindings --no-build-isolation
yices_python_info
########################################################################################################################
########################################################################################################################
# GIGAHORSE
########################################################################################################################
if [ -z $NO_GIGAHORSE ]; then
# install solc-select
pip install solc-select
# command -v >&- mkisofs || echo "${bold}${red}mkisofs is not installed. solc-select might not work correctly (e.g., sudo apt install mkisofs)${normal}"
solc-select versions | grep -q 0.8.7 || { echo "Installing solc 0.8.7"; solc-select install 0.8.7; solc-select use 0.8.7; }
# then install gigahorse from the official repo
echo "Number of parallel datalog jobs: $j (override with $0 -j N)"
read -rsn1 -p "Setting up gigahorse.. Press any key to continue (ctrl-c to abort)"
echo
# command -v >&- souffle || { echo "${bold}${red}souffle is not installed. Please install it before proceeding (see https://github.com/souffle-lang/souffle/releases/tag/2.4 and https://souffle-lang.github.io/build, version 2.4 preferred)${normal}"; echo "${bold}${red}Or maybe you forgot --no-gigahorse?${normal}"; exit 1; }
# dpkg -l | grep -q libboost-all-dev || { echo "${bold}${red}libboost-all-dev is not installed. Please install it before proceeding (e.g., sudo apt install libboost-all-dev)${normal}"; echo "${bold}${red}Or maybe you forgot --no-gigahorse?${normal}"; exit 1; }
# clone the gigahorse-toolchain repo
if [ ! -d $GREED_DIR/gigahorse-toolchain ]; then
git clone --recursive https://github.com/nevillegrech/gigahorse-toolchain.git $GIGAHORSE_DIR
cd $GIGAHORSE_DIR
git checkout 10de8a71ca7b12f657e0de18e455e02d408089b8
fi
# copy greed client
cp $GREED_DIR/resources/greed_client.dl $GIGAHORSE_DIR/clientlib/
# compile souffle-addon
echo "Compiling souffle-addon.."
cd $GIGAHORSE_DIR/souffle-addon
make || { echo "${bold}${red}Failed to build gigahorse's souffle-addon${normal}"; exit 1; }
cd $GREED_DIR
# compile gigahorse clients
echo "Compiling gigahorse clients. This will take some time.."
function compile () {
echo "Compiling $1.."
souffle --jobs $j -M "GIGAHORSE_DIR=$GIGAHORSE_DIR BULK_ANALYSIS=" -o $GIGAHORSE_DIR/clients/$1_compiled.tmp $GIGAHORSE_DIR/$2 -L $GIGAHORSE_DIR/souffle-addon || { echo "${bold}${red}Failed to build $1_compiled${normal}"; exit 1; } &&
mv $GIGAHORSE_DIR/clients/$1_compiled.tmp $GIGAHORSE_DIR/clients/$1_compiled &&
mv $GIGAHORSE_DIR/clients/$1_compiled.tmp.cpp $GIGAHORSE_DIR/clients/$1_compiled.cpp &&
echo "Successfully compiled $1.."
}
compile "main.dl" "logic/main.dl"
compile "greed_client.dl" "clientlib/greed_client.dl"
else
true
fi
########################################################################################################################
########################################################################################################################
# GREED
########################################################################################################################
# link our scripts into virtualenv's bin dir
echo "Linking scripts into virtualenv's bin directory.."
for script in $GREED_DIR/resources/{*.sh,*.py}; do
ln -sf $script $VIRTUAL_ENV_BIN/
done
# create alias for run.py
echo "Creating alias run.py -> greed.."
ln -sf $GREED_DIR/resources/run.py $VIRTUAL_ENV_BIN/greed
# install greed
pip install -e $GREED_DIR
########################################################################################################################
# set +x