Print this page
Kayak uses sudo with variable set (and sudoers set)
| Split |
Close |
| Expand all |
| Collapse all |
--- old/build/kayak/build.sh
+++ new/build/kayak/build.sh
1 1 #!/usr/bin/bash
2 2 #
3 3 # CDDL HEADER START
4 4 #
5 5 # The contents of this file are subject to the terms of the
6 6 # Common Development and Distribution License, Version 1.0 only
7 7 # (the "License"). You may not use this file except in compliance
8 8 # with the License.
9 9 #
10 10 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 11 # or http://www.opensolaris.org/os/licensing.
12 12 # See the License for the specific language governing permissions
13 13 # and limitations under the License.
14 14 #
15 15 # When distributing Covered Code, include this CDDL HEADER in each
16 16 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 17 # If applicable, add the following below this CDDL HEADER, with the
18 18 # fields enclosed by brackets "[]" replaced with your own identifying
19 19 # information: Portions Copyright [yyyy] [name of copyright owner]
20 20 #
|
↓ open down ↓ |
20 lines elided |
↑ open up ↑ |
21 21 # CDDL HEADER END
22 22 #
23 23 #
24 24 # Copyright 2011-2012 OmniTI Computer Consulting, Inc. All rights reserved.
25 25 # Use is subject to license terms.
26 26 #
27 27
28 28 # We have to build as root to manipulate ZFS datasets
29 29 export ROOT_OK=yes
30 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 +
31 41 # Load support functions
32 42 . ../../lib/functions.sh
33 43
34 44 if [[ "$UID" != "0" ]]; then
35 45 logerr "--- This script needs to be run as root."
36 46 fi
37 47
38 48 # We also need to be in the global zone to access the kernel binary
39 49 if [[ `zonename` != "global" ]]; then
40 50 logerr "--- This script must be run in the global zone."
41 51 fi
42 52
43 53 PROG=kayak
44 54 VER=1.1
45 55 VERHUMAN=$VER
46 56 PKG=system/install/kayak
47 57 SUMMARY="Kayak - network installer (server files)"
48 58 DESC="Kayak is the network installer for OmniOS, using PXE, DHCP and HTTP"
49 59
50 60 BUILD_DEPENDS_IPS="developer/versioning/git"
51 61 DEPENDS_IPS="developer/build/gnu-make developer/dtrace service/network/tftp"
52 62
53 63 GIT=/usr/bin/git
54 64 CHECKOUTDIR=$TMPDIR/$BUILDDIR
55 65 IMG_DSET=rpool/kayak_image
56 66 PKGURL=$PKGSRVR
57 67 export PKGURL
58 68
59 69 clone_source() {
60 70 logmsg "kayak -> $CHECKOUTDIR/kayak"
61 71 logcmd mkdir -p $TMPDIR/$BUILDDIR
62 72 pushd $CHECKOUTDIR > /dev/null
63 73 if [[ ! -d kayak ]]; then
64 74 logmsg "--- No checkout found, cloning anew"
65 75 logcmd $GIT clone anon@src.omniti.com:~omnios/core/kayak
66 76 else
67 77 logmsg "--- Checkout found, updating it"
68 78 pushd kayak > /dev/null
69 79 $GIT pull || logerr "failed to update"
70 80 popd > /dev/null
71 81 fi
72 82 pushd kayak > /dev/null
73 83 GITREV=$(git rev-parse HEAD)
74 84 VERHUMAN="$VERHUMAN (git: ${GITREV:0:7})"
75 85 popd > /dev/null
76 86 popd > /dev/null
77 87 }
78 88
79 89 build_server() {
80 90 pushd $CHECKOUTDIR/kayak > /dev/null || logerr "Cannot change to src dir"
81 91 logmsg "Installing server files"
82 92 logcmd gmake DESTDIR=$DESTDIR install-package || \
83 93 logerr "gmake failed"
84 94 popd > /dev/null
85 95 }
86 96
87 97 build_miniroot() {
88 98 if [[ -z "`zfs list $IMG_DSET`" ]]; then
89 99 /sbin/zfs create $IMG_DSET
90 100 fi
91 101 pushd $CHECKOUTDIR/kayak > /dev/null || logerr "Cannot change to src dir"
92 102 logmsg "Building miniroot"
93 103 logcmd gmake BUILDSEND=$IMG_DSET DESTDIR=$DESTDIR install-tftp || \
94 104 logerr "gmake failed"
95 105
|
↓ open down ↓ |
55 lines elided |
↑ open up ↑ |
96 106 popd > /dev/null
97 107 }
98 108
99 109 init
100 110 clone_source
101 111 prep_build
102 112 logmsg "Now building $PKG"
103 113 build_server
104 114 make_package kayak.mog
105 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
106 122
107 123 PKG=system/install/kayak-kernel
108 124 SUMMARY="Kayak - network installer (kernel, miniroot and pxegrub)"
109 125 PKGE=$(url_encode $PKG)
110 126 PKGD=${PKGE//%/_}
111 127 DESTDIR=$DTMPDIR/${PKGD}_pkg
112 128 DEPENDS_IPS=""
113 129
114 130 logmsg "Now building $PKG"
115 131 build_miniroot
116 132 make_package
117 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
118 140
119 141 # Vim hints
120 142 # vim:ts=4:sw=4:et:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX