This repository has been archived by the owner on Feb 21, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinstall-navmesh
executable file
·144 lines (127 loc) · 3.96 KB
/
install-navmesh
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
#!/bin/bash
# Function to detect the Linux distribution
detect_distro() {
if [ -f /etc/os-release ]; then
. /etc/os-release
case "$ID" in
"garuda")
echo "arch" # Garuda is Arch-based
;;
"linuxmint"|"ubuntu")
echo "debian" # Mint and Ubuntu are Debian-based
;;
*)
echo "$ID"
;;
esac
elif [ -f /etc/arch-release ]; then
echo "arch"
elif [ -f /etc/debian_version ]; then
echo "debian"
elif [ -f /etc/fedora-release ]; then
echo "fedora"
elif [ -f /etc/gentoo-release ]; then
echo "gentoo"
elif [ -f /etc/void-release ]; then
echo "void"
else
echo "unknown"
fi
}
# Function to install pv if missing
ensure_pv_installed() {
if ! command -v pv >/dev/null 2>&1; then
print_colored "blue" "Installing pv package for progress bars..."
local distro=$(detect_distro)
case "$distro" in
"manjaro"|"arch")
sudo pacman -S --needed pv
;;
"ubuntu"|"debian")
sudo apt-get update
sudo apt-get install -y pv
;;
"fedora")
sudo dnf install -y pv
;;
*)
print_colored "red" "Could not install pv. Progress bars will be disabled."
return 1
;;
esac
fi
return 0
}
# Function to find TF2 installation directory
find_tf2_dir() {
local default_paths=(
"$HOME/.steam/steam/steamapps/common/Team Fortress 2"
"$HOME/.local/share/Steam/steamapps/common/Team Fortress 2"
"$HOME/Steam/steamapps/common/Team Fortress 2"
)
for path in "${default_paths[@]}"; do
if [ -d "$path" ]; then
echo "$path"
return 0
fi
done
return 1
}
# Print colored text
print_colored() {
local color=$1
local text=$2
case $color in
"green") echo -e "\033[32m${text}\033[0m" ;;
"blue") echo -e "\033[34m${text}\033[0m" ;;
"red") echo -e "\033[31m${text}\033[0m" ;;
*) echo "${text}" ;;
esac
}
# Main script
# Try to install pv if missing
ensure_pv_installed
PV_AVAILABLE=$?
print_colored "blue" "Downloading navmesh files..."
temp_dir=$(mktemp -d)
wget --progress=bar:force:noscroll https://cdn.cathook.org/goyslop/catbot-navmesh.zip -O "$temp_dir/catbot-navmesh.zip" 2>&1 | stdbuf -o0 tr '\r' '\n' | grep -o '[0-9]*%'
if [ $? -ne 0 ]; then
print_colored "red" "Failed to download catbot-navmesh.zip"
rm -rf "$temp_dir"
exit 1
fi
# Find TF2 directory
tf2_dir=$(find_tf2_dir)
if [ -z "$tf2_dir" ]; then
echo "TF2 isn't installed, or couldn't find the installation directory."
echo "Please either install TF2 or manually specify the path."
echo "The path should look like: ~/.steam/steam/steamapps/common/Team Fortress 2/"
read -p "Enter TF2 path (or press Ctrl+C to cancel): " tf2_dir
if [ ! -d "$tf2_dir" ]; then
print_colored "red" "Invalid directory!"
rm -rf "$temp_dir"
exit 1
fi
fi
# Check if tf directory exists
tf_dir="$tf2_dir/tf/maps"
if [ ! -d "$tf_dir" ]; then
print_colored "red" "Could not find tf directory in $tf2_dir"
rm -rf "$temp_dir"
exit 1
fi
print_colored "blue" "Found TF2 directory: $tf2_dir"
print_colored "blue" "Extracting navmesh files to tf directory..."
# Use pv if available, otherwise use regular unzip
if [ $PV_AVAILABLE -eq 0 ] && command -v pv >/dev/null 2>&1; then
unzip -o "$temp_dir/catbot-navmesh.zip" -d "$tf_dir" | pv -l -s $(unzip -l "$temp_dir/catbot-navmesh.zip" | tail -n 1 | awk '{print $2}') > /dev/null
else
unzip -o "$temp_dir/catbot-navmesh.zip" -d "$tf_dir"
fi
if [ $? -eq 0 ]; then
print_colored "green" "Navmesh files installed successfully!"
else
print_colored "red" "Failed to extract navmesh files!"
fi
# Cleanup
rm -rf "$temp_dir"