63 lines
2.6 KiB
Bash
63 lines
2.6 KiB
Bash
|
|
#!/bin/bash
|
||
|
|
# Install only X11 display recovery; keep the kiosk/Moonlight session running.
|
||
|
|
set -euo pipefail
|
||
|
|
|
||
|
|
BOX="${VDI_BOX:-armbian@192.168.1.188}"
|
||
|
|
REPO="$(cd "$(dirname "$0")/.." && pwd)"
|
||
|
|
SRC="$REPO/terminal/kiosk-shell"
|
||
|
|
STAGE=$(ssh -o BatchMode=yes -o ConnectTimeout=8 "$BOX" 'mktemp -d /tmp/vdi-display-deploy.XXXXXX')
|
||
|
|
scp -q "$SRC/scripts/vdi-display-guard" "$SRC/scripts/vdi-kiosk-start" \
|
||
|
|
"$SRC/etc/vdi-display-guard.service" "$BOX:$STAGE/"
|
||
|
|
ssh "$BOX" bash -s -- "$STAGE" <<'REMOTE'
|
||
|
|
set -euo pipefail
|
||
|
|
stage=$1
|
||
|
|
backup="$HOME/vdi-terminal/backups/display-guard-$(date +%Y%m%d-%H%M%S)"
|
||
|
|
mkdir -p "$backup" "$HOME/vdi-terminal/bin" "$HOME/.config/systemd/user"
|
||
|
|
for file in "$HOME/vdi-terminal/bin/vdi-kiosk-start" \
|
||
|
|
"$HOME/vdi-terminal/bin/vdi-display-guard" \
|
||
|
|
"$HOME/.config/systemd/user/vdi-display-guard.service"; do
|
||
|
|
test ! -f "$file" || cp -p "$file" "$backup/"
|
||
|
|
done
|
||
|
|
sed -i 's/\r$//' "$stage/"*
|
||
|
|
python3 -c 'import ast, sys; ast.parse(open(sys.argv[1]).read())' "$stage/vdi-display-guard"
|
||
|
|
sh -n "$stage/vdi-kiosk-start"
|
||
|
|
install -m 0755 "$stage/vdi-display-guard" "$stage/vdi-kiosk-start" "$HOME/vdi-terminal/bin/"
|
||
|
|
install -m 0644 "$stage/vdi-display-guard.service" "$HOME/.config/systemd/user/"
|
||
|
|
|
||
|
|
# Correct only this monitor's known stale layout; preserve all other layouts.
|
||
|
|
python3 - "$backup" <<'PY'
|
||
|
|
from pathlib import Path
|
||
|
|
import shutil
|
||
|
|
import sys
|
||
|
|
import xml.etree.ElementTree as ET
|
||
|
|
path = Path.home() / '.config/monitors.xml'
|
||
|
|
if path.exists():
|
||
|
|
tree = ET.parse(path)
|
||
|
|
changed = False
|
||
|
|
for output in tree.findall('.//output'):
|
||
|
|
if (output.get('name') == 'HDMI-1'
|
||
|
|
and output.findtext('vendor') == 'GWR'
|
||
|
|
and output.findtext('product') == '0x2708'
|
||
|
|
and output.findtext('width') == '1920'
|
||
|
|
and output.findtext('height') == '1440'
|
||
|
|
and output.findtext('rate') == '75'):
|
||
|
|
for name, value in [('width', '2560'), ('height', '1440'), ('rate', '60')]:
|
||
|
|
output.find(name).text = value
|
||
|
|
changed = True
|
||
|
|
if changed:
|
||
|
|
shutil.copy2(path, Path(sys.argv[1]) / 'monitors.xml')
|
||
|
|
temp = path.with_name('monitors.xml.vdi-new')
|
||
|
|
tree.write(temp, encoding='utf-8', xml_declaration=True)
|
||
|
|
temp.replace(path)
|
||
|
|
print('Updated known stale MATE layout to 2560x1440@60')
|
||
|
|
PY
|
||
|
|
systemctl --user daemon-reload
|
||
|
|
systemctl --user enable vdi-display-guard.service
|
||
|
|
systemctl --user restart vdi-display-guard.service
|
||
|
|
systemctl --user is-active vdi-display-guard.service
|
||
|
|
echo "Backup: $backup"
|
||
|
|
# Only remove the three files uploaded by this deployment.
|
||
|
|
rm -- "$stage/vdi-display-guard" "$stage/vdi-kiosk-start" "$stage/vdi-display-guard.service"
|
||
|
|
rmdir -- "$stage"
|
||
|
|
REMOTE
|