iso-builder/build.sh

103 lines
2.3 KiB
Bash
Executable file

#!/bin/bash
set -e
# check for root permissions
if [[ "$(id -u)" != 0 ]]; then
echo "E: Requires root permissions" > /dev/stderr
exit 1
fi
# get config
if [ -n "$1" ]; then
CONFIG_FILE="$1"
else
CONFIG_FILE="etc/terraform.conf"
fi
BASE_DIR="$PWD"
source "$BASE_DIR"/"$CONFIG_FILE"
echo -e "
#----------------------#
# INSTALL DEPENDENCIES #
#----------------------#
"
# Use system live-build if running on Debian
dist="$(lsb_release -i -s)"
if [ $dist == "Debian" ]; then
apt-get install -y binutils zstd live-build
dpkg -i ./debs/ubuntu-keyring*.deb
elif [ $dist == "Ubuntu" ]; then
apt-get install -y binutils zstd
dpkg -i ./debs/*.deb
else
echo "E: Unsupported distribution for building"
fi
ln -sfn /usr/share/debootstrap/scripts/gutsy /usr/share/debootstrap/scripts/lunar
build () {
BUILD_ARCH="$1"
mkdir -p "$BASE_DIR/tmp/$BUILD_ARCH"
cd "$BASE_DIR/tmp/$BUILD_ARCH" || exit
# remove old configs and copy over new
rm -rf config auto
cp -r "$BASE_DIR"/etc/* .
# Make sure conffile specified as arg has correct name
cp -f "$BASE_DIR"/"$CONFIG_FILE" terraform.conf
# Symlink chosen package lists to where live-build will find them
ln -s "package-lists.$PACKAGE_LISTS_SUFFIX" "config/package-lists"
echo -e "
#------------------#
# LIVE-BUILD CLEAN #
#------------------#
"
lb clean
echo -e "
#-------------------#
# LIVE-BUILD CONFIG #
#-------------------#
"
lb config
echo -e "
#------------------#
# LIVE-BUILD BUILD #
#------------------#
"
lb build
echo -e "
#---------------------------#
# MOVE OUTPUT TO BUILDS DIR #
#---------------------------#
"
YYYYMMDD="$(date +%Y%m%d%H%M)"
OUTPUT_DIR="$BASE_DIR/builds/$BUILD_ARCH"
mkdir -p "$OUTPUT_DIR"
if [ "$CHANNEL" == dev ]; then
FNAME="ubuntusway-$VERSION-$CHANNEL-$YYYYMMDD-$OUTPUT_SUFFIX-$ARCH"
elif [ "$CHANNEL" == stable ]; then
FNAME="ubuntusway-$VERSION-$OUTPUT_SUFFIX-$ARCH"
else
echo -e "Error: invalid channel name!"
fi
mv "$BASE_DIR/tmp/$BUILD_ARCH/live-image-$BUILD_ARCH.hybrid.iso" "$OUTPUT_DIR/${FNAME}.iso"
md5sum "$OUTPUT_DIR/${FNAME}.iso" > "$OUTPUT_DIR/${FNAME}.md5.txt"
sha256sum "$OUTPUT_DIR/${FNAME}.iso" > "$OUTPUT_DIR/${FNAME}.sha256.txt"
}
# remove old builds before creating new ones
rm -rf "$BASE_DIR"/builds
build "$ARCH"