e@9
|
1 #!/bin/bash
|
e@9
|
2 # Based on: http://www.richud.com/wiki/Ubuntu_Fluxbox_GUI_with_x11vnc_and_Xvfb
|
e@9
|
3
|
e@9
|
4 readonly G_LOG_I='[INFO]'
|
e@9
|
5 readonly G_LOG_W='[WARN]'
|
e@9
|
6 readonly G_LOG_E='[ERROR]'
|
e@9
|
7
|
e@9
|
8 main() {
|
e@9
|
9 launch_xvfb
|
e@9
|
10 launch_window_manager
|
e@9
|
11 run_vnc_server
|
e@9
|
12 }
|
e@9
|
13
|
e@9
|
14 launch_xvfb() {
|
e@9
|
15 # Set defaults if the user did not specify envs.
|
e@9
|
16 export DISPLAY=${XVFB_DISPLAY:-:1}
|
e@9
|
17 local screen=${XVFB_SCREEN:-0}
|
e@9
|
18 local resolution=${XVFB_RESOLUTION:-1280x1024x24}
|
e@9
|
19 local timeout=${XVFB_TIMEOUT:-5}
|
e@9
|
20
|
e@9
|
21 # Start and wait for either Xvfb to be fully up or we hit the timeout.
|
e@9
|
22 Xvfb ${DISPLAY} -screen ${screen} ${resolution} &
|
e@9
|
23 local loopCount=0
|
e@9
|
24 until xdpyinfo -display ${DISPLAY} > /dev/null 2>&1
|
e@9
|
25 do
|
e@9
|
26 loopCount=$((loopCount+1))
|
e@9
|
27 sleep 1
|
e@9
|
28 if [ ${loopCount} -gt ${timeout} ]
|
e@9
|
29 then
|
e@9
|
30 echo "${G_LOG_E} xvfb failed to start."
|
e@9
|
31 exit 1
|
e@9
|
32 fi
|
e@9
|
33 done
|
e@9
|
34 }
|
e@9
|
35
|
e@9
|
36 launch_window_manager() {
|
e@9
|
37 local timeout=${XVFB_TIMEOUT:-5}
|
e@9
|
38
|
e@9
|
39 # Start and wait for either fluxbox to be fully up or we hit the timeout.
|
e@9
|
40 fluxbox &
|
e@9
|
41 local loopCount=0
|
e@9
|
42 until wmctrl -m > /dev/null 2>&1
|
e@9
|
43 do
|
e@9
|
44 loopCount=$((loopCount+1))
|
e@9
|
45 sleep 1
|
e@9
|
46 if [ ${loopCount} -gt ${timeout} ]
|
e@9
|
47 then
|
e@9
|
48 echo "${G_LOG_E} fluxbox failed to start."
|
e@9
|
49 exit 1
|
e@9
|
50 fi
|
e@9
|
51 done
|
e@9
|
52 }
|
e@9
|
53
|
e@9
|
54 run_vnc_server() {
|
e@9
|
55 local passwordArgument='-nopw'
|
e@9
|
56
|
e@9
|
57 if [ -n "${VNC_SERVER_PASSWORD}" ]
|
e@9
|
58 then
|
e@9
|
59 local passwordFilePath="${HOME}/x11vnc.pass"
|
e@9
|
60 if ! x11vnc -storepasswd "${VNC_SERVER_PASSWORD}" "${passwordFilePath}"
|
e@9
|
61 then
|
e@9
|
62 echo "${G_LOG_E} Failed to store x11vnc password."
|
e@9
|
63 exit 1
|
e@9
|
64 fi
|
e@9
|
65 passwordArgument=-"-rfbauth ${passwordFilePath}"
|
e@9
|
66 echo "${G_LOG_I} The VNC server will ask for a password."
|
e@9
|
67 else
|
e@9
|
68 echo "${G_LOG_W} The VNC server will NOT ask for a password."
|
e@9
|
69 fi
|
e@9
|
70
|
e@9
|
71 x11vnc -display ${DISPLAY} -forever ${passwordArgument} &
|
e@9
|
72 wait $!
|
e@9
|
73 }
|
e@9
|
74
|
e@9
|
75 control_c() {
|
e@9
|
76 echo ""
|
e@9
|
77 exit
|
e@9
|
78 }
|
e@9
|
79
|
e@9
|
80 trap control_c SIGINT SIGTERM SIGHUP
|
e@9
|
81
|
e@9
|
82 main
|
e@9
|
83
|
e@9
|
84 exit
|