v86starter.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env bash
  2. ROOT_DIR="$(pwd)"
  3. # This has to be something, that isn't wrapped by a repo with a package.json
  4. VM_DIR="/tmp/vm"
  5. # Goes from 1 to 22
  6. ZSTD_LEVEL=22
  7. build()
  8. {
  9. mkdir -p "$VM_DIR"
  10. rm -rf "$VM_DIR/v86"
  11. cd "$ROOT_DIR/make_container" || exit
  12. docker build . -t v86builder
  13. docker run --name v86build v86builder
  14. docker cp v86build:/app/v86 "$VM_DIR"
  15. docker rm v86build
  16. # Overwrite v86'd debian Dockerfile with our own
  17. cat "$ROOT_DIR/imagegen/Dockerfile" > "$VM_DIR/v86/tools/docker/debian/Dockerfile"
  18. # Navigate to the Dockerfile directory
  19. cd "$VM_DIR/v86/tools/docker/debian" || exit
  20. # Build the container which will be used to serve v86
  21. chmod +x build-container.sh
  22. ./build-container.sh
  23. # Build the state of the VM
  24. chmod +x build-state.js
  25. ./build-state.js
  26. # Compress the generated state image
  27. zstd --ultra -$ZSTD_LEVEL < "$VM_DIR/v86/images/debian-state-base.bin" > "$VM_DIR/v86/images/image.bin"
  28. # Make project directories
  29. mkdir -p "$ROOT_DIR/www/third-party"
  30. mkdir -p "$ROOT_DIR/www/static"
  31. # Copy/move necessary files to deployment directory
  32. mv "$VM_DIR/v86/images/image.bin" "$ROOT_DIR/www/static/image.bin"
  33. cp "$VM_DIR/v86/build/libv86.js" "$ROOT_DIR/www/third-party/libv86.js"
  34. cp "$VM_DIR/v86/build/v86.wasm" "$ROOT_DIR/www/third-party/v86.wasm"
  35. cp -r "$VM_DIR/v86/images/debian-9p-rootfs-flat/" "$ROOT_DIR/www/static/9p-rootfs/"
  36. }
  37. if [ ! -d "$VM_DIR/v86" ]
  38. then
  39. build
  40. else
  41. echo "V86 appears to be built"
  42. read -p "Do you want to rebuild V86? (yes/no): " rebuild_choice
  43. if [ "$rebuild_choice" = "yes" ]; then
  44. echo "Rebuilding v86..."
  45. build
  46. fi
  47. fi
  48. # Start a HTTP server
  49. cd "$ROOT_DIR/www/" || exit
  50. echo "Opening a server on localhost with port 8080"
  51. python3 -m http.server -b 127.0.0.1 8080