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