Bladeren bron

Only upgrade when there's something to upgrade.

Steve Thielemann 1 dag geleden
bovenliggende
commit
0adf1e73ea
1 gewijzigde bestanden met toevoegingen van 12 en 5 verwijderingen
  1. 12 5
      aptgrade.go

+ 12 - 5
aptgrade.go

@@ -26,7 +26,8 @@ NOTES:
 
 type CheckResult struct {
 	Lines      int  // Number of lines read.
-	UpToDate   bool // All packages are up to date.
+	Upgradable bool // 'apt list --upgradable'
+	// UpToDate   bool // All packages are up to date.
 	AutoRemove bool // Use 'apt autoremove' to remove it.
 }
 
@@ -40,11 +41,17 @@ func check_lines(r io.Reader, output chan CheckResult) {
 	for scanner.Scan() {
 		line = scanner.Text()
 
-		if line == "All packages are up to date." {
-			result.UpToDate = true
+		/*
+			if line == "All packages are up to date." {
+				result.UpToDate = true
+			}
+		*/
+
+		if strings.Contains(line, "apt list --upgradable") {
+			result.Upgradable = true
 		}
 
-		if line == "Use 'apt autoremove' to remove it." {
+		if line == "Use 'apt autoremove' to remove it." || line == "Use 'sudo apt autoremove' to remove it" {
 			result.AutoRemove = true
 		}
 
@@ -162,7 +169,7 @@ func main() {
 	}
 
 	// Is everything up to date?
-	if !result.UpToDate {
+	if result.Upgradable {
 		// Perform upgrade.
 		result, err = run_check_command([]string{APT, "upgrade", "-y"}, output)
 		if err != nil {