-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvmplayer-start.sh
executable file
·129 lines (115 loc) · 3.5 KB
/
vmplayer-start.sh
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/sh
########################################################################
# vmplayer-start.sh: VMware Player Startup Script
#
# Description:
# This script starts VMware Player in a virtual X server environment.
# It uses xvfb, fluxbox, x11vnc, and vmplayer to set up a virtual desktop
# accessible via VNC.
#
# Author: id774 (More info: http://id774.net)
# Source Code: https://github.com/id774/scripts
# License: The GPL version 3, or LGPL version 3 (Dual License).
# Contact: idnanashi@gmail.com
#
# Version History:
# v0.5 2025-04-13
# Unify log level formatting using [INFO], [WARN], and [ERROR] tags.
# v0.4 2025-03-25
# Rename start-vmplayer.sh to vmplayer-start.sh.
# Refactor main function to perform system and command checks.
# v0.3 2025-03-22
# Unify usage information by extracting help text from header comments.
# v0.2 2023-12-20
# Replaced 'which' with 'command -v' for command existence check.
# Updated script header for consistency.
# v0.1 2011-11-07
# First release.
#
# Usage:
# ./vmplayer-start.sh
#
# Notes:
# This script requires xvfb, fluxbox (non-free), x11vnc (non-free),
# and vmplayer (non-free) packages.
# Start with the privileges of the user.
#
# To connect from a client, use SSH port forwarding:
# ssh servername -L5900:localhost:5900
#
# Then, connect to localhost:5900 using xtightvncviewer.
# Kill the VNC and fluxbox for safety after starting VM.
#
########################################################################
# Display script usage information
usage() {
awk '
BEGIN { in_usage = 0 }
/^# Usage:/ { in_usage = 1; print substr($0, 4); next }
/^#{10}/ { if (in_usage) exit }
in_usage && /^#/ { print substr($0, 4) }
' "$0"
exit 0
}
# Function to check if the system is Linux
check_system() {
if [ "$(uname -s)" != "Linux" ]; then
echo "[ERROR] This script is intended for Linux systems only." >&2
exit 1
fi
}
# Function to check required commands
check_commands() {
for cmd in "$@"; do
cmd_path=$(command -v "$cmd" 2>/dev/null)
if [ -z "$cmd_path" ]; then
echo "[ERROR] Command '$cmd' is not installed. Please install $cmd and try again." >&2
exit 127
elif [ ! -x "$cmd_path" ]; then
echo "[ERROR] Command '$cmd' is not executable. Please check the permissions." >&2
exit 126
fi
done
}
# Start a virtual X server using Xvfb.
start_xvfb() {
sudo Xvfb $DISPLAY -screen 0 1024x768x24 2>&1 >> $TMP/xvfb.log &
sleep 10
}
# Launch the Fluxbox window manager.
start_fluxbox() {
fluxbox 2>&1 >> $TMP/window-manager.log &
sleep 5
}
# Start x11vnc server to expose the virtual display over VNC.
start_vnc() {
x11vnc -display $DISPLAY -loop -bg -nopw -listen localhost -xkb 2>&1 >> $TMP/vnc.log &
sleep 10
}
# Launch VMware Player twice (for redundancy or multiple instances).
start_vmplayer() {
vmplayer 2>&1 >> $TMP/vmplayer1.log &
vmplayer 2>&1 >> $TMP/vmplayer2.log &
sleep 10
}
# Start all required background processes in sequence.
start_daemon() {
start_xvfb
start_fluxbox
start_vnc
start_vmplayer
}
# Main function to execute the script
main() {
case "$1" in
-h|--help) usage ;;
esac
check_system
check_commands Xvfb fluxbox x11vnc vmplayer
test -n "$TMP" || export TMP=$HOME/.tmp
test -n "$1" && export DISPLAY=$1
test -n "$1" || export DISPLAY=:99
start_daemon
}
# Execute main function
main "$@"