|
|
|
@ -2,7 +2,6 @@ package pacman |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"io" |
|
|
|
|
|
|
|
"os" |
|
|
|
"os" |
|
|
|
"os/exec" |
|
|
|
"os/exec" |
|
|
|
"regexp" |
|
|
|
"regexp" |
|
|
|
@ -11,7 +10,6 @@ import ( |
|
|
|
|
|
|
|
|
|
|
|
"github.com/Riyyi/declpac/pkg/fetch" |
|
|
|
"github.com/Riyyi/declpac/pkg/fetch" |
|
|
|
"github.com/Riyyi/declpac/pkg/output" |
|
|
|
"github.com/Riyyi/declpac/pkg/output" |
|
|
|
"github.com/Riyyi/declpac/pkg/state" |
|
|
|
|
|
|
|
"github.com/Riyyi/declpac/pkg/validation" |
|
|
|
"github.com/Riyyi/declpac/pkg/validation" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
@ -20,13 +18,9 @@ func MarkAllAsDeps() error { |
|
|
|
fmt.Fprintf(os.Stderr, "[debug] MarkAllAsDeps: starting...\n") |
|
|
|
fmt.Fprintf(os.Stderr, "[debug] MarkAllAsDeps: starting...\n") |
|
|
|
|
|
|
|
|
|
|
|
cmd := exec.Command("pacman", "-D", "--asdeps") |
|
|
|
cmd := exec.Command("pacman", "-D", "--asdeps") |
|
|
|
state.Write([]byte("MarkAllAsDeps...\n")) |
|
|
|
cmd.Stdout = os.Stdout |
|
|
|
cmd.Stdout = io.MultiWriter(os.Stdout, state.GetLogWriter()) |
|
|
|
cmd.Stderr = os.Stderr |
|
|
|
cmd.Stderr = io.MultiWriter(os.Stderr, state.GetLogWriter()) |
|
|
|
|
|
|
|
err := cmd.Run() |
|
|
|
err := cmd.Run() |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
state.Write([]byte(fmt.Sprintf("error: %v\n", err))) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fmt.Fprintf(os.Stderr, "[debug] MarkAllAsDeps: done (%.2fs)\n", time.Since(start).Seconds()) |
|
|
|
fmt.Fprintf(os.Stderr, "[debug] MarkAllAsDeps: done (%.2fs)\n", time.Since(start).Seconds()) |
|
|
|
return err |
|
|
|
return err |
|
|
|
@ -41,13 +35,9 @@ func MarkAsExplicit(packages []string) error { |
|
|
|
|
|
|
|
|
|
|
|
args := append([]string{"-D", "--asexplicit"}, packages...) |
|
|
|
args := append([]string{"-D", "--asexplicit"}, packages...) |
|
|
|
cmd := exec.Command("pacman", args...) |
|
|
|
cmd := exec.Command("pacman", args...) |
|
|
|
state.Write([]byte("MarkAsExplicit...\n")) |
|
|
|
cmd.Stdout = os.Stdout |
|
|
|
cmd.Stdout = io.MultiWriter(os.Stdout, state.GetLogWriter()) |
|
|
|
cmd.Stderr = os.Stderr |
|
|
|
cmd.Stderr = io.MultiWriter(os.Stderr, state.GetLogWriter()) |
|
|
|
|
|
|
|
err := cmd.Run() |
|
|
|
err := cmd.Run() |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
state.Write([]byte(fmt.Sprintf("error: %v\n", err))) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fmt.Fprintf(os.Stderr, "[debug] MarkAsExplicit: done (%.2fs)\n", time.Since(start).Seconds()) |
|
|
|
fmt.Fprintf(os.Stderr, "[debug] MarkAsExplicit: done (%.2fs)\n", time.Since(start).Seconds()) |
|
|
|
return err |
|
|
|
return err |
|
|
|
@ -167,25 +157,19 @@ func InstallAUR(f *fetch.Fetcher, pkgName string) error { |
|
|
|
defer os.RemoveAll(tmpDir) |
|
|
|
defer os.RemoveAll(tmpDir) |
|
|
|
|
|
|
|
|
|
|
|
cloneURL := "https://aur.archlinux.org/" + aurInfo.PackageBase + ".git" |
|
|
|
cloneURL := "https://aur.archlinux.org/" + aurInfo.PackageBase + ".git" |
|
|
|
state.Write([]byte("Cloning " + cloneURL + "\n")) |
|
|
|
|
|
|
|
cloneCmd := exec.Command("git", "clone", cloneURL, tmpDir) |
|
|
|
cloneCmd := exec.Command("git", "clone", cloneURL, tmpDir) |
|
|
|
cloneCmd.Stdout = io.MultiWriter(os.Stdout, state.GetLogWriter()) |
|
|
|
cloneCmd.Stdout = os.Stdout |
|
|
|
cloneCmd.Stderr = io.MultiWriter(os.Stderr, state.GetLogWriter()) |
|
|
|
cloneCmd.Stderr = os.Stderr |
|
|
|
if err := cloneCmd.Run(); err != nil { |
|
|
|
if err := cloneCmd.Run(); err != nil { |
|
|
|
errMsg := fmt.Sprintf("failed to clone AUR repo: %w\n", err) |
|
|
|
|
|
|
|
state.Write([]byte("error: " + errMsg)) |
|
|
|
|
|
|
|
return fmt.Errorf("failed to clone AUR repo: %w", err) |
|
|
|
return fmt.Errorf("failed to clone AUR repo: %w", err) |
|
|
|
} |
|
|
|
} |
|
|
|
fmt.Fprintf(os.Stderr, "[debug] InstallAUR: cloned (%.2fs)\n", time.Since(start).Seconds()) |
|
|
|
fmt.Fprintf(os.Stderr, "[debug] InstallAUR: cloned (%.2fs)\n", time.Since(start).Seconds()) |
|
|
|
|
|
|
|
|
|
|
|
state.Write([]byte("Building package...\n")) |
|
|
|
|
|
|
|
makepkgCmd := exec.Command("makepkg", "-si", "--noconfirm") |
|
|
|
makepkgCmd := exec.Command("makepkg", "-si", "--noconfirm") |
|
|
|
makepkgCmd.Stdout = io.MultiWriter(os.Stdout, state.GetLogWriter()) |
|
|
|
makepkgCmd.Stdout = os.Stdout |
|
|
|
makepkgCmd.Stderr = io.MultiWriter(os.Stderr, state.GetLogWriter()) |
|
|
|
makepkgCmd.Stderr = os.Stderr |
|
|
|
makepkgCmd.Dir = tmpDir |
|
|
|
makepkgCmd.Dir = tmpDir |
|
|
|
if err := makepkgCmd.Run(); err != nil { |
|
|
|
if err := makepkgCmd.Run(); err != nil { |
|
|
|
errMsg := fmt.Sprintf("makepkg failed to build AUR package: %w\n", err) |
|
|
|
|
|
|
|
state.Write([]byte("error: " + errMsg)) |
|
|
|
|
|
|
|
return fmt.Errorf("makepkg failed to build AUR package: %w", err) |
|
|
|
return fmt.Errorf("makepkg failed to build AUR package: %w", err) |
|
|
|
} |
|
|
|
} |
|
|
|
fmt.Fprintf(os.Stderr, "[debug] InstallAUR: built (%.2fs)\n", time.Since(start).Seconds()) |
|
|
|
fmt.Fprintf(os.Stderr, "[debug] InstallAUR: built (%.2fs)\n", time.Since(start).Seconds()) |
|
|
|
@ -216,19 +200,13 @@ func SyncPackages(packages []string) (int, error) { |
|
|
|
start := time.Now() |
|
|
|
start := time.Now() |
|
|
|
fmt.Fprintf(os.Stderr, "[debug] SyncPackages: starting...\n") |
|
|
|
fmt.Fprintf(os.Stderr, "[debug] SyncPackages: starting...\n") |
|
|
|
|
|
|
|
|
|
|
|
args := append([]string{"-S", "--needed"}, packages...) |
|
|
|
args := append([]string{"-Syu"}, packages...) |
|
|
|
cmd := exec.Command("pacman", args...) |
|
|
|
cmd := exec.Command("pacman", args...) |
|
|
|
output, err := cmd.CombinedOutput() |
|
|
|
output, err := cmd.CombinedOutput() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
errMsg := fmt.Sprintf("pacman sync failed: %s", output) |
|
|
|
|
|
|
|
state.Write([]byte(errMsg)) |
|
|
|
|
|
|
|
return 0, fmt.Errorf("pacman sync failed: %s", output) |
|
|
|
return 0, fmt.Errorf("pacman sync failed: %s", output) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if len(output) > 0 { |
|
|
|
|
|
|
|
state.Write(output) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
re := regexp.MustCompile(`upgrading (\S+)`) |
|
|
|
re := regexp.MustCompile(`upgrading (\S+)`) |
|
|
|
matches := re.FindAllStringSubmatch(string(output), -1) |
|
|
|
matches := re.FindAllStringSubmatch(string(output), -1) |
|
|
|
|
|
|
|
|
|
|
|
@ -255,15 +233,9 @@ func CleanupOrphans() (int, error) { |
|
|
|
removeCmd := exec.Command("pacman", "-Rns") |
|
|
|
removeCmd := exec.Command("pacman", "-Rns") |
|
|
|
output, err := removeCmd.CombinedOutput() |
|
|
|
output, err := removeCmd.CombinedOutput() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
errMsg := fmt.Sprintf("%s: %s", err, output) |
|
|
|
|
|
|
|
state.Write([]byte(errMsg)) |
|
|
|
|
|
|
|
return 0, fmt.Errorf("%s: %s", err, output) |
|
|
|
return 0, fmt.Errorf("%s: %s", err, output) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if len(output) > 0 { |
|
|
|
|
|
|
|
state.Write(output) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
count := len(orphans) |
|
|
|
count := len(orphans) |
|
|
|
|
|
|
|
|
|
|
|
fmt.Fprintf(os.Stderr, "[debug] CleanupOrphans: done (%.2fs)\n", time.Since(start).Seconds()) |
|
|
|
fmt.Fprintf(os.Stderr, "[debug] CleanupOrphans: done (%.2fs)\n", time.Since(start).Seconds()) |
|
|
|
@ -299,10 +271,12 @@ func DryRun(packages []string) (*output.Result, error) { |
|
|
|
if info == nil || !info.Exists { |
|
|
|
if info == nil || !info.Exists { |
|
|
|
return nil, fmt.Errorf("package not found: %s", pkg) |
|
|
|
return nil, fmt.Errorf("package not found: %s", pkg) |
|
|
|
} |
|
|
|
} |
|
|
|
if info.InAUR { |
|
|
|
if _, installed := localPkgs[pkg]; !installed { |
|
|
|
aurPkgs = append(aurPkgs, pkg) |
|
|
|
if info.InAUR { |
|
|
|
} else if _, installed := localPkgs[pkg]; !installed { |
|
|
|
aurPkgs = append(aurPkgs, pkg) |
|
|
|
toInstall = append(toInstall, pkg) |
|
|
|
} else { |
|
|
|
|
|
|
|
toInstall = append(toInstall, pkg) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
fmt.Fprintf(os.Stderr, "[debug] DryRun: packages categorized (%.2fs)\n", time.Since(start).Seconds()) |
|
|
|
fmt.Fprintf(os.Stderr, "[debug] DryRun: packages categorized (%.2fs)\n", time.Since(start).Seconds()) |
|
|
|
|