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

245 lines
4.4 KiB
Bash
Raw Normal View History

2016-04-11 02:21:07 -04:00
#!/bin/bash -e
2017-07-02 07:08:24 -04:00
export IMG_DATE="$(date +%Y-%m-%d)"
2017-07-02 07:07:37 -04:00
export BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
2017-07-02 07:08:24 -04:00
export SCRIPT_DIR="$BASE_DIR/scripts"
export WORK_DIR="$BASE_DIR/work/$IMG_DATE-$IMG_NAME"
export DEPLOY_DIR="$BASE_DIR/deploy"
export LOG_FILE="$WORK_DIR/build.log"
2017-07-02 07:07:37 -04:00
export CLEAN
export IMG_NAME
export HOSTNAME
export USERNAME
export PASSWORD
export STAGE
export STAGE_DIR
export STAGE_WORK_DIR
export PREV_STAGE
export PREV_STAGE_DIR
export ROOTFS_DIR
export PREV_ROOTFS_DIR
export EXPORT_ROOTFS_DIR
export QUILT_PATCHES
export QUILT_NO_DIFF_INDEX=1
export QUILT_NO_DIFF_TIMESTAMPS=1
2017-07-02 07:10:54 -04:00
export QUILT_REFRESH_ARGS='-p ab'
2017-07-02 07:07:37 -04:00
source "$SCRIPT_DIR/common.sh"
source "$SCRIPT_DIR/dependencies_check.sh"
2017-07-01 23:29:44 -04:00
log_begin() {
log "Begin $1"
}
log_end() {
log "End $1"
}
2017-07-01 23:34:28 -04:00
task_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:34:28 -04:00
task_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
2017-07-01 23:33:46 -04:00
apt-get install --no-install-recommends -y $PACKAGES
2017-07-01 23:26:26 -04:00
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:34:28 -04:00
task_packages() {
2017-07-01 23:33:13 -04:00
if [ -f "$1" ]; then
log_begin "$1"
PACKAGES="$(sed -f "$SCRIPT_DIR/remove-comments.sed" < "$1")"
if [ -n "$PACKAGES" ]; then
on_chroot <<EOF
2017-07-01 23:33:46 -04:00
apt-get install -y $PACKAGES
2017-07-01 23:33:13 -04:00
EOF
fi
log_end "$1"
fi
}
2017-07-02 00:05:20 -04:00
task_run() {
if [ -x "$1" ]; then
log_begin "$1"
"$1"
log_end "$1"
fi
}
2017-07-02 00:07:12 -04:00
task_run_chroot() {
if [ -f "$1" ]; then
log_begin "$1"
on_chroot < "$1"
log_end "$1"
fi
}
2017-07-01 23:12:49 -04:00
run_sub_stage() {
2017-07-02 00:09:12 -04:00
log_begin "$SUB_STAGE_DIR"
pushd "$SUB_STAGE_DIR" > /dev/null
2016-04-11 02:21:07 -04:00
for i in {00..99}; do
2017-07-01 23:34:28 -04:00
task_debconf "$SUB_STAGE_DIR/$i-debconf"
task_packages_nr "$SUB_STAGE_DIR/$i-packages-nr"
task_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
2017-07-02 06:54:31 -04:00
log_begin "$SUB_STAGE_DIR/$i-patches"
2016-04-11 02:21:07 -04:00
pushd ${STAGE_WORK_DIR} > /dev/null
2017-07-02 07:10:54 -04:00
if [ "${CLEAN}" = '1' ]; then
2016-04-11 02:21:07 -04:00
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
2017-07-02 02:21:22 -04:00
tput setaf 3 # Yellow color
2017-07-02 07:10:54 -04:00
echo 'Dropping into bash to edit patches...'
echo 'Tutorial: https://raphaelhertzog.com/2012/08/08/how-to-use-quilt-to-manage-patches-in-debian-packages/'
echo 'Example:'
echo ' quilt new XX-name-of-the-patch.diff'
echo ' quilt edit rootfs/path/to/file'
echo ' quilt diff'
echo ' quilt refresh'
2017-07-02 02:21:22 -04:00
tput sgr0 # No color
2016-04-11 02:21:07 -04:00
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
2017-07-02 06:54:31 -04:00
log_end "$SUB_STAGE_DIR/$i-patches"
2016-04-11 02:21:07 -04:00
fi
2017-07-02 00:05:20 -04:00
2017-07-02 00:07:12 -04:00
task_run "$SUB_STAGE_DIR/$i-run.sh"
task_run_chroot "$SUB_STAGE_DIR/$i-run-chroot.sh"
2016-04-11 02:21:07 -04:00
done
2017-07-02 00:09:12 -04:00
2016-04-11 02:21:07 -04:00
popd > /dev/null
2017-07-02 00:09:12 -04:00
log_end "$SUB_STAGE_DIR"
2016-04-11 02:21:07 -04:00
}
2017-07-01 23:12:49 -04:00
run_stage() {
2017-07-02 06:54:31 -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
if [ ! -f SKIP ]; then
2017-07-02 07:10:54 -04:00
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
2017-07-02 06:54:31 -04:00
log_begin "$STAGE_DIR/prerun.sh"
./prerun.sh
2017-07-02 06:54:31 -04:00
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
2017-07-02 06:54:31 -04:00
log_end "$STAGE_DIR"
2016-04-11 02:21:07 -04:00
}
run_base() {
log_begin "$BASE_DIR"
2017-07-02 07:01:01 -04:00
for STAGE_DIR in $BASE_DIR/stage*; do
run_stage
done
CLEAN=1
STAGE_DIR="$BASE_DIR/export-image"
EXPORT_ROOTFS_DIR="$WORK_DIR/stage3/rootfs"
run_stage
log_end "$BASE_DIR"
}
2017-07-02 07:10:54 -04:00
if [ "$(id -u)" != '0' ]; then
echo 'Please run as root' 1>&2
2017-07-02 07:03:59 -04:00
exit 1
fi
if [ -f config ]; then
source config
fi
if [ -z "${IMG_NAME}" ]; then
2017-07-02 07:10:54 -04:00
echo 'IMG_NAME not set' 1>&2
2017-07-02 07:03:59 -04:00
exit 1
fi
if [ -z "${HOSTNAME}" ]; then
2017-07-02 07:10:54 -04:00
echo 'HOSTNAME not set' 1>&2
2017-07-02 07:03:59 -04:00
exit 1
fi
if [ -z "${USERNAME}" ]; then
2017-07-02 07:10:54 -04:00
echo 'USERNAME not set' 1>&2
2017-07-02 07:03:59 -04:00
exit 1
fi
if [ -z "${PASSWORD}" ]; then
2017-07-02 07:10:54 -04:00
echo 'PASSWORD not set' 1>&2
2017-07-02 07:03:59 -04:00
exit 1
fi
2017-07-02 07:01:01 -04:00
dependencies_check "$BASE_DIR/depends"
2016-04-11 02:21:07 -04:00
2017-07-02 07:01:01 -04:00
mkdir -p "$WORK_DIR"
2016-04-11 02:21:07 -04:00
run_base