Skip to content

Commit

Permalink
Merge pull request #175 from phyzical/master
Browse files Browse the repository at this point in the history
Copy less files in Docker and download git updates
  • Loading branch information
kus authored Jan 22, 2025
2 parents 5883d0b + 6b8f6f4 commit ab569a2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
.env copy
/custom_files/*
cs2
tmp
10 changes: 9 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@ ENV SRC_DIR="/home/cs2-modded-server"

WORKDIR $SRC_DIR

COPY . $SRC_DIR
COPY custom_files $SRC_DIR/custom_files

COPY install_docker.sh \
run.sh \
start.sh \
stop.sh \
$SRC_DIR

COPY game/csgo $SRC_DIR/game/csgo

USER steam

Expand Down
45 changes: 45 additions & 0 deletions scripts/check-updates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,50 @@ fetch_last_updated() {
fi
}

download_and_extract_latest_release() {
local repo_url="$1"
if [[ $repo_url != *"github.com"* ]]; then
echo "Unsupported URL: $repo_url"
return
fi

local repo_name=$(echo "$repo_url" | awk -F'github.com/' '{print $2}')
local latest_release_urls=$(curl -s "https://api.github.com/repos/${repo_name}/releases/latest" | grep "browser_download_url" | cut -d '"' -f 4)

if [ -z "$latest_release_urls" ]; then
echo "No releases found for $repo_name"
return 1
fi

rm -rf "./tmp/${repo_name}"
local temp_dir="./tmp/${repo_name}"
mkdir -p "${temp_dir}" || echo ""

for url in $latest_release_urls; do
local temp_file="./tmp/$(basename "$url")"
local temp_unzip_dir="$temp_dir"

if [[ "$temp_file" == *"windows"* ]]; then
temp_unzip_dir="$temp_unzip_dir/windows"
elif [[ "$temp_file" == *"linux"* ]]; then
temp_unzip_dir="$temp_unzip_dir/linux"
fi

if [ ! -f "$temp_file" ]; then
echo "Downloading latest release from $url..."
curl -L -o "$temp_file" "$url"
fi

echo "Extracting $temp_file..."
case "$temp_file" in
*.tar.gz) tar --overwrite -xzf "$temp_file" -C "$temp_unzip_dir" >/dev/null ;;
*.zip) unzip -o "$temp_file" -d "$temp_unzip_dir" >/dev/null ;;
*) echo "Unsupported file format: $temp_file" ;;
esac
done
echo "Latest release downloaded and extracted to $temp_dir"
}

main() {
# Call extract_mods and read output into an array
IFS=$'\n' read -rd '' -a modList < <(extract_mods)
Expand All @@ -105,6 +149,7 @@ main() {
echo -e "\033[0;32m✅ ${name} ${latest_release}\033[0m"
else
echo -e "\033[0;33m📦 ${name} update available ${version} > ${latest_release} ${url}\033[0m"
download_and_extract_latest_release "$url"
fi
elif [ -n "$last_updated" ]; then
echo -e "\033[1;30m🔍 ${name} ${version} - Last updated ${last_updated} ${url}\033[0m"
Expand Down

0 comments on commit ab569a2

Please sign in to comment.