2018-08-06 01:49:45 +00:00
|
|
|
#!/usr/bin/env bash
|
2018-08-18 18:42:42 +00:00
|
|
|
# Copyright (C) 2018 Luke Shumaker
|
2024-01-04 22:16:23 +00:00
|
|
|
# Copyright (C) 2023-2024 Umorpha Systems
|
2018-08-18 18:42:42 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
2024-02-14 03:00:05 +00:00
|
|
|
declare -r NAME=osi-shell
|
2023-10-23 22:19:22 +00:00
|
|
|
declare -r VERSION=20231023
|
2018-08-12 20:37:04 +00:00
|
|
|
|
|
|
|
set -euE
|
2024-01-04 22:16:23 +00:00
|
|
|
|
|
|
|
install_prefix="$(realpath --logical --canonicalize-missing -- "${BASH_SOURCE[0]}/../..")"
|
|
|
|
readonly install_prefix
|
|
|
|
|
|
|
|
source "${install_prefix}/lib/osi.sh"
|
2024-02-14 03:00:05 +00:00
|
|
|
source "${install_prefix}/lib/argparse.sh"
|
2018-08-11 22:46:04 +00:00
|
|
|
|
2018-08-12 20:37:04 +00:00
|
|
|
main() {
|
2018-08-16 21:20:19 +00:00
|
|
|
local arg_image=
|
|
|
|
local arg_qemu=()
|
2024-02-14 03:00:05 +00:00
|
|
|
opt_positional() {
|
|
|
|
if (( $# < 1 )); then
|
|
|
|
argparse:error "Expected at least 1 positional argument, got none"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
arg_image=$1
|
|
|
|
arg_qemu=("${@:2}")
|
|
|
|
}
|
|
|
|
argparse main "$@"
|
|
|
|
|
|
|
|
case "$opt_mode" in
|
2023-10-25 10:59:35 +00:00
|
|
|
error)
|
2024-02-14 02:07:36 +00:00
|
|
|
osi.sh:print "Try '%q --help' for more information" "${0##*/}" >&2
|
2023-10-25 10:59:35 +00:00
|
|
|
return $EXIT_INVALIDARGUMENT
|
|
|
|
;;
|
2018-08-12 20:37:04 +00:00
|
|
|
version)
|
2024-02-14 02:07:36 +00:00
|
|
|
osi.sh:print "%s (osi-tools) %s" "$NAME" "$VERSION"
|
2023-10-25 10:59:35 +00:00
|
|
|
return $EXIT_SUCCESS
|
2018-08-12 20:37:04 +00:00
|
|
|
;;
|
2024-02-14 03:00:05 +00:00
|
|
|
help)
|
2024-02-14 02:07:36 +00:00
|
|
|
osi.sh:print 'Usage: %s [OPTIONS] FILENAME.img [-- QEMU_ARGS...] [< SCRIPT.sh]' "${0##*/}"
|
|
|
|
osi.sh:print ' or: %s [OPTIONS] -- FILENAME.img [QEMU_ARGS...] [< SCRIPT.sh]' "${0##*/}"
|
|
|
|
osi.sh:print 'Operating System Image: Interactive Shell'
|
2018-08-12 20:37:04 +00:00
|
|
|
echo
|
2024-02-14 02:07:36 +00:00
|
|
|
osi.sh:print 'OPTIONS:'
|
2024-02-14 03:00:05 +00:00
|
|
|
echo "${opt_flaghelp}"
|
2023-10-25 10:59:35 +00:00
|
|
|
return $EXIT_SUCCESS
|
2018-08-12 20:37:04 +00:00
|
|
|
;;
|
2018-08-14 15:37:29 +00:00
|
|
|
main)
|
2018-08-15 01:15:21 +00:00
|
|
|
tmp=$(mktemp -td -- "${0##*/}.XXXXXXXXXX")
|
|
|
|
trap "rm -rf -- ${tmp@Q}" EXIT
|
2018-08-06 01:49:45 +00:00
|
|
|
|
2018-08-15 01:15:21 +00:00
|
|
|
mkfifo -- "$tmp/sync"
|
|
|
|
|
|
|
|
qemu-system-x86_64 \
|
|
|
|
-machine accel=kvm \
|
|
|
|
-m 512 \
|
2018-08-16 18:47:39 +00:00
|
|
|
-vnc unix:"$tmp/vnc.sock" \
|
2018-08-15 01:15:21 +00:00
|
|
|
-name "osi-shell $arg_image" \
|
|
|
|
-drive media=disk,format=raw,if=virtio,file="$arg_image" \
|
|
|
|
-serial stdio \
|
|
|
|
-serial file:"$tmp/exit" \
|
2018-08-16 21:20:19 +00:00
|
|
|
"${arg_qemu[@]}" \
|
2018-08-15 01:15:21 +00:00
|
|
|
< <(cat <"$tmp/sync" >/dev/null; cat; while sleep 0.1; do printf '\x04'; done) \
|
2018-08-16 05:32:59 +00:00
|
|
|
> >(read -r -N1 c; printf '%s' "$c"; :>"$tmp/sync"; exec cat)
|
2018-08-15 01:15:21 +00:00
|
|
|
|
|
|
|
return "$(sed 's/\r$//' <"$tmp/exit")"
|
|
|
|
;;
|
2024-02-14 03:00:05 +00:00
|
|
|
|
|
|
|
*) osi.sh:error $EXIT_FAILURE 'Internal error. The programmer writing this tool screwed up.';;
|
2018-08-12 20:37:04 +00:00
|
|
|
esac
|
2018-08-06 01:49:45 +00:00
|
|
|
}
|
2018-08-12 20:37:04 +00:00
|
|
|
|
|
|
|
main "$@"
|