Add versioning to config. Some renaming. Add config file to chroot script. Extract logic to functions. Misc cleanup.

This commit is contained in:
Ken Gilmer 2021-04-16 07:51:49 -07:00
parent eba2e7f51c
commit c2e82ba0e6
4 changed files with 102 additions and 37 deletions

View File

@ -5,14 +5,6 @@ set -o pipefail # exit on pipeline error
set -u # treat unset variable as error
#set -x
if [[ -f ./configuration.sh ]]; then
source configuration.sh
fi
if [[ -z "$GRUB_LIVEBOOT_LABEL" ]]; then
GRUB_LIVEBOOT_LABEL="Ubuntu FS"
fi
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
CMD=(setup_host debootstrap run_chroot build_iso)
@ -22,7 +14,7 @@ DATE=`TZ="UTC" date +"%y%m%d-%H%M%S"`
function help() {
# if $1 is set, use $1 as headline message in help()
if [ -z ${1+x} ]; then
echo -e "This script builds bootable ubuntu ISO image"
echo -e "This script builds a bootable ubuntu ISO image"
echo -e
else
echo -e $1
@ -81,6 +73,29 @@ function check_host() {
fi
}
# Load configuration values from file
function load_config() {
if [[ -f "$SCRIPT_DIR/config.sh" ]]; then
. "$SCRIPT_DIR/config.sh"
elif [[ -f "$SCRIPT_DIR/default_config.sh" ]]; then
. "$SCRIPT_DIR/default_config.sh"
else
>&2 echo "Unable to find default config file $SCRIPT_DIR/default_config.sh, aborting."
exit 1
fi
}
# Verify that necessary configuration values are set and they are valid
function check_config() {
local expected_config_version
expected_config_version="0.1"
if [[ "$CONFIG_FILE_VERSION" != "$expected_config_version" ]]; then
>&2 echo "Invalid or old config version $CONFIG_FILE_VERSION, expected $expected_config_version. Please update your configuration file from the default."
exit 1
fi
}
function setup_host() {
echo "=====> running setup_host ..."
sudo apt update
@ -98,9 +113,22 @@ function run_chroot() {
chroot_enter_setup
# Setup build scripts in chroot environment
sudo ln -f $SCRIPT_DIR/chroot_build.sh chroot/root/chroot_build.sh
sudo ln -f $SCRIPT_DIR/default_config.sh chroot/root/default_config.sh
if [[ -f "$SCRIPT_DIR/config.sh" ]]; then
sudo ln -f $SCRIPT_DIR/config.sh chroot/root/config.sh
fi
# Launch into chroot environment to build install image.
sudo chroot chroot /root/chroot_build.sh -
# Cleanup after image changes
sudo rm -f chroot/root/chroot_build.sh
sudo rm -f chroot/root/default_config.sh
if [[ -f "chroot/root/config.sh" ]]; then
sudo rm -f chroot/root/config.sh
fi
chroot_exit_teardown
}
@ -133,12 +161,12 @@ insmod all_video
set default="0"
set timeout=30
menuentry "Try ${GRUB_LIVEBOOT_LABEL} without installing" {
menuentry "${GRUB_LIVEBOOT_LABEL}" {
linux /casper/vmlinuz boot=casper nopersistent toram quiet splash ---
initrd /casper/initrd
}
menuentry "Install ${GRUB_LIVEBOOT_LABEL}" {
menuentry "${GRUB_INSTALL_LABEL}" {
linux /casper/vmlinuz boot=casper only-ubiquity quiet splash ---
initrd /casper/initrd
}
@ -257,6 +285,8 @@ EOF
# we always stay in $SCRIPT_DIR
cd $SCRIPT_DIR
load_config
check_config
check_host
# check number of args

View File

@ -81,6 +81,19 @@ EOF
ln -s /bin/true /sbin/initctl
}
# Load configuration values from file
function load_config() {
if [[ -f "$SCRIPT_DIR/config.sh" ]]; then
. "$SCRIPT_DIR/config.sh"
elif [[ -f "$SCRIPT_DIR/default_config.sh" ]]; then
. "$SCRIPT_DIR/default_config.sh"
else
>&2 echo "Unable to find default config file $SCRIPT_DIR/default_config.sh, aborting."
exit 1
fi
}
function install_pkg() {
echo "=====> running install_pkg ... will take a long time ..."
apt-get -y upgrade
@ -110,31 +123,8 @@ function install_pkg() {
ubiquity-slideshow-ubuntu \
ubiquity-ubuntu-artwork
# install graphics and desktop
apt-get install -y \
plymouth-theme-ubuntu-logo \
ubuntu-gnome-desktop \
ubuntu-gnome-wallpapers
# useful tools
apt-get install -y \
clamav-daemon \
terminator \
apt-transport-https \
curl \
vim \
nano \
less
# purge
apt-get purge -y \
transmission-gtk \
transmission-common \
gnome-mahjongg \
gnome-mines \
gnome-sudoku \
aisleriot \
hitori
# Call into config function
customize_image
# remove unused and clean up apt cache
apt-get autoremove -y

View File

@ -1 +0,0 @@
GRUB_LIVEBOOT_LABEL="Ubuntu FS"

46
scripts/default_config.sh Normal file
View File

@ -0,0 +1,46 @@
#!/bin/bash
#
# This script provides common customization options for the ISO
#
# Used to version the configuration. If breaking changes occur, manual
# updates to this file from the default may be necessary.
export CONFIG_FILE_VERSION="0.1"
# The text label shown in GRUB for booting into the live environment
export GRUB_LIVEBOOT_LABEL="Try Ubuntu FS without installing"
# The text label shown in GRUB for starting installation
export GRUB_INSTALL_LABEL="Install Ubuntu FS"
# Package customisation function. Update this function to customize packages
# present on the installed system.
function customize_image() {
# install graphics and desktop
apt-get install -y \
plymouth-theme-ubuntu-logo \
ubuntu-gnome-desktop \
ubuntu-gnome-wallpapers
# useful tools
apt-get install -y \
clamav-daemon \
terminator \
apt-transport-https \
curl \
vim \
nano \
less
# purge
apt-get purge -y \
transmission-gtk \
transmission-common \
gnome-mahjongg \
gnome-mines \
gnome-sudoku \
aisleriot \
hitori
}