fix permissions subcommand

This commit is contained in:
abrown38 committed 2026-10-02 21:21:59 +00:00
1 parent c4a12727d4
commit ef63609db9
5 files changed
+34 -4

No files matched your search

+25
View File
@@ -79,6 +79,8 @@ Admin commands:
cmd <name> <console command...> send a console command (e.g. save, say hi)
reinstall <name> [--clean] re-unpack server on next start
(--clean also re-downloads tModLoader's .NET)
fix-perms <name> give all of an instance's files back to the
'$SVC_USER' user, with the usual modes (run as root)
mods <name> [list] show installed mods and whether they're enabled
mods <name> add <file.tmod|folder>... install mods (and ModConfigs) and enable them
mods <name> enable|disable <mod>... change which installed mods load
@@ -1119,6 +1121,28 @@ cmd_reinstall() {
echo "server/ will be re-unpacked on next start: $(hint group restart "$name")"
}
# Gives every file of an instance back to the service user, with the modes the
# service creates files with (UMask=0027): the terraria group can read but not
# change them, others get nothing. For files copied in as root, or with odd
# modes (e.g. 'cp -a' or 'scp -p'). Symlinks are left alone, never followed.
cmd_fix_perms() {
local name=$1 dir; shift
[[ $# -eq 0 ]] || die "usage: terractl fix-perms <name>"
[[ $EUID -eq 0 ]] || die "fix-perms must be run as root: sudo terractl fix-perms $name"
dir=$(inst_dir "$name")
[[ -f $dir/instance.conf && ! -L $dir ]] || die "no instance '$name'"
chown -R -h "$SVC_USER:$SVC_USER" "$dir"
# X: directories, and files that were already executable for someone
chmod -R u+rwX,u-s,g=rX,o= "$dir"
# The server binaries must stay executable, whatever happened to them
if [[ -d $dir/server ]]; then
find "$dir/server" -maxdepth 1 -type f \
\( -name TerrariaServer.bin.x86_64 -o -name TerrariaServer -o -name '*.sh' \) \
-exec chmod u+x,g+x {} +
fi
echo "'$name': all files owned by $SVC_USER:$SVC_USER, readable by the '$SVC_USER' group, private to everyone else"
}
# key=value facts, one per line, for people and for terractl-remote (copy, move,
# tab completion). Without a name: this host. Repeated keys are lists.
cmd_info() {
@@ -1218,6 +1242,7 @@ case $command in
mods) cmd_mods "$@" ;;
new) cmd_new "$@" ;;
reinstall) cmd_reinstall "$@" ;;
fix-perms) cmd_fix_perms "$@" ;;
delete) cmd_delete "$@" ;;
rename) cmd_rename "$@" ;;
export) cmd_export "$@" ;;