-
Notifications
You must be signed in to change notification settings - Fork 8
/
install_fpga_mgmt_tools.sh
executable file
·124 lines (111 loc) · 3.69 KB
/
install_fpga_mgmt_tools.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
#!/bin/bash
#
# Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You may
# not use this file except in compliance with the License. A copy of the
# License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.
#
if [ -z "$SDK_DIR" ]; then
echo "Error: SDK_DIR environment variable is not set. Please 'source sdk_setup.sh' from the aws-fpga directory first."
exit 1
fi
if [ $EUID != 0 ]; then
echo ""
echo "Root privileges are required to install. You may be asked for your password..."
sudo -E "$0" "$@"
exit $?
else
echo "Executing as root..."
echo ""
fi
BASE_PATH=/usr/local
# check to see if the /usr/local/bin is on the sudo PATH (is secure_path enabled?)
echo $PATH | grep "$BASE_PATH"
ret=$?
if [ $ret -ne "0" ]; then
BASE_PATH=/usr
fi
SDK_MGMT_DIR=$SDK_DIR/userspace
AFI_MGMT_TOOLS_SRC_DIR=$SDK_MGMT_DIR/fpga_mgmt_tools/src
AFI_MGMT_TOOLS_DST_DIR=$BASE_PATH/bin
AFI_MGMT_TOOLS_LIB_DIR=$SDK_MGMT_DIR/lib/so
# in order to accommodate different distributions, check several options for the user-libraries directory
if [ -d "/usr/local/lib64" ]; then
AFI_MGMT_LIBS_DST_DIR=/usr/local/lib64
elif [ -d "/usr/local/lib" ]; then
AFI_MGMT_LIBS_DST_DIR=/usr/local/lib
elif [ -d "/usr/lib64" ]; then
AFI_MGMT_LIBS_DST_DIR=/usr/lib64
elif [ -d "/usr/lib" ]; then
AFI_MGMT_LIBS_DST_DIR=/usr/lib
else
echo "Error: No directory for installing libraries."
exit 1
fi
if [ ! -d "$AFI_MGMT_TOOLS_DST_DIR" ]; then
mkdir -p $AFI_MGMT_TOOLS_DST_DIR
fi
# /usr/bin requires sudo permissions
echo "AWS FPGA: Copying Amazon FPGA Image (AFI) Management Tools to $AFI_MGMT_TOOLS_DST_DIR"
cp -f $AFI_MGMT_TOOLS_SRC_DIR/fpga-* $AFI_MGMT_TOOLS_DST_DIR
cp -f $AFI_MGMT_TOOLS_LIB_DIR/libfpga_mgmt.so.1.0.0 $AFI_MGMT_LIBS_DST_DIR
ln -sf libfpga_mgmt.so.1 $AFI_MGMT_LIBS_DST_DIR/libfpga_mgmt.so
ln -sf libfpga_mgmt.so.1.0.0 $AFI_MGMT_LIBS_DST_DIR/libfpga_mgmt.so.1
source /tmp/sdk_root_env.exp
if allow_non_root ; then
chmod u+s $AFI_MGMT_TOOLS_DST_DIR/fpga-local-cmd
fi
echo "AWS FPGA: Installing shared library to $AFI_MGMT_LIBS_DST_DIR"
ld_conf_change="0"
while true; do
# update the dynamic linker cache
ldconfig
# confirm that the linker cache stored the library we want
ldconfig -p | grep "libfpga_mgmt\.so\.1"
ret=$?
if [ $ret -ne "0" ]; then
if [ "$ld_conf_change" -eq "1" ]; then
echo "Error: Unable to automatically install the fpga_mgmt library."
exit 1
fi
ld_conf_change="1"
echo "$AFI_MGMT_LIBS_DST_DIR" > /etc/ld.so.conf.d/fpga_mgmt-x86_64.conf
else
break
fi
done
echo "AWS FPGA: Installing python bindings for FPGA management library"
cat>/tmp/mod_search_path<<EF
rm -f /tmp/py_install_paths
if [[ \$? -ne 0 ]] ; then
echo "Could not install python modules"
exit 1
fi
for i in 2 3 ; do
which python\$i >/dev/null 2>&1 || continue
python\$i -c "import sys
print(sys.path)
" | tr , '\n' | tr -d "'[]" | grep -E "64.*site-packages$" >> /tmp/py_install_paths
done
EF
bash /tmp/mod_search_path
while read -t 2 site_package ; do
PYMODULES="fpga_dma.py fpga_mgmt.py fpga_pci.py"
for mod in $PYMODULES ; do
sudo sed -e "s,PY_BIND_AFI_MGMT_LIBS_DST_DIR,$AFI_MGMT_LIBS_DST_DIR,g" $SDK_DIR/userspace/python_bindings/$mod > $site_package/$mod
if [[ $? -ne 0 ]] ; then
echo "Could not install $mod"
exit 1
fi
echo "Installed $site_package/$mod"
done
done < /tmp/py_install_paths
echo "AWS FPGA: Done with Amazon FPGA Image (AFI) Management Tools install."