From f0bc10f1e8c98a3327da10ca752910013e5e8f64 Mon Sep 17 00:00:00 2001 From: ProgrammerIn-wonderland <3838shah@gmail.com> Date: Mon, 14 Oct 2024 18:28:58 -0400 Subject: [PATCH] WIP persistence --- src/emulator/image/Dockerfile | 36 +++++++++++-------- src/emulator/image/rootfs/bin/puter-restore | 7 ++++ src/emulator/image/rootfs/bin/puter-save | 4 +++ .../image/rootfs/bin/puter-save-daemon | 3 ++ .../rootfs/etc/apk/commit_hooks.d/puter.sh | 4 +++ .../image/rootfs/etc/init.d/puter-save-daemon | 15 ++++++++ src/emulator/src/main.js | 2 +- 7 files changed, 56 insertions(+), 15 deletions(-) create mode 100644 src/emulator/image/rootfs/bin/puter-restore create mode 100644 src/emulator/image/rootfs/bin/puter-save create mode 100644 src/emulator/image/rootfs/bin/puter-save-daemon create mode 100644 src/emulator/image/rootfs/etc/apk/commit_hooks.d/puter.sh create mode 100644 src/emulator/image/rootfs/etc/init.d/puter-save-daemon diff --git a/src/emulator/image/Dockerfile b/src/emulator/image/Dockerfile index b1291c5e..1d79cc56 100644 --- a/src/emulator/image/Dockerfile +++ b/src/emulator/image/Dockerfile @@ -6,7 +6,7 @@ RUN apk add --update \ gcc make gcompat musl-dev libx11-dev xinit \ bind-tools \ util-linux \ - htop vim nano \ + htop vim nano jq \ && \ setup-xorg-base xhost xterm xcalc xdotool xkill || true && \ setup-devd udev || true && \ @@ -16,6 +16,18 @@ RUN apk add --update \ chsh -s /bin/bash RUN apk add neofetch +# programming language tools +RUN apk add --no-cache \ + nodejs npm \ + php \ + perl \ + go + +# Fun packages +RUN apk add cowsay --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing/ + +# Shell +RUN apk add zsh sudo git libgit2 COPY rootfs/ / @@ -24,20 +36,17 @@ RUN chmod +x /etc/init.d/basic-boot COPY assets/epoxy-server /bin/epoxy-server RUN chmod u+x /bin/epoxy-server + +RUN chmod +x /etc/init.d/puter-save-daemon + RUN rc-update add twisp-service default +RUN rc-update add puter-save-daemon default RUN rc-update add debug-service default RUN chmod +x /etc/init.d/network-service RUN rc-update add network-service default -# programming language tools -RUN apk add --no-cache \ - nodejs npm \ - php \ - perl \ - go - # RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y # ENV PATH="/root/.cargo/bin:${PATH}" # RUN rustup default nightly @@ -57,12 +66,6 @@ RUN \ rc-update add killprocs shutdown && \ rc-update add savecache shutdown -# Fun packages -RUN apk add cowsay --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing/ - -# Shell -RUN apk add zsh sudo git libgit2 - RUN mkdir /root/Downloads # Setup user @@ -97,4 +100,9 @@ RUN echo "/etc/puter-motd" >> /root/.zshrc RUN cp /root/.zshrc /home/puter-user/.zshrc RUN cp /root/.bashrc /home/puter-user/.bashrc +RUN chmod +x /bin/puter-save +RUN chmod +x /bin/puter-save-daemon +RUN chmod +x /bin/puter-restore +RUN chmod +x /etc/apk/commit_hooks.d/puter.sh + RUN bash diff --git a/src/emulator/image/rootfs/bin/puter-restore b/src/emulator/image/rootfs/bin/puter-restore new file mode 100644 index 00000000..8f22c000 --- /dev/null +++ b/src/emulator/image/rootfs/bin/puter-restore @@ -0,0 +1,7 @@ +#!/bin/bash +PUTERUSERNAME=$( cat /proc/cmdline | sed -n 's/.*puterusername=\(.*\)/\1/p' ) + +echo > /tmp/restore-in-progress +tar -C / -zxvf /puter/$PUTERUSERNAME/emulatorstate.apkovl.tar.gz # no worries if this errors, its just the first boot +apk add --no-cache $(cat /etc/apk/world) +rm /tmp/restore-in-progress \ No newline at end of file diff --git a/src/emulator/image/rootfs/bin/puter-save b/src/emulator/image/rootfs/bin/puter-save new file mode 100644 index 00000000..a0ccbbff --- /dev/null +++ b/src/emulator/image/rootfs/bin/puter-save @@ -0,0 +1,4 @@ +#!/bin/bash + +PUTERUSERNAME=$( cat /proc/cmdline | sed -n 's/.*puterusername=\(.*\)/\1/p' ) +lbu package - > /puter/$PUTERUSERNAME/emulatorstate.apkovl.tar.gz \ No newline at end of file diff --git a/src/emulator/image/rootfs/bin/puter-save-daemon b/src/emulator/image/rootfs/bin/puter-save-daemon new file mode 100644 index 00000000..5e57938b --- /dev/null +++ b/src/emulator/image/rootfs/bin/puter-save-daemon @@ -0,0 +1,3 @@ +#!/bin/bash + +inotifyd /bin/puter-save /etc:cdDw \ No newline at end of file diff --git a/src/emulator/image/rootfs/etc/apk/commit_hooks.d/puter.sh b/src/emulator/image/rootfs/etc/apk/commit_hooks.d/puter.sh new file mode 100644 index 00000000..f3f5d46d --- /dev/null +++ b/src/emulator/image/rootfs/etc/apk/commit_hooks.d/puter.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +echo saving state to puter... +puter-save diff --git a/src/emulator/image/rootfs/etc/init.d/puter-save-daemon b/src/emulator/image/rootfs/etc/init.d/puter-save-daemon new file mode 100644 index 00000000..4ca3f873 --- /dev/null +++ b/src/emulator/image/rootfs/etc/init.d/puter-save-daemon @@ -0,0 +1,15 @@ +#!/sbin/openrc-run + +description="Puter Save Daemon" +command="/bin/puter-save-daemon" +command_args="" +command_background="yes" +pidfile="/var/run/puter-save-daemon.pid" +start_stop_daemon_args="--background --make-pidfile" +output_log="/dev/ttyS0" +error_log="/dev/ttyS0" + +depend() { + need localmount + after bootmisc +} diff --git a/src/emulator/src/main.js b/src/emulator/src/main.js index 09cd932f..e5129cb0 100644 --- a/src/emulator/src/main.js +++ b/src/emulator/src/main.js @@ -308,7 +308,7 @@ window.onload = async function() url: './image/build/boot/vmlinuz-virt', async: false }, - cmdline: 'rw root=/dev/sda init=/sbin/init rootfstype=ext4', + cmdline: 'rw root=/dev/sda init=/sbin/init rootfstype=ext4 puterusername=' + (await puter.getUser()).username, // cmdline: 'rw root=/dev/sda init=/bin/bash rootfstype=ext4', // cmdline: "rw init=/sbin/init root=/dev/sda rootfstype=ext4", // cmdline: "rw init=/sbin/init root=/dev/sda rootfstype=ext4 random.trust_cpu=on 8250.nr_uarts=10 spectre_v2=off pti=off mitigations=off",