OLD | NEW |
1 // Copyright 2012, 2013 Canonical Ltd. | 1 // Copyright 2012, 2013 Canonical Ltd. |
2 // Licensed under the AGPLv3, see LICENCE file for details. | 2 // Licensed under the AGPLv3, see LICENCE file for details. |
3 | 3 |
4 package utils | 4 package utils |
5 | 5 |
6 import ( | 6 import ( |
7 "bytes" | 7 "bytes" |
8 "fmt" | 8 "fmt" |
9 "os" | 9 "os" |
10 "os/exec" | 10 "os/exec" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 // that is suitable for use with the apt-get --target-release option | 74 // that is suitable for use with the apt-get --target-release option |
75 func targetRelease(series string) string { | 75 func targetRelease(series string) string { |
76 switch series { | 76 switch series { |
77 case "precise": | 77 case "precise": |
78 return "precise-updates/cloud-tools" | 78 return "precise-updates/cloud-tools" |
79 default: | 79 default: |
80 return "" | 80 return "" |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
| 84 // AptGetCommand returns a command to execute apt-get |
| 85 // with the specified arguments, and the appropriate |
| 86 // environment variables and options for a non-interactive |
| 87 // session. |
| 88 func AptGetCommand(args ...string) []string { |
| 89 cmd := append([]string{"env"}, aptGetEnvOptions...) |
| 90 cmd = append(cmd, aptGetCommand...) |
| 91 return append(cmd, args...) |
| 92 } |
| 93 |
84 // AptGetPreparePackages returns a slice of installCommands. Each item | 94 // AptGetPreparePackages returns a slice of installCommands. Each item |
85 // in the slice is suitable for passing directly to AptGetInstall. | 95 // in the slice is suitable for passing directly to AptGetInstall. |
86 // | 96 // |
87 // AptGetPreparePackages will inspect the series passed to it | 97 // AptGetPreparePackages will inspect the series passed to it |
88 // and properly generate an installCommand entry with a --target-release | 98 // and properly generate an installCommand entry with a --target-release |
89 // should the series be an LTS release with cloud archive packages. | 99 // should the series be an LTS release with cloud archive packages. |
90 func AptGetPreparePackages(packages []string, series string) [][]string { | 100 func AptGetPreparePackages(packages []string, series string) [][]string { |
91 var installCommands [][]string | 101 var installCommands [][]string |
92 if target := targetRelease(series); target == "" { | 102 if target := targetRelease(series); target == "" { |
93 return append(installCommands, packages) | 103 return append(installCommands, packages) |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 } | 210 } |
201 return strings.TrimSpace(out) == "Ubuntu" | 211 return strings.TrimSpace(out) == "Ubuntu" |
202 } | 212 } |
203 | 213 |
204 // IsPackageInstalled uses dpkg-query to determine if the `packageName` | 214 // IsPackageInstalled uses dpkg-query to determine if the `packageName` |
205 // package is installed. | 215 // package is installed. |
206 func IsPackageInstalled(packageName string) bool { | 216 func IsPackageInstalled(packageName string) bool { |
207 _, err := RunCommand("dpkg-query", "--status", packageName) | 217 _, err := RunCommand("dpkg-query", "--status", packageName) |
208 return err == nil | 218 return err == nil |
209 } | 219 } |
OLD | NEW |