bdisk/bin/build.sh

209 lines
5.2 KiB
Bash
Raw Permalink Normal View History

2014-12-19 14:13:30 -05:00
#!/bin/bash
# A lot of snippets, inspiration, and some config directives are from https://projects.archlinux.org/archiso.git/ / the ArchLinux ISO layout.
# Many thanks and praise are deserved.
#DEBUG
#set -x
echo "Starting at $(date)..."
2014-12-19 14:13:30 -05:00
## Import settings
if [ -f "build.conf" ];
then
echo "Now importing settings/variables."
set -e
source extra/build.conf.sample
source build.conf
set +e
else
echo "You have not configured a build.conf OR you are not running from the project's root directory (the git repository's working directory).
If you are indeed in the correct directory, you may copy the sample at extra/build.conf.sample,
edit it for appropriate values, and copy to <PROJECT ROOT>/build.conf"
echo 'For now, though, I am using the defaults. If the build fails complaining about a'
echo 'missing http user, you need to specify a custom/distro-pertinent one.'
cp extra/build.conf.sample build.conf
set -e
source extra/build.conf.sample
set +e
fi
## PREPARATION ##
# safemode browsing enabled. lolz
set -e
# do some basic error checking
ARCH=$(uname -m)
if [[ ${EUID} -ne 0 ]];
then
#echo "This script must be run as root" 1>&2
echo "This script must be run as root."
exit 1
elif [ -f ${LOCKFILE} ];
then
echo "Script already running, stale lockfile present, or an error occurred during last run."
echo "Please clear ${LOCKFILE} by hand before attempting another build."
echo -n "Timestamp of lockfile is: "
ls -l ${LOCKFILE} | awk '{print $6" "$7" "$8}'
exit 1
elif [[ "$(uname -s)" != "Linux" ]];
then
echo "ERROR: This script is only supported on GNU/Linux."
exit 1
elif [[ "${ARCH}" != 'x86_64' ]];
then
echo "Your hardware architecture, ${ARCH}, is not supported. Only x86_64 is supported."
echo "Dying now."
exit 1
fi
echo "Checking directory structure and creating lockfile at ${LOCKFILE}..."
touch ${LOCKFILE}
# make sure the paths exist and then check for an existing chroot session
for i in ${BASEDIR} ${CHROOTDIR32} ${CHROOTDIR64} ${BUILDDIR}32 ${BUILDDIR}64 ${ISODIR} ${MOUNTPT} ${TEMPDIR}/{${UXNAME},${DISTNAME}} ${ARCHBOOT} ${SRCDIR} ${TFTPDIR} ${HTTPDIR}/${DISTNAME} ${BASEDIR}/logs;
2014-12-19 14:13:30 -05:00
do
if [ ! -d ${i} ];
then
2015-01-10 15:50:34 -05:00
#echo "${i} does not exist - creating."
2014-12-19 14:13:30 -05:00
mkdir -p ${i}
fi
done
source ${BASEDIR}/lib/00-depcheck.func.sh
2014-12-19 14:13:30 -05:00
if [ ! -f "./BUILDNO" ];
then
echo '0' > ./BUILDNO
fi
CHROOTDIR_GLOB="${CHROOTDIR}"
BUILDDIR_GLOB="${BUILDDIR}"
# Set the version.
BUILDVERSION="$(git describe --abbrev=0 --tags)-$(git rev-parse --short --verify HEAD)"
2014-12-19 14:13:30 -05:00
BUILD="$(cat BUILDNO)"
BUILD="$(expr ${BUILD} + 1)"
echo ${BUILD} > ./BUILDNO
BUILDTIME="$(date)"
BUILD_MACHINE="$(hostname -f) (${HOST_DIST})"
2014-12-19 14:13:30 -05:00
#BUILD_USERNAME="${SUDO_USER}"
#BUILD_USERNAME="$(who am i | awk '{print $1}')"
set +e ; logname > /dev/null 2>&1
if [[ "${?}" == "0" ]];
then
BUILD_USERNAME="$(logname)"
else
BUILD_USERNAME="$(whoami)"
fi
set -e
USERNAME_REAL="$(grep ${BUILD_USERNAME} /etc/passwd | cut -f5 -d':')"
cat > ${BASEDIR}/VERSION_INFO.txt << EOF
Version: ${BUILDVERSION}
2014-12-19 14:13:30 -05:00
Build: ${BUILD}
Time: ${BUILDTIME}
Machine: ${BUILD_MACHINE}
User: ${BUILD_USERNAME} (${USERNAME_REAL})
EOF
## FUNCTIONS ##
#source ${BASEDIR}/lib/00-depcheck.func.sh ## this should be called like, VERYYYY first thing, right after sanity/safety checks and such.
source ${BASEDIR}/lib/01-mk.chroot.func.sh ## this is called automatically and only if no chroot exists
source ${BASEDIR}/lib/02-holla_atcha_boi.func.sh
source ${BASEDIR}/lib/03-release_me.func.sh
source ${BASEDIR}/lib/04-facehugger.func.sh
source ${BASEDIR}/lib/05-chroot_wrapper.func.sh
source ${BASEDIR}/lib/06-jenny_craig.func.sh
2015-07-17 07:04:19 -04:00
source ${BASEDIR}/lib/07-centos_is_stupid.func.sh
source ${BASEDIR}/lib/08-will_it_blend.func.sh
source ${BASEDIR}/lib/09-stuffy.func.sh
source ${BASEDIR}/lib/10-yo_dj.func.sh
source ${BASEDIR}/lib/11-mentos.func.sh
2014-12-19 14:13:30 -05:00
## The Business-End(TM) ##
CHROOTDIR="${CHROOTDIR_GLOB}"
BUILDDIR="${BUILDDIR_GLOB}"
holla_atcha_boi
rm -rf ${TEMPDIR}/*
release_me 64 > /dev/null 2>&1
release_me 32 > /dev/null 2>&1
# do we need to perform any updates?
if [[ ${1} == "update" ]];
then
mentos
2015-07-17 07:04:19 -04:00
centos_is_stupid
2014-12-19 14:13:30 -05:00
will_it_blend 32
will_it_blend 64
yo_dj
fi
# or do we want to just chroot in?
if [[ ${1} == "chroot" ]];
then
chroot_wrapper 64
chroot_wrapper 32
rm -f ${LOCKFILE}
exit 0
fi
# implement for future, needs tweaking- JUST rebuild the ISO.
#if [[ ${1} == "respin" ]];
#then
# if [[ "${MULTIARCH}" == "y" ]];
# then
# centos_is_stupid
# yo_dj any
# else
# centos_is_stupid
# yo_dj 64
# centos_is_stupid
# yo_dj 32
# fi
#fi
#
2014-12-19 14:13:30 -05:00
# or are we just building?
if [[ ${1} == "build" || -z ${1} || ${1} == "all" ]];
2014-12-19 14:13:30 -05:00
then
if [[ "${MULTIARCH}" == "y" ]];
then
2015-07-17 07:04:19 -04:00
centos_is_stupid
2014-12-19 14:13:30 -05:00
will_it_blend 64
will_it_blend 32
yo_dj any
else
2015-07-17 07:04:19 -04:00
centos_is_stupid
2014-12-19 14:13:30 -05:00
will_it_blend 64
yo_dj 64
2015-07-17 07:04:19 -04:00
centos_is_stupid
2014-12-19 14:13:30 -05:00
will_it_blend 32
yo_dj 32
fi
fi
# clean up, clean up, everybody, everywhere
echo "Cleaning up some stuff leftover from the build..."
#rm -rf ${TEMPDIR}/*
#rm -rf ${SRCDIR}/*
cd ${BASEDIR}
2014-12-19 14:13:30 -05:00
if [[ "${GIT}" == "yes" ]];
then
echo "Committing changes to git..."
git add --all .
git commit -m "post-build at $(date)"
fi
# yay! we're done!
rm -f ${LOCKFILE}
echo "Finished successfully at $(date)!"