2024-01-24 23:43:58 -06:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
. ./common.sh
|
|
|
|
|
2024-04-24 16:54:52 -05:00
|
|
|
print_help() {
|
2024-01-24 23:43:58 -06:00
|
|
|
echo "Usage: ./build_complete.sh board_name"
|
|
|
|
echo "Valid named arguments (specify with 'key=value'):"
|
2024-01-30 15:13:03 -06:00
|
|
|
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 - Don't use progress indicators which may clog up log files."
|
2024-04-24 16:54:52 -05:00
|
|
|
}
|
2024-01-24 23:43:58 -06:00
|
|
|
|
2024-04-24 16:54:52 -05:00
|
|
|
assert_root
|
|
|
|
assert_args "$1"
|
2024-01-25 15:12:20 -06:00
|
|
|
parse_args "$@"
|
2024-04-24 16:54:52 -05:00
|
|
|
|
2024-01-25 15:12:20 -06:00
|
|
|
needed_deps="wget python3 unzip zip git debootstrap cpio binwalk pcregrep cgpt mkfs.ext4 mkfs.ext2 fdisk rsync"
|
2024-01-25 17:08:00 -06:00
|
|
|
if [ "$(check_deps "$needed_deps")" ]; then
|
2024-01-25 15:12:20 -06:00
|
|
|
#install deps automatically on debian and ubuntu
|
|
|
|
if [ -f "/etc/debian_version" ]; then
|
|
|
|
echo "attempting to install build deps"
|
2024-01-25 17:08:00 -06:00
|
|
|
apt-get install wget python3-all unzip zip debootstrap cpio binwalk pcregrep cgpt rsync pv -y
|
2024-01-25 15:12:20 -06:00
|
|
|
fi
|
|
|
|
assert_deps "$needed_deps"
|
|
|
|
fi
|
|
|
|
|
2024-01-24 23:43:58 -06:00
|
|
|
cleanup_path=""
|
|
|
|
sigint_handler() {
|
|
|
|
if [ $cleanup_path ]; then
|
|
|
|
rm -rf $cleanup_path
|
|
|
|
fi
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
trap sigint_handler SIGINT
|
|
|
|
|
2024-01-25 15:19:25 -06:00
|
|
|
base_dir="$(realpath -m $(dirname "$0"))"
|
2024-01-24 23:43:58 -06:00
|
|
|
board="$1"
|
2024-04-25 15:13:30 -05:00
|
|
|
shim_url="https://dl.darkn.bio/api/raw/?path=/SH1mmer/$board.zip"
|
2024-01-24 23:43:58 -06:00
|
|
|
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
|
2024-01-30 15:13:03 -06:00
|
|
|
if [ ! "${args['quiet']}" ]; then
|
2024-01-25 17:08:00 -06:00
|
|
|
wget -q --show-progress $url -O $zip_path -c
|
|
|
|
else
|
|
|
|
wget -q $url -O $zip_path -c
|
|
|
|
fi
|
2024-01-24 23:43:58 -06:00
|
|
|
fi
|
2024-01-25 17:08:00 -06:00
|
|
|
|
2024-01-24 23:43:58 -06:00
|
|
|
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)"
|
2024-01-30 15:13:03 -06:00
|
|
|
if [ ! "${args['quiet']}" ]; then
|
2024-01-25 17:08:00 -06:00
|
|
|
unzip -p $zip_path | pv -s $total_bytes > $bin_path
|
|
|
|
else
|
|
|
|
unzip -p $zip_path > $bin_path
|
|
|
|
fi
|
2024-01-24 23:43:58 -06:00
|
|
|
rm -rf $zip_path
|
|
|
|
cleanup_path=""
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-01-30 16:25:45 -06:00
|
|
|
retry_cmd() {
|
|
|
|
local cmd="$@"
|
|
|
|
for i in 1 2 3 4 5; do
|
|
|
|
$cmd && break
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2024-01-24 23:43:58 -06:00
|
|
|
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
|
|
|
|
|
2024-01-25 15:12:20 -06:00
|
|
|
if [ ! "${args['rootfs_dir']}" ]; then
|
2024-01-25 15:19:25 -06:00
|
|
|
rootfs_dir="$(realpath -m data/rootfs_$board)"
|
2024-01-25 15:12:20 -06:00
|
|
|
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
|
|
|
|
else
|
2024-01-25 15:19:25 -06:00
|
|
|
rootfs_dir="$(realpath -m "${args['rootfs_dir']}")"
|
2024-01-25 15:12:20 -06:00
|
|
|
fi
|
2024-01-24 23:43:58 -06:00
|
|
|
|
|
|
|
echo "patching debian rootfs"
|
2024-01-30 16:25:45 -06:00
|
|
|
retry_cmd ./patch_rootfs.sh $shim_bin $reco_bin $rootfs_dir "quiet=${args['quiet']}"
|
2024-01-24 23:43:58 -06:00
|
|
|
|
|
|
|
echo "building final disk image"
|
|
|
|
final_image="$base_dir/data/shimboot_$board.bin"
|
2024-01-25 15:12:20 -06:00
|
|
|
rm -rf $final_image
|
2024-01-30 16:25:45 -06:00
|
|
|
retry_cmd ./build.sh $final_image $shim_bin $rootfs_dir "quiet=${args['quiet']}"
|
2024-01-24 23:43:58 -06:00
|
|
|
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
|