Skip to content

Instantly share code, notes, and snippets.

@robertoschwald
Last active April 16, 2022 17:35
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertoschwald/e404372e4e6b13cfe20b to your computer and use it in GitHub Desktop.
Save robertoschwald/e404372e4e6b13cfe20b to your computer and use it in GitHub Desktop.
Script to build a standalone Bacula Client MDMG Package on OSX using MacPorts. Tested on OSX 10.11 using XCode 7.1.1 and Bacula 7.0.4
#!/bin/sh
# Script to build MacPorts based OSX Bacula FD Client (7.0.4) in private dir as MDMG installer
# containing all dependencies.
# (c) 2015 Robert Oschwald
# Prerequisites:
# - OSX (10.11 tested)
# - XCODE (7.1.1 and 7.2.0 tested)
# - PackageMaker.app (http://adcdownload.apple.com/Developer_Tools/auxiliary_tools_for_xcode__late_july_2012/xcode44auxtools6938114a.dmg)
# Yes, this is an obsolete Apple tool, but MacPORTS still relies on it to generate PKG files. See https://trac.macports.org/ticket/42725
# Usage: simply call this script. It builds a private installation of MacPorts
# and builds bacula with all dependencies as a MDMG Meta Package for installation
# of the bacula client on many OSX bacula client machines without MacPorts.
# Client installation:
# Copy the mdmg file to the client machine and install.
# Afterwards, you need to configure bacula-fd (/opt/macports-private/etc/bacula/bacula-fd.conf)
# Enable the bacula-fd daemon:
# "daemondo", the MacPorts Wrapper program is not part of the dmg.
# To enable the contained LaunchDaemon plist, you first need to install daemondo from your
# MacPorts mdmg build machine to the clients /opt/macports-private/bin dir.
# BAT GUI
# BAT is NOT included in the MDMG by default.
# If you want to build BAT (and it's large amount of dependencies),
# enable MP_FLAGS in the config
# Version: 1.2.1
# History:
# 1.2.1 disable startup item install in private MacPorts
# 1.2 El Capitan / XCode 7.1.1
# 1.1 fixes
# 1.0 initial version
####
# config
MP_PREFIX=/opt/macports-private
MP_ARCHIVE_NAME="MacPorts-2.3.4"
MP_ARCHIVE_FILENAME="${MP_ARCHIVE_NAME}.tar.bz2"
MP_URL="https://distfiles.macports.org/MacPorts/${MP_ARCHIVE_FILENAME}"
PACKAGE_MAKER="/Applications/PackageMaker.app"
export PATH="/bin:/sbin:/usr/bin:/usr/sbin"
build_dir=`pwd`
#
# if you do want to build the BAT GUI application as well, enable
#MP_FLAGS="+console_bat"
####
if [ ! -d ${PACKAGE_MAKER} ]; then
echo "PackageMaker not found. Please install using"
echo "https://developer.apple.com/downloads/"
echo "(Part of Auxiliary Tools for Xcode Late July 2012. Simply copy PackageMaker.app to /Applications)"
exit 7
fi
cat <<EOF
*********************************************************************
This script builds BACULA Client DMG with all MacPorts dependencies
for installation in private dir ${MP_PREFIX}
This does not clash with any installed default MacPorts
You can use the DMG to install on any OSX machine which doesn't need
to have MacPorts installed
*********************************************************************
EOF
echo "Are you sure [y]?"
read yn
if [ "${yn}" != "y" ]; then
echo "Aborting"
exit 100
fi
if [ ! -d ${MP_PREFIX} -a ! -x ${MP_PREFIX}/bin/port ]; then
echo "MacPorts doesn's seem to be installed in ${MP_PREFIX}, yet"
echo "Fetching ${MP_URL}"
curl -O ${MP_URL}
if [ ! -f ${MP_ARCHIVE_FILENAME} ]; then
echo "Downloading file ${MP_URL} failed"
exit 1
fi
## build in private dir prefix
tar xf $MP_ARCHIVE_FILENAME
cd $MP_ARCHIVE_NAME/
./configure --prefix=$MP_PREFIX --with-applications-dir=$MP_PREFIX/Applications
if [ $? != 0 ]; then
echo "configure failed."
exit 2
fi
make
echo "Installing MacPorts into ${MP_PREFIX}"
sudo make install
if [ $? != 0 ]; then
echo "Installing MacPorts into ${MP_PREFIX} failed"
exit 3
fi
echo "INSTALLATION DONE."
else
echo "MacPorts already installed in ${MP_PREFIX}"
fi
export PATH=${MP_PREFIX}/bin:$PATH
echo "Now syncing ports.."
sudo ${MP_PREFIX}/bin/port -v selfupdate
echo "Modifying ${MP_PREFIX} to not automatically install startup items"
sudo cp ${MP_PREFIX}/etc/macports/macports.conf ${MP_PREFIX}/etc/macports/macports.conf.dist
sudo sed -i '' -e 's/startupitem_install yes/startupitem_install no/' ${MP_PREFIX}/etc/macports/macports.conf
echo " Modifying bacula port file to only build the bacula-fd client (Bug #49203)"
cd `port dir bacula`
sudo cp Portfile Portfile.dist
sudo sed -i '' -e 's/\+console_bat/\+client_only/' Portfile
echo " "
echo " "
echo "Building Bacula-FD MPKG"
sudo ${MP_PREFIX}/bin/port clean bacula
sudo ${MP_PREFIX}/bin/port mdmg bacula ${MP_FLAGS}
if [ $? = 0 ]; then
mpkg_loc=`port work bacula`
echo "Done."
echo "You might find the mdmg in ${mpkg_loc}"
popd
fi
cat <<EOF
*********************************************************************
You can copy the mdmg file (or mpkg if you prefer that) to your bacula client machine and install.
Do not forget to copy ${MP_PREFIX}/bin/daemondo manually onto the
client as well.
After you configured bacula-fd (${MP_PREFIX}/etc/bacula/bacula-fd.conf),
you can enable the daemon by:
sudo bash
cd /Library/LaunchDaemons
ln -s ${MP_PREFIX}/etc/LaunchDaemons/org.macports.bacula/org.macports.bacula.plist
chmod 644 ${MP_PREFIX}/etc/LaunchDaemons/org.macports.bacula/org.macports.bacula.plist
chgrp wheel ${MP_PREFIX}/etc/LaunchDaemons/org.macports.bacula/org.macports.bacula.plist
launchctl load -w /Library/LaunchDaemons/org.macports.bacula.plist
*********************************************************************
Have a nice day.
EOF
# cleanup
cd $build_dir
rm ${MP_ARCHIVE_FILENAME}
rm -rf ${MP_ARCHIVE_NAME}
@prism69
Copy link

prism69 commented Feb 15, 2016

Sorry, im at a loss, could you pls provide clearer instructions of how to get the Bacula client running on El-Capitan?

@robertoschwald
Copy link
Author

Copy the raw version of the script into a file on your OSX machine. Then make the file executable in the Terminal:

chmod 755 <your_file.sh>

Now execute the script in your terminal:

./<your_file.sh>

Ensure XCode is installed on your machine before executing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment