prophunt-garrysmod/gmod/forceWorkshopDownload.sh

38 lines
1.1 KiB
Bash
Raw Normal View History

2019-07-21 23:04:00 +02:00
#!/bin/bash
if [ "${DEBUGGING}" = "true" ]; then
set -o xtrace
fi
set -o errexit
set -o nounset
set -o pipefail
#using WORKSHOP_COLLECTION_ID
LUA_PATH="${SERVER_PATH}/garrysmod/lua/autorun/server"
LUA_FILE="${LUA_PATH}/workshop_autoload.lua"
#remove old file
if [ -e "$LUA_FILE" ]; then
rm "$LUA_FILE"
else
mkdir -p "$LUA_PATH"
fi
2019-07-29 21:53:55 +02:00
if [ "$WORKSHOP_COLLECTION_ID" = "0" ] || [ "$WORKSHOP_COLLECTION_ID" = "" ] || [ "$WORKSHOP_AUTOLOAD" != "true" ]; then
echo "[forceWorkshopDownload.sh]No auto workshop download"
2019-07-21 23:04:00 +02:00
else
echo "[forceWorkshopDownload.sh]processing workshop collection ${WORKSHOP_COLLECTION_ID}"
2019-07-21 23:04:00 +02:00
touch "$LUA_FILE"
arr=$(wget -q -O - https://steamcommunity.com/sharedfiles/filedetails/?id="${WORKSHOP_COLLECTION_ID}" | tr '\n' ' ' | grep -Po '"workshopItem"[^"]+"https://steamcommunity.com/sharedfiles/filedetails/\?id=(\d+)' | grep -Po '\d\d\d+' )
str=""
2019-07-29 21:53:55 +02:00
# resplitting needed here, otherwise one string with complete ids
# shellcheck disable=SC2068
for i in ${arr[@]}
2019-07-21 23:04:00 +02:00
do
str=${str}"resource.AddWorkshop( \"${i}\" )"$'\n'
done
echo "$str" > "$LUA_FILE"
fi