2023-10-20 05:38:45 -05:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#build the debian rootfs
|
|
|
|
|
|
|
|
set -e
|
|
|
|
if [ "$DEBUG" ]; then
|
|
|
|
set -x
|
|
|
|
fi
|
|
|
|
|
|
|
|
print_help() {
|
2023-12-21 18:58:08 -06:00
|
|
|
echo "Usage: ./build_rootfs.sh rootfs_path release_name [custom_packages]"
|
2023-10-20 05:38:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
check_deps() {
|
|
|
|
local needed_commands="realpath debootstrap"
|
|
|
|
for command in $needed_commands; do
|
|
|
|
if ! command -v $command &> /dev/null; then
|
|
|
|
echo $command
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ "$EUID" -ne 0 ]; then
|
|
|
|
echo "this needs to be run as root."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$2" ]; then
|
|
|
|
print_help
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
missing_commands=$(check_deps)
|
|
|
|
if [ "${missing_commands}" ]; then
|
|
|
|
echo "You are missing dependencies needed for this script."
|
|
|
|
echo "Commands needed:"
|
|
|
|
echo "${missing_commands}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
rootfs_dir=$(realpath "${1}")
|
|
|
|
release_name="${2}"
|
2023-12-21 18:58:08 -06:00
|
|
|
packages="${3-'task-xfce-desktop'}"
|
2023-10-20 05:38:45 -05:00
|
|
|
|
2023-10-21 04:06:52 -05:00
|
|
|
debootstrap --arch amd64 $release_name $rootfs_dir http://deb.debian.org/debian/
|
2023-10-21 01:23:39 -05:00
|
|
|
cp -ar rootfs/* $rootfs_dir
|
2023-12-25 21:33:28 -06:00
|
|
|
cp /etc/resolv.conf $rootfs_dir/etc/resolv.conf
|
2023-10-20 21:30:02 -05:00
|
|
|
|
|
|
|
chroot_mounts="proc sys dev run"
|
|
|
|
for mountpoint in $chroot_mounts; do
|
|
|
|
mount --make-rslave --rbind "/${mountpoint}" "${rootfs_dir}/$mountpoint"
|
|
|
|
done
|
|
|
|
|
2023-12-22 00:51:47 -06:00
|
|
|
chroot_command="/opt/setup_rootfs.sh '$DEBUG' '$release_name' '$packages'"
|
2023-10-20 07:39:43 -05:00
|
|
|
chroot $rootfs_dir /bin/bash -c "${chroot_command}"
|
|
|
|
|
2023-10-20 21:30:02 -05:00
|
|
|
for mountpoint in $chroot_mounts; do
|
2023-10-21 01:23:39 -05:00
|
|
|
umount -l "${rootfs_dir}/$mountpoint"
|
2023-10-20 21:30:02 -05:00
|
|
|
done
|
|
|
|
|
2023-10-20 07:39:43 -05:00
|
|
|
echo "rootfs has been created"
|