summaryrefslogtreecommitdiff
path: root/osi-shell
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2018-08-14 21:15:21 -0400
committerLuke Shumaker <lukeshu@lukeshu.com>2018-08-14 21:15:21 -0400
commitf61ce11643e228343d111f47c03f2dded83dc300 (patch)
treee23f1b3a687a114213262b7cd8b6fd3612fe9f2e /osi-shell
parenta3e647985f2c429c06613eedaf7824ff7cba5484 (diff)
replace osi-run with osi-shell
Diffstat (limited to 'osi-shell')
-rwxr-xr-xosi-shell75
1 files changed, 75 insertions, 0 deletions
diff --git a/osi-shell b/osi-shell
new file mode 100755
index 0000000..1230f19
--- /dev/null
+++ b/osi-shell
@@ -0,0 +1,75 @@
+#!/usr/bin/env bash
+# 2018 Luke Shumaker
+declare -r NAME=osi-run
+declare -r VERSION=20180814
+
+set -euE
+source "${BASH_SOURCE[0]%/*}/lib/osi.sh"
+
+main() {
+ local arg_mode=main
+ local args
+ if ! args="$(getopt -n "${0##*/}" -o hV -l help,version -- "$@")"; then
+ arg_mode=error
+ else
+ eval "set -- $args"
+ while true; do
+ case "$1" in
+ -V|--version) shift; arg_mode=version;;
+ -h|--help) shift; arg_mode=usage;;
+ --) shift; break;;
+ *) error 1 'Internal error. The programmer writing this tool screwed up.';;
+ esac
+ done
+ case "$arg_mode" in
+ main)
+ if (( $# != 1 )); then
+ if (( $# == 0 )); then
+ error 0 "Expected 1 positional argument, got none"
+ else
+ error 0 "Expected 1 positional argument, got %d: %s" "$#" "${*@Q}"
+ fi
+ arg_mode=error
+ else
+ arg_image=$1
+ fi
+ ;;
+ esac
+ fi
+ case "$arg_mode" in
+ error) print "Try '%q --help' for more information" "${0##*/}" >&2; return 2;;
+ version)
+ print "%s (notsystemd) %s" "$NAME" "$VERSION"
+ return 0
+ ;;
+ usage)
+ print 'Usage: %s [OPTIONS] FILENAME.img [< SCRIPT.sh]' "${0##*/}"
+ print 'Operating System Image: Interactive Shell'
+ echo
+ print 'OPTIONS:'
+ print ' -h, --help display this help'
+ print ' -V, --version output version information'
+ return 0
+ ;;
+ main)
+ tmp=$(mktemp -td -- "${0##*/}.XXXXXXXXXX")
+ trap "rm -rf -- ${tmp@Q}" EXIT
+
+ mkfifo -- "$tmp/sync"
+
+ qemu-system-x86_64 \
+ -machine accel=kvm \
+ -m 512 \
+ -name "osi-shell $arg_image" \
+ -drive media=disk,format=raw,if=virtio,file="$arg_image" \
+ -serial stdio \
+ -serial file:"$tmp/exit" \
+ < <(cat <"$tmp/sync" >/dev/null; cat; while sleep 0.1; do printf '\x04'; done) \
+ > >(read -N1 c; printf '%s' "$c"; :>"$tmp/sync"; exec cat)
+
+ return "$(sed 's/\r$//' <"$tmp/exit")"
+ ;;
+ esac
+}
+
+main "$@"