Fix NaClVmmapUpdate and add test
[nativeclient.git] / tools / linux.x86_64.prep.sh
blobea0fa00c33b9e3a86c1916126743a4fb1aae6ea8
1 #!/bin/bash
2 PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin
4 umask=077
5 d=${TMPDIR:-/tmp}/nacl64.$$
6 if ! mkdir "$d" > /dev/null 2>&1
7 then
8 cat >&2 << EOF
9 Could not create safe temporary directory "$d".
11 ABORTING.
12 EOF
13 exit 1
15 f="$d/x.c"
16 fout="$d/x"
17 trap 'rm -fr "$d"; exit' 0 1 2 3 15
19 function isRunningAsRoot() {
20 whoami | grep -q 'root'
23 function try() {
24 cat > "$f" << EOF
25 #include <openssl/aes.h>
26 int main(void) {
27 AES_KEY k;
28 char key[AES_BLOCK_SIZE];
30 AES_set_encrypt_key(key, AES_BLOCK_SIZE * 8, &k);
31 return 0;
33 EOF
34 if ! gcc -o "$fout" "$f" -lssl -lcrypto > /dev/null 2>&1
35 then
36 return 1
38 return 0
41 if ! [ -f /usr/include/openssl/aes.h ]
42 then
43 cat >&2 << \EOF
44 libssl-dev not installed. Installing...
45 EOF
46 if apt-get install libssl-dev
47 then
48 echo "Success." >&2
49 else
50 cat >&2 << \EOF
51 ... could not install libssl-dev.
53 ABORTING.
54 EOF
55 exit 1
59 cat > "$f" << \EOF
60 int main(void) { return sizeof(long) == 8; }
61 EOF
62 gcc -o "$fout" "$f" > /dev/null 2>&1
64 if "$fout"
65 then
66 cat << \EOF
67 You do not appear to be using an x86_64 system. This rest of this script
68 is not required.
69 EOF
70 exit 0
73 if ! isRunningAsRoot
74 then
75 cat >&2 << \EOF
76 Not running as root, so cannot install libraries/links.
77 Note: you probably will need to copy this script to the local file system
78 (and off of NFS) in order to run this script as root.
80 ABORTING.
81 EOF
82 exit 1
85 if ! [ -d /usr/lib32 ]
86 then
87 cat >&2 << \EOF
88 ... you do not have /usr/lib32 at all!
90 First, must install ia32-libs...
91 EOF
92 if apt-get install ia32-libs > /dev/null 2>&1
93 then
94 echo "... done" >&2
95 else
96 cat >&2 << \EOF
97 ... failed to install ia32-libs.
99 ABORTING.
101 exit 1
105 declare -a x11_libs
107 if ! [ -f /usr/lib32/libX11.so ]
108 then
109 x11_libs=($(echo /usr/lib32/libX11.so.*))
110 if (( ${#x11_libs[@]} != 1 ))
111 then
112 cat >&2 << \EOF
113 More than one version of /usr/lib32/libX11.so.* exists. This script will
114 picks the lexicographically greatest one.
116 x11_libs=(${x11_libs[${#x11_libs[@]}-1]})
117 echo "Using $x11_libs" >&2
119 cat >&2 <<EOF
120 Linking /usr/lib32/libX11.so to $x11_libs
122 ln -s $x11_libs /usr/lib32/libX11.so
125 if [ -f /usr/lib32/libcrypto.so -a -f /usr/lib32/libssl.so ] && try
126 then
127 echo "You already have /usr/lib32/libcrypto.so and libssl.so"
128 exit 0
131 declare -a ssl_libs
132 ssl_libs=($(echo /usr/lib32/libssl.so.*))
133 if (( ${#ssl_libs[@]} != 1 ))
134 then
135 cat >&2 << \EOF
136 WARNING: More than one versions of /usr/lib32/libssl.so.* This script will
137 pick the lexicographically greatest one.
139 ssl_libs=(${ssl_libs[${#ssl_libs[@]}-1]})
140 echo "Using $ssl_libs" >&2
142 ssl_lib=${ssl_libs[0]}
144 ssl_vers=$(expr \( $ssl_lib : '/usr/lib32/libssl\.so\.\(.*\)' \))
145 case "$ssl_vers" in
146 ''|'*')
147 cat >&2 << \EOF
148 /usr/lib32/libssl.so.SSLVERSION missing. This should have been installed
149 as part of the ia32-libs package.
151 ABORTING.
153 exit 1
155 esac
156 if ! [ -f /usr/lib32/libcrypto.so.$ssl_vers ]
157 then
158 cat >&2 << EOF
159 Version mismatch: /usr/lib32/libssl.so.$ssl_vers exists, but
160 /usr/lib32/libcrypto.so.$ssl_vers does not!
162 ABORTING.
164 exit 1
166 echo "SSL version $ssl_vers shared libraries are available"
168 echo "Attempting to install ia32-libs-dev to get crypto libraries..." >&2
169 apt-get install ia32-libs-dev > /dev/null 2>&1
170 if [ -f /usr/lib32/libcrypto.so -a -f /usr/lib32/libssl.so ] && try
171 then
172 echo "Done."
173 exit 0
175 cat >&2 << \EOF
176 ... failed.
178 Attempting to install lib32bz2-dev to get crypto libraries...
180 apt-get install lib32bz2-dev > /dev/null 2>&1
181 if [ -f /usr/lib32/libcrypto.so -a -f /usr/lib32/libssl.so ] && try
182 then
183 echo "Done."
184 exit 0
186 cat >&2 << \EOF
187 ... failed.
189 Falling back to installing symlinks manually....
191 if ! ln -s libcrypto.so.$ssl_vers /usr/lib32/libcrypto.so
192 then
193 cat >&2 << \EOF
194 ... failed. Could not make symbolic links in /usr/lib32.
196 ABORTING.
198 exit 1
200 ln -s libssl.so.$ssl_vers /usr/lib32/libssl.so
201 if try
202 then
203 echo "Success."
204 else
205 echo "FAILED." >&2
206 exit 1