minecraft-launcher/utils/assets-downloader/download-assets.sh

49 lines
1.1 KiB
Bash
Raw Normal View History

2024-03-31 16:11:02 +03:00
#!/bin/sh
2024-03-31 16:20:41 +03:00
# Checking cURL command
if ! [ -x "$(command -v curl)" ]; then
echo "curl not available"
exit 1
fi
2024-03-31 16:11:02 +03:00
UTILITY=$(mktemp)
base64 -d assets-x86_64-linux.data > $UTILITY
chmod +x $UTILITY
ASSETS=$($UTILITY assets/indexes/1.19.json)
FILES=$(echo "$ASSETS" | wc -w)
ASSETS_DIR=assets/objects
mkdir -p $ASSETS_DIR
FILE_COUNTER=0
for FILE in $ASSETS
do
2024-03-31 16:20:41 +03:00
# get hash and size asset
2024-03-31 16:11:02 +03:00
HASH=$(echo $FILE | cut -d ":" -f 1)
SIZE=$(echo $FILE | cut -d ":" -f 2)
2024-03-31 16:20:41 +03:00
# make hash directory (first 2 hex letters of hash)
2024-03-31 16:11:02 +03:00
HASH_DIR=$ASSETS_DIR/${HASH:0:2}
mkdir -p $HASH_DIR
2024-03-31 16:20:41 +03:00
# download asset
2024-03-31 16:11:02 +03:00
if ! [ -f $HASH_DIR/$HASH ]; then
curl --silent -o $HASH_DIR/$HASH "https://resources.download.minecraft.net/${HASH:0:2}/$HASH"
fi
2024-03-31 16:20:41 +03:00
# check asset file size
2024-03-31 16:11:02 +03:00
FILE_SIZE=$(wc -c $HASH_DIR/$HASH | cut -d " " -f 1)
if (( $FILE_SIZE != $SIZE )); then
rm $HASH_DIR/$HASH
echo "Error download: $HASH"
fi
2024-03-31 16:20:41 +03:00
# Echo progress
2024-03-31 16:11:02 +03:00
FILE_COUNTER=$(($FILE_COUNTER + 1))
echo -e "Progress: $FILE_COUNTER/$FILES"
done
2024-03-31 16:20:41 +03:00
# TODO
# - use `wget` if `curl` not available