-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-renderer.sh
More file actions
165 lines (138 loc) · 3.91 KB
/
Copy pathrun-renderer.sh
File metadata and controls
165 lines (138 loc) · 3.91 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/bin/bash
#
# Run Physics
#KNOWN issues
set -euo pipefail
#################################################
# Helper functions
#################################################
function err() {
printf "\e[41;37m[%s]: %s\e[0m\n" "$(date +'%Y-%m-%dT%H:%M:%S%z')" "$*" >&2
exit 1
}
function log() {
local level="${1}"
shift
if [[ $level == 'verbose' ]] && [[ $VERBOSE != 'true' ]]; then
return
fi
if [[ $level == 'warning' ]]; then
printf "\e[43;30m"
fi
printf "[%s]: %s" "$(date +'%Y-%m-%dT%H:%M:%S%z')" "$*"
if [[ $level == 'warning' ]]; then
printf "\e[0m"
fi
printf "\n"
}
function usage() {
local usage_info="Arguments:
-i <ip_address>
IP address to listen on for.
-p <port_number>
Port to listen on.
-v
Activate verbose logging."
printf "%s\n" "${usage_info}"
}
function ctrl_c_intercepted() {
kill -SIGKILL -$$
exit 1
}
trap ctrl_c_intercepted SIGINT
#################################################
# Arguments
#################################################
VERBOSE='false'
port=''
interface=''
renderer=''
render_path=''
while getopts :b:i:p:r:vh flag; do
case "$flag" in
i) interface="${OPTARG}" ;;
p) port="${OPTARG}";;
b) renderer="${OPTARG}" ;;
r) render_path="${OPTARG}";;
v)
VERBOSE='true'
set -x
;;
h)
usage
exit 0
;;
\?)
usage
err "Invalid option: ${OPTARG}." ;;
: )
usage
err "Invalid option: ${OPTARG} requires an argument." ;;
esac
done
readonly VERBOSE
readonly port
readonly interface
#################################################
# Validate arguments
#################################################
if [[ -z $renderer ]]; then
err "Missing path to executable. Ensure that this is the path to the built unity executable"
elif [[ ! -f $renderer ]] || [[ ! -x $renderer ]]; then
err "Cannot run executable at ${renderer}. Ensure path is valid and you\
have the correct permissions."
fi
# validate port
if [ -n "$port" ] && { [[ ! $port == +([0-9]) ]] || [[ $port -lt 1024 ]] \
|| [[ $port -gt 65535 ]]; }; then
err "Invalid port value (${port}) provided. Ensure that it is an \
integer between 1024 and 65535."
fi
# validate render path
if [ -n "$render_path" ]; then
if ! readlink -m "${render_path}" > /dev/null; then
err "Invalid render path \"${render_path}\""
# Try to create the directory if it does not exist
elif ! readlink -e "${render_path}" > /dev/null \
&& ! mkdir -p "${render_path}"; then
err "Could not create render output directory."
# Check permissions for path
elif [[ ! -r $render_path ]] || [[ ! -w $render_path ]]; then
err "Missing permissions for render output directory. \
Please ensure that you have the required permissions for this directory."
# Resolve the path
else
render_path=$(readlink -e "${render_path}")
fi
fi
#################################################
# Unparse args and run
#################################################
run_renderer=("${renderer}" "-batchmode")
run_renderer+=("-logFile")
if [[ $VERBOSE != 'true' ]]; then
run_renderer+=("\"./renderer.log\"")
else
run_renderer+=("/dev/stdout")
fi
run_renderer+=("renderer")
if [ -n "$port" ]; then
run_renderer+=('--port' "${port}")
fi
if [ -n "$interface" ]; then
run_renderer+=('--interface' \""${interface}\"")
fi
if [ -n "$render_path" ]; then
run_renderer+=('--renderPath' \""${render_path}\"")
fi
log verbose "Renderer arguments:" "${run_renderer[@]}"
DISPLAY=:0 eval "${run_renderer[@]}" &
renderer_pid=$!
while [[ -d "/proc/${renderer_pid}" ]]; do
sleep 0.25
done
if wait "${renderer_pid}"; then
log normal "Renderer has completed successfully."
else
err "Renderer failed to complete successfully"
fi