Skip to content

Instantly share code, notes, and snippets.

@HirbodBehnam
Created November 23, 2022 06:50
Show Gist options
  • Save HirbodBehnam/4e53a853d4d7d8524199a596508f9bbf to your computer and use it in GitHub Desktop.
Save HirbodBehnam/4e53a853d4d7d8524199a596508f9bbf to your computer and use it in GitHub Desktop.
Split the files of a steam depot with maximum size of each group
#!/bin/bash
# A manifest file generated from https://github.com/SteamRE/DepotDownloader must be passed to the script.
# It should contain only the file lines.
# Use this script like bash depot-downloader-splitter.sh mainfest.txt 40000000000
rm part*.txt # remove old files
MAX_SIZE=$2 # maximum size of each part
CURRENT_SIZE=0
COUNTER=1
while read -r line; do
line=$(echo $line) # trim each column
size=$(cut -d' ' -f1 <<< "$line")
if [[ $(cut -d' ' -f4 <<< "$line") != "0" || "$size" == "0" ]]; then # skip folders and files with zero size
echo "skipped $line"
continue
fi
if [[ $((CURRENT_SIZE + size)) -gt $MAX_SIZE ]]; then # if size is more than specified amount, move to new file
COUNTER=$((COUNTER+1))
CURRENT_SIZE=0
fi
CURRENT_SIZE=$((CURRENT_SIZE + size))
echo $(cut -d' ' -f5 <<< "$line") >> "part$COUNTER.txt"
done <<< $(sort -r "$1")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment