Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion scripts/install-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,20 @@ if [[ ! -d "$INSTALL_DIR/.git" ]]; then
git clone --depth 1 --branch "$BRANCH" "$REPO" "$INSTALL_DIR"
else
log "updating existing checkout"
(cd "$INSTALL_DIR" && git fetch --depth 1 origin "$BRANCH" && git reset --hard "origin/$BRANCH")
# The repo is chowned to the 'taos' service user at the end of a system
# install, so a re-run (as root) trips git's dubious-ownership check.
# That check is guarding a real privilege-escalation path: running git as
# root inside a tree the unprivileged 'taos' user can write to would let a
# planted .git/config or hook execute as root. So drop to the owning user
# for the update instead of overriding the check. When the tree is already
# root-owned, or we are not root (user-mode / macOS install), run directly.
_repo_owner="$(stat -c '%U' "$INSTALL_DIR" 2>/dev/null || stat -f '%Su' "$INSTALL_DIR" 2>/dev/null || echo "")"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: _repo_owner variable leaks to global scope

The variable _repo_owner is assigned at the top level without local declaration. While this script doesn't use functions for this section, global namespace pollution can cause subtle bugs if this variable name is used elsewhere. Consider using a more unique name (e.g., _taos_repo_owner) or wrapping this logic in a function with local.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: Explicitly handle symlinks with stat -L

The stat command follows symlinks by default, but being explicit with -L (GNU) or relying on default behavior makes the intent clearer. Since $INSTALL_DIR could theoretically be a symlink (though unlikely in this script's flow), consider: stat -L -c '%U' ... for GNU stat. Note: BSD stat doesn't support -L flag the same way, so the current fallback chain handles it.

if [[ "$(id -u)" == "0" && -n "$_repo_owner" && "$_repo_owner" != "root" ]]; then

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: No validation that the owning user exists before sudo -u

If $INSTALL_DIR was manually chowned to a non-existent user (or a user that was deleted), the stat call succeeds but sudo -u "$_repo_owner" will fail with a confusing error like "sudo: unknown user: ...". The script will exit due to set -e, but the error message won't clearly indicate the root cause. Consider adding a check: id -u "$_repo_owner" >/dev/null 2>&1 before attempting the sudo.

sudo -u "$_repo_owner" git -C "$INSTALL_DIR" fetch --depth 1 origin "$BRANCH" \

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: Capture and surface sudo/git errors more clearly

If sudo -u fails (e.g., user doesn't exist, sudo not configured for passwordless), the script exits via set -e but the error message comes from sudo/git directly. Wrapping in a function or adding explicit error handling would improve debuggability. Example: sudo -u "$_repo_owner" git -C "$INSTALL_DIR" fetch ... || die "git fetch as $_repo_owner failed"

&& sudo -u "$_repo_owner" git -C "$INSTALL_DIR" reset --hard "origin/$BRANCH"
else
(cd "$INSTALL_DIR" && git fetch --depth 1 origin "$BRANCH" && git reset --hard "origin/$BRANCH")
fi
fi

cd "$INSTALL_DIR"
Expand Down
Loading