-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.sh
More file actions
executable file
·53 lines (38 loc) · 1.14 KB
/
main.sh
File metadata and controls
executable file
·53 lines (38 loc) · 1.14 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
#!/bin/bash
#shellcheck source=shellcheck.sh
# main file
declare -r USERPID="$(uuidgen)"
#set -x
YOSH_PATH="${YOSH_PATH:-/usr/share/yosh}"
declare -r YOSH_PATH="${YOSH_PATH%/}"
# use autoloader
source ${YOSH_PATH}/autoloader.sh
_exit() {
# Send header
! [[ -z "$access_control_allow_origin" ]] && Http::send::header Access-Control-Allow-Origin "${access_control_allow_origin:-*}"
Http::send::out
# send data from route
[[ -s "$tmpStdout" ]] && cat $tmpStdout
if [[ -s "$tmpStderr" ]]; then
# Log::stack::trace
@error "$(<$tmpStderr)"
fi
Yosh::on::exit
}
set -o errtrace
#set -e
trap 'Log::stack::trace' ERR
# Clean TMP file on exit
trap '_exit' EXIT
# redirect stdout and stderr of function to file, to print after
tmpStdout="$(Mktemp::create)"
tmpStderr="$(Mktemp::create)"
Yosh::on::start
# check if application.sh exist
[[ -f "${DOCUMENT_ROOT%/}/../application.sh" ]] && source ${DOCUMENT_ROOT%/}/../application.sh
# Save stdout and stderr to a file, to print out the both
# route::check 1>$tmpStdout 2>$tmpStderr
Route::check 1>$tmpStdout 2>$tmpStderr
# exit like a pro
# TRAP will now do the job
exit