~mil/f_scripts

ref: 10435e989bacd02b1c9e3daebb178379867e8b45 f_scripts/scripts/f_xorg -rwxr-xr-x 1.6 KiB
10435e98Miles Alan Add experimental f_xorg script to launch an X application via VNC 9 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env osh
shopt -s strict:all
DEP="fbvnc xvfb x11vnc xdpyinfo spectrwm xclock gedit firefox"
DEC="Run an arbitrary Xorg application via VNC and view in the framebuffer"
DOC="
  f_xorg allows you to run an arbitrary Xorg application in Xvfb along
  with x11vnc and then view the resulting appliaction in the framebuffer
  via fbvnc. Running the script will prompt you for the command to run.

  A given number of prefilled applications F_XORG_APPS will appear in the
  menu if installed on the system.
"
VAR="
  F_XORG_APPS='xclock gedit firefox'
  F_XORG_FBPRATIO='2 / 3'
  F_XORG_YRES='1440'
  F_XORG_XRES='720'
"

runbg() {
  local CMD DISPLAY
  CMD="$1"
  DISPLAY="$2"

  export DISPLAY=$DISPLAY
  pkill Xvfb
  pkill x11vnc
  pkill dwm
  pkill X
  Xvfb -screen 0 720x960x24 $DISPLAY >&2 2>/dev/null &

  while ! xdpyinfo -display "${DISPLAY}" >&2 2>/dev/null; do
	echo "Waiting for X server to become available"
  	sleep 1
  done

  x11vnc -many -forever -ncache 1 >&2 2>/dev/null &
  spectrwm >&2 2>/dev/null &
  "$CMD" >&2 2>/dev/null &
}

run() {
  local CMD DISPLAY

  #TODO random display
  CMD="$1"
  DISPLAY=:8

  sleep 1
  runbg "$CMD" "$DISPLAY" >&2 2>/dev/null
  while ! nc -z localhost 5900; do   
    echo "Waiting for VNC server to become available"
    sleep 1
  done
  while true; do
    fbvnc
  done
}

main() {
  env | grep -q "^$(basename "$0" | tr '[a-z]' '[A-Z]')=" || eval "$VAR"

  [ -p /tmp/fbp.fifo ] && { echo -e "\b\f\r"; echo "$F_XORG_APPS" | tr " " "\n"; } > /tmp/fbp.fifo
  read -p "Run ($F_XORG_APPS): " APP
  run "$APP"
  [ -p /tmp/fbp.fifo ] && echo -e "\v" > /tmp/fbp.fifo
}

if [ -n "$1" ]; then "$@"; else main; fi