2015-12-21 20:07:53 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
############################################################################
|
|
|
|
#
|
2016-12-28 21:49:46 +00:00
|
|
|
# Title: Build Environment Script for macOS
|
2015-12-21 20:07:53 +00:00
|
|
|
# Authors: CR Oldham, Shane Lee
|
|
|
|
# Date: December 2015
|
|
|
|
#
|
2017-07-19 23:30:47 +00:00
|
|
|
# Description: This script sets up a build environment for Salt on macOS.
|
2015-12-21 20:07:53 +00:00
|
|
|
#
|
|
|
|
# Requirements:
|
|
|
|
# - XCode Command Line Tools (xcode-select --install)
|
|
|
|
#
|
|
|
|
# Usage:
|
2017-07-19 23:30:47 +00:00
|
|
|
# This script can be passed 1 parameter
|
|
|
|
# $1 : <python version> : the version of Python to use for the
|
|
|
|
# build environment. Default is 2
|
2015-12-21 20:07:53 +00:00
|
|
|
#
|
|
|
|
# Example:
|
2017-07-19 23:30:47 +00:00
|
|
|
# The following will set up a Python 3 build environment for Salt
|
|
|
|
# on macOS
|
2015-12-21 20:07:53 +00:00
|
|
|
#
|
2017-07-19 23:30:47 +00:00
|
|
|
# ./dev_env.sh 3
|
2015-12-21 20:07:53 +00:00
|
|
|
#
|
|
|
|
############################################################################
|
|
|
|
|
2016-03-31 21:24:30 +00:00
|
|
|
############################################################################
|
|
|
|
# Set to Exit on all Errors
|
|
|
|
############################################################################
|
2015-12-21 20:07:53 +00:00
|
|
|
trap 'quit_on_error $LINENO $BASH_COMMAND' ERR
|
|
|
|
|
|
|
|
quit_on_error() {
|
|
|
|
echo "$(basename $0) caught error on line : $1 command was: $2"
|
|
|
|
exit -1
|
|
|
|
}
|
|
|
|
|
2017-07-19 23:30:47 +00:00
|
|
|
############################################################################
|
|
|
|
# Check passed parameters, set defaults
|
|
|
|
############################################################################
|
|
|
|
if [ "$1" == "" ]; then
|
|
|
|
PYVER=2
|
|
|
|
else
|
|
|
|
PYVER=$1
|
|
|
|
fi
|
|
|
|
|
2015-12-21 20:07:53 +00:00
|
|
|
############################################################################
|
|
|
|
# Parameters Required for the script to function properly
|
|
|
|
############################################################################
|
2016-03-31 21:24:30 +00:00
|
|
|
echo -n -e "\033]0;Build_Env: Variables\007"
|
2015-12-21 20:07:53 +00:00
|
|
|
|
|
|
|
# This is needed to allow the some test suites (zmq) to pass
|
|
|
|
ulimit -n 1200
|
|
|
|
|
|
|
|
SRCDIR=`git rev-parse --show-toplevel`
|
|
|
|
SCRIPTDIR=`pwd`
|
2015-12-22 20:08:23 +00:00
|
|
|
SHADIR=$SCRIPTDIR/shasums
|
2015-12-21 20:07:53 +00:00
|
|
|
PKG_CONFIG_PATH=/opt/salt/lib/pkgconfig
|
|
|
|
CFLAGS="-I/opt/salt/include"
|
|
|
|
LDFLAGS="-L/opt/salt/lib"
|
2017-07-19 23:30:47 +00:00
|
|
|
if [ "$PYVER" == "2" ]; then
|
|
|
|
PYDIR=/opt/salt/lib/python2.7
|
|
|
|
PYTHON=/opt/salt/bin/python
|
|
|
|
PIP=/opt/salt/bin/pip
|
|
|
|
else
|
|
|
|
PYDIR=/opt/salt/lib/python3.5
|
|
|
|
PYTHON=/opt/salt/bin/python3
|
|
|
|
PIP=/opt/salt/bin/pip3
|
|
|
|
fi
|
2015-12-21 20:07:53 +00:00
|
|
|
|
|
|
|
############################################################################
|
|
|
|
# Determine Which XCode is being used (XCode or XCode Command Line Tools)
|
|
|
|
############################################################################
|
|
|
|
# Prefer Xcode command line tools over any other gcc installed (e.g. MacPorts,
|
|
|
|
# Fink, Brew)
|
2016-03-31 21:24:30 +00:00
|
|
|
# Check for Xcode Command Line Tools first
|
2015-12-21 20:07:53 +00:00
|
|
|
if [ -d '/Library/Developer/CommandLineTools/usr/bin' ]; then
|
|
|
|
PATH=/Library/Developer/CommandLineTools/usr/bin:/opt/salt/bin:$PATH
|
|
|
|
MAKE=/Library/Developer/CommandLineTools/usr/bin/make
|
2016-03-31 21:24:30 +00:00
|
|
|
elif [ -d '/Applications/Xcode.app/Contents/Developer/usr/bin' ]; then
|
2015-12-21 20:07:53 +00:00
|
|
|
PATH=/Applications/Xcode.app/Contents/Developer/usr/bin:/opt/salt/bin:$PATH
|
|
|
|
MAKE=/Applications/Xcode.app/Contents/Developer/usr/bin/make
|
2016-03-31 21:24:30 +00:00
|
|
|
else
|
|
|
|
echo "No installation of XCode found. This script requires XCode."
|
|
|
|
exit -1
|
2015-12-21 20:07:53 +00:00
|
|
|
fi
|
|
|
|
export PATH
|
|
|
|
|
2015-12-22 20:08:23 +00:00
|
|
|
############################################################################
|
2016-03-31 21:24:30 +00:00
|
|
|
# Download Function
|
|
|
|
# - Downloads and verifies the MD5
|
2015-12-22 20:08:23 +00:00
|
|
|
############################################################################
|
|
|
|
download(){
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
echo "Must pass a URL to the download function"
|
|
|
|
fi
|
|
|
|
|
|
|
|
URL=$1
|
|
|
|
PKGNAME=${URL##*/}
|
|
|
|
|
|
|
|
cd $BUILDDIR
|
|
|
|
|
|
|
|
echo "################################################################################"
|
|
|
|
echo "Retrieving $PKGNAME"
|
|
|
|
echo "################################################################################"
|
2016-03-31 21:24:30 +00:00
|
|
|
curl -LO# $URL
|
2015-12-22 20:08:23 +00:00
|
|
|
|
|
|
|
echo "################################################################################"
|
|
|
|
echo "Comparing Sha512 Hash"
|
|
|
|
echo "################################################################################"
|
|
|
|
FILESHA=($(shasum -a 512 $PKGNAME))
|
|
|
|
EXPECTEDSHA=($(cat $SHADIR/$PKGNAME.sha512))
|
|
|
|
if [ "$FILESHA" != "$EXPECTEDSHA" ]; then
|
|
|
|
echo "ERROR: Sha Check Failed for $PKGNAME"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "################################################################################"
|
|
|
|
echo "Unpacking $PKGNAME"
|
|
|
|
echo "################################################################################"
|
|
|
|
tar -zxvf $PKGNAME
|
|
|
|
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
2015-12-21 20:07:53 +00:00
|
|
|
############################################################################
|
|
|
|
# Ensure Paths are present and clean
|
|
|
|
############################################################################
|
2016-03-31 21:24:30 +00:00
|
|
|
echo -n -e "\033]0;Build_Env: Clean\007"
|
|
|
|
|
2015-12-21 20:07:53 +00:00
|
|
|
# Make sure /opt/salt is clean
|
|
|
|
sudo rm -rf /opt/salt
|
|
|
|
sudo mkdir -p /opt/salt
|
|
|
|
sudo chown $USER:staff /opt/salt
|
|
|
|
|
|
|
|
# Make sure build staging is clean
|
|
|
|
rm -rf build
|
|
|
|
mkdir -p build
|
|
|
|
BUILDDIR=$SCRIPTDIR/build
|
|
|
|
|
|
|
|
############################################################################
|
|
|
|
# Download and install pkg-config
|
|
|
|
############################################################################
|
2016-03-31 21:24:30 +00:00
|
|
|
echo -n -e "\033]0;Build_Env: pkg-config\007"
|
2015-12-21 20:07:53 +00:00
|
|
|
|
2017-07-19 17:22:07 +00:00
|
|
|
PKGURL="http://pkgconfig.freedesktop.org/releases/pkg-config-0.29.2.tar.gz"
|
|
|
|
PKGDIR="pkg-config-0.29.2"
|
2015-12-21 20:07:53 +00:00
|
|
|
|
2015-12-22 20:08:23 +00:00
|
|
|
download $PKGURL
|
2015-12-21 20:07:53 +00:00
|
|
|
|
2015-12-22 20:08:23 +00:00
|
|
|
echo "################################################################################"
|
2015-12-21 20:07:53 +00:00
|
|
|
echo "Building pkg-config"
|
2015-12-22 20:08:23 +00:00
|
|
|
echo "################################################################################"
|
|
|
|
cd $PKGDIR
|
2015-12-21 20:07:53 +00:00
|
|
|
env LDFLAGS="-framework CoreFoundation -framework Carbon" ./configure --prefix=/opt/salt --with-internal-glib
|
|
|
|
$MAKE
|
|
|
|
$MAKE check
|
2016-03-31 21:24:30 +00:00
|
|
|
sudo -H $MAKE install
|
2015-12-21 20:07:53 +00:00
|
|
|
|
|
|
|
############################################################################
|
|
|
|
# Download and install libsodium
|
|
|
|
############################################################################
|
2016-03-31 21:24:30 +00:00
|
|
|
echo -n -e "\033]0;Build_Env: libsodium\007"
|
2015-12-21 20:07:53 +00:00
|
|
|
|
2018-08-23 16:15:28 +00:00
|
|
|
PKGURL="https://download.libsodium.org/libsodium/releases/old/libsodium-1.0.13.tar.gz"
|
2017-07-19 17:22:07 +00:00
|
|
|
PKGDIR="libsodium-1.0.13"
|
2015-12-21 20:07:53 +00:00
|
|
|
|
2015-12-22 20:08:23 +00:00
|
|
|
download $PKGURL
|
2015-12-21 20:07:53 +00:00
|
|
|
|
2015-12-22 20:08:23 +00:00
|
|
|
echo "################################################################################"
|
2015-12-21 20:07:53 +00:00
|
|
|
echo "Building libsodium"
|
2015-12-22 20:08:23 +00:00
|
|
|
echo "################################################################################"
|
|
|
|
cd $PKGDIR
|
2015-12-21 20:07:53 +00:00
|
|
|
./configure --prefix=/opt/salt
|
|
|
|
$MAKE
|
|
|
|
$MAKE check
|
2016-03-31 21:24:30 +00:00
|
|
|
sudo -H $MAKE install
|
2015-12-21 20:07:53 +00:00
|
|
|
|
|
|
|
############################################################################
|
|
|
|
# Download and install zeromq
|
|
|
|
############################################################################
|
2016-03-31 21:24:30 +00:00
|
|
|
echo -n -e "\033]0;Build_Env: zeromq\007"
|
2015-12-21 20:07:53 +00:00
|
|
|
|
2017-07-19 17:22:07 +00:00
|
|
|
PKGURL="http://download.zeromq.org/zeromq-4.1.4.tar.gz"
|
|
|
|
PKGDIR="zeromq-4.1.4"
|
2015-12-21 20:07:53 +00:00
|
|
|
|
2015-12-22 20:08:23 +00:00
|
|
|
download $PKGURL
|
2015-12-21 20:07:53 +00:00
|
|
|
|
2015-12-22 20:08:23 +00:00
|
|
|
echo "################################################################################"
|
2015-12-21 20:07:53 +00:00
|
|
|
echo "Building zeromq"
|
2015-12-22 20:08:23 +00:00
|
|
|
echo "################################################################################"
|
|
|
|
cd $PKGDIR
|
2015-12-21 20:07:53 +00:00
|
|
|
./configure --prefix=/opt/salt
|
|
|
|
$MAKE
|
|
|
|
$MAKE check
|
2016-03-31 21:24:30 +00:00
|
|
|
sudo -H $MAKE install
|
2015-12-21 20:07:53 +00:00
|
|
|
|
|
|
|
############################################################################
|
|
|
|
# Download and install OpenSSL
|
|
|
|
############################################################################
|
2016-03-31 21:24:30 +00:00
|
|
|
echo -n -e "\033]0;Build_Env: OpenSSL\007"
|
2015-12-21 20:07:53 +00:00
|
|
|
|
2018-09-06 15:37:24 +00:00
|
|
|
PKGURL="http://openssl.org/source/openssl-1.0.2p.tar.gz"
|
|
|
|
PKGDIR="openssl-1.0.2p"
|
2015-12-21 20:07:53 +00:00
|
|
|
|
2015-12-22 20:08:23 +00:00
|
|
|
download $PKGURL
|
2015-12-21 20:07:53 +00:00
|
|
|
|
2015-12-22 20:08:23 +00:00
|
|
|
echo "################################################################################"
|
2017-07-19 17:22:07 +00:00
|
|
|
echo "Building OpenSSL"
|
2015-12-22 20:08:23 +00:00
|
|
|
echo "################################################################################"
|
|
|
|
cd $PKGDIR
|
2015-12-21 20:07:53 +00:00
|
|
|
./Configure darwin64-x86_64-cc --prefix=/opt/salt --openssldir=/opt/salt/openssl
|
|
|
|
$MAKE
|
|
|
|
$MAKE test
|
2016-03-31 21:24:30 +00:00
|
|
|
sudo -H $MAKE install
|
2015-12-21 20:07:53 +00:00
|
|
|
|
|
|
|
############################################################################
|
|
|
|
# Download and install Python
|
|
|
|
############################################################################
|
2016-03-31 21:24:30 +00:00
|
|
|
echo -n -e "\033]0;Build_Env: Python\007"
|
2015-12-21 20:07:53 +00:00
|
|
|
|
2017-07-19 23:30:47 +00:00
|
|
|
if [ "$PYVER" == "2" ]; then
|
|
|
|
PKGURL="https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tar.xz"
|
|
|
|
PKGDIR="Python-2.7.13"
|
|
|
|
else
|
|
|
|
PKGURL="https://www.python.org/ftp/python/3.5.3/Python-3.5.3.tar.xz"
|
|
|
|
PKGDIR="Python-3.5.3"
|
|
|
|
fi
|
2015-12-21 20:07:53 +00:00
|
|
|
|
2015-12-22 20:08:23 +00:00
|
|
|
download $PKGURL
|
2015-12-21 20:07:53 +00:00
|
|
|
|
2015-12-22 20:08:23 +00:00
|
|
|
echo "################################################################################"
|
2017-07-19 17:22:07 +00:00
|
|
|
echo "Building Python"
|
2015-12-22 20:08:23 +00:00
|
|
|
echo "################################################################################"
|
2015-12-21 20:07:53 +00:00
|
|
|
echo "Note there are some test failures"
|
2015-12-22 20:08:23 +00:00
|
|
|
cd $PKGDIR
|
2015-12-21 20:07:53 +00:00
|
|
|
./configure --prefix=/opt/salt --enable-shared --enable-toolbox-glue --with-ensurepip=install
|
|
|
|
$MAKE
|
|
|
|
# $MAKE test
|
2016-02-03 19:16:47 +00:00
|
|
|
sudo -H $MAKE install
|
2015-12-21 20:07:53 +00:00
|
|
|
|
2016-02-03 20:21:44 +00:00
|
|
|
############################################################################
|
|
|
|
# upgrade pip
|
|
|
|
############################################################################
|
2018-09-06 15:59:46 +00:00
|
|
|
sudo -H $PIP install --upgrade pip
|
2016-02-03 20:21:44 +00:00
|
|
|
|
2015-12-21 20:07:53 +00:00
|
|
|
############################################################################
|
|
|
|
# Download and install salt python dependencies
|
|
|
|
############################################################################
|
2016-03-31 21:24:30 +00:00
|
|
|
echo -n -e "\033]0;Build_Env: PIP Dependencies\007"
|
2015-12-21 20:07:53 +00:00
|
|
|
|
|
|
|
cd $BUILDDIR
|
|
|
|
|
2015-12-22 20:08:23 +00:00
|
|
|
echo "################################################################################"
|
2015-12-21 20:07:53 +00:00
|
|
|
echo "Installing Salt Dependencies with pip (normal)"
|
2015-12-22 20:08:23 +00:00
|
|
|
echo "################################################################################"
|
2017-07-19 23:30:47 +00:00
|
|
|
sudo -H $PIP install \
|
|
|
|
-r $SRCDIR/pkg/osx/req.txt \
|
|
|
|
--no-cache-dir
|
2015-12-21 20:07:53 +00:00
|
|
|
|
2015-12-22 20:08:23 +00:00
|
|
|
echo "################################################################################"
|
2015-12-21 20:07:53 +00:00
|
|
|
echo "Installing Salt Dependencies with pip (build_ext)"
|
2015-12-22 20:08:23 +00:00
|
|
|
echo "################################################################################"
|
2017-07-19 23:30:47 +00:00
|
|
|
sudo -H $PIP install \
|
|
|
|
-r $SRCDIR/pkg/osx/req_ext.txt \
|
|
|
|
--global-option=build_ext \
|
|
|
|
--global-option="-I/opt/salt/include" \
|
|
|
|
--no-cache-dir
|
2015-12-21 20:07:53 +00:00
|
|
|
|
2015-12-22 20:08:23 +00:00
|
|
|
echo "--------------------------------------------------------------------------------"
|
2015-12-21 20:07:53 +00:00
|
|
|
echo "Create Symlink to certifi for openssl"
|
2015-12-22 20:08:23 +00:00
|
|
|
echo "--------------------------------------------------------------------------------"
|
2017-07-19 23:30:47 +00:00
|
|
|
sudo ln -s $PYDIR/site-packages/certifi/cacert.pem /opt/salt/openssl/cert.pem
|
2015-12-21 20:07:53 +00:00
|
|
|
|
2016-03-31 21:24:30 +00:00
|
|
|
echo -n -e "\033]0;Build_Env: Finished\007"
|
2015-12-21 20:07:53 +00:00
|
|
|
|
|
|
|
cd $BUILDDIR
|
|
|
|
|
2015-12-22 20:08:23 +00:00
|
|
|
echo "################################################################################"
|
2015-12-21 20:07:53 +00:00
|
|
|
echo "Build Environment Script Completed"
|
2015-12-22 20:08:23 +00:00
|
|
|
echo "################################################################################"
|