2024-01-14 20:52:21 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-08-11 14:45:54 +00:00
|
|
|
# matter-iso | MatterLinux ISO build script
|
2024-05-01 20:56:27 +00:00
|
|
|
# MatterLinux 2023-2024 (https://matterlinux.xyz)
|
2024-01-14 20:52:21 +00:00
|
|
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
2024-08-11 14:45:54 +00:00
|
|
|
#############################
|
|
|
|
## import common functions ##
|
|
|
|
#############################
|
|
|
|
location="$(dirname "${0}")"
|
|
|
|
location="$(realpath "${location}")"
|
|
|
|
commonsh="$(echo "${location}" | sed 's/\/bin/\/lib/g')/mtsc-common.sh"
|
2024-01-14 20:52:21 +00:00
|
|
|
|
2024-08-11 14:45:54 +00:00
|
|
|
source "${commonsh}"
|
2024-01-14 20:52:21 +00:00
|
|
|
|
2024-08-11 14:45:54 +00:00
|
|
|
if [ "${?}" != "0" ]; then
|
|
|
|
echo "Failed to import mtsc-common"
|
2024-01-14 20:52:21 +00:00
|
|
|
exit 1
|
2024-08-11 14:45:54 +00:00
|
|
|
fi
|
2024-01-16 21:05:00 +00:00
|
|
|
|
2024-01-14 20:52:21 +00:00
|
|
|
####################
|
|
|
|
## util functions ##
|
|
|
|
####################
|
2024-01-16 21:05:00 +00:00
|
|
|
check_retc() {
|
|
|
|
if [ $? -ne 0 ]; then
|
2024-08-11 14:45:54 +00:00
|
|
|
error "${1}"
|
2024-01-16 21:05:00 +00:00
|
|
|
clean_tmpdir
|
2024-01-18 12:51:19 +00:00
|
|
|
exit 1
|
2024-01-16 21:05:00 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
clean_tmpdir(){
|
2024-08-11 14:45:54 +00:00
|
|
|
if [ -d "${tmpdir}" ]; then
|
2024-08-18 18:27:51 +00:00
|
|
|
unset_indent
|
2024-01-16 21:05:00 +00:00
|
|
|
info "Cleaning up temp directory"
|
2024-08-18 18:27:51 +00:00
|
|
|
set_indent
|
|
|
|
for d in "${tmpdir}/"*; do
|
|
|
|
if mountpoint -q -- "${d}"; then
|
|
|
|
error "Failed: ${d} is still mounted"
|
|
|
|
unset_indent
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
done
|
2024-08-11 14:45:54 +00:00
|
|
|
rm -rf "${tmpdir}"
|
2024-08-18 18:27:51 +00:00
|
|
|
success "Completed"
|
2024-01-16 21:05:00 +00:00
|
|
|
fi
|
2024-08-18 18:27:51 +00:00
|
|
|
unset_indent
|
|
|
|
return 0
|
2024-01-16 21:05:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
check_iso_vars() {
|
|
|
|
if [ ! -n "$NAME" ]; then
|
|
|
|
return 1
|
|
|
|
elif [ ! -n "$VERSION" ]; then
|
|
|
|
return 1
|
2024-08-18 22:10:22 +00:00
|
|
|
elif ! type BUILD &>/dev/null; then
|
2024-01-16 21:05:00 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
2024-01-14 20:52:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#################
|
|
|
|
## main script ##
|
|
|
|
#################
|
2024-08-18 19:17:43 +00:00
|
|
|
if ! type "grub-mkrescue" > /dev/null; then
|
|
|
|
error "You need to install GRUB to create ISO files with grub-mkrescue"
|
|
|
|
set_indent
|
2024-08-18 21:50:31 +00:00
|
|
|
warn "If you want to create UEFI ISO files make sure you install x64 GRUB or grub-efi"
|
|
|
|
warn "If you want to create BIOS ISO files make sure you install x86 GRUB or grub-bios"
|
2024-08-20 23:40:19 +00:00
|
|
|
warn "After installing GRUB, don't forget to install libisoburn as well"
|
2024-08-18 19:17:43 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-02-22 19:19:01 +00:00
|
|
|
if [ "$EUID" -ne 0 ]; then
|
|
|
|
error "You should run this script as root"
|
2024-08-11 14:45:54 +00:00
|
|
|
exit 1
|
2024-02-22 19:19:01 +00:00
|
|
|
fi
|
|
|
|
|
2024-01-14 20:52:21 +00:00
|
|
|
if [ $# -ne 2 ]; then
|
2024-01-16 21:05:00 +00:00
|
|
|
error "Please specify a release archive and a config directory"
|
2024-08-11 14:45:54 +00:00
|
|
|
exit 1
|
2024-01-14 20:52:21 +00:00
|
|
|
fi
|
2024-08-12 00:07:34 +00:00
|
|
|
|
2024-08-11 14:45:54 +00:00
|
|
|
archive="$(realpath "${1}")"
|
|
|
|
|
2024-08-12 00:07:34 +00:00
|
|
|
if [ ! -f "${archive}" ]; then
|
2024-01-14 20:52:21 +00:00
|
|
|
error "Archive file not found"
|
2024-08-11 14:45:54 +00:00
|
|
|
exit 1
|
2024-01-14 20:52:21 +00:00
|
|
|
fi
|
|
|
|
|
2024-08-11 14:45:54 +00:00
|
|
|
if [[ "$(file "${archive}")" != *"gzip compressed data"* ]]; then
|
2024-01-16 21:05:00 +00:00
|
|
|
error "Bad archive format"
|
2024-08-11 14:45:54 +00:00
|
|
|
exit 1
|
2024-01-16 21:05:00 +00:00
|
|
|
fi
|
2024-01-14 20:52:21 +00:00
|
|
|
|
2024-08-11 14:45:54 +00:00
|
|
|
confdir="$(realpath "${2}")"
|
|
|
|
|
|
|
|
if [ ! -d "${confdir}" ]; then
|
2024-01-16 21:05:00 +00:00
|
|
|
error "Config directory not found"
|
2024-08-11 14:45:54 +00:00
|
|
|
exit 1
|
2024-01-14 20:52:21 +00:00
|
|
|
fi
|
2024-01-16 21:05:00 +00:00
|
|
|
|
2024-08-11 14:45:54 +00:00
|
|
|
tmpdir="${confdir}_tmp"
|
|
|
|
distdir="${confdir}/dist"
|
|
|
|
rootdir="${distdir}/root"
|
|
|
|
isoh="${tmpdir}/iso.sh"
|
2024-01-16 21:05:00 +00:00
|
|
|
|
2024-08-11 14:45:54 +00:00
|
|
|
mkdir -p "${rootdir}"
|
2024-01-16 21:05:00 +00:00
|
|
|
success "Created root and dist directory"
|
2024-01-14 20:52:21 +00:00
|
|
|
|
2024-01-16 21:05:00 +00:00
|
|
|
info "Copying over the config directory"
|
2024-08-11 14:45:54 +00:00
|
|
|
cp -r "${confdir}" "${tmpdir}"
|
2024-01-16 21:05:00 +00:00
|
|
|
check_ret "Copy failed"
|
2024-01-14 20:52:21 +00:00
|
|
|
|
2024-08-11 14:45:54 +00:00
|
|
|
if [ ! -f "${isoh}" ]; then
|
2024-01-16 21:05:00 +00:00
|
|
|
error "ISO script not found"
|
2024-08-11 14:45:54 +00:00
|
|
|
exit 1
|
2024-01-16 21:05:00 +00:00
|
|
|
fi
|
|
|
|
|
2024-08-11 14:45:54 +00:00
|
|
|
source "${isoh}"
|
2024-01-16 21:05:00 +00:00
|
|
|
check_retc "Cannot source the ISO script"
|
2024-08-11 14:45:54 +00:00
|
|
|
|
2024-01-16 21:05:00 +00:00
|
|
|
check_iso_vars
|
|
|
|
check_retc "ISO script is not valid"
|
|
|
|
success "Sourced the ISO script"
|
|
|
|
|
|
|
|
info "Removing excluded files"
|
2024-08-11 14:45:54 +00:00
|
|
|
rm -rf "${tmpdir}/dist"
|
2024-01-16 21:05:00 +00:00
|
|
|
set_indent
|
|
|
|
for e in "${EXCLUDE[@]}"; do
|
2024-08-11 14:45:54 +00:00
|
|
|
info "Removing ${e}"
|
|
|
|
rm -rf "${tmpdir}/${e}"
|
2024-01-16 21:05:00 +00:00
|
|
|
done
|
2024-08-11 14:45:54 +00:00
|
|
|
rm -rf "${tmpdir}/.git"
|
2024-01-16 21:05:00 +00:00
|
|
|
unset_indent
|
|
|
|
|
|
|
|
info "Extracting release archive"
|
|
|
|
SECONDS=0
|
2024-08-11 14:45:54 +00:00
|
|
|
|
|
|
|
tar --skip-old-files -xf "${archive}" -C "${tmpdir}"
|
2024-01-16 21:05:00 +00:00
|
|
|
check_retc "Extract failed"
|
|
|
|
success "Extracted in ${SECONDS}s"
|
|
|
|
|
|
|
|
for k in "${KEYS[@]}"; do
|
|
|
|
if [ -z ${keys_str+x} ]; then
|
|
|
|
keys_str="$k"
|
|
|
|
else
|
|
|
|
keys_str="$keys_str $k"
|
2024-01-14 20:52:21 +00:00
|
|
|
fi
|
2024-01-16 21:05:00 +00:00
|
|
|
done
|
2024-01-14 20:52:21 +00:00
|
|
|
|
2024-01-16 21:05:00 +00:00
|
|
|
for p1 in "${PKGS1[@]}"; do
|
|
|
|
if [ -z ${pkgs1_str+x} ]; then
|
|
|
|
pkgs1_str="$p1"
|
|
|
|
else
|
|
|
|
pkgs1_str="$pkgs1_str $p1"
|
|
|
|
fi
|
|
|
|
done
|
2024-01-14 20:52:21 +00:00
|
|
|
|
2024-01-16 21:05:00 +00:00
|
|
|
for p2 in "${PKGS2[@]}"; do
|
|
|
|
if [ -z ${pkgs2_str+x} ]; then
|
|
|
|
pkgs2_str="$p2"
|
|
|
|
else
|
|
|
|
pkgs2_str="$pkgs2_str $p2"
|
|
|
|
fi
|
|
|
|
done
|
2024-01-14 20:52:21 +00:00
|
|
|
|
2024-01-18 12:51:19 +00:00
|
|
|
info "Adding public keys"
|
2024-08-12 00:07:34 +00:00
|
|
|
matter-chroot "${tmpdir}" gpg --receive-keys $keys_str
|
2024-01-18 12:51:19 +00:00
|
|
|
check_retc "Failed to add public keys"
|
2024-01-16 21:05:00 +00:00
|
|
|
|
2024-01-18 12:51:19 +00:00
|
|
|
if [ ! -z "${PKGS1}" ]; then
|
|
|
|
info "Installing extra packages (1)"
|
2024-08-11 14:45:54 +00:00
|
|
|
matter-chroot "${tmpdir}" matt sync
|
2024-01-18 12:51:19 +00:00
|
|
|
check_retc "Sync failed"
|
2024-08-12 00:07:34 +00:00
|
|
|
|
|
|
|
matter-chroot "${tmpdir}" matt install --yes $pkgs1_str
|
2024-01-18 12:51:19 +00:00
|
|
|
check_retc "Install failed"
|
|
|
|
fi
|
2024-01-14 20:52:21 +00:00
|
|
|
|
2024-01-16 21:05:00 +00:00
|
|
|
info "Running build script"
|
2024-08-18 22:10:22 +00:00
|
|
|
echo "source /iso.sh && BUILD" > "${tmpdir}/stager.sh"
|
2024-08-12 00:07:34 +00:00
|
|
|
matter-chroot "${tmpdir}" chmod +x /stager.sh
|
|
|
|
matter-chroot "${tmpdir}" /stager.sh
|
2024-01-16 21:05:00 +00:00
|
|
|
check_ret "Build script failed"
|
2024-08-11 14:45:54 +00:00
|
|
|
rm "${tmpdir}/stager.sh"
|
2024-01-16 21:05:00 +00:00
|
|
|
|
|
|
|
info "Cleaning up and building initrd"
|
2024-08-11 14:45:54 +00:00
|
|
|
rm "${isoh}"
|
2024-08-25 19:23:47 +00:00
|
|
|
pushd "${tmpdir}" > /dev/null
|
2024-08-11 14:45:54 +00:00
|
|
|
mkdir -p "${rootdir}/boot"
|
|
|
|
find . | cpio --quiet -H newc -o | xz -T0 --check=crc32 > "${rootdir}/boot/initrd.img"
|
2024-01-14 20:52:21 +00:00
|
|
|
check_ret "Failed to build initrd"
|
|
|
|
popd > /dev/null
|
|
|
|
|
2024-01-16 21:05:00 +00:00
|
|
|
if [ ! -z "${PKGS2}" ]; then
|
|
|
|
info "Installing extra packages (2)"
|
2024-08-12 00:07:34 +00:00
|
|
|
matter-chroot "${tmpdir}" matt install --yes $pkgs2_str
|
2024-01-18 12:51:19 +00:00
|
|
|
check_ret "Install failed"
|
2024-01-14 20:52:21 +00:00
|
|
|
fi
|
|
|
|
|
2024-01-16 21:05:00 +00:00
|
|
|
info "Copying over the bootdir"
|
2024-08-11 14:45:54 +00:00
|
|
|
cp -r "${tmpdir}/boot"/* "${rootdir}/boot"
|
2024-01-14 20:52:21 +00:00
|
|
|
|
2024-01-16 21:05:00 +00:00
|
|
|
info "Building the ISO..."
|
2024-08-11 14:45:54 +00:00
|
|
|
pushd "${distdir}" > /dev/null
|
|
|
|
grub-mkrescue -o "${distdir}/${NAME}_${VERSION}.iso" root
|
2024-01-16 21:05:00 +00:00
|
|
|
check_retc "grub-mkrescue failed"
|
|
|
|
popd > /dev/null
|
2024-01-14 20:52:21 +00:00
|
|
|
|
2024-01-16 21:05:00 +00:00
|
|
|
success "ISO is ready, cleaning up"
|
|
|
|
clean_tmpdir
|