--- /dev/null
+Automated VM Builder
+====================
+:toc:
+:numbered:
+
+This automated VM Builder script set is intended to allow someone who does not
+have experience setting up Evergreen get one or more "test" virtual machines
+running. The initial setup should be done by someone familiar with linux, or
+more specifically Ubuntu, after which setting up new test virtual machines is
+hopefully as simple as running a command and waiting for things to finish.
+
+Host Machine Requirements
+-------------------------
+
+This script setup currently expects to be running on an Ubuntu system and uses
+the ubuntu-vm-builder package. In addition, the host machine will need to
+support hardware virtualization.
+
+The latter can be checked by running kvm-ok, which is provided by cpu-checker.
+
+[source,bash]
+--------------------------------------------------------------------------------
+sudo apt-get install cpu-checker
+kvm-ok
+--------------------------------------------------------------------------------
+
+Depending on your system configuration you may need to change bios settings to
+enable hardware virtualization before kvm-ok will return success.
+
+Required Packages
+~~~~~~~~~~~~~~~~~
+
+In order to build virtual machines you will need several packages. The command
+below should install the packages you need.
+
+[source,bash]
+--------------------------------------------------------------------------------
+sudo apt-get install ubuntu-vm-builder kvm libvirt-bin git wget
+--------------------------------------------------------------------------------
+
+After installing those packages you should add the user you wish to run the
+scripts as to the libvirtd group as well, giving them the ability to control
+virtual machines. This is accomplished with the following command.
+
+[source,bash]
+--------------------------------------------------------------------------------
+sudo adduser $USER libvirtd
+--------------------------------------------------------------------------------
+
+Bridge Configuration
+~~~~~~~~~~~~~~~~~~~~
+
+In order to get the virtual machine(s) onto the network you will need to setup
+at least one bridge. To set one up manually you should edit the
+/etc/network/interfaces file.
+
+It is recommended that when using bridges you disable the original interface(s)
+by commenting out the "auto eth#" line(s). You would then add a new bridge that
+is configured similarly to the original interface:
+
+[source]
+--------------------------------------------------------------------------------
+# Static Configuration
+iface br0 inet static
+ address 10.0.0.2
+ netmask 255.255.255.0
+ network 10.0.0.0
+ broadcast 10.0.0.255
+ gateway 10.0.0.1
+ dns-nameservers 10.0.0.1 10.0.0.254
+ dns-search example.com
+ bridge_ports eth0
+ bridge_fd 9
+ bridge_hello 2
+ bridge_maxage 12
+ bridge_stp off
+
+# DHCP configuration
+iface br1 inet dhcp
+ bridge_ports eth1
+ bridge_fd 9
+ bridge_hello 2
+ bridge_maxage 12
+ bridge_stp off
+--------------------------------------------------------------------------------
+
+I recommend naming your bridge interfaces similarly to the network interface you
+are using for the bridge. That is, eth# becomes br# so that:
+ * eth0 = br0
+ * eth1 = br1
+ * eth4 = br4
+
+If you are configured to support multiple VLANs on your interfaces then follow
+the overall pattern:
+ * eth0.5 = br0.5
+ * eth1.120 = br1.120
+ * eth4.30 = br4.30
+
+This overall bridge naming scheme helps to ensure you know exactly where your
+virtual machines are being attached to the network.
+
+Optional: Local caching
+~~~~~~~~~~~~~~~~~~~~~~~
+
+Locally caching install packages may be of benefit for repeated VM building. The
+two areas that benefit from this the most are apt and CPAN.
+
+For CPAN I find a local mirror works well and how/where/if you set one up is up
+to you. Instructions can be obtained from CPAN here:
+http://www.cpan.org/misc/how-to-mirror.html
+
+For apt I find that apt-cacher or variants thereof work well and don't require
+the storage space of a full apt mirror.
+
+Configuration
+-------------
+
+Base config
+~~~~~~~~~~~
+
+For the base configuration you should copy "config.example" to "config" and then
+make your changes, if any. Reasonable defaults have been provided for all
+options though you may want to pay attention to the following.
+
+Repo Locations
+++++++++++++++
+
+The GIT Repo locations can be configured to allow for local or alternate mirrors
+to be used instead of the official ones. Note that in most cases only the
+working repos are actually loaded.
+
+EGVMUSEDOMAIN
++++++++++++++
+
+If your vmname.domain values resolve then it is recommended that you turn this
+setting on. By doing so the staff clients built will use the domain for the
+initial hostname and automatic updates.
+
+EGVMSMARTHOST
++++++++++++++
+
+If you wish to test email delivery you will want to set this to an appropriate
+mail server. With it set all email generated by the server will be delivered to
+the server in question. Information on capturing all mail from a given host when
+using postfix is provided in a later section.
+
+Without this option no mail delivery will be supported.
+
+EGVMAPTMIRROR and EGVMCPANURLLIST
++++++++++++++++++++++++++++++++++
+
+These options control whether or not local mirrors or cache servers are used for
+apt and CPAN. EGVMAPTMIRROR can also be used to point at an apt cacher or proxy.
+
+Individual VM configuration
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+In the vmbuilder folder you should find an example configuration file. Using
+that file as a base you will need to create one or more hostname.conf files.
+
+Each hostname.conf file defines a different virtual machine that can be built.
+You will specify the network information, password, memory, cpu count, drive and
+swap sizes, and suite information here at a minimum.
+
+SSL Certificates
+~~~~~~~~~~~~~~~~
+
+In addition to everything else you will need to provide SSL certificates. For
+ease of testing I recommend using a single domain for all the virtual machines
+and obtaining a single wildcard certificate for the set.
+
+The crt file, key file, and if needed chain (or bundle) file should be placed in
+the files/ssl folder to be automatically copied into place in the individual
+virtual machines. If a chain.crt file is present the virtual machines will
+automatically add the proper configuration lines to use it.
+
+Building VMs
+------------
+
+Once everything is configured you will need to build the VMs. At this stage it
+may be beneficial to either ensure you do not need a password to run "sudo" or
+that you have pre-entered the password by running "sudo -v".
+
+The command for setting up a virtual machine is setupvm and the only required
+argument is the virtual machine name. If vmbuilder/$VMNAME.conf does not exist
+then the script will report as such.
+
+[source,bash]
+--------------------------------------------------------------------------------
+./setupvm testsystem
+--------------------------------------------------------------------------------
+
+You can also specify branches to load in the Evergreen, OpenSRF, and (if enabled
+in config) SIPServer repositories. These branches are generally expected to be
+located in the community "working" repositories. The syntax is project:branch.
+
+[source,bash]
+--------------------------------------------------------------------------------
+./setupvm testsystem Evergreen:working/user/somedude/lpsomething
+--------------------------------------------------------------------------------
+
+You can specify as many branches as you want. Note, however, that if any of the
+branches do not merge cleanly and automatically then the virtual machine will
+fail to build.
+
+In the event you wish to test a branch against something other than master you
+can specify that with repo:BASE:branch, which will check out the branch from the
+main git repository. This should be done *before* any merge branches are
+specified as the actions are taken in order.
+
+[source,bash]
+--------------------------------------------------------------------------------
+./setupvm testsystem Evergreen:BASE:rel_2_7 Evergreen:working/user/somedude/lpsomething_2_7
+--------------------------------------------------------------------------------
+
+Capturing email with Postfix
+----------------------------
+
+It is possible to configure a postfix install to capture all mail from a given
+host, or set of hosts, into a given account. By doing this you can ensure that
+any email generated by a test system can be examined without worry about the
+apparent destination. This is generally a useful configuration for training,
+development, and test systems.
+
+This script's side of this is configured with the EGVMSMARTHOST option in the
+config file. The specified smarthost, however, will need to be configured to
+capture email. This is easily done with a check_client_access configuration
+utilizing the REDIRECT parameter. For example, if you have /etc/postfix/access
+containing the following:
+
+[source]
+--------------------------------------------------------------------------------
+10.0.0.10 REDIRECT testserver0@domain.ext
+10.0.0.11 REDIRECT testserver1@domain.ext
+--------------------------------------------------------------------------------
+
+You will need to compile that into a hash file:
+
+[source,bash]
+--------------------------------------------------------------------------------
+sudo postalias hash:/etc/postfix/access
+--------------------------------------------------------------------------------
+
+And then you can add to, for example, smtpd_recipient_restrictions to check the
+newly created hash:
+
+[source]
+--------------------------------------------------------------------------------
+check_client_access hash:/etc/postfix/access,
+--------------------------------------------------------------------------------
--- /dev/null
+# Configuration of various things
+
+################################################################################
+# Required settings #
+# #
+# While reasonable defaults have generally been provided these settings all #
+# need to be uncommented with valid values. #
+################################################################################
+
+# Repo locations, in case you want to use local mirrors or alternate protocols
+EGVMEVERGREENMAIN=git://git.evergreen-ils.org/Evergreen
+EGVMEVERGREENWORKING=git://git.evergreen-ils.org/working/Evergreen
+EGVMOPENSRFMAIN=git://git.evergreen-ils.org/OpenSRF
+EGVMOPENSRFWORKING=git://git.evergreen-ils.org/working/OpenSRF
+# These two are only required when EGVMUSESIPSERVER is 1 below
+EGVMSIPSERVERMAIN=git://git.evergreen-ils.org/SIPServer
+EGVMSIPSERVERWORKING=git://git.evergreen-ils.org/working/SIPServer
+
+# Postgresql Password
+# Not that having it configurable matters overly much, but we need one
+EGVMPGPASS=neergreve
+
+# Evergreen Admin Username and Password
+EGVMEGUSER=admin
+EGVMEGPASS=evergreen123
+
+# Dojo URL
+# Defaulting to the copy we use for make_release
+EGVMDOJOURL=http://evergreen-ils.org/downloads/dojo.tgz
+
+################################################################################
+# Optional Settings #
+# #
+# These settings are generally ignored unless set. If you don't want to use #
+# the features they are for then you don't have to set them. #
+################################################################################
+
+# Include Authorized Keys File
+# If configured this is the path to an authorized keys file to be installed for
+# the opensrf user.
+# Relative to install directory:
+#EGVMAUTHORIZEDKEYS=files/authorized_keys
+# Or grab a specific user's (say the user you plan on running this as):
+#EGVMAUTHORIZEDKEYS=/home/someone/.ssh/authorized_keys
+
+# Use domain for initial host and update url
+# If set to 1 the hostname (vmname) and domain are used to build a host for the
+# initial host and update url options for the staff client
+# You should ensure that your hostname/domain combinations resolve correctly
+# before turning this on
+EGVMUSEDOMAIN=0
+
+# Adjust Windows Installer Name
+# If set to 1 the Windows Installer Name is changed to say "VMNAME.DOMAIN"
+# instead of the default "Master" (or whatever else a loaded branch changed it
+# to, if any have)
+EGVMCHANGEINSTALLERNAME=1
+
+# Adjust Application Name
+# If set to 1 add ".VMNAME.DOMAIN" to the XULRunner Application Name so that
+# multiple clients can co-exist at the same time. This will also guarantee that
+# no two test server clients use the same preferences file by default.
+EGVMCHANGEAPPLICATIONNAME=1
+
+# Use SIPServer?
+# If this is 1 the SIPServer repo values above are required
+# Otherwise we don't even load the SIPServer repo
+EGVMUSESIPSERVER=0
+
+# Smarthost - If defined, install Postfix with this as a smarthost
+# If not defined we don't install Postfix on VMs
+#EGVMSMARTHOST=example.com
+
+# Apt Mirror - If defined use this as the Apt mirror
+#EGVMAPTMIRROR=http://archive.ubuntu.com/ubuntu
+# For apt-cacher or apt-proxy - Replace ?.?.?.? with appropriate IP or hostname
+#EGVMAPTMIRROR=http://?.?.?.?:3142/archive.ubuntu.com/ubuntu
+
+# CPAN URL List
+# You can specify multiple mirrors, space delimited
+# In theory CPAN FirstTime autoconfig should find something suitable
+# If not this may be required instead
+#EGVMCPANURLLIST="http://first.host/CPAN http://second.host/CPAN"
+
--- /dev/null
+% This is a minimalist ejabberd configuration file
+% Most things not needed for opensrf, have been removed.
+{acl, admin, {user, "", "localhost"}}.
+{hosts, ["localhost","public.localhost","private.localhost"]}.
+{loglevel, 4}.
+{listen,
+ [
+ {5222, ejabberd_c2s, [
+ {access, c2s},
+ {shaper, c2s_shaper},
+ {max_stanza_size, 2000000},
+ starttls, {certfile, "/etc/ejabberd/ejabberd.pem"}
+ ]},
+ {5269, ejabberd_s2s_in, [
+ {shaper, s2s_shaper},
+ {max_stanza_size, 2000000}
+ ]},
+ {5280, ejabberd_http, [
+ http_bind,
+ http_poll,
+ web_admin
+ ]}
+ ]}.
+{max_fsm_queue, 1000}.
+{s2s_use_starttls, true}.
+{s2s_certfile, "/etc/ejabberd/ejabberd.pem"}.
+{auth_method, internal}.
+{shaper, normal, {maxrate, 500000}}.
+{shaper, fast, {maxrate, 500000}}.
+{acl, local, {user_regexp, ""}}.
+{access, max_user_sessions, [{10000, all}]}.
+{access, max_user_offline_messages, [{5000, admin}, {100, all}]}.
+{access, local, [{allow, local}]}.
+{access, c2s, [{deny, blocked},
+ {allow, all}]}.
+{access, c2s_shaper, [{none, admin},
+ {normal, all}]}.
+{access, s2s_shaper, [{fast, all}]}.
+{access, announce, [{allow, admin}]}.
+{access, configure, [{allow, admin}]}.
+{access, register, [{deny, all}]}.
+{access, pubsub_createnode, [{allow, all}]}.
+{language, "en"}.
+{modules,
+ [
+ {mod_adhoc, []},
+ {mod_announce, [{access, announce}]}, % requires mod_adhoc
+ {mod_caps, []},
+ {mod_configure,[]}, % requires mod_adhoc
+ {mod_admin_extra, []},
+ {mod_disco, []},
+ {mod_version, []}
+ ]}.
+
--- /dev/null
+SSL Certificate files should be placed in here
+
+server.crt - The main certificate file
+server.key - The private key for the certificate file
+chain.crt - The certificate chain, if needed (config will be updated to include it if necessary)
--- /dev/null
+#!/bin/bash
+
+# First up, build/install Evergreen
+# Which should generally cover everything, actually
+sudo -i -u opensrf /bin/bash /home/opensrf/buildeg.sh 2>&1 > /home/opensrf/buildeg.txt
--- /dev/null
+#!/bin/bash
+
+cd $EGVMSCRIPTPATH
+source $EGVMSCRIPTPATH/config
+
+# First up, copy various things we want/need
+
+# Pre-made git repos
+cp -r $EGVMSCRIPTPATH/working/$EGVMNAME/* $1/home/opensrf/
+
+# Ejabberd Config
+cp $EGVMSCRIPTPATH/files/configuration/ejabberd.cfg $1/etc/ejabberd/ejabberd.cfg
+chroot $1 chown root:ejabberd /etc/ejabberd/ejabberd.cfg
+chmod o-rwx,g+r $1/etc/ejabberd/ejabberd.cfg
+sed -i -e 's/#SMP=disable/SMP=auto/' $1/etc/default/ejabberd
+
+# SSL Certificate
+mkdir -p $1/etc/apache2
+cp -R $EGVMSCRIPTPATH/files/ssl $1/etc/apache2/
+chown -R root:root $1/etc/apache2/ssl
+chmod -R go-rwx $1/etc/apache2/ssl
+
+# hosts config for ejabberd
+cat >> $1/etc/hosts <<END_HOSTS
+127.0.0.1 private.localhost public.localhost
+END_HOSTS
+
+# bashrc additions - Note .bashrc doesn't start with #!/bin/bash by default
+# we want this at the *top* of the file so that it always applies and not just for interactive
+# But we have to do a little bit of a dance due to adding to the top of the file
+cat - $1/home/opensrf/.bashrc > $1/home/opensrf/.bashrc.temp <<EOF_BASHRC
+# Evergreen path addition
+export PATH=\$PATH:/openils/bin
+
+EOF_BASHRC
+rm $1/home/opensrf/.bashrc
+mv $1/home/opensrf/.bashrc.temp $1/home/opensrf/.bashrc
+
+# Authorized SSH keys (if any)
+if [ "$EGVMAUTHORIZEDKEYS" != "" -a -f "$EGVMAUTHORIZEDKEYS" ]; then
+ mkdir -p $1/home/opensrf/.ssh
+ cp "$EGVMAUTHORIZEDKEYS" $1/home/opensrf/.ssh/authorized_keys
+ chmod -R go-rwx,u+rw $1/home/opensrf/.ssh
+fi
+
+# screen defaults to having a startup message, disable it
+cat > $1/home/opensrf/.screensrc <<EOF_SCREENRC
+startup_message off
+EOF_SCREENRC
+
+# Allow opensrf to sudo sans password
+cat >> $1/etc/sudoers <<EOF_SUDOERS
+
+# opensrf needs no passwords!
+opensrf ALL=(ALL) NOPASSWD: ALL
+EOF_SUDOERS
+
+# Check if we should be using the domain
+if [ "$EGVMUSEDOMAIN" = "1" ]; then
+ EGVMCONFIGHOST="--with-initialhost=$EGVMNAME.$EGVMDOMAIN --with-updateshost=$EGVMNAME.$EGVMDOMAIN"
+fi
+
+# Write script for building evergreen
+cat - > $1/home/opensrf/buildeg.sh <<EOF_BUILDEG
+#!/bin/bash
+
+echo "Starting at: \$(date)"
+
+cd /home/opensrf
+
+# First up, configure CPAN
+sudo perl <<CPANCONFIG
+use strict;
+use Config;
+use CPAN::FirstTime;
+
+\\\$ENV{PERL_MM_USE_DEFAULT}=1;
+\\\$ENV{PERL_MM_NONINTERACTIVE}=1;
+\\\$ENV{AUTOMATED_TESTING}=1;
+
+\\\$CPAN::Config->{urllist}
+ = [qw($EGVMCPANURLLIST)] if ("$EGVMCPANURLLIST");
+\\\$CPAN::Config->{prerequisites_policy} = 'follow';
+CPAN::FirstTime::init(undef, {auto_config => 1});
+
+exit 0;
+CPANCONFIG
+
+sudo make -f OpenSRF/src/extras/Makefile.install ubuntu-$EGVMSUITE
+sudo make -f Evergreen/Open-ILS/src/extras/Makefile.install ubuntu-$EGVMSUITE postgres-server-ubuntu-$EGVMSUITE
+
+cd /home/opensrf/OpenSRF
+autoreconf -i
+./configure --prefix=/openils --sysconfdir=/openils/conf
+make
+sudo make install
+
+export PATH=\$PATH:/openils/bin
+
+cd /home/opensrf/Evergreen
+autoreconf -i
+./configure --prefix=/openils --sysconfdir=/openils/conf $EGVMCONFIGHOST
+make
+sudo make STAFF_CLIENT_VERSION=$(date "+%Y.%m$EGVMNAME.%d.%H%M%S") install
+sudo chown -R opensrf:opensrf /home/opensrf /openils
+cd /openils/var/web/xul
+ln -sf */server
+cd /openils/conf
+for file in *.example; do [ -f \${file%%.example} ] || cp \$file \${file%%.example}; done
+rm /home/opensrf/.srfsh.xml
+mv srfsh.xml /home/opensrf/.srfsh.xml
+cd /home/opensrf/Evergreen/Open-ILS/xul/staff_client
+make rigbeta rebuild permachine updates-client
+
+sudo /bin/bash -s <<EOF_RUNASROOT
+service apache2 stop
+chown -R opensrf /var/lock/apache2
+cd /home/opensrf/Evergreen/Open-ILS/examples
+if [ "\\\$(/usr/sbin/apache2 -v | grep Apache/2 | cut -d. -f2)" -ge 4 ]; then
+ cp apache_24/eg_24.conf /etc/apache2/sites-available/evergreen.conf
+ cp apache_24/eg_vhost_24.conf /etc/apache2/eg_vhost.conf
+ a2dismod mpm_event
+ a2enmod mpm_prefork
+ a2enmod perl
+else
+ cp apache/eg.conf /etc/apache2/sites-available/evergreen
+ cp apache/eg_vhost.conf /etc/apache2/eg_vhost.conf
+fi
+cp apache/eg_startup /etc/apache2/eg_startup
+sed -i -e 's/APACHE_RUN_USER=www-data/APACHE_RUN_USER=opensrf/' /etc/apache2/envvars
+sed -i -e 's/StartServers 5/StartServers 20/' -e 's/MaxRequestsPerChild 0/MaxRequestsPerChild 10000/' /etc/apache2/apache2.conf
+if [ -f '/etc/apache2/ssl/chain.crt' ]; then
+ sed -i -e 's:SSLCertificateKeyFile ssl/server.key:SSLCertificateKeyFile ssl/server.key\\n SSLCertificateChainFile ssl/chain.crt:' /etc/apache2/sites-available/evergreen
+fi
+a2dissite 000-default
+a2ensite evergreen
+
+echo /opensrf/lib > /etc/ld.so.conf.d/opensrf.conf
+ldconfig
+
+# We need to set up ejabberd users
+# And "password" is used here to be lazy
+ejabberdctl register router private.localhost password
+ejabberdctl register router public.localhost password
+ejabberdctl register opensrf private.localhost password
+ejabberdctl register opensrf public.localhost password
+EOF_RUNASROOT
+
+# We need to do some postgresql work, and build the evergreen DB
+sudo -u postgres psql -c "CREATE ROLE evergreen PASSWORD '$EGVMPGPASS' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;"
+cd /home/opensrf/Evergreen
+perl Open-ILS/src/support-scripts/eg_db_config --update-config \\
+--service all --create-database --create-schema --create-offline \\
+--user evergreen --password $EGVMPGPASS --hostname localhost --port 5432 \\
+--database evergreen --admin-user $EGVMEGUSER --admin-pass $EGVMEGPASS --load-all-sample
+
+# Start Evergreen up!
+osrf_control --localhost --start-all
+/openils/bin/autogen.sh
+sudo service apache2 restart
+
+# Setup crontab
+cat - Open-ILS/examples/crontab.example > /home/opensrf/crontab <<EOF_CRONTAB
+# Fix shell as master crontab example doesn't ensure we are using bash
+SHELL=/bin/bash
+
+EOF_CRONTAB
+crontab /home/opensrf/crontab
+
+echo "Complete at: \$(date)"
+EOF_BUILDEG
+chroot $1 chown opensrf:opensrf /home/opensrf/buildeg.sh
+chmod u+x $1/home/opensrf/buildeg.sh
+
+if [ "$EGVMSMARTHOST" != "" ]; then
+cat - >> $1/home/opensrf/buildeg.sh <<EOF_POSTFIX
+
+debconf-set-selections <<POSTFIX
+postfix postfix/main_mailer_type select Satellite system
+postfix postfix/relayhost string $EGVMSMARTHOST
+postfix postfix/mailname string ${EGVMNAME}.${EGVMDOMAIN}
+POSTFIX
+apt-get install postfix
+EOF_POSTFIX
+fi
+
+chroot $1 chown -R opensrf:opensrf /home/opensrf
+exit 0
--- /dev/null
+#!/bin/bash
+
+VMHOST=${1:-mlnc1}
+
+cd /data/vmbuild
+virsh destroy $VMHOST
+virsh undefine $VMHOST
+sudo rm -rf virtual_machines/$VMHOST
+sudo vmbuilder kvm ubuntu --hostname=$VMHOST -c vmbuilder/$VMHOST.conf -d virtual_machines/$VMHOST --part=vmbuild/partition.conf --user=opensrf --mirror=http://archive.ubuntu.com/ubuntu
+virsh start $VMHOST
+
+ssh-keygen -f "/home/masslnc/.ssh/known_hosts" -R $VMHOST > /dev/null 2>&1
+ssh-keygen -f "/home/masslnc/.ssh/known_hosts" -R $VMHOST.masslnc.org > /dev/null 2>&1
--- /dev/null
+#!/bin/bash
+
+# Current script dir
+export EGVMSCRIPTPATH=$( cd "$(dirname "$0")" ; pwd -P)
+# Do everything in our script path, regardless of where we were called from
+cd $EGVMSCRIPTPATH
+
+# Check if configured
+if [ ! -f "config" ]; then
+ echo "Please create configuration file"
+ exit -1
+fi
+
+# Pull in settings
+source config
+
+# Check if we have all required configuration settings
+EGVMMISSINGCONFIG=
+if [ "$EGVMEVERGREENMAIN" = "" ]; then
+ EGVMMISSINGCONFIG="EGVMEVERGREENMAIN $EGVMMISSINGCONFIG"
+fi
+if [ "$EGVMEVERGREENWORKING" = "" ]; then
+ EGVMMISSINGCONFIG="EGVMEVERGREENWORKING $EGVMMISSINGCONFIG"
+fi
+if [ "$EGVMOPENSRFMAIN" = "" ]; then
+ EGVMMISSINGCONFIG="EGVMOPENSRFMAIN $EGVMMISSINGCONFIG"
+fi
+if [ "$EGVMOPENSRFWORKING" = "" ]; then
+ EGVMMISSINGCONFIG="EGVMOPENSRFWORKING $EGVMMISSINGCONFIG"
+fi
+if [ "$EGVMMLNCMAIN" = "" ]; then
+ EGVMMISSINGCONFIG="EGVMMLNCMAIN $EGVMMISSINGCONFIG"
+fi
+if [ "$EGVMPGPASS" = "" ]; then
+ EGVMMISSINGCONFIG="EGVMPGPASS $EGVMMISSINGCONFIG"
+fi
+if [ "$EGVMEGUSER" = "" ]; then
+ EGVMMISSINGCONFIG="EGVMEGUSER $EGVMMISSINGCONFIG"
+fi
+if [ "$EGVMEGPASS" = "" ]; then
+ EGVMMISSINGCONFIG="EGVEPGPASS $EGVMMISSINGCONFIG"
+fi
+if [ "$EGVMDOJOURL" = "" ]; then
+ EGVMMISSINGCONFIG="EGVMDOJOURL $EGVMMISSINGCONFIG"
+fi
+if [ "$EGVMUSESIPSERVER" = "1" ]; then
+ if [ "$EGVMSIPSERVERMAIN" = "" ]; then
+ EGVMMISSINGCONFIG="EGVMSIPSERVERMAIN $EGVMMISSINGCONFIG"
+ fi
+ if [ "$EGVMSIPSERVERWORKING" = "" ]; then
+ EGVMMISSINGCONFIG="EGVMSIPSERVERWORKING $EGVMMISSINGCONFIG"
+ fi
+fi
+
+if [ "$EGVMMISSINGCONFIG" != "" ]; then
+ echo "Config parameters missing: $EGVMMISSINGCONFIG"
+ exit 1
+fi
+
+# If the requested VM config doesn't exist we can't continue
+export EGVMNAME=$1
+if [ ! -f "vmbuilder/$EGVMNAME.conf" ]; then
+ echo "$(pwd)/vmbuilder/$EGVMNAME.conf does not exist, cannot continue"
+ exit -1
+fi
+
+# Remove the VM config name from our arguments list
+shift
+
+# Record the suite (precise, trusty, whatever comes later) for use in postbuild
+export EGVMSUITE=$(grep 'suite=' vmbuilder/$EGVMNAME.conf | sed 's/suite=//')
+
+# Get the domain from the config file for possible use in postbuild
+EGVMDOMAIN=$(grep '^domain=' $EGVMSCRIPTPATH/vmbuilder/$EGVMNAME.conf | sed 's/domain=//')
+
+# Turn the mirror into a command line argument if present
+if [ "$EGVMAPTMIRROR" != "" ]; then
+ EGVMAPTMIRROR="--mirror=$EGVMAPTMIRROR"
+fi
+
+# Download dojo, if needed
+if [ ! -f 'files/dojo.tgz' ]; then
+ wget $EGVMDOJOURL -O files/dojo.tgz
+fi
+
+# Remaining args (if any) should be a set of branches to merge (no args = install master)
+# To speed some things up we are going to merge first, aborting on failure
+# This export ensures that we aren't prompted for merge messages
+export GIT_MERGE_AUTOEDIT=no
+# Remove any existing working directory data to ensure things are clean
+rm -rf working/$EGVMNAME 2>/dev/null
+# Re-create the working directory data
+mkdir -p working/$EGVMNAME
+# Clone working repos into place
+git clone --origin working $EGVMEVERGREENWORKING working/$EGVMNAME/Evergreen
+git clone --origin working $EGVMOPENSRFWORKING working/$EGVMNAME/OpenSRF
+if [ "$EGVMUSESIPSERVER" = "1" ]; then
+ git clone --origin working $EGVMSIPSERVERWORKING working/$EGVMNAME/SIPServer
+fi
+# Add mainrepo remotes, but don't bother fetching (if we need them later we will fetch)
+cd working/$EGVMNAME/Evergreen
+git remote add mainrepo $EGVMEVERGREENMAIN
+# MassLNC Repo
+git remote add masslnc $EGVMMLNCMAIN
+cd ../OpenSRF
+git remote add mainrepo $EGVMOPENSRFMAIN
+if [ "$EGVMUSESIPSERVER" = "1" ]; then
+ cd ../SIPServer
+ git remote add mainrepo $EGVMSIPSERVERMAIN
+fi
+cd $EGVMSCRIPTPATH
+# MERGE!
+while (($#)); do
+ # Split the repo and branch
+ REPO=${1%%:*}
+ BRANCH=${1#*:}
+ # Ensure that the repo is valid, if not we have a bad command
+ if [ ! -d working/$EGVMNAME/$REPO ]; then
+ echo "Invalid project name for branch merge: $REPO (Request: $1)"
+ exit -1
+ fi
+ # If the branch has no : in it then these two will do nothing to the value
+ HEAD=${BRANCH%:*}
+ BRANCH=${BRANCH#*:}
+ # When BRANCH starts with BASE: then we check out what follows from the main repo
+ if [ "$BRANCH" != "$HEAD" -a "$HEAD" = "BASE" ]; then
+ # To check out from the main repo we have to add the proper remote, fetch it, then checkout
+ cd working/$EGVMNAME/$REPO && git fetch mainrepo && git checkout -b $BRANCH mainrepo/$BRANCH
+ if [ $? -ne 0 ]; then
+ echo "Base branch of $BRANCH for $REPO could not be checked out (Request: $1)"
+ exit -1
+ fi
+ echo $?
+ elif [ "$BRANCH" != "$HEAD" -a "$HEAD" = "MASSLNC" ]; then
+ # To check out from the main repo we have to add the proper remote, fetch it, then checkout
+ cd working/$EGVMNAME/$REPO && git fetch masslnc && git merge masslnc/$BRANCH
+ if [ $? -ne 0 ]; then
+ echo "MassLNC branch of $BRANCH for $REPO could not be merged (Request: $1)"
+ exit -1
+ fi
+ echo $?
+ # At this point the only extra piece allowed is BASE:, so fail if that isn't what was provided
+ elif [ "$BRANCH" != "$HEAD" ]; then
+ echo "Unknown modifier: $HEAD (Request: $1)"
+ exit -1
+ # No modifiers means merge. We already disabled attempting to edit the commit message earlier.
+ else
+ cd working/$EGVMNAME/$REPO && git merge $BRANCH
+ if [ $? -ne 0 ]; then
+ echo "Merge failure in $REPO: $BRANCH could not be merged (Request: $1)"
+ exit -1
+ fi
+ fi
+
+ # Reset our working directory and move to the next argument
+ cd $EGVMSCRIPTPATH
+ shift
+done
+
+# We now have everything merged (if we had anything to merge)
+# Lets do some additional tweaking of things before we build VM
+
+# Pre-install dojo into Evergreen
+tar xzf files/dojo.tgz -C working/$EGVMNAME/Evergreen/Open-ILS/web/js/dojo/
+
+# If we are going to, tweak the installer name
+if [ "$EGVMCHANGEINSTALLERNAME" = "1" ]; then
+ sed -i -e "s/^!define PRODUCT_TAG \"[^\"]*\"/!define PRODUCT_TAG \"$EGVMNAME.$EGVMDOMAIN\"/" \
+ working/$EGVMNAME/Evergreen/Open-ILS/xul/staff_client/windowssetup.nsi
+fi
+
+# If we are going to, tweak the application name
+if [ "$EGVMCHANGEAPPLICATIONNAME" = "1" ]; then
+ sed -i -e "s/^Name=[^ ]*/&.$EGVMNAME.$EGVMDOMAIN/" \
+ working/$EGVMNAME/Evergreen/Open-ILS/xul/staff_client/application.ini
+fi
+
+# Clean out and purge any old versions of the VM
+virsh destroy $EGVMNAME
+virsh undefine $EGVMNAME
+rm -rf virtual_machines/$EGVMNAME
+# Build the VM! This will (hopefully) set up several other things
+# Note: the env command is due to sudo removing all env vars by default
+sudo env EGVMSCRIPTPATH=$EGVMSCRIPTPATH EGVMNAME=$EGVMNAME EGVMSUITE=$EGVMSUITE EGVMDOMAIN=$EGVMDOMAIN \
+ vmbuilder kvm ubuntu --hostname=$EGVMNAME -c vmbuilder/$EGVMNAME.conf -d virtual_machines/$EGVMNAME \
+ --user=opensrf $EGVMAPTMIRROR --part=vmbuilder/partition.conf \
+ --execscript $EGVMSCRIPTPATH/scripts/postbuild.sh --firstboot $EGVMSCRIPTPATH/scripts/firstboot.sh
+
+# At this point the VM should be ready to boot!
+virsh start $EGVMNAME
+
+# And now tell whomever is running this to be patient ;)
+echo "$EGVMNAME should be starting. After boot it will complete the Evergreen install."
+echo "If you wish to monitor the Evergreen install can you SSH to it and watch the buildeg.txt file"
+echo "For example, running \"tail -f buildeg.txt\" from the opensrf user's home directory"
+echo
+echo "To get a staff client for the VM you can navigate to http://host/updates/manualupdate.html"
+if [ "$EGVMUSESIPSERVER" = "1" ]; then
+ echo
+ echo "In addition, SIPServer is located in /home/opensrf/SIPServer"
+ echo "You will need to manually configure and run it"
+ echo "While in the install directory you can do so for testing by running:"
+ echo "perl SIPServer.pm /openils/conf/oils_sip.xml"
+fi
+
+ssh-keygen -f "/home/masslnc/.ssh/known_hosts" -R $EGVMNAME > /dev/null 2>&1
+ssh-keygen -f "/home/masslnc/.ssh/known_hosts" -R $EGVMNAME.$EGVMDOMAIN > /dev/null 2>&1
--- /dev/null
+Virtual Machine images will be placed here
--- /dev/null
+Configuration files for vmbuilder go here
--- /dev/null
+root 81920
+swap 12288
--- /dev/null
+[DEFAULT]
+# Networking settings - Change as needed
+bridge=br0
+# Hostname is set by the name of the file, but domain is appended after that
+domain=example.com
+ip=?.?.?.?
+mask=255.255.255.0
+net=?.?.?.0
+bcast=?.?.?.255
+gw=?.?.?.1
+dns=?.?.?.? ?.?.?.? ...
+
+# User info - Set password as desired. We force the username to opensrf elsewhere.
+pass=evergreen
+
+# Virtual Hardware config
+mem=40960
+cpus=2
+rootsize=80G
+swapsize=12G
+
+# Other useful settings
+flavor=virtual
+timezone=America/New_York
+components=main,universe
+# Some of this (wget, make, autoconf, nsis, zip, unzip, ejabberd at least) is generally needed.
+# The rest are to make other things easier.
+# WARNING: For trusty (see suite below) you should add linux-image-generic to this list!
+addpkg=acpid, vim, openssh-server, screen, wget, ntp, aptitude, make, autoconf, git, ejabberd, nsis, zip, unzip
+
+arch=amd64
+libvirt=qemu:///system
+
+[ubuntu]
+# Set the suite to the desired test suite
+# WARNING: If setting to trusty add linux-image-generic to the addpkg list (see above)
+suite=precise
+virtio_net=1