mirror of
https://github.com/AuxXxilium/arv-v-dsm.git
synced 2024-11-23 23:10:58 +07:00
fix: Refactor
* fix: Refactor
This commit is contained in:
parent
19aa313753
commit
d09588b915
32
src/entry.sh
32
src/entry.sh
@ -19,35 +19,13 @@ cd /run
|
||||
trap - ERR
|
||||
|
||||
if [[ "$CONSOLE" == [Yy]* ]]; then
|
||||
exec qemu-system-x86_64 -pidfile "$QEMU_PID" ${ARGS:+ $ARGS}
|
||||
exit $?
|
||||
exec qemu-system-x86_64 ${ARGS:+ $ARGS} && exit $?
|
||||
fi
|
||||
|
||||
[[ "$DEBUG" == [Yy1]* ]] && info "$VERS" && set -x
|
||||
msg=$(qemu-system-x86_64 -daemonize -pidfile "$QEMU_PID" ${ARGS:+ $ARGS})
|
||||
{ set +x; } 2>/dev/null
|
||||
msg=$(qemu-system-x86_64 -daemonize ${ARGS:+ $ARGS})
|
||||
|
||||
if [[ "$msg" != "char"* || "$msg" != *"serial0)" ]]; then
|
||||
echo "$msg"
|
||||
fi
|
||||
{ set +x; } 2>/dev/null && terminal "$msg"
|
||||
cat "$QEMU_TERM" 2>/dev/null & wait $! || true
|
||||
|
||||
dev="${msg#*/dev/p}"
|
||||
dev="/dev/p${dev%% *}"
|
||||
|
||||
if [ ! -c "$dev" ]; then
|
||||
dev=$(echo 'info chardev' | nc -q 1 -w 1 localhost "$QEMU_PORT" | tr -d '\000')
|
||||
dev="${dev#*charserial0}"
|
||||
dev="${dev#*pty:}"
|
||||
dev="${dev%%$'\n'*}"
|
||||
dev="${dev%%$'\r'*}"
|
||||
fi
|
||||
|
||||
if [ ! -c "$dev" ]; then
|
||||
error "Device '$dev' not found!"
|
||||
finish 34
|
||||
fi
|
||||
|
||||
cat "$dev" 2>/dev/null & wait $! || true
|
||||
|
||||
sleep 1
|
||||
finish 0
|
||||
sleep 1 && finish 0
|
||||
|
33
src/power.sh
33
src/power.sh
@ -7,6 +7,7 @@ API_CMD=6
|
||||
API_TIMEOUT=50
|
||||
API_HOST="127.0.0.1:2210"
|
||||
|
||||
QEMU_TERM=""
|
||||
QEMU_PORT=7100
|
||||
QEMU_TIMEOUT=50
|
||||
QEMU_PID="/run/qemu.pid"
|
||||
@ -56,6 +57,34 @@ finish() {
|
||||
exit "$reason"
|
||||
}
|
||||
|
||||
terminal() {
|
||||
|
||||
local msg=$1
|
||||
|
||||
if [[ "${msg,,}" != "char"* || "$msg" != *"serial0)" ]]; then
|
||||
echo "$msg"
|
||||
fi
|
||||
|
||||
local dev="${msg#*/dev/p}"
|
||||
dev="/dev/p${dev%% *}"
|
||||
|
||||
if [ ! -c "$dev" ]; then
|
||||
dev=$(echo 'info chardev' | nc -q 1 -w 1 localhost "$QEMU_PORT" | tr -d '\000')
|
||||
dev="${dev#*charserial0}"
|
||||
dev="${dev#*pty:}"
|
||||
dev="${dev%%$'\n'*}"
|
||||
dev="${dev%%$'\r'*}"
|
||||
fi
|
||||
|
||||
if [ ! -c "$dev" ]; then
|
||||
error "Device '$dev' not found!"
|
||||
finish 34 && return 34
|
||||
fi
|
||||
|
||||
QEMU_TERM="$dev"
|
||||
return 0
|
||||
}
|
||||
|
||||
_graceful_shutdown() {
|
||||
|
||||
local code=$?
|
||||
@ -129,4 +158,6 @@ _graceful_shutdown() {
|
||||
|
||||
_trap _graceful_shutdown SIGTERM SIGHUP SIGINT SIGABRT SIGQUIT
|
||||
|
||||
MON_OPTS="-monitor telnet:localhost:$QEMU_PORT,server,nowait,nodelay"
|
||||
MON_OPTS="\
|
||||
-pidfile $QEMU_PID \
|
||||
-monitor telnet:localhost:$QEMU_PORT,server,nowait,nodelay"
|
||||
|
Loading…
Reference in New Issue
Block a user