~mil/f_scripts

ref: dev-f_xorg f_scripts/scripts/f_xorg -rwxr-xr-x 1.6 KiB
2344f048Miles Alan f_xorg: Use fbvncm fork, switch to i3, don't run fbvnc in loop 11 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
#!/usr/bin/env osh
shopt -s strict:all
DEP="fbvncm xvfb x11vnc i3wm xclock firefox gedit"
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_WMCMD='mkdir -p  ~/.config/i3; cp -r /etc/i3/config ~/.config/i3/config; i3'
  F_XORG_RES='720x960'
"

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

  export DISPLAY=$DISPLAY
  pkill Xvfb
  pkill x11vnc
  pkill X
  Xvfb -screen 0 "${F_XORG_RES}x24" $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 &
  eval "$F_XORG_WMCMD" &
  "$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
  fbvncm
}

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