Archived
add upgrade command; reinstall keeps the same version
- terractl upgrade <name> lists the zips an instance can use; with a zip or 'latest' it checks the zip, stops the server, backs up worlds and configs to instances/.backups/, pins ZIP=, unpacks right away and starts the server again. Downgrades need --downgrade. - reinstall pins the installed zip when ZIP= is blank, so it never changes version, and keeps server/.installed (uses a .reinstall flag). - Resolve terractl's own path before cd /, so a relative $0 works. - Docs, completion and the daemon's command list; version 0.0.12. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ef63609db9
commit
96f7876729
7 files changed
+325
-31
No files matched your search
@@ -4,16 +4,36 @@
|
||||
# Installed to <prefix>/share/bash-completion/completions/terractl, where the
|
||||
# bash-completion package loads it automatically. Also works with 'sudo terractl'.
|
||||
|
||||
# Instances directory: default, or TERRARIA_BASE from /etc/default/terractl.
|
||||
# A setting from /etc/default/terractl, or its default: _terractl_setting <name> <default>.
|
||||
# The file is parsed rather than sourced, so nothing runs in your shell.
|
||||
_terractl_base() {
|
||||
local base=/var/lib/terraria/instances value
|
||||
_terractl_setting() {
|
||||
local result=$2 value
|
||||
if [[ -r /etc/default/terractl ]]; then
|
||||
value=$(sed -n 's/^[[:space:]]*TERRARIA_BASE=//p' /etc/default/terractl | tail -n 1)
|
||||
value=$(sed -n "s/^[[:space:]]*$1=//p" /etc/default/terractl | tail -n 1)
|
||||
value=${value%\"}; value=${value#\"}; value=${value%\'}; value=${value#\'}
|
||||
if [[ -n $value ]]; then base=$value; fi
|
||||
if [[ -n $value ]]; then result=$value; fi
|
||||
fi
|
||||
printf '%s\n' "$base"
|
||||
printf '%s\n' "$result"
|
||||
}
|
||||
|
||||
# Instances directory
|
||||
_terractl_base() { _terractl_setting TERRARIA_BASE /var/lib/terraria/instances; }
|
||||
|
||||
# Server zips an instance can use, by its TYPE in instance.conf (all zips if
|
||||
# that can't be read). On a remote, all of its zips, from its daemon.
|
||||
_terractl_zips() {
|
||||
if [[ -n $2 ]]; then
|
||||
timeout 5 terractl --host "$2" info 2>/dev/null </dev/null | sed -n 's/^dist_zip=//p'
|
||||
return
|
||||
fi
|
||||
local dist type pattern='*.zip' f
|
||||
dist=$(_terractl_setting TERRARIA_DIST /var/lib/terraria/dist)
|
||||
type=$(sed -n 's/^TYPE=\([a-z]*\).*/\1/p' "$(_terractl_base)/$1/instance.conf" 2>/dev/null | tail -n 1)
|
||||
case $type in
|
||||
vanilla) pattern='terraria-server-*.zip' ;;
|
||||
tmodloader) pattern='tModLoader*.zip' ;;
|
||||
esac
|
||||
while IFS= read -r f; do printf '%s\n' "${f##*/}"; done < <(compgen -G "$dist/$pattern")
|
||||
}
|
||||
|
||||
# Instance names. Reading the directory needs root or the 'terraria' group; if
|
||||
@@ -105,7 +125,7 @@ _terractl() {
|
||||
cword=$COMP_CWORD
|
||||
fi
|
||||
|
||||
local commands="new list info start stop restart enable disable attach watch cmd mods reinstall fix-perms delete rename export import"
|
||||
local commands="new list info start stop restart enable disable attach watch cmd mods upgrade reinstall fix-perms delete rename export import"
|
||||
local console="save say playing kick ban motd password time dawn noon dusk midnight settle seed version maxplayers port clear help"
|
||||
|
||||
# terractl --host <remote> <command> ...: the same as on this host, except
|
||||
@@ -173,6 +193,12 @@ _terractl() {
|
||||
if (( cword == 3 )); then _terractl_reply "$console"; fi ;;
|
||||
reinstall)
|
||||
if (( cword == 3 )); then _terractl_reply "--clean"; fi ;;
|
||||
upgrade)
|
||||
if [[ $cur == -* ]]; then
|
||||
_terractl_reply "--downgrade --no-backup"
|
||||
else
|
||||
_terractl_reply "latest $(_terractl_zips "$instance" "$host")"
|
||||
fi ;;
|
||||
enable|disable)
|
||||
if (( cword == 3 )); then _terractl_reply "--now"; fi ;;
|
||||
watch)
|
||||
|
||||
Reference in new issue
Block a user