diff --git a/src/emulator/basic.html b/src/emulator/basic.html new file mode 100644 index 000000000..07bbfb3f2 --- /dev/null +++ b/src/emulator/basic.html @@ -0,0 +1,412 @@ + +Basic Emulator + + + + + + +
+
+ +
diff --git a/src/emulator/image/Dockerfile b/src/emulator/image/Dockerfile new file mode 100644 index 000000000..c45e3b8ef --- /dev/null +++ b/src/emulator/image/Dockerfile @@ -0,0 +1,57 @@ +FROM i386/alpine:edge + +RUN apk add --update \ + alpine-base bash ncurses shadow curl \ + linux-lts linux-firmware-none linux-headers \ + gcc make gcompat musl-dev libx11-dev xinit \ + bind-tools \ + util-linux \ + htop vim nano \ + && \ + setup-xorg-base xhost xterm xcalc xdotool xkill || true && \ + setup-devd udev || true && \ + touch /root/.Xdefaults && \ + rm /etc/motd /etc/issue && \ + passwd -d root && \ + chsh -s /bin/bash + +RUN apk add neofetch + +COPY basic-boot /etc/init.d/ +RUN chmod +x /etc/init.d/basic-boot + +COPY assets/twisp /bin/twisp +RUN chmod u+x /bin/twisp +COPY twisp-service /etc/init.d/ +RUN chmod +x /etc/init.d/twisp-service +RUN rc-update add twisp-service default + +COPY debug-service /etc/init.d/ +RUN chmod +x /etc/init.d/debug-service +RUN rc-update add debug-service default + +COPY initd/network-service /etc/init.d/ +RUN chmod +x /etc/init.d/network-service +RUN rc-update add network-service default + +# setup init system +# COPY rc.conf /etc/rc.conf +RUN rc-update add dmesg sysinit +RUN rc-update add basic-boot sysinit + +RUN rc-update add root boot +RUN rc-update add localmount boot +RUN rc-update add modules boot +RUN rc-update add sysctl boot +RUN rc-update add bootmisc boot +RUN rc-update add syslog boot + +RUN rc-update add mount-ro shutdown +RUN rc-update add killprocs shutdown +RUN rc-update add savecache shutdown + +COPY rootfs/ / + +RUN setup-hostname puter-alpine + +RUN bash \ No newline at end of file diff --git a/src/emulator/image/basic-boot b/src/emulator/image/basic-boot new file mode 100644 index 000000000..11e9d3824 --- /dev/null +++ b/src/emulator/image/basic-boot @@ -0,0 +1,14 @@ +#!/sbin/openrc-run + +description="Run Essential Boot Scripts" + +start() { + ebegin "Running Essential Boot Scripts" + mount / -o remount,rw + eend $? +} + +stop() { + ebegin "Stopping Essential Boot Scripts" + eend $? +} diff --git a/src/emulator/image/build.sh b/src/emulator/image/build.sh new file mode 100755 index 000000000..f8d51fa5e --- /dev/null +++ b/src/emulator/image/build.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash +set -veu + +if [ -w /var/run/docker.sock ] +then + echo true +else + echo "You aren't in the docker group, please run usermod -a -G docker $USER && newgrp docker" + exit 2 +fi + + +IMAGES="$(dirname "$0")"/build/x86images +OUT_ROOTFS_TAR="$IMAGES"/rootfs.tar +OUT_ROOTFS_BIN="$IMAGES"/rootfs.bin +OUT_ROOTFS_MNT="$IMAGES"/rootfs.mntpoint +CONTAINER_NAME=alpine-full +IMAGE_NAME=i386/alpine-full + +rm -rf $OUT_ROOTFS_BIN || : + +mkdir -p "$IMAGES" +docker build . --platform linux/386 --rm --tag "$IMAGE_NAME" +docker rm "$CONTAINER_NAME" || true +docker create --platform linux/386 -t -i --name "$CONTAINER_NAME" "$IMAGE_NAME" bash + +docker export "$CONTAINER_NAME" > "$OUT_ROOTFS_TAR" +dd if=/dev/zero "of=$OUT_ROOTFS_BIN" bs=512M count=2 + +loop=$(sudo losetup -f) +sudo losetup -P "$loop" "$OUT_ROOTFS_BIN" +sudo mkfs.ext4 "$loop" +mkdir -p "$OUT_ROOTFS_MNT" +sudo mount "$loop" "$OUT_ROOTFS_MNT" + +sudo tar -xf "$OUT_ROOTFS_TAR" -C "$OUT_ROOTFS_MNT" +sudo cp -r "$OUT_ROOTFS_MNT/boot" "$IMAGES/boot" + +sudo umount "$loop" +sudo losetup -d "$loop" +rm "$OUT_ROOTFS_TAR" +rm -rf "$OUT_ROOTFS_MNT" + +echo "done! created" +sudo chown -R $USER:$USER $IMAGES/boot +cd "$IMAGES" +mkdir -p rootfs +split -b50M rootfs.bin rootfs/ +cd ../ +find x86images/rootfs/* | jq -Rnc "[inputs]" diff --git a/src/emulator/image/clean.sh b/src/emulator/image/clean.sh new file mode 100755 index 000000000..81dec73eb --- /dev/null +++ b/src/emulator/image/clean.sh @@ -0,0 +1,3 @@ +sudo umount build/x86images/rootfs.mntpoint +sudo rm -rf ./build + diff --git a/src/emulator/image/debug-service b/src/emulator/image/debug-service new file mode 100644 index 000000000..d3f48d5a8 --- /dev/null +++ b/src/emulator/image/debug-service @@ -0,0 +1,19 @@ +#!/sbin/openrc-run + +description="Run debug init" + +depend() { + after twisp-service +} + +start() { + ebegin "Running Debug Init" + echo " 🛠 bash will be on tty2" + setsid bash < /dev/tty2 > /dev/tty2 2>&1 & + eend $? +} + +stop() { + ebegin "Stopping Debug Init" + eend $? +} diff --git a/src/emulator/image/initd/network-service b/src/emulator/image/initd/network-service new file mode 100644 index 000000000..b68ba438c --- /dev/null +++ b/src/emulator/image/initd/network-service @@ -0,0 +1,17 @@ +#!/sbin/openrc-run + +description="Run network setup" + +start() { + ebegin "Running network setup" + modprobe ne2k-pci + ifupdown ifup eth0 + ip link set lo up + echo "nameserver 192.168.86.1" > /etc/resolv.conf + eend $? +} + +stop() { + ebegin "Stopping network setup" + eend $? +} diff --git a/src/emulator/image/qemu.sh b/src/emulator/image/qemu.sh new file mode 100755 index 000000000..f0388f53e --- /dev/null +++ b/src/emulator/image/qemu.sh @@ -0,0 +1,7 @@ +qemu-system-i386 \ + -kernel ./build/x86images/boot/vmlinuz-lts \ + -initrd ./build/x86images/boot/initramfs-lts \ + -append "rw root=/dev/sda console=ttyS0 init=/sbin/init rootfstype=ext4" \ + -hda ./build/x86images/rootfs.bin \ + -m 1024M \ + -nographic diff --git a/src/emulator/image/rootfs/etc/hostname b/src/emulator/image/rootfs/etc/hostname new file mode 100644 index 000000000..9e566746c --- /dev/null +++ b/src/emulator/image/rootfs/etc/hostname @@ -0,0 +1 @@ +puter-alpine diff --git a/src/emulator/image/rootfs/etc/network/interfaces b/src/emulator/image/rootfs/etc/network/interfaces new file mode 100644 index 000000000..f6278a237 --- /dev/null +++ b/src/emulator/image/rootfs/etc/network/interfaces @@ -0,0 +1,4 @@ +iface eth0 inet static + address 192.168.86.100 + netmask 255.255.255.0 + gateway 192.168.86.1 diff --git a/src/emulator/image/rootfs/etc/resolv.conf b/src/emulator/image/rootfs/etc/resolv.conf new file mode 100644 index 000000000..c43526bf5 --- /dev/null +++ b/src/emulator/image/rootfs/etc/resolv.conf @@ -0,0 +1 @@ +nameserver 192.168.86.1 diff --git a/src/emulator/image/twisp-service b/src/emulator/image/twisp-service new file mode 100644 index 000000000..8ca743e43 --- /dev/null +++ b/src/emulator/image/twisp-service @@ -0,0 +1,25 @@ +#!/sbin/openrc-run + +description="twisp daemon" +command="/bin/twisp" +command_args="--pty /dev/hvc0" +pidfile="/var/run/twisp.pid" +command_background="yes" +start_stop_daemon_args="--background --make-pidfile" + +depend() { + need localmount + after bootmisc +} + +start() { + ebegin "Starting ${description}" + start-stop-daemon --start --pidfile "${pidfile}" --background --exec ${command} -- ${command_args} + eend $? +} + +stop() { + ebegin "Stopping ${description}" + start-stop-daemon --stop --pidfile "${pidfile}" + eend $? +}