From 9840555faa9e7bc7be2c48059e3719b4dd2d5c75 Mon Sep 17 00:00:00 2001 From: ading2210 Date: Thu, 25 Jan 2024 05:43:58 +0000 Subject: [PATCH 1/7] add unified build script and named argument parser --- build_complete.sh | 105 +++++++++++++++++++++++++++++++++++++ build_rootfs.sh | 57 ++++++++++---------- common.sh | 31 +++++++++++ rootfs/opt/setup_rootfs.sh | 46 +++++++++++----- 4 files changed, 198 insertions(+), 41 deletions(-) create mode 100755 build_complete.sh create mode 100755 common.sh diff --git a/build_complete.sh b/build_complete.sh new file mode 100755 index 0000000..990ec98 --- /dev/null +++ b/build_complete.sh @@ -0,0 +1,105 @@ +#!/bin/bash + +set -e +if [ "$DEBUG" ]; then + set -x + export DEBUG=1 +fi + +. ./common.sh + +if [ "$EUID" -ne 0 ]; then + echo "This script must be run as root." + exit 1 +fi + +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." + exit 1 +fi + +cleanup_path="" +sigint_handler() { + if [ $cleanup_path ]; then + rm -rf $cleanup_path + fi + exit 1 +} +trap sigint_handler SIGINT + +base_dir="$(realpath $(dirname "$0"))" +board="$1" +shim_url="https://dl.osu.bio/api/raw/?path=/SH1mmer/$board.zip" +boards_url="https://chromiumdash.appspot.com/cros/fetch_serving_builds?deviceCategory=ChromeOS" + +echo "downloading list of recovery images" +reco_url="$(wget -qO- --show-progress $boards_url | python3 -c ' +import json, sys + +all_builds = json.load(sys.stdin) +board = all_builds["builds"][sys.argv[1]] +if "models" in board: + board = next(iter(board["models"].values())) + +reco_url = list(board["pushRecoveries"].values())[-1] +print(reco_url) +' $board)" +echo "found url: $reco_url" + +shim_bin="$base_dir/data/shim_$board.bin" +shim_zip="$base_dir/data/shim_$board.zip" +reco_bin="$base_dir/data/reco_$board.bin" +reco_zip="$base_dir/data/reco_$board.zip" +mkdir -p "$base_dir/data" + +download_and_unzip() { + local url="$1" + local zip_path="$2" + local bin_path="$3" + if [ ! -f "$bin_path" ]; then + wget -q --show-progress $url -O $zip_path -c + fi + if [ ! -f "$bin_path" ]; then + cleanup_path="$bin_path" + echo "extracting $zip_path" + local total_bytes="$(unzip -lq $zip_path | tail -1 | xargs | cut -d' ' -f1)" + unzip -p $zip_path | pv -s $total_bytes > $bin_path + rm -rf $zip_path + cleanup_path="" + fi +} + +echo "downloading recovery image" +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 + +echo "building debian rootfs" +./build_rootfs.sh $rootfs_dir bookworm \ + hostname=shimboot-$board \ + root_passwd=root \ + username=user \ + user_passwd=user + +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" +./build.sh $final_image $shim_bin data/rootfs +echo "build complete! the final disk image is located at $final_image" + +if [ "${args['compress_img']}" ]; then + image_zip="$base_dir/data/shimboot_$board.zip" + echo "compressing disk image into a zip file" + zip -j $image_zip $final_image + echo "finished compressing the disk file" + echo "the finished zip file can be found at $image_zip" +fi \ No newline at end of file diff --git a/build_rootfs.sh b/build_rootfs.sh index d1dc2b6..30e8af9 100755 --- a/build_rootfs.sh +++ b/build_rootfs.sh @@ -7,55 +7,56 @@ if [ "$DEBUG" ]; then set -x fi -print_help() { - echo "Usage: ./build_rootfs.sh rootfs_path release_name [custom_packages]" -} - -check_deps() { - local needed_commands="realpath debootstrap" - for command in $needed_commands; do - if ! command -v $command &> /dev/null; then - echo $command - fi - done -} +. ./common.sh if [ "$EUID" -ne 0 ]; then - echo "this needs to be run as root." + echo "This script must be run as root." exit 1 fi if [ -z "$2" ]; then - print_help + 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." 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 +assert_deps "realpath debootstrap" +parse_args "$@" rootfs_dir=$(realpath "${1}") release_name="${2}" -packages="${3-'task-xfce-desktop'}" +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 +} debootstrap --arch amd64 $release_name $rootfs_dir http://deb.debian.org/debian/ cp -ar rootfs/* $rootfs_dir cp /etc/resolv.conf $rootfs_dir/etc/resolv.conf -chroot_mounts="proc sys dev run" +trap unmount_all EXIT for mountpoint in $chroot_mounts; do mount --make-rslave --rbind "/${mountpoint}" "${rootfs_dir}/$mountpoint" done -chroot_command="/opt/setup_rootfs.sh '$DEBUG' '$release_name' '$packages'" -chroot $rootfs_dir /bin/bash -c "${chroot_command}" +hostname="${args['hostname']}" +root_passwd="${args['root_passwd']}" +username="${args['username']}" +user_passwd="${args['user_passwd']}" -for mountpoint in $chroot_mounts; do - umount -l "${rootfs_dir}/$mountpoint" -done +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 echo "rootfs has been created" \ No newline at end of file diff --git a/common.sh b/common.sh new file mode 100755 index 0000000..ae71d56 --- /dev/null +++ b/common.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +check_deps() { + local needed_commands="$1" + for command in $needed_commands; do + if ! command -v $command &> /dev/null; then + echo $command + fi + done +} + +assert_deps() { + local needed_commands="$1" + local missing_commands=$(check_deps "$needed_commands") + if [ "${missing_commands}" ]; then + echo "You are missing dependencies needed for this script." + echo "Commands needed:" + echo "${missing_commands}" + exit 1 + fi +} + +parse_args() { + declare -g -A args + for argument in "$@"; do + local key=$(echo $argument | cut -f1 -d=) + local key_length=${#key} + local value="${argument:$key_length+1}" + args["$key"]="$value" + done +} \ No newline at end of file diff --git a/rootfs/opt/setup_rootfs.sh b/rootfs/opt/setup_rootfs.sh index a28df18..f2c6279 100755 --- a/rootfs/opt/setup_rootfs.sh +++ b/rootfs/opt/setup_rootfs.sh @@ -3,19 +3,26 @@ #setup the debian rootfs #this is meant to be run within the chroot created by debootstrap -DEBUG="$1" -release_name="$2" -packages="$3" - set -e if [ "$DEBUG" ]; then set -x fi +DEBUG="$1" +release_name="$2" +packages="$3" + +hostname="$4" +root_passwd="$5" +username="$6" +user_passwd="$7" + custom_repo="https://shimboot.ading.dev/debian" custom_repo_domain="shimboot.ading.dev" sources_entry="deb [trusted=yes arch=amd64] ${custom_repo} ${release_name} main" +export DEBIAN_FRONTEND=noninteractive + #add shimboot repos echo -e "${sources_entry}\n$(cat /etc/apt/sources.list)" > /etc/apt/sources.list tee -a /etc/apt/preferences << END @@ -43,7 +50,9 @@ PERCENT=50 END #set up hostname and username -read -p "Enter the hostname for the system: " hostname +if [ ! "$hostname" ]; then + read -p "Enter the hostname for the system: " hostname +fi echo "${hostname}" > /etc/hostname tee -a /etc/hosts << END 127.0.0.1 localhost @@ -56,16 +65,27 @@ ff02::2 ip6-allrouters END echo "Enter a root password:" -while ! passwd root; do - echo "Failed to set password, please try again." -done +if [ ! "$root_passwd" ]; then + while ! passwd root; do + echo "Failed to set password, please try again." + done +else + yes "$root_passwd" | passwd root +fi -read -p "Enter the username for the user account: " username +if [ ! $username ]; then + read -p "Enter the username for the user account: " username +fi useradd -m -s /bin/bash -G sudo $username -echo "Enter the password for ${username}:" -while ! passwd $username; do - echo "Failed to set password, please try again." -done + +if [ ! "$user_passwd" ]; then + echo "Enter the password for ${username}:" + while ! passwd $username; do + echo "Failed to set password, please try again." + done +else + yes "$user_passwd" | passwd $username +fi #clean apt caches apt-get clean \ No newline at end of file From 73a2a386984ef90b2d1ef6b62379e26f9f588daa Mon Sep 17 00:00:00 2001 From: ading2210 Date: Thu, 25 Jan 2024 21:12:20 +0000 Subject: [PATCH 2/7] 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" From 922eccba4250ec133df0284977dd1e702bf3141e Mon Sep 17 00:00:00 2001 From: ading2210 Date: Thu, 25 Jan 2024 21:19:25 +0000 Subject: [PATCH 3/7] github actions related fixes --- .github/workflows/build-rootfs.yaml | 8 +++++++- build.sh | 6 +++--- build_complete.sh | 6 +++--- build_squashfs.sh | 6 +++--- image_utils.sh | 16 ++++++++-------- patch_rootfs.sh | 16 ++++++++-------- 6 files changed, 32 insertions(+), 26 deletions(-) diff --git a/.github/workflows/build-rootfs.yaml b/.github/workflows/build-rootfs.yaml index 4bd8f92..0667baa 100644 --- a/.github/workflows/build-rootfs.yaml +++ b/.github/workflows/build-rootfs.yaml @@ -1,6 +1,12 @@ name: build-rootfs run-name: Build the base Debian rootfs on: [push] + +defaults: + run: + shell: bash + working-directory: ./ + jobs: main: runs-on: ubuntu-latest @@ -17,7 +23,7 @@ jobs: 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 ./ + run: sudo tar -vcf data/rootfs.tar.gz -C data/rootfs ./ - name: upload rootfs uses: actions/upload-artifact@v4 diff --git a/build.sh b/build.sh index ed42cf0..dc7b4cf 100755 --- a/build.sh +++ b/build.sh @@ -27,9 +27,9 @@ fi . ./common.sh assert_deps "cpio binwalk pcregrep realpath cgpt mkfs.ext4 mkfs.ext2 fdisk rsync" -output_path=$(realpath "${1}") -shim_path=$(realpath "${2}") -rootfs_dir=$(realpath "${3}") +output_path=$(realpath -m "${1}") +shim_path=$(realpath -m "${2}") +rootfs_dir=$(realpath -m "${3}") echo "created loop device for shim" shim_loop=$(create_loop "${shim_path}") diff --git a/build_complete.sh b/build_complete.sh index 3c1f41e..2220268 100755 --- a/build_complete.sh +++ b/build_complete.sh @@ -41,7 +41,7 @@ sigint_handler() { } trap sigint_handler SIGINT -base_dir="$(realpath $(dirname "$0"))" +base_dir="$(realpath -m $(dirname "$0"))" board="$1" shim_url="https://dl.osu.bio/api/raw/?path=/SH1mmer/$board.zip" boards_url="https://chromiumdash.appspot.com/cros/fetch_serving_builds?deviceCategory=ChromeOS" @@ -90,7 +90,7 @@ echo "downloading shim image" download_and_unzip $shim_url $shim_zip $shim_bin if [ ! "${args['rootfs_dir']}" ]; then - rootfs_dir="$(realpath data/rootfs_$board)" + rootfs_dir="$(realpath -m data/rootfs_$board)" rm -rf $rootfs_dir mkdir -p $rootfs_dir @@ -101,7 +101,7 @@ if [ ! "${args['rootfs_dir']}" ]; then username=user \ user_passwd=user else - rootfs_dir="$(realpath "${args['rootfs_dir']}")" + rootfs_dir="$(realpath -m "${args['rootfs_dir']}")" fi echo "patching debian rootfs" diff --git a/build_squashfs.sh b/build_squashfs.sh index e3a7d6b..2efab18 100755 --- a/build_squashfs.sh +++ b/build_squashfs.sh @@ -47,9 +47,9 @@ compile_unionfs() { cd $original_dir } -rootfs_dir=$(realpath $1) -old_dir=$(realpath $2) -shim_path=$(realpath $3) +rootfs_dir=$(realpath -m $1) +old_dir=$(realpath -m $2) +shim_path=$(realpath -m $3) shim_rootfs="/tmp/shim_rootfs" root_squashfs="$rootfs_dir/root.squashfs" diff --git a/image_utils.sh b/image_utils.sh index 76b0122..5f5f9a0 100755 --- a/image_utils.sh +++ b/image_utils.sh @@ -17,7 +17,7 @@ make_bootable() { } partition_disk() { - local image_path=$(realpath "${1}") + local image_path=$(realpath -m "${1}") local bootloader_size=${2} #create partition table with fdisk @@ -72,8 +72,8 @@ safe_mount() { } create_partitions() { - local image_loop=$(realpath "${1}") - local kernel_path=$(realpath "${2}") + local image_loop=$(realpath -m "${1}") + local kernel_path=$(realpath -m "${2}") #create stateful mkfs.ext4 "${image_loop}p1" @@ -87,9 +87,9 @@ create_partitions() { } populate_partitions() { - local image_loop=$(realpath "${1}") - local bootloader_dir=$(realpath "${2}") - local rootfs_dir=$(realpath "${3}") + local image_loop=$(realpath -m "${1}") + local bootloader_dir=$(realpath -m "${2}") + local rootfs_dir=$(realpath -m "${3}") #mount and write empty file to stateful local stateful_mount=/tmp/shim_stateful @@ -113,7 +113,7 @@ populate_partitions() { } create_image() { - local image_path=$(realpath "${1}") + local image_path=$(realpath -m "${1}") local bootloader_size=${2} local rootfs_size=${3} @@ -126,7 +126,7 @@ create_image() { } patch_initramfs() { - local initramfs_path=$(realpath $1) + local initramfs_path=$(realpath -m $1) rm "${initramfs_path}/init" -f cp -r bootloader/* "${initramfs_path}/" diff --git a/patch_rootfs.sh b/patch_rootfs.sh index 1aca979..101b19a 100755 --- a/patch_rootfs.sh +++ b/patch_rootfs.sh @@ -24,9 +24,9 @@ if [ -z "$3" ]; then fi copy_modules() { - local shim_rootfs=$(realpath $1) - local reco_rootfs=$(realpath $2) - local target_rootfs=$(realpath $3) + local shim_rootfs=$(realpath -m $1) + local reco_rootfs=$(realpath -m $2) + local target_rootfs=$(realpath -m $3) rm -rf "${target_rootfs}/lib/modules" cp -r "${shim_rootfs}/lib/modules" "${target_rootfs}/lib/modules" @@ -43,7 +43,7 @@ copy_modules() { copy_firmware() { local firmware_path="/tmp/chromium-firmware" - local target_rootfs=$(realpath $1) + local target_rootfs=$(realpath -m $1) if [ ! -e "$firmware_path" ]; then download_firmware $firmware_path @@ -54,14 +54,14 @@ copy_firmware() { download_firmware() { local firmware_url="https://chromium.googlesource.com/chromiumos/third_party/linux-firmware" - local firmware_path=$(realpath $1) + local firmware_path=$(realpath -m $1) git clone --branch master --depth=1 "${firmware_url}" $firmware_path } -shim_path=$(realpath $1) -reco_path=$(realpath $2) -target_rootfs=$(realpath $3) +shim_path=$(realpath -m $1) +reco_path=$(realpath -m $2) +target_rootfs=$(realpath -m $3) shim_rootfs="/tmp/shim_rootfs" reco_rootfs="/tmp/reco_rootfs" From 91f719d8124222fdeeb9b4334aa314e69de085a3 Mon Sep 17 00:00:00 2001 From: ading2210 Date: Thu, 25 Jan 2024 22:13:19 +0000 Subject: [PATCH 4/7] add action to build image --- .github/workflows/build-image.yaml | 43 +++++++++++++++++++++++++++++ .github/workflows/build-rootfs.yaml | 4 +-- 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/build-image.yaml diff --git a/.github/workflows/build-image.yaml b/.github/workflows/build-image.yaml new file mode 100644 index 0000000..53d0f4d --- /dev/null +++ b/.github/workflows/build-image.yaml @@ -0,0 +1,43 @@ +name: build-image +run-name: Build the shimboot disk image for all boards +on: [push] + +jobs: + main: + strategy: + matrix: + board: [dedede, octopus] + + runs-on: ubuntu-latest + steps: + - name: wait for rootfs build to finish + uses: lewagon/wait-on-check-action@v1.3.3 + with: + ref: ${{ github.ref }} + running-workflow-name: build-rootfs + repo-token: ${{ secrets.GITHUB_TOKEN }} + wait-interval: 10 + + - name: download repo + uses: actions/checkout@v4 + + - name: download rootfs + uses: actions/download-artifact@v4 + with: + name: rootfs_tar + path: data/rootfs.tar.gz + + - name: extract rootfs + run: | + sudo mkdir -p data/rootfs + sudo tar -xvf data/rootfs.tar.gz -C data/rootfs + + - name: run build + run: sudo DEBUG=1 ./build_complete.sh ${{ matrix.board }} compress_img=1 rootfs_dir=./data/rootfs + + - name: upload img + uses: actions/upload-artifact@v4 + with: + name: shimboot_${{ matrix.board }} + path: data/shimboot_${{ matrix.board }}.zip + compression-level: 0 \ No newline at end of file diff --git a/.github/workflows/build-rootfs.yaml b/.github/workflows/build-rootfs.yaml index 0667baa..c0a2e38 100644 --- a/.github/workflows/build-rootfs.yaml +++ b/.github/workflows/build-rootfs.yaml @@ -19,7 +19,6 @@ jobs: 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 @@ -29,4 +28,5 @@ jobs: uses: actions/upload-artifact@v4 with: name: rootfs_tar - path: data/rootfs.tar.gz \ No newline at end of file + path: data/rootfs.tar.gz + compression-level: 0 \ No newline at end of file From 9a4b78d8816141b5a40d171f98239d522f57850c Mon Sep 17 00:00:00 2001 From: ading2210 Date: Thu, 25 Jan 2024 22:33:27 +0000 Subject: [PATCH 5/7] use single workflow instead --- .github/workflows/build-image.yaml | 21 +------------------ .github/workflows/build-rootfs.yaml | 32 ----------------------------- 2 files changed, 1 insertion(+), 52 deletions(-) delete mode 100644 .github/workflows/build-rootfs.yaml diff --git a/.github/workflows/build-image.yaml b/.github/workflows/build-image.yaml index 53d0f4d..91cf0ef 100644 --- a/.github/workflows/build-image.yaml +++ b/.github/workflows/build-image.yaml @@ -10,30 +10,11 @@ jobs: runs-on: ubuntu-latest steps: - - name: wait for rootfs build to finish - uses: lewagon/wait-on-check-action@v1.3.3 - with: - ref: ${{ github.ref }} - running-workflow-name: build-rootfs - repo-token: ${{ secrets.GITHUB_TOKEN }} - wait-interval: 10 - - name: download repo uses: actions/checkout@v4 - - - name: download rootfs - uses: actions/download-artifact@v4 - with: - name: rootfs_tar - path: data/rootfs.tar.gz - - - name: extract rootfs - run: | - sudo mkdir -p data/rootfs - sudo tar -xvf data/rootfs.tar.gz -C data/rootfs - name: run build - run: sudo DEBUG=1 ./build_complete.sh ${{ matrix.board }} compress_img=1 rootfs_dir=./data/rootfs + run: sudo DEBUG=1 ./build_complete.sh ${{ matrix.board }} compress_img=1 - name: upload img uses: actions/upload-artifact@v4 diff --git a/.github/workflows/build-rootfs.yaml b/.github/workflows/build-rootfs.yaml deleted file mode 100644 index c0a2e38..0000000 --- a/.github/workflows/build-rootfs.yaml +++ /dev/null @@ -1,32 +0,0 @@ -name: build-rootfs -run-name: Build the base Debian rootfs -on: [push] - -defaults: - run: - shell: bash - working-directory: ./ - -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 - run: sudo DEBUG=1 ./build_rootfs.sh data/rootfs bookworm hostname=shimboot root_passwd=root username=user user_passwd=user - - - name: archive rootfs - run: sudo 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 - compression-level: 0 \ No newline at end of file From 8e51654190d0693e6bb50f99df3f36203b81090c Mon Sep 17 00:00:00 2001 From: ading2210 Date: Thu, 25 Jan 2024 23:08:00 +0000 Subject: [PATCH 6/7] misc build script bugfixes --- .github/workflows/build-image.yaml | 2 +- build_complete.sh | 24 +++++++++++++++++------- image_utils.sh | 2 +- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build-image.yaml b/.github/workflows/build-image.yaml index 91cf0ef..5e7e9a7 100644 --- a/.github/workflows/build-image.yaml +++ b/.github/workflows/build-image.yaml @@ -14,7 +14,7 @@ jobs: uses: actions/checkout@v4 - name: run build - run: sudo DEBUG=1 ./build_complete.sh ${{ matrix.board }} compress_img=1 + run: sudo DEBUG=1 ./build_complete.sh ${{ matrix.board }} compress_img=1 quiet_download=1 - name: upload img uses: actions/upload-artifact@v4 diff --git a/build_complete.sh b/build_complete.sh index 2220268..56bc65d 100755 --- a/build_complete.sh +++ b/build_complete.sh @@ -16,18 +16,19 @@ fi 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." + 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." + echo " quiet_download - Don't use progress bars on downloads." 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 +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 + apt-get install wget python3-all unzip zip debootstrap cpio binwalk pcregrep cgpt rsync pv -y fi assert_deps "$needed_deps" fi @@ -71,13 +72,22 @@ download_and_unzip() { local zip_path="$2" local bin_path="$3" if [ ! -f "$bin_path" ]; then - wget -q --show-progress $url -O $zip_path -c + if [ ! "${args['quiet_download']}" ]; then + wget -q --show-progress $url -O $zip_path -c + else + wget -q $url -O $zip_path -c + fi fi + if [ ! -f "$bin_path" ]; then cleanup_path="$bin_path" echo "extracting $zip_path" local total_bytes="$(unzip -lq $zip_path | tail -1 | xargs | cut -d' ' -f1)" - unzip -p $zip_path | pv -s $total_bytes > $bin_path + if [ ! "${args['quiet_download']}" ]; then + unzip -p $zip_path | pv -s $total_bytes > $bin_path + else + unzip -p $zip_path > $bin_path + fi rm -rf $zip_path cleanup_path="" fi @@ -110,7 +120,7 @@ echo "patching debian rootfs" 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 +./build.sh $final_image $shim_bin $rootfs_dir echo "build complete! the final disk image is located at $final_image" if [ "${args['compress_img']}" ]; then diff --git a/image_utils.sh b/image_utils.sh index 5f5f9a0..fb6d241 100755 --- a/image_utils.sh +++ b/image_utils.sh @@ -68,7 +68,7 @@ safe_mount() { umount $2 2> /dev/null || /bin/true rm -rf $2 mkdir -p $2 - mount $1 $2 + mount $1 $2 || mount $1 $2 || mount $1 $2 || mount $1 $2 #try to mount multiple times } create_partitions() { From d6ffc7d9be8782db6061bcfe56957e9f425582b8 Mon Sep 17 00:00:00 2001 From: ading2210 Date: Thu, 25 Jan 2024 23:46:10 +0000 Subject: [PATCH 7/7] create release automatically --- .github/workflows/build-image.yaml | 11 +++++++++-- image_utils.sh | 3 ++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-image.yaml b/.github/workflows/build-image.yaml index 5e7e9a7..516b898 100644 --- a/.github/workflows/build-image.yaml +++ b/.github/workflows/build-image.yaml @@ -3,7 +3,7 @@ run-name: Build the shimboot disk image for all boards on: [push] jobs: - main: + build: strategy: matrix: board: [dedede, octopus] @@ -21,4 +21,11 @@ jobs: with: name: shimboot_${{ matrix.board }} path: data/shimboot_${{ matrix.board }}.zip - compression-level: 0 \ No newline at end of file + compression-level: 0 + + - name: create release + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + draft: true + files: data/shimboot_${{ matrix.board }}.zip \ No newline at end of file diff --git a/image_utils.sh b/image_utils.sh index fb6d241..0ef193a 100755 --- a/image_utils.sh +++ b/image_utils.sh @@ -68,7 +68,8 @@ safe_mount() { umount $2 2> /dev/null || /bin/true rm -rf $2 mkdir -p $2 - mount $1 $2 || mount $1 $2 || mount $1 $2 || mount $1 $2 #try to mount multiple times + #try to mount multiple times + mount $1 $2 || mount $1 $2 || mount $1 $2 || mount $1 $2 } create_partitions() {