270 lines
10 KiB
Bash
Executable File
270 lines
10 KiB
Bash
Executable File
#!/bin/bash
|
|
# Copyright 2010-2012, Asio Software Technologies
|
|
# Distributed under the terms of the GNU General Public License v3
|
|
|
|
|
|
# Declare basic system variables
|
|
EZNAME=$(basename ${0})
|
|
EZROOT=$(dirname $(readlink -ne ${0}))
|
|
|
|
# Load necessary files
|
|
source /etc/profile
|
|
source ${EZROOT}/libraries/common
|
|
|
|
# Load EzBuild libraries & configuration
|
|
loadLibraries
|
|
loadConfiguration
|
|
|
|
# Print EzBuild notice and parse arguments
|
|
printNotice
|
|
until [[ -z "${1}" ]]; do
|
|
case "${1}" in
|
|
-c|--cleanlog)
|
|
EZOPT_CLEANLOG=true
|
|
;;
|
|
-D|--tarballdate)
|
|
shift
|
|
if [ -z ${1} ]; then
|
|
die "--tarballdate requires an additional argument!"
|
|
else
|
|
TARBALLDATE="${1}"
|
|
fi
|
|
;;
|
|
-h|--help)
|
|
showEzsyncUsage
|
|
;;
|
|
-l|--listmods)
|
|
listModules
|
|
;;
|
|
-n|--nosync)
|
|
shift
|
|
if [ -z ${1} ]; then
|
|
die "--nosync requires an additional argument!"
|
|
else
|
|
EZNOSYNC=${EZNOSYNC+"$EZNOSYNC "}"${1}"
|
|
fi
|
|
;;
|
|
-N|--nopush)
|
|
EZOPT_NOPUSH=true
|
|
;;
|
|
-p|--purge)
|
|
EZOPT_PURGETMP=true
|
|
;;
|
|
-P|--purgeonly)
|
|
EZOPT_PURGETMP=true
|
|
EZOPT_PURGEONLY=true
|
|
;;
|
|
-s|--syscheck)
|
|
EZOPT_SYSCHECKONLY=true
|
|
;;
|
|
-t|--notrigger)
|
|
EZOPT_NOTRIGGER=true
|
|
;;
|
|
-T|--tarballformat)
|
|
shift
|
|
if [ -z ${1} ]; then
|
|
die "--tarballformat requires an additional argument!"
|
|
else
|
|
TARBALLFORMAT="${1}"
|
|
fi
|
|
;;
|
|
*)
|
|
die "Unrecognized option ${1}"
|
|
;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
# Check system requirements
|
|
printInfo "Checking system prerequisites..."
|
|
checkPrerequisites
|
|
[ ${?} -ne 0 ] && die "Your environment does not meet EzBuild requirements!" 1
|
|
if isEnabled ${EZOPT_SYSCHECKONLY}; then
|
|
printInfo "Your system meets all EzBuild requirements!"
|
|
quit
|
|
fi
|
|
|
|
# Do not allow more than one working copy
|
|
PID=$(pidof -s -o '%PPID' -x ${EZNAME})
|
|
if [ ${PID} ]; then
|
|
printWarn "The ${EZNAME} is already working with PID: ${PID}"
|
|
printWarn "You cannot have more than one instancy running"
|
|
exit 0
|
|
fi
|
|
|
|
# Optionally purge whole temp directory or log file only
|
|
if isEnabled ${EZOPT_PURGETMP}; then
|
|
printInfo "Clearing temp directory..."
|
|
cleanTemp
|
|
if isEnabled ${EZOPT_PURGEONLY}; then
|
|
quit
|
|
fi
|
|
elif isEnabled ${EZOPT_CLEANLOG}; then
|
|
printInfo "Clearing log file..."
|
|
cleanLog
|
|
fi
|
|
|
|
# Initialize EzBuild environment
|
|
makeCoreDirectories || die "EzBuild was unable to create all necessary directories!" 1
|
|
EZNOTIFY="yes"
|
|
prepareWrappers || die "EzBuild was unable to create a wrapper files!" 1
|
|
export LC_ALL="C"
|
|
trap 'die "Process killed! This may lead into unexpected problems!"' 1 2 3 9 15 17 18 23
|
|
|
|
# Load necessary public keys
|
|
printInfo "Loading public keys..."
|
|
eval `keychain --noask --eval id_dsa id_rsa &> /dev/null`
|
|
[ ${?} -ne 0 ] && die "EzBuild was unable to load public keys!" 1
|
|
|
|
# Execute all 'presync' enabled modules
|
|
if ! isEnabled ${EZOPT_NOTRIGGER}; then
|
|
for MODULE in ${MODULES_PRESYNC}; do
|
|
loadModule ${MODULE} "presync"
|
|
RESULT=${?}
|
|
if [ ${RESULT} -eq 255 ]; then
|
|
printWarn "Trying to load module: ${MODULE}, that is incompatible with event: presync!"
|
|
elif [ ${RESULT} -ne 0 ]; then
|
|
fail "EzBuild was unable to execute module: ${MODULE}!" 255
|
|
fi
|
|
unloadModule
|
|
done
|
|
fi
|
|
|
|
# Update local copy of Portage that is being built
|
|
printInfo "Refreshing constructed Portage tree..."
|
|
pullRepository ${PORTAGESDIR}/${PORTAGE_BUILD[0]} ${PORTAGE_BUILD[1]} ${PORTAGE_BUILD[2]} ${PORTAGE_BUILD[3]}
|
|
[ ${?} -ne 0 ] && die "EzBuild was unable to refresh local copy of constructed Portage tree!" 2
|
|
|
|
# Update local copy of mainline Portage
|
|
if ! hasElement "mainline" ${EZNOSYNC} && ! hasElement "portage" ${EZNOSYNC}; then
|
|
printInfo "Refreshing mainline Portage tree..."
|
|
pullRepository ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]} ${PORTAGE_MAINLINE[1]} ${PORTAGE_MAINLINE[2]} ${PORTAGE_MAINLINE[3]}
|
|
[ ${?} -ne 0 ] && die "EzBuild was unable to refresh local copy of mainline Portage tree!" 2
|
|
[ -e ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/metadata/cache ] && rm -rf ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/metadata/cache
|
|
[ -e ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/metadata/md5-cache ] && rm -rf ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/metadata/md5-cache
|
|
echo "distfiles/*" > ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/.gitignore
|
|
echo "packages/*" >> ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/.gitignore
|
|
if [ ! -d ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.mask ]; then
|
|
mv ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.mask ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.mask.bak &> /dev/null
|
|
makeDirectory ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.mask
|
|
mv ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.mask.bak ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.mask/${PORTAGE_MAINLINE[0]%-*} &> /dev/null
|
|
fi
|
|
if [ ! -d ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.unmask ]; then
|
|
mv ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.unmask ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.unmask.bak &> /dev/null
|
|
makeDirectory ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.unmask
|
|
mv ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.unmask.bak ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.unmask/${PORTAGE_MAINLINE[0]%-*} &> /dev/null
|
|
fi
|
|
if [ ! -d ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.use ]; then
|
|
mv ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.use ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.use.bak &> /dev/null
|
|
makeDirectory ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.use
|
|
mv ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.use.bak ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.use/${PORTAGE_MAINLINE[0]%-*} &> /dev/null
|
|
fi
|
|
fi
|
|
|
|
# Update all overlays (including the one that's optionally going to be built)
|
|
SYNC_OVERLAYS=( ${MERGED_OVERLAY[*]} ${MERGED_PORTAGE[*]} )
|
|
for OVERLAY in ${SYNC_OVERLAYS[*]}; do
|
|
TEMP="\${$OVERLAY[*]}"
|
|
CURRENT_OVERLAY=(`eval echo ${TEMP}`)
|
|
if ! hasElement "${CURRENT_OVERLAY[0]}" ${EZNOSYNC}; then
|
|
printInfo "Refreshing overlay: ${CURRENT_OVERLAY[0]}..."
|
|
pullRepository ${OVERLAYSDIR}/${CURRENT_OVERLAY[0]} ${CURRENT_OVERLAY[1]} ${CURRENT_OVERLAY[2]} ${CURRENT_OVERLAY[3]}
|
|
[ ${?} -ne 0 ] && fail "EzBuild was unable to refresh local copy of overlay: ${CURRENT_OVERLAY[0]}!" 4
|
|
fi
|
|
done
|
|
|
|
# Execute all 'postsync' enabled modules
|
|
if ! isEnabled ${EZOPT_NOTRIGGER}; then
|
|
for MODULE in ${MODULES_POSTSYNC}; do
|
|
loadModule ${MODULE} "postsync"
|
|
RESULT=${?}
|
|
if [ ${RESULT} -eq 255 ]; then
|
|
printWarn "Trying to load module: ${MODULE}, that is incompatible with event: postsync!"
|
|
elif [ ${RESULT} -ne 0 ]; then
|
|
fail "EzBuild was unable to execute module: ${MODULE}!" 255
|
|
fi
|
|
unloadModule
|
|
done
|
|
fi
|
|
|
|
# Optionally merge data into build overlay
|
|
if isSet MERGED_OVERLAY && isSet OVERLAY_BUILD; then
|
|
printInfo "Merging ebuilds into Overlay..."
|
|
for OVERLAY in ${MERGED_OVERLAY[*]}; do
|
|
TEMP="\${$OVERLAY[*]}"
|
|
CURRENT_OVERLAY=(`eval echo ${TEMP}`)
|
|
mergeOverlay ${OVERLAYSDIR}/${CURRENT_OVERLAY[0]} ${OVERLAYSDIR}/${OVERLAY_BUILD[0]} ${CURRENT_OVERLAY[4]} ${CURRENT_OVERLAY[5]} ${CURRENT_OVERLAY[6]}
|
|
[ ${?} -ne 0 ] && fail "EzBuild was unable to merge ebuilds into overlay!" 8
|
|
done
|
|
if ! isEnabled ${EZOPT_NOPUSH}; then
|
|
pushRepository ${OVERLAYSDIR}/${OVERLAY_BUILD[0]} ${OVERLAY_BUILD[1]} "Automatic update [$(date +"${PUSHDATEFORMAT}")]."
|
|
[ ${?} -ne 0 ] && die "Ezbuild was unable to record changes to the remote overlay repository!" 8
|
|
fi
|
|
fi
|
|
|
|
# Merge data into build portage
|
|
printInfo "Merging ebuilds into Portage..."
|
|
pullRsync ${PORTAGESDIR}/${PORTAGE_BUILD[0]} ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}
|
|
[ ${?} -ne 0 ] && die "EzBuild was unable to merge ebuilds into Portage tree!" 16
|
|
for OVERLAY in ${MERGED_PORTAGE[*]}; do
|
|
TEMP="\${$OVERLAY[*]}"
|
|
CURRENT_OVERLAY=(`eval echo ${TEMP}`)
|
|
mergeOverlay ${OVERLAYSDIR}/${CURRENT_OVERLAY[0]} ${PORTAGESDIR}/${PORTAGE_BUILD[0]} ${CURRENT_OVERLAY[4]} ${CURRENT_OVERLAY[5]} ${CURRENT_OVERLAY[6]}
|
|
[ ${?} -ne 0 ] && die "EzBuild was unable to merge ebuilds into Portage tree!" 16
|
|
if [ -f ${OVERLAYSDIR}/${CURRENT_OVERLAY[0]}/profiles/package.mask ]; then
|
|
run "cp -apf ${OVERLAYSDIR}/${CURRENT_OVERLAY[0]}/profiles/package.mask ${PORTAGESDIR}/${PORTAGE_BUILD[0]}/profiles/package.mask/${CURRENT_OVERLAY[0]%-*}"
|
|
[ ${?} -ne 0 ] && die "EzBuild was unable to merge package.mask file into Portage tree!" 16
|
|
fi
|
|
if [ -f ${OVERLAYSDIR}/${CURRENT_OVERLAY[0]}/profiles/package.unmask ]; then
|
|
run "cp -apf ${OVERLAYSDIR}/${CURRENT_OVERLAY[0]}/profiles/package.unmask ${PORTAGESDIR}/${PORTAGE_BUILD[0]}/profiles/package.unmask/${CURRENT_OVERLAY[0]%-*}"
|
|
[ ${?} -ne 0 ] && die "EzBuild was unable to merge package.unmask file into Portage tree!" 16
|
|
fi
|
|
if [ -f ${OVERLAYSDIR}/${CURRENT_OVERLAY[0]}/profiles/package.use ]; then
|
|
run "cp -apf ${OVERLAYSDIR}/${CURRENT_OVERLAY[0]}/profiles/package.use ${PORTAGESDIR}/${PORTAGE_BUILD[0]}/profiles/package.use/${CURRENT_OVERLAY[0]%-*}"
|
|
[ ${?} -ne 0 ] && die "EzBuild was unable to merge package.use file into Portage tree!" 16
|
|
fi
|
|
done
|
|
|
|
# Execute all 'precommit' enabled modules
|
|
if ! isEnabled ${EZOPT_NOTRIGGER}; then
|
|
for MODULE in ${MODULES_PRECOMMIT}; do
|
|
loadModule ${MODULE} "precommit"
|
|
RESULT=${?}
|
|
if [ ${RESULT} -eq 255 ]; then
|
|
printWarn "Trying to load module: ${MODULE}, that is incompatible with event: precommit!"
|
|
elif [ ${RESULT} -ne 0 ]; then
|
|
fail "EzBuild was unable to execute module: ${MODULE}!" 255
|
|
fi
|
|
unloadModule
|
|
done
|
|
fi
|
|
|
|
# Regenerate Portage cache
|
|
printInfo "Updating constructed Portage cache..."
|
|
run "FEATURES="metadata-transfer" PORTDIR="${PORTAGESDIR}/${PORTAGE_BUILD[0]}" egencache --update --portdir=${PORTAGESDIR}/${PORTAGE_BUILD[0]} --jobs=${MAXJOBS} --load-average=${LOADAVERAGE} --tolerant"
|
|
[ ${?} -ne 0 ] && die "EzBuild was unable to regenerate cache!" 32
|
|
|
|
# Optionally commit all changes to remote Portage repository
|
|
if ! isEnabled ${EZOPT_NOPUSH}; then
|
|
printInfo "Sending constructed Portage update..."
|
|
pushRepository ${PORTAGESDIR}/${PORTAGE_BUILD[0]} ${PORTAGE_BUILD[1]} "Automatic update [$(date +"${PUSHDATEFORMAT}")]."
|
|
[ ${?} -ne 0 ] && die "Ezbuild was unable to record changes to the remote Portage repository!" 64
|
|
fi
|
|
|
|
# Execute all 'postcommit' enabled modules
|
|
if ! isEnabled ${EZOPT_NOTRIGGER}; then
|
|
for MODULE in ${MODULES_POSTCOMMIT}; do
|
|
loadModule ${MODULE} "postcommit"
|
|
RESULT=${?}
|
|
if [ ${RESULT} -eq 255 ]; then
|
|
printWarn "Trying to load module: ${MODULE}, that is incompatible with event: postcommit!"
|
|
elif [ ${RESULT} -ne 0 ]; then
|
|
fail "EzBuild was unable to execute module: ${MODULE}!" 255
|
|
fi
|
|
unloadModule
|
|
done
|
|
fi
|
|
|
|
# Finally quit the application
|
|
quit
|