/
RunCharon.sh
146 lines (125 loc) · 3.72 KB
/
RunCharon.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
# ###### DETERMINE CURRENT DIRECTORY ##########
SCRIPT_DIR=$(cd "`dirname "$0"`" && pwd)
EXECUTABLE_DIR=$SCRIPT_DIR
EXECUTABLE_NAME="Charon.exe"
EXECUTABLE_PATH="$SCRIPT_DIR/$EXECUTABLE_NAME"
EXITCODE=0
RESTORE_IS_DONE=0
check_mono_version() {
local mono_version=$(mono --version | head -n1 | grep -oE 'version [0-9]+' | awk '{print $2}')
if [[ -z "$mono_version" ]]; then
exit_failure_wrong_or_missing_mono
fi
if (( mono_version < 5 )); then
exit_failure_wrong_or_missing_mono
fi
}
locate_executable() {
FILE_NAME="Charon.exe"
for D in "$SCRIPT_DIR"/gamedevware.charon/*/; do
if [[ -e "$D/tools/$EXECUTABLE_NAME" ]]; then
EXECUTABLE_DIR="$D/tools"
EXECUTABLE_PATH="$D/tools/$EXECUTABLE_NAME"
return
fi
done
if [[ "$RESTORE_IS_DONE" == "1" ]]; then
exit_failure_no_executable
fi
if [ ! -f "$SCRIPT_DIR/Charon.csproj" ]; then
cat > "$SCRIPT_DIR/Charon.csproj" << EOF
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="GameDevWare.Charon" Version="*" />
</ItemGroup>
</Project>
EOF
fi
# ###### RESTORING NUGET PACKAGE ##########
pushd "$SCRIPT_DIR" > /dev/null
dotnet restore --packages "." --force --ignore-failed-sources > /dev/null
EXITCODE=$?
popd > /dev/null
RESTORE_IS_DONE=1
if [[ "$EXITCODE" != "0" ]]; then
exit_failure_dotnet_restore_failed
fi
locate_executable
}
run_executable() {
if [ ! -f "$SCRIPT_DIR/appsettings.json" ]; then
cat > "$SCRIPT_DIR/appsettings.json" << EOF
{
"Logging": {
"LogLevel": {
"Default": "Debug"
}
},
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
"MinimumLevel": "Debug",
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "logs/log_.txt",
"rollingInterval": "Day",
"buffered": false,
"fileSizeLimitBytes": 10485760,
"rollOnFileSizeLimit": true,
"outputTemplate": "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}: {Message}{NewLine}{Exception}"
}
}
],
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
"Properties": {
"Application": "Charon"
}
}
}
EOF
fi
STANDALONE__APPLICATIONDATAPATH="$SCRIPT_DIR/data"
STANDALONE__APPLICATIONTEMPPATH="$SCRIPT_DIR/temp"
SERILOG__WRITETO__0__NAME="File"
SERILOG__WRITETO__0__ARGS__PATH="$SCRIPT_DIR/logs/log_.txt"
# Drop in configuration file before launching executable
cp "$SCRIPT_DIR/appsettings.json" "$EXECUTABLE_DIR/appsettings.json"
# Run 'mono Charon.exe' with passed parameters
mono "$EXECUTABLE_PATH" "$@"
EXITCODE=$?
if [[ "$EXITCODE" != "0" ]]; then
exit_failure
else
exit_success
fi
}
exit_failure_wrong_or_missing_mono() {
EXITCODE=-3
echo "Wrong or missing installation of 'mono' framework. Ensure that the 'mono' v5+ is installed and available in the 'PATH'. Check https://www.mono-project.com/download/stable/ for the installer."
exit_failure
}
exit_failure_dotnet_restore_failed() {
EXITCODE=-2
echo "Failed to execute the 'dotnet restore' command to retrieve the latest package version from NuGet. Ensure that the 'dotnet' tool is installed and available in the 'PATH'. Check 'https://dotnet.microsoft.com/en-us/download' for the installer."
exit_failure
}
exit_failure_no_executable() {
EXITCODE=-1
echo "Unable to find the '$FILE_NAME' executable in './gamedevware.charon/*/tools' subfolders."
exit_failure
}
exit_failure() {
exit $EXITCODE
}
exit_success() {
exit 0
}
# Start the process
check_mono_version
locate_executable
run_executable "$@"