Update version according to OSCI-856
[packages/precise/mcollective.git] / ext / osx / bldmacpkg
1 #!/bin/bash
2 MPATH="$1"
3 BETCDIR='/etc/mcollective'
4 BRUBYDIR='/Library/Ruby/Site/1.8'
5 BSBINDIR='/usr/sbin'
6 BBINDIR='/usr/bin'
7 BLIBEXECDIR='/usr/libexec/mcollective'
8 BDOCDIR='/usr/share/doc/mcollective'
9 BLAUNCHDIR='/Library/LaunchDaemons'
10 BLOGDIR='/var/log/mcollective'
11 PACKAGEMAKER='/Applications/PackageMaker.app/Contents/MacOS/PackageMaker'
12
13 if [ -z $MPATH ]; then
14   echo 'Please give the path to the MCollective source directory'
15   exit 1
16 fi
17
18 msg_stomp() {
19   echo "It is recommended to install stomp on this system using ruby gems"
20   exit 2
21 }
22
23 msg_xcode() {
24   echo 'It is required to have the latest XCode installed'
25   exit 3
26 }
27
28 # Make sure we have stomp so we can load mcollective
29 /usr/bin/ruby <<EOF || msg_stomp
30 require 'rubygems'
31 require 'stomp'
32 EOF
33
34 # Make sure we have PackageMaker installed
35 [ -x $PACKAGEMAKER ] || msg_xcode
36
37 # Get the MCollective version
38 export RUBYLIB=$RUBYLIB:$MPATH/lib
39 mcversion=$(/usr/bin/ruby <<EOF
40 require 'mcollective'
41 puts MCollective.version
42 EOF
43 )
44
45 # Make our tmp directory
46 tmpbase=`basename $0`
47 common_tmpdir=`mktemp -d /tmp/${tmpbase}-common_$mcversion.XXXX` || exit 1
48 client_tmpdir=`mktemp -d /tmp/${tmpbase}-client_$mcversion.XXXX` || exit 1
49 tmpdir=`mktemp -d /tmp/${tmpbase}_$mcversion.XXXX` || exit 1
50 pkgdir=`mktemp -d /tmp/${tmpbase}_${mcversion}_packages.XXXX` || exit 1
51
52 # Build the common environment
53 mkdir -p "$common_tmpdir/$BRUBYDIR"
54 mkdir -p "$common_tmpdir/$BLIBEXECDIR"
55 mkdir -p "$common_tmpdir/$BDOCDIR"
56 mkdir -p "$common_tmpdir/$BLOGDIR"
57
58 cp -r $MPATH/lib/mcollective     $common_tmpdir/$BRUBYDIR/
59 cp    $MPATH/lib/mcollective.rb  $common_tmpdir/$BRUBYDIR/
60 cp -r $MPATH/plugins/mcollective $common_tmpdir/$BLIBEXECDIR/
61 cp    $MPATH/COPYING             $common_tmpdir/$BDOCDIR/
62
63 # Build the server environment
64 mkdir -p "$tmpdir/$BSBINDIR"
65 mkdir -p "$tmpdir/$BETCDIR"
66 mkdir -p "$tmpdir/$BETCDIR/ssl/clients"
67 mkdir -p "$tmpdir/$BLAUNCHDIR"
68
69 cp $MPATH/bin/mcollectived    $tmpdir/$BSBINDIR/mcollectived
70 cp $MPATH/etc/facts.yaml.dist $tmpdir/$BETCDIR/facts.yaml
71 cp $MPATH/etc/server.cfg.dist $tmpdir/$BETCDIR/server.cfg
72
73 # This is needed for macs since launcd will handle daemonizing
74 perl -i -pe 's/daemonize = 1/daemonize = 0/' $tmpdir/$BETCDIR/server.cfg
75
76 # Build the client environment
77 mkdir -p "$client_tmpdir/$BETCDIR"
78 mkdir -p "$client_tmpdir/$BSBINDIR"
79
80 cp $MPATH/etc/client.cfg.dist $client_tmpdir/$BETCDIR/client.cfg
81 cp $MPATH/etc/rpc-help.erb    $client_tmpdir/$BETCDIR/
82 cp $MPATH/bin/mc-call-agent   $client_tmpdir/$BSBINDIR/
83 cp $MPATH/bin/mco             $client_tmpdir/$BSBINDIR/
84
85 #Build our launchd property list file
86 cat - > $tmpdir/$BLAUNCHDIR/org.marionette-collective.mcollective.plist <<EOF
87 <?xml version="1.0" encoding="UTF-8"?>
88 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
89 <plist version="1.0">
90 <dict>
91         <key>EnvironmentVariables</key>
92         <dict>
93                 <key>PATH</key>
94                 <string>/sbin:/usr/sbin:/bin:/usr/bin</string>
95                 <key>RUBYLIB</key>
96                 <string>/Library/Ruby/Site/1.8</string>
97         </dict>
98         <key>Label</key>
99         <string>org.marionette-collective.mcollective</string>
100         <key>OnDemand</key>
101         <false/>
102         <key>KeepAlive</key>
103         <true/>
104         <key>ProgramArguments</key>
105         <array>
106                 <string>/usr/sbin/mcollectived</string>
107                 <string>--config=/etc/mcollective/server.cfg</string>
108         </array>
109         <key>RunAtLoad</key>
110         <true/>
111         <key>ServiceDescription</key>
112         <string>MCollective Server</string>
113         <key>ServiceIPC</key>
114         <false/>
115 </dict>
116 </plist>
117 EOF
118
119
120 #Make our Packages.  This requires XCode be installed
121 $PACKAGEMAKER -r $tmpdir --version $mcversion --title "MCollective" -l / -o $pkgdir/MCollective_$mcversion.pkg -i org.marionette-collective.mcollective
122 $PACKAGEMAKER -r $common_tmpdir --version $mcversion --title "MCollective Common" -l / -o $pkgdir/MCollective-Common_$mcversion.pkg -i org.marionette-collective.mcollective-common
123 $PACKAGEMAKER -r $client_tmpdir --version $mcversion --title "MCollective Client" -l / -o $pkgdir/MCollective-Client_$mcversion.pkg -i org.marionette-collective.mcollective-client
124
125 # Make sure that we install the stomp gem, this is ugly and should be part of the package
126 cat - > $pkgdir/MCollective-Common_$mcversion.pkg/Contents/Resources/postflight <<EOF
127 #!/bin/bash
128 /usr/bin/gem install --no-ri --no-rdoc stomp
129 EOF
130 chmod +x $pkgdir/MCollective-Common_$mcversion.pkg/Contents/Resources/postflight
131
132 # launchd complains if the permissions aren't right, this is a dumb hack that
133 # I needed since PackageMaker doesn't seem to respect permissions (originally had chmod 644 in the tmpdir)
134 cat - > $pkgdir/MCollective_$mcversion.pkg/Contents/Resources/postflight <<EOF
135 #!/bin/bash
136 chmod 644 /Library/LaunchDaemons/org.marionette-collective.mcollective.plist
137 EOF
138 chmod +x $pkgdir/MCollective_$mcversion.pkg/Contents/Resources/postflight
139
140 # Create a r/o compressed dmg from our pkgs
141 hdiutil create -srcfolder $pkgdir -format UDZO -scrub -imagekey zlib-level=9 -volname "mcollective-$mcversion" mcollective-$mcversion.dmg
142
143 #Clean up
144 rm -rf $tmpdir
145 rm -rf $common_tmpdir
146 rm -rf $client_tmpdir
147 rm -rf $pkgdir