SHA256
101 lines
2.8 KiB
Bash
Executable File
101 lines
2.8 KiB
Bash
Executable File
#!/bin/mksh
|
|
|
|
scriptdir=$(dirname $0)
|
|
libdir="${scriptdir}/lib"
|
|
targetdir="${scriptdir}/target"
|
|
profilesdir="${scriptdir}/profiles"
|
|
|
|
source "${scriptdir}/config.sh"
|
|
eval "$@"
|
|
|
|
usage() {
|
|
echo "usage: mkliveimage [VAR1=var1 VAR2=var2 ...]"
|
|
echo
|
|
echo "Variables":
|
|
echo " PROFILE=<profile> Base image profile."
|
|
echo " VERSION=<version> Version of the operating system. [default: latest]"
|
|
echo " SNAPSHOT=[1|0] Build the image using the latest packages. [default: 0]"
|
|
echo " ARCH=<triple> Architecture triple. [default: system]"
|
|
echo " OUTPUTDIR=<path> Output directory. [default: ${targetdir}]"
|
|
echo " OUTPUT=<path> Output file. (ignores OUTPUTDIR if this is set)"
|
|
echo " SUDO=[1|0] Use sudo on operations that may require root. [default: 0]"
|
|
echo
|
|
echo "Available profiles:"
|
|
ls "${profilesdir}" | sed 's/^/ /; s/\.sh$//'
|
|
exit 1
|
|
}
|
|
|
|
default_arch() {
|
|
if [ $(uname -s) -eq "Linux" ]; then
|
|
local KERNELTYPE="linux"
|
|
fi
|
|
|
|
local MACHINETYPE=$(uname -m)
|
|
|
|
echo "${MACHINETYPE}-semios-${KERNELTYPE}"
|
|
}
|
|
|
|
default_output_filename() {
|
|
current_date=$(date +%Y%m%d)
|
|
if [ "${SNAPSHOT}" -eq "1" ]; then
|
|
echo "SemiOS-${PROFILE}-${VERSION}-snapshot-${current_date}-${ARCH}${FORMAT}"
|
|
else
|
|
echo "SemiOS-${PROFILE}-${VERSION}-${ARCH}${FORMAT}"
|
|
fi
|
|
}
|
|
|
|
begin_root() {
|
|
rm -rf "$1"
|
|
mkdir -p "$1" "$1/var/config/packie/repos.d" "$1/dev" "$1/sys" "$1/proc" "$1/etc" "$1/tmp"
|
|
echo "${REPOS}" > "$1/var/config/packie/repos.d/10-distribution.toml"
|
|
if [ -L "/etc/resolv.conf" -o -e "/etc/resolv.conf" ]; then
|
|
cp "/etc/resolv.conf" "$1/etc/resolv.conf"
|
|
fi
|
|
if [ -L "/var/config/resolv.conf" -o -e "/var/config/resolv.conf" ]; then
|
|
cp "/var/config/resolv.conf" "$1/var/config/resolv.conf"
|
|
fi
|
|
}
|
|
|
|
end_root() {
|
|
rm -rf "$1/etc" "$1/var/cache/"*
|
|
}
|
|
|
|
ARCH=$(default_arch)
|
|
|
|
if [ -z "${PROFILE}" ]; then
|
|
usage
|
|
fi
|
|
if [ ! -e "${profilesdir}/${PROFILE}.sh" ]; then
|
|
echo "mkliveimage: Profile \"${PROFILE}\" does not exist."
|
|
usage
|
|
fi
|
|
source "${profilesdir}/${PROFILE}.sh"
|
|
|
|
if [ -z "${OUTPUT}" ]; then
|
|
OUTPUT="${OUTPUTDIR}/$(default_output_filename)"
|
|
fi
|
|
|
|
workdir="${targetdir}/work.$(default_output_filename)"
|
|
begin_root "${workdir}/root"
|
|
|
|
packie --chroot "${workdir}/root" update || exit 1
|
|
packie --chroot "${workdir}/root" install -y "${PACKAGES[@]}" || exit 1
|
|
|
|
end_root "${workdir}/root"
|
|
|
|
case "${FORMAT}" in
|
|
.tar.*)
|
|
source "${libdir}/tarball.sh"
|
|
create_tarball "${workdir}"
|
|
;;
|
|
.iso)
|
|
source "${libdir}/isoimage.sh"
|
|
create_iso "${workdir}"
|
|
;;
|
|
*)
|
|
echo "mkliveimage: FATAL: Profile \"${PROFILE}\" issued an illegal format \"${FORMAT}\"."
|
|
echo "mkliveimage: FATAL: Aborting."
|
|
exit 1
|
|
;;
|
|
esac
|