This repository has been archived by the owner on Feb 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 222
/
build_tf_ubuntu.sh
118 lines (110 loc) · 3.8 KB
/
build_tf_ubuntu.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
function update_package_lists() {
printf "Updating package lists"
apt-get update -y 2> /dev/null > /dev/null
if [ $? -eq 0 ]; then
printf " => Done\n"
return 0
else
printf " => ERROR\n"
return 1
fi
}
to_upgrade=(`apt-get --just-print upgrade | awk '/^Inst/ { print $2 }'`)
STATUS_needs_upgrade="needs to be upgraded"
STATUS_up_to_date="up to date"
STATUS_installing="installing"
function package_status() {
package=$1
if `printf '%s\n' "${to_upgrade[@]}" | grep -x -q ${package}`; then
echo "${STATUS_needs_upgrade}"
elif `dpkg -l ${package} > /dev/null 2> /dev/null`; then
echo "${STATUS_up_to_date}"
else
echo "${STATUS_installing}"
fi
}
function backspace25() {
printf '\b%.0s' {1..25}
}
function install_or_update() {
packages="$@"
for package in ${packages[@]}; do
status=`package_status ${package}`
printf "> %-15s => %-25s" "${package}" "${status}"
if [ "${status}" != "${STATUS_up_to_date}" ]; then
apt-get install --upgrade -y ${package} 2> /dev/null > /dev/null
if [ $? -ne 0 ]; then
backspace25
printf '%-25s' "error"
else
backspace25
printf '%-25s' "${STATUS_up_to_date}"
fi
fi
printf '\n'
done
}
function latest_release_tag() {
repo=$1
curl -s https://api.github.com/repos/${repo}/releases/latest \
| grep -F "tag_name" \
| cut -d'"' -f4
}
function current_bazel_version() {
if `$HOME/bin/bazel version 2> /dev/null > /dev/null`; then
$HOME/bin/bazel version 2>&1 | grep label | cut -d' ' -f3
else
echo "not installed"
fi
}
bazel_prereqs=(pkg-config zip g++ zlib1g-dev unzip python)
function install_bazel_version() {
required_version=$1
current_version=`current_bazel_version`
echo "Current bazel version is: ${current_version}"
if [ "${required_version}" == "${current_version}" ]; then
echo "Bazel is already at the required version (${required_version})"
return 0
fi
installer_name="bazel-${required_version}-installer-linux-x86_64.sh"
installer_path="/tmp/${installer_name}"
if [ -e "${installer_path}" ]; then
echo "Found bazel installer at ${installer_path}"
else
echo "Downlading bazel ${required_version} installer"
dl_url="https://github.com/bazelbuild/bazel/releases/download/${required_version}/${installer_name}"
curl -L -o ${installer_path} ${dl_url}
fi
echo "Installing/upgrading dependencies for Bazel"
install_or_update "${bazel_prereqs[@]}"
chmod +x ${installer_path}
${installer_path} --user
}
packagelist=(
curl git
libc-ares-dev
python-dev python3-dev
python-pip python3-pip
)
update_package_lists
printf "Installing/upgrading system packages\n"
install_or_update "${packagelist[@]}"
install_bazel_version `latest_release_tag "bazelbuild/bazel"`
echo "Installing/upgrading required python packages"
for python in "python2" "python3"; do
${python} -m pip install -U --user pip six numpy wheel mock scipy h5py enum34
${python} -m pip install -U --user keras_applications==1.0.5 --no-deps
${python} -m pip install -U --user keras_preprocessing==1.0.3 --no-deps
done
tf_version=`latest_release_tag "tensorflow/tensorflow"`
echo Latest TF version is $tf_version
tf_dir="/tmp/tensorflow-${tf_version:1}"
tf_zip="${tf_dir}.zip"
curl -L -o ${tf_zip} "https://github.com/tensorflow/tensorflow/archive/${tf_version}.zip"
unzip ${tf_zip} -d /tmp
cd ${tf_dir}
for i in 1 2; do
PATH="$HOME/bin/:$PATH" ./configure
bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
done