2016-04-11 02:21:07 -04:00
|
|
|
#!/bin/bash -e
|
|
|
|
|
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"
|
2017-07-02 07:37:33 -04:00
|
|
|
export FUNCTIONS_DIR="$BASE_DIR/functions"
|
2017-07-02 07:08:24 -04:00
|
|
|
export DEPLOY_DIR="$BASE_DIR/deploy"
|
2017-07-02 07:07:37 -04:00
|
|
|
|
2017-07-02 09:18:10 -04:00
|
|
|
export IMG_DATE
|
|
|
|
export WORK_DIR
|
|
|
|
|
2017-07-02 07:07:37 -04:00
|
|
|
export IMG_NAME
|
|
|
|
export HOSTNAME
|
|
|
|
export USERNAME
|
|
|
|
export PASSWORD
|
|
|
|
|
|
|
|
export STAGE
|
|
|
|
export STAGE_DIR
|
|
|
|
export STAGE_WORK_DIR
|
|
|
|
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
|
|
|
|
2017-07-02 07:37:33 -04:00
|
|
|
source "$FUNCTIONS_DIR/logging.sh"
|
2017-07-02 07:07:37 -04:00
|
|
|
source "$SCRIPT_DIR/common.sh"
|
2017-07-02 07:59:35 -04:00
|
|
|
source "$FUNCTIONS_DIR/dependencies_check.sh"
|
2017-07-02 07:07:37 -04:00
|
|
|
|
2017-07-02 07:23:16 -04:00
|
|
|
main() {
|
|
|
|
dependencies_check "$BASE_DIR/depends"
|
|
|
|
|
|
|
|
source "$BASE_DIR/config"
|
|
|
|
|
|
|
|
if [ "$(id -u)" != '0' ]; then
|
|
|
|
echo 'Please run as root' 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-07-02 13:48:08 -04:00
|
|
|
if [ -z "$IMG_NAME" ]; then
|
2017-07-02 07:23:16 -04:00
|
|
|
echo 'IMG_NAME not set' 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-07-02 13:48:08 -04:00
|
|
|
if [ -z "$HOSTNAME" ]; then
|
2017-07-02 07:23:16 -04:00
|
|
|
echo 'HOSTNAME not set' 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-07-02 13:48:08 -04:00
|
|
|
if [ -z "$USERNAME" ]; then
|
2017-07-02 07:23:16 -04:00
|
|
|
echo 'USERNAME not set' 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-07-02 13:48:08 -04:00
|
|
|
if [ -z "$PASSWORD" ]; then
|
2017-07-02 07:23:16 -04:00
|
|
|
echo 'PASSWORD not set' 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-07-02 09:18:10 -04:00
|
|
|
IMG_DATE="$(date +%Y-%m-%d)"
|
|
|
|
WORK_DIR="$BASE_DIR/work/$IMG_DATE-$IMG_NAME"
|
|
|
|
|
2017-07-02 13:43:36 -04:00
|
|
|
STAGE='stage0'
|
|
|
|
STAGE_DIR="$BASE_DIR/$STAGE"
|
2017-07-02 12:01:08 -04:00
|
|
|
STAGE_WORK_DIR="$WORK_DIR/$STAGE"
|
|
|
|
ROOTFS_DIR="$STAGE_WORK_DIR/rootfs"
|
2017-07-02 11:58:27 -04:00
|
|
|
|
2017-07-02 13:43:52 -04:00
|
|
|
mkdir -p "$WORK_DIR"
|
|
|
|
|
2017-07-02 13:42:33 -04:00
|
|
|
pushd "$STAGE_DIR" > /dev/null
|
|
|
|
|
2017-07-02 12:01:54 -04:00
|
|
|
unmount "$STAGE_WORK_DIR"
|
2017-07-02 11:58:27 -04:00
|
|
|
|
2017-07-02 12:00:34 -04:00
|
|
|
for SUB_STAGE_DIR in $STAGE_DIR/*; do
|
|
|
|
if [ -d "$SUB_STAGE_DIR" ]; then
|
2017-07-02 11:58:56 -04:00
|
|
|
run_sub_stage
|
|
|
|
fi
|
|
|
|
done
|
2017-07-02 11:51:13 -04:00
|
|
|
|
2017-07-02 12:01:54 -04:00
|
|
|
unmount "$STAGE_WORK_DIR"
|
2017-07-02 11:50:51 -04:00
|
|
|
|
2017-07-02 11:58:27 -04:00
|
|
|
popd > /dev/null
|
2017-07-02 07:30:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
run_sub_stage() {
|
|
|
|
log_begin "$SUB_STAGE_DIR"
|
|
|
|
pushd "$SUB_STAGE_DIR" > /dev/null
|
|
|
|
|
|
|
|
for i in {00..99}; do
|
|
|
|
task_debconf "$SUB_STAGE_DIR/$i-debconf"
|
|
|
|
task_packages_nr "$SUB_STAGE_DIR/$i-packages-nr"
|
|
|
|
task_packages "$SUB_STAGE_DIR/$i-packages"
|
|
|
|
|
|
|
|
if [ -d ${i}-patches ]; then
|
|
|
|
log_begin "$SUB_STAGE_DIR/$i-patches"
|
|
|
|
pushd ${STAGE_WORK_DIR} > /dev/null
|
2017-07-02 11:32:25 -04:00
|
|
|
rm -rf .pc
|
|
|
|
rm -rf *-pc
|
2017-07-02 07:30:26 -04: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
|
|
|
|
tput setaf 3 # Yellow color
|
|
|
|
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'
|
|
|
|
tput sgr0 # No color
|
|
|
|
|
|
|
|
bash
|
|
|
|
fi
|
|
|
|
quilt upgrade
|
|
|
|
RC=0
|
|
|
|
quilt push -a || RC=$?
|
|
|
|
case "$RC" in
|
|
|
|
0|2)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
false
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
popd > /dev/null
|
|
|
|
log_end "$SUB_STAGE_DIR/$i-patches"
|
|
|
|
fi
|
|
|
|
|
|
|
|
task_run "$SUB_STAGE_DIR/$i-run.sh"
|
|
|
|
task_run_chroot "$SUB_STAGE_DIR/$i-run-chroot.sh"
|
|
|
|
done
|
|
|
|
|
|
|
|
popd > /dev/null
|
|
|
|
log_end "$SUB_STAGE_DIR"
|
2017-07-01 23:29:44 -04:00
|
|
|
}
|
|
|
|
|
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-02 07:23:16 -04:00
|
|
|
main
|