Blame


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