diff options
| author | Marc Vertes <mvertes@free.fr> | 2021-03-12 12:31:20 +0100 |
|---|---|---|
| committer | Marc Vertes <mvertes@free.fr> | 2021-03-12 12:31:20 +0100 |
| commit | 050afa8def0739b459122b9d4c7fcf854ae1ed2a (patch) | |
| tree | 9c0c67707c71c8f9351788dc346c96fd9e8fcc4a /bin/vm | |
| parent | 9aa9c25a4d2ced1ea41d1d981b3fad9fe28a17a6 (diff) | |
added wol. Updated vm
Diffstat (limited to 'bin/vm')
| -rwxr-xr-x | bin/vm | 68 |
1 files changed, 62 insertions, 6 deletions
@@ -9,7 +9,10 @@ export LC_ALL=C IFS=' add() { usage 'add name' 'Add a new VM' && return - echo 'not implemented yet' + [ -d "$idir/$1" ] && die "vm $1 already exists in $idir/$1" + init_alpine || die "could not init alpine iso" + mkdir -p "$idir/$1" && cd "$idir/$1" || die "add $1 failed" + pwd } del() { @@ -32,9 +35,54 @@ info() { echo 'not implemented yet' } -list() { - usage 'list' 'list VMs' && return - echo 'not implemented yet' +init() { + : +} + +init_alpine() { + mkdir -p "$sdir/alpine" && cd "$sdir/alpine" || die "init alpine failed" + [ -f Makefile ] || cat << \EOT > Makefile +# Do no edit. This file is generated by vm. +# Install a run a native AlpineLinux VM in Apple silicon MacOS + +# Check https://alpinelinux.org/downloads for possible upgrades +iso_url = https://dl-cdn.alpinelinux.org/alpine/v3.13/releases/aarch64/alpine-virt-3.13.2-aarch64.iso +iso = $(notdir $(iso_url)) +isoinfo ?= /opt/homebrew/bin/isoinfo + +all: initrd vmlinux + +runiso: initrd vmlinux $(iso) + vftool -k vmlinux -i initrd -d hdd.img -c $(iso) + +initrd: $(iso) $(isoinfo) + isoinfo -i $(iso) -J -x /boot/initramfs-virt > $@ + +vmlinux: $(iso) $(isoinfo) + isoinfo -i $(iso) -J -x /boot/vmlinuz-virt | gunzip > $@ + +$(iso): + curl -LO $(iso_url) || { rm -f $@; false; } + +$(isoinfo): + brew install cdrtools +EOT + + make -s all +} + +ls() { + usage 'ls' 'list VMs' && return + [ -d "$idir" ] && cd "$idir" || return + for i in *; do + echo "$i" + done +} + +runiso() { + usage 'runiso [isoname]' 'run a cdrom iso' && return + init_alpine + make runiso } start() { @@ -55,7 +103,15 @@ version() { } # Main starts here. -Cmdlist='add del info help list start stop version' +pdir="$HOME/.vm" +sdir="$pdir/iso" +edir="$pdir/engine" +idir="$pdir/img" + +engines="vftool" # Todo: add qemu (when supported on m1) +isos="alpine" # Todo: add freebsd, openbsd, archlinux, debian, ubuntu, macOS, win10, etc... + +Cmdlist='add del info help ls runiso start stop version' [ "$1" ] && C=$1 && shift 1 || { help; exit 1; } for c in $Cmdlist do @@ -64,4 +120,4 @@ do ($C*) [ "$cmd" ] && die "ambiguous command $C" || cmd=$c;; esac done -[ "$cmd" ] || die "no command \"$C\"" && $cmd "$@" +[ "$cmd" ] || { help; exit 1; } && $cmd "$@" |
