(was []byte, dstTrack string)
| 519 | } |
| 520 | |
| 521 | func updateDebianAptSourcesListBytes(was []byte, dstTrack string) (newContent []byte, err error) { |
| 522 | trackURLPrefix := []byte("https://pkgs.tailscale.com/" + dstTrack + "/") |
| 523 | var buf bytes.Buffer |
| 524 | var changes int |
| 525 | bs := bufio.NewScanner(bytes.NewReader(was)) |
| 526 | hadCorrect := false |
| 527 | commentLine := regexp.MustCompile(`^\s*\#`) |
| 528 | pkgsURL := regexp.MustCompile(`\bhttps://pkgs\.tailscale\.com/(stable|unstable|release-candidate)/`) |
| 529 | for bs.Scan() { |
| 530 | line := bs.Bytes() |
| 531 | if !commentLine.Match(line) { |
| 532 | line = pkgsURL.ReplaceAllFunc(line, func(m []byte) []byte { |
| 533 | if bytes.Equal(m, trackURLPrefix) { |
| 534 | hadCorrect = true |
| 535 | } else { |
| 536 | changes++ |
| 537 | } |
| 538 | return trackURLPrefix |
| 539 | }) |
| 540 | } |
| 541 | buf.Write(line) |
| 542 | buf.WriteByte('\n') |
| 543 | } |
| 544 | if hadCorrect || (changes == 1 && bytes.Equal(bytes.TrimSpace(was), bytes.TrimSpace(buf.Bytes()))) { |
| 545 | // Unchanged or close enough. |
| 546 | return was, nil |
| 547 | } |
| 548 | if changes != 1 { |
| 549 | // No changes, or an unexpected number of changes (what?). Bail. |
| 550 | // They probably editted it by hand and we don't know what to do. |
| 551 | return nil, fmt.Errorf("unexpected/unsupported %s contents", aptSourcesFile) |
| 552 | } |
| 553 | return buf.Bytes(), nil |
| 554 | } |
| 555 | |
| 556 | func (up *Updater) archPackageInstalled() bool { |
| 557 | err := exec.Command("pacman", "--query", "tailscale").Run() |
searching dependent graphs…