#!/usr/bin/env bash # Updates Spellcast3D on Linux: downloads the newest version with git, then reinstalls only the parts that changed. # It never deletes your projects or downloaded models. TOOLS="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" . "$TOOLS/environment.sh" || exit 1 # All in one function: bash has then read this file whole before the update replaces it. update() { # Files that are in use cannot be replaced, and a running installer must finish first. "$PY" "$ROOT/code/install.py" --busy-check if [ $? -ge 3 ]; then echo echo "Spellcast3D is still open, or it is being installed in another terminal." echo "Close it first (that stops Spellcast3D and its tools), then run update.sh again. Nothing was changed." return 1 fi local triflow_failed="" skip_triflow=() code if [ ! -e "$ROOT/.git" ]; then echo "This copy of Spellcast3D was not downloaded with git, so it cannot update itself." echo "To update it, clone the newest version into a new folder and move your \"projects\" folder into it." echo "To avoid downloading the AI models again, also move the \"models\" folder over. If you changed" echo "spellcast3d-config.ini, copy it over too." echo echo "Checking the installed parts of this copy anyway..." else echo "Downloading the newest version of Spellcast3D..." # Only the newest commit (--depth 1), without the tools (they follow below, also --depth 1). git -C "$ROOT" update-index -q --refresh if ! git -C "$ROOT" fetch --depth 1 --no-recurse-submodules origin; then echo echo "ERROR: The update could not be downloaded, and nothing was changed." echo "Check your internet connection and try again. Your projects folder is never affected." return 1 fi # reset --keep moves to what was just downloaded, even when the published history was rewritten, and it # still refuses to overwrite a file edited here. It needs a branch that follows the download's. if ! git -C "$ROOT" rev-parse --quiet --verify '@{u}' > /dev/null 2>&1; then echo echo "ERROR: The update was downloaded, but this Spellcast3D folder is not on a branch that follows it" echo "(git status says where it is), so nothing was changed. Switch back to the branch it was cloned" echo "with - for example: git -C \"$ROOT\" switch main - and run update.sh again." return 1 fi if ! git -C "$ROOT" reset --keep '@{u}'; then echo echo "ERROR: The update was downloaded, but a file it changes was edited in this Spellcast3D folder" echo "(git names it above), so nothing was changed. Undo that edit - or move the file away - and run" echo "update.sh again. Your projects folder is never affected." return 1 fi # Remember each tool's installed commit as a ref: git offers only refs to the server as "what I have", and # the pinned commit otherwise sits on a detached HEAD, so a tool's next update would download much more. # TriFlow first: its licence asks that its files stay exactly as committed (core.autocrlf=false); its own # nested parts are checked out by install.py below, and a failure there stops only TriFlow. # Never --recursive: the tools' own nested submodules are not needed and some break builds. if ! git -C "$ROOT" submodule sync; then code=1 else git -C "$ROOT" submodule foreach --quiet "git update-ref refs/spellcast/installed HEAD" git -c core.autocrlf=false -C "$ROOT" submodule update --init --depth 1 -- code/triflow || triflow_failed=1 [ -e "$ROOT/code/triflow/.git" ] && git -C "$ROOT/code/triflow" config core.autocrlf false [ -n "$triflow_failed" ] && skip_triflow=(-c submodule.triflow.update=none) git "${skip_triflow[@]}" -C "$ROOT" submodule update --init --depth 1 code=$? fi if [ "$code" -ne 0 ]; then echo echo "ERROR: Spellcast3D was updated, but updating the tools in its code folder failed." echo "Check your internet connection and run update.sh again." return 1 fi fi "$PY" "$ROOT/code/install.py" code=$? if [ -n "$triflow_failed" ]; then echo echo "NOTE: TriFlow (one of the AI retopology tools) could not be updated; the other tools were." echo "Check your internet connection and run update.sh again to update TriFlow too." fi if [ "$code" -ge 3 ]; then # another Spellcast3D or installer is at work: install.py said so return 1 elif [ "$code" -ne 0 ]; then echo echo "Some parts could not be installed - the messages above say why. The full log is in:" echo " $ROOT/code/logs/install.log" echo "Starting Spellcast3D retries them." return 1 fi echo echo "Spellcast3D is up to date. Start it with run-browser/run-spellcast3d.sh" } update exit $?