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: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
|
|
|
|
if [ "${CLEAN}" = "1" ]; then
|
|
|
|
rm -rf .pc
|
|
|
|
rm -rf *-pc
|
|
|
|
fi
|
|
|
|
QUILT_PATCHES=${SUB_STAGE_DIR}/${i}-patches
|
2016-07-29 11:41:13 -04: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 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
|
2016-04-11 02:21:07 -04:00
|
|
|
echo "Dropping into bash to edit patches..."
|
2017-07-02 02:21:22 -04:00
|
|
|
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"
|
|
|
|
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
|
2016-10-11 13:16:41 -04:00
|
|
|
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
|
2016-10-11 13:16:41 -04:00
|
|
|
if [ -x prerun.sh ]; then
|
2017-07-02 06:54:31 -04:00
|
|
|
log_begin "$STAGE_DIR/prerun.sh"
|
2016-10-11 13:16:41 -04:00
|
|
|
./prerun.sh
|
2017-07-02 06:54:31 -04:00
|
|
|
log_end "$STAGE_DIR/prerun.sh"
|
2016-10-05 04:32:03 -04:00
|
|
|
fi
|
2016-10-11 13:16:41 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-07-02 06:59:02 -04:00
|
|
|
run_base() {
|
|
|
|
log_begin "$BASE_DIR"
|
|
|
|
|
2017-07-02 07:01:01 -04:00
|
|
|
for STAGE_DIR in $BASE_DIR/stage*; do
|
2017-07-02 06:59:02 -04:00
|
|
|
run_stage
|
|
|
|
done
|
|
|
|
|
|
|
|
CLEAN=1
|
|
|
|
STAGE_DIR="$BASE_DIR/export-image"
|
|
|
|
EXPORT_ROOTFS_DIR="$WORK_DIR/stage3/rootfs"
|
|
|
|
run_stage
|
|
|
|
|
|
|
|
log_end "$BASE_DIR"
|
|
|
|
}
|
|
|
|
|
2016-04-11 02:21:07 -04:00
|
|
|
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
|
|
|
|
|
2017-06-30 22:09:28 -04:00
|
|
|
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"
|
2017-03-10 17:17:44 -05:00
|
|
|
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
|
2017-06-30 22:09:28 -04:00
|
|
|
export USERNAME
|
|
|
|
export PASSWORD
|
2016-04-11 02:21:07 -04:00
|
|
|
|
|
|
|
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
|
2017-07-02 06:59:02 -04:00
|
|
|
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-02 07:01:01 -04:00
|
|
|
source "$SCRIPT_DIR/common.sh"
|
|
|
|
source "$SCRIPT_DIR/dependencies_check.sh"
|
2016-09-14 06:07:52 -04:00
|
|
|
|
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
|
|
|
|
2017-07-02 06:59:02 -04:00
|
|
|
run_base
|