1 #!/usr/bin/bash
   2 #
   3 # CDDL HEADER START
   4 #
   5 # The contents of this file are subject to the terms of the
   6 # Common Development and Distribution License, Version 1.0 only
   7 # (the "License").  You may not use this file except in compliance
   8 # with the License.
   9 #
  10 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  11 # or http://www.opensolaris.org/os/licensing.
  12 # See the License for the specific language governing permissions
  13 # and limitations under the License.
  14 #
  15 # When distributing Covered Code, include this CDDL HEADER in each
  16 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  17 # If applicable, add the following below this CDDL HEADER, with the
  18 # fields enclosed by brackets "[]" replaced with your own identifying
  19 # information: Portions Copyright [yyyy] [name of copyright owner]
  20 #
  21 # CDDL HEADER END
  22 #
  23 #
  24 # Copyright 2011-2012 OmniTI Computer Consulting, Inc.  All rights reserved.
  25 # Use is subject to license terms.
  26 #
  27 
  28 SHELL=/usr/bin/bash
  29 export SHELL
  30 
  31 RELEASE_DATE=nightly # This is overridden by the checkout
  32 
  33 # Load support functions
  34 . ../../lib/functions.sh
  35 
  36 PROG=omnios    # App name
  37 VER=$RELVER    # App version
  38 PVER=1         # Package Version (numeric only)
  39 
  40 PKG=illumos-gate # Package name (without prefix)
  41 SUMMARY="$PROG" # A short summary of what the app is, starting with its name
  42 DESC="$SUMMARY -- Illumos and some special sauce." # Longer description
  43 
  44 #all of the ips depends should be available from OmniTI repos
  45 
  46 BUILD_DEPENDS_IPS="developer/versioning/sccs developer/as developer/astdev developer/build/make developer/build/onbld developer/gcc44 developer/java/jdk developer/lexer/flex developer/object-file developer/parser/bison library/glib2 library/libxml2 library/libxslt library/nspr/header-nspr library/perl-5/xml-parser library/security/trousers runtime/perl runtime/perl-64 runtime/perl/manual system/library/install system/library/dbus system/library/libdbus system/library/libdbus-glib system/library/mozilla-nss/header-nss system/management/snmp/net-snmp text/gnu-gettext sunstudio12.1"
  47 
  48 GIT=git
  49 
  50 USE_SYSTEM_SSL_HEADERS="TRUE"
  51 
  52 PKGPREFIX=""
  53 PREFIX=""
  54 TMPDIR=/code    # This directory must be writable as your non-root user
  55 BUILDDIR=$USER-$PROG-$VER
  56 CODEMGR_WS=$TMPDIR/$BUILDDIR/illumos-omnios
  57 
  58 #Since these variables are used in a sed statment make sure to escape properly
  59 ILLUMOS_NO="NIGHTLY\_OPTIONS=\'\-nDCmpr\'"
  60 ILLUMOS_CODEMGR_WS="CODEMGR\_WS=\/code\/$BUILDDIR\/illumos\-omnios"
  61 #ILLUMOS_CLONE_WS="CLONE\_WS=\'ssh:\/\/anonhg@hg.illumos.org\/illumos\-gate\'"
  62 ILLUMOS_CLONE_WS="CLONE\_WS=\'anon@src.omniti.com:~omnios\/core\/illumos\-omnios\'"
  63 
  64 ILLUMOS_PKG_REDIST="PKGPUBLISHER\_REDIST=\'omnios\'"
  65 
  66 #these variables are appended to the end of the script so no need to escape
  67 ILLUMOS_GNUC="export __GNUC=''"
  68 ILLUMOS_GNUC4="export __GNUC4=''"
  69 ILLUMOS_NO_SHADOW="export CW_NO_SHADOW=1"
  70 ILLUMOS_GCC_ROOT='export GCC_ROOT="/opt/gcc-4.4.4"'
  71 ILLUMOS_CW_GCC_DIR='export CW_GCC_DIR="$GCC_ROOT/bin"'
  72 ILLUMOS_BUILDNUM="ONNV_BUILDNUM=$VER; export ONNV_BUILDNUM;"
  73 ILLUMOS_MULTI_PROTO="export MULTI_PROTO=yes"
  74 
  75 sunstudio_location() {
  76     logmsg "Ensuring that Sun Studio is where Illumos thinks it is..."
  77     if [[ -L /opt/SUNWspro ]]; then
  78         logmsg "--- fake SUNWspro link exists, good"
  79     else
  80         logmsg "--- making fake SUNWspro directory"
  81         logcmd sudo ln -s /opt/sunstudio12.1 /opt/SUNWspro || \
  82             logerr "--- Error: failed to make link"
  83     fi
  84 }
  85 
  86 #In order for the clone to work while running as root, you must have ssh'ed into the box with agent forwarding turned on.  Also the sudo'er file must either have the default, group, or user set to allow SSL_AUTH_SOCK.
  87 
  88 clone_source(){
  89     logmsg "Creating build dir $TMPDIR/$BUILDDIR"
  90     logcmd mkdir -p $TMPDIR/$BUILDDIR || \
  91         logerr "--- Failed to create build dir $TMPDIR/$BUILDDIR"
  92     logmsg "Entering $TMPDIR/$BUILDDIR"
  93     pushd $TMPDIR/$BUILDDIR > /dev/null 
  94     if [ -d illumos-omnios ]; then
  95         logmsg "OMNI Illumos Source in place. Using existing workspace."
  96     else
  97         logmsg "Cloning OMNI Illumos Source..."
  98         logcmd  $GIT clone anon@src.omniti.com:~omnios/core/illumos-omnios || \
  99             logerr "--- Failed to clone source"
 100     fi
 101     pushd illumos-omnios 
 102     ILLUMOS_VERSION="VERSION=\'omnios\-`$GIT log --pretty=format:'%h' -n 1`'" 
 103     RELEASE_DATE=`$GIT show --format=format:%ai | awk '{print $1; exit;}' | tr - .` 
 104     echo $ILLUMOS_VERSION
 105     popd > /dev/null 
 106     logmsg "Leaving $TMPDIR/$BUILDDIR"
 107     popd > /dev/null 
 108 }
 109 
 110 build_tools(){
 111     logmsg "Entering $CODEMGR_WS"
 112     pushd $CODEMGR_WS > /dev/null
 113     logmsg "Building extra tools needed for illumos pkgs..."
 114     logcmd ln -s usr/src/tools/scripts/bldenv.sh .
 115     logcmd ksh93 bldenv.sh -d illumos.sh -c "cd usr/src && dmake setup" 
 116     logmsg "Leaving $CODEMGR_WS"
 117     popd > /dev/null
 118 }
 119 
 120 modify_build_script() {
 121     logmsg "Entering $CODEMGR_WS"
 122     pushd $CODEMGR_WS > /dev/null
 123     logmsg "Changing illumos.sh variables to what we want them to be..."
 124     logcmd cp usr/src/tools/env/illumos.sh .    
 125     logcmd /usr/bin/gsed -i -e 's/^.*export NIGHTLY_OPTIONS.*/export '$ILLUMOS_NO'/g;s/^.*export CODEMGR_WS=.*/export '$ILLUMOS_CODEMGR_WS'/g;s/^.*export CLONE_WS=.*/export '$ILLUMOS_CLONE_WS'/g;s/^.*export PKGPUBLISHER_REDIST=.*/export '$ILLUMOS_PKG_REDIST'/g;s/^.*export VERSION=.*/export '$ILLUMOS_VERSION'/g;/^.*GNUC=.*/d;/^.*CW_NO_SHADOW=.*/d;/^.*ONNV_BUILDNUM=.*/d' illumos.sh || \
 126         logerr "/usr/bin/gsed failed"
 127     logcmd `echo $ILLUMOS_GNUC >> illumos.sh` 
 128     logcmd `echo $ILLUMOS_GNUC4 >> illumos.sh` 
 129     logcmd `echo $ILLUMOS_GCC_ROOT >> illumos.sh` 
 130     logcmd `echo $ILLUMOS_CW_GCC_DIR >> illumos.sh`
 131     logcmd `echo $ILLUMOS_NO_SHADOW >> illumos.sh`
 132     logcmd `echo $ILLUMOS_BUILDNUM >> illumos.sh`
 133     logcmd `echo $ILLUMOS_MULTI_PROTO >> illumos.sh`
 134     logcmd `echo RELEASE_DATE=$RELEASE_DATE >> illumos.sh`
 135     logmsg "Leaving $CODEMGR_WS"
 136     popd > /dev/null
 137 
 138 }
 139 
 140 closed_bins() {
 141     logmsg "Entering $CODEMGR_WS"
 142     pushd $CODEMGR_WS > /dev/null
 143     logmsg "Getting Closed Source Bins..."
 144     for bin in on-closed-bins.i386.tar.bz2 on-closed-bins-nd.i386.tar.bz2 ; do
 145         if [[ ! -f $bin ]]; then
 146             logcmd curl -s -O http://mirrors.omniti.com/illumos-gate/$bin
 147         fi
 148         logcmd tar xvpf $bin
 149     done
 150     logmsg "Leaving $CODEMGR_WS"
 151     popd > /dev/null 
 152 }
 153 
 154 build_pkgs() {
 155     logmsg "Entering $CODEMGR_WS"
 156     pushd $CODEMGR_WS > /dev/null
 157     logmsg "Building illumos pkgs..."
 158     logcmd cp usr/src/tools/scripts/nightly.sh .
 159     logcmd chmod +x nightly.sh
 160     logcmd ./nightly.sh illumos.sh || logerr "Nightly failed"
 161     logmsg "Leaving $CODEMGR_WS"
 162     popd > /dev/null
 163 }
 164 
 165 push_pkgs() {
 166     logmsg "Entering $CODEMGR_WS"
 167     pushd $CODEMGR_WS > /dev/null
 168     logmsg "Pushing illumos pkgs to $PKGSRVR..."
 169     if [[ -z $BATCH ]]; then
 170         logmsg "Intentional pause: Last chance to sanity-check before publication!"
 171         ask_to_continue
 172     fi
 173     logcmd pkgrecv -s packages/i386/nightly-nd/repo.redist/ -d $PKGSRVR 'pkg:/*'
 174     logmsg "Leaving $CODEMGR_WS"
 175     popd > /dev/null
 176 }
 177 
 178 init
 179 prep_build
 180 if [ -d ${PREBUILT_ILLUMOS:-/dev/null} ]; then
 181     wait_for_prebuilt
 182     # Check for existing packages, or for freshly built ones if we pwaited.
 183     if [ -d $PREBUILT_ILLUMOS/packages/i386/nightly-nd/repo.redist ]; then
 184         logmsg "Using illumos-omnios pre-compiled at $PREBUILT_ILLUMOS"
 185         CODEMGR_WS=$PREBUILT_ILLUMOS
 186         push_pkgs
 187     else
 188         logmsg "No $PREBUILT_ILLUMOS/packages/i386/nightly-nd/repo.redist"
 189         if [[ -z $BATCH ]]; then
 190             ask_to_continue
 191         fi
 192     fi
 193 else
 194     sunstudio_location
 195     clone_source
 196     modify_build_script
 197     closed_bins
 198     build_tools
 199     build_pkgs
 200     push_pkgs
 201 fi
 202 clean_up