Files
linux-live-framework/build
T
2023-10-13 01:41:27 +02:00

107 lines
3.7 KiB
Python
Executable File

#!/usr/bin/env bash
set -eE -o pipefail
exec > >(tee -i /tmp/lif.log) 2>&1
cd "$(dirname $(readlink -f ${0}))"
cp -fv config .config
for i in mksquashfs cpio gzip sed grep xorriso tar find file; do
if [ ! -x "$(command -v ${i})" ]; then
case ${i} in
mksquashfs) a="squashfs-tools";;
readelf) a="binutils";;
find) a="find-utils";;
*) a="${i}"
esac
echo "Please install ${a} package to run this tool"
false
fi
done
main()
{
local top DATA INITRD ret tmpRoot utc v
echo "KERNEL=\"${kernel}}\"" >>.config
echo "LMK=\"/lib/modules/$(file -bL ${kernel} | grep -o 'version .*' | cut -d' ' -f2)\"" >>.config
top="$(pwd)"
DATA="${workTmpDir}/isoImage"
INITRD="$(initrd/create)"
ret="${?}"
tmpRoot="${workTmpDir}/tmpRoot"
mkdir -pv ${DATA}/changes ${DATA}/os/modules
rsync --force -aAP $(for i in $(awk '{print $2}' /proc/mounts) /tmp; do echo "--exclude=${i}/*"; done) / ${tmpRoot}
chmod +x -Rv inc2sys
cp -rvf inc2sys/* ${tmpRoot}
mknod ${tmpRoot}/dev/console c 5 1
mknod ${tmpRoot}/dev/null c 1 3
mknod ${tmpRoot}/dev/ram0 b 1 0
mknod ${tmpRoot}/dev/tty1 c 4 1
mknod ${tmpRoot}/dev/tty2 c 4 2
mknod ${tmpRoot}/dev/tty3 c 4 3
mknod ${tmpRoot}/dev/tty4 c 4 4
for i in zstd xz lzma bzip2 gzip; do
mksquashfs ${tmpRoot} ${DATA}/os/system.sfs -comp ${i} -noappend -limit 50
[ -e ${DATA}/os/system.sfs ]&&break
done
mv -fv ${INITRD} ${DATA}/initrd.img
cp -rvf bootfiles/* ${DATA}
for i in ${DATA}/syslinux.cfg ${DATA}/boot/grub/grub.cfg; do
sed -i -r "s/__DISTRO__/${DISTRO}/" ${i}
done
cp -f ${KERNEL} ${DATA}/vmlinuz
cd ${DATA}
utc="$(date +%s)"
v="$(git -C ${top} rev-parse HEAD 2>/dev/null|tr [:lower:] [:upper:]):$(git -C ${top} branch --show-current 2>/dev/null|tr [:lower:] [:upper:]):GIT"||v="INFINITY:PRIVATE:LOCAL"
cat <<eot >.LlfMeta
# Built using Linux-Live-Framework technology.
LLF_VERSION="${v}"
LLF_NAME="${DISTRO}"
LLF_UTC="${utc}"
eot
[[ ${ret} = 2 ]]&&echo "LLF_ELF_STATIC_INITRD=\"y\"" >>.LlfMeta||echo "LLF_ELF_STATIC_INITRD=\"n\"" >>.LlfMeta
xorriso -as mkisofs -o /${DISTRO}-${utc}.iso -iso-level 3 -J -R -D -A ${DISTRO} -V ${DISTRO} -no-emul-boot -boot-info-table -boot-load-size 2 -b boot/grub/i386-pc/eltorito.img -c boot/grub/grub.cat -eltorito-alt-boot -e /efi.img -no-emul-boot .
isohybrid --version >/dev/null 2>&1&&isohybrid -u /${DISTRO}-${utc}.iso
return 0
}
chooseKernel()
{
local n=0 list
mapfile -t list < <(find /boot -type f | egrep "bzImage|kernel|vmlinuz" 2>/dev/null | egrep -v "init|*.old")
if [ ${#list[@]} -gt 1 ]; then
echo -e "Please choose your kernel to proceed:\nChoose number from ${n} to ${#list[@]}\n-----\n"
for a in "${list[@]}"; do
echo "[${n}] - ${a}"
((n++))
done
echo "-----"
read kernel
kernel="/boot/${list[${kernel}]}"
else
kernel="/boot/${list[0]}"
fi
export kernel
return 0
}
for i; do
case ${i} in
-i|--interactive) helper="true" ;;
-k|--kernel) export kernel="${2}"; shift ;;
-d|--distro) DISTRO="${2}"; shift ;;
-w|--workdir) workTmpDir="${2}"; shift ;;
-D|--debug) set -x; export V="-v" ;;
-C|--clean) clean="true" ;;
--) shift; break ;;
*) echo "Unknown option: ${i}"; exit 1 ;;
esac
done
trap '[[ ${clean} ]]&&echo "Cleaning up..."&&rm -rvf ${workTmpDir} /tmp/MlbInitRd{,.img};exit 1' 2 6 15
export workTmpDir
[[ -t 0 && ${helper} || ${helper} ]]&&if chooseKernel&&main; then true else; false; fi
[[ ! ${helper} ]]&& {
[[ ! -e ${kernel} ]]&&echo "[E]: Kernel not found: ${kernel}"&&false
[[ -z ${DISTRO} ]]&&. .config&&echo "[W]: DISTRO not set. Using defaults: ${DISTRO}"||true
[[ -z ${workTmpDir} ]]&&workTmpDir="$(mktemp -d /tmp/Llf_WorkDir_XXXXXXX)"&&echo "[W]: workTmpDir not set. Using defaults: ${workTmpDir}"&&true
export workTmpDir
export DISTRO
mkdir -pv "${workTmpDir}"
if main; then true; else false; fi
}