2016-06-02 07:56:56 -05:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Build script to create Mac App Bundle and DMG for pgAdmin4 runtime
|
|
|
|
|
|
|
|
export WD=$(cd `dirname $0` && pwd)
|
2019-03-21 09:02:19 -05:00
|
|
|
export SOURCEDIR=${WD}/../..
|
|
|
|
export BUILDROOT=${WD}/../../mac-build
|
|
|
|
export DISTROOT=${WD}/../../dist
|
2016-06-02 07:56:56 -05:00
|
|
|
export VIRTUALENV=venv
|
|
|
|
|
2019-03-21 09:02:19 -05:00
|
|
|
if [ ! -f ${SOURCEDIR}/pkg/mac/framework.conf ]; then
|
2017-02-16 05:25:32 -06:00
|
|
|
echo
|
|
|
|
echo "Error: pkg/mac/framework.conf not found!"
|
|
|
|
echo "Copy pkg/mac/framework.conf.in to pkg/mac/framework.conf and edit as required for the current system."
|
|
|
|
echo
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-03-21 09:02:19 -05:00
|
|
|
if [ "x${PYTHON_HOME}" == "x" ]; then
|
2020-05-04 08:56:28 -05:00
|
|
|
echo "PYTHON_HOME not set. It must be set, and pointing to a Python 3 installation."
|
|
|
|
exit 1
|
2016-06-02 07:56:56 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Check if Python is working and calculate PYTHON_VERSION
|
2020-05-04 08:56:28 -05:00
|
|
|
if ${PYTHON_HOME}/bin/python3 -V > /dev/null 2>&1; then
|
2019-03-21 09:02:19 -05:00
|
|
|
export PYTHON_VERSION=`${PYTHON_HOME}/bin/python3 -V 2>&1 | awk '{print $2}' | cut -d"." -f1-2 | sed 's/\.//'`
|
2016-06-02 07:56:56 -05:00
|
|
|
else
|
|
|
|
echo "Error: Python installation missing!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-05-04 08:56:28 -05:00
|
|
|
if [ "${PYTHON_VERSION}" -gt "38" -a "${PYTHON_VERSION}" -lt "34" ]; then
|
|
|
|
echo "Python version not supported."
|
2016-06-02 07:56:56 -05:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-05-04 08:56:28 -05:00
|
|
|
export PYTHON=${PYTHON_HOME}/bin/python3
|
|
|
|
export PIP=pip3
|
2016-06-02 07:56:56 -05:00
|
|
|
|
2019-03-21 09:02:19 -05:00
|
|
|
if [ "x${QTDIR}" == "x" ]; then
|
2020-05-04 08:56:28 -05:00
|
|
|
echo "QTDIR not set. Setting it to default."
|
2017-02-16 05:25:32 -06:00
|
|
|
export QTDIR=~/Qt/5.8/clang_64
|
2016-06-02 07:56:56 -05:00
|
|
|
fi
|
2019-03-21 09:02:19 -05:00
|
|
|
export QMAKE=${QTDIR}/bin/qmake
|
|
|
|
if ! ${QMAKE} --version > /dev/null 2>&1; then
|
2016-06-02 07:56:56 -05:00
|
|
|
echo "Error: qmake not found. QT installation is not present or incomplete."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-03-21 09:02:19 -05:00
|
|
|
if [ "x${PGDIR}" == "x" ]; then
|
2020-05-04 08:56:28 -05:00
|
|
|
echo "PGDIR not set. Setting it to default."
|
2016-06-02 07:56:56 -05:00
|
|
|
export PGDIR=/usr/local/pgsql
|
|
|
|
fi
|
|
|
|
|
|
|
|
_get_version() {
|
|
|
|
export APP_RELEASE=`grep "^APP_RELEASE" web/config.py | cut -d"=" -f2 | sed 's/ //g'`
|
|
|
|
export APP_REVISION=`grep "^APP_REVISION" web/config.py | cut -d"=" -f2 | sed 's/ //g'`
|
|
|
|
export APP_NAME=`grep "^APP_NAME" web/config.py | cut -d"=" -f2 | sed "s/'//g" | sed 's/^ //'`
|
2019-03-21 09:02:19 -05:00
|
|
|
export APP_BUNDLE_NAME=${APP_NAME}.app
|
|
|
|
export APP_LONG_VERSION=${APP_RELEASE}.${APP_REVISION}
|
|
|
|
export APP_SHORT_VERSION=`echo ${APP_LONG_VERSION} | cut -d . -f1,2`
|
2016-06-02 07:56:56 -05:00
|
|
|
export APP_SUFFIX=`grep "^APP_SUFFIX" web/config.py | cut -d"=" -f2 | sed 's/ //g' | sed "s/'//g"`
|
2019-03-21 09:02:19 -05:00
|
|
|
if [ ! -z ${APP_SUFFIX} ]; then
|
|
|
|
export APP_LONG_VERSION=${APP_LONG_VERSION}-${APP_SUFFIX}
|
2016-06-02 07:56:56 -05:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
_cleanup() {
|
|
|
|
echo "Cleaning up the old environment and app bundle"
|
2019-03-21 09:02:19 -05:00
|
|
|
rm -rf ${SOURCEDIR}/runtime/pgAdmin4.app
|
|
|
|
rm -rf ${BUILDROOT}
|
|
|
|
rm -f ${DISTROOT}/pgadmin4*.dmg
|
2016-06-02 07:56:56 -05:00
|
|
|
}
|
|
|
|
|
2020-05-04 04:20:51 -05:00
|
|
|
_create_venv() {
|
2019-03-21 09:02:19 -05:00
|
|
|
export PATH=${PGDIR}/bin:${PATH}
|
|
|
|
export LD_LIBRARY_PATH=${PGDIR}/lib:${LD_LIBRARY_PATH}
|
|
|
|
test -d ${BUILDROOT} || mkdir ${BUILDROOT} || exit 1
|
|
|
|
cd ${BUILDROOT}
|
2018-06-14 10:16:30 -05:00
|
|
|
|
2020-05-04 08:56:28 -05:00
|
|
|
test -d ${VIRTUALENV} || virtualenv -p ${PYTHON} --always-copy ${VIRTUALENV} || exit 1
|
2018-06-14 10:16:30 -05:00
|
|
|
|
2019-03-21 09:02:19 -05:00
|
|
|
source ${VIRTUALENV}/bin/activate
|
|
|
|
${PIP} install --no-cache-dir --no-binary psycopg2 -r ${SOURCEDIR}/requirements.txt || { echo PIP install failed. Please resolve the issue and rerun the script; exit 1; }
|
2016-06-02 07:56:56 -05:00
|
|
|
|
2016-09-02 09:19:54 -05:00
|
|
|
# Figure out some paths for use when completing the venv
|
|
|
|
# Use "python" here as we want the venv path
|
2016-06-02 07:56:56 -05:00
|
|
|
export PYMODULES_PATH=`python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"`
|
2019-03-21 09:02:19 -05:00
|
|
|
export DIR_PYMODULES_PATH=`dirname ${PYMODULES_PATH}`
|
2016-09-02 09:19:54 -05:00
|
|
|
|
|
|
|
# Use $PYTHON here as we want the system path
|
2019-03-21 09:02:19 -05:00
|
|
|
export PYSYSLIB_PATH=`${PYTHON} -c "import sys; print('%s/lib/python%d.%.d' % (sys.prefix, sys.version_info.major, sys.version_info.minor))"`
|
2016-09-02 09:19:54 -05:00
|
|
|
|
|
|
|
# Symlink in the rest of the Python libs. This is required because the runtime
|
|
|
|
# will clear PYTHONHOME for safety, which has the side-effect of preventing
|
2018-05-02 06:05:17 -05:00
|
|
|
# it from finding modules that are not explicitly included in the venv
|
2019-03-21 09:02:19 -05:00
|
|
|
cd ${DIR_PYMODULES_PATH}
|
2018-06-14 10:16:30 -05:00
|
|
|
|
2016-09-02 09:19:54 -05:00
|
|
|
# Files
|
2019-03-21 09:02:19 -05:00
|
|
|
for FULLPATH in ${PYSYSLIB_PATH}/*.py; do
|
2016-09-02 09:19:54 -05:00
|
|
|
FILE=${FULLPATH##*/}
|
2019-03-21 09:02:19 -05:00
|
|
|
if [ ! -e ${FILE} ]; then
|
2020-05-04 08:56:28 -05:00
|
|
|
cp ${FULLPATH} ${FILE}
|
2016-09-02 09:19:54 -05:00
|
|
|
fi
|
|
|
|
done
|
2018-06-14 10:16:30 -05:00
|
|
|
|
2016-09-02 09:19:54 -05:00
|
|
|
# Paths
|
2019-03-21 09:02:19 -05:00
|
|
|
for FULLPATH in ${PYSYSLIB_PATH}/*/; do
|
2016-09-02 09:19:54 -05:00
|
|
|
FULLPATH=${FULLPATH%*/}
|
|
|
|
FILE=${FULLPATH##*/}
|
2019-03-21 09:02:19 -05:00
|
|
|
if [ ! -e ${FILE} ]; then
|
2020-05-04 08:56:28 -05:00
|
|
|
cp -R ${FULLPATH} ${FILE}
|
2016-09-02 09:19:54 -05:00
|
|
|
fi
|
|
|
|
done
|
2017-03-17 07:21:15 -05:00
|
|
|
|
|
|
|
# Remove tests
|
|
|
|
cd site-packages
|
2020-04-24 09:07:50 -05:00
|
|
|
find . -name "test" -type d -print0 | xargs -0 rm -rf
|
|
|
|
find . -name "tests" -type d -print0 | xargs -0 rm -rf
|
2017-03-17 07:21:15 -05:00
|
|
|
|
2018-06-14 10:16:30 -05:00
|
|
|
# Link the python<version> directory to python so that the private environment path is found by the application.
|
2019-03-21 09:02:19 -05:00
|
|
|
if test -d ${DIR_PYMODULES_PATH}; then
|
|
|
|
ln -s $(basename ${DIR_PYMODULES_PATH}) ${DIR_PYMODULES_PATH}/../python
|
2016-06-02 07:56:56 -05:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
_build_runtime() {
|
2019-03-21 09:02:19 -05:00
|
|
|
cd ${SOURCEDIR}/runtime
|
2017-04-05 06:35:07 -05:00
|
|
|
make clean
|
2020-05-04 04:20:51 -05:00
|
|
|
PGADMIN_PYTHON_DIR=${PYTHON_HOME} ${QMAKE} || { echo qmake failed; exit 1; }
|
2016-06-02 07:56:56 -05:00
|
|
|
make || { echo make failed; exit 1; }
|
2019-03-21 09:02:19 -05:00
|
|
|
cp -r pgAdmin4.app "${BUILDROOT}/${APP_BUNDLE_NAME}"
|
2016-06-02 07:56:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
_build_doc() {
|
2019-03-21 09:02:19 -05:00
|
|
|
cd ${SOURCEDIR}/docs/en_US
|
|
|
|
test -d "${BUILDROOT}/${APP_BUNDLE_NAME}/Contents/Resources" || "mkdir -p ${BUILDROOT}/${APP_BUNDLE_NAME}/Contents/Resources"
|
|
|
|
test -d "${BUILDROOT}/${APP_BUNDLE_NAME}/Contents/Resources/docs/en_US" || mkdir -p "${BUILDROOT}/${APP_BUNDLE_NAME}/Contents/Resources/docs/en_US"
|
|
|
|
cp -r _build/html "${BUILDROOT}/${APP_BUNDLE_NAME}/Contents/Resources/docs/en_US/" || exit 1
|
2016-06-02 07:56:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
_complete_bundle() {
|
2019-03-21 09:02:19 -05:00
|
|
|
cd ${SOURCEDIR}/pkg/mac
|
2016-11-23 04:03:40 -06:00
|
|
|
|
|
|
|
# Copy the binary utilities into place
|
2019-03-26 09:09:30 -05:00
|
|
|
mkdir -p "${BUILDROOT}/${APP_BUNDLE_NAME}/Contents/SharedSupport/" || exit 1
|
2019-03-21 09:02:19 -05:00
|
|
|
cp "${PGDIR}/bin/pg_dump" "${BUILDROOT}/${APP_BUNDLE_NAME}/Contents/SharedSupport/" || exit 1
|
|
|
|
cp "${PGDIR}/bin/pg_dumpall" "${BUILDROOT}/${APP_BUNDLE_NAME}/Contents/SharedSupport/" || exit 1
|
|
|
|
cp "${PGDIR}/bin/pg_restore" "${BUILDROOT}/${APP_BUNDLE_NAME}/Contents/SharedSupport/" || exit 1
|
|
|
|
cp "${PGDIR}/bin/psql" "${BUILDROOT}/${APP_BUNDLE_NAME}/Contents/SharedSupport/" || exit 1
|
2016-06-02 07:56:56 -05:00
|
|
|
|
|
|
|
# Replace the place holders with the current version
|
2019-03-21 09:02:19 -05:00
|
|
|
sed -e "s/PGADMIN_LONG_VERSION/${APP_LONG_VERSION}/g" -e "s/PGADMIN_SHORT_VERSION/${APP_SHORT_VERSION}/g" pgadmin.Info.plist.in > pgadmin.Info.plist
|
2016-06-02 07:56:56 -05:00
|
|
|
|
|
|
|
# copy Python private environment to app bundle
|
2019-03-21 09:02:19 -05:00
|
|
|
cp -PR ${BUILDROOT}/${VIRTUALENV} "${BUILDROOT}/${APP_BUNDLE_NAME}/Contents/Resources/" || exit 1
|
2016-06-02 07:56:56 -05:00
|
|
|
|
2018-06-14 10:16:30 -05:00
|
|
|
# Remove any TCL-related files that may cause us problems
|
2020-04-24 09:07:50 -05:00
|
|
|
find "${BUILDROOT}/${APP_BUNDLE_NAME}/Contents/Resources/${VIRTUALENV}/" -name "_tkinter*" -print0 | xargs -0 rm -f
|
2016-06-02 07:56:56 -05:00
|
|
|
|
|
|
|
# run complete-bundle to copy the dependent libraries and frameworks and fix the rpaths
|
2019-03-21 09:02:19 -05:00
|
|
|
./complete-bundle.sh "${BUILDROOT}/${APP_BUNDLE_NAME}" || { echo complete-bundle.sh failed; exit 1; }
|
2016-06-02 07:56:56 -05:00
|
|
|
|
2019-03-21 09:02:19 -05:00
|
|
|
pushd ${SOURCEDIR}/web
|
2019-03-15 04:20:13 -05:00
|
|
|
yarn install || exit 1
|
|
|
|
yarn run bundle || exit 1
|
2018-07-23 10:15:58 -05:00
|
|
|
|
|
|
|
curl https://curl.haxx.se/ca/cacert.pem -o cacert.pem -s || { echo Failed to download cacert.pem; exit 1; }
|
2017-06-12 10:51:54 -05:00
|
|
|
popd
|
|
|
|
|
2016-06-02 07:56:56 -05:00
|
|
|
# copy the web directory to the bundle as it is required by runtime
|
2019-03-21 09:02:19 -05:00
|
|
|
cp -r ${SOURCEDIR}/web "${BUILDROOT}/${APP_BUNDLE_NAME}/Contents/Resources/" || exit 1
|
|
|
|
cd "${BUILDROOT}/${APP_BUNDLE_NAME}/Contents/Resources/web"
|
2016-06-02 07:56:56 -05:00
|
|
|
rm -f pgadmin4.db config_local.*
|
2018-02-05 09:32:14 -06:00
|
|
|
rm -rf karma.conf.js package.json node_modules/ regression/ tools/ pgadmin/static/js/generated/.cache
|
2020-04-24 09:07:50 -05:00
|
|
|
find . -name "tests" -type d -print0 | xargs -0 rm -rf
|
|
|
|
find . -name "feature_tests" -type d -print0 | xargs -0 rm -rf
|
|
|
|
find . -name ".DS_Store" -print0 | xargs -0 rm -f
|
2017-03-15 12:14:37 -05:00
|
|
|
|
2016-10-19 08:10:28 -05:00
|
|
|
echo "SERVER_MODE = False" > config_distro.py
|
|
|
|
echo "HELP_PATH = '../../../docs/en_US/html/'" >> config_distro.py
|
2016-11-23 07:38:17 -06:00
|
|
|
echo "DEFAULT_BINARY_PATHS = {" >> config_distro.py
|
2016-11-23 07:43:12 -06:00
|
|
|
echo " 'pg': '\$DIR/../../SharedSupport'," >> config_distro.py
|
2016-11-23 07:38:17 -06:00
|
|
|
echo " 'ppas': ''" >> config_distro.py
|
|
|
|
echo "}" >> config_distro.py
|
2016-06-02 07:56:56 -05:00
|
|
|
|
|
|
|
# Remove the .pyc files if any
|
2019-03-21 09:02:19 -05:00
|
|
|
cd "${BUILDROOT}/${APP_BUNDLE_NAME}"
|
2020-04-24 09:07:50 -05:00
|
|
|
find . -name *.pyc -print0 | xargs -0 rm -f
|
2016-06-02 07:56:56 -05:00
|
|
|
}
|
|
|
|
|
2017-02-16 05:25:32 -06:00
|
|
|
_framework_config() {
|
2019-03-21 09:02:19 -05:00
|
|
|
cd ${SOURCEDIR}/pkg/mac
|
|
|
|
./framework-config.sh "${BUILDROOT}/${APP_BUNDLE_NAME}" || { echo "framework-config.sh failed"; exit 1; }
|
2017-02-16 05:25:32 -06:00
|
|
|
}
|
|
|
|
|
2020-01-03 03:56:45 -06:00
|
|
|
_codesign_binaries() {
|
|
|
|
cd ${SOURCEDIR}/pkg/mac
|
|
|
|
|
|
|
|
if [ ! -f codesign.conf ]; then
|
|
|
|
echo
|
|
|
|
echo "******************************************************************"
|
|
|
|
echo "* codesign.conf not found. NOT signing the binaries."
|
|
|
|
echo "******************************************************************"
|
|
|
|
echo
|
|
|
|
sleep 5
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
./codesign-binaries.sh "${BUILDROOT}/${APP_BUNDLE_NAME}" || { echo codesign-binaries.sh failed; exit 1; }
|
|
|
|
}
|
|
|
|
|
2016-10-04 06:50:16 -05:00
|
|
|
_codesign_bundle() {
|
2019-03-21 09:02:19 -05:00
|
|
|
cd ${SOURCEDIR}/pkg/mac
|
2017-02-16 05:25:32 -06:00
|
|
|
|
2016-10-04 06:50:16 -05:00
|
|
|
if [ ! -f codesign.conf ]; then
|
|
|
|
echo
|
|
|
|
echo "******************************************************************"
|
|
|
|
echo "* codesign.conf not found. NOT signing the bundle."
|
|
|
|
echo "******************************************************************"
|
|
|
|
echo
|
|
|
|
sleep 5
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2019-03-21 09:02:19 -05:00
|
|
|
./codesign-bundle.sh "${BUILDROOT}/${APP_BUNDLE_NAME}" || { echo codesign-bundle.sh failed; exit 1; }
|
2016-10-04 06:50:16 -05:00
|
|
|
}
|
|
|
|
|
2016-06-02 07:56:56 -05:00
|
|
|
_create_dmg() {
|
2019-03-21 09:02:19 -05:00
|
|
|
cd ${SOURCEDIR}
|
2016-06-02 07:56:56 -05:00
|
|
|
./pkg/mac/create-dmg.sh || { echo create-dmg.sh failed; exit 1; }
|
|
|
|
# Clean the mac-build/ on successful build
|
2019-03-21 09:02:19 -05:00
|
|
|
rm -rf ${BUILDROOT}/*
|
2016-06-02 07:56:56 -05:00
|
|
|
}
|
|
|
|
|
2016-10-04 06:50:16 -05:00
|
|
|
_codesign_dmg() {
|
2019-03-21 09:02:19 -05:00
|
|
|
cd ${SOURCEDIR}/pkg/mac
|
2016-10-04 06:50:16 -05:00
|
|
|
|
|
|
|
if [ ! -f codesign.conf ]; then
|
|
|
|
echo
|
|
|
|
echo "******************************************************************"
|
|
|
|
echo "* codesign.conf not found. NOT signing the disk image."
|
|
|
|
echo "******************************************************************"
|
|
|
|
echo
|
|
|
|
sleep 5
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
./codesign-dmg.sh || { echo codesign-bundle.sh failed; exit 1; }
|
|
|
|
}
|
|
|
|
|
2016-06-02 07:56:56 -05:00
|
|
|
_get_version || { echo Could not get versioning; exit 1; }
|
|
|
|
_cleanup
|
2020-05-04 04:20:51 -05:00
|
|
|
_create_venv || { echo venv creation failed; exit 1; }
|
2016-06-02 07:56:56 -05:00
|
|
|
_build_runtime || { echo Runtime build failed; exit 1; }
|
|
|
|
_build_doc
|
|
|
|
_complete_bundle
|
2017-02-16 05:25:32 -06:00
|
|
|
_framework_config
|
2020-01-03 03:56:45 -06:00
|
|
|
_codesign_binaries
|
2016-10-04 06:50:16 -05:00
|
|
|
_codesign_bundle
|
2016-06-02 07:56:56 -05:00
|
|
|
_create_dmg
|
2017-02-26 03:06:17 -06:00
|
|
|
_codesign_dmg
|