2016-04-11 06:21:07 +00:00
|
|
|
#!/bin/bash -e
|
|
|
|
|
|
|
|
run_sub_stage()
|
|
|
|
{
|
|
|
|
log "Begin ${SUB_STAGE_DIR}"
|
|
|
|
pushd ${SUB_STAGE_DIR} > /dev/null
|
|
|
|
for i in {00..99}; do
|
|
|
|
if [ -f ${i}-debconf ]; then
|
|
|
|
log "Begin ${SUB_STAGE_DIR}/${i}-debconf"
|
|
|
|
on_chroot sh -e - << EOF
|
|
|
|
debconf-set-selections <<SELEOF
|
|
|
|
`cat ${i}-debconf`
|
|
|
|
SELEOF
|
|
|
|
EOF
|
|
|
|
log "End ${SUB_STAGE_DIR}/${i}-debconf"
|
|
|
|
fi
|
|
|
|
if [ -f ${i}-packages-nr ]; then
|
|
|
|
log "Begin ${SUB_STAGE_DIR}/${i}-packages-nr"
|
2016-09-07 20:32:36 +00:00
|
|
|
PACKAGES="$(sed -f "${SCRIPT_DIR}/remove-comments.sed" < ${i}-packages-nr)"
|
2016-04-11 06:21:07 +00:00
|
|
|
if [ -n "$PACKAGES" ]; then
|
|
|
|
on_chroot sh -e - << EOF
|
|
|
|
apt-get install --no-install-recommends -y $PACKAGES
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
log "End ${SUB_STAGE_DIR}/${i}-packages-nr"
|
|
|
|
fi
|
|
|
|
if [ -f ${i}-packages ]; then
|
|
|
|
log "Begin ${SUB_STAGE_DIR}/${i}-packages"
|
2016-09-07 20:32:36 +00:00
|
|
|
PACKAGES="$(sed -f "${SCRIPT_DIR}/remove-comments.sed" < ${i}-packages)"
|
2016-04-11 06:21:07 +00:00
|
|
|
if [ -n "$PACKAGES" ]; then
|
|
|
|
on_chroot sh -e - << EOF
|
|
|
|
apt-get install -y $PACKAGES
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
log "End ${SUB_STAGE_DIR}/${i}-packages"
|
|
|
|
fi
|
|
|
|
if [ -d ${i}-patches ]; then
|
|
|
|
log "Begin ${SUB_STAGE_DIR}/${i}-patches"
|
|
|
|
pushd ${STAGE_WORK_DIR} > /dev/null
|
|
|
|
if [ "${CLEAN}" = "1" ]; then
|
|
|
|
rm -rf .pc
|
|
|
|
rm -rf *-pc
|
|
|
|
fi
|
|
|
|
QUILT_PATCHES=${SUB_STAGE_DIR}/${i}-patches
|
2016-07-29 15:41:13 +00:00
|
|
|
SUB_STAGE_QUILT_PATCH_DIR="$(basename $SUB_STAGE_DIR)-pc"
|
|
|
|
mkdir -p $SUB_STAGE_QUILT_PATCH_DIR
|
|
|
|
ln -snf $SUB_STAGE_QUILT_PATCH_DIR .pc
|
2016-04-11 06:21:07 +00:00
|
|
|
if [ -e ${SUB_STAGE_DIR}/${i}-patches/EDIT ]; then
|
|
|
|
echo "Dropping into bash to edit patches..."
|
|
|
|
bash
|
|
|
|
fi
|
2016-05-05 15:55:35 +00:00
|
|
|
quilt upgrade
|
2016-04-11 06:21:07 +00:00
|
|
|
RC=0
|
|
|
|
quilt push -a || RC=$?
|
|
|
|
case "$RC" in
|
|
|
|
0|2)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
false
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
popd > /dev/null
|
|
|
|
log "End ${SUB_STAGE_DIR}/${i}-patches"
|
|
|
|
fi
|
|
|
|
if [ -x ${i}-run.sh ]; then
|
|
|
|
log "Begin ${SUB_STAGE_DIR}/${i}-run.sh"
|
|
|
|
./${i}-run.sh
|
|
|
|
log "End ${SUB_STAGE_DIR}/${i}-run.sh"
|
|
|
|
fi
|
|
|
|
if [ -f ${i}-run-chroot ]; then
|
|
|
|
log "Begin ${SUB_STAGE_DIR}/${i}-run-chroot"
|
|
|
|
on_chroot sh -e - < ${i}-run-chroot
|
|
|
|
log "End ${SUB_STAGE_DIR}/${i}-run-chroot"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
popd > /dev/null
|
|
|
|
log "End ${SUB_STAGE_DIR}"
|
|
|
|
}
|
|
|
|
|
2016-09-07 20:32:36 +00:00
|
|
|
|
2016-04-11 06:21:07 +00:00
|
|
|
run_stage(){
|
|
|
|
log "Begin ${STAGE_DIR}"
|
2016-05-04 14:51:41 +00:00
|
|
|
STAGE=$(basename ${STAGE_DIR})
|
2016-04-11 06:21:07 +00:00
|
|
|
pushd ${STAGE_DIR} > /dev/null
|
|
|
|
unmount ${WORK_DIR}/${STAGE}
|
|
|
|
STAGE_WORK_DIR=${WORK_DIR}/${STAGE}
|
|
|
|
ROOTFS_DIR=${STAGE_WORK_DIR}/rootfs
|
2016-05-04 14:51:41 +00:00
|
|
|
if [ -f ${STAGE_DIR}/EXPORT_IMAGE ]; then
|
|
|
|
EXPORT_DIRS="${EXPORT_DIRS} ${STAGE_DIR}"
|
|
|
|
fi
|
2016-04-11 06:21:07 +00:00
|
|
|
if [ ! -f SKIP ]; then
|
|
|
|
if [ "${CLEAN}" = "1" ]; then
|
|
|
|
if [ -d ${ROOTFS_DIR} ]; then
|
|
|
|
rm -rf ${ROOTFS_DIR}
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [ -x prerun.sh ]; then
|
|
|
|
log "Begin ${STAGE_DIR}/prerun.sh"
|
|
|
|
./prerun.sh
|
|
|
|
log "End ${STAGE_DIR}/prerun.sh"
|
|
|
|
fi
|
|
|
|
for SUB_STAGE_DIR in ${STAGE_DIR}/*; do
|
2016-05-04 14:51:41 +00:00
|
|
|
if [ -d ${SUB_STAGE_DIR} ] &&
|
|
|
|
[ ! -f ${SUB_STAGE_DIR}/SKIP ]; then
|
2016-04-11 06:21:07 +00:00
|
|
|
run_sub_stage
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
unmount ${WORK_DIR}/${STAGE}
|
|
|
|
PREV_STAGE=${STAGE}
|
|
|
|
PREV_STAGE_DIR=${STAGE_DIR}
|
|
|
|
PREV_ROOTFS_DIR=${ROOTFS_DIR}
|
|
|
|
popd > /dev/null
|
|
|
|
log "End ${STAGE_DIR}"
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ "$(id -u)" != "0" ]; then
|
|
|
|
echo "Please run as root" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f config ]; then
|
|
|
|
source config
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "${IMG_NAME}" ]; then
|
|
|
|
echo "IMG_NAME not set" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
export IMG_DATE=${IMG_DATE:-"$(date -u +%Y-%m-%d)"}
|
|
|
|
|
|
|
|
export BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
export SCRIPT_DIR="${BASE_DIR}/scripts"
|
|
|
|
export WORK_DIR="${BASE_DIR}/work/${IMG_DATE}-${IMG_NAME}"
|
2016-05-04 14:51:41 +00:00
|
|
|
export DEPLOY_DIR="${BASE_DIR}/deploy"
|
2016-04-11 06:21:07 +00:00
|
|
|
export LOG_FILE="${WORK_DIR}/build.log"
|
|
|
|
|
|
|
|
export CLEAN
|
|
|
|
export IMG_NAME
|
|
|
|
export APT_PROXY
|
|
|
|
|
|
|
|
export STAGE
|
|
|
|
export STAGE_DIR
|
2016-05-04 14:51:41 +00:00
|
|
|
export STAGE_WORK_DIR
|
|
|
|
export PREV_STAGE
|
2016-04-11 06:21:07 +00:00
|
|
|
export PREV_STAGE_DIR
|
|
|
|
export ROOTFS_DIR
|
|
|
|
export PREV_ROOTFS_DIR
|
2016-05-04 14:51:41 +00:00
|
|
|
export IMG_SUFFIX
|
|
|
|
export EXPORT_DIR
|
|
|
|
export EXPORT_ROOTFS_DIR
|
2016-04-11 06:21:07 +00:00
|
|
|
|
|
|
|
export QUILT_PATCHES
|
|
|
|
export QUILT_NO_DIFF_INDEX=1
|
|
|
|
export QUILT_NO_DIFF_TIMESTAMPS=1
|
|
|
|
export QUILT_REFRESH_ARGS="-p ab"
|
|
|
|
|
2016-09-16 08:29:17 +00:00
|
|
|
source ${SCRIPT_DIR}/common.sh
|
|
|
|
source ${SCRIPT_DIR}/check_deps.sh
|
2016-09-14 10:07:52 +00:00
|
|
|
|
|
|
|
|
2016-09-16 08:29:17 +00:00
|
|
|
check_deps ${BASE_DIR}/depends
|
2016-04-11 06:21:07 +00:00
|
|
|
|
|
|
|
mkdir -p ${WORK_DIR}
|
|
|
|
log "Begin ${BASE_DIR}"
|
|
|
|
|
|
|
|
for STAGE_DIR in ${BASE_DIR}/stage*; do
|
2016-05-04 14:51:41 +00:00
|
|
|
run_stage
|
|
|
|
done
|
|
|
|
|
|
|
|
CLEAN=1
|
|
|
|
for EXPORT_DIR in ${EXPORT_DIRS}; do
|
2016-05-27 10:54:56 +00:00
|
|
|
STAGE_DIR=${BASE_DIR}/export-image
|
2016-05-04 14:51:41 +00:00
|
|
|
IMG_SUFFIX=$(cat ${EXPORT_DIR}/EXPORT_IMAGE)
|
|
|
|
EXPORT_ROOTFS_DIR=${WORK_DIR}/$(basename ${EXPORT_DIR})/rootfs
|
2016-04-11 06:21:07 +00:00
|
|
|
run_stage
|
2016-05-27 10:54:56 +00:00
|
|
|
if [ -e ${EXPORT_DIR}/EXPORT_NOOBS ]; then
|
|
|
|
STAGE_DIR=${BASE_DIR}/export-noobs
|
|
|
|
run_stage
|
|
|
|
fi
|
2016-04-11 06:21:07 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
log "End ${BASE_DIR}"
|