-
Notifications
You must be signed in to change notification settings - Fork 321
/
Copy patharma3managemods.sh
63 lines (49 loc) · 1.85 KB
/
arma3managemods.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
#!/bin/bash
ModDirFormat="$1"
cd ./arma3/233780
workshopDir="./steamapps/workshop/content/107410"
if [ -d "$workshopDir" ]; then
echo "Converting and linking mods"
# Convert uppercase filenames to lowercase
find "$workshopDir/" -depth -name "*[A-Z]*" -print0 | \
xargs -0 -I {} bash -c "mv \"{}\" \"\$(echo \"{}\" | sed 's,\(.*\)\/\(.*\),\1\/\L\2,')\"" >/dev/null 2>&1
find "$workshopDir" -maxdepth 1 -mindepth 1 -type d | while read -r modDir; do
modName=""
# Extract modName from meta.cpp
metaCppPath="$modDir/meta.cpp"
if [ -f "$metaCppPath" ]; then
modName=$(sed -n 's/^[[:space:]]*name[[:space:]]*=[[:space:]]*"\([^"]\+\)".*/\1/p' "$metaCppPath")
fi
if [ -z "$modName" ]; then
# Fallback: Try mod.cpp if meta.cpp does not contain a name
modCppPath="$modDir/mod.cpp"
if [ -f "$modCppPath" ]; then
modName=$(sed -n 's/^[[:space:]]*name[[:space:]]*=[[:space:]]*"\([^"]\+\)".*/\1/p' "$modCppPath")
fi
if [ -z "$modName" ]; then
# Final fallback: Try fetching name from Steam workshop webpage if no name found
modID=$(basename "$modDir")
modName=$(wget -qO- "https://steamcommunity.com/workshop/filedetails/?id=$modID" | \
sed -n 's/.*<div class="workshopItemTitle">\([^<]*\)<\/div>.*/\1/p' | head -n 1)
if [ -z "$modName" ]; then
echo "Error: Unable to retrieve name for workshop item $modID. Skipping"
continue
fi
fi
fi
if [ "$ModDirFormat" = "false" ]; then
# Remove @name symlinks
rm -f "./@$modName" >/dev/null 2>&1
# Create numbered symlinks
ln -sf "$modDir" ./
else
# Remove numbered symlinks
rm -f "./$(basename "$modDir")" >/dev/null 2>&1
# Create @name symlink
ln -sfT "$modDir" "./@$modName"
fi
done
else
echo "No mods to convert and link"
fi
exit 0