Blob


1 #!/bin/sh
3 set -euo pipefail
5 DATA_DIR="${XDG_DATA_HOME:-$HOME/.local/share}"/mcl
7 parse_flags() {
8 local usage="usage: mcl -v <version>"
9 while getopts v: name; do
10 case "$name" in
11 v) version="$OPTARG"
12 ;;
13 *) echo "$usage" && exit 1
14 ;;
15 esac
16 done
17 if [ "${version:-}" = "" ]; then
18 echo "$usage" && exit 1
19 fi
20 }
22 ensure_rootfs() {
23 local rootfs="$1"
24 if [ ! -d "$rootfs" ]; then
25 mkdir -p "$rootfs"
26 wget -O- https://cloud-images.ubuntu.com/minimal/releases/jammy/release/ubuntu-22.04-minimal-cloudimg-amd64-root.tar.xz \
27 | xzcat \
28 | tar -xC "$rootfs" --exclude dev --exclude /var/lib/snapd/void
29 fi
30 }
32 ensure_worlds() {
33 local worlds="$1"
34 mkdir -p "$worlds"
35 }
37 ensure_version() {
38 local version="$1"
39 local dir="$2"
40 if [ ! -d "$dir" ]; then
41 local archive
42 archive="$(mktemp -t minecraft.zip-XXXXXX)"
43 wget -O "$archive" https://minecraft.azureedge.net/bin-linux/bedrock-server-"$version".zip
44 mkdir -p "$dir"
45 unzip -q "$archive" -d "$dir"
46 rm -f "$archive"
47 fi
48 local crun="$dir".config.json
49 if [ ! -f "$crun" ]; then
50 local mcl_dir
51 mcl_dir="$(dirname "$(readlink "$0")")"
52 sed "s/__VERSION__/${version}/" \
53 < "$mcl_dir"/config.json > "$crun"
54 fi
55 }
57 parse_flags "$@"
58 ensure_rootfs "$DATA_DIR"/rootfs
59 ensure_worlds "$DATA_DIR"/worlds
60 ensure_version "$version" "$DATA_DIR"/versions/"$version"
61 exec crun run -b "$DATA_DIR" -f "$DATA_DIR"/versions/"$version".config.json mcl-"$version"