salt/pkg/osx/build_pkg.sh

199 lines
6.9 KiB
Bash
Raw Normal View History

2015-12-21 20:07:53 +00:00
#!/bin/bash
############################################################################
#
# Title: Build Package Script for macOS
2015-12-21 20:07:53 +00:00
# Authors: CR Oldham, Shane Lee
# Date: December 2015
#
# Description: This creates an macOS package for Salt from the contents of
2015-12-21 20:07:53 +00:00
# /opt/salt
#
# Requirements:
# - XCode Command Line Tools (xcode-select --install)
#
# Usage:
# This script can be passed 2 parameters
# $1 : <version> : the version name to give the package (overrides
2015-12-21 20:07:53 +00:00
# version of the git repo) (Defaults to the git repo version)
2017-07-19 23:30:47 +00:00
# $2 : <python ver> : the version of python that was built (defaults
# to 2)
# $3 : <package dir> : the staging area for the package defaults to
# /tmp/salt_pkg
2015-12-21 20:07:53 +00:00
#
# Example:
2017-07-19 23:30:47 +00:00
# The following will build Salt version 2017.7.0 with Python 3 and
# stage all files in /tmp/salt_pkg:
2015-12-21 20:07:53 +00:00
#
2017-07-19 23:30:47 +00:00
# ./build.sh 2017.7.0 3
2015-12-21 20:07:53 +00:00
#
############################################################################
############################################################################
# Make sure the script is launched with sudo
############################################################################
if [[ $(id -u) -ne 0 ]]
then
exec sudo /bin/bash -c "$(printf '%q ' "$BASH_SOURCE" "$@")"
fi
############################################################################
# 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
}
############################################################################
# Check passed parameters, set defaults
############################################################################
# Get/Set Version
2015-12-21 20:07:53 +00:00
if [ "$1" == "" ]; then
VERSION=`git describe`
2015-12-21 20:07:53 +00:00
else
VERSION=$1
2015-12-21 20:07:53 +00:00
fi
2017-07-19 23:30:47 +00:00
# Get/Set Python Version
2015-12-21 20:07:53 +00:00
if [ "$2" == "" ]; then
2017-07-19 23:30:47 +00:00
PYVER=2
else
PYVER=$2
fi
# Get/Set temp directory
if [ "$3" == "" ]; then
PKGDIR=/tmp/salt_pkg
2015-12-21 20:07:53 +00:00
else
2017-07-19 23:30:47 +00:00
PKGDIR=$3
2015-12-21 20:07:53 +00:00
fi
2016-05-25 20:11:12 +00:00
CPUARCH=`uname -m`
2015-12-21 20:07:53 +00:00
############################################################################
# Additional Parameters Required for the script to function properly
############################################################################
echo -n -e "\033]0;Build_Pkg: Variables\007"
SRCDIR=`git rev-parse --show-toplevel`
PKGRESOURCES=$SRCDIR/pkg/osx
2015-12-21 20:07:53 +00:00
############################################################################
# Make sure this is the Salt Repository
############################################################################
if [[ ! -e "$SRCDIR/.git" ]] && [[ ! -e "$SRCDIR/scripts/salt" ]]; then
echo "This directory doesn't appear to be a git repository."
echo "The macOS build process needs some files from a Git checkout of Salt."
echo "Run this script from the 'pkg/osx' directory of the Git checkout."
2015-12-21 20:07:53 +00:00
exit -1
fi
############################################################################
# Ensure Paths are present and clean
############################################################################
echo -n -e "\033]0;Build_Pkg: Clean Staging Area\007"
# Clean folder in the staging area
rm -rdf $PKGDIR
2015-12-21 20:07:53 +00:00
mkdir -p $PKGDIR
############################################################################
# Copy Start Scripts from Salt Repo to /opt/salt
############################################################################
echo -n -e "\033]0;Build_Pkg: Copy Start Scripts\007"
cp $PKGRESOURCES/scripts/start-*.sh /opt/salt/bin/
cp $PKGRESOURCES/scripts/salt-config.sh /opt/salt/bin
2015-12-21 20:07:53 +00:00
############################################################################
# Copy Service Definitions from Salt Repo to the Package Directory
############################################################################
echo -n -e "\033]0;Build_Pkg: Copy Service Definitions\007"
mkdir -p $PKGDIR/opt
cp -r /opt/salt $PKGDIR/opt
mkdir -p $PKGDIR/Library/LaunchDaemons $PKGDIR/etc
cp $PKGRESOURCES/scripts/com.saltstack.salt.minion.plist $PKGDIR/Library/LaunchDaemons
cp $PKGRESOURCES/scripts/com.saltstack.salt.master.plist $PKGDIR/Library/LaunchDaemons
cp $PKGRESOURCES/scripts/com.saltstack.salt.syndic.plist $PKGDIR/Library/LaunchDaemons
cp $PKGRESOURCES/scripts/com.saltstack.salt.api.plist $PKGDIR/Library/LaunchDaemons
############################################################################
# Remove unnecessary files from the package
############################################################################
echo -n -e "\033]0;Build_Pkg: Trim unneeded files\007"
rm -rdf $PKGDIR/opt/salt/bin/pkg-config
rm -rdf $PKGDIR/opt/salt/lib/pkgconfig
rm -rdf $PKGDIR/opt/salt/lib/engines
rm -rdf $PKGDIR/opt/salt/share/aclocal
rm -rdf $PKGDIR/opt/salt/share/doc
rm -rdf $PKGDIR/opt/salt/share/man/man1/pkg-config.1
2017-07-19 23:30:47 +00:00
if [ "$PYVER" == "2" ]; then
rm -rdf $PKGDIR/opt/salt/lib/python2.7/test
2017-07-19 23:30:47 +00:00
else
rm -rdf $PKGDIR/opt/salt/lib/python3.5/test
2017-07-19 23:30:47 +00:00
fi
echo -n -e "\033]0;Build_Pkg: Remove compiled python files\007"
find $PKGDIR/opt/salt -name '*.pyc' -type f -delete
2015-12-21 20:07:53 +00:00
############################################################################
# Copy Config Files from Salt Repo to the Package Directory
############################################################################
echo -n -e "\033]0;Build_Pkg: Copy Config Files\007"
mkdir -p $PKGDIR/etc/salt
cp $SRCDIR/conf/minion $PKGDIR/etc/salt/minion.dist
cp $SRCDIR/conf/master $PKGDIR/etc/salt/master.dist
############################################################################
2016-05-25 20:11:12 +00:00
# Add Version and CPU Arch to distribution.xml
2015-12-21 20:07:53 +00:00
############################################################################
echo -n -e "\033]0;Build_Pkg: Add Version to .xml\007"
2017-07-19 23:30:47 +00:00
if [ "$PYVER" == "2" ]; then
TITLE="Salt $VERSION"
DESC="Salt $VERSION with Python 2"
else
TITLE="Salt $VERSION (Python 3)"
DESC="Salt $VERSION with Python 3"
fi
2015-12-21 20:07:53 +00:00
cd $PKGRESOURCES
cp distribution.xml.dist distribution.xml
2017-07-19 23:30:47 +00:00
SEDSTR="s/@TITLE@/$TITLE/g"
sed -E -i '' "$SEDSTR" distribution.xml
SEDSTR="s/@DESC@/$DESC/g"
sed -E -i '' "$SEDSTR" distribution.xml
SEDSTR="s/@VERSION@/$VERSION/g"
sed -E -i '' "$SEDSTR" distribution.xml
SEDSTR="s/@PYVER@/$PYVER/g"
sed -E -i '' "$SEDSTR" distribution.xml
2015-12-21 20:07:53 +00:00
2017-07-19 23:30:47 +00:00
SEDSTR="s/@CPUARCH@/$CPUARCH/g"
sed -i '' "$SEDSTR" distribution.xml
2016-05-25 20:11:12 +00:00
2015-12-21 20:07:53 +00:00
############################################################################
# Build the Package
############################################################################
echo -n -e "\033]0;Build_Pkg: Build Package\007"
pkgbuild --root=$PKGDIR \
--scripts=pkg-scripts \
2015-12-21 20:07:53 +00:00
--identifier=com.saltstack.salt \
--version=$VERSION \
2017-07-19 23:30:47 +00:00
--ownership=recommended salt-src-$VERSION-py$PYVER-$CPUARCH.pkg
2015-12-21 20:07:53 +00:00
productbuild --resources=pkg-resources \
2015-12-21 20:07:53 +00:00
--distribution=distribution.xml \
2017-07-19 23:30:47 +00:00
--package-path=salt-src-$VERSION-py$PYVER-$CPUARCH.pkg \
--version=$VERSION salt-$VERSION-py$PYVER-$CPUARCH.pkg
2015-12-21 20:07:53 +00:00