-
Notifications
You must be signed in to change notification settings - Fork 2
/
fakex
executable file
·105 lines (92 loc) · 2.92 KB
/
fakex
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
# (c) 2020 Leif Sawyer
# License: GPL 3.0 (see https://github.com/akhepcat/)
# Permanent home: https://github.com/akhepcat/Miscellaneous/
# Direct download: https://raw.githubusercontent.com/akhepcat/Miscellaneous/master/fakex
#
prereqs() {
for i in Xvfb x11vnc xfwm4 xfce4-panel xterm xhost;
do
if [ -z "$(which $i)" ]
then
showreqs=1
reqs="${reqs} ${i}"
fi
done
if [ 1 -eq ${showreqs:-0} ]
then
echo "Prerequisites are missing!"
echo "Please make sure the following packages are installed:"
echo ""
echo "xvfb x11vnc xfwm4 xfwm4-themes xfce4-panel xfce4-indicator-plugin xterm x11-xserver-utils"
echo ""
echo "can't find: ${reqs}"
echo ""
[[ ${IGNORE:-0} -eq 0 ]] && exit 1
fi
}
PROG="${0##*/}"
stop() {
PIDS=$(pgrep Xvfb)
for PID in $PIDS
do
kill ${PID}
done
}
status() {
pgrep -l Xvfb
[[ $? -eq 1 ]] && echo "fakex is not running (no Xvfb processes found)"
}
XYRES=${XYRES:-1440x900}
do_xfwm4() {
# different versions need different calling
xfwm4 --display=${XDISP} 2>/dev/null &
if [ $? -ne 0 ]
then
DISPLAY=${XDISP} xfwm4 2>/dev/null &
fi
}
do_xfce4() {
# different versions need different calling
xfce4-panel --display=${XDISP} 2>/dev/null &
if [ $? -ne 0 ]
then
DISPLAY=${XDISP} xfce4-panel 2>/dev/null &
fi
}
start() {
USER=$(/usr/bin/whoami)
HOST=$(/bin/hostname | cut -f 1 -d.)
FBDIR=$(mktemp -d /tmp/vmfbXXXXX)
# Base display is 1001, but will auto-increment for each additional...
DISP=$(ps -ef|grep Xvfb | grep -v grep | sed 's/.*:\([0-9]*\).*/\1/' | tail -1)
DISPLAY=${DISP:-1000}
RFBPORT=$((DISPLAY + 4901))
DISPLAY=":$((DISPLAY + 1))"
Xvfb ${DISPLAY} -dpms -shmem -br -nolisten tcp -noreset -v -xinerama -ac -screen 0 ${XYRES}x16 -fbdir ${FBDIR} 2>/dev/null &
sleep 2
xterm -ls -sl 1000 -sb -T ${USER}@${HOST} -fg white -bg black -C -fn 9x15 -display ${DISPLAY} 2>/dev/null &
sleep 1
do_xfwm4
sleep 1
do_xfce4
sleep 1
DISPLAY=${DISPLAY} xhost +localhost
# -noxrecord works around x11vnc "stack smash" bug
x11vnc -q ${LISTEN} -rfbport ${RFBPORT} -forever -noxrecord -alwaysshared -bg -nopw -display ${DISPLAY}
}
case "$1" in
start) prereqs; start
;;
startg) ADDR=$(ip -4 addr show scope global dev $(awk 'BEGIN { IGNORECASE=1 } /^[a-z0-9]+[ \t]+00000000/ { print $1 }' /proc/net/route
) | awk '/inet/ { split($2, arr, "/"); print arr[1];}')
LISTEN="-listen $ADDR"
start
;;
stop) stop
;;
status) prereqs; status
;;
*) echo "${PROG} [start|startg|stop|status]"
;;
esac