-
Notifications
You must be signed in to change notification settings - Fork 1
/
pqsetup.sh
executable file
·176 lines (146 loc) · 5.07 KB
/
pqsetup.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
#!/bin/bash
# Script to:
# 1. Install liboqs
# 2. Install OQS openssl
# This script is written for Ubuntu OS only.
BASE_DIR=$(pwd)
###############################################################################
################################## IMPORTANT ##################################
###############################################################################
# The variables in this section MUST be set for proper execution of this script.
#ABSOLUTE path to the directory to which OQS openssl should be installed:
OPENSSL_DIR=$BASE_DIR/openssl
###############################################################################
# -----------------------------------------------------------------------------
# logging helpers
# -----------------------------------------------------------------------------
function _log {
level=$1
msg=$2
case "$level" in
info)
tag="\e[1;36minfo\e[0m"
;;
err)
tag="\e[1;31merr \e[0m"
;;
warn)
tag="\e[1;33mwarn\e[0m"
;;
ok)
tag="\e[1;32m ok \e[0m"
;;
fail)
tag="\e[1;31mfail\e[0m"
;;
*)
tag=" "
;;
esac
echo -e "`date +%Y-%m-%dT%H:%M:%S` [$tag] $msg"
}
function _err {
msg=$1
_log "err" "$msg"
}
function _warn {
msg=$1
_log "warn" "$msg"
}
function _info {
msg=$1
_log "info" "$msg"
}
function _success {
msg=$1
_log "ok" "$msg"
}
function _fail {
msg=$1
_log "fail" "$msg"
}
# -----------------------------------------------------------------------------
# Checking dependencies
# -----------------------------------------------------------------------------
function check_dependencies {
DEPS=("bc" "astyle" "cmake" "gcc" "ninja-build" "libssl-dev" "python3-pytest" "python3-pytest-xdist" "unzip" "xsltproc" "doxygen" "graphviz" "python3-yaml" "valgrind" "libtool" "make" "git" "software-properties-common" "build-essential" "moreutils")
for d in ${DEPS[@]}; do
_info "Looking for '$d'"
found=0
PKG_OK=$(dpkg-query -W --showformat='${Status}\n' $d |grep "install ok installed")
if [ "" != "$PKG_OK" ]; then
_success "'$d' installed"
found=1
fi
if [ $found -eq 0 ]; then
_fail "Missing dependency: $d"
_info "On Debian/Ubuntu: apt-get install '$d'"
prompt_installer $d
fi
done
}
# -----------------------------------------------------------------------------
# Prompt installer
# -----------------------------------------------------------------------------
function prompt_installer {
read -p "Do you want to install it? [Y/n]: " -n 10 CHOICE
case $CHOICE in
y|Y|yes|YES|"")
sudo apt-get install $1
;;
*)
_info "Quitting..."
exit 1
;;
esac
}
# -----------------------------------------------------------------------------
# Main
# -----------------------------------------------------------------------------
OS=$(cat /etc/os-release | grep VERSION_ID | cut -d '"' -f2)
################################ VERSION CHECK ################################
# Ubuntu Jammy uses OpenSSL >= 3.x.x , and at the time of making this script OpenSSL 1.x.x is not installable.
# This may (or may not) be a problem. I haven't tried to install this in Jammy.
# If you believe it can successfully be installed on your system, feel free to remove the below check & clean up the rest of the if statement.
if (( $(echo "$OS < 18.04" |bc -l) )) || (( $(echo "$OS < 21.04" |bc -l) )); then
_fail "You are running Ubuntu version $OS, which may not support openssl 1.1.1"
else
################################ MEMORY CHECK ################################
# Building liboqs is VERY memory intensive, will likely fail on VMs with < 16GB RAM.
# I read somewhere that this command helps, but had no success with it myself.
# sysctl -w vm.overcommit_memory=2
# The workaround is to (temporarily) provision at least 16GB of RAM to the VM, then run this script.
# You can reduce the RAM afterwards when liboqs is built.
_info "Check dependencies"
check_dependencies
_info "OQS OpenSSL target directory set to $BASE_DIR/openssl"
git clone --branch OQS-OpenSSL_1_1_1-stable https://github.com/open-quantum-safe/openssl.git $OPENSSL_DIR
_info "Install liboqs to '$BASE_DIR'/liboqs"
git clone --branch main https://github.com/open-quantum-safe/liboqs.git
cd liboqs
mkdir build && cd build
cmake -GNinja -DCMAKE_INSTALL_PREFIX=$OPENSSL_DIR/oqs ..
ninja
ninja install
if [ $? -eq 0 ]; then
ninja clean
_success "Success"
else
ninja clean
_fail "Failed"
exit 1
fi
_info "Install OQS OpenSSL to $BASE_DIR/openssl"
cd $OPENSSL_DIR
./Configure no-shared linux-x86_64 -lm
make -j
if [ $? -eq 0 ]; then
_success "Success"
else
make clean
_fail "Failed"
exit 1
fi
cd $BASE_DIR
exit 0
fi