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 if [[ "$UID" != 0 && ! -z $KAYAK_SUDO_BUILD ]]; then
  32        # Run sudo BEFORE functions.sh eats the parameters.
  33        # Installing OmniOS-on-demand should create an entry in /etc/sudoers.d/
  34        # to cover running this script under sudo.
  35        echo "Running again under sudo, currently UID = $UID, EUID = $EUID."
  36        export OLDUSER=`whoami`
  37        export KAYAK_SUDO_BUILD
  38        exec sudo -n ./build.sh $@
  39 fi
  40 
  41 # Load support functions
  42 . ../../lib/functions.sh
  43 
  44 if [[ "$UID" != "0" ]]; then
  45     logerr "--- This script needs to be run as root."
  46 fi
  47 
  48 # We also need to be in the global zone to access the kernel binary
  49 if [[ `zonename` != "global" ]]; then
  50     logerr "--- This script must be run in the global zone."
  51 fi
  52 
  53 PROG=kayak
  54 VER=1.1
  55 VERHUMAN=$VER
  56 PKG=system/install/kayak
  57 SUMMARY="Kayak - network installer (server files)"
  58 DESC="Kayak is the network installer for OmniOS, using PXE, DHCP and HTTP"
  59 
  60 BUILD_DEPENDS_IPS="developer/versioning/git"
  61 DEPENDS_IPS="developer/build/gnu-make developer/dtrace service/network/tftp"
  62 
  63 GIT=/usr/bin/git
  64 CHECKOUTDIR=$TMPDIR/$BUILDDIR
  65 IMG_DSET=rpool/kayak_image
  66 PKGURL=$PKGSRVR
  67 export PKGURL
  68 
  69 clone_source() {
  70     logmsg "kayak -> $CHECKOUTDIR/kayak"
  71     logcmd mkdir -p $TMPDIR/$BUILDDIR
  72     pushd $CHECKOUTDIR > /dev/null
  73     if [[ ! -d kayak ]]; then
  74         logmsg "--- No checkout found, cloning anew"
  75         logcmd $GIT clone anon@src.omniti.com:~omnios/core/kayak
  76     else
  77         logmsg "--- Checkout found, updating it"
  78         pushd kayak > /dev/null
  79         $GIT pull || logerr "failed to update"
  80         popd > /dev/null
  81     fi
  82     pushd kayak > /dev/null
  83     GITREV=$(git rev-parse HEAD)
  84     VERHUMAN="$VERHUMAN (git: ${GITREV:0:7})"
  85     popd > /dev/null
  86     popd > /dev/null
  87 }
  88 
  89 build_server() {
  90     pushd $CHECKOUTDIR/kayak > /dev/null || logerr "Cannot change to src dir"
  91     logmsg "Installing server files"
  92     logcmd gmake DESTDIR=$DESTDIR install-package || \
  93         logerr "gmake failed"
  94     popd > /dev/null
  95 }
  96 
  97 build_miniroot() {
  98     if [[ -z "`zfs list $IMG_DSET`" ]]; then
  99         /sbin/zfs create $IMG_DSET
 100     fi
 101     pushd $CHECKOUTDIR/kayak > /dev/null || logerr "Cannot change to src dir"
 102     logmsg "Building miniroot"
 103     logcmd gmake BUILDSEND=$IMG_DSET DESTDIR=$DESTDIR install-tftp || \
 104         logerr "gmake failed"
 105 
 106     popd > /dev/null
 107 }
 108 
 109 init
 110 clone_source
 111 prep_build
 112 logmsg "Now building $PKG"
 113 build_server
 114 make_package kayak.mog
 115 clean_up
 116 # Do extra cleaning up if we got run under sudo from ourselves.
 117 if [[ -z `echo $RPATH | grep http://` ]]; then
 118        OLDUSER=`ls -ltd $RPATH | awk '{print $3}'`
 119        logmsg "--- Re-chowning $RPATH to user $OLDUSER"
 120        chown -R $OLDUSER $RPATH
 121 fi
 122 
 123 PKG=system/install/kayak-kernel
 124 SUMMARY="Kayak - network installer (kernel, miniroot and pxegrub)"
 125 PKGE=$(url_encode $PKG)
 126 PKGD=${PKGE//%/_}
 127 DESTDIR=$DTMPDIR/${PKGD}_pkg
 128 DEPENDS_IPS=""
 129 
 130 logmsg "Now building $PKG"
 131 build_miniroot
 132 make_package
 133 clean_up
 134 # Do extra cleaning up if we got run under sudo from ourselves.
 135 if [[ -z `echo $RPATH | grep http://` ]]; then
 136        OLDUSER=`ls -ltd $RPATH | awk '{print $3}'`
 137        logmsg "--- Re-chowning $RPATH to user $OLDUSER"
 138        chown -R $OLDUSER $RPATH
 139 fi
 140 
 141 # Vim hints
 142 # vim:ts=4:sw=4:et: