Frostbite
Frostbite

Reputation: 11

Terminal Not Reciving Input When makepkg is called and asks for sudo (using bubble tea and golang)

Title really says it all, I was using bubble tea in go when I disabled bubble to install a package, when the app calls sudo you simply cant give it any input.

I've tried using pty and bufio, and using cmd.Stdin = os.Stdin

Ive also

Heres my install function since if I put all of my code it'll give me a its mostly code:


func Install(url string) tea.Cmd {
    return func() tea.Msg {
        fmt.Println("Exiting to normal terminal to install the package...")

        // Store the current working directory
        originalDir, err := os.Getwd()
        if err != nil {
            fmt.Println("Failed to get current directory:", err)
            promptToContinue()
            return nil
        }

        // Clear the terminal
        clearCmd := exec.Command("clear")
        clearCmd.Stdout = os.Stdout
        clearCmd.Run()

        // Clone the repository
        repoName := getRepoName(url)
        fmt.Println("Cloning repository:", url)
        cmd := exec.Command("git", "clone", url)
        cmd.Stdout = os.Stdout
        cmd.Stderr = os.Stderr
        if err := cmd.Run(); err != nil {
            fmt.Println("Error cloning repository:", err)
            promptToContinue()
            return nil
        }

        // Change to the repository directory
        if err := os.Chdir(repoName); err != nil {
            fmt.Println("Failed to change to repo directory:", err)
            promptToContinue()
            return nil
        }

        // Run the installation
        fmt.Println("Running makepkg to install the package...")
        cmd = exec.Command("sh", "-c", "makepkg -si --noconfirm")
        cmd.Stdout = os.Stdout
        cmd.Stderr = os.Stderr
        cmd.Stdin = os.Stdin
        if err := cmd.Run(); err != nil {
            fmt.Println("Package installation failed:", err)
            promptToContinue()
            return nil
        }

        fmt.Println("Package installed successfully!")

        // Return to the original directory
        if err := os.Chdir(originalDir); err != nil {
            fmt.Println("Failed to return to original directory:", err)
            promptToContinue()
            return nil
        }

        // Clean up the cloned repository
        fmt.Println("Cleaning up the repository...")
        rmDir := exec.Command("rm", "-rf", repoName)
        if err := rmDir.Run(); err != nil {
            fmt.Println("Failed to remove the installer directory:", err)
            promptToContinue()
            return nil
        }

        // Wait before returning to Bubble Tea
        fmt.Println("Installation complete! Press Enter to return to the menu...")
        promptToContinue()

        return nil
    }
}

Upvotes: 0

Views: 35

Answers (0)

Related Questions