2024-07-11 20:22:11 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
IMAGE_ARCH="e2kv6" # possible values are e2k, e2kv4, e2kv5, e2kv6
|
|
|
|
IMAGE_VERSION="20240705"
|
|
|
|
IMAGE_PATH="/ALTLinux/images/Sisyphus/docker/docker-$IMAGE_VERSION-$IMAGE_ARCH.tar.xz"
|
|
|
|
MIRRORS=("http://elbrus.ivk.ru/pub" "http://setwd.ws/altlinux")
|
|
|
|
|
|
|
|
QEMU_BUILD_FLAGS="--disable-werror --disable-pie"
|
|
|
|
QEMU_BRANCH="e2k-v8.1.3"
|
|
|
|
|
|
|
|
CHROOT_DIR="chroot-$IMAGE_ARCH"
|
|
|
|
|
|
|
|
BINFMT_REGISTER_FLAGS=""
|
|
|
|
|
|
|
|
# this is taken from qemu's binfmt set up script because I don't want to pollute
|
|
|
|
# binfmt_misc with unrelated stuff
|
|
|
|
e2k_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xaf\x00'
|
|
|
|
e2k_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
|
|
|
|
e2k_old_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x31\x00'
|
|
|
|
e2k_old_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
|
|
|
|
qemu_target_list="e2k e2k_old"
|
|
|
|
|
|
|
|
if ! command -v git > /dev/null; then
|
|
|
|
echo "To build qemu-e2k, we need to clone git repository. Install git."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! command -v xz > /dev/null; then
|
|
|
|
echo "To unpack ALTLinux Docker image, we need xz. Install it."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! command -v wget > /dev/null; then
|
|
|
|
echo "To download ALTLinux Docker image, we need wget. Install it."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-07-11 20:36:39 +02:00
|
|
|
if [ "$(uname -m)" == "e2k" ]; then
|
2024-07-11 20:22:11 +02:00
|
|
|
echo "This script is for emulating Elbrus and you're already running on this architecture"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "WARNING: this script just set ups basic chroot to play with."
|
|
|
|
echo "Do not use this in production!\n"
|
|
|
|
echo "During installation, you will be asked for root access to properly"
|
|
|
|
echo "unpack image and install binfmt_misc rule\n"
|
|
|
|
read -p "Did you read and understood the message above? [Yn] " yn
|
|
|
|
|
|
|
|
case $yn in
|
2024-07-11 20:36:39 +02:00
|
|
|
[yY|""] ) echo "Continuing..."; ;;
|
2024-07-11 20:22:11 +02:00
|
|
|
[nN] ) echo "Exiting"; exit 0;;
|
|
|
|
[*] ) echo "Unrecognized answer"; exit 1;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
set -x
|
|
|
|
|
|
|
|
git clone https://git.mentality.rip/OpenE2K/qemu-e2k -b $QEMU_BRANCH --depth=1 || exit 2
|
2024-07-11 20:36:39 +02:00
|
|
|
pushd qemu-e2k || exit 2
|
|
|
|
./configure --target-list=e2k-linux-user --static $QEMU_BUILD_FLAGS || exit 2
|
|
|
|
make -j$(nproc) || exit 2
|
|
|
|
popd || exit 2
|
2024-07-11 20:22:11 +02:00
|
|
|
|
2024-07-11 20:36:39 +02:00
|
|
|
for i in "${MIRRORS[@]}"; do
|
2024-07-11 20:22:11 +02:00
|
|
|
echo -n "Probing mirror $i..."
|
2024-07-11 20:36:39 +02:00
|
|
|
if wget -q -O/dev/null "$i"; then
|
2024-07-11 20:22:11 +02:00
|
|
|
SELECTED_MIRROR=$i
|
|
|
|
|
|
|
|
echo "OK"
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
echo "BAD"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2024-07-11 20:36:39 +02:00
|
|
|
if [ -z "$SELECTED_MIRROR" ]; then
|
2024-07-11 20:22:11 +02:00
|
|
|
echo "Can't find working mirror, exiting..."
|
2024-07-11 20:36:39 +02:00
|
|
|
exit 2
|
2024-07-11 20:22:11 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
qemu_register_interpreter() {
|
|
|
|
echo "Setting $qemu as binfmt interpreter for $cpu"
|
2024-07-11 20:36:39 +02:00
|
|
|
qemu_generate_register | sudo tee /proc/sys/fs/binfmt_misc/register || exit 2
|
2024-07-11 20:22:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
qemu_generate_register() {
|
|
|
|
flags="${BINFMT_REGISTER_FLAGS}"
|
|
|
|
|
|
|
|
echo ":qemu-$cpu:M::$magic:$mask:$qemu:$flags"
|
|
|
|
}
|
|
|
|
|
2024-07-11 20:36:39 +02:00
|
|
|
wget -Odocker.txz "$SELECTED_MIRROR$IMAGE_PATH"
|
2024-07-11 20:22:11 +02:00
|
|
|
mkdir -p $CHROOT_DIR || exit 2
|
|
|
|
pushd $CHROOT_DIR
|
|
|
|
sudo tar -xJf ../docker.txz || exit 2
|
2024-07-11 20:36:39 +02:00
|
|
|
sudo cp ../qemu-e2k/build/qemu-e2k usr/bin || exit 2
|
2024-07-11 20:22:11 +02:00
|
|
|
|
|
|
|
# Change default mirror in case if ivk is unreachable (it's kinda stupid to block non-Russian IP addresses, isn't it?)
|
2024-07-11 20:36:39 +02:00
|
|
|
if [ "$SELECTED_MIRROR" != "http://elbrus.ivk.ru/pub" ]; then
|
2024-07-11 20:22:11 +02:00
|
|
|
sed "s|http://elbrus.ivk.ru/pub|$SELECTED_MIRROR|g" etc/apt/sources.list.d/ivk.list | sudo tee etc/apt/sources.list.d/mirror.list
|
|
|
|
|
|
|
|
sudo mv etc/apt/sources.list.d/ivk.list etc/apt/sources.list.d/ivk.list.disabled
|
|
|
|
fi
|
|
|
|
|
|
|
|
sudo cp /etc/resolv.conf etc/resolv.conf
|
|
|
|
|
|
|
|
for cpu in ${qemu_target_list} ; do
|
|
|
|
qemu="/usr/bin/qemu-e2k"
|
|
|
|
magic=$(eval echo \$${cpu}_magic)
|
|
|
|
mask=$(eval echo \$${cpu}_mask)
|
|
|
|
qemu_register_interpreter
|
|
|
|
done
|
2024-07-11 20:36:39 +02:00
|
|
|
popd || exit 2
|
2024-07-11 20:22:11 +02:00
|
|
|
|
|
|
|
set +x
|
|
|
|
|
|
|
|
echo "All done."
|
|
|
|
echo "Keep in mind, it's up to you to set up binfmt_misc so it doesn't get lost between reboots"
|
|
|
|
echo "Now you can do 'sudo chroot $CHROOT_DIR /bin/bash' and have some fun!"
|