tools/run_guest_kernel.sh: Allow overriding $TMPDIR

Also use $XDG_RUNTIME_DIR by default if set

Signed-off-by: Hector Martin <marcan@marcan.st>
This commit is contained in:
Hector Martin 2022-09-12 17:46:31 +09:00
parent 281784d48e
commit 5e26ae26f8

View file

@ -1,6 +1,9 @@
#!/bin/sh
set -e
: ${TMPDIR:=$XDG_RUNTIME_DIR}
: ${TMPDIR:=/tmp}
if [ "$1" == "-k" ]; then
kernel="$(realpath "$2")"
shift 2
@ -29,23 +32,25 @@ fi
base="$(dirname "$0")"
echo "Creating m1n1+kernel image"
cp "$base"/../../build/m1n1.bin /tmp/m1n1-linux.bin
cp "$base"/../../build/m1n1.bin "$TMPDIR/m1n1-linux.bin"
if [ -n "$args" ]; then
echo "chosen.bootargs=$args" >>/tmp/m1n1-linux.bin
echo "chosen.bootargs=$args" >>"$TMPDIR/m1n1-linux.bin"
fi
cat "$kernel_base"/arch/arm64/boot/dts/apple/*.dtb >>/tmp/m1n1-linux.bin
cat "$kernel_base"/arch/arm64/boot/dts/apple/*.dtb >>"$TMPDIR/m1n1-linux.bin"
if [[ "$kernel" == *.gz ]]; then
cat "$kernel" >>/tmp/m1n1-linux.bin
cat "$kernel" >>"$TMPDIR/m1n1-linux.bin"
else
gzip -c <"$kernel" >>/tmp/m1n1-linux.bin
gzip -c <"$kernel" >>"$TMPDIR/m1n1-linux.bin"
fi
if [ -n "$initramfs" ]; then
cat "$initramfs" >>/tmp/m1n1-linux.bin
cat "$initramfs" >>"$TMPDIR/m1n1-linux.bin"
fi
echo "Chainloading to updated m1n1..."
python "$base"/chainload.py -r "$base"/../../build/m1n1.bin
echo "Starting guest..."
exec python "$base"/run_guest.py -c "load_system_map('$kernel_base/System.map')" "$@" -r /tmp/m1n1-linux.bin
exec python "$base"/run_guest.py \
-c "load_system_map('$kernel_base/System.map')" "$@" \
-r "$TMPDIR/m1n1-linux.bin"