#!/bin/sh
#
#   cbfstool_get.sh: wgets the sources and makes a cbfstool utility.
#
#      Please send your feedback to Mike Banon <mikebdp2@gmail.com>.
#   Released under the terms of GNU GPL v3 by Free Software Foundation.
#

wget --recursive --no-parent --no-host-directories --cut-dirs=3 \
--user-agent="Mozilla/5.0" --execute robots=off \
--directory-prefix=./3rdparty/vboot/ \
https://review.coreboot.org/cgit/vboot.git/plain/cgpt/ \
--reject=cgpt.c,cgpt_legacy.c,cgpt_repair.c,cgpt_wrapper.c,\
cmd_add.c,cmd_boot.c,cmd_create.c,cmd_edit.c,cmd_find.c,\
cmd_legacy.c,cmd_prioritize.c,cmd_repair.c,cmd_show.c

wget --recursive --no-parent --no-host-directories --cut-dirs=3 \
--user-agent="Mozilla/5.0" --execute robots=off \
--directory-prefix=./3rdparty/vboot/ \
https://review.coreboot.org/cgit/vboot.git/plain/firmware/2lib/ \
--reject=2api.c,2auxfw_sync.c,2ec_sync.c,2firmware.c,2gbb.c,2misc.c,\
2packed_key.c,2secdata_firmware.c,2secdata_fwmp.c,2secdata_kernel.c,\
2tpm_bootmode.c,2ui.c,2ui_screens.c,2tpm_bootmode.h,2ui.h,2ui_private.h

wget --recursive --no-parent --no-host-directories --cut-dirs=3 \
--user-agent="Mozilla/5.0" --execute robots=off \
--directory-prefix=./3rdparty/vboot/ \
https://review.coreboot.org/cgit/vboot.git/plain/firmware/include/ \
--reject=OWNERS,tpm2_marshaling.h,tpm2_tss_constants.h,vb2_api.h,\
vb2_constants.h,vb2_internals_please_do_not_use.h

wget --recursive --no-parent --no-host-directories --cut-dirs=3 \
--user-agent="Mozilla/5.0" --execute robots=off \
--directory-prefix=./3rdparty/vboot/ \
https://review.coreboot.org/cgit/vboot.git/plain/firmware/lib/ \
--exclude-directories=/cgit/vboot.git/plain/firmware/lib/tpm2_lite/

wget --recursive --no-parent --no-host-directories --cut-dirs=3 \
--user-agent="Mozilla/5.0" --execute robots=off \
--directory-prefix=./3rdparty/vboot/ \
https://review.coreboot.org/cgit/vboot.git/plain/firmware/lib20/include/vb2_common.h

wget --recursive --no-parent --no-host-directories --cut-dirs=3 \
--user-agent="Mozilla/5.0" --execute robots=off \
--directory-prefix=./3rdparty/vboot/ \
https://review.coreboot.org/cgit/vboot.git/plain/firmware/stub/ \
--reject=OWNERS

wget --recursive --no-parent --no-host-directories --cut-dirs=3 \
--user-agent="Mozilla/5.0" --execute robots=off \
--directory-prefix=./3rdparty/vboot/ \
https://review.coreboot.org/cgit/vboot.git/plain/futility/dump_kernel_config_lib.c

wget --recursive --no-parent --no-host-directories --cut-dirs=3 \
--user-agent="Mozilla/5.0" --execute robots=off \
--directory-prefix=./3rdparty/vboot/ \
https://review.coreboot.org/cgit/vboot.git/plain/futility/futility.h

wget --recursive --no-parent --no-host-directories --cut-dirs=3 \
--user-agent="Mozilla/5.0" --execute robots=off \
--directory-prefix=./3rdparty/vboot/ \
https://review.coreboot.org/cgit/vboot.git/plain/futility/kernel_blob.h

wget --recursive --no-parent --no-host-directories --cut-dirs=3 \
--user-agent="Mozilla/5.0" --execute robots=off \
--directory-prefix=./3rdparty/vboot/ \
https://review.coreboot.org/cgit/vboot.git/plain/host/ \
--exclude-directories=/cgit/vboot.git/plain/host/arch/

wget --recursive --no-parent --no-host-directories --cut-dirs=3 \
--user-agent="Mozilla/5.0" --execute robots=off \
--directory-prefix=./3rdparty/vboot/ \
https://review.coreboot.org/cgit/vboot.git/plain/host/arch/x86/lib/crossystem_arch.c

wget --recursive --no-parent --no-host-directories --cut-dirs=3 \
--user-agent="Mozilla/5.0" --execute robots=off \
--directory-prefix=./3rdparty/vboot/ \
https://review.coreboot.org/cgit/vboot.git/plain/host/arch/x86_64/lib/crossystem_arch.c

cp ./3rdparty/vboot/host/arch/x86/lib/crossystem_arch.c \
./3rdparty/vboot/host/arch/x86_64/lib/crossystem_arch.c

wget --recursive --no-parent --no-host-directories --cut-dirs=3 \
--user-agent="Mozilla/5.0" --execute robots=off \
--directory-prefix=./3rdparty/vboot/ \
https://review.coreboot.org/cgit/vboot.git/plain/Makefile

wget --recursive --no-parent --no-host-directories --cut-dirs=3 \
--user-agent="Mozilla/5.0" --execute robots=off \
https://review.coreboot.org/cgit/coreboot.git/plain/src/commonlib/ \
--exclude-directories=/cgit/coreboot.git/plain/src/commonlib/storage/ \
--reject=configstring.c,iobuf.c,cbmem_id.h,configstring.h,coreboot_tables.h,\
fmap_serialized.h,iobuf.h,sd_mmc_ctrlr.h,sdhci.h,stdlib.h,storage.h,\
timestamp_serialized.h

wget --recursive --no-parent --no-host-directories --cut-dirs=3 \
--user-agent="Mozilla/5.0" --execute robots=off \
https://review.coreboot.org/cgit/coreboot.git/plain/src/vendorcode/intel/edk2/uefi_2.4/

wget --recursive --no-parent --no-host-directories --cut-dirs=3 \
--user-agent="Mozilla/5.0" --execute robots=off \
https://review.coreboot.org/cgit/coreboot.git/plain/src/vendorcode/intel/fsp/fsp1_1/IntelFspPkg/Include/FspInfoHeader.h

wget --recursive --no-parent --no-host-directories --cut-dirs=3 \
--user-agent="Mozilla/5.0" --execute robots=off \
https://review.coreboot.org/cgit/coreboot.git/plain/util/cbfstool/

wget --recursive --no-parent --no-host-directories --cut-dirs=3 \
--user-agent="Mozilla/5.0" --execute robots=off \
https://review.coreboot.org/cgit/coreboot.git/plain/util/vboot_lib/

mkdir ./3rdparty/vboot/tests/
mkdir ./3rdparty/vboot/tests/tpm_lite/
mkdir ./3rdparty/vboot/utility/

cd ./util/cbfstool/

make all

cd ./../../

ln -s ./util/cbfstool/cbfstool ./cbfstool

#
