Skip to content

Fix ubuntu#205

Merged
Benzbeeb merged 12 commits intomainfrom
fix-ubuntu
Mar 19, 2026
Merged

Fix ubuntu#205
Benzbeeb merged 12 commits intomainfrom
fix-ubuntu

Conversation

@Benzbeeb
Copy link
Copy Markdown
Collaborator

@Benzbeeb Benzbeeb commented Mar 19, 2026

Description

Closes: #XXXX


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow-up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • Refactor

    • Standardized binary path resolution across macOS and Linux and simplified flows so executable permissions are applied consistently on all paths.
    • Extraction and upgrade flows now use a temporary private directory and defer cleanup.
  • New Features

    • Added a binary-discovery helper to locate executables under extracted releases.
    • Launch/service logic uses discovery for locating binaries when needed.
  • New Behavior

    • Systemd setup checks lingering first and attempts enablement with a sudo fallback and clear next-step instructions on failure.

- Set the SHELL variable to /bin/bash in the Makefile for improved script compatibility.
- Updated GetMinitiadBinaryPath to include OS and architecture in the binary path for Linux, improving compatibility.
- Refactored NewMinitiadQuerier and downloadMinitiaApp to utilize the updated binary path resolution, ensuring correct binary retrieval based on the environment.
- Consolidated the binary path resolution logic in GetMinitiadBinaryPath to handle both Darwin and Linux operating systems uniformly, enhancing code clarity and maintainability.
- Updated the permission setting for binaries in InstallMinitiadBinary and NewMinitiadQuerier to use a more concise error handling approach.
- Cleaned up whitespace in RecoverKeyFromMnemonicWithCoinType for improved readability.
- Ensured consistent permission setting logic across multiple files, enhancing code clarity and maintainability.
- Eliminated the SHELL variable assignment in the Makefile as it is no longer needed, streamlining the build configuration.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 19, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Centralized minitiad binary resolution, added FindBinaryDir to locate executables, and unified permission setting to run unconditionally. Callers updated to use the helper. Added Systemd helpers to detect/enable lingering with a sudo fallback and adjusted service launch/upgrade paths. Minor formatting tweak in key recovery code.

Changes

Cohort / File(s) Summary
Binary utils
cosmosutils/binary.go
Added FindBinaryDir(versionDir, binaryName) to walk and locate executables; consolidated GetMinitiadBinaryPath() so darwin and linux return .../minitiad; moved os.Chmod(..., 0755) to run unconditionally after download/extract.
CLI querier
cosmosutils/cli_query.go
NewMinitiadQuerier now calls GetMinitiadBinaryPath(...) and fails early on error; permission setting moved to post-extract/unconditional location.
Model launch
models/minitia/launch.go
Replaced runtime.GOOS branching with cosmosutils.GetMinitiadBinaryPath(...) and wrapped errors; unified chmod call after download/extract branch.
Upgrade command
cmd/upgrade.go
downloadAndReplaceBinary extracts into a private temp dir and uses cosmosutils.FindBinaryDir(tempDir, "weave") to find the extracted weave binary directory; defers cleanup of temp dir.
launchd service
service/launchd.go
For Minitia, resolve binary via cosmosutils.FindBinaryDir(versionDir, binaryName) and return an error if not found; other commands unchanged.
Systemd lingering & service flow
service/systemd.go
Added non-exported isLingeringEnabled() and enableLingering(); enableLingering() tries loginctl enable-linger then sudo fallback and surfaces helpful error output; ensureUserServicePrerequisites() skips enabling when already enabled. Adjusted Create() path mapping to include Minitia in the standard binaryPath case.
Minor formatting
cosmosutils/keys.go
Whitespace/newline adjustments in RecoverKeyFromMnemonicWithCoinType() only; no behavioral changes.

Sequence Diagram(s)

sequenceDiagram
  participant Launcher as Launcher
  participant Systemd as Systemd helper
  participant OS as OS (file system)
  participant Loginctl as loginctl / sudo

  Launcher->>Systemd: ensureUserServicePrerequisites()
  Systemd->>OS: isLingeringEnabled() (check /var/lib/systemd/linger/<user>)
  alt lingering enabled
    Systemd-->>Launcher: skip enablement
  else lingering not enabled
    Systemd->>Loginctl: run "loginctl enable-linger <user>"
    alt success
      Loginctl-->>Systemd: success
      Systemd-->>Launcher: enabled
    else failure
      Systemd->>Loginctl: run "sudo loginctl enable-linger <user>"
      alt sudo success
        Loginctl-->>Systemd: success (sudo)
        Systemd-->>Launcher: enabled
      else sudo failure
        Loginctl-->>Systemd: error output
        Systemd-->>Launcher: return formatted error with sudo output
      end
    end
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Poem

