2016-04-11 06:21:07 +00:00
|
|
|
#!/bin/bash -e
|
2018-03-02 20:08:24 +00:00
|
|
|
# shellcheck disable=SC2119,SC1091
|
2016-04-11 06:21:07 +00:00
|
|
|
run_sub_stage()
|
|
|
|
{
|
|
|
|
log "Begin ${SUB_STAGE_DIR}"
|
2018-03-02 20:08:24 +00:00
|
|
|
pushd "${SUB_STAGE_DIR}" > /dev/null
|
2016-04-11 06:21:07 +00:00
|
|
|
for i in {00..99}; do
|
2018-03-02 20:08:24 +00:00
|
|
|
if [ -f "${i}-debconf" ]; then
|
2016-04-11 06:21:07 +00:00
|
|
|
log "Begin ${SUB_STAGE_DIR}/${i}-debconf"
|
2016-11-14 23:55:45 +00:00
|
|
|
on_chroot << EOF
|
2016-04-11 06:21:07 +00:00
|
|
|
debconf-set-selections <<SELEOF
|
2018-03-02 20:08:24 +00:00
|
|
|
$(cat "${i}-debconf")
|
2016-04-11 06:21:07 +00:00
|
|
|
SELEOF
|
|
|
|
EOF
|
2018-03-02 20:08:24 +00:00
|
|
|
|
2016-04-11 06:21:07 +00:00
|
|
|
log "End ${SUB_STAGE_DIR}/${i}-debconf"
|
|
|
|
fi
|
2018-03-02 20:08:24 +00:00
|
|
|
if [ -f "${i}-packages-nr" ]; then
|
2016-04-11 06:21:07 +00:00
|
|
|
log "Begin ${SUB_STAGE_DIR}/${i}-packages-nr"
|
2018-03-02 20:08:24 +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
|
2016-11-14 23:55:45 +00:00
|
|
|
on_chroot << EOF
|
2016-04-11 06:21:07 +00:00
|
|
|
apt-get install --no-install-recommends -y $PACKAGES
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
log "End ${SUB_STAGE_DIR}/${i}-packages-nr"
|
|
|
|
fi
|
2018-03-02 20:08:24 +00:00
|
|
|
if [ -f "${i}-packages" ]; then
|
2016-04-11 06:21:07 +00:00
|
|
|
log "Begin ${SUB_STAGE_DIR}/${i}-packages"
|
2018-03-02 20:08:24 +00:00
|
|
|
PACKAGES="$(sed -f "${SCRIPT_DIR}/remove-comments.sed" < "${i}-packages")"
|
2016-04-11 06:21:07 +00:00
|
|
|
if [ -n "$PACKAGES" ]; then
|
2016-11-14 23:55:45 +00:00
|
|
|
on_chroot << EOF
|
2016-04-11 06:21:07 +00:00
|
|
|
apt-get install -y $PACKAGES
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
log "End ${SUB_STAGE_DIR}/${i}-packages"
|
|
|
|
fi
|
2018-03-02 20:08:24 +00:00
|
|
|
if [ -d "${i}-patches" ]; then
|
2016-04-11 06:21:07 +00:00
|
|
|
log "Begin ${SUB_STAGE_DIR}/${i}-patches"
|
2018-03-02 20:08:24 +00:00
|
|
|
pushd "${STAGE_WORK_DIR}" > /dev/null
|
2016-04-11 06:21:07 +00:00
|
|
|
if [ "${CLEAN}" = "1" ]; then
|
|
|
|
rm -rf .pc
|
2018-03-24 17:36:18 +00:00
|
|
|
rm -rf ./*-pc
|
2016-04-11 06:21:07 +00:00
|
|
|
fi
|
2018-03-02 20:08:24 +00:00
|
|
|
QUILT_PATCHES="${SUB_STAGE_DIR}/${i}-patches"
|
|
|
|
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
|
|
|
|
if [ -e "${SUB_STAGE_DIR}/${i}-patches/EDIT" ]; then
|
2016-04-11 06:21:07 +00:00
|
|
|
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
|
2017-03-17 11:45:47 +00:00
|
|
|
if [ -f ${i}-run-chroot.sh ]; then
|
|
|
|
log "Begin ${SUB_STAGE_DIR}/${i}-run-chroot.sh"
|
|
|
|
on_chroot < ${i}-run-chroot.sh
|
|
|
|
log "End ${SUB_STAGE_DIR}/${i}-run-chroot.sh"
|
2016-04-11 06:21:07 +00:00
|
|
|
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}"
|
2018-03-02 20:08:24 +00:00
|
|
|
STAGE="$(basename "${STAGE_DIR}")"
|
|
|
|
pushd "${STAGE_DIR}" > /dev/null
|
|
|
|
unmount "${WORK_DIR}/${STAGE}"
|
|
|
|
STAGE_WORK_DIR="${WORK_DIR}/${STAGE}"
|
|
|
|
ROOTFS_DIR="${STAGE_WORK_DIR}"/rootfs
|
2018-01-03 12:48:31 +00:00
|
|
|
if [ ! -f SKIP_IMAGES ]; then
|
2018-03-02 20:08:24 +00:00
|
|
|
if [ -f "${STAGE_DIR}/EXPORT_IMAGE" ]; then
|
2018-01-03 12:48:31 +00:00
|
|
|
EXPORT_DIRS="${EXPORT_DIRS} ${STAGE_DIR}"
|
|
|
|
fi
|
2016-05-04 14:51:41 +00:00
|
|
|
fi
|
2016-10-11 17:16:41 +00:00
|
|
|
if [ ! -f SKIP ]; then
|
|
|
|
if [ "${CLEAN}" = "1" ]; then
|
2018-03-02 20:08:24 +00:00
|
|
|
if [ -d "${ROOTFS_DIR}" ]; then
|
|
|
|
rm -rf "${ROOTFS_DIR}"
|
2016-10-11 17:16:41 +00:00
|
|
|
fi
|
2016-04-11 06:21:07 +00:00
|
|
|
fi
|
2016-10-11 17:16:41 +00:00
|
|
|
if [ -x prerun.sh ]; then
|
|
|
|
log "Begin ${STAGE_DIR}/prerun.sh"
|
|
|
|
./prerun.sh
|
|
|
|
log "End ${STAGE_DIR}/prerun.sh"
|
2016-10-05 08:32:03 +00:00
|
|
|
fi
|
2016-10-11 17:16:41 +00:00
|
|
|
for SUB_STAGE_DIR in ${STAGE_DIR}/*; do
|
2018-03-02 20:08:24 +00:00
|
|
|
if [ -d "${SUB_STAGE_DIR}" ] &&
|
|
|
|
[ ! -f "${SUB_STAGE_DIR}/SKIP" ]; then
|
2016-10-11 17:16:41 +00:00
|
|
|
run_sub_stage
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
2018-03-02 20:08:24 +00:00
|
|
|
unmount "${WORK_DIR}/${STAGE}"
|
|
|
|
PREV_STAGE="${STAGE}"
|
|
|
|
PREV_STAGE_DIR="${STAGE_DIR}"
|
|
|
|
PREV_ROOTFS_DIR="${ROOTFS_DIR}"
|
2016-04-11 06:21:07 +00:00
|
|
|
popd > /dev/null
|
|
|
|
log "End ${STAGE_DIR}"
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ "$(id -u)" != "0" ]; then
|
|
|
|
echo "Please run as root" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-09-07 21:47:35 +00:00
|
|
|
|
2016-04-11 06:21:07 +00:00
|
|
|
if [ -f config ]; then
|
|
|
|
source config
|
|
|
|
fi
|
|
|
|
|
2018-12-18 21:06:18 +00:00
|
|
|
while getopts "c:" flag
|
|
|
|
do
|
|
|
|
case "$flag" in
|
|
|
|
c)
|
|
|
|
EXTRA_CONFIG="$OPTARG"
|
|
|
|
source "$EXTRA_CONFIG"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2016-04-11 06:21:07 +00:00
|
|
|
if [ -z "${IMG_NAME}" ]; then
|
|
|
|
echo "IMG_NAME not set" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-03-02 20:08:24 +00:00
|
|
|
export USE_QEMU="${USE_QEMU:-0}"
|
|
|
|
export IMG_DATE="${IMG_DATE:-"$(date +%Y-%m-%d)"}"
|
2019-01-21 18:42:54 +00:00
|
|
|
export IMG_FILENAME="${IMG_FILENAME:-"${IMG_DATE}-${IMG_NAME}"}"
|
|
|
|
export ZIP_FILENAME="${ZIP_FILENAME:-"image_${IMG_DATE}-${IMG_NAME}"}"
|
2016-04-11 06:21:07 +00:00
|
|
|
|
2018-03-02 20:08:24 +00:00
|
|
|
BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
2016-04-11 06:21:07 +00:00
|
|
|
export SCRIPT_DIR="${BASE_DIR}/scripts"
|
2018-03-02 20:08:24 +00:00
|
|
|
export WORK_DIR="${WORK_DIR:-"${BASE_DIR}/work/${IMG_DATE}-${IMG_NAME}"}"
|
2017-03-10 22:17:44 +00:00
|
|
|
export DEPLOY_DIR=${DEPLOY_DIR:-"${BASE_DIR}/deploy"}
|
2016-04-11 06:21:07 +00:00
|
|
|
export LOG_FILE="${WORK_DIR}/build.log"
|
|
|
|
|
2018-12-09 22:52:03 +00:00
|
|
|
export FIRST_USER_NAME=${FIRST_USER_NAME:-pi}
|
|
|
|
export FIRST_USER_PASS=${FIRST_USER_PASS:-raspberry}
|
2018-12-17 00:01:04 +00:00
|
|
|
export WPA_ESSID
|
|
|
|
export WPA_PASSWORD
|
|
|
|
export WPA_COUNTRY
|
2018-12-18 18:32:06 +00:00
|
|
|
export ENABLE_SSH="${ENABLE_SSH:-0}"
|
2018-12-09 22:52:03 +00:00
|
|
|
|
2018-03-02 20:08:24 +00:00
|
|
|
export BASE_DIR
|
|
|
|
|
2016-04-11 06:21:07 +00:00
|
|
|
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
|
2017-03-13 17:39:58 +00:00
|
|
|
export NOOBS_NAME
|
|
|
|
export NOOBS_DESCRIPTION
|
2016-05-04 14:51:41 +00:00
|
|
|
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"
|
|
|
|
|
2018-03-02 20:08:24 +00:00
|
|
|
# shellcheck source=scripts/common
|
|
|
|
source "${SCRIPT_DIR}/common"
|
|
|
|
# shellcheck source=scripts/dependencies_check
|
|
|
|
source "${SCRIPT_DIR}/dependencies_check"
|
2016-09-14 10:07:52 +00:00
|
|
|
|
|
|
|
|
2018-03-02 20:08:24 +00:00
|
|
|
dependencies_check "${BASE_DIR}/depends"
|
2016-04-11 06:21:07 +00:00
|
|
|
|
2018-03-02 20:08:24 +00:00
|
|
|
mkdir -p "${WORK_DIR}"
|
2016-04-11 06:21:07 +00:00
|
|
|
log "Begin ${BASE_DIR}"
|
|
|
|
|
2019-01-06 22:37:44 +00:00
|
|
|
STAGE_LIST=${STAGE_LIST:-${BASE_DIR}/stage*}
|
|
|
|
|
|
|
|
for STAGE_DIR_ in $STAGE_LIST; do
|
|
|
|
STAGE_DIR=`realpath "${STAGE_DIR_}"`
|
2016-10-11 17:16:41 +00:00
|
|
|
run_stage
|
2016-05-04 14:51:41 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
CLEAN=1
|
|
|
|
for EXPORT_DIR in ${EXPORT_DIRS}; do
|
2016-05-27 10:54:56 +00:00
|
|
|
STAGE_DIR=${BASE_DIR}/export-image
|
2018-03-02 20:08:24 +00:00
|
|
|
# shellcheck source=/dev/null
|
2017-03-13 17:39:58 +00:00
|
|
|
source "${EXPORT_DIR}/EXPORT_IMAGE"
|
2018-03-02 20:08:24 +00:00
|
|
|
EXPORT_ROOTFS_DIR=${WORK_DIR}/$(basename "${EXPORT_DIR}")/rootfs
|
2016-04-11 06:21:07 +00:00
|
|
|
run_stage
|
2017-09-07 21:47:35 +00:00
|
|
|
if [ "${USE_QEMU}" != "1" ]; then
|
2018-03-02 20:08:24 +00:00
|
|
|
if [ -e "${EXPORT_DIR}/EXPORT_NOOBS" ]; then
|
|
|
|
# shellcheck source=/dev/null
|
|
|
|
source "${EXPORT_DIR}/EXPORT_NOOBS"
|
|
|
|
STAGE_DIR="${BASE_DIR}/export-noobs"
|
2017-09-07 21:47:35 +00:00
|
|
|
run_stage
|
|
|
|
fi
|
2016-05-27 10:54:56 +00:00
|
|
|
fi
|
2016-04-11 06:21:07 +00:00
|
|
|
done
|
|
|
|
|
2017-03-13 17:44:00 +00:00
|
|
|
if [ -x postrun.sh ]; then
|
|
|
|
log "Begin postrun.sh"
|
|
|
|
cd "${BASE_DIR}"
|
|
|
|
./postrun.sh
|
|
|
|
log "End postrun.sh"
|
|
|
|
fi
|
|
|
|
|
2016-04-11 06:21:07 +00:00
|
|
|
log "End ${BASE_DIR}"
|