initial revision
authorGuido Berhoerster <guido@berhoerster.name>
Wed, 26 Jan 2011 16:53:37 +0100
changeset 0 b10069f5bd70
child 1 83e0fb06f53d
initial revision
README
patches/desktop-cbe-mini-01-privileges.patch
patches/desktop-cbe-mini-02-pkgbuild-patches.patch
plugins/jds.sh
plugins/oiac.sh
plugins/sfe-unsupported.sh
setup-buildenv.sh
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README	Wed Jan 26 16:53:37 2011 +0100
@@ -0,0 +1,12 @@
+OpenIndiana Common Build Environment for pkgbuild-based consolidations
+======================================================================
+
+The following files need to be downloaded an placed into ./sources:
+
+* sunstudio12u1-patched-ii-2010Feb-sol-x86.tar.gz (SunStudio 12 Update 1),
+  available at https://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_SMI-Site/en_US/-/USD/ViewProductDetail-Start?ProductRef=SS12U1-OSOLCBE-0210-G-F@CDS-CDS_SMI
+* desktop-cbe-mini-1.8.0.tar.bz2 (Common Build Environment 1.8.0), available
+  at http://dlc.sun.com/osol/jds/downloads/cbe/test/desktop-cbe-mini-1.8.0.tar.bz2
+
+After copying or loopback mounting this directory into the build zone, the
+script setup-buildenv.sh [plugin] needs to be executed with root privileges.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/patches/desktop-cbe-mini-01-privileges.patch	Wed Jan 26 16:53:37 2011 +0100
@@ -0,0 +1,15 @@
+diff -ur desktop-cbe-mini-1.8.0.orig/mini-cbe-install desktop-cbe-mini-1.8.0/mini-cbe-install
+--- desktop-cbe-mini-1.8.0.orig/mini-cbe-install	Mi. Jul 14 15:24:39 2010
++++ desktop-cbe-mini-1.8.0/mini-cbe-install	Sa. Okt 30 11:49:33 2010
+@@ -1000,9 +1000,9 @@
+     msg "Building CBEenv"
+     logrun_quiet /usr/bin/pkgbuild --define "cbe_prefix $cbe_prefix" --define "cbe_version $CBE_VERSION" --define "build_user $logname" -ba CBEenv.spec || return 1
+     pkg_try_install cbe/desktop/CBEenv || return 1
+-    logrun cp ${envdir}/* $cbe_prefix/lib/cbe-env/
++    logrun pfexec cp ${envdir}/* $cbe_prefix/lib/cbe-env/
+     def_env_name=$(basename $default_env)
+-    cd $cbe_prefix/lib/cbe-env; rm -f default; ln -s $def_env_name default
++    cd $cbe_prefix/lib/cbe-env; pfexec rm -f default; pfexec ln -s $def_env_name default
+     cd $mydir
+     msg "CBE setup complete"
+     msg "Run"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/patches/desktop-cbe-mini-02-pkgbuild-patches.patch	Wed Jan 26 16:53:37 2011 +0100
@@ -0,0 +1,262 @@
+diff -urN desktop-cbe-mini-1.8.0.orig/mini-cbe-install desktop-cbe-mini-1.8.0/mini-cbe-install
+--- desktop-cbe-mini-1.8.0.orig/mini-cbe-install	2010-07-14 15:24:39.000000000 +0200
++++ desktop-cbe-mini-1.8.0/mini-cbe-install	2010-11-02 13:35:10.000000000 +0100
+@@ -919,8 +919,10 @@
+     msg "Please be patient, this may take a couple of minutes."
+     logrun mkdir -p $tmp_build_dir/packages/SOURCES || return 1
+     logrun ln -s $tardir/pkgbuild-$PKGBUILD_VERSION.tar.bz2 $tmp_build_dir/packages/SOURCES/ || return 1
++    logrun cp $mydir/patches/pkgbuild-*.patch $tmp_build_dir/packages/SOURCES/ || return 1
++    logrun patch -p1 < $mydir/pkgbuild-add-patches.patch || return 1
+     logrun cp -pr $tmp_build_dir/src/pkgbuild-$PKGBUILD_VERSION/COPYING $tmp_build_dir/packages/SOURCES/gpl-2.0.txt || return 1
+-    logrun_quiet bash -c "$tmp_build_dir/bin/pkgtool --src $tmp_build_dir/packages/SOURCES --nonotify --define \"pkgbuild_prefix /usr\" --define \"_topdir $tmp_build_dir/packages\" build --update-if-newer $tmp_build_dir/src/pkgbuild-$PKGBUILD_VERSION/pkgbuild.spec" || return 1
++    logrun_quiet bash -c "$tmp_build_dir/bin/pkgtool --src $tmp_build_dir/packages/SOURCES --patches $tmp_build_dir/packages/SOURCES --nonotify --define \"pkgbuild_prefix /usr\" --define \"_topdir $tmp_build_dir/packages\" build --update-if-newer $tmp_build_dir/src/pkgbuild-$PKGBUILD_VERSION/pkgbuild.spec" || return 1
+     pkgbuild_topdir=`/usr/bin/pkgbuild -bp /usr/lib/pkgbuild-$PKGBUILD_VERSION/get_rpm_topdir 2>&1 | grep '^TOPDIR=' | cut -f2- -d=`
+     logrun mkdir -p "$rootdir/$pkgbuild_topdir/PKGS" "$rootdir/$pkgbuild_topdir/SPKGS"
+     cd /tmp || return 1
+diff -urN desktop-cbe-mini-1.8.0.orig/patches/pkgbuild-01-add-unknown-dependencies.patch desktop-cbe-mini-1.8.0/patches/pkgbuild-01-add-unknown-dependencies.patch
+--- desktop-cbe-mini-1.8.0.orig/patches/pkgbuild-01-add-unknown-dependencies.patch	1970-01-01 01:00:00.000000000 +0100
++++ desktop-cbe-mini-1.8.0/patches/pkgbuild-01-add-unknown-dependencies.patch	2010-11-02 13:35:10.000000000 +0100
+@@ -0,0 +1,13 @@
++diff -ur pkgbuild-1.3.103.orig/pkgbuild.pl.in pkgbuild-1.3.103/pkgbuild.pl.in
++--- pkgbuild-1.3.103.orig/pkgbuild.pl.in	2010-07-12 04:56:34.000000000 +0200
+++++ pkgbuild-1.3.103/pkgbuild.pl.in	2010-10-24 11:47:20.000000000 +0200
++@@ -995,7 +995,8 @@
++ 	if (defined ($pkg) and defined($pkgname)) {
++ 	    print $fhandle "P $pkg $pkgname\n"; 
++ 	} else {
++-	    print "WARNING: omitting $dep from the SVr4 depend file\n";
+++	    print "WARNING: unknown dependency $dep\n";
+++	    print $fhandle "P $dep\n"; 
++ 	}
++     }
++ 
+diff -urN desktop-cbe-mini-1.8.0.orig/patches/pkgbuild-02-nopkg.patch desktop-cbe-mini-1.8.0/patches/pkgbuild-02-nopkg.patch
+--- desktop-cbe-mini-1.8.0.orig/patches/pkgbuild-02-nopkg.patch	1970-01-01 01:00:00.000000000 +0100
++++ desktop-cbe-mini-1.8.0/patches/pkgbuild-02-nopkg.patch	2010-11-02 13:45:19.000000000 +0100
+@@ -0,0 +1,182 @@
++diff -ur pkgbuild-1.3.103.orig/pkgtool.pl pkgbuild-1.3.103/pkgtool.pl
++--- pkgbuild-1.3.103.orig/pkgtool.pl	2010-07-14 13:03:12.000000000 +0200
+++++ pkgbuild-1.3.103/pkgtool.pl	2010-11-02 13:44:16.000000000 +0100
++@@ -98,6 +98,7 @@
++ # Which package mechanism are we going to install by default?
++ my $ips;
++ my $svr4;
+++my $nopkg;
++ 
++ sub process_defaults () {
++     my $default_spec_dir = "$topdir/SPECS";
++@@ -363,9 +364,11 @@
++ 	(defined ($ips_utils) and $ips_utils->is_depotd_enabled())) {
++ 	$ips = 1;
++ 	$svr4 = undef;
+++	$nopkg = undef;
++     } else {
++ 	$ips = undef;
++ 	$svr4 = 1;
+++	$nopkg = undef;
++     }
++ }
++ 
++@@ -764,12 +767,22 @@
++ 	}
++ 	$ips = shift;
++ 	$svr4 = undef;
+++	$nopkg = undef;
++ }
++ 
++ sub set_svr4($) {
++ 	msg_info (0,"SVr4 packages will be installed by default");
++ 	$svr4 = shift;
++ 	$ips = undef;
+++	$nopkg = undef;
+++}
+++
+++sub set_nopkg($) {
+++	msg_info (0,"Packages will be copied into the filesystem without using a package system");
+++	msg_warning (0,"This may break your system!");
+++	$ips = undef;
+++	$svr4 = undef;
+++	$nopkg = shift;
++ }
++ 
++ sub process_options {
++@@ -868,6 +881,7 @@
++ 		},
++ 		'ips' => sub { set_ips(1); },
++ 		'svr4' => sub { set_svr4(1); },
+++		'nopkg' => sub { set_nopkg(1); },
++                 'rmlog' => sub { shift; $defaults->set ('rmlog', shift); },
++ 		'<>' => \&process_args);
++ 
++@@ -945,6 +959,11 @@
++ 
++ 		  Install SVr4 packages by default.
++ 
+++    --nopkg
+++
+++		  Don't install any packages, simply copy the files.
+++		  WARNING: This may break your system!
+++
++     --rmlog
++ 
++                   Automatically remove the log file with each build
++@@ -1511,6 +1530,95 @@
++     return 1;
++ }
++ 
+++sub install_pkgs_nopkg ($) {
+++    my $spec_id = shift;
+++    my $spec = $specs_to_build[$spec_id];
+++    
+++    my @pkgs = $spec->get_package_names ($ds);
+++    my $verbose = $defaults->get ('verbose');
+++    if ($verbose > 0) {
+++	map msg_info (0, "Installing $_\n"), @pkgs;
+++    }
+++    
+++    my $pkgsdir = $spec->get_value_of ("_topdir") . "/PKGS";
+++    
+++    my $adminfile = "/tmp/pkg.admin.$$";
+++    make_admin_file ($adminfile);
+++
+++# FIXME: should install in dependency order
+++    foreach my $pkg (@pkgs) {
+++	my $msg;
+++	
+++	# Only install SVr4 package if --svr4 is defined
+++	if (defined $nopkg) {
+++		my $nopkgdir = "/tmp/.pkgtool-pkg.tmp.$$";
+++            if (-e $nopkgdir) {
+++		    `rm -rf $nopkgdir`;
+++	    }
+++	    `mkdir $nopkgdir`;
+++
+++	    if (defined ($ds)) {
+++		$msg=`/usr/bin/pkgtrans $pkgsdir/$pkg $nopkgdir all 2>&1`;
+++	    } else {
+++		$msg=`/usr/bin/pkgtrans $pkgsdir $nopkgdir $pkg 2>&1`;
+++	    }
+++	    
+++	    if ($? > 0) {
+++		unlink ($adminfile);
+++		msg_error "failed to install package: $msg";
+++		$build_status[$spec_id] = 'FAILED';
+++		$status_details[$spec_id] = $msg;
+++		return 0;
+++	    }
+++
+++	    my $basedir = `grep '^BASEDIR=' $nopkgdir/$pkg/pkginfo |cut -d = -f 2`;
+++	    chomp $basedir;
+++
+++	    my $pkgmap = `cat $nopkgdir/$pkg/pkgmap`;
+++
+++	    # Install directories first.
+++	    while ($pkgmap =~ /^\S+ [dx] \S+ (\S+) (\S+)/mg) {
+++		my ($path, $mode) = ($1, $2);
+++
+++		if (! -d "$basedir/$path") {
+++		    `pfexec mkdir -m $mode -p $basedir/$path`;
+++		}
+++	    }
+++
+++	    # Install files. Skip editable/volatile files that already exist.
+++	    while ($pkgmap =~ /^\S+ ([fev]) \S+ (\S+) (\S+)/mg) {
+++		my ($type, $path, $mode) = ($1, $2, $3);
+++
+++		if ($type !~ /^[ev]$/ || ! -e "$basedir/$path") {
+++		    `pfexec cp -Ppf $nopkgdir/$pkg/reloc/$path $basedir/$path`;
+++		    `pfexec chmod $mode $basedir/$path`;
+++		}
+++	    }
+++
+++	    # Install links.
+++	    while ($pkgmap =~ /^\S+ ([sl]) \S+ (\S+)=(\S+)/mg) {
+++		my ($type, $path, $dest) = ($1, $2, $3);
+++
+++		# Make sure the last argument to ln won't be interpreted as a
+++		# directory name by removing existing directories and symlinks
+++		# to directories first.
+++		if (-e "$basedir/$path") {
+++			`pfexec rm -rf $basedir/$path`;
+++		}
+++
+++		if ($type eq 'l') {
+++			`pfexec ln -f $dest $basedir/$path`;
+++		} else {
+++			`pfexec ln -sf $dest $basedir/$path`;
+++		}
+++	    }
+++	}
+++    }
+++    
+++    unlink ($adminfile);
+++    return 1;
+++}
+++
++ my %all_incorporations;
++ my %incorporated;
++ 
++@@ -2594,6 +2702,8 @@
++ 		install_pkgs_ips ($spec_id) || return 0;
++ 	    } elsif (defined ($svr4)) {
++ 		install_pkgs_svr4 ($spec_id) || return 0;
+++            } elsif (defined ($nopkg)) {
+++                install_pkgs_nopkg ($spec_id) || return 0;
++ 	    } else {
++ 		msg_error ("Internal error: either IPS or SVr4 should be selected");
++ 		return 0;
++@@ -2673,6 +2783,10 @@
++ 	$the_command = "$the_command --nodeps";
++     }
++ 
+++    if ($nopkg) {
+++	$the_command = "$the_command --nodeps";
+++    }
+++
++ # FIXME: ExclusiveArch?
++     my $rpm_target = $defaults->get ('target');
++     if (defined($rpm_target)) {
+diff -urN desktop-cbe-mini-1.8.0.orig/patches/pkgbuild-03-forcefully-copy-docs.patch desktop-cbe-mini-1.8.0/patches/pkgbuild-03-forcefully-copy-docs.patch
+--- desktop-cbe-mini-1.8.0.orig/patches/pkgbuild-03-forcefully-copy-docs.patch	1970-01-01 01:00:00.000000000 +0100
++++ desktop-cbe-mini-1.8.0/patches/pkgbuild-03-forcefully-copy-docs.patch	2010-11-02 13:46:45.000000000 +0100
+@@ -0,0 +1,13 @@
++diff -ur pkgbuild-1.3.103.orig/pkgbuild.pl.in pkgbuild-1.3.103/pkgbuild.pl.in
++--- pkgbuild-1.3.103.orig/pkgbuild.pl.in	2010-11-02 13:39:24.000000000 +0100
+++++ pkgbuild-1.3.103/pkgbuild.pl.in	2010-11-02 13:46:09.000000000 +0100
++@@ -1172,7 +1172,7 @@
++     # %doc foo/bar/COPYING
++     my $fname_basedir = dirname ($fname);
++     mkdir_p ("./$basedir/$docdir/$fname_basedir") or fatal ("Failed to create directory $mydir/$docdir/$fname_basedir");
++-    system ("cp -p '$blddir/$bsdirname/$doc_subdir$fname' './$basedir/$docdir/$fname_basedir'");
+++    system ("cp -fp '$blddir/$bsdirname/$doc_subdir$fname' './$basedir/$docdir/$fname_basedir'");
++     if ($? != 0) {
++ 	fatal ("ERROR: failed to copy $fname to $mydir/$basedir/$docdir/$fname_basedir");
++ 	return undef;
++Only in pkgbuild-1.3.103: pkgbuild.pl.in.orig
+diff -urN desktop-cbe-mini-1.8.0.orig/pkgbuild-add-patches.patch desktop-cbe-mini-1.8.0/pkgbuild-add-patches.patch
+--- desktop-cbe-mini-1.8.0.orig/pkgbuild-add-patches.patch	1970-01-01 01:00:00.000000000 +0100
++++ desktop-cbe-mini-1.8.0/pkgbuild-add-patches.patch	2010-11-02 13:54:45.000000000 +0100
+@@ -0,0 +1,23 @@
++diff -ur pkgbuild-1.3.103.orig/pkgbuild.spec pkgbuild-1.3.103/pkgbuild.spec
++--- pkgbuild-1.3.103.orig/pkgbuild.spec	2010-07-14 12:53:27.000000000 +0200
+++++ pkgbuild-1.3.103/pkgbuild.spec	2010-11-02 13:54:32.000000000 +0100
++@@ -16,6 +16,9 @@
++ Vendor:	      OpenSolaris Community
++ Summary:      pkgbuild - rpmbuild-like tool for building Solaris packages
++ Source:       http://prdownloads.sourceforge.net/pkgbuild/pkgbuild-%{version}.tar.bz2
+++Patch1:       pkgbuild-01-add-unknown-dependencies.patch
+++Patch2:       pkgbuild-02-nopkg.patch
+++Patch3:       pkgbuild-03-forcefully-copy-docs.patch
++ BuildRoot:    %{_tmppath}/%{name}-%{version}-build
++ 
++ %if %_is_pkgbuild
++@@ -45,6 +48,9 @@
++ 
++ %prep
++ %setup -q -n pkgbuild-%version
+++%patch1 -p1
+++%patch2 -p1
+++%patch3 -p1
++ 
++ %build
++ ./configure --prefix=%{pkgbuild_prefix}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/jds.sh	Wed Jan 26 16:53:37 2011 +0100
@@ -0,0 +1,146 @@
+# install additional dependencies
+# FIMXE cbe-mini installs the following: developer/build/ant developer/macro/gnu-m4 developer/build/autoconf developer/build/libtool developer/build/automake-19 developer/build/automake-110 developer/parser/bison file/gnu-coreutils text/gnu-diffutils developer/lexer/flex text/gnu-gettext developer/build/gnu-make developer/versioning/subversion developer/build/cmake text/gnu-patch system/header web/wget archiver/gnu-tar system/xopen/xcu4 developer/build/make x11/header x11/header/header-xorg developer/object-file system/library/math/header-math
+ADDITIONAL_PKGS='
+wget
+xml-parser
+gnu-sed
+object-file
+header-nss
+header-nspr
+libdbus
+libdbus-glib
+gnome-vfs
+bison
+flex
+net-snmp
+libxslt
+terminfo
+docbook
+astdev
+runtime/perl-510
+runtime/perl-510/extra
+runtime/python-24
+package/pkg
+system/extended-system-utilities
+text/locale
+library/security/trousers
+system/management/product-registry
+print/cups
+system/library/install
+developer/swig
+system/boot/wanboot/internal
+system/library/install/libinstzones
+system/library/libdiskmgt/header-libdiskmgt
+system/zones/internal
+text/gnu-gettext
+library/gnome/gnome-libs
+system/library/storage/ima/header-ima
+developer/gnome/gettext
+developer/gnome/gnome-doc-utils
+text/gnu-patch
+developer/versioning/mercurial
+gnome/accessibility/gnome-a11y-libs
+x11/header
+developer/gnome/gettext
+library/python-2/setuptools-26
+system/zones/internal
+developer/gnome/gnome-doc-utils
+gnu-coreutils
+ant
+compatibility/ucb
+texinfo
+gnu-findutils
+developer/java/junit
+developer/build/libtool
+x11/library/mesa
+x11/optional-clients
+library/sdl
+library/ilmbase
+runtime/erlang
+library/motif
+system/xopen/xcu4
+library/libevent
+developer/build/automake-19
+library/glib1
+web/java-servlet/tomcat
+text/gawk
+database/mysql-51/library
+runtime/ocaml
+text/gnu-diffutils
+library/slang
+developer/build/cmake
+database/postgres-82/developer
+library/guile
+library/desktop/gtksourceview
+library/desktop/gtkspell
+runtime/ocaml/lablgtk
+database/postgres/pgtcl
+library/graphics/wxwidgets
+text/groff
+print/filter/ghostscript
+desktop/pdf-viewer/evince
+compress/gzip
+compress/unzip
+archiver/gnu-tar
+developer/build/autoconf
+developer/build/automake-110
+developer/build/gnu-make
+library/c++/sigcpp
+driver/network/bpf
+developer/versioning/subversion
+service/opengl/ogl-select
+system/library/usb/libusb
+system/header/header-ugen
+system/header/header-audio
+library/tooltalk
+system/library/libpcap
+text/doctools
+text/gnu-grep
+runtime/lua
+web/server/apache-22
+developer/debug/mdb
+web/browser/lynx
+system/header/header-usb
+developer/versioning/cvs
+image/imagemagick
+text/auto_ef
+library/medialib
+system/library/processor
+system/library/platform
+SUNWcsd
+media/cdrtools
+compress/zip
+developer/gperf
+crypto/gnupg
+system/library/iconv/unicode
+library/idnkit/header-idnkit
+library/idnkit
+system/input-method/iiim
+library/graphics/libmng
+system/library/libvirt
+library/python-2/libxml2-24
+system/manual
+database/mysql-51
+system/file-system/ntfsprogs
+library/openldap
+library/print/open-printing
+system/storage/parted
+print/lp/print-client-commands
+print/lp
+library/pth
+library/python-2/pycups
+image/scanner/xsane/sane-backends
+print/lp/compatibility/sunos4
+service/network/smtp/sendmail
+network/ssh/ssh-key
+system/trusted
+driver/usb/ugen
+system/library/iconv/utf-8
+web/urlgrabber
+system/virtinst
+x11/x11-config
+'
+pkg install $ADDITIONAL_PKGS
+
+# prepare SGML catalogs for offline usage
+/usr/share/sgml/docbook/docbook-catalog-install.sh
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/oiac.sh	Wed Jan 26 16:53:37 2011 +0100
@@ -0,0 +1,16 @@
+# install additional dependencies
+ADDITIONAL_PKGS='
+'
+pkg install $ADDITIONAL_PKGS
+
+# set up default IPS repository
+pkgrepo create /export/repos/repo_local
+pkgrepo -s /export/repos/repo_local set publisher/prefix=local
+svccfg -s pkg/server setprop pkg/inst_root=/export/repos/repo_local
+svcadm enable pkg/server
+sleep 30 # allow server to come up
+pkg set-publisher -O http://localhost:80/ local
+
+# prepare SGML catalogs for offline usage
+/usr/share/sgml/docbook/docbook-catalog-install.sh
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/sfe-unsupported.sh	Wed Jan 26 16:53:37 2011 +0100
@@ -0,0 +1,18 @@
+# install additional dependencies
+ADDITIONAL_PKGS='
+developer/versioning/subversion
+service/postrun
+'
+pkg install $ADDITIONAL_PKGS
+
+# set up default IPS repository
+pkgrepo create /export/repos/repo_local
+pkgrepo -s /export/repos/repo_local set publisher/prefix=local
+svccfg -s pkg/server setprop pkg/inst_root=/export/repos/repo_local
+svcadm enable pkg/server
+sleep 30 # allow server to come up
+pkg set-publisher -O http://localhost:80/ local
+
+# prepare SGML catalogs for offline usage
+/usr/share/sgml/docbook/docbook-catalog-install.sh
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/setup-buildenv.sh	Wed Jan 26 16:53:37 2011 +0100
@@ -0,0 +1,116 @@
+#!/sbin/sh
+
+set -e
+
+export LC_ALL=C
+export PATH=/usr/xpg6/bin:/usr/xpg4/bin:/usr/bin:/sbin:/usr/sbin
+
+builduser="abuild"
+CBE_SOURCE="desktop-cbe-mini-1.8.0.tar.bz2"
+SS_SOURCE="sunstudio12u1-patched-ii-2010Feb-sol-x86.tar.gz"
+TMPDIR="${TMPDIR:-/var/tmp}"
+PKGS='system/xopen/xcu4
+text/gnu-patch
+text/gnu-grep
+archiver/gnu-tar
+developer/gcc-3
+developer/build/make
+system/header
+package/svr4'
+os_version="$(uname -v)"
+build_number="${os_version#oi_}"
+basedir="${PWD}"
+sourcedir="${basedir}/sources"
+patchdir="${basedir}/patches"
+
+error ()
+{
+    printf "error: %s\n" "$@" >&2
+    exit 1
+}
+
+usage ()
+{
+    printf "usage: ${0##*/} [-b build_number] [-u username]" >&2
+}
+
+while getopts b:u: opt
+do
+    case "$opt" in
+        b)      build_number="${OPTARG}"
+                ;;
+        u)      builduser="${OPTARG}"
+                ;;
+        \?)     usage
+                exit 2
+                ;;
+    esac
+done
+shift $((OPTIND - 1))
+
+if [ $# -gt 1 ]; then
+    printf "usage: ${0##*/} [plugin]\n" >&2
+elif [ $# -eq 1 ]; then
+    plugin="${basedir}/plugins/$1.sh"
+    [ -f "${plugin}" ] || error "${plugin} does not exist"
+fi
+[ -f "${sourcedir}/${CBE_SOURCE}" ] || error "missing CBE"
+[ -f "${sourcedir}/${SS_SOURCE}" ] || error "missing SunStudio"
+
+# install prerequisites
+pkg install ${PKGS}
+
+# create build user
+if ! getent passwd ${builduser} >/dev/null; then
+    mkdir -p /export/home || :
+    useradd -b /export/home -m -s /usr/bin/bash ${builduser}
+fi
+if ! profiles | grep -q '^Primary Administrator$'; then
+    usermod -P "Primary Administrator" ${builduser}
+fi
+
+# install SunStudio
+(
+    cd /opt
+    tar xf "${sourcedir}/${SS_SOURCE}"
+    ln -s sunstudio12.1 SUNWspro
+)
+
+# install CBE
+(
+    cd "${TMPDIR}"
+    tar xf "${sourcedir}/${CBE_SOURCE}"
+    cd ${CBE_SOURCE%.tar.bz2}
+    for patchfile in ${patchdir}/*; do
+        patch -p1 < ${patchfile}
+    done
+)
+pkgrepo create ${TMPDIR}/repo_cbe
+pkgrepo -s ${TMPDIR}/repo_cbe set publisher/prefix=cbe
+svccfg -s pkg/server setprop pkg/inst_root=${TMPDIR}/repo_cbe
+svccfg -s pkg/server setprop pkg/readonly=false
+svcadm enable pkg/server
+sleep 60 # allow server to come up
+pkg set-publisher -O http://localhost:80/ cbe
+pkg set-publisher --non-sticky -P cbe
+su $builduser -c "mkdir ${TMPDIR}/packages_cbe && cd ${TMPDIR}/packages_cbe && mkdir BUILD PKGMAPS PKGS SOURCES SPECS SPKGS"
+su $builduser -c "[ -f /export/home/${builduser}/.pkgbuildmacros ] && cp /export/home/${builduser}/.pkgbuildmacros /export/home/${builduser}/.pkgbuildmacros.bak.$$ || :"
+su $builduser -c "printf '%%_topdir    %s\n' ${TMPDIR}/packages_cbe >/export/home/${builduser}/.pkgbuildmacros"
+su $builduser -c "cd ${TMPDIR}/${CBE_SOURCE%.tar.bz2} && ./mini-cbe-install -n -c /opt/sunstudio12.1/bin/cc"
+su $builduser -c "[ -f /export/home/${builduser}/.pkgbuildmacros.bak.$$ ] && mv /export/home/${builduser}/.pkgbuildmacros.bak.$$ /export/home/${builduser}/.pkgbuildmacros || :"
+pkg set-publisher -P openindiana.org
+pkg unset-publisher cbe
+svcadm disable pkg/server
+mkdir -p /opt/jdsbld/share
+(
+    cd /opt/jdsbld
+    ln -s ../dtbld/bin .
+    cd ./share
+    ln -s ../../usr/share/aclocal .
+)
+# create log and packages directory
+su $builduser -c "mkdir /export/home/${builduser}/logs"
+su $builduser -c "mkdir /export/home/${builduser}/packages/; cd /export/home/${builduser}/packages/; mkdir BUILD PKGMAPS PKGS SPECS SPKGS SOURCES"
+
+[ -n "${plugin}" ] && . "${plugin}"
+