Knowledge Base

Preserving for the future: Shell scripts, AoC, and more

Initialize Mineclonia git repo

I was testing my latest build of mineclonia dpkg which bundles the latest halon luanti client with the latest mineclonia game itself.

I wanted to start fresh, so I wiped the .minetest directory, and whipped up a script to bootstrap all the mods.

I also realized I should mirror all the repositories of projects I care about, in case they disappear from the Internet, but I haven't automated that process yet.

files/2026/listings/initialize-mineclonia.sh (Source)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/sh
# File: initialize-mineclonia.sh
# Location: http://server3/git/luanti/initialize-mineclonia/
# Author: bgstack15
# Startdate: 2026-01-25-1 10:03
# Title:
# Project: initialize-mineclonia
# Purpose: Turn https://bgstack15.ddns.net/blog/posts/2025/12/01/my-necessary-luanti-mods-for-mineclonia/ into a shell script
# Usage:
#     Run this after `apt-get install mineclonia`
# References:
#    https://bgstack15.ddns.net/cgit/luanti/mineclonia-dpkg/tree/debian/README.debian
#    Dpkg from https://bgstack15.ddns.net/blog/posts/2025/09/28/package-for-devuan-mineclonia/
# Improve:
#    Save down all non-cgit code in case it disappears upstream. Update my-necessary-luanti-mods-for-mineclonia.md to offer the backup local repos.
# Dependencies:
#     sudo apt-get install mineclonia

mineclonia_repo="https://codeberg.org/mineclonia/mineclonia"
host="http://server3/git"

ginit() {
    echo "# ginit ${@}" 1>&2
    (
    # from google AI "function to git clone or cd and change branch" and adapted 2026-01-25-1 10:43
    # Check if correct number of arguments are provided (URL and optionally branch name)
    if [ "$#" -lt 1 ]; then
        echo "Usage: ginit <repository_url> [branch_name] [dirname]"
        return 1
    fi
    REPO_URL=$1
    # Extract repository name from URL (simple heuristic for common Git URLs)
    REPO_DIR=$(basename "$REPO_URL" .git)
    BRANCH_NAME=$2
    DIRNAME=$3
    if test -n "${DIRNAME}" ; then REPO_DIR="${DIRNAME}" ; fi
    if [ -d "$REPO_DIR" ]; then
        echo "Directory $REPO_DIR already exists. Changing directory to it."
        cd "$REPO_DIR" || return # Change directory
        if [ -n "$BRANCH_NAME" ]; then
            echo "Switching to branch $BRANCH_NAME"
            git fetch --all
            # Use 'git switch' (modern) or 'git checkout' (older versions)
            # 'git switch -c' creates and switches to a new branch if it doesn't exist locally
            git switch -c "$BRANCH_NAME" "origin/$BRANCH_NAME" || git checkout -b "$BRANCH_NAME" "origin/$BRANCH_NAME" || git checkout "$BRANCH_NAME"
        fi
    else
        # Clone the repository with the specified branch (if provided)
        if [ -n "$BRANCH_NAME" ]; then
            echo "Cloning branch $BRANCH_NAME into $REPO_DIR"
            git clone -b "$BRANCH_NAME" "$REPO_URL" "${REPO_DIR}"
        else
            echo "Cloning default branch into $REPO_DIR"
            git clone "$REPO_URL" "${REPO_DIR}"
        fi
        # Change directory into the cloned repository
        if [ -d "$REPO_DIR" ]; then
            cd "$REPO_DIR" || return
            git pull
            echo "Changed directory to $REPO_DIR"
        else
            echo "Failed to clone repository or directory name $REPO_DIR is different from heuristic."
            return 1
        fi
    fi
    )
}

# Mineclonia game itself
install_mineclonia() {
    mkdir -p ~/.minetest/games ; cd ~/.minetest/games
    ginit "${mineclonia_repo}" 0.119.0 mineclonia
}

# Mods
install_mods() {
    mkdir -p ~/.minetest/mods ; cd ~/.minetest/mods
    ginit "${host}/luanti/enchantments_extractor" dev
    ginit "${host}/luanti/enchantments_workbench"
    ginit "${host}/luanti/farmtools" feature/fix-warnings
    ginit "${host}/luanti/minetest_inventory_icon" feature/add-pouches inventory_icon
    ginit "${host}/luanti/inventory_pouches" combined
    ginit "${host}/luanti-readonly/minetest-k-ambient-light" "main" k_ambient_light
    ginit "${host}/luanti-readonly/minetest-k-recycler" "main" k_recycle_bin
    ginit "${host}/luanti/lava_furnace" feature/support-voxelibre
    ginit "${host}/luanti-readonly/leads" main
    ginit "${host}/luanti/list_to_file" dev/add_list_items_to_file
    ginit "${host}/luanti-readonly/mapserver_mod" "" mapserver
    ginit "${host}/luanti/mcl_chiseled_bookshelf"
    ginit "${host}/luanti/mcl_colored_chests"
    ginit "${host}/luanti-readonly/mcl_copper_stuff"
    ginit "${host}/luanti/mcl_cozy"
    ginit "${host}/luanti-readonly/mcl_decor"
    ginit "${host}/luanti/mcl_emerald_stuff" main
    ginit "${host}/luanti/mcl_lapis_stuff"
    ginit "${host}/luanti/mcl_misk_recipes" main
    ginit "${host}/luanti/mcl_morefood" feature/add-applesauce
    ginit "${host}/luanti/milk_potion"
    ginit "${host}/luanti/molten_sailor_mcl"
    ginit "${host}/luanti/mtimer" feature/add-biome
    ginit "${host}/luanti-readonly/mtui_mod"
    ginit "${host}/luanti/obsidian_extra"
    ginit "${host}/luanti-readonly/playerlist" main
    ginit "${host}/luanti-readonly/minetest_poi" "" poi
    ginit "${host}/luanti/privs_per_world"
    ginit "${host}/luanti/mt-respawn" dev/add-dialog respawn
    ginit "${host}/luanti/safe_chest" dev/support-mineclonia
    ginit "${host}/luanti-readonly/snippets"
}

install_config() {
    # use LUANTI_CONFIG if defined, otherwise, use from directory where this script is stored.
    tf="${LUANTI_CONFIG:-${_td}/minetest.conf}"
    if test -f "${tf}" ;
    then
        echo "Installing luanti config ${tf}. You can use env var LUANTI_CONFIG to override." 1>&2
        cp -pf "${tf}" ~/.minetest/
    fi
}

_td="$( dirname "$( readlink -f "${0}" )" )"

main() {
    install_mineclonia
    install_mods
    install_config
}

# BEGIN IS-SOURCED
sourced=0
if [ -n "$ZSH_VERSION" ]; then 
   case $ZSH_EVAL_CONTEXT in *:file) sourced=1;; esac
elif [ -n "$KSH_VERSION" ]; then
   [ "$(cd -- "$(dirname -- "$0")" && pwd -P)/$(basename -- "$0")" != "$(cd -- "$(dirname -- "${.sh.file}")" && pwd -P)/$(basename -- "${.sh.file}")" ] && sourced=1
elif [ -n "$BASH_VERSION" ]; then
   (return 0 2>/dev/null) && sourced=1 
else # All other shells: examine $0 for known shell binary filenames.
   # Detects `sh` and `dash`; add additional shell filenames as needed.
   case ${0##*/} in sh|-sh|dash|-dash) sourced=1;; esac
fi
# END BEGIN IS-SOURCED

if ! test "${sourced}" = "1" ;
then
    main
fi

Comments