1
0
Fork 0
This repository has been archived on 2023-03-27. You can view files and clone it, but cannot push or open issues or pull requests.
raspberrypi-build/build.sh

234 lines
4.5 KiB
Bash
Raw Normal View History

2016-04-11 02:21:07 -04:00
#!/bin/bash -e
2017-07-01 23:29:44 -04:00
log_begin() {
log "Begin $1"
}
log_end() {
log "End $1"
}
2017-07-01 23:17:11 -04:00
run_debconf() {
2017-07-01 23:28:24 -04:00
if [ -f "$1" ]; then
2017-07-01 23:29:44 -04:00
log_begin "$1"
2017-07-01 23:17:11 -04:00
on_chroot << EOF
debconf-set-selections <<SELEOF
2017-07-01 23:28:24 -04:00
`cat "$1"`
2017-07-01 23:17:11 -04:00
SELEOF
EOF
2017-07-01 23:29:44 -04:00
log_end "$1"
2017-07-01 23:17:11 -04:00
fi
}
2017-07-01 23:26:26 -04:00
run_packages_nr() {
2017-07-01 23:28:24 -04:00
if [ -f "$1" ]; then
2017-07-01 23:29:44 -04:00
log_begin "$1"
2017-07-01 23:26:26 -04:00
2017-07-01 23:28:24 -04:00
PACKAGES="$(sed -f "$SCRIPT_DIR/remove-comments.sed" < "$1")"
2017-07-01 23:26:26 -04:00
if [ -n "$PACKAGES" ]; then
on_chroot <<EOF
apt-get install --n-install-recommends -y $PACKAGES
EOF
fi
2017-07-01 23:29:44 -04:00
log_end "$1"
2017-07-01 23:26:26 -04:00
fi
}
2017-07-01 23:33:13 -04:00
run_packages() {
if [ -f "$1" ]; then
log_begin "$1"
PACKAGES="$(sed -f "$SCRIPT_DIR/remove-comments.sed" < "$1")"
if [ -n "$PACKAGES" ]; then
on_chroot <<EOF
apt-get install --n-install-recommends -y $PACKAGES
EOF
fi
log_end "$1"
fi
}
2017-07-01 23:12:49 -04:00
run_sub_stage() {
2016-04-11 02:21:07 -04:00
log "Begin ${SUB_STAGE_DIR}"
pushd ${SUB_STAGE_DIR} > /dev/null
for i in {00..99}; do
2017-07-01 23:30:37 -04:00
run_debconf "$SUB_STAGE_DIR/$i-debconf"
run_packages_nr "$SUB_STAGE_DIR/$i-packages-nr"
2017-07-01 23:33:13 -04:00
run_packages "$SUB_STAGE_DIR/$i-packages"
2017-07-01 23:26:26 -04:00
2016-04-11 02:21:07 -04:00
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
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 02:21:07 -04:00
if [ -e ${SUB_STAGE_DIR}/${i}-patches/EDIT ]; then
echo "Dropping into bash to edit patches..."
bash
fi
2016-05-05 11:55:35 -04:00
quilt upgrade
2016-04-11 02:21:07 -04: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.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 02:21:07 -04:00
fi
done
popd > /dev/null
log "End ${SUB_STAGE_DIR}"
}
2017-07-01 23:12:49 -04:00
run_stage() {
2016-04-11 02:21:07 -04:00
log "Begin ${STAGE_DIR}"
2016-05-04 10:51:41 -04:00
STAGE=$(basename ${STAGE_DIR})
2016-04-11 02:21:07 -04: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 10:51:41 -04:00
if [ -f ${STAGE_DIR}/EXPORT_IMAGE ]; then
EXPORT_DIRS="${EXPORT_DIRS} ${STAGE_DIR}"
fi
if [ ! -f SKIP ]; then
if [ "${CLEAN}" = "1" ]; then
if [ -d ${ROOTFS_DIR} ]; then
rm -rf ${ROOTFS_DIR}
fi
2016-04-11 02:21:07 -04:00
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
if [ -d ${SUB_STAGE_DIR} ] &&
[ ! -f ${SUB_STAGE_DIR}/SKIP ]; then
run_sub_stage
fi
done
fi
2016-04-11 02:21:07 -04:00
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
2017-06-30 21:33:24 -04:00
if [ -z "${HOSTNAME}" ]; then
echo "HOSTNAME not set" 1>&2
exit 1
fi
if [ -z "${USERNAME}" ]; then
echo "USERNAME not set" 1>&2
exit 1
fi
if [ -z "${PASSWORD}" ]; then
echo "PASSWORD not set" 1>&2
exit 1
fi
2017-06-02 00:51:54 -04:00
export IMG_DATE=${IMG_DATE:-"$(date +%Y-%m-%d)"}
2016-04-11 02:21:07 -04:00
export BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
export SCRIPT_DIR="${BASE_DIR}/scripts"
export WORK_DIR=${WORK_DIR:-"${BASE_DIR}/work/${IMG_DATE}-${IMG_NAME}"}
export DEPLOY_DIR=${DEPLOY_DIR:-"${BASE_DIR}/deploy"}
2016-04-11 02:21:07 -04:00
export LOG_FILE="${WORK_DIR}/build.log"
export CLEAN
export IMG_NAME
2017-06-30 21:33:24 -04:00
export HOSTNAME
export USERNAME
export PASSWORD
2016-04-11 02:21:07 -04:00
export APT_PROXY
export STAGE
export STAGE_DIR
2016-05-04 10:51:41 -04:00
export STAGE_WORK_DIR
export PREV_STAGE
2016-04-11 02:21:07 -04:00
export PREV_STAGE_DIR
export ROOTFS_DIR
export PREV_ROOTFS_DIR
2016-05-04 10:51:41 -04:00
export IMG_SUFFIX
export EXPORT_DIR
export EXPORT_ROOTFS_DIR
2016-04-11 02:21:07 -04:00
export QUILT_PATCHES
export QUILT_NO_DIFF_INDEX=1
export QUILT_NO_DIFF_TIMESTAMPS=1
export QUILT_REFRESH_ARGS="-p ab"
2017-07-01 23:06:34 -04:00
source ${SCRIPT_DIR}/common.sh
source ${SCRIPT_DIR}/dependencies_check.sh
dependencies_check ${BASE_DIR}/depends
2016-04-11 02:21:07 -04:00
mkdir -p ${WORK_DIR}
log "Begin ${BASE_DIR}"
for STAGE_DIR in ${BASE_DIR}/stage*; do
run_stage
2016-05-04 10:51:41 -04:00
done
CLEAN=1
for EXPORT_DIR in ${EXPORT_DIRS}; do
2016-05-27 06:54:56 -04:00
STAGE_DIR=${BASE_DIR}/export-image
source "${EXPORT_DIR}/EXPORT_IMAGE"
2016-05-04 10:51:41 -04:00
EXPORT_ROOTFS_DIR=${WORK_DIR}/$(basename ${EXPORT_DIR})/rootfs
2016-04-11 02:21:07 -04:00
run_stage
done
if [ -x postrun.sh ]; then
log "Begin postrun.sh"
cd "${BASE_DIR}"
./postrun.sh
log "End postrun.sh"
fi
2016-04-11 02:21:07 -04:00
log "End ${BASE_DIR}"