build_fn: Fix build in alpine chroot
This commit is contained in:
parent
3d4593bed5
commit
79ad8d8aba
|
@ -1,5 +1,7 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
require "wget"
|
||||||
|
|
||||||
get_image_path()
|
get_image_path()
|
||||||
{
|
{
|
||||||
printf "%s" "$(realpath "./raw/${1}.img")"
|
printf "%s" "$(realpath "./raw/${1}.img")"
|
||||||
|
@ -34,7 +36,7 @@ create_image()
|
||||||
rm "$name"
|
rm "$name"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
truncate --size "$size" "$name" || {
|
truncate -s "$size" "$name" || {
|
||||||
log "Failed to cretae image [$name]" ierror
|
log "Failed to cretae image [$name]" ierror
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
@ -119,24 +121,26 @@ prepare_chroot()
|
||||||
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:\$PATH
|
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:\$PATH
|
||||||
rootdir="$(realpath "$1")"
|
rootdir="$(realpath "$1")"
|
||||||
|
|
||||||
mount --bind /proc "$rootdir/proc" > /dev/null 2>&1
|
mount -t proc proc "$rootdir/proc" > /dev/null 2>&1
|
||||||
mount --bind /sys "$rootdir/sys" > /dev/null 2>&1
|
mount -t sysfs sysfs "$rootdir/sys" > /dev/null 2>&1
|
||||||
mount --bind /dev "$rootdir/dev" > /dev/null 2>&1
|
mount -t devtmpfs devtmpfs "$rootdir/dev" > /dev/null 2>&1
|
||||||
mount --bind /dev/pts "$rootdir/dev/pts" > /dev/null 2>&1
|
mount -t devpts devpts "$rootdir/dev/pts" > /dev/null 2>&1
|
||||||
|
mount -t tmpfs devshm "$rootdir/dev/shm" > /dev/null 2>&1
|
||||||
|
|
||||||
if uname -m | grep -q aarch64 || [ -f "/proc/sys/fs/binfmt_misc/qemu-aarch64" ]; then
|
if uname -m | grep -q aarch64 || [ -f "/proc/sys/fs/binfmt_misc/qemu-aarch64" ]; then
|
||||||
log "Cancel qemu install for arm64" internal
|
log "Cancel qemu install for arm64" internal
|
||||||
else
|
else
|
||||||
wget -N https://github.com/multiarch/qemu-user-static/releases/download/v7.2.0-1/qemu-aarch64-static -O ./cache/qemu-aarch64-static
|
wget -q --show-progress -N https://github.com/multiarch/qemu-user-static/releases/download/v7.2.0-1/qemu-aarch64-static -O ./cache/qemu-aarch64-static
|
||||||
install -m755 ./cache/qemu-aarch64-static "$rootdir/"
|
install -m755 ./cache/qemu-aarch64-static "$rootdir/"
|
||||||
|
|
||||||
# shellcheck disable=SC2028
|
# shellcheck disable=SC2028
|
||||||
echo ':aarch64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/qemu-aarch64-static:' > /proc/sys/fs/binfmt_misc/register
|
echo ':aarch64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/qemu-aarch64-static:PF' > /proc/sys/fs/binfmt_misc/register 2> /dev/null
|
||||||
|
|
||||||
# shellcheck disable=SC2028
|
# shellcheck disable=SC2028
|
||||||
echo ':aarch64ld:M::\x7fELF\x02\x01\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\xb7:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/qemu-aarch64-static:' > /proc/sys/fs/binfmt_misc/register
|
echo ':aarch64ld:M::\x7fELF\x02\x01\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\xb7\x00:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/qemu-aarch64-static:PF' > /proc/sys/fs/binfmt_misc/register 2> /dev/null
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
detach_chroot()
|
detach_chroot()
|
||||||
|
@ -148,28 +152,25 @@ detach_chroot()
|
||||||
}
|
}
|
||||||
|
|
||||||
rootdir=$(realpath "$1")
|
rootdir=$(realpath "$1")
|
||||||
blocking=$(lsof -t "$rootdir")
|
umount "$rootdir/proc"
|
||||||
if [ -n "$blocking" ]; then
|
umount "$rootdir/sys"
|
||||||
kill -9 "$blocking"
|
umount "$rootdir/dev/pts"
|
||||||
fi
|
umount "$rootdir/dev/shm"
|
||||||
killall gpg-agent > /dev/null 2>&1
|
umount "$rootdir/dev"
|
||||||
umount "$rootdir/proc" > /dev/null 2>&1
|
|
||||||
umount "$rootdir/sys" > /dev/null 2>&1
|
|
||||||
umount "$rootdir/dev/pts" > /dev/null 2>&1
|
|
||||||
umount "$rootdir/dev" > /dev/null 2>&1
|
|
||||||
|
|
||||||
if uname -m | grep -q aarch64; then
|
if uname -m | grep -q aarch64; then
|
||||||
log "Cancel qemu uninstall for arm64" internal
|
log "Cancel qemu uninstall for arm64" internal
|
||||||
else
|
else
|
||||||
if [ -f "/proc/sys/fs/binfmt_misc/aarch64" ]; then
|
if [ -f "/proc/sys/fs/binfmt_misc/aarch64" ]; then
|
||||||
echo -1 > /proc/sys/fs/binfmt_misc/aarch64
|
echo -1 > /proc/sys/fs/binfmt_misc/aarch64 2> /dev/null
|
||||||
fi
|
fi
|
||||||
if [ -f "/proc/sys/fs/binfmt_misc/aarch64ld" ]; then
|
if [ -f "/proc/sys/fs/binfmt_misc/aarch64ld" ]; then
|
||||||
echo -1 > /proc/sys/fs/binfmt_misc/aarch64ld
|
echo -1 > /proc/sys/fs/binfmt_misc/aarch64ld 2> /dev/null
|
||||||
fi
|
fi
|
||||||
if [ -f "$rootdir/qemu-aarch64-static" ]; then
|
if [ -f "$rootdir/qemu-aarch64-static" ]; then
|
||||||
rm "$rootdir/qemu-aarch64-static"
|
rm "$rootdir/qemu-aarch64-static"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue