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 # We have to build as root to manipulate ZFS datasets
  29 export ROOT_OK=yes
  30 
  31 # Load support functions
  32 . ../../lib/functions.sh
  33 
  34 if [[ "$UID" != "0" ]]; then
  35     logerr "--- This script needs to be run as root."
  36 fi
  37 
  38 # We also need to be in the global zone to access the kernel binary
  39 if [[ `zonename` != "global" ]]; then
  40     logerr "--- This script must be run in the global zone."
  41 fi
  42 
  43 PROG=kayak
  44 VER=1.1
  45 VERHUMAN=$VER
  46 PKG=system/install/kayak
  47 SUMMARY="Kayak - network installer (server files)"
  48 DESC="Kayak is the network installer for OmniOS, using PXE, DHCP and HTTP"
  49 
  50 BUILD_DEPENDS_IPS="developer/versioning/git"
  51 DEPENDS_IPS="developer/build/gnu-make developer/dtrace service/network/tftp"
  52 
  53 GIT=/usr/bin/git
  54 CHECKOUTDIR=$TMPDIR/$BUILDDIR
  55 IMG_DSET=rpool/kayak_image
  56 PKGURL=$PKGSRVR
  57 export PKGURL
  58 
  59 clone_source() {
  60     logmsg "kayak -> $CHECKOUTDIR/kayak"
  61     logcmd mkdir -p $TMPDIR/$BUILDDIR
  62     pushd $CHECKOUTDIR > /dev/null
  63     if [[ ! -d kayak ]]; then
  64         logmsg "--- No checkout found, cloning anew"
  65         logcmd $GIT clone anon@src.omniti.com:~omnios/core/kayak
  66     else
  67         logmsg "--- Checkout found, updating it"
  68         pushd kayak > /dev/null
  69         $GIT pull || logerr "failed to update"
  70         popd > /dev/null
  71     fi
  72     pushd kayak > /dev/null
  73     GITREV=$(git rev-parse HEAD)
  74     VERHUMAN="$VERHUMAN (git: ${GITREV:0:7})"
  75     popd > /dev/null
  76     popd > /dev/null
  77 }
  78 
  79 build_server() {
  80     pushd $CHECKOUTDIR/kayak > /dev/null || logerr "Cannot change to src dir"
  81     logmsg "Installing server files"
  82     logcmd gmake DESTDIR=$DESTDIR install-package || \
  83         logerr "gmake failed"
  84     popd > /dev/null
  85 }
  86 
  87 build_miniroot() {
  88     if [[ -z "`zfs list $IMG_DSET`" ]]; then
  89         /sbin/zfs create $IMG_DSET
  90     fi
  91     pushd $CHECKOUTDIR/kayak > /dev/null || logerr "Cannot change to src dir"
  92     logmsg "Building miniroot"
  93     logcmd gmake BUILDSEND=$IMG_DSET DESTDIR=$DESTDIR install-tftp || \
  94         logerr "gmake failed"
  95 
  96     popd > /dev/null
  97 }
  98 
  99 init
 100 clone_source
 101 prep_build
 102 logmsg "Now building $PKG"
 103 build_server
 104 make_package kayak.mog
 105 clean_up
 106 
 107 PKG=system/install/kayak-kernel
 108 SUMMARY="Kayak - network installer (kernel, miniroot and pxegrub)"
 109 PKGE=$(url_encode $PKG)
 110 PKGD=${PKGE//%/_}
 111 DESTDIR=$DTMPDIR/${PKGD}_pkg
 112 DEPENDS_IPS=""
 113 
 114 logmsg "Now building $PKG"
 115 build_miniroot
 116 make_package
 117 clean_up
 118 
 119 # Vim hints
 120 # vim:ts=4:sw=4:et: