#!/bin/sh
# SPDX-License-Identifier: GPL-3.0
# V/UX
#
# init
#
# COPYRIGHT NOTICE
# Copyright (C) 2025-2026 0x4248 and contributors
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the license is not changed.
#
# This software is free and open source. Licensed under the GNU general
# public license version 3.0 as published by the Free Software Foundation.


clear

echo "Welcome to V/UX"

mkdir /proc /sys /tmp /mnt
mount -t proc none /proc
mount -t sysfs none /sys
mount -t tmpfs none /tmp
mount -t devtmpfs none /dev

echo -e "\e[44m"

echo "+-------------------+"
echo "|   V/UX SYSTEM 1   |"
echo "|   4248 Systems    |"
echo "+-------------------+"

echo -e "\e[0m"

echo "(C) 2025 0x4248 and contributors"
echo "(C) 2025 4248 Systems, A Division of 0x4248"
echo "Licensed under GNU GPL v3.0"
echo ""
echo "Welcome to V/UX please mount a stage 2 system disk to continue."

export PS1="V/UX (NO DISK) # "

mkdir /mnt

echo "Found the following disks:"
ls /dev/*da*

echo "Please enter the disk to mount:"
read disk



if [ -z "$disk" ]; then
	echo "No disk specified, exiting."
	/bin/sh
fi

echo "Mounting disk $disk"
mount /dev/$disk /mnt
echo "Disk mounted to /mnt"
PS1="V/UX ($disk) # "

echo "Leaving stage 1 to fully enter stage 2"
mkdir -p /mnt/proc /mnt/sys /mnt/tmp /mnt/mnt
mount -t proc none /mnt/proc
mount -t sysfs none /mnt/sys
mount -t tmpfs none /mnt/tmp
mount -t devtmpfs none /mnt/dev

# set /mnt to /
cd /mnt
mount --bind /mnt /mnt
mount --make-rslave /mnt

# set /mnt/dev to /dev
cd /mnt/dev
mount --bind /dev /mnt/dev
mount --make-rslave /mnt/dev

# set /mnt/proc to /proc
cd /mnt/proc
mount --bind /proc /mnt/proc
mount --make-rslave /mnt/proc

# set /mnt/sys to /sys
cd /mnt/sys
mount --bind /sys /mnt/sys
mount --make-rslave /mnt/sys

# set /mnt/tmp to /tmp
cd /mnt/tmp
mount --bind /tmp /mnt/tmp
mount --make-rslave /mnt/tmp

echo "Entering stage 2"
chroot /mnt /bin/sh
