Skip to content

Extract duplicated package-manager/sudo/permission logic into common-utils #70

Description

@tomgrv

Problem

Package-manager detection (apt-get/apk/dnf/yum/brew/pacman/zypper), sudo-escalation checks, and mkdir+chmod permission patterns are duplicated across multiple install scripts rather than living in one shared place, e.g.:

  • src/gitutils/install-gitflow.sh branches across 6+ package managers.
  • src/common-utils/install.sh has its own separate apt-get/apk/winget branching.
  • Numerous scripts repeat if [ "$(id -u)" -eq 0 ] / command -v sudo checks before privileged operations.
  • mkdir -p ... && chmod ... permission-fixing patterns recur in _configure-feature.sh and feature-specific setup scripts.

This duplication is a likely contributor to recurring permission-related fixes in git history, e.g. 5818e42 fix(githooks): use sudo for chmod to ensure proper permissions.

Proposal

Add shared helpers to src/common-utils (alongside the existing _zz_*.sh library):

  • _zz_pkg-manager.sh — a single install_package <name> function that detects and dispatches to the right package manager.
  • A run_with_sudo wrapper that consistently handles the root/sudo/no-sudo cases in one place.
  • An ensure_dir_perms <dir> [<mode>] helper for the recurring mkdir -p && chmod pattern.

Then migrate gitutils, githooks, and other features' install scripts to call these instead of reimplementing the logic.

Where this lives / sync note

These helpers belong in src/common-utils since it's the shared foundation every other feature already depends on via dependsOn. Because common-utils is redistributed to its own standalone repo via split-monorepo.yml/merge-monorepo.yml, adding helpers here automatically makes them available to every consumer once synced — this must not be done as a one-off copy-paste into individual features. Also verify this repo's own dev environment (which dogfoods common-utils for its own tooling) keeps working against the refactored helpers.

Acceptance criteria

  • New shared helpers added to src/common-utils.
  • At least 2 other features (e.g. gitutils, githooks) migrated to use them instead of inline duplicated logic.
  • No regression in the repo's own dogfooded usage of common-utils.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions