2016-04-11 02:21:07 -04:00
|
|
|
#!/bin/bash -e
|
|
|
|
|
2017-07-02 20:53:08 -04:00
|
|
|
source "$FUNCTIONS_DIR/logging.sh"
|
|
|
|
source "$FUNCTIONS_DIR/dependencies_check.sh"
|
|
|
|
|
2017-07-02 20:52:41 -04:00
|
|
|
export IMG_NAME='BarnacleOS'
|
|
|
|
export HOSTNAME='barnacleos'
|
|
|
|
export USERNAME='user'
|
|
|
|
export PASSWORD='password'
|
|
|
|
|
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 20:17:20 -04:00
|
|
|
export ROOTFS_DIR="$BASE_DIR/rootfs"
|
|
|
|
export BOOTFS_DIR="$ROOTFS_DIR/boot"
|
2017-07-02 20:24:50 -04:00
|
|
|
export MOUNT_DIR="$BASE_DIR/mnt"
|
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 STAGE
|
|
|
|
export STAGE_DIR
|
|
|
|
export STAGE_WORK_DIR
|
|
|
|
|
2017-07-02 14:01:01 -04:00
|
|
|
export IMG_FILE
|
2017-07-02 14:07:25 -04:00
|
|
|
export ZIP_FILE
|
2017-07-02 14:01:01 -04:00
|
|
|
|
2017-07-02 07:07:37 -04:00
|
|
|
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"
|
|
|
|
|
2017-07-02 07:23:16 -04:00
|
|
|
main() {
|
|
|
|
dependencies_check "$BASE_DIR/depends"
|
|
|
|
|
|
|
|
if [ "$(id -u)" != '0' ]; then
|
|
|
|
echo 'Please run as root' 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"
|
2017-07-02 11:58:27 -04:00
|
|
|
|
2017-07-02 20:50:06 -04:00
|
|
|
IMG_FILE="$DEPLOY_DIR/$IMG_DATE-${IMG_NAME}.img"
|
|
|
|
ZIP_FILE="$DEPLOY_DIR/$IMG_DATE-${IMG_NAME}.zip"
|
2017-07-02 14:01:01 -04:00
|
|
|
|
2017-07-02 15:03:56 -04:00
|
|
|
tput setaf 2 # Green color
|
2017-07-02 15:34:27 -04:00
|
|
|
echo "$IMG_DATE $(date +"%T")"
|
2017-07-02 15:03:56 -04:00
|
|
|
echo
|
2017-07-02 15:33:48 -04:00
|
|
|
echo "Work dir: $WORK_DIR"
|
|
|
|
echo "Stage dir: $STAGE_DIR"
|
|
|
|
echo "Stage work dir: $STAGE_WORK_DIR"
|
2017-07-02 15:44:11 -04:00
|
|
|
echo
|
2017-07-02 15:44:26 -04:00
|
|
|
echo "Root FS dir: $ROOTFS_DIR"
|
|
|
|
echo "Boot FS dir: $BOOTFS_DIR"
|
2017-07-02 15:44:11 -04:00
|
|
|
echo
|
2017-07-02 15:44:26 -04:00
|
|
|
echo "Image file: $IMG_FILE"
|
|
|
|
echo "ZIP file: $ZIP_FILE"
|
2017-07-02 15:03:56 -04:00
|
|
|
echo
|
|
|
|
tput sgr0 # No color
|
|
|
|
|
2017-07-02 13:43:52 -04:00
|
|
|
mkdir -p "$WORK_DIR"
|
2017-07-02 14:13:27 -04:00
|
|
|
mkdir -p "$DEPLOY_DIR"
|
2017-07-02 13:43:52 -04:00
|
|
|
|
2017-07-02 19:42:50 -04:00
|
|
|
run_sub_stage "$STAGE_DIR/00-substage"
|
2017-07-02 07:30:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
run_sub_stage() {
|
2017-07-02 15:55:24 -04:00
|
|
|
log_begin "$1"
|
|
|
|
pushd "$1" > /dev/null
|
2017-07-02 15:11:15 -04:00
|
|
|
|
|
|
|
for i in {00..99}; do
|
2017-07-02 19:42:03 -04:00
|
|
|
task_patches "$1/$i-patches"
|
|
|
|
task_run "$1/$i-run.sh"
|
2017-07-02 15:11:15 -04:00
|
|
|
done
|
|
|
|
|
|
|
|
popd > /dev/null
|
2017-07-02 15:55:24 -04:00
|
|
|
log_end "$1"
|
2017-07-02 14:53:17 -04:00
|
|
|
}
|
2017-07-02 07:30:26 -04:00
|
|
|
|
2017-07-02 15:24:25 -04:00
|
|
|
task_patches() {
|
2017-07-02 16:05:56 -04:00
|
|
|
if [ -d "$1" ]; then
|
|
|
|
local SUB_STAGE_DIR=$(dirname "$1")
|
2017-07-02 16:09:03 -04:00
|
|
|
local SUB_STAGE_NAME=$(basename "$SUB_STAGE_DIR")
|
2017-07-02 16:05:56 -04:00
|
|
|
|
|
|
|
log_begin "$1"
|
2017-07-02 15:24:25 -04:00
|
|
|
pushd "$STAGE_WORK_DIR" > /dev/null
|
|
|
|
|
|
|
|
rm -rf .pc
|
|
|
|
rm -rf *-pc
|
|
|
|
|
2017-07-02 16:05:56 -04:00
|
|
|
export QUILT_PATCHES="$1"
|
2017-07-02 15:24:25 -04:00
|
|
|
|
2017-07-02 16:09:03 -04:00
|
|
|
SUB_STAGE_QUILT_PATCH_DIR="$SUB_STAGE_NAME-pc"
|
2017-07-02 15:24:25 -04:00
|
|
|
mkdir -p "$SUB_STAGE_QUILT_PATCH_DIR"
|
|
|
|
ln -snf "$SUB_STAGE_QUILT_PATCH_DIR" .pc
|
|
|
|
|
2017-07-02 16:05:56 -04:00
|
|
|
if [ -e "$1/EDIT" ]; then
|
2017-07-02 15:24:25 -04:00
|
|
|
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
|
2017-07-02 16:05:56 -04:00
|
|
|
log_end "$1"
|
2017-07-02 15:24:25 -04:00
|
|
|
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 07:23:16 -04:00
|
|
|
main
|