aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaroline Larimore <caroline@larimo.re>2025-08-18 01:20:50 -0700
committerCaroline Larimore <caroline@larimo.re>2025-08-18 01:20:50 -0700
commit0acd9acd953dae1dea70a9c1af45b825713e8a89 (patch)
treecb672a25217bc874d1297e05d512d586eb617954
parent8f035b6094fb2902e59fe764d7b59ccc13d084d1 (diff)
feat: accept game version as arg
-rwxr-xr-xmcsh.sh31
-rw-r--r--meta.jq1
2 files changed, 17 insertions, 15 deletions
diff --git a/mcsh.sh b/mcsh.sh
index 8436ee3..778ff66 100755
--- a/mcsh.sh
+++ b/mcsh.sh
@@ -8,19 +8,19 @@ NATIVES_DIR="natives"
ASSETS_DIR="assets"
GAME_DIR="run"
-VERSION="1.21.8"
-
function update_metadata (
printf 'updating version manifest\n' >&2
mkdir -p "$VERSIONS_DIR"
curl --silent "https://piston-meta.mojang.com/mc/game/version_manifest_v2.json" | jq '{"latest": .latest, "versions": [.versions[] | {"key": .id, "value": .url}] | from_entries}' > "$VERSIONS_DIR/manifest.json"
- printf 'updating %s meta %s\n' "$VERSION" >&2
- mkdir -p "$VERSIONS_DIR/$VERSION"
- curl --silent -o "$VERSIONS_DIR/$VERSION/meta.json" "$(jq -r --arg version "$VERSION" '.versions[$version]' $VERSIONS_DIR/manifest.json)"
- meta="$(jq -c --slurpfile info info.json --slurpfile auth auth.json -f meta.jq "$VERSIONS_DIR/$VERSION/meta.json")"
+ version="${1:-"$(jq -r '.latest.release' "$VERSIONS_DIR/manifest.json")"}"
+
+ printf 'updating %s meta %s\n' "$version" >&2
+ mkdir -p "$VERSIONS_DIR/$version"
+ curl --silent -o "$VERSIONS_DIR/$version/meta.json" "$(jq -r --arg version "$version" '.versions[$version]' $VERSIONS_DIR/manifest.json)"
+ meta="$(jq -c --slurpfile info info.json --slurpfile auth auth.json -f meta.jq "$VERSIONS_DIR/$version/meta.json")"
- printf 'updating %s asset index...\n' "$VERSION" >&2
+ printf 'updating %s asset index...\n' "$version" >&2
mkdir -p "$ASSETS_DIR/indexes"
assets_url="$(<<<"$meta" jq -r '.asset_index')"
curl --silent -o "$ASSETS_DIR/indexes/$(basename "$assets_url")" "$assets_url"
@@ -29,7 +29,7 @@ function update_metadata (
)
function launch (
- meta="$(update_metadata)"
+ meta="$(update_metadata "${1:-}")"
export LIBRARIES_DIR
function download_library {
@@ -52,9 +52,10 @@ function launch (
export -f download_asset
#TODO: check hash
- if ! [[ -e "$VERSIONS_DIR/$VERSION/client.jar" ]]; then
- printf 'downloading %s client jar...\n' "$VERSION" >&2
- <<<"$meta" jq -r '.client_url' | xargs curl --silent -o "$VERSIONS_DIR/$VERSION/client.jar"
+ version="$(<<<"$meta" jq -r '.version')"
+ if ! [[ -e "$VERSIONS_DIR/$version/client.jar" ]]; then
+ printf 'downloading %s client jar...\n' "$version" >&2
+ <<<"$meta" jq -r '.client_url' | xargs curl --silent -o "$VERSIONS_DIR/$version/client.jar"
fi
printf 'downloading libraries...\n' >&2
@@ -63,9 +64,9 @@ function launch (
printf 'downloading assets...\n' >&2
jq -r '.objects | to_entries[] | "\(.key) \(.value.hash[:2])/\(.value.hash)"' "$ASSETS_DIR/indexes/$(basename "$(<<<"$meta" jq -r '.asset_index')")" | xargs -P 10 -I {} "$SHELL" -c "download_asset {}"
- # if ! [[ -e "$VERSIONS_DIR/$VERSION/log4j.xml" ]]; then
- # printf 'downloading %s log4j config...\n' "$VERSION" >&2
- # <<<"$meta" jq -r '.logging_config' | xargs curl --silent -o "$VERSIONS_DIR/$VERSION/log4j.xml"
+ # if ! [[ -e "$VERSIONS_DIR/$version/log4j.xml" ]]; then
+ # printf 'downloading %s log4j config...\n' "$version" >&2
+ # <<<"$meta" jq -r '.logging_config' | xargs curl --silent -o "$VERSIONS_DIR/$version/log4j.xml"
# fi
function replace_placeholders {
@@ -81,4 +82,4 @@ function launch (
<<<"$meta" jq -r '.args.jvm + [.main_class] + .args.game | join(" ")' | replace_placeholders | xargs java
)
-launch
+launch "${1:-}"
diff --git a/meta.jq b/meta.jq
index 44de571..138ef15 100644
--- a/meta.jq
+++ b/meta.jq
@@ -57,6 +57,7 @@ replace_placeholders | {
"path": .downloads.artifact.path,
"url": .downloads.artifact.url
}],
+ "version": .id,
"asset_index": .assetIndex.url,
"java_version": .javaVersion.majorVersion,
"client_url": .downloads.client.url,