its-ap-builder/build-image.sh

85 lines
2.4 KiB
Bash
Raw Normal View History

2017-10-04 18:52:03 +02:00
#!/bin/sh
[ $# -ge 1 ] || exit 1
CONTROL="$1"; shift
IMAGEBUILDER_URL=${IMAGEBUILDER_URL:-https://downloads.lede-project.org/snapshots/targets/ar71xx/generic/lede-imagebuilder-ar71xx-generic.Linux-x86_64.tar.xz}
2017-10-04 18:52:03 +02:00
TOPDIR="$PWD"
DLDIR=${DLDIR:-"dl"}
BUILDDIR=${BUILDDIR:-"build"}
IMAGESDIR=${IMAGEDIR:-"images"}
2017-10-04 18:52:03 +02:00
mkdir -p "$DLDIR"
mkdir -p "$BUILDDIR"; rm -rf "$BUILDDIR"/*
mkdir -p "$IMAGESDIR"
2017-10-04 18:52:03 +02:00
VERSION="$(basename "$(git describe --always --tags --dirty --match 'access-points/*')")"
IMAGEDIR="$IMAGESDIR"/"$VERSION"
2018-04-13 23:57:13 +02:00
mkdir -p "$IMAGEDIR"
2017-10-04 18:52:03 +02:00
imagebuilder="$(basename "$IMAGEBUILDER_URL")"
(
cd "$DLDIR"
wget --continue "$IMAGEBUILDER_URL" -O "$imagebuilder"
)
tar -C "$BUILDDIR" -axf "$DLDIR"/"$imagebuilder"
IMAGEBUILDER_DIR="$BUILDDIR"/"$(tar -atf "$DLDIR"/"$imagebuilder" | head -n1)"
2018-09-02 21:27:01 +02:00
# source control file and extract variables
2018-04-13 23:57:13 +02:00
profile=$(. "$CONTROL"; echo "${PROFILE}")
2018-08-03 21:31:55 +02:00
target=$(. "$CONTROL"; echo "${TARGET}")
subtarget=$(. "$CONTROL"; echo "${SUBTARGET}")
2017-10-04 18:52:03 +02:00
(
2018-09-02 21:27:01 +02:00
# `make` below consumes these
2017-10-04 18:52:03 +02:00
export PROFILE PACKAGES
2018-04-13 23:57:13 +02:00
2017-10-04 18:52:03 +02:00
. "$CONTROL"
2018-09-02 21:29:10 +02:00
tmp="$(mktemp --tmpdir -d files.XXXXXXXXX)"
2017-10-04 18:52:03 +02:00
2018-04-13 23:57:13 +02:00
mkdir -p "$tmp"/etc
mkdir -p "$tmp"/etc/its-access-point/
printf '%s\n' "$VERSION" > "$tmp"/etc/its-access-point-version # legacy
printf '%s\n' "$VERSION" > "$tmp"/etc/its-access-point/version
printf '%s\n' "$IMAGEBUILDER_URL" \
> "$tmp"/etc/its-access-point/imagebuilder-url
sha512sum "$imagebuilder" > "$tmp"/etc/its-access-point/imagebuilder-hash
cat "$CONTROL" > "$tmp"/etc/its-access-point/control
2017-10-04 18:52:03 +02:00
2018-04-13 23:57:13 +02:00
if [ -n "$COMMON_FILES" ]; then
cp -aLTv "$TOPDIR/$COMMON_FILES" "$tmp"
fi
if [ -n "$FILES" ]; then
cp -aLTv "$TOPDIR/$FILES" "$tmp"
fi
2017-10-04 18:52:03 +02:00
cd "$IMAGEBUILDER_DIR"
2018-04-13 23:57:13 +02:00
unset COMMON_FILES
make image FILES="$tmp" 1>&2
2017-10-04 18:52:03 +02:00
)
2018-08-03 21:31:55 +02:00
cp "$IMAGEBUILDER_DIR"/bin/targets/ar71xx/"${subtarget}"/openwrt*-"${target}-${subtarget}-${profile}"-squashfs-sysupgrade.bin "$IMAGEDIR"/
2017-10-04 18:52:03 +02:00
2018-09-02 21:27:01 +02:00
ln -snf "$VERSION" images/latest
2017-10-04 18:52:03 +02:00
{
printf '%s\n' "Date: $(date -R)"
printf '%s\n' "Image-Builder: $IMAGEBUILDER_URL"
printf '%s\n'
printf 'Checksums-Sha512:\n'
{
( cd "$DLDIR" ; sha512sum "$imagebuilder" )
2018-08-03 21:31:55 +02:00
( cd "$IMAGEDIR"; sha512sum openwrt*-"${target}-${subtarget}-${profile}"-squashfs-sysupgrade.bin )
2017-10-04 18:52:03 +02:00
} | sed 's/^/ /'
2018-04-14 01:00:40 +02:00
} > "$IMAGEDIR"/"${profile}".image-manifest
2018-09-02 21:27:01 +02:00
echo
echo
echo "Wrote images to $IMAGEDIR"
echo