From 73a2a386984ef90b2d1ef6b62379e26f9f588daa Mon Sep 17 00:00:00 2001 From: ading2210 Date: Thu, 25 Jan 2024 21:12:20 +0000 Subject: [PATCH] add github action to build the rootfs --- .github/workflows/build-rootfs.yaml | 26 +++++++++++++++++++++ build.sh | 18 ++------------- build_complete.sh | 35 +++++++++++++++++++++-------- build_rootfs.sh | 4 +++- 4 files changed, 57 insertions(+), 26 deletions(-) create mode 100644 .github/workflows/build-rootfs.yaml diff --git a/.github/workflows/build-rootfs.yaml b/.github/workflows/build-rootfs.yaml new file mode 100644 index 0000000..4bd8f92 --- /dev/null +++ b/.github/workflows/build-rootfs.yaml @@ -0,0 +1,26 @@ +name: build-rootfs +run-name: Build the base Debian rootfs +on: [push] +jobs: + main: + runs-on: ubuntu-latest + steps: + - name: download repo + uses: actions/checkout@v4 + + - name: install deps + run: | + sudo apt-get install debootstrap coreutils -y + + - name: run build + id: run_build + run: sudo DEBUG=1 ./build_rootfs.sh data/rootfs bookworm hostname=shimboot root_passwd=root username=user user_passwd=user + + - name: archive rootfs + run: tar -vcf data/rootfs.tar.gz -C data/rootfs ./ + + - name: upload rootfs + uses: actions/upload-artifact@v4 + with: + name: rootfs_tar + path: data/rootfs.tar.gz \ No newline at end of file diff --git a/build.sh b/build.sh index 40f9385..ed42cf0 100755 --- a/build.sh +++ b/build.sh @@ -14,15 +14,6 @@ print_help() { echo "Usage: ./build.sh output_path shim_path rootfs_dir" } -check_deps() { - local needed_commands="cpio binwalk pcregrep realpath cgpt mkfs.ext4 mkfs.ext2 fdisk rsync" - 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 @@ -33,13 +24,8 @@ if [ -z "$3" ]; then 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 +. ./common.sh +assert_deps "cpio binwalk pcregrep realpath cgpt mkfs.ext4 mkfs.ext2 fdisk rsync" output_path=$(realpath "${1}") shim_path=$(realpath "${2}") diff --git a/build_complete.sh b/build_complete.sh index 990ec98..3c1f41e 100755 --- a/build_complete.sh +++ b/build_complete.sh @@ -17,9 +17,21 @@ if [ -z "$1" ]; then echo "Usage: ./build_complete.sh board_name" echo "Valid named arguments (specify with 'key=value'):" echo " compress_img - Compress the final disk image into a zip file. Set this to any value to enable this option." + echo " rootfs_dir - Use a different rootfs for the build. The directory you select will be copied before any patches are applied." exit 1 fi +parse_args "$@" +needed_deps="wget python3 unzip zip git debootstrap cpio binwalk pcregrep cgpt mkfs.ext4 mkfs.ext2 fdisk rsync" +if ! check_deps "$needed_deps"; then + #install deps automatically on debian and ubuntu + if [ -f "/etc/debian_version" ]; then + echo "attempting to install build deps" + apt-get install wget python3-all unzip zip debootstrap cpio binwalk pcregrep cgpt rsync -y + fi + assert_deps "$needed_deps" +fi + cleanup_path="" sigint_handler() { if [ $cleanup_path ]; then @@ -77,22 +89,27 @@ download_and_unzip $reco_url $reco_zip $reco_bin echo "downloading shim image" download_and_unzip $shim_url $shim_zip $shim_bin -rootfs_dir="$(realpath data/rootfs_$board)" -rm -rf $rootfs_dir -mkdir -p $rootfs_dir +if [ ! "${args['rootfs_dir']}" ]; then + rootfs_dir="$(realpath data/rootfs_$board)" + rm -rf $rootfs_dir + mkdir -p $rootfs_dir -echo "building debian rootfs" -./build_rootfs.sh $rootfs_dir bookworm \ - hostname=shimboot-$board \ - root_passwd=root \ - username=user \ - user_passwd=user + echo "building debian rootfs" + ./build_rootfs.sh $rootfs_dir bookworm \ + hostname=shimboot-$board \ + root_passwd=root \ + username=user \ + user_passwd=user +else + rootfs_dir="$(realpath "${args['rootfs_dir']}")" +fi echo "patching debian rootfs" ./patch_rootfs.sh $shim_bin $reco_bin $rootfs_dir echo "building final disk image" final_image="$base_dir/data/shimboot_$board.bin" +rm -rf $final_image ./build.sh $final_image $shim_bin data/rootfs echo "build complete! the final disk image is located at $final_image" diff --git a/build_rootfs.sh b/build_rootfs.sh index 30e8af9..b798704 100755 --- a/build_rootfs.sh +++ b/build_rootfs.sh @@ -29,11 +29,13 @@ fi assert_deps "realpath debootstrap" parse_args "$@" -rootfs_dir=$(realpath "${1}") +rootfs_dir=$(realpath -m "${1}") release_name="${2}" packages="${args['custom_packages']-'task-xfce-desktop'}" chroot_mounts="proc sys dev run" +mkdir -p $rootfs_dir + unmount_all() { for mountpoint in $chroot_mounts; do umount -l "$rootfs_dir/$mountpoint"