├── README.md └── build_tf_ubuntu.sh /README.md: -------------------------------------------------------------------------------- 1 | This repository has moved to https://github.com/lakshayg/tensorflow-build 2 | -------------------------------------------------------------------------------- /build_tf_ubuntu.sh: -------------------------------------------------------------------------------- 1 | function update_package_lists() { 2 | printf "Updating package lists" 3 | apt-get update -y 2> /dev/null > /dev/null 4 | if [ $? -eq 0 ]; then 5 | printf " => Done\n" 6 | return 0 7 | else 8 | printf " => ERROR\n" 9 | return 1 10 | fi 11 | } 12 | 13 | to_upgrade=(`apt-get --just-print upgrade | awk '/^Inst/ { print $2 }'`) 14 | STATUS_needs_upgrade="needs to be upgraded" 15 | STATUS_up_to_date="up to date" 16 | STATUS_installing="installing" 17 | function package_status() { 18 | package=$1 19 | if `printf '%s\n' "${to_upgrade[@]}" | grep -x -q ${package}`; then 20 | echo "${STATUS_needs_upgrade}" 21 | elif `dpkg -l ${package} > /dev/null 2> /dev/null`; then 22 | echo "${STATUS_up_to_date}" 23 | else 24 | echo "${STATUS_installing}" 25 | fi 26 | } 27 | 28 | function backspace25() { 29 | printf '\b%.0s' {1..25} 30 | } 31 | 32 | function install_or_update() { 33 | packages="$@" 34 | for package in ${packages[@]}; do 35 | status=`package_status ${package}` 36 | printf "> %-15s => %-25s" "${package}" "${status}" 37 | if [ "${status}" != "${STATUS_up_to_date}" ]; then 38 | apt-get install --upgrade -y ${package} 2> /dev/null > /dev/null 39 | if [ $? -ne 0 ]; then 40 | backspace25 41 | printf '%-25s' "error" 42 | else 43 | backspace25 44 | printf '%-25s' "${STATUS_up_to_date}" 45 | fi 46 | fi 47 | printf '\n' 48 | done 49 | } 50 | 51 | function latest_release_tag() { 52 | repo=$1 53 | curl -s https://api.github.com/repos/${repo}/releases/latest \ 54 | | grep -F "tag_name" \ 55 | | cut -d'"' -f4 56 | } 57 | 58 | function current_bazel_version() { 59 | if `$HOME/bin/bazel version 2> /dev/null > /dev/null`; then 60 | $HOME/bin/bazel version 2>&1 | grep label | cut -d' ' -f3 61 | else 62 | echo "not installed" 63 | fi 64 | } 65 | 66 | bazel_prereqs=(pkg-config zip g++ zlib1g-dev unzip python) 67 | function install_bazel_version() { 68 | required_version=$1 69 | current_version=`current_bazel_version` 70 | echo "Current bazel version is: ${current_version}" 71 | if [ "${required_version}" == "${current_version}" ]; then 72 | echo "Bazel is already at the required version (${required_version})" 73 | return 0 74 | fi 75 | installer_name="bazel-${required_version}-installer-linux-x86_64.sh" 76 | installer_path="/tmp/${installer_name}" 77 | if [ -e "${installer_path}" ]; then 78 | echo "Found bazel installer at ${installer_path}" 79 | else 80 | echo "Downlading bazel ${required_version} installer" 81 | dl_url="https://github.com/bazelbuild/bazel/releases/download/${required_version}/${installer_name}" 82 | curl -L -o ${installer_path} ${dl_url} 83 | fi 84 | echo "Installing/upgrading dependencies for Bazel" 85 | install_or_update "${bazel_prereqs[@]}" 86 | chmod +x ${installer_path} 87 | ${installer_path} --user 88 | } 89 | 90 | packagelist=( 91 | curl git 92 | libc-ares-dev 93 | python-dev python3-dev 94 | python-pip python3-pip 95 | ) 96 | 97 | update_package_lists 98 | printf "Installing/upgrading system packages\n" 99 | install_or_update "${packagelist[@]}" 100 | install_bazel_version `latest_release_tag "bazelbuild/bazel"` 101 | echo "Installing/upgrading required python packages" 102 | for python in "python2" "python3"; do 103 | ${python} -m pip install -U --user pip six numpy wheel mock scipy h5py enum34 104 | ${python} -m pip install -U --user keras_applications==1.0.5 --no-deps 105 | ${python} -m pip install -U --user keras_preprocessing==1.0.3 --no-deps 106 | done 107 | tf_version=`latest_release_tag "tensorflow/tensorflow"` 108 | echo Latest TF version is $tf_version 109 | tf_dir="/tmp/tensorflow-${tf_version:1}" 110 | tf_zip="${tf_dir}.zip" 111 | curl -L -o ${tf_zip} "https://github.com/tensorflow/tensorflow/archive/${tf_version}.zip" 112 | unzip ${tf_zip} -d /tmp 113 | cd ${tf_dir} 114 | for i in 1 2; do 115 | PATH="$HOME/bin/:$PATH" ./configure 116 | bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package 117 | ./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg 118 | done 119 | --------------------------------------------------------------------------------