Archive
Posts Tagged ‘boot_crunch.mk’
Automating FreeBSD’s crunchgen(1)
July 27, 2012
2 comments
Automating FreeBSD’s crunchgen(1)
Hey, Joe…this one’s for you…thanks for reading!
One of my main tasks in my role at work is to maintain FreeBSD provisioning bits. I have found myself generating boot_crunch files with various binaries and what not to extend the capabilities of the provisioning aspect of FreeBSD. So much so that I whipped up a quick script to automate the task for me.
Please bear in mind, it is a quick script which makes a number of assumptions. It’s not perfect and can certainly use some tweaking and the like, but this initial version gets one started.
I keep my boot_crunch.conf in a subversion repo, thus the calls to svn.
#! /bin/sh
#
# bldcrunch.sh: Generate a FreeBSD boot_crunch file. This script does not
# function on hosts that are not running FreeBSD.
#
# Author: Rick
# Date: 25 July 2012
# Modif:
#####
## Variables
#####
SELF="${0##*/}";
NULL="/dev/null";
TMP="/tmp";
PATH="${PATH}";
SVNREPO="http://svn.domain.com/freebsd-repo";
REPODIR="/freebsd-repo";
BOOTCRUNCHDIR="boot_crunch";
BOOTCRUNCHCONF="boot_crunch.conf";
BOOTCRUNCHMK="boot_crunch.mk";
SVNBIN="/usr/local/bin/svn";
CRUNCHGEN="/usr/bin/crunchgen";
MAKE="/usr/bin/make";
#####
## Functions
#####
ERROR_EXIT() {
echo "${1}" 1>&2;
[ -d ${TMP}/${BOOTCRUNCHDIR} ] && rm ${TMP}/${BOOTCRUNCHDIR};
exit 1;
}
#####
## Main
#####
# Verify we're on a FreeBSD host
HOSTOS=`uname -s`;
[ ${HOSTOS} != "FreeBSD" ] && ERROR_EXIT "Build host is not FreeBSD! Exiting!";
# Do all of our binaries exist?
for ea in ${SVNBIN} ${CRUNCHGEN} ${MAKE}; do
if [ -e ${ea} ]; then
continue;
else
ERROR_EXIT "${ea} is required! Exiting!";
fi
done
# Update SVN repo to make sure we're using the latest boot_crunch.conf
if [ -d ${REPODIR}/${BOOTCRUNCHDIR} ]; then
cd ${REPODIR}/${BOOTCRUNCHDIR} && ${SVNBIN} update;
else
${SVN} co ${SVNREPO} ${REPODIR};
fi
# Setup our build environment
[ -d ${TMP}/${BOOTCRUNCHDIR} ] && rm -rf ${TMP}/${BOOTCRUNCHDIR};
mkdir ${TMP}/${BOOTCRUNCHDIR} && cd ${TMP}/${BOOTCRUNCHDIR};
# Build the boot_crunch
${CRUNCHGEN} -o ${REPODIR}/${BOOTCRUNCHDIR}/${BOOTCRUNCHCONF};
[ $? -eq 0 ] && ${MAKE} -f ${BOOTCRUNCHMK};
[ $? -ne 0 ] && ERROR_EXIT "Error generating boot_crunch! Exiting!";
#####
## EOF
#####
BTW, I edited this because I found out about wordpress’s sourcecode tag…awesome!
Categories: FreeBSD