-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateFunctions.sh
58 lines (44 loc) · 1.45 KB
/
updateFunctions.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
#!/bin/bash
get_factorio_version() {
local basePath=$1
# Ensure a base path was provided
if [ -z "$basePath" ]; then
echo "Please provide the base path to the Factorio binary."
return 1
fi
# Construct the full path to the Factorio binary
local binary_path="$basePath/bin/x64/factorio"
# Check if the binary exists at the specified path
if [ ! -f "$binary_path" ]; then
echo "Factorio binary not found at $binary_path."
return 1
fi
# Run the Factorio binary with --version and capture the output
local output
output=$("$binary_path" --version)
# Parse the output to extract the Factorio version
local version
version=$(echo "$output" | grep -oP 'Version: \K.*?(?= \()')
# Output the version
echo "$version"
}
compare_versions() {
local baseVersion=$1
local currentGameVersion=$2
if [ "$(printf '%s\n' "$baseVersion" "$currentGameVersion" | sort -V | head -n1)" != "$baseVersion" ]; then
echo true # baseVersion is greater than currentGameVersion
else
echo false # baseVersion is not greater than currentGameVersion
fi
}
join_by_comma() {
# Save the current IFS value.
local oldIFS=$IFS
# Temporarily change the IFS value to a comma.
IFS=','
# Use "${@}" to join the arguments into a string.
local result="$*"
# Restore the original IFS value.
IFS=$oldIFS
echo "$result"
}