#!/bin/bash
# Copyright 2021-2022 Ian Jackson, Simon Tatham, and contributors to Hippotat
# SPDX-License-Identifier: GPL-3.0-or-later WITH LicenseRef-Hippotat-OpenSSL-Exception
# There is NO WARRANTY.

set -ex

mkdir /dev/pts
mount -t proc none /proc
mount -t sysfs none /sys
mount -t devpts none /dev/pts
mount -t tmpfs none /tmp
mount -t tmpfs none /run

mount --bind /usr/lib/uml/modules/ /lib/modules/   
modprobe tun

exec 0<>/dev/tty1 1>&0
stty raw -echo

# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=991959
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
export PATH
export SHELL=/bin/bash

HOME=$(cat /proc/cmdline)
case "$HOME" in
*' psusan-uml-tmp='*) ;;
*) echo >&2 'psusan-uml-tmp not found in /proc/cmdline'; exit 1;;
esac
HOME=${HOME##* psusan-uml-tmp=}
HOME=${HOME%% *}
export HOME
cd "$HOME"

dd if=random-seed of=/dev/urandom
src/uml/rndaddtoentcnt/rndaddtoentcnt 4096 >&2

exec psusan
