Block remapping or unmapping code mappings
[nativeclient.git] / tools / linux.x86_64.prep.sh
blob3b5a85f897436ab68213c53a04233d7364c8d654
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 function ensure_installed {
42 if ! [ -e "$1" ]
43 then
44 cat >&2 << EOF
45 ... you do not have $2. Installing...
46 EOF
47 if apt-get -y install "$2" > /dev/null 2>&1
48 then
49 echo "... done" >&2
50 else
51 cat >&2 <<EOF
52 ... failed to install $2.
54 ABORTING
55 EOF
56 exit 1
61 if ! isRunningAsRoot
62 then
63 cat >&2 << \EOF
64 Not running as root, so cannot install libraries/links.
65 Note: you probably will need to copy this script to the local file system
66 (and off of NFS) in order to run this script as root.
68 ABORTING.
69 EOF
70 exit 1
73 # openssl is required for both 32 and 64-bit systems.
74 ensure_installed '/usr/include/openssl/aes.h' 'libssl-dev'
75 # gtk-2.0 is required for both 32 and 64-bit systems
76 ensure_installed '/usr/include/gtk-2.0/gtk/gtk.h' 'libgtk2.0-dev'
78 cat > "$f" << \EOF
79 int main(void) { return sizeof(long) == 8; }
80 EOF
81 gcc -o "$fout" "$f" > /dev/null 2>&1
83 if "$fout"
84 then
85 cat << \EOF
86 You do not appear to be using an x86_64 system. This rest of this script
87 is not required.
88 EOF
89 exit 0
92 ensure_installed '/usr/lib32' 'ia32-libs'
93 ensure_installed '/usr/lib32/libncurses.a' 'lib32ncurses5-dev'
95 # now check for symlinks
97 function do_symlink {
98 declare -a vers
100 target="/usr/lib32/$1"
102 if ! [ -f "$target" ]
103 then
104 vers=($(echo "$target".*))
105 if (( ${#vers[@]} != 1 ))
106 then
107 cat >&2 << EOF
108 More than one version of $target.* exists. This script will
109 picks the lexicographically greatest one.
111 vers=("${vers[${#vers[@]}-1]}")
112 echo "Using $vers" >&2
114 cat >&2 <<EOF
115 Linking $target to $vers
117 ln -s "$vers" "$target"
121 declare -a dev_libs
122 dev_libs=(libatk-1.0.so libgtk-x11-2.0.so libgdk-x11-2.0.so \
123 libgdk_pixbuf-2.0.so libpangocairo-1.0.so libpango-1.0.so \
124 libcairo.so libgobject-2.0.so libgmodule-2.0.so libglib-2.0.so \
125 libXt.so libX11.so)
127 for lib in "${dev_libs[@]}"
129 do_symlink "$lib"
130 done
132 if [ -f /usr/lib32/libcrypto.so -a -f /usr/lib32/libssl.so ] && try
133 then
134 echo "You already have /usr/lib32/libcrypto.so and libssl.so"
135 else
137 # we omit libssl.so and libcrypto.so from dev_libs so we can ensure
138 # that ssl_vers is consistent between the two.
140 declare -a ssl_libs
141 ssl_libs=($(echo /usr/lib32/libssl.so.*))
142 if (( ${#ssl_libs[@]} != 1 ))
143 then
144 cat >&2 << \EOF
145 WARNING: More than one versions of /usr/lib32/libssl.so.* This script will
146 pick the lexicographically greatest one.
148 ssl_libs=(${ssl_libs[${#ssl_libs[@]}-1]})
149 echo "Using $ssl_libs" >&2
151 ssl_lib=${ssl_libs[0]}
153 ssl_vers=$(expr \( $ssl_lib : '/usr/lib32/libssl\.so\.\(.*\)' \))
154 case "$ssl_vers" in
155 ''|'*')
156 cat >&2 << \EOF
157 /usr/lib32/libssl.so.SSLVERSION missing. This should have been installed
158 as part of the ia32-libs package.
160 ABORTING.
162 exit 1
164 esac
165 if ! [ -f /usr/lib32/libcrypto.so.$ssl_vers ]
166 then
167 cat >&2 << EOF
168 Version mismatch: /usr/lib32/libssl.so.$ssl_vers exists, but
169 /usr/lib32/libcrypto.so.$ssl_vers does not!
171 ABORTING.
173 exit 1
175 echo "SSL version $ssl_vers shared libraries are available"
177 echo "Attempting to install ia32-libs-dev to get crypto libraries..." >&2
178 apt-get -y install ia32-libs-dev > /dev/null 2>&1
179 if [ -f /usr/lib32/libcrypto.so -a -f /usr/lib32/libssl.so ] && try
180 then
181 echo "Done."
182 exit 0
184 cat >&2 << \EOF
185 ... failed.
187 Fallback: attempting to install lib32bz2-dev to get crypto libraries...
189 apt-get -y install lib32bz2-dev > /dev/null 2>&1
190 if [ -f /usr/lib32/libcrypto.so -a -f /usr/lib32/libssl.so ] && try
191 then
192 echo "Done."
193 exit 0
195 cat >&2 << \EOF
196 ... failed.
198 Fallback: installing symlinks manually....
200 if ! ln -s libcrypto.so.$ssl_vers /usr/lib32/libcrypto.so
201 then
202 cat >&2 << \EOF
203 ... failed. Could not make symbolic links in /usr/lib32.
205 ABORTING.
207 exit 1
209 ln -s libssl.so.$ssl_vers /usr/lib32/libssl.so
211 if try
212 then
213 echo "Success."
214 else
215 echo "FAILED." >&2
216 exit 1