Add optional output_filename argument in rootfs.sh

Downloads to a particular filename, allows for different names than
whatever is upstream.
This commit is contained in:
fosslinux 2021-02-15 19:31:17 +11:00
parent 372e08e4f9
commit 44bad278e0
1 changed files with 45 additions and 49 deletions

View File

@ -8,13 +8,13 @@
set -ex set -ex
QEMU_CMD="${1:-qemu-system-x86_64}" # or 'chroot' or 'minikernel' QEMU_CMD="${1:-qemu-system-x86_64}" # or 'chroot' or 'minikernel'
QEMU_RAM="${2:-8G}" QEMU_RAM="${2:-8G}"
GITDIR="$PWD/$(dirname "$0")" GITDIR="$PWD/$(dirname "$0")"
if [ ! -f 'rootfs.sh' ]; then if [ ! -f 'rootfs.sh' ]; then
echo 'must be run from base of repo' echo 'must be run from base of repo'
exit 1 exit 1
fi fi
pushd sysa pushd sysa
@ -27,33 +27,28 @@ sudo mount -t tmpfs -o size=8G tmpfs tmp
LOGFILE="$PWD/tmp/bootstrap.log" LOGFILE="$PWD/tmp/bootstrap.log"
wget() _wget() {
{ local url="$1"
local url="$1" local dir="${CACHEDIR:-$GITDIR/sources}"
local dir="${CACHEDIR:-$GITDIR/sources}" local file="${2:-$(basename "${url}")}"
local file mkdir -p "$dir"
test -s "$dir/$file" || command wget -O "$dir/$file" "$url"
file=$(basename "$url") cp -v "$dir/$file" .
mkdir -p "$dir" checksum_do "$dir" "$file"
test -s "$dir/$file" || command wget -O "$dir/$file" "$url"
cp -v "$dir/$file" .
checksum_do "$dir" "$file"
} }
checksum_do() checksum_do() {
{ local dir="$1"
local dir="$1" local file="$2"
local file="$2" local line
local line local store="$GITDIR/SHA256SUMS.sources"
local store="$GITDIR/SHA256SUMS.sources"
if line=$(grep "[[:space:]][[:space:]]$file"$ "$store"); then if line=$(grep "[[:space:]][[:space:]]$file"$ "$store"); then
(cd "$dir" && echo "$line" | sha256sum -c) (cd "$dir" && echo "$line" | sha256sum -c)
else else
echo 'Checksum mismatch or not found!' echo 'Checksum mismatch or not found!'
exit 1 exit 1
fi fi
} }
# base: mescc-tools-seed # base: mescc-tools-seed
@ -127,11 +122,12 @@ tar -C tmp/after/tar-1.12/src -xf "tmp/after/tar-1.12/src/$(basename $url)" --st
get_file() { get_file() {
url=$1 url=$1
make_build=${2:-0} make_build=${2:-0}
output_filename=$3
ext="${url##*.}" ext="${url##*.}"
if [ "$ext" = "tar" ]; then if [ "$ext" = "tar" ]; then
bname=$(basename "$url" ".tar") bname=$(basename "${output_filename:-${url}}" ".tar")
else else
bname=$(basename "$url" ".tar.${ext}") bname=$(basename "${output_filename:-${url}}" ".tar.${ext}")
fi fi
cp -r "${bname}" tmp/after/ cp -r "${bname}" tmp/after/
target="tmp/after/${bname}" target="tmp/after/${bname}"
@ -141,7 +137,7 @@ get_file() {
fi fi
pushd "tmp/after/${bname}/src" pushd "tmp/after/${bname}/src"
if [ ! -f "$(basename "$url")" ]; then if [ ! -f "$(basename "$url")" ]; then
wget "$url" _wget "$url" "${output_filename:-${url##*/}}"
fi fi
popd popd
} }
@ -209,26 +205,26 @@ find . | cpio -H newc -o | gzip > initramfs.igz
# Run # Run
case "${QEMU_CMD}" in case "${QEMU_CMD}" in
chroot) chroot)
sudo PATH="/after/bin:${PATH}" chroot . /init | tee "$LOGFILE" sudo PATH="/after/bin:${PATH}" chroot . /init | tee "$LOGFILE"
;; ;;
minikernel) minikernel)
git clone --depth 1 --branch v0.4 https://github.com/bittorf/kritis-linux.git git clone --depth 1 --branch v0.4 https://github.com/bittorf/kritis-linux.git
kritis-linux/ci_helper.sh \ kritis-linux/ci_helper.sh \
--arch x86_64 \ --arch x86_64 \
--ramsize 4G \ --ramsize 4G \
--kernel 5.10.8 \ --kernel 5.10.8 \
--initrd initramfs.igz \ --initrd initramfs.igz \
--log "$LOGFILE" --log "$LOGFILE"
;; ;;
*) *)
${QEMU_CMD} -enable-kvm \ ${QEMU_CMD} -enable-kvm \
-m "${QEMU_RAM:-8G}" \ -m "${QEMU_RAM:-8G}" \
-nographic \ -nographic \
-no-reboot \ -no-reboot \
-kernel ../../kernel -initrd initramfs.igz -append console=ttyS0 | tee "$LOGFILE" -kernel ../../kernel -initrd initramfs.igz -append console=ttyS0 | tee "$LOGFILE"
;; ;;
esac esac
cd ../.. cd ../..