🐰 I dug through folders, sniffed each bin so fine,

I hopped to set permissions, made the runtimes shine,
I nudged systemd gently, tried loginctl and sudo,
If lingering slept, I gave it a tiny nudge,
A twitch of whiskers — binaries found and snug.

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Fix ubuntu' is vague and generic, using non-descriptive terms that don't convey meaningful information about the changeset. Provide a more descriptive title that captures the primary change, such as 'Refactor binary extraction process to use temporary directories' or 'Fix OS-specific binary path handling and add lingering enablement'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-ubuntu
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

- Introduced a new method to check if systemd lingering is enabled for the user by inspecting the linger state file directly, avoiding potential permission issues with loginctl.
- Updated the ensureUserServicePrerequisites method to utilize the new check, improving error handling and user guidance when enabling lingering.
- Added a new method to enable systemd lingering for the current user, attempting both loginctl and sudo for improved compatibility on cloud VMs.
- Updated ensureUserServicePrerequisites to utilize the new enableLingering method, enhancing error handling and user guidance.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
cosmosutils/cli_query.go (1)

76-104: Reuse InstallMinitiadBinary here instead of carrying another copy of the installer flow.

This block is still a second copy of the download/extract/chmod sequence from cosmosutils.InstallMinitiadBinary, and the same manual sequence exists again in models/minitia/launch.go:2165-2199. Keeping NewMinitiadQuerier on the helper avoids having to replicate the next archive-layout fix in multiple places.

Proposed simplification
-	userHome, err := os.UserHomeDir()
-	if err != nil {
-		return nil, fmt.Errorf("failed to get user home dir: %v", err)
-	}
 	binaryPath, err := GetMinitiadBinaryPath(DefaultMinitiadQuerierVM, version)
 	if err != nil {
 		return nil, fmt.Errorf("failed to get binary path: %v", err)
 	}
 
