xrsh-buildroot/buildroot-v86/board/v86/rootfs_overlay/root/bin/save

59 lines
1.4 KiB
Text
Raw Normal View History

#!/bin/sh
source /etc/profile.sh
2025-04-08 15:25:20 +02:00
state(){
javascript='
const isoterminal = document.querySelector("[isoterminal]").components.isoterminal.term
isoterminal.save()
return "[OK] xrsh state saved\n"
'
echo "[i] triggering ~/hook.d/save/* scripts"
hook save
echo "[i] warning: do not resize the browserwindow"
echo "[i] please wait.."
js "$javascript"
exit
}
file(){
javascript='
2025-04-08 18:42:07 +02:00
filename="'$(pwd)/$1'"
res = ""
function saveUint8Array(uint8Array, filename = "download.bin", mimeType = "application/octet-stream") {
if( !uint8Array ){
console.log( res = "file not found" )
return false
}
2025-04-08 15:25:20 +02:00
const blob = new Blob([uint8Array], { type: mimeType });
const url = URL.createObjectURL(blob);
2025-04-08 18:42:07 +02:00
const a = document.createElement("a");
2025-04-08 15:25:20 +02:00
a.href = url;
2025-04-08 18:42:07 +02:00
a.download = filename.replace(/.*\//,"");
2025-04-08 15:25:20 +02:00
// Programmatically trigger the click event
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
// Clean up the URL object
URL.revokeObjectURL(url);
}
let term = document.querySelector("[isoterminal]")
2025-04-08 18:42:07 +02:00
term.emit("read_file", [filename, (str,buf) => saveUint8Array(buf, filename) ] )
2025-04-08 15:25:20 +02:00
2025-04-08 18:42:07 +02:00
return res
2025-04-08 15:25:20 +02:00
'
hook save
js "$javascript"
exit
}
test -z "$1" && state
2025-04-08 18:42:07 +02:00
test -n "$1" && file "$1"
2025-04-08 15:25:20 +02:00
echo "Usage: save [file] # pass no argument to save VM state to localStorage"