1
0
Fork 0
mirror of https://github.com/xHyroM/aetheria.git synced 2024-11-09 17:58:05 +01:00
aetheria/mrpack-to-slugs.sh

39 lines
No EOL
915 B
Bash
Executable file
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# This script is used to convert .mrpack to slugs.txt
MRPACK_FILE=$1
if [ -z "$MRPACK_FILE" ]; then
echo "Please provide a .mrpack file"
exit 1
fi
MRPACK_NAME=$(basename "$MRPACK_FILE" ".mrpack")
MRPACK_NAME=${MRPACK_NAME// /-}
mkdir -p .cache
rm -rf .cache/*
rm -rf .output/*
mkdir -p .output/$MRPACK_NAME
# Extract the .mrpack file
unzip -o "$MRPACK_FILE" -d .cache/$MRPACK_NAME
# Chmod the index
chmod 755 .cache/$MRPACK_NAME/modrinth.index.json
# Get the slugs
length=$(jq -r '.files | length' .cache/$MRPACK_NAME/modrinth.index.json)
i=1
jq -r '.files[] | .downloads[0]' .cache/$MRPACK_NAME/modrinth.index.json | while read -r url; do
project_id=$(echo $url | cut -d'/' -f5)
slug=$(curl -s https://api.modrinth.com/v2/project/$project_id | jq -r '.slug')
echo "$slug ($project_id) ($i / $length)"
echo $slug >> .output/$MRPACK_NAME/slugs.txt
i=$((i+1))
done