bundle.sh 4.3 KB
Newer Older
1 2 3
#
# This file is part of the xTuple ERP: PostBooks Edition, a free and
# open source Enterprise Resource Planning software suite,
gilmoskowitz's avatar
gilmoskowitz committed
4
# Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
5 6 7 8 9 10
# It is licensed to you under the Common Public Attribution License
# version 1.0, the full text of which (including xTuple-specific Exhibits)
# is available at www.xtuple.com/CPAL.  By using this software, you agree
# to be bound by its terms.
#

gilmoskowitz's avatar
gilmoskowitz committed
11
PROG=`basename $0`
12
ARCH=
13
VERFILE=common/data.cpp
gilmoskowitz's avatar
gilmoskowitz committed
14 15 16 17 18 19
BUILD=false
DEMO=false
BASEDIR=`pwd`
if [ "$BASEDIR" = . ] ; then
  BASEDIR=`pwd`
fi
20 21 22 23 24
OS=`uname -s`
if [ "$OS" = Darwin ] ; then
  ARCH=`uname -p`
  OSVER=MAC${ARCH}
fi
gilmoskowitz's avatar
gilmoskowitz committed
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

usage() {
  echo "$PROG -h"
  echo "$PROG -b -d [ -x ]"
  echo
  fmt <<EOF
$PROG bundles the Updater application for release on the current platform
(currently only Mac OS X is supported).
$PROG reads $VERFILE to get release information used to
name the release package.
EOF
  echo
  echo "-h	get this usage message"
  echo "-b	force build (run qmake and make before bundling)"
  echo "	$PROG runs qmake and make if the required binaries are missing "
  echo "	from the bin directory even if -b is not specified."
  echo "-d <file>	build and bundle a demo release, including the help file named <file>"
  echo "-x	turn on shell debugging output"
}

bundle() {
  if [ "$#" -ne 2 ] ; then
    echo "Illegal call to bundle: bad arg count"
    echo "usage: bundle app dir_to_put_it_in"
    return 1
  fi

  STARTDIR=`pwd`

  APPNAME="$1"
  if expr "$APPNAME" : ".*\.app" ; then
    BINARY="$APPNAME"
    APPNAME=`basename "$APPNAME" .app`
  else
    BINARY="${APPNAME}.app"
  fi

  if $DEMO ; then
63
    BUNDLENAME="${APPNAME}-${VERSION}Demo-${OSVER}"
gilmoskowitz's avatar
gilmoskowitz committed
64
  else
65
    BUNDLENAME="${APPNAME}-${VERSION}-${OSVER}"
gilmoskowitz's avatar
gilmoskowitz committed
66 67 68 69 70 71 72 73 74 75 76 77 78
  fi
  BUNDLEDIR="${2}/${BUNDLENAME}"

  if [ -d "$BUNDLEDIR" ] ; then
    if ! rm -rf "$BUNDLEDIR" ; then
      return 3
    fi
  fi

  if ! mkdir "$BUNDLEDIR" ; then
    return 3
  fi

79
  if $DEMO ; then
gilmoskowitz's avatar
gilmoskowitz committed
80
    BINARY="${APPNAME}_Demo.app"
81 82 83 84 85 86 87 88 89 90
  else
    BINARY="${APPNAME}.app"
  fi
  if [ "$OSVER" = MacUniversal ] ; then
    cp -R "$BASEDIR/bin/${APPNAME}.app" "$BUNDLEDIR"  || return 4
  else
    ditto --rsrc -arch $ARCH "$BASEDIR/bin/${APPNAME}.app" "$BUNDLEDIR/$BINARY" || return 4
  fi

  if $DEMO ; then
gilmoskowitz's avatar
gilmoskowitz committed
91 92
    if [ -d "$HELPFILE" ] ; then
      if ! cp -R -L "$HELPFILE" \
93
	      "$BUNDLEDIR"/"${BINARY}"/Contents/Resources/helpOpenMFGGUIClient ; then
gilmoskowitz's avatar
gilmoskowitz committed
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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
	return 5
      fi
    elif [ -f "$HELPFILE" ] ; then
      CURRDIR=`pwd`
      if ! cd "$BUNDLEDIR"/"${BINARY}"/Contents/Resources ; then
	return 5
      fi
      if ! jar xf "$HELPFILE" ; then
	return 5
      fi
      if [ ! -d helpOpenMFGGUIClient ] ; then
	echo "$PROG: help file $HELPFILE was not installed properly in demo client"
	return 5
      fi
      cd "$CURRDIR"
    fi
  fi

  cd "$BUNDLEDIR"/..
  if [ -f "$BUNDLENAME".dmg ] && ! rm "$BUNDLENAME".dmg ; then
    return 5
  fi
  if ! hdiutil create -fs HFS+ -volname "$BUNDLENAME" -srcfolder "$BUNDLENAME" "$BUNDLENAME".dmg ; then
    return 5
  fi

  cd $STARTDIR
}

ARGS=`getopt hbd:x $*`
if [ $? != 0 ] ; then
  usage
  exit 1
fi
set -- $ARGS

while [ "$1" != -- ] ; do
  case "$1" in
    -h)
	usage
	exit 0
	;;
    -b)
	BUILD=true
	;;
    -d)
	DEMO=true
	HELPFILE=$2
	if ! expr ${HELPFILE} : "\/" ; then
	  HELPFILE=`pwd`/"$HELPFILE"
	fi
	shift
	;;
    -x)
	set -x
	;;
    *)
	usage
	exit 1
	;;
  esac
  shift
done
shift # past the --

if [ "$#" -gt 0 ] ; then
  echo "$PROG: ignoring extra arguments $*"
fi

if [ `uname -s` != Darwin ] ; then
  echo "$PROG: only supports Macintosh OS X (Darwin) at this time"
  usage
  exit 2
fi
168 169
ARCH=`uname -p`
OSVER=MAC${ARCH}
gilmoskowitz's avatar
gilmoskowitz committed
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199

if [ -z "$QTDIR" ] ; then
  echo "$PROG: Cannot run properly without the QTDIR environment variable set"
  exit 2
fi
if [ -z "$PGDIR" ] ; then
  echo "$PROG: Cannot run properly without the PGDIR environment variable set"
  exit 2
fi

if [ ! -e "$BASEDIR"/bin/updater.app ] ; then
  if ! $BUILD ; then
    echo "Building even though not explicitly told to do so"
  fi
  BUILD=true
fi

if [ ! -f "$VERFILE" ] ; then
  echo "Could not find $VERFILE"
  exit 2
fi
VERSION=`cpp $VERFILE | sed -n '/_version/s/.*"\([^"]*\)".*/\1/p'`

if $BUILD ; then
  cd "$BASEDIR"
  qmake
  make
fi

cd "$BASEDIR"/loader
200 201
./fixPackage -pID ../bin/updater.app

gilmoskowitz's avatar
gilmoskowitz committed
202 203 204 205 206 207 208 209 210 211

cd "$BASEDIR"/bin

for FILE in updater ; do
  if ! bundle ${FILE} "${BASEDIR}/.." ; then
    exit $?
  fi
done

echo "DONE!"