-	weaveDataPath := filepath.Join(userHome, common.WeaveDataDirectory)
-	tarballPath := filepath.Join(weaveDataPath, "minitia.tar.gz")
-	extractedPath := filepath.Join(weaveDataPath, fmt.Sprintf("mini%s@%s", DefaultMinitiadQuerierVM, version))
-
-	if _, err := os.Stat(binaryPath); os.IsNotExist(err) {
-		if _, err := os.Stat(extractedPath); os.IsNotExist(err) {
-			err := os.MkdirAll(extractedPath, os.ModePerm)
-			if err != nil {
-				return nil, fmt.Errorf("failed to create weave data directory: %v", err)
-			}
-		}
-
-		if err = io.DownloadAndExtractTarGz(downloadURL, tarballPath, extractedPath); err != nil {
-			return nil, fmt.Errorf("failed to download minitia binary: %v", err)
-		}
-	}
-
-	if err := os.Chmod(binaryPath, 0755); err != nil {
-		return nil, fmt.Errorf("failed to set permissions for binary: %v", err)
+	if err := InstallMinitiadBinary(DefaultMinitiadQuerierVM, version, downloadURL, binaryPath); err != nil {
+		return nil, fmt.Errorf("failed to install minitiad binary: %v", err)
 	}

Then remove the now-unused imports in this file.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cosmosutils/cli_query.go` around lines 76 - 104, The NewMinitiadQuerier
factory duplicates the download/extract/chmod flow already implemented in
InstallMinitiadBinary; replace the manual sequence (calls around
GetMinitiadBinaryPath, os.Stat, io.DownloadAndExtractTarGz, os.MkdirAll and
os.Chmod) by invoking InstallMinitiadBinary(DefaultMinitiadQuerierVM, version,
downloadURL) (or the appropriate InstallMinitiadBinary signature) and then
continue using GetMinitiadBinaryPath as before; after switching to
InstallMinitiadBinary, remove the now-unused imports introduced for the manual
flow and any local helper variables that become redundant (e.g., tarballPath,
extractedPath, weaveDataPath).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@cosmosutils/cli_query.go`:
- Around line 76-104: The NewMinitiadQuerier factory duplicates the
download/extract/chmod flow already implemented in InstallMinitiadBinary;
replace the manual sequence (calls around GetMinitiadBinaryPath, os.Stat,
io.DownloadAndExtractTarGz, os.MkdirAll and os.Chmod) by invoking
InstallMinitiadBinary(DefaultMinitiadQuerierVM, version, downloadURL) (or the
appropriate InstallMinitiadBinary signature) and then continue using
GetMinitiadBinaryPath as before; after switching to InstallMinitiadBinary,
remove the now-unused imports introduced for the manual flow and any local
helper variables that become redundant (e.g., tarballPath, extractedPath,
weaveDataPath).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 69c5f4e6-7ec6-46bf-a232-1e5f23e620b2

📥 Commits

Reviewing files that changed from the base of the PR and between e4add5c and 103d047.

📒 Files selected for processing (4)
  • cosmosutils/binary.go
  • cosmosutils/cli_query.go
  • cosmosutils/keys.go
  • models/minitia/launch.go

coderabbitai[bot]
coderabbitai Bot previously approved these changes Mar 19, 2026
- Modified the binary path resolution logic in the Create method to include Minitia in the switch case, ensuring correct path handling for this command.
- Removed redundant case handling for Minitia, streamlining the code and improving maintainability.
coderabbitai[bot]
coderabbitai Bot previously approved these changes Mar 19, 2026
- Implemented FindBinaryDir function to dynamically locate the binary directory for Minitia, improving flexibility and compatibility with varying tarball structures.
- Updated the Create methods in both systemd and launchd services to utilize the new binary path resolution logic, ensuring accurate binary retrieval for Minitia commands.
- Enhanced error handling for binary location failures, providing clearer feedback on issues during the binary extraction process.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmd/upgrade.go`:
- Around line 124-128: FindBinaryDir(extractedPath, "weave") can match an
existing stale weave under the shared data root and cause deletion of the wrong
file; change the workflow so the release/archive is extracted into a
uniquely-named temporary directory (not the shared data root) before calling
FindBinaryDir, then use the resulting binaryDir/binaryPath from that temp
extraction and perform cleanup on that temp directory only; update any
references to extractedPath passed into FindBinaryDir to point to the temp
extraction dir and ensure deferred removal targets the temp dir containing the
newly extracted assets.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 4db7ea67-917e-4f88-9828-f413e42ca05d

📥 Commits

Reviewing files that changed from the base of the PR and between a0deb10 and 85f5858.

📒 Files selected for processing (4)
  • cmd/upgrade.go
  • cosmosutils/binary.go
  • service/launchd.go
  • service/systemd.go
✅ Files skipped from review due to trivial changes (1)
  • service/systemd.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cosmosutils/binary.go

Comment thread cmd/upgrade.go Outdated
- Changed the binary extraction process to utilize a temporary directory, preventing conflicts with existing binaries in the shared data root.
- Updated the download and extraction logic to reflect the new temporary path, enhancing reliability during upgrades.
- Improved error handling for directory creation and binary location, ensuring clearer feedback on potential issues.
coderabbitai[bot]
coderabbitai Bot previously approved these changes Mar 19, 2026
- Replaced GetMinitiadBinaryPath and InstallMinitiadBinary with a new EnsureMinitiadBinary function to streamline binary retrieval and installation.
- Improved error handling and clarity in the binary extraction process, ensuring the binary is correctly located or downloaded as needed.
- Updated related functions across the codebase to utilize the new binary management approach, enhancing maintainability and reducing redundancy.
Copy link
Copy Markdown
Collaborator

@restorenode restorenode left a comment

Choose a reason for hiding this comment

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

Please add tests for the extracted minitiad binary layouts, and this should be good to go.

- Introduced new test cases for FindBinaryDir to validate binary location logic across various directory structures and conditions.
- Added tests for EnsureMinitiadBinary to ensure correct binary retrieval from nested directories, enhancing coverage and reliability of binary management functions.
- Implemented helper function createExecutable to streamline test setup for executable files.
@Benzbeeb Benzbeeb requested a review from restorenode March 19, 2026 08:37
@Benzbeeb Benzbeeb merged commit 42070f1 into main Mar 19, 2026
8 checks passed
@Benzbeeb Benzbeeb deleted the fix-ubuntu branch March 19, 2026 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants