shimboot/build_rootfs.sh

62 lines
1.7 KiB
Bash
Raw Normal View History

2023-10-20 06:38:45 -04:00
#!/bin/bash
#build the debian rootfs
set -e
if [ "$DEBUG" ]; then
set -x
fi
. ./common.sh
2023-10-20 06:38:45 -04:00
if [ "$EUID" -ne 0 ]; then
echo "This script must be run as root."
2023-10-20 06:38:45 -04:00
exit 1
fi
if [ -z "$2" ]; then
echo "Usage: ./build_rootfs.sh rootfs_path release_name"
echo "Valid named arguments (specify with 'key=value'):"
echo " custom_packages - The packages that will be installed in place of task-xfce-desktop."
echo " hostname - The hostname for the new rootfs."
echo " root_passwd - The root password."
echo " username - The unprivileged user name for the new rootfs."
echo " user_passwd - The password for the unprivileged user."
echo "If you do not specify the hostname and credentials, you will be prompted for them later."
2023-10-20 06:38:45 -04:00
exit 1
fi
assert_deps "realpath debootstrap"
parse_args "$@"
2023-10-20 06:38:45 -04:00
rootfs_dir=$(realpath "${1}")
release_name="${2}"
packages="${args['custom_packages']-'task-xfce-desktop'}"
chroot_mounts="proc sys dev run"
unmount_all() {
for mountpoint in $chroot_mounts; do
umount -l "$rootfs_dir/$mountpoint"
done
}
2023-10-20 06:38:45 -04:00
2023-10-21 05:06:52 -04:00
debootstrap --arch amd64 $release_name $rootfs_dir http://deb.debian.org/debian/
cp -ar rootfs/* $rootfs_dir
2023-12-25 22:33:28 -05:00
cp /etc/resolv.conf $rootfs_dir/etc/resolv.conf
2023-10-20 22:30:02 -04:00
trap unmount_all EXIT
2023-10-20 22:30:02 -04:00
for mountpoint in $chroot_mounts; do
mount --make-rslave --rbind "/${mountpoint}" "${rootfs_dir}/$mountpoint"
done
hostname="${args['hostname']}"
root_passwd="${args['root_passwd']}"
username="${args['username']}"
user_passwd="${args['user_passwd']}"
2023-10-20 08:39:43 -04:00
chroot_command="/opt/setup_rootfs.sh '$DEBUG' '$release_name' '$packages' '$hostname' '$root_passwd' '$username' '$user_passwd'"
chroot $rootfs_dir /bin/bash -c "${chroot_command}"
trap - EXIT
unmount_all
2023-10-20 22:30:02 -04:00
2023-10-20 08:39:43 -04:00
echo "rootfs has been created"