104 lines
3.3 KiB
Bash
104 lines
3.3 KiB
Bash
#!/bin/bash
|
|
# Принять лицензию KRT через QMP (абсолютные координаты) и снять главное окно.
|
|
set -e
|
|
STAGE=/path/to/pf/KRD/files
|
|
IMG=/root/krd24/ui-fat32.img
|
|
|
|
rm -f "$IMG"; truncate -s 8G "$IMG"
|
|
mkfs.vfat -F 32 -n PARAVIS "$IMG" >/dev/null 2>&1
|
|
mkdir -p /mnt/krdtest; mount -o loop "$IMG" /mnt/krdtest
|
|
mkdir -p /mnt/krdtest/efi/Paravis/KRD
|
|
cp -r "$STAGE/." /mnt/krdtest/efi/Paravis/KRD/
|
|
sync; umount /mnt/krdtest
|
|
|
|
rm -f /tmp/qmp.sock /tmp/ui*.ppm
|
|
qemu-system-x86_64 -m 4096 -smp 4 -machine q35 \
|
|
-kernel "$STAGE/live/vmlinuz" -initrd "$STAGE/live/initrd.img" \
|
|
-append "boot=live components live-media-path=/efi/Paravis/KRD/live locales=ru_RU.UTF-8 trace" \
|
|
-drive file="$IMG",format=raw,if=ide \
|
|
-netdev user,id=n0 -device e1000,netdev=n0 \
|
|
-device qemu-xhci -device usb-tablet -display none -vga std \
|
|
-qmp unix:/tmp/qmp.sock,server,nowait -daemonize
|
|
|
|
python3 - <<'EOF'
|
|
import json, socket, time
|
|
|
|
class Q:
|
|
def __init__(self, path):
|
|
self.s = socket.socket(socket.AF_UNIX); self.s.connect(path)
|
|
self.f = self.s.makefile('rwb')
|
|
self._read()
|
|
self.cmd('qmp_capabilities')
|
|
def _read(self):
|
|
while True:
|
|
line = self.f.readline()
|
|
if not line: return None
|
|
msg = json.loads(line)
|
|
if 'event' in msg: continue
|
|
return msg
|
|
def cmd(self, name, args=None):
|
|
self.f.write((json.dumps({'execute': name, 'arguments': args or {}})+'\n').encode())
|
|
self.f.flush()
|
|
return self._read()
|
|
def hmp(self, line):
|
|
return self.cmd('human-monitor-command', {'command-line': line})
|
|
|
|
W, H = 1280, 800
|
|
def absxy(x, y):
|
|
return int(x*32767/W), int(y*32767/H)
|
|
|
|
def click(q, x, y):
|
|
ax, ay = absxy(x, y)
|
|
q.cmd('input-send-event', {'events': [
|
|
{'type':'abs','data':{'axis':'x','value':ax}},
|
|
{'type':'abs','data':{'axis':'y','value':ay}},
|
|
]})
|
|
time.sleep(0.15)
|
|
q.cmd('input-send-event', {'events':[{'type':'btn','data':{'down':True,'button':'left'}}]})
|
|
time.sleep(0.1)
|
|
q.cmd('input-send-event', {'events':[{'type':'btn','data':{'down':False,'button':'left'}}]})
|
|
time.sleep(0.6)
|
|
|
|
time.sleep(150)
|
|
q = Q('/tmp/qmp.sock')
|
|
q.hmp('screendump /tmp/ui0.ppm')
|
|
|
|
for i,(x,y) in enumerate([(366,525),(366,558),(366,611)], start=1):
|
|
click(q, x, y)
|
|
q.hmp(f'screendump /tmp/ui{i}.ppm')
|
|
|
|
click(q, 865, 657)
|
|
time.sleep(8)
|
|
q.hmp('screendump /tmp/ui4.ppm')
|
|
time.sleep(8)
|
|
q.hmp('screendump /tmp/ui5.ppm')
|
|
q.cmd('quit')
|
|
EOF
|
|
sleep 3
|
|
pkill -f 'qemu-system-x86_64.*ui-fat32.img' 2>/dev/null || true
|
|
python3 - <<'PYEOF'
|
|
import zlib, struct
|
|
def ppm2png(src, dst):
|
|
d=open(src,'rb').read()
|
|
parts=[]; i=0
|
|
while len(parts)<4:
|
|
while d[i:i+1].isspace(): i+=1
|
|
j=i
|
|
while not d[j:j+1].isspace(): j+=1
|
|
parts.append(d[i:j]); i=j
|
|
i+=1
|
|
w=int(parts[1]); h=int(parts[2]); px=d[i:i+w*h*3]
|
|
raw=b''.join(b'\x00'+px[y*w*3:(y+1)*w*3] for y in range(h))
|
|
def chunk(t,data):
|
|
c=t+data
|
|
return struct.pack('>I',len(data))+c+struct.pack('>I',zlib.crc32(c)&0xffffffff)
|
|
png=b'\x89PNG\r\n\x1a\n'
|
|
png+=chunk(b'IHDR',struct.pack('>IIBBBBB',w,h,8,2,0,0,0))
|
|
png+=chunk(b'IDAT',zlib.compress(raw,9))
|
|
png+=chunk(b'IEND',b'')
|
|
open(dst,'wb').write(png)
|
|
print(dst,w,h)
|
|
for n in range(6):
|
|
ppm2png(f'/tmp/ui{n}.ppm', f'/path/to/pf/KRD/ui-{n}.png')
|
|
PYEOF
|