summaryrefslogtreecommitdiffstats
path: root/conf
diff options
context:
space:
mode:
authorNigel Kersten <nigel@explanatorygap.net>2008-08-01 20:45:25 -0700
committerJames Turnbull <james@lovedthanlost.net>2008-08-03 02:57:51 +1000
commitff45c8639dae54e48890ab780653d4f039b02afc (patch)
tree8c7fac89a6fd6bf7e8003bae49d0d35f06a0d470 /conf
parent9b4218292e06ea4d0b4c07b272653dcf52a24142 (diff)
downloadfacter-ff45c8639dae54e48890ab780653d4f039b02afc.tar.gz
facter-ff45c8639dae54e48890ab780653d4f039b02afc.tar.xz
facter-ff45c8639dae54e48890ab780653d4f039b02afc.zip
Feature #1487: Package creation scripts for Mac OS X
Diffstat (limited to 'conf')
-rw-r--r--conf/osx/PackageInfo.plist36
-rwxr-xr-xconf/osx/createpackage.sh167
-rwxr-xr-xconf/osx/preflight11
3 files changed, 214 insertions, 0 deletions
diff --git a/conf/osx/PackageInfo.plist b/conf/osx/PackageInfo.plist
new file mode 100644
index 0000000..84b4422
--- /dev/null
+++ b/conf/osx/PackageInfo.plist
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleIdentifier</key>
+ <string>com.reductivelabs.facter</string>
+ <key>CFBundleShortVersionString</key>
+ <string>{SHORTVERSION}</string>
+ <key>IFMajorVersion</key>
+ <integer>{MAJORVERSION}</integer>
+ <key>IFMinorVersion</key>
+ <integer>{MINORVERSION}</integer>
+ <key>IFPkgFlagAllowBackRev</key>
+ <false/>
+ <key>IFPkgFlagAuthorizationAction</key>
+ <string>RootAuthorization</string>
+ <key>IFPkgFlagDefaultLocation</key>
+ <string>/</string>
+ <key>IFPkgFlagFollowLinks</key>
+ <true/>
+ <key>IFPkgFlagInstallFat</key>
+ <false/>
+ <key>IFPkgFlagIsRequired</key>
+ <false/>
+ <key>IFPkgFlagOverwritePermissions</key>
+ <true/>
+ <key>IFPkgFlagRelocatable</key>
+ <false/>
+ <key>IFPkgFlagRestartAction</key>
+ <string>None</string>
+ <key>IFPkgFlagRootVolumeOnly</key>
+ <true/>
+ <key>IFPkgFlagUpdateInstalledLanguages</key>
+ <false/>
+</dict>
+</plist>
diff --git a/conf/osx/createpackage.sh b/conf/osx/createpackage.sh
new file mode 100755
index 0000000..747dda9
--- /dev/null
+++ b/conf/osx/createpackage.sh
@@ -0,0 +1,167 @@
+#!/bin/bash
+#
+# Script to build an "old style" not flat pkg out of the facter repository.
+#
+# Author: Nigel Kersten (nigelk@google.com)
+#
+# Last Updated: 2008-07-31
+#
+# Copyright 2008 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License
+
+
+INSTALLRB="install.rb"
+BINDIR="/usr/bin"
+SITELIBDIR="/usr/lib/ruby/site_ruby/1.8"
+PACKAGEMAKER="/Developer/usr/bin/packagemaker"
+PROTO_PLIST="PackageInfo.plist"
+PREFLIGHT="preflight"
+
+
+function find_installer() {
+ # we walk up three directories to make this executable from the root,
+ # root/conf or root/conf/osx
+ if [ -f "./${INSTALLRB}" ]; then
+ installer="$(pwd)/${INSTALLRB}"
+ elif [ -f "../${INSTALLRB}" ]; then
+ installer="$(pwd)/../${INSTALLRB}"
+ elif [ -f "../../${INSTALLRB}" ]; then
+ installer="$(pwd)/../${INSTALLRB}"
+ else
+ installer=""
+ fi
+}
+
+function find_facter_root() {
+ facter_root=$(dirname "${installer}")
+}
+
+function install_facter() {
+ echo "Installing Facter to ${pkgroot}"
+ "${installer}" --destdir="${pkgroot}" --bindir="${BINDIR}" --sitelibdir="${SITELIBDIR}" &> /dev/null
+ chown -R root:admin "${pkgroot}"
+}
+
+function get_facter_version() {
+ facter_version=$(RUBYLIB="${pkgroot}/${SITELIBDIR}:${RUBYLIB}" ruby -e "require 'facter'; puts Facter.version")
+}
+
+function prepare_package() {
+ # As we can't specify to follow symlinks from the command line, we have
+ # to go through the hassle of creating an Info.plist file for packagemaker
+ # to look at for package creation and substitue the version strings out.
+ # Major/Minor versions can only be integers, so we have "0" and "245" for
+ # puppet version 0.24.5
+ # Note too that for 10.5 compatibility this Info.plist *must* be set to
+ # follow symlinks.
+ VER1=$(echo ${facter_version} | awk -F "." '{print $1}')
+ VER2=$(echo ${facter_version} | awk -F "." '{print $2}')
+ VER3=$(echo ${facter_version} | awk -F "." '{print $3}')
+ major_version="${VER1}"
+ minor_version="${VER2}${VER3}"
+ cp "${facter_root}/conf/osx/${PROTO_PLIST}" "${pkgtemp}"
+ sed -i '' "s/{SHORTVERSION}/${facter_version}/g" "${pkgtemp}/${PROTO_PLIST}"
+ sed -i '' "s/{MAJORVERSION}/${major_version}/g" "${pkgtemp}/${PROTO_PLIST}"
+ sed -i '' "s/{MINORVERSION}/${minor_version}/g" "${pkgtemp}/${PROTO_PLIST}"
+
+ # We need to create a preflight script to remove traces of previous
+ # puppet installs due to limitations in Apple's pkg format.
+ mkdir "${pkgtemp}/scripts"
+ cp "${facter_root}/conf/osx/${PREFLIGHT}" "${pkgtemp}/scripts"
+
+ # substitute in the sitelibdir specified above on the assumption that this
+ # is where any previous puppet install exists that should be cleaned out.
+ sed -i '' "s|{SITELIBDIR}|${SITELIBDIR}|g" "${pkgtemp}/scripts/${PREFLIGHT}"
+ chmod 0755 "${pkgtemp}/scripts/${PREFLIGHT}"
+}
+
+function create_package() {
+ rm -fr "$(pwd)/facter-${puppet_version}.pkg"
+ echo "Building package"
+ echo "Note that packagemaker is reknowned for spurious errors. Don't panic."
+ "${PACKAGEMAKER}" --root "${pkgroot}" \
+ --info "${pkgtemp}/${PROTO_PLIST}" \
+ --scripts ${pkgtemp}/scripts \
+ --out "$(pwd)/facter-${facter_version}.pkg"
+ if [ $? -ne 0 ]; then
+ echo "There was a problem building the package."
+ cleanup_and_exit 1
+ exit 1
+ else
+ echo "The package has been built at:"
+ echo "$(pwd)/facter-${facter_version}.pkg"
+ fi
+}
+
+function cleanup_and_exit() {
+ if [ -d "${pkgroot}" ]; then
+ rm -fr "${pkgroot}"
+ fi
+ if [ -d "${pkgtemp}" ]; then
+ rm -fr "${pkgtemp}"
+ fi
+ exit $1
+}
+
+# Program entry point
+function main() {
+
+ if [ $(whoami) != "root" ]; then
+ echo "This script needs to be run as root via su or sudo."
+ cleanup_and_exit 1
+ fi
+
+ find_installer
+
+ if [ ! "${installer}" ]; then
+ echo "Unable to find ${INSTALLRB}"
+ cleanup_and_exit 1
+ fi
+
+ find_facter_root
+
+ if [ ! "${facter_root}" ]; then
+ echo "Unable to find facter repository root."
+ cleanup_and_exit 1
+ fi
+
+ pkgroot=$(mktemp -d -t facterpkg)
+
+ if [ ! "${pkgroot}" ]; then
+ echo "Unable to create temporary package root."
+ cleanup_and_exit 1
+ fi
+
+ pkgtemp=$(mktemp -d -t factertmp)
+
+ if [ ! "${pkgtemp}" ]; then
+ echo "Unable to create temporary package root."
+ cleanup_and_exit 1
+ fi
+
+ install_facter
+ get_facter_version
+
+ if [ ! "${facter_version}" ]; then
+ echo "Unable to retrieve facter version"
+ cleanup_and_exit 1
+ fi
+
+ prepare_package
+ create_package
+
+ cleanup_and_exit 0
+}
+
+main "$@"
diff --git a/conf/osx/preflight b/conf/osx/preflight
new file mode 100755
index 0000000..400a261
--- /dev/null
+++ b/conf/osx/preflight
@@ -0,0 +1,11 @@
+#!/bin/bash
+#
+# Make sure that old facter cruft is removed
+# This also allows us to downgrade facter as
+# it's more likely that installing old versions
+# over new will cause issues.
+#
+# ${3} is the destination volume so that this works correctly
+# when being installed to volumes other than the current OS.
+
+rm -Rf "${3}{SITELIBDIR}/facter*"