aboutsummaryrefslogtreecommitdiff
path: root/mcsh.sh
diff options
context:
space:
mode:
authorCaroline Larimore <caroline@larimo.re>2025-11-27 14:23:24 -0800
committerCaroline Larimore <caroline@larimo.re>2025-11-27 14:23:24 -0800
commitb1e559ef3a9e68538d057f37779277f12abaae77 (patch)
tree05c8561a4e8045e67d4ffdaff20911d4a6d282cb /mcsh.sh
parent55dd94a95f7c597c9e45276cfb9306746d9eefe0 (diff)
refactor: move version updating to function
Diffstat (limited to 'mcsh.sh')
-rwxr-xr-xmcsh.sh168
1 files changed, 87 insertions, 81 deletions
diff --git a/mcsh.sh b/mcsh.sh
index 9c0ecca..ed3092a 100755
--- a/mcsh.sh
+++ b/mcsh.sh
@@ -186,91 +186,88 @@ function update_profile (
jq --arg profile "$profile" '.[$profile]' "$DATA_DIR/profiles.json"
)
-function update_metadata (
- meta_filter="$(cat <<-'EOF'
- def apply_optional: if has("rules") then
- {
- "rules": [.rules[] | {
- "action": .action,
- "match": del(.action)
+function update_version (
+ function update_metadata (
+ meta_filter="$(cat <<-'EOF'
+ def apply_optional: if has("rules") then
+ {
+ "rules": [.rules[] | {
+ "action": .action,
+ "match": del(.action)
+ }],
+ "value": del(.rules)
+ } as $optional
+ | if $optional.rules[].match | inside($info[0]) then
+ $optional.value
+ else
+ empty
+ end
+ end;
+
+ def replace_placeholders: {
+ "version_name": .id,
+ "version_type": .type,
+
+ "assets_index_name": .assets,
+
+ "classpath": (. as $root | [
+ .libraries[] | apply_optional | "${libraries_directory}/" + .downloads.artifact.path
+ ] + ["${versions_directory}/\($root.id)/client.jar"] | join(":")),
+ "clientid": "idfk",
+
+ # log4j config path
+ "path": "${versions_directory}/\(.id)/log4j.xml"
+ } as $strings | walk(if type == "string" then
+ gsub("\\${(?<key>.*)}"; "\($strings[.key] // "${\(.key)}")")
+ end);
+
+ replace_placeholders | {
+ "args": .arguments | to_entries | [.[] | {
+ "key": .key,
+ "value": .value | [
+ .[] | if type == "object" then
+ apply_optional | .value
+ end
+ ] | flatten
+ }] | from_entries, # as $args | $args + {"jvm": [.logging.client.argument] + $args.jvm}),
+ "libraries": [.libraries[] | apply_optional | {
+ "name": .name,
+ "path": .downloads.artifact.path,
+ "url": .downloads.artifact.url
}],
- "value": del(.rules)
- } as $optional
- | if $optional.rules[].match | inside($info[0]) then
- $optional.value
- else
- empty
- end
- end;
-
- def replace_placeholders: {
- "version_name": .id,
- "version_type": .type,
-
- "assets_index_name": .assets,
-
- "classpath": (. as $root | [
- .libraries[] | apply_optional | "${libraries_directory}/" + .downloads.artifact.path
- ] + ["${versions_directory}/\($root.id)/client.jar"] | join(":")),
- "clientid": "idfk",
-
- # log4j config path
- "path": "${versions_directory}/\(.id)/log4j.xml"
- } as $strings | walk(if type == "string" then
- gsub("\\${(?<key>.*)}"; "\($strings[.key] // "${\(.key)}")")
- end);
-
- replace_placeholders | {
- "args": .arguments | to_entries | [.[] | {
- "key": .key,
- "value": .value | [
- .[] | if type == "object" then
- apply_optional | .value
- end
- ] | flatten
- }] | from_entries, # as $args | $args + {"jvm": [.logging.client.argument] + $args.jvm}),
- "libraries": [.libraries[] | apply_optional | {
- "name": .name,
- "path": .downloads.artifact.path,
- "url": .downloads.artifact.url
- }],
- "version": .id,
- "asset_index": .assetIndex.url,
- "java_version": .javaVersion.majorVersion,
- "client_url": .downloads.client.url,
- "main_class": .mainClass,
- "logging_config": .logging.client.file.url
- }
- EOF
- )"
-
- 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"
-
- version="${1:-}"
- if [[ "$version" == "" || "$version" == "latest" || "$version" == "release" ]]; then
- version="$(jq -r '.latest.release' "$VERSIONS_DIR/manifest.json")"
- elif [[ "$version" == "snapshot" ]]; then
- version="$(jq -r '.latest.snapshot' "$VERSIONS_DIR/manifest.json")"
- fi
+ "version": .id,
+ "asset_index": .assetIndex.url,
+ "java_version": .javaVersion.majorVersion,
+ "client_url": .downloads.client.url,
+ "main_class": .mainClass,
+ "logging_config": .logging.client.file.url
+ }
+ EOF
+ )"
+
+ 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"
+
+ version="${1:-}"
+ if [[ "$version" == "" || "$version" == "latest" || "$version" == "release" ]]; then
+ version="$(jq -r '.latest.release' "$VERSIONS_DIR/manifest.json")"
+ elif [[ "$version" == "snapshot" ]]; then
+ version="$(jq -r '.latest.snapshot' "$VERSIONS_DIR/manifest.json")"
+ fi
- 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 "$meta_filter" "$VERSIONS_DIR/$version/meta.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 "$meta_filter" "$VERSIONS_DIR/$version/meta.json")"
- 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"
+ 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"
- printf '%s\n' "$meta"
-)
-
-function launch (
- profile="$(update_profile "$(auth "${2:-}")")"
- printf '\n' >&2
+ printf '%s\n' "$meta"
+ )
meta="$(update_metadata "${1:-}")"
@@ -312,6 +309,15 @@ function launch (
# <<<"$meta" jq -r '.logging_config' | xargs curl --silent -o "$VERSIONS_DIR/$version/log4j.xml"
# fi
+ printf '%s\n' "$meta"
+)
+
+function launch (
+ profile="$(update_profile "$(auth "${2:-}")")"
+ printf '\n' >&2
+
+ meta="$(update_version "${1:-}")"
+
function replace_placeholders {
cat - | sed \
-e "s:\${versions_directory}:$VERSIONS_DIR:g" \