#!/bin/sh

# Use this script without arguments to run the generated ISO image with QEMU.
# If you pass '-hdd' or '-h' the virtual hard disk 'hdd.img' will be attached.
# Note that this virtual hard disk has to be created in advance. You can use
# the script 'generate_hdd.sh' to generate the hard disk image file. Once you
# have hard disk image, you can use it as overlay device and persist all your
# changes. See the '.config' file for more information on the overlay support.

global cmd := '"qemu-system-x86_64 -m 128M -cdrom minimal_linux_live.iso -boot d -vga std'"

if test $1 = "-hdd" -o $1 = "-h"  {
  echo "Starting QEMU with attached ISO image and hard disk."
  $cmd -hda hdd.img
} else {
  echo "Starting QEMU with attached ISO image."
  $cmd
}

(CommandList
  children: [
    (Assignment
      keyword: Assign_None
      pairs: [
        (assign_pair
          lhs: (LhsName name:cmd)
          op: Equal
          rhs: {(DQ ("qemu-system-x86_64 -m 128M -cdrom minimal_linux_live.iso -boot d -vga std"))}
          spids: [23]
        )
      ]
      spids: [23]
    )
    (If
      arms: [
        (if_arm
          cond: [
            (Sentence
              child: 
                (C {(Lit_Other "[")} {(DQ ($ VSub_Number "$1"))} {(Lit_Other "=")} {(DQ (-hdd))} {(-o)} 
                  {(DQ ($ VSub_Number "$1"))} {(Lit_Other "=")} {(DQ (-h))} {(Lit_Other "]")}
                )
              terminator: <Op_Semi ";">
            )
          ]
          action: [
            (C {(echo)} {(DQ ("Starting QEMU with attached ISO image and hard disk."))})
            (C {($ VSub_Name "$cmd")} {(-hda)} {(hdd.img)})
          ]
          spids: [-1 59]
        )
      ]
      else_action: [
        (C {(echo)} {(DQ ("Starting QEMU with attached ISO image."))})
        (C {($ VSub_Name "$cmd")})
      ]
      spids: [75 87]
    )
  ]
)