1 #!/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 2012 OmniTI Computer Consulting, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27 fail() {
28 echo $*
29 exit 1
30 }
31
32 # NOTE --> The URL needs to be updated with every release.
33 # Change "bloody" to whatever release the current branch is.
34 PUBLISHER=omnios
35 OMNIOS_URL=http://pkg.omniti.com/omnios/bloody
36 : ${PKGURL:=http://pkg.omniti.com/omnios/bloody}
37 : ${BZIP2:=bzip2}
38 ZROOT=rpool
39 OUT=
40 CLEANUP=0
41 set -- `getopt cd:o:p: $*`
42 for i in $*
43 do
44 case $i in
45 -c) CLEANUP=1; shift ;;
46 -d) ZROOT=$2; shift 2;;
47 -o) OUT=$2; shift 2;;
48 -p) PROFILE=$2; shift 2;;
49 -P) PUBLISHER_OVERRIDE=1; shift ;;
50 --) shift; break ;;
51 esac
52 done
53
54 name=$1
55 if [[ -z "$name" ]]; then
56 echo "$0 [-cP] [-d zfsparent] [-p profile] [-o outputfile] <release_name>"
57 exit
58 fi
59
60 MPR=`zfs get -H mountpoint $ZROOT | awk '{print $3}'`
61 if [[ -z "$OUT" ]]; then
62 OUT=$MPR/kayak_$name.zfs.bz2
63 fi
64
65 if zfs list $ZROOT/$name@entire > /dev/null 2>&1; then
66 zfs rollback -r $ZROOT/$name@entire
67 MP=`zfs get -H mountpoint $ZROOT/$name | awk '{print $3}'`
68 else
69 zfs create $ZROOT/$name || fail "zfs create"
70 MP=`zfs get -H mountpoint $ZROOT/$name | awk '{print $3}'`
71 pkg image-create -F -a $PUBLISHER=$PKGURL $MP || fail "image-create"
72 # If r151006, use a specific version to avoid missing incorporation
73 if [[ "$name" == "r151006" ]]; then
74 entire_version="151006:20131210T224515Z"
75 else
76 entire_version=${name//r/}
77 fi
78 pkg -R $MP install entire@11-0.$entire_version || fail "install entire"
79 zfs snapshot $ZROOT/$name@entire
80 fi
81
82 if [[ -n "$PROFILE" ]]; then
83 echo "Applying custom profile: $PROFILE"
84 [[ -r "$PROFILE" ]] || fail "Cannot find file: $PROFILE"
85 while read line ;
86 do
87 TMPPUB=`echo $line | cut -f1 -d=`
88 TMPURL=`echo $line | cut -f2 -d=`
89 if [[ -n "$TMPURL" && "$TMPURL" != "$TMPPUB" ]]; then
90 echo "Setting publisher: $TMPPUB / $TMPURL"
91 pkg -R $MP set-publisher -g $TMPURL $TMPPUB || fail "set publisher $TMPPUB"
92 PUBLISHER=$TMPPUB
93 PKGURL=$TMPURL
94 else
95 echo "Installing additional package: $line"
96 pkg -R $MP install -g $PKGURL $line || fail "install $line"
97 fi
98 done < <(grep . $PROFILE | grep -v '^ *#')
99 fi
100
101 if [[ -n "$PUBLISHER_OVERRIDE" ]]; then
102 OMNIOS_URL=$PKGURL
103 fi
104 echo "Setting omnios publisher to $OMNIOS_URL"
105 pkg -R $MP unset-publisher omnios
106 pkg -R $MP set-publisher -P --no-refresh -g $OMNIOS_URL omnios
107
108 zfs snapshot $ZROOT/$name@kayak || fail "snap"
109 zfs send $ZROOT/$name@kayak | $BZIP2 -9 > $OUT || fail "send/compress"
110 if [[ "$CLEANUP" -eq "1" ]]; then
111 zfs destroy $ZROOT/$name@kayak || fail "could not remove snapshot"
112 zfs destroy $ZROOT/$name || fail "could not remove zfs filesystem"
113 fi